##// END OF EJS Templates
fixed bug in category implementation. model now owns the category and sets
sauimone -
r173:5bd6f6e4373b
parent child
Show More
@@ -13,29 +13,29 int main(int argc, char *argv[])
13 QApplication a(argc, argv);
13 QApplication a(argc, argv);
14 QMainWindow window;
14 QMainWindow window;
15
15
16 QBarCategory category;
16 QBarCategory *category = new QBarCategory;
17 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
17 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
18
18
19 BarChartSeries* series0 = new BarChartSeries(category);
19 BarChartSeries* series0 = new BarChartSeries(category);
20
20
21 QBarSet barSet0;
21 QBarSet *set0 = new QBarSet;
22 QBarSet barSet1;
22 QBarSet *set1 = new QBarSet;
23 QBarSet barSet2;
23 QBarSet *set2 = new QBarSet;
24 QBarSet barSet3;
24 QBarSet *set3 = new QBarSet;
25 QBarSet barSet4;
25 QBarSet *set4 = new QBarSet;
26
26
27 // Create some test data to chart
27 // Create some test data to chart
28 barSet0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
28 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
29 barSet1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
29 *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
30 barSet2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
30 *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
31 barSet3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
31 *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
32 barSet4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
32 *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
33
33
34 series0->addBarSet(barSet0);
34 series0->addBarSet(set0);
35 series0->addBarSet(barSet1);
35 series0->addBarSet(set1);
36 series0->addBarSet(barSet2);
36 series0->addBarSet(set2);
37 series0->addBarSet(barSet3);
37 series0->addBarSet(set3);
38 series0->addBarSet(barSet4);
38 series0->addBarSet(set4);
39
39
40 ChartWidget* chartWidget = new ChartWidget(&window);
40 ChartWidget* chartWidget = new ChartWidget(&window);
41 chartWidget->addSeries(series0);
41 chartWidget->addSeries(series0);
@@ -13,29 +13,29 int main(int argc, char *argv[])
13 QApplication a(argc, argv);
13 QApplication a(argc, argv);
14 QMainWindow window;
14 QMainWindow window;
15
15
16 QBarCategory category;
16 QBarCategory *category = new QBarCategory;
17 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
17 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
18
18
19 PercentBarChartSeries* series0 = new PercentBarChartSeries(category);
19 PercentBarChartSeries* series0 = new PercentBarChartSeries(category);
20
20
21 QBarSet barSet0;
21 QBarSet *set0 = new QBarSet;
22 QBarSet barSet1;
22 QBarSet *set1 = new QBarSet;
23 QBarSet barSet2;
23 QBarSet *set2 = new QBarSet;
24 QBarSet barSet3;
24 QBarSet *set3 = new QBarSet;
25 QBarSet barSet4;
25 QBarSet *set4 = new QBarSet;
26
26
27 // Create some test data to chart
27 // Create some test data to chart
28 barSet0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
28 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
29 barSet1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
29 *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
30 barSet2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
30 *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
31 barSet3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
31 *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
32 barSet4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
32 *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
33
33
34 series0->addBarSet(barSet0);
34 series0->addBarSet(set0);
35 series0->addBarSet(barSet1);
35 series0->addBarSet(set1);
36 series0->addBarSet(barSet2);
36 series0->addBarSet(set2);
37 series0->addBarSet(barSet3);
37 series0->addBarSet(set3);
38 series0->addBarSet(barSet4);
38 series0->addBarSet(set4);
39
39
40 ChartWidget* chartWidget = new ChartWidget(&window);
40 ChartWidget* chartWidget = new ChartWidget(&window);
41 chartWidget->addSeries(series0);
41 chartWidget->addSeries(series0);
@@ -13,29 +13,29 int main(int argc, char *argv[])
13 QApplication a(argc, argv);
13 QApplication a(argc, argv);
14 QMainWindow window;
14 QMainWindow window;
15
15
16 QBarCategory category;
16 QBarCategory *category = new QBarCategory;
17 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
17 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
18
18
19 StackedBarChartSeries* series0 = new StackedBarChartSeries(category);
19 StackedBarChartSeries* series0 = new StackedBarChartSeries(category);
20
20
21 QBarSet barSet0;
21 QBarSet *set0 = new QBarSet;
22 QBarSet barSet1;
22 QBarSet *set1 = new QBarSet;
23 QBarSet barSet2;
23 QBarSet *set2 = new QBarSet;
24 QBarSet barSet3;
24 QBarSet *set3 = new QBarSet;
25 QBarSet barSet4;
25 QBarSet *set4 = new QBarSet;
26
26
27 // Create some test data to chart
27 // Create some test data to chart
28 barSet0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
28 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
29 barSet1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
29 *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
30 barSet2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
30 *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
31 barSet3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
31 *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
32 barSet4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
32 *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
33
33
34 series0->addBarSet(barSet0);
34 series0->addBarSet(set0);
35 series0->addBarSet(barSet1);
35 series0->addBarSet(set1);
36 series0->addBarSet(barSet2);
36 series0->addBarSet(set2);
37 series0->addBarSet(barSet3);
37 series0->addBarSet(set3);
38 series0->addBarSet(barSet4);
38 series0->addBarSet(set4);
39
39
40 ChartWidget* chartWidget = new ChartWidget(&window);
40 ChartWidget* chartWidget = new ChartWidget(&window);
41 chartWidget->addSeries(series0);
41 chartWidget->addSeries(series0);
@@ -7,27 +7,35
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 BarChartModel::BarChartModel(QBarCategory &category, QObject *parent) :
10 BarChartModel::BarChartModel(QBarCategory *category, QObject *parent) :
11 QObject(parent)
11 QObject(parent)
12 ,mCategory(category)
12 ,mCategory(category)
13 {
13 {
14 }
14 }
15
15
16 QBarCategory& BarChartModel::category()
16 BarChartModel::~BarChartModel()
17 {
17 {
18 return mCategory;
18 delete mCategory;
19 }
19 }
20
20
21 void BarChartModel::addBarSet(QBarSet &set)
21
22 QBarCategory& BarChartModel::category()
22 {
23 {
23 mDataModel.append(&set);
24 return *mCategory;
24 }
25 }
25
26
26 void BarChartModel::removeBarSet(QBarSet &set)
27 void BarChartModel::addBarSet(QBarSet *set)
27 {
28 {
28 mDataModel.removeOne(&set);
29 mDataModel.append(set);
29 }
30 }
30
31
32 void BarChartModel::removeBarSet(QBarSet *set)
33 {
34 if (mDataModel.contains(set)) {
35 mDataModel.removeOne(set);
36 delete set;
37 }
38 }
31
39
32 int BarChartModel::countSets()
40 int BarChartModel::countSets()
33 {
41 {
@@ -135,7 +143,7 qreal BarChartModel::maxCategorySum()
135
143
136 QString BarChartModel::label(int category)
144 QString BarChartModel::label(int category)
137 {
145 {
138 return mCategory.label(category);
146 return mCategory->label(category);
139 }
147 }
140
148
141 #include "moc_barchartmodel_p.cpp"
149 #include "moc_barchartmodel_p.cpp"
@@ -16,11 +16,12 class BarChartModel : public QObject //, public QAbstractItemModel
16 {
16 {
17 Q_OBJECT
17 Q_OBJECT
18 public:
18 public:
19 explicit BarChartModel(QBarCategory &category, QObject *parent = 0);
19 explicit BarChartModel(QBarCategory *category, QObject *parent = 0);
20 ~BarChartModel();
20
21
21 QBarCategory& category();
22 QBarCategory& category();
22 void addBarSet(QBarSet &set);
23 void addBarSet(QBarSet *set);
23 void removeBarSet(QBarSet &set);
24 void removeBarSet(QBarSet *set);
24
25
25 int countSets(); // Number of sets in model
26 int countSets(); // Number of sets in model
26 int countCategories(); // Number of categories
27 int countCategories(); // Number of categories
@@ -43,7 +44,7 public slots:
43 private:
44 private:
44
45
45 QList<QBarSet*> mDataModel;
46 QList<QBarSet*> mDataModel;
46 QBarCategory& mCategory;
47 QBarCategory* mCategory; // Owned
47
48
48 };
49 };
49
50
@@ -7,18 +7,18
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 BarChartSeries::BarChartSeries(QBarCategory &category, QObject *parent)
10 BarChartSeries::BarChartSeries(QBarCategory *category, QObject *parent)
11 : QChartSeries(parent)
11 : QChartSeries(parent)
12 ,mModel(new BarChartModel(category, this))
12 ,mModel(new BarChartModel(category, this))
13 {
13 {
14 }
14 }
15
15
16 void BarChartSeries::addBarSet(QBarSet &set)
16 void BarChartSeries::addBarSet(QBarSet *set)
17 {
17 {
18 mModel->addBarSet(set);
18 mModel->addBarSet(set);
19 }
19 }
20
20
21 void BarChartSeries::removeBarSet(QBarSet &set)
21 void BarChartSeries::removeBarSet(QBarSet *set)
22 {
22 {
23 mModel->removeBarSet(set);
23 mModel->removeBarSet(set);
24 }
24 }
@@ -17,14 +17,18 class QTCOMMERCIALCHART_EXPORT BarChartSeries : public QChartSeries
17 {
17 {
18 Q_OBJECT
18 Q_OBJECT
19 public:
19 public:
20 BarChartSeries(QBarCategory &category, QObject* parent=0);
20 BarChartSeries(QBarCategory *category, QObject* parent=0);
21
21
22 // from BarChartSeriesBase
23 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; }
22 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; }
24
23
25 void addBarSet(QBarSet &set);
24 void addBarSet(QBarSet *set); // Takes ownership
26 void removeBarSet(QBarSet &set);
25 void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned.
27
26
27 //TODO:
28 //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
29
30 // TODO: Functions below this are not part of api and will be moved
31 // to private implementation, when we start using it (not part of api)
28 int countCategories();
32 int countCategories();
29 qreal min();
33 qreal min();
30 qreal max();
34 qreal max();
@@ -8,7 +8,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 BarGroup::BarGroup(BarChartModel& model, QGraphicsItem *parent) :
8 BarGroup::BarGroup(BarChartModel& model, QGraphicsItem *parent) :
9 BarGroupBase(model,parent)
9 BarGroupBase(model,parent)
10 {
10 {
11 mBarDefaultWidth = 10;
11 mBarDefaultWidth = 5;
12 }
12 }
13
13
14 void BarGroup::layoutChanged()
14 void BarGroup::layoutChanged()
@@ -17,6 +17,7 void BarGroup::layoutChanged()
17 // Scale bars to new layout
17 // Scale bars to new layout
18 // Layout for bars:
18 // Layout for bars:
19 if (mModel.countSets() <= 0) {
19 if (mModel.countSets() <= 0) {
20 qDebug() << "No sets in model!";
20 return;
21 return;
21 }
22 }
22
23
@@ -13,7 +13,6 BarGroupBase::BarGroupBase(BarChartModel& model, QGraphicsItem *parent)
13 ,mLayoutDirty(true)
13 ,mLayoutDirty(true)
14 ,mSeparatorsVisible(true)
14 ,mSeparatorsVisible(true)
15 ,mModel(model)
15 ,mModel(model)
16 // ,mSeries(series)
17 {
16 {
18 dataChanged();
17 dataChanged();
19 }
18 }
@@ -72,20 +71,20 void BarGroupBase::dataChanged()
72 }
71 }
73
72
74 // Create new graphic items for bars
73 // Create new graphic items for bars
75 int totalItems = mModel.countTotalItems(); // mSeries.countTotalItems();
74 int totalItems = mModel.countTotalItems();
76 for (int i=0; i<totalItems; i++) {
75 for (int i=0; i<totalItems; i++) {
77 Bar *bar = new Bar(this);
76 Bar *bar = new Bar(this);
78 childItems().append(bar);
77 childItems().append(bar);
79 }
78 }
80
79
81 int count = mModel.countCategories(); // mSeries.countColumns();
80 int count = mModel.countCategories();
82 for (int i=0; i<count; i++) {
81 for (int i=0; i<count; i++) {
83 BarLabel* label = new BarLabel(this);
82 BarLabel* label = new BarLabel(this);
84 label->set(mModel.label(i));
83 label->set(mModel.label(i));
85 childItems().append(label);
84 childItems().append(label);
86 }
85 }
87
86
88 count = mModel.countCategories() - 1; // mSeries.countColumns() - 1; // There is one less separator than columns
87 count = mModel.countCategories() - 1; // There is one less separator than columns
89 for (int i=0; i<count; i++) {
88 for (int i=0; i<count; i++) {
90 Separator* sep = new Separator(this);
89 Separator* sep = new Separator(this);
91 sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme
90 sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme
@@ -100,14 +99,13 void BarGroupBase::dataChanged()
100
99
101 void BarGroupBase::handleModelChanged(int index)
100 void BarGroupBase::handleModelChanged(int index)
102 {
101 {
103 qDebug() << "BarGroupBase::handleModelChanged" << index;
102 // qDebug() << "BarGroupBase::handleModelChanged" << index;
104 dataChanged();
103 dataChanged();
105 }
104 }
106
105
107 void BarGroupBase::handleDomainChanged(const Domain& domain)
106 void BarGroupBase::handleDomainChanged(const Domain& domain)
108 {
107 {
109 // qDebug() << "BarGroupBase::handleDomainChanged";
108 // qDebug() << "BarGroupBase::handleDomainChanged";
110
111 // TODO: Figure out the use case for this.
109 // TODO: Figure out the use case for this.
112 // Affects the size of visible item, so layout is changed.
110 // Affects the size of visible item, so layout is changed.
113 // layoutChanged();
111 // layoutChanged();
@@ -115,7 +113,6 void BarGroupBase::handleDomainChanged(const Domain& domain)
115
113
116 void BarGroupBase::handleGeometryChanged(const QRectF& rect)
114 void BarGroupBase::handleGeometryChanged(const QRectF& rect)
117 {
115 {
118 // qDebug() << "BarGroupBase::handleGeometryChanged";
119 mWidth = rect.width();
116 mWidth = rect.width();
120 mHeight = rect.height();
117 mHeight = rect.height();
121 layoutChanged();
118 layoutChanged();
@@ -9,18 +9,18
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 PercentBarChartSeries::PercentBarChartSeries(QBarCategory &category, QObject *parent)
12 PercentBarChartSeries::PercentBarChartSeries(QBarCategory *category, QObject *parent)
13 : QChartSeries(parent)
13 : QChartSeries(parent)
14 ,mModel(new BarChartModel(category, this))
14 ,mModel(new BarChartModel(category, this))
15 {
15 {
16 }
16 }
17
17
18 void PercentBarChartSeries::addBarSet(QBarSet &set)
18 void PercentBarChartSeries::addBarSet(QBarSet *set)
19 {
19 {
20 mModel->addBarSet(set);
20 mModel->addBarSet(set);
21 }
21 }
22
22
23 void PercentBarChartSeries::removeBarSet(QBarSet &set)
23 void PercentBarChartSeries::removeBarSet(QBarSet *set)
24 {
24 {
25 mModel->removeBarSet(set);
25 mModel->removeBarSet(set);
26 }
26 }
@@ -16,14 +16,19 class QTCOMMERCIALCHART_EXPORT PercentBarChartSeries : public QChartSeries
16 {
16 {
17 Q_OBJECT
17 Q_OBJECT
18 public:
18 public:
19 PercentBarChartSeries(QBarCategory &category, QObject* parent=0);
19 PercentBarChartSeries(QBarCategory *category, QObject* parent=0);
20
20
21 // from BarChartSeriesBase
21 // from BarChartSeriesBase
22 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypePercentBar; }
22 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypePercentBar; }
23
23
24 void addBarSet(QBarSet &set);
24 void addBarSet(QBarSet *set); // Takes ownership
25 void removeBarSet(QBarSet &set);
25 void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned.
26
26
27 //TODO:
28 //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
29
30 // TODO: Functions below this are not part of api and will be moved
31 // to private implementation, when we start using it (not part of api)
27 int countCategories();
32 int countCategories();
28 qreal min();
33 qreal min();
29 qreal max();
34 qreal max();
@@ -14,9 +14,11 PercentBarGroup::PercentBarGroup(BarChartModel& model, QGraphicsItem *parent) :
14
14
15 void PercentBarGroup::layoutChanged()
15 void PercentBarGroup::layoutChanged()
16 {
16 {
17 // qDebug() << "PercentBarGroup::layoutChanged";
17 // Scale bars to new layout
18 // Scale bars to new layout
18 // Layout for bars:
19 // Layout for bars:
19 if (mModel.countSets() <= 0) {
20 if (mModel.countSets() <= 0) {
21 qDebug() << "No sets in model!";
20 // Nothing to do.
22 // Nothing to do.
21 return;
23 return;
22 }
24 }
@@ -22,5 +22,6 QString QBarCategory::label(int category)
22 return mList.at(category);
22 return mList.at(category);
23 }
23 }
24
24
25
25 // TODO?:
26 //#include "moc_qbarcategory.cpp"
26 QTCOMMERCIALCHART_END_NAMESPACE
27 QTCOMMERCIALCHART_END_NAMESPACE
@@ -5,8 +5,9
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 class QTCOMMERCIALCHART_EXPORT QBarCategory // TODO? : pubclic QObject
8 class QTCOMMERCIALCHART_EXPORT QBarCategory // TODO?: : public QObject
9 {
9 {
10 // Q_OBJECT;
10 public:
11 public:
11 QBarCategory();
12 QBarCategory();
12
13
@@ -31,5 +31,6 qreal QBarSet::valueAt(int index)
31 return mValues.at(index);
31 return mValues.at(index);
32 }
32 }
33
33
34
34 //TODO?:
35 //#include "moc_qbarset.cpp"
35 QTCOMMERCIALCHART_END_NAMESPACE
36 QTCOMMERCIALCHART_END_NAMESPACE
@@ -5,8 +5,9
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 class QTCOMMERCIALCHART_EXPORT QBarSet // : pubclic QObject // TODO: Need for this?
8 class QTCOMMERCIALCHART_EXPORT QBarSet // TODO? : public QObject
9 {
9 {
10 //Q_OBJECT;
10 public:
11 public:
11 QBarSet();
12 QBarSet();
12
13
@@ -7,18 +7,18
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 StackedBarChartSeries::StackedBarChartSeries(QBarCategory &category, QObject *parent)
10 StackedBarChartSeries::StackedBarChartSeries(QBarCategory *category, QObject *parent)
11 : QChartSeries(parent)
11 : QChartSeries(parent)
12 ,mModel(new BarChartModel(category, this))
12 ,mModel(new BarChartModel(category, this))
13 {
13 {
14 }
14 }
15
15
16 void StackedBarChartSeries::addBarSet(QBarSet &set)
16 void StackedBarChartSeries::addBarSet(QBarSet *set)
17 {
17 {
18 mModel->addBarSet(set);
18 mModel->addBarSet(set);
19 }
19 }
20
20
21 void StackedBarChartSeries::removeBarSet(QBarSet &set)
21 void StackedBarChartSeries::removeBarSet(QBarSet *set)
22 {
22 {
23 mModel->removeBarSet(set);
23 mModel->removeBarSet(set);
24 }
24 }
@@ -16,14 +16,19 class QTCOMMERCIALCHART_EXPORT StackedBarChartSeries : public QChartSeries
16 {
16 {
17 Q_OBJECT
17 Q_OBJECT
18 public:
18 public:
19 StackedBarChartSeries(QBarCategory &category, QObject* parent=0);
19 StackedBarChartSeries(QBarCategory *category, QObject* parent=0);
20
20
21 // from QChartSeries
21 // from QChartSeries
22 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeStackedBar; }
22 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeStackedBar; }
23
23
24 void addBarSet(QBarSet &set);
24 void addBarSet(QBarSet *set); // Takes ownership
25 void removeBarSet(QBarSet &set);
25 void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned.
26
26
27 //TODO:
28 //QList<QString> legend(); // Returns legend of series (ie. names of all sets in series)
29
30 // TODO: Functions below this are not part of api and will be moved
31 // to private implementation, when we start using it (not part of api)
27 int countCategories();
32 int countCategories();
28 qreal min();
33 qreal min();
29 qreal max();
34 qreal max();
@@ -17,11 +17,13 void StackedBarGroup::layoutChanged()
17 // Scale bars to new layout
17 // Scale bars to new layout
18 // Layout for bars:
18 // Layout for bars:
19 if (mModel.countSets() <= 0) {
19 if (mModel.countSets() <= 0) {
20 qDebug() << "No sets in model!";
20 // Nothing to do.
21 // Nothing to do.
21 return;
22 return;
22 }
23 }
23
24
24 if (mModel.countCategories() == 0) {
25 if (mModel.countCategories() == 0) {
26 qDebug() << "No categories in model!";
25 // Nothing to do
27 // Nothing to do
26 return;
28 return;
27 }
29 }
@@ -65,7 +67,6 void StackedBarGroup::layoutChanged()
65 xPos += xStep;
67 xPos += xStep;
66 }
68 }
67
69
68
69 // Position separators
70 // Position separators
70 int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these?
71 int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these?
71 xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left.
72 xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left.
@@ -52,7 +52,7 void ChartDataSet::addSeries(QChartSeries* series)
52 break;
52 break;
53 }
53 }
54 case QChartSeries::SeriesTypeBar: {
54 case QChartSeries::SeriesTypeBar: {
55
55 qDebug() << "QChartSeries::SeriesTypeBar";
56 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
56 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
57 qreal x = barSeries->countCategories();
57 qreal x = barSeries->countCategories();
58 qreal y = barSeries->max();
58 qreal y = barSeries->max();
@@ -63,6 +63,7 void ChartDataSet::addSeries(QChartSeries* series)
63 break;
63 break;
64 }
64 }
65 case QChartSeries::SeriesTypeStackedBar: {
65 case QChartSeries::SeriesTypeStackedBar: {
66 qDebug() << "QChartSeries::SeriesTypeStackedBar";
66
67
67 StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series);
68 StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series);
68 qreal x = stackedBarSeries->countCategories();
69 qreal x = stackedBarSeries->countCategories();
@@ -74,6 +75,7 void ChartDataSet::addSeries(QChartSeries* series)
74 break;
75 break;
75 }
76 }
76 case QChartSeries::SeriesTypePercentBar: {
77 case QChartSeries::SeriesTypePercentBar: {
78 qDebug() << "QChartSeries::SeriesTypePercentBar";
77
79
78 PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series);
80 PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series);
79 qreal x = percentBarSeries->countCategories();
81 qreal x = percentBarSeries->countCategories();
@@ -76,6 +76,7 void ChartPresenter::setMargin(int margin)
76
76
77 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
77 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
78 {
78 {
79 qDebug() << " ChartPresenter::handleSeriesAdded";
79 switch(series->type())
80 switch(series->type())
80 {
81 {
81 case QChartSeries::SeriesTypeLine: {
82 case QChartSeries::SeriesTypeLine: {
@@ -180,11 +180,11 void MainWidget::addSeries(QString series, QString data)
180 QList<qreal> x;
180 QList<qreal> x;
181 QList<qreal> y;
181 QList<qreal> y;
182
182
183 QBarSet set0;
183 QBarSet *set0 = new QBarSet;
184 QBarSet set1;
184 QBarSet *set1 = new QBarSet;
185 QBarSet set2;
185 QBarSet *set2 = new QBarSet;
186 QBarSet set3;
186 QBarSet *set3 = new QBarSet;
187 QBarSet set4;
187 QBarSet *set4 = new QBarSet;
188
188
189 if (data == "linear") {
189 if (data == "linear") {
190 for (int i = 0; i < 20; i++) {
190 for (int i = 0; i < 20; i++) {
@@ -213,11 +213,11 void MainWidget::addSeries(QString series, QString data)
213 }
213 }
214 } else if (data == "Table, 5 series"){
214 } else if (data == "Table, 5 series"){
215 // Create some test data to chart
215 // Create some test data to chart
216 set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
216 *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
217 set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
217 *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
218 set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
218 *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
219 set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
219 *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
220 set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
220 *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
221 } else {
221 } else {
222 // TODO: check if data has a valid file name
222 // TODO: check if data has a valid file name
223 Q_ASSERT(false);
223 Q_ASSERT(false);
@@ -248,8 +248,8 void MainWidget::addSeries(QString series, QString data)
248 } else if (series == "Bar") {
248 } else if (series == "Bar") {
249 qDebug() << "Bar chart series";
249 qDebug() << "Bar chart series";
250
250
251 QBarCategory category;
251 QBarCategory *category = new QBarCategory;
252 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
252 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
253
253
254 BarChartSeries* series0 = new BarChartSeries(category, this);
254 BarChartSeries* series0 = new BarChartSeries(category, this);
255
255
@@ -264,8 +264,8 void MainWidget::addSeries(QString series, QString data)
264 } else if (series == "StackedBar") {
264 } else if (series == "StackedBar") {
265 qDebug() << "Stacked bar chart series";
265 qDebug() << "Stacked bar chart series";
266
266
267 QBarCategory category;
267 QBarCategory *category = new QBarCategory;
268 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
268 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
269
269
270 StackedBarChartSeries* series0 = new StackedBarChartSeries(category, this);
270 StackedBarChartSeries* series0 = new StackedBarChartSeries(category, this);
271
271
@@ -280,8 +280,8 void MainWidget::addSeries(QString series, QString data)
280 } else if (series == "PercentBar") {
280 } else if (series == "PercentBar") {
281 qDebug() << "Percent bar chart series";
281 qDebug() << "Percent bar chart series";
282
282
283 QBarCategory category;
283 QBarCategory *category = new QBarCategory;
284 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
284 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
285
285
286 PercentBarChartSeries* series0 = new PercentBarChartSeries(category, this);
286 PercentBarChartSeries* series0 = new PercentBarChartSeries(category, this);
287
287
General Comments 0
You need to be logged in to leave comments. Login now