From d4b8c60ed973857f8de73836645d13b63a49982b 2012-02-14 08:48:39 From: sauimone Date: 2012-02-14 08:48:39 Subject: [PATCH] Barset and barcategory implememtation. Updated test application --- diff --git a/example/barchart/main.cpp b/example/barchart/main.cpp index 467c985..2a0dbea 100644 --- a/example/barchart/main.cpp +++ b/example/barchart/main.cpp @@ -14,7 +14,7 @@ int main(int argc, char *argv[]) QMainWindow window; QBarCategory category; - category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec"; + category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; BarChartSeries* series0 = new BarChartSeries(category); diff --git a/example/percentbarchart/main.cpp b/example/percentbarchart/main.cpp index e899190..02e2080 100644 --- a/example/percentbarchart/main.cpp +++ b/example/percentbarchart/main.cpp @@ -14,7 +14,7 @@ int main(int argc, char *argv[]) QMainWindow window; QBarCategory category; - category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec"; + category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; PercentBarChartSeries* series0 = new PercentBarChartSeries(category); diff --git a/example/stackedbarchart/main.cpp b/example/stackedbarchart/main.cpp index 95e57c6..75107a7 100644 --- a/example/stackedbarchart/main.cpp +++ b/example/stackedbarchart/main.cpp @@ -14,7 +14,7 @@ int main(int argc, char *argv[]) QMainWindow window; QBarCategory category; - category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec"; + category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; StackedBarChartSeries* series0 = new StackedBarChartSeries(category); diff --git a/src/barchart/barchartmodel.cpp b/src/barchart/barchartmodel.cpp index 17e7fff..5b3183a 100644 --- a/src/barchart/barchartmodel.cpp +++ b/src/barchart/barchartmodel.cpp @@ -9,67 +9,37 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE BarChartModel::BarChartModel(QBarCategory &category, QObject *parent) : QObject(parent) - ,mRunningId(1) ,mCategory(category) { } -BarChartModel::~BarChartModel() +QBarCategory& BarChartModel::category() { -// qDebug() << "BarChartModel::~BarChartModel"; - foreach (DataContainer* c, mDataModel) { - delete c; - } -} - -int BarChartModel::addData(QList data) -{ -// qDebug() << "BarChartModel::addData" << data.count(); - DataContainer* c = new DataContainer(data,mRunningId); - mDataModel.append(c); - mRunningId++; - emit modelUpdated(); - return mRunningId-1; -} - -void BarChartModel::removeData(int id) -{ -// qDebug() << "BarChartModel::removeData"; - foreach(DataContainer* c, mDataModel) { - if (c->mId == id) { - mDataModel.removeOne(c); - delete c; - } - } - emit modelUpdated(); + return mCategory; } void BarChartModel::addBarSet(QBarSet &set) { - DataContainer* c = new DataContainer(set.mValues,mRunningId); - mDataModel.append(c); - mRunningId++; + mDataModel.append(&set); } void BarChartModel::removeBarSet(QBarSet &set) { - // TODO: + mDataModel.removeOne(&set); } -int BarChartModel::countRows() +int BarChartModel::countSets() { -// qDebug() << "BarChartModel::countRows"; return mDataModel.count(); } -int BarChartModel::countColumns() +int BarChartModel::countCategories() { -// qDebug() << "BarChartModel::countColumns"; int count(0); for (int i=0; icountColumns(); + int temp = mDataModel.at(i)->count(); if (temp > count) { count = temp; } @@ -79,21 +49,19 @@ int BarChartModel::countColumns() int BarChartModel::countTotalItems() { -// qDebug() << "BarChartModel::countTotalItems"; - int total = mDataModel.count() * countColumns(); + int total = mDataModel.count() * countCategories(); return total; } qreal BarChartModel::min() { - // qDebug() << "BarChartModel::min"; Q_ASSERT(mDataModel.count() > 0); // TODO: make min and max members and update them when data changes. // This is slower since they are checked every time, even if data is same since previous call. qreal min = INT_MAX; for (int i=0; i countColumns(); + int itemCount = mDataModel.at(i)->count(); for (int j=0; jvalueAt(j); if (temp < min) { @@ -106,7 +74,6 @@ qreal BarChartModel::min() qreal BarChartModel::max() { -// qDebug() << "BarChartModel::max"; Q_ASSERT(mDataModel.count() > 0); // TODO: make min and max members and update them when data changes. @@ -114,7 +81,7 @@ qreal BarChartModel::max() qreal max = INT_MIN; for (int i=0; i countColumns(); + int itemCount = mDataModel.at(i)->count(); for (int j=0; jvalueAt(j); if (temp > max) { @@ -126,43 +93,39 @@ qreal BarChartModel::max() return max; } -qreal BarChartModel::valueAt(int series, int item) +qreal BarChartModel::valueAt(int set, int category) { -// qDebug() << "BarChartModel::valueAt" << series << item; - if ((series < 0) || (series >= mDataModel.count())) { - // No series, no value. + if ((set < 0) || (set >= mDataModel.count())) { + // No set, no value. return 0; - } else if ((item < 0) || (item >= mDataModel.at(series)->countColumns())) { - // No item, no value. + } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { + // No category, no value. return 0; } -// qDebug() << "ValueAt" << series << item << "=" << mDataModel.at(series)->valueAt(item); - return mDataModel.at(series)->valueAt(item); + return mDataModel.at(set)->valueAt(category); } -qreal BarChartModel::columnSum(int column) +qreal BarChartModel::categorySum(int column) { -// qDebug() << "BarChartModel::columnSum"; - int sum(0); + qreal sum(0); int count = mDataModel.count(); // Count rows for (int row = 0; row < count; row++) { - if (column < mDataModel.at(row)->countColumns()) { + if (column < mDataModel.at(row)->count()) { sum += mDataModel.at(row)->valueAt(column); } } return sum; } -qreal BarChartModel::maxColumnSum() +qreal BarChartModel::maxCategorySum() { -// qDebug() << "BarChartModel::maxColumnSum"; - int max = INT_MIN; - int count = countColumns(); + qreal max = INT_MIN; + int count = countCategories(); for (int col=0; col max) { max = sum; } diff --git a/src/barchart/barchartmodel_p.h b/src/barchart/barchartmodel_p.h index e210575..34bd707 100644 --- a/src/barchart/barchartmodel_p.h +++ b/src/barchart/barchartmodel_p.h @@ -17,25 +17,21 @@ class BarChartModel : public QObject //, public QAbstractItemModel Q_OBJECT public: explicit BarChartModel(QBarCategory &category, QObject *parent = 0); - ~BarChartModel(); - - // TODO: remove these after add and remove QBarSet works. - int addData(QList data); - void removeData(int id); + QBarCategory& category(); void addBarSet(QBarSet &set); void removeBarSet(QBarSet &set); - int countRows(); // Number of series in model - int countColumns(); // Maximum number of items in series - int countTotalItems(); // Total items in all series. Includes empty items. + int countSets(); // Number of sets in model + int countCategories(); // Number of categories + int countTotalItems(); // Total items in all sets. Includes empty items. - qreal max(); // Maximum value of all series - qreal min(); // Minimum value of all series - qreal valueAt(int series, int item); + qreal max(); // Maximum value of all sets + qreal min(); // Minimum value of all sets + qreal valueAt(int set, int category); - qreal columnSum(int column); - qreal maxColumnSum(); // returns maximum sum of items in all columns. + qreal categorySum(int column); + qreal maxCategorySum(); // returns maximum sum of sets in all categories. signals: void modelUpdated(); @@ -44,22 +40,7 @@ public slots: private: - // Little helper class. - class DataContainer { - public: - DataContainer(QList data, int id) : mId(id), mData(data) {} - int countColumns() { return mData.count(); } - qreal valueAt(int item) { return mData.at(item); } - - int mId; // TODO: Is this needed? - private: - QList mData; - }; - - // Owned. N series. each has a list of values. - QList mDataModel; - int mRunningId; - int mMaxColumns; // longest series in datamodel + QList mDataModel; QBarCategory& mCategory; }; diff --git a/src/barchart/barchartseries.cpp b/src/barchart/barchartseries.cpp index dfe68f1..91bcd36 100644 --- a/src/barchart/barchartseries.cpp +++ b/src/barchart/barchartseries.cpp @@ -8,6 +8,16 @@ BarChartSeries::BarChartSeries(QBarCategory &category, QObject *parent) { } +void BarChartSeries::addBarSet(QBarSet &set) +{ + BarChartSeriesBase::addBarSet(set); +} + +void BarChartSeries::removeBarSet(QBarSet &set) +{ + BarChartSeriesBase::removeBarSet(set); +} + #include "moc_barchartseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/barchartseries.h b/src/barchart/barchartseries.h index e842e44..b1dabb2 100644 --- a/src/barchart/barchartseries.h +++ b/src/barchart/barchartseries.h @@ -19,6 +19,11 @@ public: // from BarChartSeriesBase virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; } + void addBarSet(QBarSet &set); + void removeBarSet(QBarSet &set); + +public Q_SLOTS: + private: BarGroup* mBarGroup; diff --git a/src/barchart/barchartseriesbase.cpp b/src/barchart/barchartseriesbase.cpp index 6715034..286c31f 100644 --- a/src/barchart/barchartseriesbase.cpp +++ b/src/barchart/barchartseriesbase.cpp @@ -4,6 +4,7 @@ #include "bargroup.h" #include "barchartmodel_p.h" #include "qbarset.h" +#include "qbarcategory.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -11,21 +12,7 @@ BarChartSeriesBase::BarChartSeriesBase(QBarCategory &category, QObject *parent) : QChartSeries(parent) ,mModel(new BarChartModel(category, this)) { -} - -int BarChartSeriesBase::addData(QList data) -{ - return mModel->addData(data); -} - -void BarChartSeriesBase::removeData(int id) -{ - mModel->removeData(id); -} - -void BarChartSeriesBase::setLabels(QList labels) -{ - mLabels = labels; + mLabels.append(category.items()); } void BarChartSeriesBase::addBarSet(QBarSet &set) @@ -50,7 +37,7 @@ qreal BarChartSeriesBase::max() int BarChartSeriesBase::countColumns() { - return mModel->countColumns(); + return mModel->countCategories(); } qreal BarChartSeriesBase::valueAt(int series, int item) @@ -62,7 +49,7 @@ qreal BarChartSeriesBase::valueAt(int series, int item) qreal BarChartSeriesBase::maxColumnSum() { // qDebug() << "BarChartSeriesBase::maxColumnSum" << mModel->maxColumnSum(); - return mModel->maxColumnSum(); + return mModel->maxCategorySum(); } BarChartModel& BarChartSeriesBase::model() diff --git a/src/barchart/barchartseriesbase.h b/src/barchart/barchartseriesbase.h index 91e269b..cf15a04 100644 --- a/src/barchart/barchartseriesbase.h +++ b/src/barchart/barchartseriesbase.h @@ -25,15 +25,12 @@ public: // from QChartSeries virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeInvalid; } - // TODO: These 3 will be removed. - int addData(QList data); - void removeData(int id); - void setLabels(QList labels); - - // TODO: Expose these to user in derived class instead of here? Common implementation for all bar charts, but not visible to user - void addBarSet(QBarSet &set); // Bob[1,5,6,2,15,4] first value goes to category 1 etc.. - void removeBarSet(QBarSet &set); // +protected: + // Used by derived series + void addBarSet(QBarSet &set); + void removeBarSet(QBarSet &set); +public: // These shouldn't be visible to chart series user. However, ChartDataSet needs to access them, and friends are evil. qreal min(); qreal max(); diff --git a/src/barchart/bargroup.cpp b/src/barchart/bargroup.cpp index d48f1d1..50fd1c4 100644 --- a/src/barchart/bargroup.cpp +++ b/src/barchart/bargroup.cpp @@ -16,7 +16,7 @@ void BarGroup::layoutChanged() // qDebug() << "BarGroup::layoutChanged"; // Scale bars to new layout // Layout for bars: - if (mModel.countRows() <= 0) { + if (mModel.countSets() <= 0) { return; } @@ -27,8 +27,8 @@ void BarGroup::layoutChanged() // TODO: better way to auto-layout? // Use reals for accurancy (we might get some compiler warnings... :) - int itemCount = mModel.countColumns(); - int seriesCount = mModel.countRows(); + int itemCount = mModel.countCategories(); + int seriesCount = mModel.countSets(); qreal tW = mWidth; qreal tH = mHeight; diff --git a/src/barchart/bargroupbase.cpp b/src/barchart/bargroupbase.cpp index 0f88b39..c91da66 100644 --- a/src/barchart/bargroupbase.cpp +++ b/src/barchart/bargroupbase.cpp @@ -80,7 +80,7 @@ void BarGroupBase::dataChanged() } // TODO: labels from series. This creates just some example labels - int count = mModel.countColumns(); // mSeries.countColumns(); + int count = mModel.countCategories(); // mSeries.countColumns(); for (int i=0; isetColor(QColor(255,0,0,255)); // TODO: color for separations from theme diff --git a/src/barchart/percentbarchartseries.cpp b/src/barchart/percentbarchartseries.cpp index 553f7d4..16bdf62 100644 --- a/src/barchart/percentbarchartseries.cpp +++ b/src/barchart/percentbarchartseries.cpp @@ -11,6 +11,16 @@ PercentBarChartSeries::PercentBarChartSeries(QBarCategory &category, QObject *pa { } +void PercentBarChartSeries::addBarSet(QBarSet &set) +{ + BarChartSeriesBase::addBarSet(set); +} + +void PercentBarChartSeries::removeBarSet(QBarSet &set) +{ + BarChartSeriesBase::removeBarSet(set); +} + #include "moc_percentbarchartseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/percentbarchartseries.h b/src/barchart/percentbarchartseries.h index ff75a49..b15a2f4 100644 --- a/src/barchart/percentbarchartseries.h +++ b/src/barchart/percentbarchartseries.h @@ -18,6 +18,9 @@ public: // from BarChartSeriesBase virtual QChartSeriesType type() const { return QChartSeries::SeriesTypePercentBar; } + void addBarSet(QBarSet &set); + void removeBarSet(QBarSet &set); + public Q_SLOTS: private: diff --git a/src/barchart/percentbargroup.cpp b/src/barchart/percentbargroup.cpp index 8ff5af9..b4a3d78 100644 --- a/src/barchart/percentbargroup.cpp +++ b/src/barchart/percentbargroup.cpp @@ -16,7 +16,7 @@ void PercentBarGroup::layoutChanged() { // Scale bars to new layout // Layout for bars: - if (mModel.countRows() <= 0) { + if (mModel.countSets() <= 0) { // Nothing to do. return; } @@ -28,20 +28,20 @@ void PercentBarGroup::layoutChanged() // TODO: better way to auto-layout // Use reals for accurancy (we might get some compiler warnings... :) - int count = mModel.countColumns(); + int count = mModel.countCategories(); int itemIndex(0); qreal tW = mWidth; qreal tC = count+1; qreal xStep = (tW/tC); qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); - int labelIndex = mModel.countColumns() * mModel.countRows(); + int labelIndex = mModel.countCategories() * mModel.countSets(); - for (int column = 0; column < mModel.countColumns(); column++) { - qreal colSum = mModel.columnSum(column); + for (int column = 0; column < mModel.countCategories(); column++) { + qreal colSum = mModel.categorySum(column); qreal h = mHeight; qreal scale = (h / colSum); qreal yPos = h; - for (int row=0; row < mModel.countRows(); row++) { + for (int row=0; row < mModel.countSets(); row++) { qreal barHeight = mModel.valueAt(row, column) * scale; Bar* bar = reinterpret_cast (childItems().at(itemIndex)); @@ -63,7 +63,7 @@ void PercentBarGroup::layoutChanged() // Position separators int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these? xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. - for (int s=0; s < mModel.countColumns() - 1; s++) { + for (int s=0; s < mModel.countCategories() - 1; s++) { Separator* sep = reinterpret_cast (childItems().at(separatorIndex)); sep->setPos(xPos,0); sep->setSize(QSizeF(1,mHeight)); diff --git a/src/barchart/qbarset.cpp b/src/barchart/qbarset.cpp index d5b285d..610225f 100644 --- a/src/barchart/qbarset.cpp +++ b/src/barchart/qbarset.cpp @@ -10,6 +10,10 @@ void QBarSet::setName(QString name) { mName = name; } +QString QBarSet::name() +{ + return mName; +} QBarSet& QBarSet::operator << (const qreal &value) { @@ -17,4 +21,15 @@ QBarSet& QBarSet::operator << (const qreal &value) return *this; } +int QBarSet::count() +{ + return mValues.count(); +} + +qreal QBarSet::valueAt(int index) +{ + return mValues.at(index); +} + + QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/qbarset.h b/src/barchart/qbarset.h index 69f8366..87a4681 100644 --- a/src/barchart/qbarset.h +++ b/src/barchart/qbarset.h @@ -11,13 +11,15 @@ public: QBarSet(); void setName(QString name); -// void setValues(QList &values); - - // TODO: + QString name(); QBarSet& operator << (const qreal &value); - // TODO: Hide these from user of QBarSet. (but data model needs access to these) -public: + //TODO: What is the way to set a single value to n:th item? Is there need for such functionality? + + int count(); + qreal valueAt(int index); + +private: QString mName; QList mValues; diff --git a/src/barchart/stackedbarchartseries.cpp b/src/barchart/stackedbarchartseries.cpp index 92bf389..026966f 100644 --- a/src/barchart/stackedbarchartseries.cpp +++ b/src/barchart/stackedbarchartseries.cpp @@ -9,6 +9,16 @@ StackedBarChartSeries::StackedBarChartSeries(QBarCategory &category, QObject *pa { } +void StackedBarChartSeries::addBarSet(QBarSet &set) +{ + BarChartSeriesBase::addBarSet(set); +} + +void StackedBarChartSeries::removeBarSet(QBarSet &set) +{ + BarChartSeriesBase::removeBarSet(set); +} + #include "moc_stackedbarchartseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/stackedbarchartseries.h b/src/barchart/stackedbarchartseries.h index 4e321a4..773efd9 100644 --- a/src/barchart/stackedbarchartseries.h +++ b/src/barchart/stackedbarchartseries.h @@ -18,6 +18,9 @@ public: // from QChartSeries virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeStackedBar; } + void addBarSet(QBarSet &set); + void removeBarSet(QBarSet &set); + public Q_SLOTS: private: diff --git a/src/barchart/stackedbargroup.cpp b/src/barchart/stackedbargroup.cpp index c02c1c2..7107d7b 100644 --- a/src/barchart/stackedbargroup.cpp +++ b/src/barchart/stackedbargroup.cpp @@ -16,12 +16,12 @@ void StackedBarGroup::layoutChanged() // qDebug() << "StackedBarGroup::layoutChanged"; // Scale bars to new layout // Layout for bars: - if (mModel.countRows() <= 0) { + if (mModel.countSets() <= 0) { // Nothing to do. return; } - if (mModel.countColumns() == 0) { + if (mModel.countCategories() == 0) { // Nothing to do return; } @@ -34,20 +34,20 @@ void StackedBarGroup::layoutChanged() // TODO: better way to auto-layout // Use reals for accurancy (we might get some compiler warnings... :) // TODO: use temp variable for column count... - qreal maxSum = mModel.maxColumnSum(); + qreal maxSum = mModel.maxCategorySum(); qreal h = mHeight; qreal scale = (h / maxSum); int itemIndex(0); qreal tW = mWidth; - qreal tC = mModel.countColumns() + 1; + qreal tC = mModel.countCategories() + 1; qreal xStep = (tW/tC); qreal xPos = ((tW/tC) - mBarDefaultWidth / 2); - int labelIndex = mModel.countRows() * mModel.countColumns(); + int labelIndex = mModel.countSets() * mModel.countCategories(); - for (int column = 0; column < mModel.countColumns(); column++) { + for (int column = 0; column < mModel.countCategories(); column++) { qreal yPos = h; - for (int row=0; row < mModel.countRows(); row++) { + for (int row=0; row < mModel.countSets(); row++) { qreal barHeight = mModel.valueAt(row, column) * scale; Bar* bar = reinterpret_cast (childItems().at(itemIndex)); @@ -69,7 +69,7 @@ void StackedBarGroup::layoutChanged() // Position separators int separatorIndex = labelIndex; // Separators are after labels in childItems(). TODO: better way to store these? xPos = xStep + xStep/2; // Initial position is between first and second group. ie one and half steps from left. - for (int s=0; s < mModel.countColumns() - 1; s++) { + for (int s=0; s < mModel.countCategories() - 1; s++) { Separator* sep = reinterpret_cast (childItems().at(separatorIndex)); sep->setPos(xPos,0); sep->setSize(QSizeF(1,mHeight)); diff --git a/test/chartwidgettest/mainwidget.cpp b/test/chartwidgettest/mainwidget.cpp index 92b3097..fb498c6 100644 --- a/test/chartwidgettest/mainwidget.cpp +++ b/test/chartwidgettest/mainwidget.cpp @@ -3,6 +3,8 @@ #include "qchartseries.h" #include "qpieseries.h" #include +#include +#include #include #include #include @@ -178,11 +180,11 @@ void MainWidget::addSeries(QString series, QString data) QList x; QList y; - QList data0; - QList data1; - QList data2; - QList data3; - QList data4; + QBarSet set0; + QBarSet set1; + QBarSet set2; + QBarSet set3; + QBarSet set4; if (data == "linear") { for (int i = 0; i < 20; i++) { @@ -210,12 +212,12 @@ void MainWidget::addSeries(QString series, QString data) y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); } } else if (data == "Table, 5 series"){ - // Create some test data to chart - data0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 5; - data1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4; - data2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3; - data3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2; - data4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1; + // Create some test data to chart + set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; + set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; + set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; + set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; + set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; } else { // TODO: check if data has a valid file name Q_ASSERT(false); @@ -245,41 +247,50 @@ void MainWidget::addSeries(QString series, QString data) newSeries = series0; } else if (series == "Bar") { qDebug() << "Bar chart series"; - BarChartSeries* series0 = new BarChartSeries(this); - series0->addData(data0); - series0->addData(data1); - series0->addData(data2); - series0->addData(data3); - series0->addData(data4); - QList labels; - labels << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec"; - series0->setLabels(labels); + + QBarCategory category; + category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + + BarChartSeries* series0 = new BarChartSeries(category, this); + + series0->addBarSet(set0); + series0->addBarSet(set1); + series0->addBarSet(set2); + series0->addBarSet(set3); + series0->addBarSet(set4); + m_chartWidget->addSeries(series0); newSeries = series0; } else if (series == "StackedBar") { - qDebug() << "Bar chart series"; - StackedBarChartSeries* series0 = new StackedBarChartSeries(this); - series0->addData(data0); - series0->addData(data1); - series0->addData(data2); - series0->addData(data3); - series0->addData(data4); - QList labels; - labels << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec"; - series0->setLabels(labels); + qDebug() << "Stacked bar chart series"; + + QBarCategory category; + category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + + StackedBarChartSeries* series0 = new StackedBarChartSeries(category, this); + + series0->addBarSet(set0); + series0->addBarSet(set1); + series0->addBarSet(set2); + series0->addBarSet(set3); + series0->addBarSet(set4); + m_chartWidget->addSeries(series0); newSeries = series0; } else if (series == "PercentBar") { - qDebug() << "Bar chart series"; - PercentBarChartSeries* series0 = new PercentBarChartSeries(this); - series0->addData(data0); - series0->addData(data1); - series0->addData(data2); - series0->addData(data3); - series0->addData(data4); - QList labels; - labels << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec"; - series0->setLabels(labels); + qDebug() << "Percent bar chart series"; + + QBarCategory category; + category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + + PercentBarChartSeries* series0 = new PercentBarChartSeries(category, this); + + series0->addBarSet(set0); + series0->addBarSet(set1); + series0->addBarSet(set2); + series0->addBarSet(set3); + series0->addBarSet(set4); + m_chartWidget->addSeries(series0); newSeries = series0; } else {