@@ -1,172 +1,159 | |||||
1 | #include <limits.h> |
|
1 | #include <limits.h> | |
2 | #include <QVector> |
|
2 | #include <QVector> | |
3 | #include <QDebug> |
|
3 | #include <QDebug> | |
4 | #include "barchartmodel_p.h" |
|
4 | #include "barchartmodel_p.h" | |
5 | #include "qbarset.h" |
|
5 | #include "qbarset.h" | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | BarChartModel::BarChartModel(QStringList categories, QObject *parent) : |
|
9 | BarChartModel::BarChartModel(QStringList categories, QObject *parent) : | |
10 | QObject(parent) |
|
10 | QObject(parent) | |
11 | ,mCategory(categories) |
|
11 | ,mCategory(categories) | |
12 | { |
|
12 | { | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 | QStringList BarChartModel::category() |
|
15 | QStringList BarChartModel::category() | |
16 | { |
|
16 | { | |
17 | return mCategory; |
|
17 | return mCategory; | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 | void BarChartModel::addBarSet(QBarSet *set) |
|
20 | void BarChartModel::addBarSet(QBarSet *set) | |
21 | { |
|
21 | { | |
22 | mDataModel.append(set); |
|
22 | mDataModel.append(set); | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
25 | void BarChartModel::removeBarSet(QBarSet *set) |
|
25 | void BarChartModel::removeBarSet(QBarSet *set) | |
26 | { |
|
26 | { | |
27 | if (mDataModel.contains(set)) { |
|
27 | if (mDataModel.contains(set)) { | |
28 | mDataModel.removeOne(set); |
|
28 | mDataModel.removeOne(set); | |
29 | } |
|
29 | } | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | QBarSet* BarChartModel::setAt(int index) |
|
32 | QBarSet* BarChartModel::setAt(int index) | |
33 | { |
|
33 | { | |
34 | return mDataModel.at(index); |
|
34 | return mDataModel.at(index); | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | QList<QBarSet*> BarChartModel::barSets() |
|
37 | QList<QBarSet*> BarChartModel::barSets() | |
38 | { |
|
38 | { | |
39 | return mDataModel; |
|
39 | return mDataModel; | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QList<QSeries::LegendEntry> BarChartModel::legendEntries() |
|
|||
43 | { |
|
|||
44 | QList<QSeries::LegendEntry> legend; |
|
|||
45 |
|
||||
46 | for (int i=0; i<mDataModel.count(); i++) { |
|
|||
47 | QSeries::LegendEntry l; |
|
|||
48 | l.mName = mDataModel.at(i)->name(); |
|
|||
49 | l.mBrush = mDataModel.at(i)->brush(); |
|
|||
50 | legend.append(l); |
|
|||
51 | } |
|
|||
52 | return legend; |
|
|||
53 | } |
|
|||
54 |
|
||||
55 | int BarChartModel::barsetCount() |
|
42 | int BarChartModel::barsetCount() | |
56 | { |
|
43 | { | |
57 | return mDataModel.count(); |
|
44 | return mDataModel.count(); | |
58 | } |
|
45 | } | |
59 |
|
46 | |||
60 | int BarChartModel::categoryCount() |
|
47 | int BarChartModel::categoryCount() | |
61 | { |
|
48 | { | |
62 | return mCategory.count(); |
|
49 | return mCategory.count(); | |
63 | } |
|
50 | } | |
64 |
|
51 | |||
65 | qreal BarChartModel::min() |
|
52 | qreal BarChartModel::min() | |
66 | { |
|
53 | { | |
67 | Q_ASSERT(mDataModel.count() > 0); |
|
54 | Q_ASSERT(mDataModel.count() > 0); | |
68 | // TODO: make min and max members and update them when data changes. |
|
55 | // TODO: make min and max members and update them when data changes. | |
69 | // This is slower since they are checked every time, even if data is same since previous call. |
|
56 | // This is slower since they are checked every time, even if data is same since previous call. | |
70 | qreal min = INT_MAX; |
|
57 | qreal min = INT_MAX; | |
71 |
|
58 | |||
72 | for (int i=0; i <mDataModel.count(); i++) { |
|
59 | for (int i=0; i <mDataModel.count(); i++) { | |
73 | int itemCount = mDataModel.at(i)->count(); |
|
60 | int itemCount = mDataModel.at(i)->count(); | |
74 | for (int j=0; j<itemCount; j++) { |
|
61 | for (int j=0; j<itemCount; j++) { | |
75 | qreal temp = mDataModel.at(i)->valueAt(j); |
|
62 | qreal temp = mDataModel.at(i)->valueAt(j); | |
76 | if (temp < min) { |
|
63 | if (temp < min) { | |
77 | min = temp; |
|
64 | min = temp; | |
78 | } |
|
65 | } | |
79 | } |
|
66 | } | |
80 | } |
|
67 | } | |
81 | return min; |
|
68 | return min; | |
82 | } |
|
69 | } | |
83 |
|
70 | |||
84 | qreal BarChartModel::max() |
|
71 | qreal BarChartModel::max() | |
85 | { |
|
72 | { | |
86 | Q_ASSERT(mDataModel.count() > 0); |
|
73 | Q_ASSERT(mDataModel.count() > 0); | |
87 |
|
74 | |||
88 | // TODO: make min and max members and update them when data changes. |
|
75 | // TODO: make min and max members and update them when data changes. | |
89 | // This is slower since they are checked every time, even if data is same since previous call. |
|
76 | // This is slower since they are checked every time, even if data is same since previous call. | |
90 | qreal max = INT_MIN; |
|
77 | qreal max = INT_MIN; | |
91 |
|
78 | |||
92 | for (int i=0; i <mDataModel.count(); i++) { |
|
79 | for (int i=0; i <mDataModel.count(); i++) { | |
93 | int itemCount = mDataModel.at(i)->count(); |
|
80 | int itemCount = mDataModel.at(i)->count(); | |
94 | for (int j=0; j<itemCount; j++) { |
|
81 | for (int j=0; j<itemCount; j++) { | |
95 | qreal temp = mDataModel.at(i)->valueAt(j); |
|
82 | qreal temp = mDataModel.at(i)->valueAt(j); | |
96 | if (temp > max) { |
|
83 | if (temp > max) { | |
97 | max = temp; |
|
84 | max = temp; | |
98 | } |
|
85 | } | |
99 | } |
|
86 | } | |
100 | } |
|
87 | } | |
101 |
|
88 | |||
102 | return max; |
|
89 | return max; | |
103 | } |
|
90 | } | |
104 |
|
91 | |||
105 | qreal BarChartModel::valueAt(int set, int category) |
|
92 | qreal BarChartModel::valueAt(int set, int category) | |
106 | { |
|
93 | { | |
107 | if ((set < 0) || (set >= mDataModel.count())) { |
|
94 | if ((set < 0) || (set >= mDataModel.count())) { | |
108 | // No set, no value. |
|
95 | // No set, no value. | |
109 | return 0; |
|
96 | return 0; | |
110 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { |
|
97 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { | |
111 | // No category, no value. |
|
98 | // No category, no value. | |
112 | return 0; |
|
99 | return 0; | |
113 | } |
|
100 | } | |
114 |
|
101 | |||
115 | return mDataModel.at(set)->valueAt(category); |
|
102 | return mDataModel.at(set)->valueAt(category); | |
116 | } |
|
103 | } | |
117 |
|
104 | |||
118 | qreal BarChartModel::percentageAt(int set, int category) |
|
105 | qreal BarChartModel::percentageAt(int set, int category) | |
119 | { |
|
106 | { | |
120 | if ((set < 0) || (set >= mDataModel.count())) { |
|
107 | if ((set < 0) || (set >= mDataModel.count())) { | |
121 | // No set, no value. |
|
108 | // No set, no value. | |
122 | return 0; |
|
109 | return 0; | |
123 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { |
|
110 | } else if ((category < 0) || (category >= mDataModel.at(set)->count())) { | |
124 | // No category, no value. |
|
111 | // No category, no value. | |
125 | return 0; |
|
112 | return 0; | |
126 | } |
|
113 | } | |
127 |
|
114 | |||
128 | qreal value = mDataModel.at(set)->valueAt(category); |
|
115 | qreal value = mDataModel.at(set)->valueAt(category); | |
129 | qreal total = categorySum(category); |
|
116 | qreal total = categorySum(category); | |
130 | if (0 == total) { |
|
117 | if (0 == total) { | |
131 | return 100.0; |
|
118 | return 100.0; | |
132 | } |
|
119 | } | |
133 |
|
120 | |||
134 | return value / total; |
|
121 | return value / total; | |
135 | } |
|
122 | } | |
136 |
|
123 | |||
137 |
|
124 | |||
138 | qreal BarChartModel::categorySum(int category) |
|
125 | qreal BarChartModel::categorySum(int category) | |
139 | { |
|
126 | { | |
140 | qreal sum(0); |
|
127 | qreal sum(0); | |
141 | int count = mDataModel.count(); // Count sets |
|
128 | int count = mDataModel.count(); // Count sets | |
142 |
|
129 | |||
143 | for (int set = 0; set < count; set++) { |
|
130 | for (int set = 0; set < count; set++) { | |
144 | if (category < mDataModel.at(set)->count()) { |
|
131 | if (category < mDataModel.at(set)->count()) { | |
145 | sum += mDataModel.at(set)->valueAt(category); |
|
132 | sum += mDataModel.at(set)->valueAt(category); | |
146 | } |
|
133 | } | |
147 | } |
|
134 | } | |
148 | return sum; |
|
135 | return sum; | |
149 | } |
|
136 | } | |
150 |
|
137 | |||
151 | qreal BarChartModel::maxCategorySum() |
|
138 | qreal BarChartModel::maxCategorySum() | |
152 | { |
|
139 | { | |
153 | qreal max = INT_MIN; |
|
140 | qreal max = INT_MIN; | |
154 | int count = categoryCount(); |
|
141 | int count = categoryCount(); | |
155 |
|
142 | |||
156 | for (int col=0; col<count; col++) { |
|
143 | for (int col=0; col<count; col++) { | |
157 | qreal sum = categorySum(col); |
|
144 | qreal sum = categorySum(col); | |
158 | if (sum > max) { |
|
145 | if (sum > max) { | |
159 | max = sum; |
|
146 | max = sum; | |
160 | } |
|
147 | } | |
161 | } |
|
148 | } | |
162 | return max; |
|
149 | return max; | |
163 | } |
|
150 | } | |
164 |
|
151 | |||
165 | QString BarChartModel::categoryName(int category) |
|
152 | QString BarChartModel::categoryName(int category) | |
166 | { |
|
153 | { | |
167 | return mCategory.at(category); |
|
154 | return mCategory.at(category); | |
168 | } |
|
155 | } | |
169 |
|
156 | |||
170 | #include "moc_barchartmodel_p.cpp" |
|
157 | #include "moc_barchartmodel_p.cpp" | |
171 |
|
158 | |||
172 | QTCOMMERCIALCHART_END_NAMESPACE |
|
159 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,59 +1,57 | |||||
1 | #ifndef BARCHARTMODEL_H |
|
1 | #ifndef BARCHARTMODEL_H | |
2 | #define BARCHARTMODEL_H |
|
2 | #define BARCHARTMODEL_H | |
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 | #include <QStringList> |
|
5 | #include <QStringList> | |
6 | #include "qchartglobal.h" |
|
6 | #include "qchartglobal.h" | |
7 | #include <qseries.h> |
|
7 | #include <qseries.h> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | // Model for bar chart. Internal class. |
|
11 | // Model for bar chart. Internal class. | |
12 | // TODO: Implement as QAbstractItemModel? |
|
12 | // TODO: Implement as QAbstractItemModel? | |
13 |
|
13 | |||
14 | class QBarSet; |
|
14 | class QBarSet; | |
15 |
|
15 | |||
16 | class BarChartModel : public QObject //, public QAbstractItemModel |
|
16 | class BarChartModel : public QObject //, public QAbstractItemModel | |
17 | { |
|
17 | { | |
18 | Q_OBJECT |
|
18 | Q_OBJECT | |
19 | public: |
|
19 | public: | |
20 | explicit BarChartModel(QStringList categories, QObject *parent = 0); |
|
20 | explicit BarChartModel(QStringList categories, QObject *parent = 0); | |
21 |
|
21 | |||
22 | QStringList category(); |
|
22 | QStringList category(); | |
23 | void addBarSet(QBarSet *set); |
|
23 | void addBarSet(QBarSet *set); | |
24 | void removeBarSet(QBarSet *set); |
|
24 | void removeBarSet(QBarSet *set); | |
25 | QBarSet *setAt(int index); |
|
25 | QBarSet *setAt(int index); | |
26 | QList<QBarSet*> barSets(); |
|
26 | QList<QBarSet*> barSets(); | |
27 |
|
27 | |||
28 | QList<QSeries::LegendEntry> legendEntries(); |
|
|||
29 |
|
||||
30 | int barsetCount(); // Number of sets in model |
|
28 | int barsetCount(); // Number of sets in model | |
31 | int categoryCount(); // Number of categories |
|
29 | int categoryCount(); // Number of categories | |
32 |
|
30 | |||
33 | qreal max(); // Maximum value of all sets |
|
31 | qreal max(); // Maximum value of all sets | |
34 | qreal min(); // Minimum value of all sets |
|
32 | qreal min(); // Minimum value of all sets | |
35 | qreal valueAt(int set, int category); |
|
33 | qreal valueAt(int set, int category); | |
36 | qreal percentageAt(int set, int category); |
|
34 | qreal percentageAt(int set, int category); | |
37 |
|
35 | |||
38 | qreal categorySum(int category); |
|
36 | qreal categorySum(int category); | |
39 | qreal maxCategorySum(); // returns maximum sum of sets in all categories. |
|
37 | qreal maxCategorySum(); // returns maximum sum of sets in all categories. | |
40 |
|
38 | |||
41 | QString categoryName(int category); |
|
39 | QString categoryName(int category); | |
42 |
|
40 | |||
43 | signals: |
|
41 | signals: | |
44 | void modelUpdated(); |
|
42 | void modelUpdated(); | |
45 |
|
43 | |||
46 | public slots: |
|
44 | public slots: | |
47 |
|
45 | |||
48 | private: |
|
46 | private: | |
49 |
|
47 | |||
50 | QList<QBarSet*> mDataModel; |
|
48 | QList<QBarSet*> mDataModel; | |
51 | QStringList mCategory; |
|
49 | QStringList mCategory; | |
52 |
|
50 | |||
53 | int mCurrentSet; |
|
51 | int mCurrentSet; | |
54 |
|
52 | |||
55 | }; |
|
53 | }; | |
56 |
|
54 | |||
57 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE | |
58 |
|
56 | |||
59 | #endif // BARCHARTMODEL_H |
|
57 | #endif // BARCHARTMODEL_H |
@@ -1,249 +1,241 | |||||
1 | #include <QDebug> |
|
1 | #include <QDebug> | |
2 | #include "qbarseries.h" |
|
2 | #include "qbarseries.h" | |
3 | #include "qbarset.h" |
|
3 | #include "qbarset.h" | |
4 | #include "barchartmodel_p.h" |
|
4 | #include "barchartmodel_p.h" | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | /*! |
|
8 | /*! | |
9 | \class QBarSeries |
|
9 | \class QBarSeries | |
10 | \brief part of QtCommercial chart API. |
|
10 | \brief part of QtCommercial chart API. | |
11 |
|
11 | |||
12 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible |
|
12 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible | |
13 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
13 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
14 | by QStringList. |
|
14 | by QStringList. | |
15 |
|
15 | |||
16 | \mainclass |
|
16 | \mainclass | |
17 |
|
17 | |||
18 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
18 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
19 | */ |
|
19 | */ | |
20 |
|
20 | |||
21 | /*! |
|
21 | /*! | |
22 | \fn virtual QSeriesType QBarSeries::type() const |
|
22 | \fn virtual QSeriesType QBarSeries::type() const | |
23 | \brief Returns type of series. |
|
23 | \brief Returns type of series. | |
24 | \sa QSeries, QSeriesType |
|
24 | \sa QSeries, QSeriesType | |
25 | */ |
|
25 | */ | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) |
|
28 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | |
29 | \brief \internal \a pos \a tip |
|
29 | \brief \internal \a pos \a tip | |
30 | */ |
|
30 | */ | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
33 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
34 | QBarSeries is QObject which is a child of a \a parent. |
|
34 | QBarSeries is QObject which is a child of a \a parent. | |
35 | */ |
|
35 | */ | |
36 | QBarSeries::QBarSeries(QStringList categories, QObject *parent) |
|
36 | QBarSeries::QBarSeries(QStringList categories, QObject *parent) | |
37 | : QSeries(parent) |
|
37 | : QSeries(parent) | |
38 | ,mModel(new BarChartModel(categories, this)) |
|
38 | ,mModel(new BarChartModel(categories, this)) | |
39 | { |
|
39 | { | |
40 | m_model = NULL; |
|
40 | m_model = NULL; | |
41 | m_mapCategories = -1; |
|
41 | m_mapCategories = -1; | |
42 | m_mapBarBottom - 1; |
|
42 | m_mapBarBottom - 1; | |
43 | m_mapBarTop - 1; |
|
43 | m_mapBarTop - 1; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | /*! |
|
46 | /*! | |
47 | Adds a set of bars to series. Takes ownership of \a set. |
|
47 | Adds a set of bars to series. Takes ownership of \a set. | |
48 | Connects the clicked(QString) and rightClicked(QString) signals |
|
48 | Connects the clicked(QString) and rightClicked(QString) signals | |
49 | of \a set to this series |
|
49 | of \a set to this series | |
50 | */ |
|
50 | */ | |
51 | void QBarSeries::addBarSet(QBarSet *set) |
|
51 | void QBarSeries::addBarSet(QBarSet *set) | |
52 | { |
|
52 | { | |
53 | mModel->addBarSet(set); |
|
53 | mModel->addBarSet(set); | |
54 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
54 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | |
55 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
55 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
59 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | |
60 | Disconnects the clicked(QString) and rightClicked(QString) signals |
|
60 | Disconnects the clicked(QString) and rightClicked(QString) signals | |
61 | of \a set from this series |
|
61 | of \a set from this series | |
62 | */ |
|
62 | */ | |
63 | void QBarSeries::removeBarSet(QBarSet *set) |
|
63 | void QBarSeries::removeBarSet(QBarSet *set) | |
64 | { |
|
64 | { | |
65 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
65 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | |
66 | disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
66 | disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); | |
67 | mModel->removeBarSet(set); |
|
67 | mModel->removeBarSet(set); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | Returns number of sets in series. |
|
71 | Returns number of sets in series. | |
72 | */ |
|
72 | */ | |
73 | int QBarSeries::barsetCount() |
|
73 | int QBarSeries::barsetCount() | |
74 | { |
|
74 | { | |
75 | if(m_model) |
|
75 | if(m_model) | |
76 | return m_mapBarTop - m_mapBarBottom; |
|
76 | return m_mapBarTop - m_mapBarBottom; | |
77 | else |
|
77 | else | |
78 | return mModel->barsetCount(); |
|
78 | return mModel->barsetCount(); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | Returns number of categories in series |
|
82 | Returns number of categories in series | |
83 | */ |
|
83 | */ | |
84 | int QBarSeries::categoryCount() |
|
84 | int QBarSeries::categoryCount() | |
85 | { |
|
85 | { | |
86 | return mModel->categoryCount(); |
|
86 | return mModel->categoryCount(); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | Returns a list of sets in series. Keeps ownership of sets. |
|
90 | Returns a list of sets in series. Keeps ownership of sets. | |
91 | */ |
|
91 | */ | |
92 | QList<QBarSet*> QBarSeries::barSets() |
|
92 | QList<QBarSet*> QBarSeries::barSets() | |
93 | { |
|
93 | { | |
94 | return mModel->barSets(); |
|
94 | return mModel->barSets(); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | /*! |
|
97 | /*! | |
98 | \internal \a index |
|
98 | \internal \a index | |
99 | */ |
|
99 | */ | |
100 | QBarSet* QBarSeries::barsetAt(int index) |
|
100 | QBarSet* QBarSeries::barsetAt(int index) | |
101 | { |
|
101 | { | |
102 | return mModel->setAt(index); |
|
102 | return mModel->setAt(index); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | Returns legend of series. |
|
|||
107 | */ |
|
|||
108 | QList<QSeries::LegendEntry> QBarSeries::legendEntries() |
|
|||
109 | { |
|
|||
110 | return mModel->legendEntries(); |
|
|||
111 | } |
|
|||
112 |
|
||||
113 | /*! |
|
|||
114 | \internal \a category |
|
106 | \internal \a category | |
115 | */ |
|
107 | */ | |
116 | QString QBarSeries::categoryName(int category) |
|
108 | QString QBarSeries::categoryName(int category) | |
117 | { |
|
109 | { | |
118 | return mModel->categoryName(category); |
|
110 | return mModel->categoryName(category); | |
119 | } |
|
111 | } | |
120 |
|
112 | |||
121 | /*! |
|
113 | /*! | |
122 | Enables or disables tooltip depending on parameter \a enabled. |
|
114 | Enables or disables tooltip depending on parameter \a enabled. | |
123 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
115 | Tooltip shows the name of set, when mouse is hovering on top of bar. | |
124 | Calling without parameter \a enabled, enables the tooltip |
|
116 | Calling without parameter \a enabled, enables the tooltip | |
125 | */ |
|
117 | */ | |
126 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
118 | void QBarSeries::setToolTipEnabled(bool enabled) | |
127 | { |
|
119 | { | |
128 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
120 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
129 | if (enabled) { |
|
121 | if (enabled) { | |
130 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
122 | for (int i=0; i<mModel->barsetCount(); i++) { | |
131 | QBarSet *set = mModel->setAt(i); |
|
123 | QBarSet *set = mModel->setAt(i); | |
132 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
124 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | |
133 | } |
|
125 | } | |
134 | } else { |
|
126 | } else { | |
135 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
127 | for (int i=0; i<mModel->barsetCount(); i++) { | |
136 | QBarSet *set = mModel->setAt(i); |
|
128 | QBarSet *set = mModel->setAt(i); | |
137 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
129 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | |
138 | } |
|
130 | } | |
139 | } |
|
131 | } | |
140 | } |
|
132 | } | |
141 |
|
133 | |||
142 | /*! |
|
134 | /*! | |
143 | Enables or disables separators depending on parameter \a enabled. |
|
135 | Enables or disables separators depending on parameter \a enabled. | |
144 | Separators are visual elements that are drawn between categories. |
|
136 | Separators are visual elements that are drawn between categories. | |
145 | Calling without parameter \a enabled, enables the separators |
|
137 | Calling without parameter \a enabled, enables the separators | |
146 | */ |
|
138 | */ | |
147 | void QBarSeries::setSeparatorsVisible(bool visible) |
|
139 | void QBarSeries::setSeparatorsVisible(bool visible) | |
148 | { |
|
140 | { | |
149 | mSeparatorsVisible = visible; |
|
141 | mSeparatorsVisible = visible; | |
150 | emit enableSeparators(visible); |
|
142 | emit enableSeparators(visible); | |
151 | } |
|
143 | } | |
152 |
|
144 | |||
153 |
|
145 | |||
154 | /*! |
|
146 | /*! | |
155 | \internal \a category |
|
147 | \internal \a category | |
156 | */ |
|
148 | */ | |
157 | void QBarSeries::barsetClicked(QString category) |
|
149 | void QBarSeries::barsetClicked(QString category) | |
158 | { |
|
150 | { | |
159 | emit clicked(qobject_cast<QBarSet*>(sender()), category); |
|
151 | emit clicked(qobject_cast<QBarSet*>(sender()), category); | |
160 | } |
|
152 | } | |
161 |
|
153 | |||
162 | /*! |
|
154 | /*! | |
163 | \internal \a category |
|
155 | \internal \a category | |
164 | */ |
|
156 | */ | |
165 | void QBarSeries::barsetRightClicked(QString category) |
|
157 | void QBarSeries::barsetRightClicked(QString category) | |
166 | { |
|
158 | { | |
167 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); |
|
159 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); | |
168 | } |
|
160 | } | |
169 |
|
161 | |||
170 |
|
162 | |||
171 | /*! |
|
163 | /*! | |
172 | \internal |
|
164 | \internal | |
173 | */ |
|
165 | */ | |
174 | qreal QBarSeries::min() |
|
166 | qreal QBarSeries::min() | |
175 | { |
|
167 | { | |
176 | return mModel->min(); |
|
168 | return mModel->min(); | |
177 | } |
|
169 | } | |
178 |
|
170 | |||
179 | /*! |
|
171 | /*! | |
180 | \internal |
|
172 | \internal | |
181 | */ |
|
173 | */ | |
182 | qreal QBarSeries::max() |
|
174 | qreal QBarSeries::max() | |
183 | { |
|
175 | { | |
184 | return mModel->max(); |
|
176 | return mModel->max(); | |
185 | } |
|
177 | } | |
186 |
|
178 | |||
187 | /*! |
|
179 | /*! | |
188 | \internal \a set \a category |
|
180 | \internal \a set \a category | |
189 | */ |
|
181 | */ | |
190 | qreal QBarSeries::valueAt(int set, int category) |
|
182 | qreal QBarSeries::valueAt(int set, int category) | |
191 | { |
|
183 | { | |
192 | return mModel->valueAt(set,category); |
|
184 | return mModel->valueAt(set,category); | |
193 | } |
|
185 | } | |
194 |
|
186 | |||
195 | /*! |
|
187 | /*! | |
196 | \internal \a set \a category |
|
188 | \internal \a set \a category | |
197 | */ |
|
189 | */ | |
198 | qreal QBarSeries::percentageAt(int set, int category) |
|
190 | qreal QBarSeries::percentageAt(int set, int category) | |
199 | { |
|
191 | { | |
200 | return mModel->percentageAt(set,category); |
|
192 | return mModel->percentageAt(set,category); | |
201 | } |
|
193 | } | |
202 |
|
194 | |||
203 | /*! |
|
195 | /*! | |
204 | \internal \a category |
|
196 | \internal \a category | |
205 | */ |
|
197 | */ | |
206 | qreal QBarSeries::categorySum(int category) |
|
198 | qreal QBarSeries::categorySum(int category) | |
207 | { |
|
199 | { | |
208 | return mModel->categorySum(category); |
|
200 | return mModel->categorySum(category); | |
209 | } |
|
201 | } | |
210 |
|
202 | |||
211 | /*! |
|
203 | /*! | |
212 | \internal |
|
204 | \internal | |
213 | */ |
|
205 | */ | |
214 | qreal QBarSeries::maxCategorySum() |
|
206 | qreal QBarSeries::maxCategorySum() | |
215 | { |
|
207 | { | |
216 | return mModel->maxCategorySum(); |
|
208 | return mModel->maxCategorySum(); | |
217 | } |
|
209 | } | |
218 |
|
210 | |||
219 | /*! |
|
211 | /*! | |
220 | \internal |
|
212 | \internal | |
221 | */ |
|
213 | */ | |
222 | BarChartModel& QBarSeries::model() |
|
214 | BarChartModel& QBarSeries::model() | |
223 | { |
|
215 | { | |
224 | return *mModel; |
|
216 | return *mModel; | |
225 | } |
|
217 | } | |
226 |
|
218 | |||
227 | bool QBarSeries::separatorsVisible() |
|
219 | bool QBarSeries::separatorsVisible() | |
228 | { |
|
220 | { | |
229 | return mSeparatorsVisible; |
|
221 | return mSeparatorsVisible; | |
230 | } |
|
222 | } | |
231 |
|
223 | |||
232 | bool QBarSeries::setModel(QAbstractItemModel* model) |
|
224 | bool QBarSeries::setModel(QAbstractItemModel* model) | |
233 | { |
|
225 | { | |
234 | m_model = model; |
|
226 | m_model = model; | |
235 | } |
|
227 | } | |
236 |
|
228 | |||
237 | void QBarSeries::setModelMappingCategories(int modelColumn) |
|
229 | void QBarSeries::setModelMappingCategories(int modelColumn) | |
238 | { |
|
230 | { | |
239 | // |
|
231 | // | |
240 | } |
|
232 | } | |
241 |
|
233 | |||
242 | void QBarSeries::setModelMappingBarRange(int bottomBoundry, int topBoundry) |
|
234 | void QBarSeries::setModelMappingBarRange(int bottomBoundry, int topBoundry) | |
243 | { |
|
235 | { | |
244 | // |
|
236 | // | |
245 | } |
|
237 | } | |
246 |
|
238 | |||
247 | #include "moc_qbarseries.cpp" |
|
239 | #include "moc_qbarseries.cpp" | |
248 |
|
240 | |||
249 | QTCOMMERCIALCHART_END_NAMESPACE |
|
241 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,82 +1,81 | |||||
1 | #ifndef BARSERIES_H |
|
1 | #ifndef BARSERIES_H | |
2 | #define BARSERIES_H |
|
2 | #define BARSERIES_H | |
3 |
|
3 | |||
4 | #include "qseries.h" |
|
4 | #include "qseries.h" | |
5 | #include <QStringList> |
|
5 | #include <QStringList> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | class QBarSet; |
|
9 | class QBarSet; | |
10 | class BarChartModel; |
|
10 | class BarChartModel; | |
11 | class BarCategory; |
|
11 | class BarCategory; | |
12 |
|
12 | |||
13 | // Container for series |
|
13 | // Container for series | |
14 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries |
|
14 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries | |
15 | { |
|
15 | { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 | public: |
|
17 | public: | |
18 | QBarSeries(QStringList categories, QObject* parent=0); |
|
18 | QBarSeries(QStringList categories, QObject* parent=0); | |
19 |
|
19 | |||
20 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } |
|
20 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } | |
21 |
|
21 | |||
22 | void addBarSet(QBarSet *set); // Takes ownership of set |
|
22 | void addBarSet(QBarSet *set); // Takes ownership of set | |
23 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
23 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
24 | int barsetCount(); |
|
24 | int barsetCount(); | |
25 | int categoryCount(); |
|
25 | int categoryCount(); | |
26 | QList<QBarSet*> barSets(); |
|
26 | QList<QBarSet*> barSets(); | |
27 | QList<QSeries::LegendEntry> legendEntries(); |
|
|||
28 |
|
27 | |||
29 | bool setModel(QAbstractItemModel* model); |
|
28 | bool setModel(QAbstractItemModel* model); | |
30 | QAbstractItemModel* modelExt() {return m_model;} |
|
29 | QAbstractItemModel* modelExt() {return m_model;} | |
31 | void setModelMappingCategories(int modelColumn); |
|
30 | void setModelMappingCategories(int modelColumn); | |
32 | void setModelMappingBarRange(int bottomBoundry, int topBoundry); |
|
31 | void setModelMappingBarRange(int bottomBoundry, int topBoundry); | |
33 |
|
32 | |||
34 | public: |
|
33 | public: | |
35 | // TODO: Functions below this are not part of api and will be moved |
|
34 | // TODO: Functions below this are not part of api and will be moved | |
36 | // to private implementation, when we start using it |
|
35 | // to private implementation, when we start using it | |
37 | // TODO: TO PIMPL ---> |
|
36 | // TODO: TO PIMPL ---> | |
38 | QBarSet* barsetAt(int index); |
|
37 | QBarSet* barsetAt(int index); | |
39 | QString categoryName(int category); |
|
38 | QString categoryName(int category); | |
40 | qreal min(); |
|
39 | qreal min(); | |
41 | qreal max(); |
|
40 | qreal max(); | |
42 | qreal valueAt(int set, int category); |
|
41 | qreal valueAt(int set, int category); | |
43 | qreal percentageAt(int set, int category); |
|
42 | qreal percentageAt(int set, int category); | |
44 | qreal categorySum(int category); |
|
43 | qreal categorySum(int category); | |
45 | qreal maxCategorySum(); |
|
44 | qreal maxCategorySum(); | |
46 | BarChartModel& model(); |
|
45 | BarChartModel& model(); | |
47 | bool separatorsVisible(); |
|
46 | bool separatorsVisible(); | |
48 | // <--- TO PIMPL |
|
47 | // <--- TO PIMPL | |
49 |
|
48 | |||
50 | signals: |
|
49 | signals: | |
51 | //void changed(int index); |
|
50 | //void changed(int index); | |
52 | void clicked(QBarSet* barset, QString category); // Up to user of api, what to do with these signals |
|
51 | void clicked(QBarSet* barset, QString category); // Up to user of api, what to do with these signals | |
53 | void rightClicked(QBarSet* barset, QString category); |
|
52 | void rightClicked(QBarSet* barset, QString category); | |
54 |
|
53 | |||
55 | // TODO: internal signals, these to private implementation. |
|
54 | // TODO: internal signals, these to private implementation. | |
56 | // TODO: TO PIMPL ---> |
|
55 | // TODO: TO PIMPL ---> | |
57 | void enableSeparators(bool enable); |
|
56 | void enableSeparators(bool enable); | |
58 | void showToolTip(QPoint pos, QString tip); |
|
57 | void showToolTip(QPoint pos, QString tip); | |
59 | // <--- TO PIMPL |
|
58 | // <--- TO PIMPL | |
60 |
|
59 | |||
61 | public Q_SLOTS: |
|
60 | public Q_SLOTS: | |
62 | void setToolTipEnabled(bool enabled=true); // enables tooltips |
|
61 | void setToolTipEnabled(bool enabled=true); // enables tooltips | |
63 | void setSeparatorsVisible(bool visible=true); // enables separators between categories |
|
62 | void setSeparatorsVisible(bool visible=true); // enables separators between categories | |
64 |
|
63 | |||
65 | // TODO: TO PIMPL ---> |
|
64 | // TODO: TO PIMPL ---> | |
66 | void barsetClicked(QString category); |
|
65 | void barsetClicked(QString category); | |
67 | void barsetRightClicked(QString category); |
|
66 | void barsetRightClicked(QString category); | |
68 | // <--- TO PIMPL |
|
67 | // <--- TO PIMPL | |
69 |
|
68 | |||
70 | protected: |
|
69 | protected: | |
71 | BarChartModel* mModel; |
|
70 | BarChartModel* mModel; | |
72 | bool mSeparatorsVisible; |
|
71 | bool mSeparatorsVisible; | |
73 |
|
72 | |||
74 | QAbstractItemModel* m_model; |
|
73 | QAbstractItemModel* m_model; | |
75 | int m_mapCategories; |
|
74 | int m_mapCategories; | |
76 | int m_mapBarBottom; |
|
75 | int m_mapBarBottom; | |
77 | int m_mapBarTop; |
|
76 | int m_mapBarTop; | |
78 | }; |
|
77 | }; | |
79 |
|
78 | |||
80 | QTCOMMERCIALCHART_END_NAMESPACE |
|
79 | QTCOMMERCIALCHART_END_NAMESPACE | |
81 |
|
80 | |||
82 | #endif // BARSERIES_H |
|
81 | #endif // BARSERIES_H |
@@ -1,56 +1,53 | |||||
1 | #ifndef QSERIES_H |
|
1 | #ifndef QSERIES_H | |
2 | #define QSERIES_H |
|
2 | #define QSERIES_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include <QAbstractItemModel> |
|
6 | #include <QAbstractItemModel> | |
7 | #include <QPen> |
|
7 | #include <QPen> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class QTCOMMERCIALCHART_EXPORT QSeries : public QObject |
|
11 | class QTCOMMERCIALCHART_EXPORT QSeries : public QObject | |
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
14 | public: |
|
14 | public: | |
15 | enum QSeriesType { |
|
15 | enum QSeriesType { | |
16 | SeriesTypeLine, |
|
16 | SeriesTypeLine, | |
17 | SeriesTypeArea, |
|
17 | SeriesTypeArea, | |
18 | SeriesTypeBar, |
|
18 | SeriesTypeBar, | |
19 | SeriesTypeStackedBar, |
|
19 | SeriesTypeStackedBar, | |
20 | SeriesTypePercentBar, |
|
20 | SeriesTypePercentBar, | |
21 | SeriesTypePie, |
|
21 | SeriesTypePie, | |
22 | SeriesTypeScatter, |
|
22 | SeriesTypeScatter, | |
23 | SeriesTypeSpline |
|
23 | SeriesTypeSpline | |
24 | }; |
|
24 | }; | |
25 |
|
25 | |||
26 | // Helper class to contain legend and color for it |
|
26 | // Helper class to contain legend and color for it | |
27 | // TODO: This is actually quite close to current LegendMarker.. combine them? |
|
27 | // TODO: This is actually quite close to current LegendMarker.. combine them? | |
28 | class LegendEntry { |
|
28 | /* class LegendEntry { | |
29 | public: |
|
29 | public: | |
30 | QString mName; |
|
30 | QString mName; | |
31 | QBrush mBrush; |
|
31 | /QBrush mBrush; | |
32 |
|
|
32 | };*/ | |
33 |
|
33 | |||
34 | protected: |
|
34 | protected: | |
35 | QSeries(QObject *parent = 0) : QObject(parent) {} |
|
35 | QSeries(QObject *parent = 0) : QObject(parent) {} | |
36 |
|
36 | |||
37 | public: |
|
37 | public: | |
38 | virtual ~QSeries() {} |
|
38 | virtual ~QSeries() {} | |
39 | virtual QSeriesType type() const = 0; |
|
39 | virtual QSeriesType type() const = 0; | |
40 | QString name() { return QString("TODO: Name QSeries"); } |
|
40 | QString name() { return QString("TODO: Name QSeries"); } | |
41 | // TODO |
|
41 | // TODO | |
42 | virtual bool setModel(QAbstractItemModel* /*model*/) { return false; } |
|
42 | virtual bool setModel(QAbstractItemModel* /*model*/) { return false; } | |
43 |
|
43 | |||
44 | // TODO: consider this |
|
|||
45 | virtual QList<QSeries::LegendEntry> legendEntries() { QList<QSeries::LegendEntry> l; return l; } |
|
|||
46 |
|
||||
47 | void setTitle(QString title) { m_title = title; } |
|
44 | void setTitle(QString title) { m_title = title; } | |
48 | QString title() { return m_title; } |
|
45 | QString title() { return m_title; } | |
49 |
|
46 | |||
50 | private: |
|
47 | private: | |
51 | QString m_title; |
|
48 | QString m_title; | |
52 | }; |
|
49 | }; | |
53 |
|
50 | |||
54 | QTCOMMERCIALCHART_END_NAMESPACE |
|
51 | QTCOMMERCIALCHART_END_NAMESPACE | |
55 |
|
52 | |||
56 | #endif |
|
53 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now