##// END OF EJS Templates
replaced qbarcategory with qstringlist
sauimone -
r377:a61a7697be62
parent child
Show More
@@ -3,7 +3,7
3 #include <qchartview.h>
3 #include <qchartview.h>
4 #include <qbarseries.h>
4 #include <qbarseries.h>
5 #include <qbarset.h>
5 #include <qbarset.h>
6 #include <qbarcategory.h>
6 #include <QStringList>
7
7
8 QTCOMMERCIALCHART_USE_NAMESPACE
8 QTCOMMERCIALCHART_USE_NAMESPACE
9
9
@@ -13,9 +13,9 int main(int argc, char *argv[])
13 QMainWindow window;
13 QMainWindow window;
14
14
15 //! [1]
15 //! [1]
16 // Create category
16 // Define categories
17 QBarCategory *category = new QBarCategory;
17 QStringList catecories;
18 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
18 catecories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
19 //! [1]
19 //! [1]
20
20
21 //! [2]
21 //! [2]
@@ -36,7 +36,7 int main(int argc, char *argv[])
36
36
37 //! [3]
37 //! [3]
38 // Create series and add sets to it
38 // Create series and add sets to it
39 QBarSeries* series= new QBarSeries(category);
39 QBarSeries* series= new QBarSeries(catecories);
40
40
41 series->addBarSet(set0);
41 series->addBarSet(set0);
42 series->addBarSet(set1);
42 series->addBarSet(set1);
@@ -6,8 +6,8
6 #include <qscatterseries.h>
6 #include <qscatterseries.h>
7 #include <qbarseries.h>
7 #include <qbarseries.h>
8 #include <qbarset.h>
8 #include <qbarset.h>
9 #include <qbarcategory.h>
10 #include <qpieseries.h>
9 #include <qpieseries.h>
10 #include <QStringList>
11
11
12 QTCOMMERCIALCHART_USE_NAMESPACE
12 QTCOMMERCIALCHART_USE_NAMESPACE
13
13
@@ -60,8 +60,8 int main(int argc, char *argv[])
60 //! [5]
60 //! [5]
61 // ...
61 // ...
62 // Add bar series
62 // Add bar series
63 QBarCategory *barCategory = new QBarCategory();
63 QStringList barCategory;
64 *barCategory << "Jan"
64 barCategory << "Jan"
65 << "Feb"
65 << "Feb"
66 << "Mar";
66 << "Mar";
67 QBarSeries *bar = new QBarSeries(barCategory);
67 QBarSeries *bar = new QBarSeries(barCategory);
@@ -13,12 +13,12
13 #include <qscatterseries.h>
13 #include <qscatterseries.h>
14 #include <qchartview.h>
14 #include <qchartview.h>
15 #include <qchartaxis.h>
15 #include <qchartaxis.h>
16 #include <qbarcategory.h>
17 #include <qbarset.h>
16 #include <qbarset.h>
18 #include <QListWidget>
17 #include <QListWidget>
19 #include <QPrinter>
18 #include <QPrinter>
20 #include <QPrintDialog>
19 #include <QPrintDialog>
21 #include <QRadioButton>
20 #include <QRadioButton>
21 #include <QStringList>
22
22
23 QTCOMMERCIALCHART_USE_NAMESPACE
23 QTCOMMERCIALCHART_USE_NAMESPACE
24
24
@@ -121,9 +121,9 void Widget::refreshChart()
121 if (barChartRadioButton->isChecked())
121 if (barChartRadioButton->isChecked())
122 {
122 {
123 // use the sorted selected coutries list to initialize BarCategory
123 // use the sorted selected coutries list to initialize BarCategory
124 QBarCategory* category = new QBarCategory;
124 QStringList category;
125 for (int i = 0; i < selectedCountriesStrings.size(); i++)
125 for (int i = 0; i < selectedCountriesStrings.size(); i++)
126 *category << selectedCountriesStrings[i];
126 category << selectedCountriesStrings[i];
127 series0 = new QBarSeries(category);
127 series0 = new QBarSeries(category);
128
128
129 // prepare the selected counries SQL query
129 // prepare the selected counries SQL query
@@ -2,9 +2,9
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <QStandardItemModel>
3 #include <QStandardItemModel>
4 #include <qpercentbarseries.h>
4 #include <qpercentbarseries.h>
5 #include <qbarcategory.h>
6 #include <qchartview.h>
5 #include <qchartview.h>
7 #include <qbarset.h>
6 #include <qbarset.h>
7 #include <QStringList>
8
8
9 QTCOMMERCIALCHART_USE_NAMESPACE
9 QTCOMMERCIALCHART_USE_NAMESPACE
10
10
@@ -14,9 +14,9 int main(int argc, char *argv[])
14 QMainWindow window;
14 QMainWindow window;
15
15
16 //! [1]
16 //! [1]
17 // Create category
17 // Define categories
18 QBarCategory *category = new QBarCategory;
18 QStringList categories;
19 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
19 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
20 //! [1]
20 //! [1]
21
21
22 //! [2]
22 //! [2]
@@ -36,7 +36,7 int main(int argc, char *argv[])
36
36
37 //! [3]
37 //! [3]
38 // Create series and add sets to it
38 // Create series and add sets to it
39 QPercentBarSeries* series = new QPercentBarSeries(category);
39 QPercentBarSeries* series = new QPercentBarSeries(categories);
40
40
41 series->addBarSet(set0);
41 series->addBarSet(set0);
42 series->addBarSet(set1);
42 series->addBarSet(set1);
@@ -3,7 +3,7
3 #include <qchartview.h>
3 #include <qchartview.h>
4 #include <qstackedbarseries.h>
4 #include <qstackedbarseries.h>
5 #include <qbarset.h>
5 #include <qbarset.h>
6 #include <qbarcategory.h>
6 #include <QStringList>
7
7
8 QTCOMMERCIALCHART_USE_NAMESPACE
8 QTCOMMERCIALCHART_USE_NAMESPACE
9
9
@@ -13,9 +13,9 int main(int argc, char *argv[])
13 QMainWindow window;
13 QMainWindow window;
14
14
15 //! [1]
15 //! [1]
16 // Create category
16 // Define categories
17 QBarCategory *category = new QBarCategory;
17 QStringList catecories;
18 *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
18 catecories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
19 //! [1]
19 //! [1]
20
20
21 //! [2]
21 //! [2]
@@ -35,7 +35,7 int main(int argc, char *argv[])
35
35
36 //! [3]
36 //! [3]
37 // Create series and add sets to it
37 // Create series and add sets to it
38 QStackedBarSeries* series = new QStackedBarSeries(category);
38 QStackedBarSeries* series = new QStackedBarSeries(catecories);
39
39
40 series->addBarSet(set0);
40 series->addBarSet(set0);
41 series->addBarSet(set1);
41 series->addBarSet(set1);
@@ -8,7 +8,6 SOURCES += \
8 $$PWD/barpresenter.cpp \
8 $$PWD/barpresenter.cpp \
9 $$PWD/barpresenterbase.cpp \
9 $$PWD/barpresenterbase.cpp \
10 $$PWD/percentbarpresenter.cpp \
10 $$PWD/percentbarpresenter.cpp \
11 $$PWD/qbarcategory.cpp \
12 $$PWD/qbarseries.cpp \
11 $$PWD/qbarseries.cpp \
13 $$PWD/qbarset.cpp \
12 $$PWD/qbarset.cpp \
14 $$PWD/qpercentbarseries.cpp \
13 $$PWD/qpercentbarseries.cpp \
@@ -29,7 +28,6 PRIVATE_HEADERS += \
29 $$PWD/barvalue_p.h
28 $$PWD/barvalue_p.h
30
29
31 PUBLIC_HEADERS += \
30 PUBLIC_HEADERS += \
32 $$PWD/qbarcategory.h \
33 $$PWD/qbarseries.h \
31 $$PWD/qbarseries.h \
34 $$PWD/qbarset.h \
32 $$PWD/qbarset.h \
35 $$PWD/qpercentbarseries.h \
33 $$PWD/qpercentbarseries.h \
@@ -2,26 +2,19
2 #include <QVector>
2 #include <QVector>
3 #include <QDebug>
3 #include <QDebug>
4 #include "barchartmodel_p.h"
4 #include "barchartmodel_p.h"
5 #include "qbarcategory.h"
6 #include "qbarset.h"
5 #include "qbarset.h"
7
6
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
8
10 BarChartModel::BarChartModel(QBarCategory *category, QObject *parent) :
9 BarChartModel::BarChartModel(QStringList categories, QObject *parent) :
11 QObject(parent)
10 QObject(parent)
12 ,mCategory(category)
11 ,mCategory(categories)
13 {
12 {
14 }
13 }
15
14
16 BarChartModel::~BarChartModel()
15 QStringList BarChartModel::category()
17 {
16 {
18 delete mCategory;
17 return mCategory;
19 }
20
21
22 QBarCategory& BarChartModel::category()
23 {
24 return *mCategory;
25 }
18 }
26
19
27 void BarChartModel::addBarSet(QBarSet *set)
20 void BarChartModel::addBarSet(QBarSet *set)
@@ -182,7 +175,7 qreal BarChartModel::maxCategorySum()
182
175
183 QString BarChartModel::label(int category)
176 QString BarChartModel::label(int category)
184 {
177 {
185 return mCategory->label(category);
178 return mCategory.at(category);
186 }
179 }
187
180
188 #include "moc_barchartmodel_p.cpp"
181 #include "moc_barchartmodel_p.cpp"
@@ -2,6 +2,7
2 #define BARCHARTMODEL_H
2 #define BARCHARTMODEL_H
3
3
4 #include <QObject>
4 #include <QObject>
5 #include <QStringList>
5 #include "qchartglobal.h"
6 #include "qchartglobal.h"
6
7
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -10,16 +11,14 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 // TODO: Implement as QAbstractItemModel?
11 // TODO: Implement as QAbstractItemModel?
11
12
12 class QBarSet;
13 class QBarSet;
13 class QBarCategory;
14
14
15 class BarChartModel : public QObject //, public QAbstractItemModel
15 class BarChartModel : public QObject //, public QAbstractItemModel
16 {
16 {
17 Q_OBJECT
17 Q_OBJECT
18 public:
18 public:
19 explicit BarChartModel(QBarCategory *category, QObject *parent = 0);
19 explicit BarChartModel(QStringList categories, QObject *parent = 0);
20 ~BarChartModel();
21
20
22 QBarCategory& category();
21 QStringList category();
23 void addBarSet(QBarSet *set);
22 void addBarSet(QBarSet *set);
24 void removeBarSet(QBarSet *set);
23 void removeBarSet(QBarSet *set);
25 QBarSet *setAt(int index);
24 QBarSet *setAt(int index);
@@ -49,7 +48,7 public slots:
49 private:
48 private:
50
49
51 QList<QBarSet*> mDataModel;
50 QList<QBarSet*> mDataModel;
52 QBarCategory* mCategory; // Owned
51 QStringList mCategory;
53
52
54 int mCurrentSet;
53 int mCurrentSet;
55
54
@@ -1,6 +1,5
1 #include <QDebug>
1 #include <QDebug>
2 #include "qbarseries.h"
2 #include "qbarseries.h"
3 #include "qbarcategory.h"
4 #include "qbarset.h"
3 #include "qbarset.h"
5 #include "barchartmodel_p.h"
4 #include "barchartmodel_p.h"
6
5
@@ -13,11 +12,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13
12
14 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible
13 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible
15 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
14 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
16 by QBarCategory class.
15 by QStringList.
17
16
18 \mainclass
17 \mainclass
19
18
20 \sa QBarCategory, QBarSet, QStackedBarSeries, QPercentBarSeries
19 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
21 */
20 */
22
21
23 /*!
22 /*!
@@ -48,12 +47,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
48
47
49 /*!
48 /*!
50 Constructs empty QBarSeries. Parameter \a category defines the categories for chart.
49 Constructs empty QBarSeries. Parameter \a category defines the categories for chart.
51 Takes ownership of \a category.
52 QBarSeries is QObject which is a child of a \a parent.
50 QBarSeries is QObject which is a child of a \a parent.
53 */
51 */
54 QBarSeries::QBarSeries(QBarCategory *category, QObject *parent)
52 QBarSeries::QBarSeries(QStringList categories, QObject *parent)
55 : QSeries(parent)
53 : QSeries(parent)
56 ,mModel(new BarChartModel(category, this))
54 ,mModel(new BarChartModel(categories, this))
57 {
55 {
58 }
56 }
59
57
@@ -2,10 +2,10
2 #define BARSERIES_H
2 #define BARSERIES_H
3
3
4 #include "qseries.h"
4 #include "qseries.h"
5 #include <QStringList>
5
6
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
8
8 class QBarCategory;
9 class QBarSet;
9 class QBarSet;
10 class BarChartModel;
10 class BarChartModel;
11
11
@@ -14,7 +14,7 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries
14 {
14 {
15 Q_OBJECT
15 Q_OBJECT
16 public:
16 public:
17 QBarSeries(QBarCategory *category, QObject* parent=0);
17 QBarSeries(QStringList categories, QObject* parent=0);
18
18
19 virtual QSeriesType type() const { return QSeries::SeriesTypeBar; }
19 virtual QSeriesType type() const { return QSeries::SeriesTypeBar; }
20
20
@@ -15,7 +15,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
15
15
16 \mainclass
16 \mainclass
17
17
18 \sa QBarCategory, QBarSeries, QStackedBarSeries, QPercentBarSeries
18 \sa QBarSeries, QStackedBarSeries, QPercentBarSeries
19 */
19 */
20
20
21 /*!
21 /*!
@@ -8,11 +8,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 QPercentBarSeries represents a series of data shown as bars. Each bar of QBarSet is shown as percentage
9 QPercentBarSeries represents a series of data shown as bars. Each bar of QBarSet is shown as percentage
10 of all bars in category. One QPercentBarSeries can contain multible QBarSet data sets.
10 of all bars in category. One QPercentBarSeries can contain multible QBarSet data sets.
11 QBarSeries groups the data from sets to categories, which are defined by QBarCategory class.
11 QBarSeries groups the data from sets to categories, which are defined by QStringList.
12
12
13 \mainclass
13 \mainclass
14
14
15 \sa QBarCategory, QBarSet, QStackedBarSeries, QBarSeries
15 \sa QBarSet, QStackedBarSeries, QBarSeries
16 */
16 */
17
17
18 /*!
18 /*!
@@ -25,8 +25,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 Constructs empty QPercentBarSeries. Parameter \a category defines the categories for chart.
25 Constructs empty QPercentBarSeries. Parameter \a category defines the categories for chart.
26 QPercentBarSeries is QObject which is a child of a \a parent.
26 QPercentBarSeries is QObject which is a child of a \a parent.
27 */
27 */
28 QPercentBarSeries::QPercentBarSeries(QBarCategory *category, QObject *parent)
28 QPercentBarSeries::QPercentBarSeries(QStringList categories, QObject *parent)
29 : QBarSeries(category, parent)
29 : QBarSeries(categories, parent)
30 {
30 {
31 }
31 }
32
32
@@ -1,6 +1,7
1 #ifndef PERCENTBARSERIES_H
1 #ifndef PERCENTBARSERIES_H
2 #define PERCENTBARSERIES_H
2 #define PERCENTBARSERIES_H
3
3
4 #include <QStringList>
4 #include "qbarseries.h"
5 #include "qbarseries.h"
5
6
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -9,7 +10,7 class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries
9 {
10 {
10 Q_OBJECT
11 Q_OBJECT
11 public:
12 public:
12 QPercentBarSeries(QBarCategory *category, QObject* parent=0);
13 QPercentBarSeries(QStringList categories, QObject* parent=0);
13
14
14 virtual QSeriesType type() const { return QSeries::SeriesTypePercentBar; }
15 virtual QSeriesType type() const { return QSeries::SeriesTypePercentBar; }
15 };
16 };
@@ -8,11 +8,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 QStackedBarSeries represents a series of data shown as bars. All bars in same category are
9 QStackedBarSeries represents a series of data shown as bars. All bars in same category are
10 stacked on top of each other. One QStackedBarSeries can contain multible QBarSet data sets.
10 stacked on top of each other. One QStackedBarSeries can contain multible QBarSet data sets.
11 QStackedBarSeries groups the data from sets to categories, which are defined by QBarCategory class.
11 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
12
12
13 \mainclass
13 \mainclass
14
14
15 \sa QBarCategory, QBarSet, QPercentBarSeries, QBarSeries
15 \sa QBarSet, QPercentBarSeries, QBarSeries
16 */
16 */
17
17
18 /*!
18 /*!
@@ -25,8 +25,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 Constructs empty QStackedBarSeries. Parameter \a category defines the categories for chart.
25 Constructs empty QStackedBarSeries. Parameter \a category defines the categories for chart.
26 QStackedBarSeries is QObject which is a child of a \a parent.
26 QStackedBarSeries is QObject which is a child of a \a parent.
27 */
27 */
28 QStackedBarSeries::QStackedBarSeries(QBarCategory *category, QObject *parent)
28 QStackedBarSeries::QStackedBarSeries(QStringList categories, QObject *parent)
29 : QBarSeries(category, parent)
29 : QBarSeries(categories, parent)
30 {
30 {
31 }
31 }
32
32
@@ -1,17 +1,16
1 #ifndef STACKEDBARSERIES_H
1 #ifndef STACKEDBARSERIES_H
2 #define STACKEDBARSERIES_H
2 #define STACKEDBARSERIES_H
3
3
4 #include <QStringList>
4 #include "qbarseries.h"
5 #include "qbarseries.h"
5
6
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
8
8 class QBarCategory;
9
10 class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries
9 class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries
11 {
10 {
12 Q_OBJECT
11 Q_OBJECT
13 public:
12 public:
14 QStackedBarSeries(QBarCategory *category, QObject* parent=0);
13 QStackedBarSeries(QStringList categories, QObject* parent=0);
15
14
16 virtual QSeriesType type() const { return QSeries::SeriesTypeStackedBar; }
15 virtual QSeriesType type() const { return QSeries::SeriesTypeStackedBar; }
17 };
16 };
@@ -4,7 +4,6
4 #include "qscatterseries.h"
4 #include "qscatterseries.h"
5 #include <qlineseries.h>
5 #include <qlineseries.h>
6 #include <qbarset.h>
6 #include <qbarset.h>
7 #include <qbarcategory.h>
8 #include <qbarseries.h>
7 #include <qbarseries.h>
9 #include <qstackedbarseries.h>
8 #include <qstackedbarseries.h>
10 #include <qpercentbarseries.h>
9 #include <qpercentbarseries.h>
@@ -253,11 +252,10 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS
253 } else if (seriesName == "Bar"
252 } else if (seriesName == "Bar"
254 || seriesName == "Stacked bar"
253 || seriesName == "Stacked bar"
255 || seriesName == "Percent bar") {
254 || seriesName == "Percent bar") {
256 // TODO: replace QBarCategory with QStringList?
255 QStringList category;
257 QBarCategory *category = new QBarCategory;
258 QStringList labels = generateLabels(rowCount);
256 QStringList labels = generateLabels(rowCount);
259 foreach(QString label, labels)
257 foreach(QString label, labels)
260 *category << label;
258 category << label;
261 QBarSeries* series = 0;
259 QBarSeries* series = 0;
262 if (seriesName == "Bar")
260 if (seriesName == "Bar")
263 series = new QBarSeries(category, this);
261 series = new QBarSeries(category, this);
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now