From a61a7697be628d1fce2144d524e2d7434ec3402c 2012-02-28 10:00:54 From: sauimone Date: 2012-02-28 10:00:54 Subject: [PATCH] replaced qbarcategory with qstringlist --- diff --git a/example/barchart/main.cpp b/example/barchart/main.cpp index 4278535..b97060f 100644 --- a/example/barchart/main.cpp +++ b/example/barchart/main.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -13,9 +13,9 @@ int main(int argc, char *argv[]) QMainWindow window; //! [1] - // Create category - QBarCategory *category = new QBarCategory; - *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + // Define categories + QStringList catecories; + catecories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; //! [1] //! [2] @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) //! [3] // Create series and add sets to it - QBarSeries* series= new QBarSeries(category); + QBarSeries* series= new QBarSeries(catecories); series->addBarSet(set0); series->addBarSet(set1); diff --git a/example/chartview/main.cpp b/example/chartview/main.cpp index 6152748..68abd23 100644 --- a/example/chartview/main.cpp +++ b/example/chartview/main.cpp @@ -6,8 +6,8 @@ #include #include #include -#include #include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -60,8 +60,8 @@ int main(int argc, char *argv[]) //! [5] // ... // Add bar series - QBarCategory *barCategory = new QBarCategory(); - *barCategory << "Jan" + QStringList barCategory; + barCategory << "Jan" << "Feb" << "Mar"; QBarSeries *bar = new QBarSeries(barCategory); diff --git a/example/gdpbarchart/widget.cpp b/example/gdpbarchart/widget.cpp index aa8db21..34f314c 100644 --- a/example/gdpbarchart/widget.cpp +++ b/example/gdpbarchart/widget.cpp @@ -13,12 +13,12 @@ #include #include #include -#include #include #include #include #include #include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -121,9 +121,9 @@ void Widget::refreshChart() if (barChartRadioButton->isChecked()) { // use the sorted selected coutries list to initialize BarCategory - QBarCategory* category = new QBarCategory; + QStringList category; for (int i = 0; i < selectedCountriesStrings.size(); i++) - *category << selectedCountriesStrings[i]; + category << selectedCountriesStrings[i]; series0 = new QBarSeries(category); // prepare the selected counries SQL query diff --git a/example/percentbarchart/main.cpp b/example/percentbarchart/main.cpp index 8667397..e19e1a9 100644 --- a/example/percentbarchart/main.cpp +++ b/example/percentbarchart/main.cpp @@ -2,9 +2,9 @@ #include #include #include -#include #include #include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -14,9 +14,9 @@ int main(int argc, char *argv[]) QMainWindow window; //! [1] - // Create category - QBarCategory *category = new QBarCategory; - *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + // Define categories + QStringList categories; + categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; //! [1] //! [2] @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) //! [3] // Create series and add sets to it - QPercentBarSeries* series = new QPercentBarSeries(category); + QPercentBarSeries* series = new QPercentBarSeries(categories); series->addBarSet(set0); series->addBarSet(set1); diff --git a/example/stackedbarchart/main.cpp b/example/stackedbarchart/main.cpp index 5751f6a..32b189c 100644 --- a/example/stackedbarchart/main.cpp +++ b/example/stackedbarchart/main.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -13,9 +13,9 @@ int main(int argc, char *argv[]) QMainWindow window; //! [1] - // Create category - QBarCategory *category = new QBarCategory; - *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + // Define categories + QStringList catecories; + catecories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; //! [1] //! [2] @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) //! [3] // Create series and add sets to it - QStackedBarSeries* series = new QStackedBarSeries(category); + QStackedBarSeries* series = new QStackedBarSeries(catecories); series->addBarSet(set0); series->addBarSet(set1); diff --git a/src/barchart/barchart.pri b/src/barchart/barchart.pri index 0a98940..60c7ea0 100644 --- a/src/barchart/barchart.pri +++ b/src/barchart/barchart.pri @@ -8,7 +8,6 @@ SOURCES += \ $$PWD/barpresenter.cpp \ $$PWD/barpresenterbase.cpp \ $$PWD/percentbarpresenter.cpp \ - $$PWD/qbarcategory.cpp \ $$PWD/qbarseries.cpp \ $$PWD/qbarset.cpp \ $$PWD/qpercentbarseries.cpp \ @@ -29,7 +28,6 @@ PRIVATE_HEADERS += \ $$PWD/barvalue_p.h PUBLIC_HEADERS += \ - $$PWD/qbarcategory.h \ $$PWD/qbarseries.h \ $$PWD/qbarset.h \ $$PWD/qpercentbarseries.h \ diff --git a/src/barchart/barchartmodel.cpp b/src/barchart/barchartmodel.cpp index 611228d..7ff72ac 100644 --- a/src/barchart/barchartmodel.cpp +++ b/src/barchart/barchartmodel.cpp @@ -2,26 +2,19 @@ #include #include #include "barchartmodel_p.h" -#include "qbarcategory.h" #include "qbarset.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE -BarChartModel::BarChartModel(QBarCategory *category, QObject *parent) : +BarChartModel::BarChartModel(QStringList categories, QObject *parent) : QObject(parent) - ,mCategory(category) + ,mCategory(categories) { } -BarChartModel::~BarChartModel() +QStringList BarChartModel::category() { - delete mCategory; -} - - -QBarCategory& BarChartModel::category() -{ - return *mCategory; + return mCategory; } void BarChartModel::addBarSet(QBarSet *set) @@ -182,7 +175,7 @@ qreal BarChartModel::maxCategorySum() QString BarChartModel::label(int category) { - return mCategory->label(category); + return mCategory.at(category); } #include "moc_barchartmodel_p.cpp" diff --git a/src/barchart/barchartmodel_p.h b/src/barchart/barchartmodel_p.h index c7881b9..984b119 100644 --- a/src/barchart/barchartmodel_p.h +++ b/src/barchart/barchartmodel_p.h @@ -2,6 +2,7 @@ #define BARCHARTMODEL_H #include +#include #include "qchartglobal.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -10,16 +11,14 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE // TODO: Implement as QAbstractItemModel? class QBarSet; -class QBarCategory; class BarChartModel : public QObject //, public QAbstractItemModel { Q_OBJECT public: - explicit BarChartModel(QBarCategory *category, QObject *parent = 0); - ~BarChartModel(); + explicit BarChartModel(QStringList categories, QObject *parent = 0); - QBarCategory& category(); + QStringList category(); void addBarSet(QBarSet *set); void removeBarSet(QBarSet *set); QBarSet *setAt(int index); @@ -49,7 +48,7 @@ public slots: private: QList mDataModel; - QBarCategory* mCategory; // Owned + QStringList mCategory; int mCurrentSet; diff --git a/src/barchart/qbarcategory.cpp b/src/barchart/qbarcategory.cpp deleted file mode 100644 index 10b9b59..0000000 --- a/src/barchart/qbarcategory.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "qbarcategory.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -/*! - \class QBarCategory - \brief part of QtCommercial chart API. - - QBarCategory is a container for labels of various bar charts. Before the - bar chart can be constructed, the categories must be defined. This is done by - creating a QBarCategory class and appending the labels of categories to it. - The QBarCategory is then given to bar chart series class. - - \mainclass - - Example on how to create a category: - \snippet ../example/barchart/main.cpp 1 - - \sa QBarSeries, QStackedBarSeries, QPercentBarSeries -*/ - -/*! - Constructs the category container -*/ -QBarCategory::QBarCategory() -{ -} - -/*! - Appends the \a label in the category. -*/ -QBarCategory& QBarCategory::operator << (const QString &label) -{ - mList.append(label); - return *this; -} - -/*! - Retrurns number of labels in category -*/ -int QBarCategory::count() -{ - return mList.count(); -} - -/*! - Retruns the label of category defined by index \a category -*/ -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 deleted file mode 100644 index f534265..0000000 --- a/src/barchart/qbarcategory.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef QBARCATEGORY_H -#define QBARCATEGORY_H - -#include "qchartglobal.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class QTCOMMERCIALCHART_EXPORT QBarCategory // TODO?: : public QObject -{ -// Q_OBJECT; -public: - QBarCategory(); - - QBarCategory& operator << (const QString &label); - - // Number of items in category - int count(); - QString label(int category); - -public: - - QList mList; - -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // QBARCATEGORY_H diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index 0f3f5ff..56f0a8c 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -1,6 +1,5 @@ #include #include "qbarseries.h" -#include "qbarcategory.h" #include "qbarset.h" #include "barchartmodel_p.h" @@ -13,11 +12,11 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined - by QBarCategory class. + by QStringList. \mainclass - \sa QBarCategory, QBarSet, QStackedBarSeries, QPercentBarSeries + \sa QBarSet, QStackedBarSeries, QPercentBarSeries */ /*! @@ -48,12 +47,11 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE /*! Constructs empty QBarSeries. Parameter \a category defines the categories for chart. - Takes ownership of \a category. QBarSeries is QObject which is a child of a \a parent. */ -QBarSeries::QBarSeries(QBarCategory *category, QObject *parent) +QBarSeries::QBarSeries(QStringList categories, QObject *parent) : QSeries(parent) - ,mModel(new BarChartModel(category, this)) + ,mModel(new BarChartModel(categories, this)) { } diff --git a/src/barchart/qbarseries.h b/src/barchart/qbarseries.h index 305e322..863501a 100644 --- a/src/barchart/qbarseries.h +++ b/src/barchart/qbarseries.h @@ -2,10 +2,10 @@ #define BARSERIES_H #include "qseries.h" +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE -class QBarCategory; class QBarSet; class BarChartModel; @@ -14,7 +14,7 @@ class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries { Q_OBJECT public: - QBarSeries(QBarCategory *category, QObject* parent=0); + QBarSeries(QStringList categories, QObject* parent=0); virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } diff --git a/src/barchart/qbarset.cpp b/src/barchart/qbarset.cpp index 2429591..caa04bf 100644 --- a/src/barchart/qbarset.cpp +++ b/src/barchart/qbarset.cpp @@ -15,7 +15,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE \mainclass - \sa QBarCategory, QBarSeries, QStackedBarSeries, QPercentBarSeries + \sa QBarSeries, QStackedBarSeries, QPercentBarSeries */ /*! diff --git a/src/barchart/qpercentbarseries.cpp b/src/barchart/qpercentbarseries.cpp index 4058028..d9bb00d 100644 --- a/src/barchart/qpercentbarseries.cpp +++ b/src/barchart/qpercentbarseries.cpp @@ -8,11 +8,11 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QPercentBarSeries represents a series of data shown as bars. Each bar of QBarSet is shown as percentage of all bars in category. One QPercentBarSeries can contain multible QBarSet data sets. - QBarSeries groups the data from sets to categories, which are defined by QBarCategory class. + QBarSeries groups the data from sets to categories, which are defined by QStringList. \mainclass - \sa QBarCategory, QBarSet, QStackedBarSeries, QBarSeries + \sa QBarSet, QStackedBarSeries, QBarSeries */ /*! @@ -25,8 +25,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Constructs empty QPercentBarSeries. Parameter \a category defines the categories for chart. QPercentBarSeries is QObject which is a child of a \a parent. */ -QPercentBarSeries::QPercentBarSeries(QBarCategory *category, QObject *parent) - : QBarSeries(category, parent) +QPercentBarSeries::QPercentBarSeries(QStringList categories, QObject *parent) + : QBarSeries(categories, parent) { } diff --git a/src/barchart/qpercentbarseries.h b/src/barchart/qpercentbarseries.h index 3855097..cbcafe1 100644 --- a/src/barchart/qpercentbarseries.h +++ b/src/barchart/qpercentbarseries.h @@ -1,6 +1,7 @@ #ifndef PERCENTBARSERIES_H #define PERCENTBARSERIES_H +#include #include "qbarseries.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -9,7 +10,7 @@ class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries { Q_OBJECT public: - QPercentBarSeries(QBarCategory *category, QObject* parent=0); + QPercentBarSeries(QStringList categories, QObject* parent=0); virtual QSeriesType type() const { return QSeries::SeriesTypePercentBar; } }; diff --git a/src/barchart/qstackedbarseries.cpp b/src/barchart/qstackedbarseries.cpp index 9c1405f..7fda0de 100644 --- a/src/barchart/qstackedbarseries.cpp +++ b/src/barchart/qstackedbarseries.cpp @@ -8,11 +8,11 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QStackedBarSeries represents a series of data shown as bars. All bars in same category are stacked on top of each other. One QStackedBarSeries can contain multible QBarSet data sets. - QStackedBarSeries groups the data from sets to categories, which are defined by QBarCategory class. + QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. \mainclass - \sa QBarCategory, QBarSet, QPercentBarSeries, QBarSeries + \sa QBarSet, QPercentBarSeries, QBarSeries */ /*! @@ -25,8 +25,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Constructs empty QStackedBarSeries. Parameter \a category defines the categories for chart. QStackedBarSeries is QObject which is a child of a \a parent. */ -QStackedBarSeries::QStackedBarSeries(QBarCategory *category, QObject *parent) - : QBarSeries(category, parent) +QStackedBarSeries::QStackedBarSeries(QStringList categories, QObject *parent) + : QBarSeries(categories, parent) { } diff --git a/src/barchart/qstackedbarseries.h b/src/barchart/qstackedbarseries.h index 43d591b..e1b796e 100644 --- a/src/barchart/qstackedbarseries.h +++ b/src/barchart/qstackedbarseries.h @@ -1,17 +1,16 @@ #ifndef STACKEDBARSERIES_H #define STACKEDBARSERIES_H +#include #include "qbarseries.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE -class QBarCategory; - class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries { Q_OBJECT public: - QStackedBarSeries(QBarCategory *category, QObject* parent=0); + QStackedBarSeries(QStringList categories, QObject* parent=0); virtual QSeriesType type() const { return QSeries::SeriesTypeStackedBar; } }; diff --git a/test/chartwidgettest/mainwidget.cpp b/test/chartwidgettest/mainwidget.cpp index 20518f1..483195c 100644 --- a/test/chartwidgettest/mainwidget.cpp +++ b/test/chartwidgettest/mainwidget.cpp @@ -4,7 +4,6 @@ #include "qscatterseries.h" #include #include -#include #include #include #include @@ -253,11 +252,10 @@ void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS } else if (seriesName == "Bar" || seriesName == "Stacked bar" || seriesName == "Percent bar") { - // TODO: replace QBarCategory with QStringList? - QBarCategory *category = new QBarCategory; + QStringList category; QStringList labels = generateLabels(rowCount); foreach(QString label, labels) - *category << label; + category << label; QBarSeries* series = 0; if (seriesName == "Bar") series = new QBarSeries(category, this);