##// END OF EJS Templates
Barset and barcategory implememtation. Updated test application
sauimone -
r171:d4b8c60ed973
parent child
Show More
@@ -14,7 +14,7 int main(int argc, char *argv[])
14 14 QMainWindow window;
15 15
16 16 QBarCategory category;
17 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec";
17 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
18 18
19 19 BarChartSeries* series0 = new BarChartSeries(category);
20 20
@@ -14,7 +14,7 int main(int argc, char *argv[])
14 14 QMainWindow window;
15 15
16 16 QBarCategory category;
17 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec";
17 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
18 18
19 19 PercentBarChartSeries* series0 = new PercentBarChartSeries(category);
20 20
@@ -14,7 +14,7 int main(int argc, char *argv[])
14 14 QMainWindow window;
15 15
16 16 QBarCategory category;
17 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec";
17 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
18 18
19 19 StackedBarChartSeries* series0 = new StackedBarChartSeries(category);
20 20
@@ -9,67 +9,37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 BarChartModel::BarChartModel(QBarCategory &category, QObject *parent) :
11 11 QObject(parent)
12 ,mRunningId(1)
13 12 ,mCategory(category)
14 13 {
15 14 }
16 15
17 BarChartModel::~BarChartModel()
16 QBarCategory& BarChartModel::category()
18 17 {
19 // qDebug() << "BarChartModel::~BarChartModel";
20 foreach (DataContainer* c, mDataModel) {
21 delete c;
22 }
23 }
24
25 int BarChartModel::addData(QList<qreal> data)
26 {
27 // qDebug() << "BarChartModel::addData" << data.count();
28 DataContainer* c = new DataContainer(data,mRunningId);
29 mDataModel.append(c);
30 mRunningId++;
31 emit modelUpdated();
32 return mRunningId-1;
33 }
34
35 void BarChartModel::removeData(int id)
36 {
37 // qDebug() << "BarChartModel::removeData";
38 foreach(DataContainer* c, mDataModel) {
39 if (c->mId == id) {
40 mDataModel.removeOne(c);
41 delete c;
42 }
43 }
44 emit modelUpdated();
18 return mCategory;
45 19 }
46 20
47 21 void BarChartModel::addBarSet(QBarSet &set)
48 22 {
49 DataContainer* c = new DataContainer(set.mValues,mRunningId);
50 mDataModel.append(c);
51 mRunningId++;
23 mDataModel.append(&set);
52 24 }
53 25
54 26 void BarChartModel::removeBarSet(QBarSet &set)
55 27 {
56 // TODO:
28 mDataModel.removeOne(&set);
57 29 }
58 30
59 31
60 int BarChartModel::countRows()
32 int BarChartModel::countSets()
61 33 {
62 // qDebug() << "BarChartModel::countRows";
63 34 return mDataModel.count();
64 35 }
65 36
66 int BarChartModel::countColumns()
37 int BarChartModel::countCategories()
67 38 {
68 // qDebug() << "BarChartModel::countColumns";
69 39 int count(0);
70 40 for (int i=0; i<mDataModel.count(); i++){
71 41 // TODO: can we assume that all series have same number of values? If not. then which values are empty?
72 int temp = mDataModel.at(i)->countColumns();
42 int temp = mDataModel.at(i)->count();
73 43 if (temp > count) {
74 44 count = temp;
75 45 }
@@ -79,21 +49,19 int BarChartModel::countColumns()
79 49
80 50 int BarChartModel::countTotalItems()
81 51 {
82 // qDebug() << "BarChartModel::countTotalItems";
83 int total = mDataModel.count() * countColumns();
52 int total = mDataModel.count() * countCategories();
84 53 return total;
85 54 }
86 55
87 56 qreal BarChartModel::min()
88 57 {
89 // qDebug() << "BarChartModel::min";
90 58 Q_ASSERT(mDataModel.count() > 0);
91 59 // TODO: make min and max members and update them when data changes.
92 60 // This is slower since they are checked every time, even if data is same since previous call.
93 61 qreal min = INT_MAX;
94 62
95 63 for (int i=0; i <mDataModel.count(); i++) {
96 int itemCount = mDataModel.at(i)->countColumns();
64 int itemCount = mDataModel.at(i)->count();
97 65 for (int j=0; j<itemCount; j++) {
98 66 qreal temp = mDataModel.at(i)->valueAt(j);
99 67 if (temp < min) {
@@ -106,7 +74,6 qreal BarChartModel::min()
106 74
107 75 qreal BarChartModel::max()
108 76 {
109 // qDebug() << "BarChartModel::max";
110 77 Q_ASSERT(mDataModel.count() > 0);
111 78
112 79 // TODO: make min and max members and update them when data changes.
@@ -114,7 +81,7 qreal BarChartModel::max()
114 81 qreal max = INT_MIN;
115 82
116 83 for (int i=0; i <mDataModel.count(); i++) {
117 int itemCount = mDataModel.at(i)->countColumns();
84 int itemCount = mDataModel.at(i)->count();
118 85 for (int j=0; j<itemCount; j++) {
119 86 qreal temp = mDataModel.at(i)->valueAt(j);
120 87 if (temp > max) {
@@ -126,43 +93,39 qreal BarChartModel::max()
126 93 return max;
127 94 }
128 95
129 qreal BarChartModel::valueAt(int series, int item)
96 qreal BarChartModel::valueAt(int set, int category)
130 97 {
131 // qDebug() << "BarChartModel::valueAt" << series << item;
132 if ((series < 0) || (series >= mDataModel.count())) {
133 // No series, no value.
98 if ((set < 0) || (set >= mDataModel.count())) {
99 // No set, no value.
134 100 return 0;
135 } else if ((item < 0) || (item >= mDataModel.at(series)->countColumns())) {
136 // No item, no value.
101 } else if ((category < 0) || (category >= mDataModel.at(set)->count())) {
102 // No category, no value.
137 103 return 0;
138 104 }
139 105
140 // qDebug() << "ValueAt" << series << item << "=" << mDataModel.at(series)->valueAt(item);
141 return mDataModel.at(series)->valueAt(item);
106 return mDataModel.at(set)->valueAt(category);
142 107 }
143 108
144 qreal BarChartModel::columnSum(int column)
109 qreal BarChartModel::categorySum(int column)
145 110 {
146 // qDebug() << "BarChartModel::columnSum";
147 int sum(0);
111 qreal sum(0);
148 112 int count = mDataModel.count(); // Count rows
149 113
150 114 for (int row = 0; row < count; row++) {
151 if (column < mDataModel.at(row)->countColumns()) {
115 if (column < mDataModel.at(row)->count()) {
152 116 sum += mDataModel.at(row)->valueAt(column);
153 117 }
154 118 }
155 119 return sum;
156 120 }
157 121
158 qreal BarChartModel::maxColumnSum()
122 qreal BarChartModel::maxCategorySum()
159 123 {
160 // qDebug() << "BarChartModel::maxColumnSum";
161 int max = INT_MIN;
162 int count = countColumns();
124 qreal max = INT_MIN;
125 int count = countCategories();
163 126
164 127 for (int col=0; col<count; col++) {
165 int sum = columnSum(col);
128 qreal sum = categorySum(col);
166 129 if (sum > max) {
167 130 max = sum;
168 131 }
@@ -17,25 +17,21 class BarChartModel : public QObject //, public QAbstractItemModel
17 17 Q_OBJECT
18 18 public:
19 19 explicit BarChartModel(QBarCategory &category, QObject *parent = 0);
20 ~BarChartModel();
21
22 // TODO: remove these after add and remove QBarSet works.
23 int addData(QList<qreal> data);
24 void removeData(int id);
25 20
21 QBarCategory& category();
26 22 void addBarSet(QBarSet &set);
27 23 void removeBarSet(QBarSet &set);
28 24
29 int countRows(); // Number of series in model
30 int countColumns(); // Maximum number of items in series
31 int countTotalItems(); // Total items in all series. Includes empty items.
25 int countSets(); // Number of sets in model
26 int countCategories(); // Number of categories
27 int countTotalItems(); // Total items in all sets. Includes empty items.
32 28
33 qreal max(); // Maximum value of all series
34 qreal min(); // Minimum value of all series
35 qreal valueAt(int series, int item);
29 qreal max(); // Maximum value of all sets
30 qreal min(); // Minimum value of all sets
31 qreal valueAt(int set, int category);
36 32
37 qreal columnSum(int column);
38 qreal maxColumnSum(); // returns maximum sum of items in all columns.
33 qreal categorySum(int column);
34 qreal maxCategorySum(); // returns maximum sum of sets in all categories.
39 35
40 36 signals:
41 37 void modelUpdated();
@@ -44,22 +40,7 public slots:
44 40
45 41 private:
46 42
47 // Little helper class.
48 class DataContainer {
49 public:
50 DataContainer(QList<qreal> data, int id) : mId(id), mData(data) {}
51 int countColumns() { return mData.count(); }
52 qreal valueAt(int item) { return mData.at(item); }
53
54 int mId; // TODO: Is this needed?
55 private:
56 QList<qreal> mData;
57 };
58
59 // Owned. N series. each has a list of values.
60 QList<DataContainer*> mDataModel;
61 int mRunningId;
62 int mMaxColumns; // longest series in datamodel
43 QList<QBarSet*> mDataModel;
63 44 QBarCategory& mCategory;
64 45
65 46 };
@@ -8,6 +8,16 BarChartSeries::BarChartSeries(QBarCategory &category, QObject *parent)
8 8 {
9 9 }
10 10
11 void BarChartSeries::addBarSet(QBarSet &set)
12 {
13 BarChartSeriesBase::addBarSet(set);
14 }
15
16 void BarChartSeries::removeBarSet(QBarSet &set)
17 {
18 BarChartSeriesBase::removeBarSet(set);
19 }
20
11 21 #include "moc_barchartseries.cpp"
12 22
13 23 QTCOMMERCIALCHART_END_NAMESPACE
@@ -19,6 +19,11 public:
19 19 // from BarChartSeriesBase
20 20 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; }
21 21
22 void addBarSet(QBarSet &set);
23 void removeBarSet(QBarSet &set);
24
25 public Q_SLOTS:
26
22 27 private:
23 28
24 29 BarGroup* mBarGroup;
@@ -4,6 +4,7
4 4 #include "bargroup.h"
5 5 #include "barchartmodel_p.h"
6 6 #include "qbarset.h"
7 #include "qbarcategory.h"
7 8
8 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 10
@@ -11,21 +12,7 BarChartSeriesBase::BarChartSeriesBase(QBarCategory &category, QObject *parent)
11 12 : QChartSeries(parent)
12 13 ,mModel(new BarChartModel(category, this))
13 14 {
14 }
15
16 int BarChartSeriesBase::addData(QList<qreal> data)
17 {
18 return mModel->addData(data);
19 }
20
21 void BarChartSeriesBase::removeData(int id)
22 {
23 mModel->removeData(id);
24 }
25
26 void BarChartSeriesBase::setLabels(QList<QString> labels)
27 {
28 mLabels = labels;
15 mLabels.append(category.items());
29 16 }
30 17
31 18 void BarChartSeriesBase::addBarSet(QBarSet &set)
@@ -50,7 +37,7 qreal BarChartSeriesBase::max()
50 37
51 38 int BarChartSeriesBase::countColumns()
52 39 {
53 return mModel->countColumns();
40 return mModel->countCategories();
54 41 }
55 42
56 43 qreal BarChartSeriesBase::valueAt(int series, int item)
@@ -62,7 +49,7 qreal BarChartSeriesBase::valueAt(int series, int item)
62 49 qreal BarChartSeriesBase::maxColumnSum()
63 50 {
64 51 // qDebug() << "BarChartSeriesBase::maxColumnSum" << mModel->maxColumnSum();
65 return mModel->maxColumnSum();
52 return mModel->maxCategorySum();
66 53 }
67 54
68 55 BarChartModel& BarChartSeriesBase::model()
@@ -25,15 +25,12 public:
25 25 // from QChartSeries
26 26 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeInvalid; }
27 27
28 // TODO: These 3 will be removed.
29 int addData(QList<qreal> data);
30 void removeData(int id);
31 void setLabels(QList<QString> labels);
32
33 // TODO: Expose these to user in derived class instead of here? Common implementation for all bar charts, but not visible to user
34 void addBarSet(QBarSet &set); // Bob[1,5,6,2,15,4] first value goes to category 1 etc..
35 void removeBarSet(QBarSet &set); //
28 protected:
29 // Used by derived series
30 void addBarSet(QBarSet &set);
31 void removeBarSet(QBarSet &set);
36 32
33 public:
37 34 // These shouldn't be visible to chart series user. However, ChartDataSet needs to access them, and friends are evil.
38 35 qreal min();
39 36 qreal max();
@@ -16,7 +16,7 void BarGroup::layoutChanged()
16 16 // qDebug() << "BarGroup::layoutChanged";
17 17 // Scale bars to new layout
18 18 // Layout for bars:
19 if (mModel.countRows() <= 0) {
19 if (mModel.countSets() <= 0) {
20 20 return;
21 21 }
22 22
@@ -27,8 +27,8 void BarGroup::layoutChanged()
27 27
28 28 // TODO: better way to auto-layout?
29 29 // Use reals for accurancy (we might get some compiler warnings... :)
30 int itemCount = mModel.countColumns();
31 int seriesCount = mModel.countRows();
30 int itemCount = mModel.countCategories();
31 int seriesCount = mModel.countSets();
32 32
33 33 qreal tW = mWidth;
34 34 qreal tH = mHeight;
@@ -80,7 +80,7 void BarGroupBase::dataChanged()
80 80 }
81 81
82 82 // TODO: labels from series. This creates just some example labels
83 int count = mModel.countColumns(); // mSeries.countColumns();
83 int count = mModel.countCategories(); // mSeries.countColumns();
84 84 for (int i=0; i<count; i++) {
85 85 BarLabel* label = new BarLabel(this);
86 86 // QString text("Label " + QString::number(i));
@@ -88,7 +88,7 void BarGroupBase::dataChanged()
88 88 childItems().append(label);
89 89 }
90 90
91 count = mModel.countColumns() - 1; // mSeries.countColumns() - 1; // There is one less separator than columns
91 count = mModel.countCategories() - 1; // mSeries.countColumns() - 1; // There is one less separator than columns
92 92 for (int i=0; i<count; i++) {
93 93 Separator* sep = new Separator(this);
94 94 sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme
@@ -11,6 +11,16 PercentBarChartSeries::PercentBarChartSeries(QBarCategory &category, QObject *pa
11 11 {
12 12 }
13 13
14 void PercentBarChartSeries::addBarSet(QBarSet &set)
15 {
16 BarChartSeriesBase::addBarSet(set);
17 }
18
19 void PercentBarChartSeries::removeBarSet(QBarSet &set)
20 {
21 BarChartSeriesBase::removeBarSet(set);
22 }
23
14 24 #include "moc_percentbarchartseries.cpp"
15 25
16 26 QTCOMMERCIALCHART_END_NAMESPACE
@@ -18,6 +18,9 public:
18 18 // from BarChartSeriesBase
19 19 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypePercentBar; }
20 20
21 void addBarSet(QBarSet &set);
22 void removeBarSet(QBarSet &set);
23
21 24 public Q_SLOTS:
22 25
23 26 private:
@@ -16,7 +16,7 void PercentBarGroup::layoutChanged()
16 16 {
17 17 // Scale bars to new layout
18 18 // Layout for bars:
19 if (mModel.countRows() <= 0) {
19 if (mModel.countSets() <= 0) {
20 20 // Nothing to do.
21 21 return;
22 22 }
@@ -28,20 +28,20 void PercentBarGroup::layoutChanged()
28 28
29 29 // TODO: better way to auto-layout
30 30 // Use reals for accurancy (we might get some compiler warnings... :)
31 int count = mModel.countColumns();
31 int count = mModel.countCategories();
32 32 int itemIndex(0);
33 33 qreal tW = mWidth;
34 34 qreal tC = count+1;
35 35 qreal xStep = (tW/tC);
36 36 qreal xPos = ((tW/tC) - mBarDefaultWidth / 2);
37 int labelIndex = mModel.countColumns() * mModel.countRows();
37 int labelIndex = mModel.countCategories() * mModel.countSets();
38 38
39 for (int column = 0; column < mModel.countColumns(); column++) {
40 qreal colSum = mModel.columnSum(column);
39 for (int column = 0; column < mModel.countCategories(); column++) {
40 qreal colSum = mModel.categorySum(column);
41 41 qreal h = mHeight;
42 42 qreal scale = (h / colSum);
43 43 qreal yPos = h;
44 for (int row=0; row < mModel.countRows(); row++) {
44 for (int row=0; row < mModel.countSets(); row++) {
45 45 qreal barHeight = mModel.valueAt(row, column) * scale;
46 46 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
47 47
@@ -63,7 +63,7 void PercentBarGroup::layoutChanged()
63 63 // Position separators
64 64 int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these?
65 65 xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left.
66 for (int s=0; s < mModel.countColumns() - 1; s++) {
66 for (int s=0; s < mModel.countCategories() - 1; s++) {
67 67 Separator* sep = reinterpret_cast<Separator*> (childItems().at(separatorIndex));
68 68 sep->setPos(xPos,0);
69 69 sep->setSize(QSizeF(1,mHeight));
@@ -10,6 +10,10 void QBarSet::setName(QString name)
10 10 {
11 11 mName = name;
12 12 }
13 QString QBarSet::name()
14 {
15 return mName;
16 }
13 17
14 18 QBarSet& QBarSet::operator << (const qreal &value)
15 19 {
@@ -17,4 +21,15 QBarSet& QBarSet::operator << (const qreal &value)
17 21 return *this;
18 22 }
19 23
24 int QBarSet::count()
25 {
26 return mValues.count();
27 }
28
29 qreal QBarSet::valueAt(int index)
30 {
31 return mValues.at(index);
32 }
33
34
20 35 QTCOMMERCIALCHART_END_NAMESPACE
@@ -11,13 +11,15 public:
11 11 QBarSet();
12 12
13 13 void setName(QString name);
14 // void setValues(QList<qreal> &values);
15
16 // TODO:
14 QString name();
17 15 QBarSet& operator << (const qreal &value);
18 16
19 // TODO: Hide these from user of QBarSet. (but data model needs access to these)
20 public:
17 //TODO: What is the way to set a single value to n:th item? Is there need for such functionality?
18
19 int count();
20 qreal valueAt(int index);
21
22 private:
21 23
22 24 QString mName;
23 25 QList<qreal> mValues;
@@ -9,6 +9,16 StackedBarChartSeries::StackedBarChartSeries(QBarCategory &category, QObject *pa
9 9 {
10 10 }
11 11
12 void StackedBarChartSeries::addBarSet(QBarSet &set)
13 {
14 BarChartSeriesBase::addBarSet(set);
15 }
16
17 void StackedBarChartSeries::removeBarSet(QBarSet &set)
18 {
19 BarChartSeriesBase::removeBarSet(set);
20 }
21
12 22 #include "moc_stackedbarchartseries.cpp"
13 23
14 24 QTCOMMERCIALCHART_END_NAMESPACE
@@ -18,6 +18,9 public:
18 18 // from QChartSeries
19 19 virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeStackedBar; }
20 20
21 void addBarSet(QBarSet &set);
22 void removeBarSet(QBarSet &set);
23
21 24 public Q_SLOTS:
22 25
23 26 private:
@@ -16,12 +16,12 void StackedBarGroup::layoutChanged()
16 16 // qDebug() << "StackedBarGroup::layoutChanged";
17 17 // Scale bars to new layout
18 18 // Layout for bars:
19 if (mModel.countRows() <= 0) {
19 if (mModel.countSets() <= 0) {
20 20 // Nothing to do.
21 21 return;
22 22 }
23 23
24 if (mModel.countColumns() == 0) {
24 if (mModel.countCategories() == 0) {
25 25 // Nothing to do
26 26 return;
27 27 }
@@ -34,20 +34,20 void StackedBarGroup::layoutChanged()
34 34 // TODO: better way to auto-layout
35 35 // Use reals for accurancy (we might get some compiler warnings... :)
36 36 // TODO: use temp variable for column count...
37 qreal maxSum = mModel.maxColumnSum();
37 qreal maxSum = mModel.maxCategorySum();
38 38 qreal h = mHeight;
39 39 qreal scale = (h / maxSum);
40 40
41 41 int itemIndex(0);
42 42 qreal tW = mWidth;
43 qreal tC = mModel.countColumns() + 1;
43 qreal tC = mModel.countCategories() + 1;
44 44 qreal xStep = (tW/tC);
45 45 qreal xPos = ((tW/tC) - mBarDefaultWidth / 2);
46 int labelIndex = mModel.countRows() * mModel.countColumns();
46 int labelIndex = mModel.countSets() * mModel.countCategories();
47 47
48 for (int column = 0; column < mModel.countColumns(); column++) {
48 for (int column = 0; column < mModel.countCategories(); column++) {
49 49 qreal yPos = h;
50 for (int row=0; row < mModel.countRows(); row++) {
50 for (int row=0; row < mModel.countSets(); row++) {
51 51 qreal barHeight = mModel.valueAt(row, column) * scale;
52 52 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
53 53
@@ -69,7 +69,7 void StackedBarGroup::layoutChanged()
69 69 // Position separators
70 70 int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these?
71 71 xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left.
72 for (int s=0; s < mModel.countColumns() - 1; s++) {
72 for (int s=0; s < mModel.countCategories() - 1; s++) {
73 73 Separator* sep = reinterpret_cast<Separator*> (childItems().at(separatorIndex));
74 74 sep->setPos(xPos,0);
75 75 sep->setSize(QSizeF(1,mHeight));
@@ -3,6 +3,8
3 3 #include "qchartseries.h"
4 4 #include "qpieseries.h"
5 5 #include <qlinechartseries.h>
6 #include <qbarset.h>
7 #include <qbarcategory.h>
6 8 #include <barchartseries.h>
7 9 #include <stackedbarchartseries.h>
8 10 #include <percentbarchartseries.h>
@@ -178,11 +180,11 void MainWidget::addSeries(QString series, QString data)
178 180 QList<qreal> x;
179 181 QList<qreal> y;
180 182
181 QList<qreal> data0;
182 QList<qreal> data1;
183 QList<qreal> data2;
184 QList<qreal> data3;
185 QList<qreal> data4;
183 QBarSet set0;
184 QBarSet set1;
185 QBarSet set2;
186 QBarSet set3;
187 QBarSet set4;
186 188
187 189 if (data == "linear") {
188 190 for (int i = 0; i < 20; i++) {
@@ -210,12 +212,12 void MainWidget::addSeries(QString series, QString data)
210 212 y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
211 213 }
212 214 } else if (data == "Table, 5 series"){
213 // Create some test data to chart
214 data0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 5;
215 data1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4;
216 data2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3;
217 data3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2;
218 data4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1;
215 // Create some test data to chart
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;
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;
220 set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
219 221 } else {
220 222 // TODO: check if data has a valid file name
221 223 Q_ASSERT(false);
@@ -245,41 +247,50 void MainWidget::addSeries(QString series, QString data)
245 247 newSeries = series0;
246 248 } else if (series == "Bar") {
247 249 qDebug() << "Bar chart series";
248 BarChartSeries* series0 = new BarChartSeries(this);
249 series0->addData(data0);
250 series0->addData(data1);
251 series0->addData(data2);
252 series0->addData(data3);
253 series0->addData(data4);
254 QList<QString> labels;
255 labels << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec";
256 series0->setLabels(labels);
250
251 QBarCategory category;
252 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
253
254 BarChartSeries* series0 = new BarChartSeries(category, this);
255
256 series0->addBarSet(set0);
257 series0->addBarSet(set1);
258 series0->addBarSet(set2);
259 series0->addBarSet(set3);
260 series0->addBarSet(set4);
261
257 262 m_chartWidget->addSeries(series0);
258 263 newSeries = series0;
259 264 } else if (series == "StackedBar") {
260 qDebug() << "Bar chart series";
261 StackedBarChartSeries* series0 = new StackedBarChartSeries(this);
262 series0->addData(data0);
263 series0->addData(data1);
264 series0->addData(data2);
265 series0->addData(data3);
266 series0->addData(data4);
267 QList<QString> labels;
268 labels << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec";
269 series0->setLabels(labels);
265 qDebug() << "Stacked bar chart series";
266
267 QBarCategory category;
268 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
269
270 StackedBarChartSeries* series0 = new StackedBarChartSeries(category, this);
271
272 series0->addBarSet(set0);
273 series0->addBarSet(set1);
274 series0->addBarSet(set2);
275 series0->addBarSet(set3);
276 series0->addBarSet(set4);
277
270 278 m_chartWidget->addSeries(series0);
271 279 newSeries = series0;
272 280 } else if (series == "PercentBar") {
273 qDebug() << "Bar chart series";
274 PercentBarChartSeries* series0 = new PercentBarChartSeries(this);
275 series0->addData(data0);
276 series0->addData(data1);
277 series0->addData(data2);
278 series0->addData(data3);
279 series0->addData(data4);
280 QList<QString> labels;
281 labels << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec";
282 series0->setLabels(labels);
281 qDebug() << "Percent bar chart series";
282
283 QBarCategory category;
284 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
285
286 PercentBarChartSeries* series0 = new PercentBarChartSeries(category, this);
287
288 series0->addBarSet(set0);
289 series0->addBarSet(set1);
290 series0->addBarSet(set2);
291 series0->addBarSet(set3);
292 series0->addBarSet(set4);
293
283 294 m_chartWidget->addSeries(series0);
284 295 newSeries = series0;
285 296 } else {
General Comments 0
You need to be logged in to leave comments. Login now