From 938a9dbeab71f0bb945de67ab73d74ab7889f897 2012-05-03 11:41:20 From: sauimone Date: 2012-05-03 11:41:20 Subject: [PATCH] separated categories from barseries constructor --- diff --git a/examples/barchart/main.cpp b/examples/barchart/main.cpp index f4e2624..a1013bb 100644 --- a/examples/barchart/main.cpp +++ b/examples/barchart/main.cpp @@ -51,7 +51,8 @@ int main(int argc, char *argv[]) //![2] //![3] - QBarSeries* series = new QBarSeries(categories); + QBarSeries* series = new QBarSeries(); + series->setCategories(categories); series->appendBarSet(set0); series->appendBarSet(set1); series->appendBarSet(set2); diff --git a/examples/percentbarchart/main.cpp b/examples/percentbarchart/main.cpp index 383bdda..c72e751 100644 --- a/examples/percentbarchart/main.cpp +++ b/examples/percentbarchart/main.cpp @@ -51,7 +51,8 @@ int main(int argc, char *argv[]) //![2] //![3] - QPercentBarSeries* series = new QPercentBarSeries(categories); + QPercentBarSeries* series = new QPercentBarSeries(); + series->setCategories(categories); series->appendBarSet(set0); series->appendBarSet(set1); series->appendBarSet(set2); diff --git a/examples/stackedbarchart/main.cpp b/examples/stackedbarchart/main.cpp index 987f2f9..289171a 100644 --- a/examples/stackedbarchart/main.cpp +++ b/examples/stackedbarchart/main.cpp @@ -51,7 +51,8 @@ int main(int argc, char *argv[]) //![2] //![3] - QStackedBarSeries* series = new QStackedBarSeries(categories); + QStackedBarSeries* series = new QStackedBarSeries(); + series->setCategories(categories); series->appendBarSet(set0); series->appendBarSet(set1); series->appendBarSet(set2); diff --git a/examples/stackedbarchartdrilldown/drilldownseries.cpp b/examples/stackedbarchartdrilldown/drilldownseries.cpp index 7d3b174..f23413e 100644 --- a/examples/stackedbarchartdrilldown/drilldownseries.cpp +++ b/examples/stackedbarchartdrilldown/drilldownseries.cpp @@ -23,8 +23,9 @@ QTCOMMERCIALCHART_USE_NAMESPACE DrilldownBarSeries::DrilldownBarSeries(QStringList categories, QObject *parent) - : QStackedBarSeries(categories, parent) + : QStackedBarSeries(parent) { + setCategories(categories); } void DrilldownBarSeries::mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries) diff --git a/qmlplugin/declarativebarseries.cpp b/qmlplugin/declarativebarseries.cpp index b68adc9..31ecdd5 100644 --- a/qmlplugin/declarativebarseries.cpp +++ b/qmlplugin/declarativebarseries.cpp @@ -50,7 +50,9 @@ void DeclarativeBarSeries::setBarCategories(QStringList categories) QChart *chart = qobject_cast(declarativeChart->m_chart); Q_ASSERT(chart); - m_series = new QBarSeries(m_categories); +// m_series = new QBarSeries(m_categories); + m_series = new QBarSeries(); + m_series->setCategories(m_categories); // TODO: use data from model QBarSet *set0 = new QBarSet("Bub"); diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index 08aecbb..61aa050 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -67,8 +67,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. QBarSeries is QObject which is a child of a \a parent. */ -QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : - QAbstractSeries(*new QBarSeriesPrivate(categories, this),parent) +QBarSeries::QBarSeries(/*QBarCategories categories,*/ QObject *parent) : + QAbstractSeries(*new QBarSeriesPrivate(/*categories,*/ this),parent) { } @@ -96,6 +96,13 @@ QAbstractSeries::SeriesType QBarSeries::type() const return QAbstractSeries::SeriesTypeBar; } +void QBarSeries::setCategories(QBarCategories categories) +{ + Q_D(QBarSeries); + d->setCategories(categories); + emit d->categoriesUpdated(); +} + /*! Adds a set of bars to series. Takes ownership of \a set. */ @@ -227,15 +234,21 @@ void QBarSeries::setLabelsVisible(bool visible) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : +QBarSeriesPrivate::QBarSeriesPrivate(/*QBarCategories categories,*/ QBarSeries *q) : QAbstractSeriesPrivate(q), - m_categories(categories), +// m_categories(categories), m_mapCategories(-1), m_mapBarBottom(-1), m_mapBarTop(-1) { } +void QBarSeriesPrivate::setCategories(QBarCategories categories) +{ + m_categories = categories; +} + + QBarSet* QBarSeriesPrivate::barsetAt(int index) { return m_barSets.at(index); diff --git a/src/barchart/qbarseries.h b/src/barchart/qbarseries.h index 9d79229..45de1b5 100644 --- a/src/barchart/qbarseries.h +++ b/src/barchart/qbarseries.h @@ -39,10 +39,11 @@ class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries { Q_OBJECT public: - explicit QBarSeries(QBarCategories categories, QObject *parent = 0); + explicit QBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); virtual ~QBarSeries(); QAbstractSeries::SeriesType type() const; + void setCategories(QBarCategories categories); void appendBarSet(QBarSet *set); // Takes ownership of set void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set diff --git a/src/barchart/qbarseries_p.h b/src/barchart/qbarseries_p.h index 29e5574..ca75df8 100644 --- a/src/barchart/qbarseries_p.h +++ b/src/barchart/qbarseries_p.h @@ -15,7 +15,8 @@ class QBarSeriesPrivate : public QAbstractSeriesPrivate { Q_OBJECT public: - QBarSeriesPrivate(QBarCategories categories, QBarSeries *parent); + QBarSeriesPrivate(/*QBarCategories categories,*/ QBarSeries *parent); + void setCategories(QBarCategories categories); void scaleDomain(Domain& domain); Chart* createGraphics(ChartPresenter* presenter); diff --git a/src/barchart/qpercentbarseries.cpp b/src/barchart/qpercentbarseries.cpp index 9277f30..6889b2b 100644 --- a/src/barchart/qpercentbarseries.cpp +++ b/src/barchart/qpercentbarseries.cpp @@ -53,8 +53,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Constructs empty QPercentBarSeries. Parameter \a categories defines the categories for chart. QPercentBarSeries is QObject which is a child of a \a parent. */ -QPercentBarSeries::QPercentBarSeries(QBarCategories categories, QObject *parent) - : QBarSeries(*new QPercentBarSeriesPrivate(categories,this), parent) +QPercentBarSeries::QPercentBarSeries(/*QBarCategories categories,*/ QObject *parent) + : QBarSeries(*new QPercentBarSeriesPrivate(/*categories,*/this), parent) { } @@ -65,7 +65,7 @@ QAbstractSeries::SeriesType QPercentBarSeries::type() const /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QBarCategories categories, QPercentBarSeries *q) : QBarSeriesPrivate(categories,q) +QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(/*QBarCategories categories,*/ QPercentBarSeries *q) : QBarSeriesPrivate(/*categories,*/q) { } diff --git a/src/barchart/qpercentbarseries.h b/src/barchart/qpercentbarseries.h index e8141ec..ba12f97 100644 --- a/src/barchart/qpercentbarseries.h +++ b/src/barchart/qpercentbarseries.h @@ -32,8 +32,9 @@ class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries { Q_OBJECT public: - explicit QPercentBarSeries(QBarCategories categories, QObject *parent = 0); + explicit QPercentBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); QAbstractSeries::SeriesType type() const; + private: Q_DECLARE_PRIVATE(QPercentBarSeries) Q_DISABLE_COPY(QPercentBarSeries) diff --git a/src/barchart/qpercentbarseries_p.h b/src/barchart/qpercentbarseries_p.h index b296c91..d7494a9 100644 --- a/src/barchart/qpercentbarseries_p.h +++ b/src/barchart/qpercentbarseries_p.h @@ -39,7 +39,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class QPercentBarSeriesPrivate: public QBarSeriesPrivate { public: - QPercentBarSeriesPrivate(QBarCategories categories,QPercentBarSeries* q); + QPercentBarSeriesPrivate(/*QBarCategories categories,*/QPercentBarSeries* q); void scaleDomain(Domain& domain); Chart* createGraphics(ChartPresenter* presenter); diff --git a/src/barchart/qstackedbarseries.cpp b/src/barchart/qstackedbarseries.cpp index 3ef6dfe..12f7c62 100644 --- a/src/barchart/qstackedbarseries.cpp +++ b/src/barchart/qstackedbarseries.cpp @@ -52,8 +52,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Constructs empty QStackedBarSeries. Parameter \a categories defines the categories for chart. QStackedBarSeries is QObject which is a child of a \a parent. */ -QStackedBarSeries::QStackedBarSeries(QBarCategories categories, QObject *parent) - : QBarSeries(*new QStackedBarSeriesPrivate(categories,this), parent) +QStackedBarSeries::QStackedBarSeries(/*QBarCategories categories,*/ QObject *parent) + : QBarSeries(*new QStackedBarSeriesPrivate(/*categories,*/this), parent) { } @@ -64,7 +64,7 @@ QAbstractSeries::SeriesType QStackedBarSeries::type() const /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QBarCategories categories, QStackedBarSeries *q) : QBarSeriesPrivate(categories,q) +QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(/*QBarCategories categories,*/ QStackedBarSeries *q) : QBarSeriesPrivate(/*categories,*/q) { } diff --git a/src/barchart/qstackedbarseries.h b/src/barchart/qstackedbarseries.h index 5e0f234..8833d9f 100644 --- a/src/barchart/qstackedbarseries.h +++ b/src/barchart/qstackedbarseries.h @@ -32,8 +32,9 @@ class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries { Q_OBJECT public: - explicit QStackedBarSeries(QBarCategories categories, QObject *parent = 0); + explicit QStackedBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); QAbstractSeries::SeriesType type() const; + private: Q_DECLARE_PRIVATE(QStackedBarSeries) Q_DISABLE_COPY(QStackedBarSeries) diff --git a/src/barchart/qstackedbarseries_p.h b/src/barchart/qstackedbarseries_p.h index 0ff4011..632de86 100644 --- a/src/barchart/qstackedbarseries_p.h +++ b/src/barchart/qstackedbarseries_p.h @@ -39,7 +39,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class QStackedBarSeriesPrivate: public QBarSeriesPrivate { public: - QStackedBarSeriesPrivate(QBarCategories categories,QStackedBarSeries* q); + QStackedBarSeriesPrivate(/*QBarCategories categories,*/QStackedBarSeries* q); Chart* createGraphics(ChartPresenter* presenter); void scaleDomain(Domain& domain); diff --git a/test/auto/qbarseries/tst_qbarseries.cpp b/test/auto/qbarseries/tst_qbarseries.cpp index d184e79..be8d26c 100644 --- a/test/auto/qbarseries/tst_qbarseries.cpp +++ b/test/auto/qbarseries/tst_qbarseries.cpp @@ -78,8 +78,10 @@ void tst_QBarSeries::cleanupTestCase() void tst_QBarSeries::init() { m_categories << "category0" << "category1" << "category2"; - m_barseries = new QBarSeries(m_categories); - m_barseries_with_sets = new QBarSeries(m_categories); + m_barseries = new QBarSeries(); + m_barseries->setCategories(m_categories); + m_barseries_with_sets = new QBarSeries(); + m_barseries_with_sets->setCategories(m_categories); for (int i=0; i<5; i++) { m_testSets.append(new QBarSet("testset")); @@ -113,8 +115,9 @@ void tst_QBarSeries::qbarseries_data() void tst_QBarSeries::qbarseries() { QFETCH(QBarCategories, categories); - QBarSeries *barseries = new QBarSeries(categories); + QBarSeries *barseries = new QBarSeries(); QVERIFY(barseries != 0); + barseries->setCategories(categories); QBarCategories verifyCategories = barseries->categories(); QVERIFY(verifyCategories.count() == categories.count());