From 5bd6f6e4373bbbf475dbe8e0dc34e0c9d7c986b8 2012-02-14 14:02:35 From: sauimone Date: 2012-02-14 14:02:35 Subject: [PATCH] fixed bug in category implementation. model now owns the category and sets --- diff --git a/example/barchart/main.cpp b/example/barchart/main.cpp index 68c6034..4a82eeb 100644 --- a/example/barchart/main.cpp +++ b/example/barchart/main.cpp @@ -13,29 +13,29 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); QMainWindow window; - QBarCategory category; - category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + QBarCategory *category = new QBarCategory; + *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; BarChartSeries* series0 = new BarChartSeries(category); - QBarSet barSet0; - QBarSet barSet1; - QBarSet barSet2; - QBarSet barSet3; - QBarSet barSet4; + QBarSet *set0 = new QBarSet; + QBarSet *set1 = new QBarSet; + QBarSet *set2 = new QBarSet; + QBarSet *set3 = new QBarSet; + QBarSet *set4 = new QBarSet; // Create some test data to chart - barSet0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; - barSet1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; - barSet2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; - barSet3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; - barSet4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; - - series0->addBarSet(barSet0); - series0->addBarSet(barSet1); - series0->addBarSet(barSet2); - series0->addBarSet(barSet3); - series0->addBarSet(barSet4); + *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; + + series0->addBarSet(set0); + series0->addBarSet(set1); + series0->addBarSet(set2); + series0->addBarSet(set3); + series0->addBarSet(set4); ChartWidget* chartWidget = new ChartWidget(&window); chartWidget->addSeries(series0); diff --git a/example/percentbarchart/main.cpp b/example/percentbarchart/main.cpp index 588e8b8..eb83064 100644 --- a/example/percentbarchart/main.cpp +++ b/example/percentbarchart/main.cpp @@ -13,29 +13,29 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); QMainWindow window; - QBarCategory category; - category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + QBarCategory *category = new QBarCategory; + *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; PercentBarChartSeries* series0 = new PercentBarChartSeries(category); - QBarSet barSet0; - QBarSet barSet1; - QBarSet barSet2; - QBarSet barSet3; - QBarSet barSet4; + QBarSet *set0 = new QBarSet; + QBarSet *set1 = new QBarSet; + QBarSet *set2 = new QBarSet; + QBarSet *set3 = new QBarSet; + QBarSet *set4 = new QBarSet; // Create some test data to chart - barSet0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; - barSet1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; - barSet2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; - barSet3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; - barSet4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; - - series0->addBarSet(barSet0); - series0->addBarSet(barSet1); - series0->addBarSet(barSet2); - series0->addBarSet(barSet3); - series0->addBarSet(barSet4); + *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; + + series0->addBarSet(set0); + series0->addBarSet(set1); + series0->addBarSet(set2); + series0->addBarSet(set3); + series0->addBarSet(set4); ChartWidget* chartWidget = new ChartWidget(&window); chartWidget->addSeries(series0); diff --git a/example/stackedbarchart/main.cpp b/example/stackedbarchart/main.cpp index 9d30f5f..a03f154 100644 --- a/example/stackedbarchart/main.cpp +++ b/example/stackedbarchart/main.cpp @@ -13,29 +13,29 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); QMainWindow window; - QBarCategory category; - category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + QBarCategory *category = new QBarCategory; + *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; StackedBarChartSeries* series0 = new StackedBarChartSeries(category); - QBarSet barSet0; - QBarSet barSet1; - QBarSet barSet2; - QBarSet barSet3; - QBarSet barSet4; + QBarSet *set0 = new QBarSet; + QBarSet *set1 = new QBarSet; + QBarSet *set2 = new QBarSet; + QBarSet *set3 = new QBarSet; + QBarSet *set4 = new QBarSet; // Create some test data to chart - barSet0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; - barSet1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; - barSet2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; - barSet3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; - barSet4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; - - series0->addBarSet(barSet0); - series0->addBarSet(barSet1); - series0->addBarSet(barSet2); - series0->addBarSet(barSet3); - series0->addBarSet(barSet4); + *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; + + series0->addBarSet(set0); + series0->addBarSet(set1); + series0->addBarSet(set2); + series0->addBarSet(set3); + series0->addBarSet(set4); ChartWidget* chartWidget = new ChartWidget(&window); chartWidget->addSeries(series0); diff --git a/src/barchart/barchartmodel.cpp b/src/barchart/barchartmodel.cpp index 010274f..2e430d6 100644 --- a/src/barchart/barchartmodel.cpp +++ b/src/barchart/barchartmodel.cpp @@ -7,27 +7,35 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -BarChartModel::BarChartModel(QBarCategory &category, QObject *parent) : +BarChartModel::BarChartModel(QBarCategory *category, QObject *parent) : QObject(parent) ,mCategory(category) { } -QBarCategory& BarChartModel::category() +BarChartModel::~BarChartModel() { - return mCategory; + delete mCategory; } -void BarChartModel::addBarSet(QBarSet &set) + +QBarCategory& BarChartModel::category() { - mDataModel.append(&set); + return *mCategory; } -void BarChartModel::removeBarSet(QBarSet &set) +void BarChartModel::addBarSet(QBarSet *set) { - mDataModel.removeOne(&set); + mDataModel.append(set); } +void BarChartModel::removeBarSet(QBarSet *set) +{ + if (mDataModel.contains(set)) { + mDataModel.removeOne(set); + delete set; + } +} int BarChartModel::countSets() { @@ -135,7 +143,7 @@ qreal BarChartModel::maxCategorySum() QString BarChartModel::label(int category) { - return mCategory.label(category); + return mCategory->label(category); } #include "moc_barchartmodel_p.cpp" diff --git a/src/barchart/barchartmodel_p.h b/src/barchart/barchartmodel_p.h index a0498e4..0f03f73 100644 --- a/src/barchart/barchartmodel_p.h +++ b/src/barchart/barchartmodel_p.h @@ -16,11 +16,12 @@ class BarChartModel : public QObject //, public QAbstractItemModel { Q_OBJECT public: - explicit BarChartModel(QBarCategory &category, QObject *parent = 0); + explicit BarChartModel(QBarCategory *category, QObject *parent = 0); + ~BarChartModel(); QBarCategory& category(); - void addBarSet(QBarSet &set); - void removeBarSet(QBarSet &set); + void addBarSet(QBarSet *set); + void removeBarSet(QBarSet *set); int countSets(); // Number of sets in model int countCategories(); // Number of categories @@ -43,7 +44,7 @@ public slots: private: QList mDataModel; - QBarCategory& mCategory; + QBarCategory* mCategory; // Owned }; diff --git a/src/barchart/barchartseries.cpp b/src/barchart/barchartseries.cpp index 3229856..7b8f359 100644 --- a/src/barchart/barchartseries.cpp +++ b/src/barchart/barchartseries.cpp @@ -7,18 +7,18 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -BarChartSeries::BarChartSeries(QBarCategory &category, QObject *parent) +BarChartSeries::BarChartSeries(QBarCategory *category, QObject *parent) : QChartSeries(parent) ,mModel(new BarChartModel(category, this)) { } -void BarChartSeries::addBarSet(QBarSet &set) +void BarChartSeries::addBarSet(QBarSet *set) { mModel->addBarSet(set); } -void BarChartSeries::removeBarSet(QBarSet &set) +void BarChartSeries::removeBarSet(QBarSet *set) { mModel->removeBarSet(set); } diff --git a/src/barchart/barchartseries.h b/src/barchart/barchartseries.h index 296f003..f0f1aa6 100644 --- a/src/barchart/barchartseries.h +++ b/src/barchart/barchartseries.h @@ -17,14 +17,18 @@ class QTCOMMERCIALCHART_EXPORT BarChartSeries : public QChartSeries { Q_OBJECT public: - BarChartSeries(QBarCategory &category, QObject* parent=0); + BarChartSeries(QBarCategory *category, QObject* parent=0); - // from BarChartSeriesBase virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeBar; } - void addBarSet(QBarSet &set); - void removeBarSet(QBarSet &set); + void addBarSet(QBarSet *set); // Takes ownership + void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned. + //TODO: + //QList legend(); // Returns legend of series (ie. names of all sets in series) + + // TODO: Functions below this are not part of api and will be moved + // to private implementation, when we start using it (not part of api) int countCategories(); qreal min(); qreal max(); diff --git a/src/barchart/bargroup.cpp b/src/barchart/bargroup.cpp index 7fa5586..1222f23 100644 --- a/src/barchart/bargroup.cpp +++ b/src/barchart/bargroup.cpp @@ -8,7 +8,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE BarGroup::BarGroup(BarChartModel& model, QGraphicsItem *parent) : BarGroupBase(model,parent) { - mBarDefaultWidth = 10; + mBarDefaultWidth = 5; } void BarGroup::layoutChanged() @@ -17,6 +17,7 @@ void BarGroup::layoutChanged() // Scale bars to new layout // Layout for bars: if (mModel.countSets() <= 0) { + qDebug() << "No sets in model!"; return; } diff --git a/src/barchart/bargroupbase.cpp b/src/barchart/bargroupbase.cpp index 1feb3b2..2690fd5 100644 --- a/src/barchart/bargroupbase.cpp +++ b/src/barchart/bargroupbase.cpp @@ -13,7 +13,6 @@ BarGroupBase::BarGroupBase(BarChartModel& model, QGraphicsItem *parent) ,mLayoutDirty(true) ,mSeparatorsVisible(true) ,mModel(model) -// ,mSeries(series) { dataChanged(); } @@ -72,20 +71,20 @@ void BarGroupBase::dataChanged() } // Create new graphic items for bars - int totalItems = mModel.countTotalItems(); // mSeries.countTotalItems(); + int totalItems = mModel.countTotalItems(); for (int i=0; iset(mModel.label(i)); childItems().append(label); } - count = mModel.countCategories() - 1; // mSeries.countColumns() - 1; // There is one less separator than columns + count = mModel.countCategories() - 1; // There is one less separator than columns for (int i=0; isetColor(QColor(255,0,0,255)); // TODO: color for separations from theme @@ -100,14 +99,13 @@ void BarGroupBase::dataChanged() void BarGroupBase::handleModelChanged(int index) { - qDebug() << "BarGroupBase::handleModelChanged" << index; +// qDebug() << "BarGroupBase::handleModelChanged" << index; dataChanged(); } void BarGroupBase::handleDomainChanged(const Domain& domain) { // qDebug() << "BarGroupBase::handleDomainChanged"; - // TODO: Figure out the use case for this. // Affects the size of visible item, so layout is changed. // layoutChanged(); @@ -115,7 +113,6 @@ void BarGroupBase::handleDomainChanged(const Domain& domain) void BarGroupBase::handleGeometryChanged(const QRectF& rect) { -// qDebug() << "BarGroupBase::handleGeometryChanged"; mWidth = rect.width(); mHeight = rect.height(); layoutChanged(); diff --git a/src/barchart/percentbarchartseries.cpp b/src/barchart/percentbarchartseries.cpp index 666c83f..8edf70d 100644 --- a/src/barchart/percentbarchartseries.cpp +++ b/src/barchart/percentbarchartseries.cpp @@ -9,18 +9,18 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -PercentBarChartSeries::PercentBarChartSeries(QBarCategory &category, QObject *parent) +PercentBarChartSeries::PercentBarChartSeries(QBarCategory *category, QObject *parent) : QChartSeries(parent) ,mModel(new BarChartModel(category, this)) { } -void PercentBarChartSeries::addBarSet(QBarSet &set) +void PercentBarChartSeries::addBarSet(QBarSet *set) { mModel->addBarSet(set); } -void PercentBarChartSeries::removeBarSet(QBarSet &set) +void PercentBarChartSeries::removeBarSet(QBarSet *set) { mModel->removeBarSet(set); } diff --git a/src/barchart/percentbarchartseries.h b/src/barchart/percentbarchartseries.h index 8a17e92..3536946 100644 --- a/src/barchart/percentbarchartseries.h +++ b/src/barchart/percentbarchartseries.h @@ -16,14 +16,19 @@ class QTCOMMERCIALCHART_EXPORT PercentBarChartSeries : public QChartSeries { Q_OBJECT public: - PercentBarChartSeries(QBarCategory &category, QObject* parent=0); + PercentBarChartSeries(QBarCategory *category, QObject* parent=0); // from BarChartSeriesBase virtual QChartSeriesType type() const { return QChartSeries::SeriesTypePercentBar; } - void addBarSet(QBarSet &set); - void removeBarSet(QBarSet &set); + void addBarSet(QBarSet *set); // Takes ownership + void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned. + //TODO: + //QList legend(); // Returns legend of series (ie. names of all sets in series) + + // TODO: Functions below this are not part of api and will be moved + // to private implementation, when we start using it (not part of api) int countCategories(); qreal min(); qreal max(); diff --git a/src/barchart/percentbargroup.cpp b/src/barchart/percentbargroup.cpp index a2bdd04..1391089 100644 --- a/src/barchart/percentbargroup.cpp +++ b/src/barchart/percentbargroup.cpp @@ -14,9 +14,11 @@ PercentBarGroup::PercentBarGroup(BarChartModel& model, QGraphicsItem *parent) : void PercentBarGroup::layoutChanged() { +// qDebug() << "PercentBarGroup::layoutChanged"; // Scale bars to new layout // Layout for bars: if (mModel.countSets() <= 0) { + qDebug() << "No sets in model!"; // Nothing to do. return; } diff --git a/src/barchart/qbarcategory.cpp b/src/barchart/qbarcategory.cpp index 4389922..35cd71e 100644 --- a/src/barchart/qbarcategory.cpp +++ b/src/barchart/qbarcategory.cpp @@ -22,5 +22,6 @@ QString QBarCategory::label(int category) return mList.at(category); } - +// TODO?: +//#include "moc_qbarcategory.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/qbarcategory.h b/src/barchart/qbarcategory.h index 549ed14..f534265 100644 --- a/src/barchart/qbarcategory.h +++ b/src/barchart/qbarcategory.h @@ -5,8 +5,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -class QTCOMMERCIALCHART_EXPORT QBarCategory // TODO? : pubclic QObject +class QTCOMMERCIALCHART_EXPORT QBarCategory // TODO?: : public QObject { +// Q_OBJECT; public: QBarCategory(); diff --git a/src/barchart/qbarset.cpp b/src/barchart/qbarset.cpp index 610225f..727d838 100644 --- a/src/barchart/qbarset.cpp +++ b/src/barchart/qbarset.cpp @@ -31,5 +31,6 @@ qreal QBarSet::valueAt(int index) return mValues.at(index); } - +//TODO?: +//#include "moc_qbarset.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/qbarset.h b/src/barchart/qbarset.h index 87a4681..9541047 100644 --- a/src/barchart/qbarset.h +++ b/src/barchart/qbarset.h @@ -5,8 +5,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -class QTCOMMERCIALCHART_EXPORT QBarSet // : pubclic QObject // TODO: Need for this? +class QTCOMMERCIALCHART_EXPORT QBarSet // TODO? : public QObject { + //Q_OBJECT; public: QBarSet(); diff --git a/src/barchart/stackedbarchartseries.cpp b/src/barchart/stackedbarchartseries.cpp index 7233792..05986b4 100644 --- a/src/barchart/stackedbarchartseries.cpp +++ b/src/barchart/stackedbarchartseries.cpp @@ -7,18 +7,18 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -StackedBarChartSeries::StackedBarChartSeries(QBarCategory &category, QObject *parent) +StackedBarChartSeries::StackedBarChartSeries(QBarCategory *category, QObject *parent) : QChartSeries(parent) ,mModel(new BarChartModel(category, this)) { } -void StackedBarChartSeries::addBarSet(QBarSet &set) +void StackedBarChartSeries::addBarSet(QBarSet *set) { mModel->addBarSet(set); } -void StackedBarChartSeries::removeBarSet(QBarSet &set) +void StackedBarChartSeries::removeBarSet(QBarSet *set) { mModel->removeBarSet(set); } diff --git a/src/barchart/stackedbarchartseries.h b/src/barchart/stackedbarchartseries.h index 3344c16..c2f4d18 100644 --- a/src/barchart/stackedbarchartseries.h +++ b/src/barchart/stackedbarchartseries.h @@ -16,14 +16,19 @@ class QTCOMMERCIALCHART_EXPORT StackedBarChartSeries : public QChartSeries { Q_OBJECT public: - StackedBarChartSeries(QBarCategory &category, QObject* parent=0); + StackedBarChartSeries(QBarCategory *category, QObject* parent=0); // from QChartSeries virtual QChartSeriesType type() const { return QChartSeries::SeriesTypeStackedBar; } - void addBarSet(QBarSet &set); - void removeBarSet(QBarSet &set); + void addBarSet(QBarSet *set); // Takes ownership + void removeBarSet(QBarSet *set); // Also deletes the set, if set is owned. + //TODO: + //QList legend(); // Returns legend of series (ie. names of all sets in series) + + // TODO: Functions below this are not part of api and will be moved + // to private implementation, when we start using it (not part of api) int countCategories(); qreal min(); qreal max(); diff --git a/src/barchart/stackedbargroup.cpp b/src/barchart/stackedbargroup.cpp index b95e529..c6b0d9a 100644 --- a/src/barchart/stackedbargroup.cpp +++ b/src/barchart/stackedbargroup.cpp @@ -17,11 +17,13 @@ void StackedBarGroup::layoutChanged() // Scale bars to new layout // Layout for bars: if (mModel.countSets() <= 0) { + qDebug() << "No sets in model!"; // Nothing to do. return; } if (mModel.countCategories() == 0) { + qDebug() << "No categories in model!"; // Nothing to do return; } @@ -65,7 +67,6 @@ void StackedBarGroup::layoutChanged() xPos += xStep; } - // 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. diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index fd2c030..bd3bcb4 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -52,7 +52,7 @@ void ChartDataSet::addSeries(QChartSeries* series) break; } case QChartSeries::SeriesTypeBar: { - + qDebug() << "QChartSeries::SeriesTypeBar"; BarChartSeries* barSeries = static_cast(series); qreal x = barSeries->countCategories(); qreal y = barSeries->max(); @@ -63,6 +63,7 @@ void ChartDataSet::addSeries(QChartSeries* series) break; } case QChartSeries::SeriesTypeStackedBar: { + qDebug() << "QChartSeries::SeriesTypeStackedBar"; StackedBarChartSeries* stackedBarSeries = static_cast(series); qreal x = stackedBarSeries->countCategories(); @@ -74,6 +75,7 @@ void ChartDataSet::addSeries(QChartSeries* series) break; } case QChartSeries::SeriesTypePercentBar: { + qDebug() << "QChartSeries::SeriesTypePercentBar"; PercentBarChartSeries* percentBarSeries = static_cast(series); qreal x = percentBarSeries->countCategories(); diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 3473050..565ddcd 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -76,6 +76,7 @@ void ChartPresenter::setMargin(int margin) void ChartPresenter::handleSeriesAdded(QChartSeries* series) { + qDebug() << " ChartPresenter::handleSeriesAdded"; switch(series->type()) { case QChartSeries::SeriesTypeLine: { diff --git a/test/chartwidgettest/mainwidget.cpp b/test/chartwidgettest/mainwidget.cpp index fb498c6..8bfdfaa 100644 --- a/test/chartwidgettest/mainwidget.cpp +++ b/test/chartwidgettest/mainwidget.cpp @@ -180,11 +180,11 @@ void MainWidget::addSeries(QString series, QString data) QList x; QList y; - QBarSet set0; - QBarSet set1; - QBarSet set2; - QBarSet set3; - QBarSet set4; + QBarSet *set0 = new QBarSet; + QBarSet *set1 = new QBarSet; + QBarSet *set2 = new QBarSet; + QBarSet *set3 = new QBarSet; + QBarSet *set4 = new QBarSet; if (data == "linear") { for (int i = 0; i < 20; i++) { @@ -213,11 +213,11 @@ void MainWidget::addSeries(QString series, QString data) } } else if (data == "Table, 5 series"){ // 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; + *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); @@ -248,8 +248,8 @@ void MainWidget::addSeries(QString series, QString data) } else if (series == "Bar") { qDebug() << "Bar chart series"; - QBarCategory category; - category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + QBarCategory *category = new QBarCategory; + *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; BarChartSeries* series0 = new BarChartSeries(category, this); @@ -264,8 +264,8 @@ void MainWidget::addSeries(QString series, QString data) } else if (series == "StackedBar") { qDebug() << "Stacked bar chart series"; - QBarCategory category; - category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + QBarCategory *category = new QBarCategory; + *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; StackedBarChartSeries* series0 = new StackedBarChartSeries(category, this); @@ -280,8 +280,8 @@ void MainWidget::addSeries(QString series, QString data) } else if (series == "PercentBar") { qDebug() << "Percent bar chart series"; - QBarCategory category; - category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + QBarCategory *category = new QBarCategory; + *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; PercentBarChartSeries* series0 = new PercentBarChartSeries(category, this);