@@ -1,665 +1,665 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 |
|
30 | |||
31 | #include <QAbstractItemModel> |
|
31 | #include <QAbstractItemModel> | |
32 | #include <QModelIndex> |
|
32 | #include <QModelIndex> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \class QBarSeries |
|
37 | \class QBarSeries | |
38 | \brief part of QtCommercial chart API. |
|
38 | \brief part of QtCommercial chart API. | |
39 | \mainclass |
|
39 | \mainclass | |
40 |
|
40 | |||
41 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple |
|
41 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple | |
42 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
42 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
43 | by QStringList. |
|
43 | by QStringList. | |
44 |
|
44 | |||
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
46 | \image examples_barchart.png |
|
46 | \image examples_barchart.png | |
47 |
|
47 | |||
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | \fn void QBarSeries::clicked(QBarSet *barset, QString category) |
|
52 | \fn void QBarSeries::clicked(QBarSet *barset, QString category) | |
53 |
|
53 | |||
54 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category |
|
54 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category | |
55 | contained by the series. |
|
55 | contained by the series. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
59 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) | |
60 |
|
60 | |||
61 | The signal is emitted if mouse is hovered on top of series. |
|
61 | The signal is emitted if mouse is hovered on top of series. | |
62 | Parameter \a barset is the pointer of barset, where hover happened. |
|
62 | Parameter \a barset is the pointer of barset, where hover happened. | |
63 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
63 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
67 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
68 | QBarSeries is QObject which is a child of a \a parent. |
|
68 | QBarSeries is QObject which is a child of a \a parent. | |
69 | */ |
|
69 | */ | |
70 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : |
|
70 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : | |
71 | QAbstractSeries(*new QBarSeriesPrivate(categories, this),parent) |
|
71 | QAbstractSeries(*new QBarSeriesPrivate(categories, this),parent) | |
72 | { |
|
72 | { | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | /*! |
|
75 | /*! | |
76 | Destructs barseries and owned barsets. |
|
76 | Destructs barseries and owned barsets. | |
77 | */ |
|
77 | */ | |
78 | QBarSeries::~QBarSeries() |
|
78 | QBarSeries::~QBarSeries() | |
79 | { |
|
79 | { | |
80 | // NOTE: d_ptr destroyed by QObject |
|
80 | // NOTE: d_ptr destroyed by QObject | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \internal |
|
84 | \internal | |
85 | */ |
|
85 | */ | |
86 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
86 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : | |
87 | QAbstractSeries(d,parent) |
|
87 | QAbstractSeries(d,parent) | |
88 | { |
|
88 | { | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | Returns the type of series. Derived classes override this. |
|
92 | Returns the type of series. Derived classes override this. | |
93 | */ |
|
93 | */ | |
94 | QAbstractSeries::QSeriesType QBarSeries::type() const |
|
94 | QAbstractSeries::QSeriesType QBarSeries::type() const | |
95 | { |
|
95 | { | |
96 | return QAbstractSeries::SeriesTypeBar; |
|
96 | return QAbstractSeries::SeriesTypeBar; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | Adds a set of bars to series. Takes ownership of \a set. |
|
100 | Adds a set of bars to series. Takes ownership of \a set. | |
101 | */ |
|
101 | */ | |
102 | void QBarSeries::appendBarSet(QBarSet *set) |
|
102 | void QBarSeries::appendBarSet(QBarSet *set) | |
103 | { |
|
103 | { | |
104 | Q_D(QBarSeries); |
|
104 | Q_D(QBarSeries); | |
105 | d->m_barSets.append(set); |
|
105 | d->m_barSets.append(set); | |
106 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
106 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
107 | emit d->restructuredBars(); |
|
107 | emit d->restructuredBars(); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
111 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
112 | */ |
|
112 | */ | |
113 | void QBarSeries::removeBarSet(QBarSet *set) |
|
113 | void QBarSeries::removeBarSet(QBarSet *set) | |
114 | { |
|
114 | { | |
115 | Q_D(QBarSeries); |
|
115 | Q_D(QBarSeries); | |
116 | if (d->m_barSets.contains(set)) { |
|
116 | if (d->m_barSets.contains(set)) { | |
117 | d->m_barSets.removeOne(set); |
|
117 | d->m_barSets.removeOne(set); | |
118 |
QObject::disconnect(set, SIGNAL(updatedBars()), |
|
118 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
119 | emit d->restructuredBars(); |
|
119 | emit d->restructuredBars(); | |
120 | } |
|
120 | } | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
124 | Adds a list of barsets to series. Takes ownership of \a sets. | |
125 | */ |
|
125 | */ | |
126 | void QBarSeries::appendBarSets(QList<QBarSet* > sets) |
|
126 | void QBarSeries::appendBarSets(QList<QBarSet* > sets) | |
127 | { |
|
127 | { | |
128 | Q_D(QBarSeries); |
|
128 | Q_D(QBarSeries); | |
129 | foreach (QBarSet* set, sets) { |
|
129 | foreach (QBarSet* set, sets) { | |
130 | d->m_barSets.append(set); |
|
130 | d->m_barSets.append(set); | |
131 |
QObject::connect(set, SIGNAL(updatedBars()), |
|
131 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
132 | } |
|
132 | } | |
133 | emit d->restructuredBars(); |
|
133 | emit d->restructuredBars(); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. |
|
137 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. | |
138 | */ |
|
138 | */ | |
139 | void QBarSeries::removeBarSets(QList<QBarSet* > sets) |
|
139 | void QBarSeries::removeBarSets(QList<QBarSet* > sets) | |
140 | { |
|
140 | { | |
141 | Q_D(QBarSeries); |
|
141 | Q_D(QBarSeries); | |
142 |
|
142 | |||
143 | foreach (QBarSet* set, sets) { |
|
143 | foreach (QBarSet* set, sets) { | |
144 | if (d->m_barSets.contains(set)) { |
|
144 | if (d->m_barSets.contains(set)) { | |
145 | d->m_barSets.removeOne(set); |
|
145 | d->m_barSets.removeOne(set); | |
146 |
QObject::disconnect(set, SIGNAL(updatedBars()), |
|
146 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
147 | } |
|
147 | } | |
148 | } |
|
148 | } | |
149 | emit d->restructuredBars(); |
|
149 | emit d->restructuredBars(); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | Returns number of sets in series. |
|
153 | Returns number of sets in series. | |
154 | */ |
|
154 | */ | |
155 | int QBarSeries::barsetCount() const |
|
155 | int QBarSeries::barsetCount() const | |
156 | { |
|
156 | { | |
157 | Q_D(const QBarSeries); |
|
157 | Q_D(const QBarSeries); | |
158 | return d->m_barSets.count(); |
|
158 | return d->m_barSets.count(); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | Returns number of categories in series |
|
162 | Returns number of categories in series | |
163 | */ |
|
163 | */ | |
164 | int QBarSeries::categoryCount() const |
|
164 | int QBarSeries::categoryCount() const | |
165 | { |
|
165 | { | |
166 | Q_D(const QBarSeries); |
|
166 | Q_D(const QBarSeries); | |
167 | return d->m_categories.count(); |
|
167 | return d->m_categories.count(); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | Returns a list of sets in series. Keeps ownership of sets. |
|
171 | Returns a list of sets in series. Keeps ownership of sets. | |
172 | */ |
|
172 | */ | |
173 | QList<QBarSet*> QBarSeries::barSets() const |
|
173 | QList<QBarSet*> QBarSeries::barSets() const | |
174 | { |
|
174 | { | |
175 | Q_D(const QBarSeries); |
|
175 | Q_D(const QBarSeries); | |
176 | return d->m_barSets; |
|
176 | return d->m_barSets; | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) |
|
180 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) | |
181 | Sets the \a model to be used as a data source |
|
181 | Sets the \a model to be used as a data source | |
182 | */ |
|
182 | */ | |
183 | bool QBarSeries::setModel(QAbstractItemModel *model) |
|
183 | bool QBarSeries::setModel(QAbstractItemModel *model) | |
184 | { |
|
184 | { | |
185 | Q_D(QBarSeries); |
|
185 | Q_D(QBarSeries); | |
186 | return d->setModel(model); |
|
186 | return d->setModel(model); | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | /*! |
|
189 | /*! | |
190 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
190 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
191 | Sets column/row specified by \a categories to be used as a list of bar series categories. |
|
191 | Sets column/row specified by \a categories to be used as a list of bar series categories. | |
192 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. |
|
192 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. | |
193 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. |
|
193 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. | |
194 | All the columns/rows inbetween those two values are also used as data for bar sets. |
|
194 | All the columns/rows inbetween those two values are also used as data for bar sets. | |
195 | The \a orientation parameter specifies whether the data is in columns or in rows. |
|
195 | The \a orientation parameter specifies whether the data is in columns or in rows. | |
196 | */ |
|
196 | */ | |
197 | void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation) |
|
197 | void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation) | |
198 | { |
|
198 | { | |
199 | Q_D(QBarSeries); |
|
199 | Q_D(QBarSeries); | |
200 | d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); |
|
200 | d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | void QBarSeries::setModelMappingRange(int first, int count) |
|
203 | void QBarSeries::setModelMappingRange(int first, int count) | |
204 | { |
|
204 | { | |
205 | Q_D(QBarSeries); |
|
205 | Q_D(QBarSeries); | |
206 | d->setModelMappingRange(first, count); |
|
206 | d->setModelMappingRange(first, count); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | Returns the bar categories of the series. |
|
210 | Returns the bar categories of the series. | |
211 | */ |
|
211 | */ | |
212 | QBarCategories QBarSeries::categories() const |
|
212 | QBarCategories QBarSeries::categories() const | |
213 | { |
|
213 | { | |
214 | Q_D(const QBarSeries); |
|
214 | Q_D(const QBarSeries); | |
215 | return d->m_categories; |
|
215 | return d->m_categories; | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | /*! |
|
218 | /*! | |
219 | Sets the visibility of labels in series to \a visible |
|
219 | Sets the visibility of labels in series to \a visible | |
220 | */ |
|
220 | */ | |
221 | void QBarSeries::setLabelsVisible(bool visible) |
|
221 | void QBarSeries::setLabelsVisible(bool visible) | |
222 | { |
|
222 | { | |
223 | foreach (QBarSet* s, barSets()) { |
|
223 | foreach (QBarSet* s, barSets()) { | |
224 | s->setLabelsVisible(visible); |
|
224 | s->setLabelsVisible(visible); | |
225 | } |
|
225 | } | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
228 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
229 |
|
229 | |||
230 | QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : |
|
230 | QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : | |
231 | QAbstractSeriesPrivate(q), |
|
231 | QAbstractSeriesPrivate(q), | |
232 | m_categories(categories), |
|
232 | m_categories(categories), | |
233 | m_mapCategories(-1), |
|
233 | m_mapCategories(-1), | |
234 | m_mapBarBottom(-1), |
|
234 | m_mapBarBottom(-1), | |
235 | m_mapBarTop(-1) |
|
235 | m_mapBarTop(-1) | |
236 | { |
|
236 | { | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
239 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
240 | { |
|
240 | { | |
241 | return m_barSets.at(index); |
|
241 | return m_barSets.at(index); | |
242 | } |
|
242 | } | |
243 |
|
243 | |||
244 | QString QBarSeriesPrivate::categoryName(int category) |
|
244 | QString QBarSeriesPrivate::categoryName(int category) | |
245 | { |
|
245 | { | |
246 | return m_categories.at(category); |
|
246 | return m_categories.at(category); | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | qreal QBarSeriesPrivate::min() |
|
249 | qreal QBarSeriesPrivate::min() | |
250 | { |
|
250 | { | |
251 | if (m_barSets.count() <= 0) { |
|
251 | if (m_barSets.count() <= 0) { | |
252 | return 0; |
|
252 | return 0; | |
253 | } |
|
253 | } | |
254 | qreal min = INT_MAX; |
|
254 | qreal min = INT_MAX; | |
255 |
|
255 | |||
256 | for (int i = 0; i < m_barSets.count(); i++) { |
|
256 | for (int i = 0; i < m_barSets.count(); i++) { | |
257 | int categoryCount = m_barSets.at(i)->count(); |
|
257 | int categoryCount = m_barSets.at(i)->count(); | |
258 | for (int j = 0; j < categoryCount; j++) { |
|
258 | for (int j = 0; j < categoryCount; j++) { | |
259 | qreal temp = m_barSets.at(i)->at(j); |
|
259 | qreal temp = m_barSets.at(i)->at(j); | |
260 | if (temp < min) |
|
260 | if (temp < min) | |
261 | min = temp; |
|
261 | min = temp; | |
262 | } |
|
262 | } | |
263 | } |
|
263 | } | |
264 | return min; |
|
264 | return min; | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | qreal QBarSeriesPrivate::max() |
|
267 | qreal QBarSeriesPrivate::max() | |
268 | { |
|
268 | { | |
269 | if (m_barSets.count() <= 0) { |
|
269 | if (m_barSets.count() <= 0) { | |
270 | return 0; |
|
270 | return 0; | |
271 | } |
|
271 | } | |
272 | qreal max = INT_MIN; |
|
272 | qreal max = INT_MIN; | |
273 |
|
273 | |||
274 | for (int i = 0; i < m_barSets.count(); i++) { |
|
274 | for (int i = 0; i < m_barSets.count(); i++) { | |
275 | int categoryCount = m_barSets.at(i)->count(); |
|
275 | int categoryCount = m_barSets.at(i)->count(); | |
276 | for (int j = 0; j < categoryCount; j++) { |
|
276 | for (int j = 0; j < categoryCount; j++) { | |
277 | qreal temp = m_barSets.at(i)->at(j); |
|
277 | qreal temp = m_barSets.at(i)->at(j); | |
278 | if (temp > max) |
|
278 | if (temp > max) | |
279 | max = temp; |
|
279 | max = temp; | |
280 | } |
|
280 | } | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | return max; |
|
283 | return max; | |
284 | } |
|
284 | } | |
285 |
|
285 | |||
286 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
286 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
287 | { |
|
287 | { | |
288 | if ((set < 0) || (set >= m_barSets.count())) { |
|
288 | if ((set < 0) || (set >= m_barSets.count())) { | |
289 | // No set, no value. |
|
289 | // No set, no value. | |
290 | return 0; |
|
290 | return 0; | |
291 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
291 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
292 | // No category, no value. |
|
292 | // No category, no value. | |
293 | return 0; |
|
293 | return 0; | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 | return m_barSets.at(set)->at(category); |
|
296 | return m_barSets.at(set)->at(category); | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
299 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
300 | { |
|
300 | { | |
301 | if ((set < 0) || (set >= m_barSets.count())) { |
|
301 | if ((set < 0) || (set >= m_barSets.count())) { | |
302 | // No set, no value. |
|
302 | // No set, no value. | |
303 | return 0; |
|
303 | return 0; | |
304 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
304 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
305 | // No category, no value. |
|
305 | // No category, no value. | |
306 | return 0; |
|
306 | return 0; | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | qreal value = m_barSets.at(set)->at(category); |
|
309 | qreal value = m_barSets.at(set)->at(category); | |
310 | qreal sum = categorySum(category); |
|
310 | qreal sum = categorySum(category); | |
311 | if ( qFuzzyIsNull(sum) ) { |
|
311 | if ( qFuzzyIsNull(sum) ) { | |
312 | return 0; |
|
312 | return 0; | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | return value / sum; |
|
315 | return value / sum; | |
316 | } |
|
316 | } | |
317 |
|
317 | |||
318 | qreal QBarSeriesPrivate::categorySum(int category) |
|
318 | qreal QBarSeriesPrivate::categorySum(int category) | |
319 | { |
|
319 | { | |
320 | qreal sum(0); |
|
320 | qreal sum(0); | |
321 | int count = m_barSets.count(); // Count sets |
|
321 | int count = m_barSets.count(); // Count sets | |
322 | for (int set = 0; set < count; set++) { |
|
322 | for (int set = 0; set < count; set++) { | |
323 | if (category < m_barSets.at(set)->count()) |
|
323 | if (category < m_barSets.at(set)->count()) | |
324 | sum += m_barSets.at(set)->at(category); |
|
324 | sum += m_barSets.at(set)->at(category); | |
325 | } |
|
325 | } | |
326 | return sum; |
|
326 | return sum; | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
329 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
330 | { |
|
330 | { | |
331 | qreal sum(0); |
|
331 | qreal sum(0); | |
332 | int count = m_barSets.count(); // Count sets |
|
332 | int count = m_barSets.count(); // Count sets | |
333 | for (int set = 0; set < count; set++) { |
|
333 | for (int set = 0; set < count; set++) { | |
334 | if (category < m_barSets.at(set)->count()) |
|
334 | if (category < m_barSets.at(set)->count()) | |
335 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
335 | sum += qAbs(m_barSets.at(set)->at(category)); | |
336 | } |
|
336 | } | |
337 | return sum; |
|
337 | return sum; | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | qreal QBarSeriesPrivate::maxCategorySum() |
|
340 | qreal QBarSeriesPrivate::maxCategorySum() | |
341 | { |
|
341 | { | |
342 | qreal max = INT_MIN; |
|
342 | qreal max = INT_MIN; | |
343 | int count = m_categories.count(); |
|
343 | int count = m_categories.count(); | |
344 | for (int i = 0; i < count; i++) { |
|
344 | for (int i = 0; i < count; i++) { | |
345 | qreal sum = categorySum(i); |
|
345 | qreal sum = categorySum(i); | |
346 | if (sum > max) |
|
346 | if (sum > max) | |
347 | max = sum; |
|
347 | max = sum; | |
348 | } |
|
348 | } | |
349 | return max; |
|
349 | return max; | |
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) |
|
352 | bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) | |
353 | { |
|
353 | { | |
354 | // disconnect signals from old model |
|
354 | // disconnect signals from old model | |
355 | if(m_model) |
|
355 | if(m_model) | |
356 | { |
|
356 | { | |
357 | disconnect(m_model, 0, this, 0); |
|
357 | disconnect(m_model, 0, this, 0); | |
358 | m_mapCategories = -1; |
|
358 | m_mapCategories = -1; | |
359 | m_mapBarBottom = -1; |
|
359 | m_mapBarBottom = -1; | |
360 | m_mapBarTop = -1; |
|
360 | m_mapBarTop = -1; | |
361 | m_mapOrientation = Qt::Vertical; |
|
361 | m_mapOrientation = Qt::Vertical; | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | // set new model |
|
364 | // set new model | |
365 | if(model) |
|
365 | if(model) | |
366 | { |
|
366 | { | |
367 | m_model = model; |
|
367 | m_model = model; | |
368 | return true; |
|
368 | return true; | |
369 | } |
|
369 | } | |
370 | else |
|
370 | else | |
371 | { |
|
371 | { | |
372 | m_model = 0; |
|
372 | m_model = 0; | |
373 | return false; |
|
373 | return false; | |
374 | } |
|
374 | } | |
375 | } |
|
375 | } | |
376 |
|
376 | |||
377 | void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
377 | void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
378 | { |
|
378 | { | |
379 | Q_Q(QBarSeries); |
|
379 | Q_Q(QBarSeries); | |
380 |
|
380 | |||
381 | if (m_model == 0) |
|
381 | if (m_model == 0) | |
382 | return; |
|
382 | return; | |
383 |
|
383 | |||
384 | m_mapCategories = categories; |
|
384 | m_mapCategories = categories; | |
385 | m_mapBarBottom = bottomBoundry; |
|
385 | m_mapBarBottom = bottomBoundry; | |
386 | m_mapBarTop = topBoundry; |
|
386 | m_mapBarTop = topBoundry; | |
387 | m_mapOrientation = orientation; |
|
387 | m_mapOrientation = orientation; | |
388 |
|
388 | |||
389 | // connect the signals |
|
389 | // connect the signals | |
390 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
390 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
391 | if (m_mapOrientation == Qt::Vertical) { |
|
391 | if (m_mapOrientation == Qt::Vertical) { | |
392 | connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
392 | connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
393 | connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
393 | connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
394 | } else { |
|
394 | } else { | |
395 | connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
395 | connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
396 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
396 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | // create the initial bars |
|
399 | // create the initial bars | |
400 | m_categories.clear(); |
|
400 | m_categories.clear(); | |
401 | if (m_mapOrientation == Qt::Vertical) { |
|
401 | if (m_mapOrientation == Qt::Vertical) { | |
402 | int rowCount = 0; |
|
402 | int rowCount = 0; | |
403 | if(m_mapCount == -1) |
|
403 | if(m_mapCount == -1) | |
404 | rowCount = m_model->rowCount() - m_mapFirst; |
|
404 | rowCount = m_model->rowCount() - m_mapFirst; | |
405 | else |
|
405 | else | |
406 | rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); |
|
406 | rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); | |
407 | for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { |
|
407 | for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { | |
408 | m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
408 | m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
411 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
412 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); |
|
412 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); | |
413 | for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) |
|
413 | for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) | |
414 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
414 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
415 | q->appendBarSet(barSet); |
|
415 | q->appendBarSet(barSet); | |
416 | } |
|
416 | } | |
417 | } else { |
|
417 | } else { | |
418 | int columnCount = 0; |
|
418 | int columnCount = 0; | |
419 | if(m_mapCount == -1) |
|
419 | if(m_mapCount == -1) | |
420 | columnCount = m_model->columnCount() - m_mapFirst; |
|
420 | columnCount = m_model->columnCount() - m_mapFirst; | |
421 | else |
|
421 | else | |
422 | columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); |
|
422 | columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); | |
423 | for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { |
|
423 | for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { | |
424 | m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
424 | m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
425 | } |
|
425 | } | |
426 |
|
426 | |||
427 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
427 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
428 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); |
|
428 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); | |
429 | for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) |
|
429 | for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) | |
430 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
430 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
431 | q->appendBarSet(barSet); |
|
431 | q->appendBarSet(barSet); | |
432 | } |
|
432 | } | |
433 | } |
|
433 | } | |
434 | } |
|
434 | } | |
435 |
|
435 | |||
436 | void QBarSeriesPrivate::setModelMappingRange(int first, int count) |
|
436 | void QBarSeriesPrivate::setModelMappingRange(int first, int count) | |
437 | { |
|
437 | { | |
438 | m_mapFirst = first; |
|
438 | m_mapFirst = first; | |
439 | m_mapCount = count; |
|
439 | m_mapCount = count; | |
440 | } |
|
440 | } | |
441 |
|
441 | |||
442 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
442 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
443 | { |
|
443 | { | |
444 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
444 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
445 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
445 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
446 | if (m_mapOrientation == Qt::Vertical) |
|
446 | if (m_mapOrientation == Qt::Vertical) | |
447 | { |
|
447 | { | |
448 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
448 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
449 | if ( row >= m_mapFirst && (m_mapCount == - 1 || row < m_mapFirst + m_mapCount)) { |
|
449 | if ( row >= m_mapFirst && (m_mapCount == - 1 || row < m_mapFirst + m_mapCount)) { | |
450 | if (column >= m_mapBarBottom && column <= m_mapBarTop) |
|
450 | if (column >= m_mapBarBottom && column <= m_mapBarTop) | |
451 | barsetAt(column - m_mapBarBottom)->replace(row - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
451 | barsetAt(column - m_mapBarBottom)->replace(row - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
452 | // if (column == m_mapCategories);// TODO: |
|
452 | // if (column == m_mapCategories);// TODO: | |
453 | } |
|
453 | } | |
454 | } |
|
454 | } | |
455 | else |
|
455 | else | |
456 | { |
|
456 | { | |
457 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
457 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
458 | if (column >= m_mapFirst && (m_mapCount == - 1 || column < m_mapFirst + m_mapCount)) { |
|
458 | if (column >= m_mapFirst && (m_mapCount == - 1 || column < m_mapFirst + m_mapCount)) { | |
459 | if (row >= m_mapBarBottom && row <= m_mapBarTop) |
|
459 | if (row >= m_mapBarBottom && row <= m_mapBarTop) | |
460 | barsetAt(row - m_mapBarBottom)->replace(column - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
460 | barsetAt(row - m_mapBarBottom)->replace(column - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
461 | // if (row == m_mapCategories);// TODO: |
|
461 | // if (row == m_mapCategories);// TODO: | |
462 | } |
|
462 | } | |
463 | } |
|
463 | } | |
464 | } |
|
464 | } | |
465 | } |
|
465 | } | |
466 | } |
|
466 | } | |
467 |
|
467 | |||
468 | void QBarSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) |
|
468 | void QBarSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) | |
469 | { |
|
469 | { | |
470 | Q_UNUSED(parent); |
|
470 | Q_UNUSED(parent); | |
471 | Q_UNUSED(start); |
|
471 | Q_UNUSED(start); | |
472 | Q_UNUSED(end); |
|
472 | Q_UNUSED(end); | |
473 | initializeDataFromModel(); |
|
473 | initializeDataFromModel(); | |
474 | // // series uses model as a data sourceupda |
|
474 | // // series uses model as a data sourceupda | |
475 | // int addedCount = end - start + 1; |
|
475 | // int addedCount = end - start + 1; | |
476 | // if (m_mapCount != -1 && start >= m_mapFirst + m_mapCount) { |
|
476 | // if (m_mapCount != -1 && start >= m_mapFirst + m_mapCount) { | |
477 | // return; |
|
477 | // return; | |
478 | // } else { |
|
478 | // } else { | |
479 |
|
479 | |||
480 | // for (int bar = m_mapBarBottom; bar <= m_mapBarTop; bar++) { |
|
480 | // for (int bar = m_mapBarBottom; bar <= m_mapBarTop; bar++) { | |
481 | // QBarSet *barSet = barsetAt(bar - m_mapBarBottom); |
|
481 | // QBarSet *barSet = barsetAt(bar - m_mapBarBottom); | |
482 | // // adding items to unlimited map |
|
482 | // // adding items to unlimited map | |
483 | // if (m_mapCount == -1 && start >= m_mapFirst) { |
|
483 | // if (m_mapCount == -1 && start >= m_mapFirst) { | |
484 | // for (int i = start; i <= end; i++) { |
|
484 | // for (int i = start; i <= end; i++) { | |
485 | // if (bar == m_mapBarBottom) |
|
485 | // if (bar == m_mapBarBottom) | |
486 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
486 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); | |
487 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
487 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); | |
488 | // } |
|
488 | // } | |
489 | // } else if (m_mapCount == - 1 && start < m_mapFirst) { |
|
489 | // } else if (m_mapCount == - 1 && start < m_mapFirst) { | |
490 | // // not all newly added items |
|
490 | // // not all newly added items | |
491 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { |
|
491 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { | |
492 | // if (bar == m_mapBarBottom) |
|
492 | // if (bar == m_mapBarBottom) | |
493 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
493 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); | |
494 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
494 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); | |
495 | // } |
|
495 | // } | |
496 | // } |
|
496 | // } | |
497 |
|
497 | |||
498 | // // adding items to limited map |
|
498 | // // adding items to limited map | |
499 | // else if (start >= m_mapFirst) { |
|
499 | // else if (start >= m_mapFirst) { | |
500 | // // remove the items that will no longer fit into the map |
|
500 | // // remove the items that will no longer fit into the map | |
501 | // // int toRemove = addedCount - (count - points().size()); |
|
501 | // // int toRemove = addedCount - (count - points().size()); | |
502 | // for (int i = start; i <= end; i++) { |
|
502 | // for (int i = start; i <= end; i++) { | |
503 | // if (bar == m_mapBarBottom) |
|
503 | // if (bar == m_mapBarBottom) | |
504 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
504 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); | |
505 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
505 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); | |
506 | // } |
|
506 | // } | |
507 | // if (m_barSets.size() > m_mapCount) |
|
507 | // if (m_barSets.size() > m_mapCount) | |
508 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { |
|
508 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { | |
509 | // if (bar == m_mapBarBottom) |
|
509 | // if (bar == m_mapBarBottom) | |
510 | // removeCategory(i); |
|
510 | // removeCategory(i); | |
511 | // barSet->remove(i); |
|
511 | // barSet->remove(i); | |
512 | // } |
|
512 | // } | |
513 | // } else { |
|
513 | // } else { | |
514 | // // |
|
514 | // // | |
515 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { |
|
515 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { | |
516 | // if (bar == m_mapBarBottom) |
|
516 | // if (bar == m_mapBarBottom) | |
517 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
517 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); | |
518 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
518 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); | |
519 | // } |
|
519 | // } | |
520 | // if (m_barSets.size() > m_mapCount) |
|
520 | // if (m_barSets.size() > m_mapCount) | |
521 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { |
|
521 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { | |
522 | // if (bar == m_mapBarBottom) |
|
522 | // if (bar == m_mapBarBottom) | |
523 | // removeCategory(i); |
|
523 | // removeCategory(i); | |
524 | // barSet->remove(i); |
|
524 | // barSet->remove(i); | |
525 | // } |
|
525 | // } | |
526 | // } |
|
526 | // } | |
527 | // } |
|
527 | // } | |
528 | // emit restructuredBars(); |
|
528 | // emit restructuredBars(); | |
529 | // emit barsetChanged(); |
|
529 | // emit barsetChanged(); | |
530 | // emit categoriesUpdated(); |
|
530 | // emit categoriesUpdated(); | |
531 | // } |
|
531 | // } | |
532 | } |
|
532 | } | |
533 |
|
533 | |||
534 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) |
|
534 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
535 | { |
|
535 | { | |
536 | Q_UNUSED(parent); |
|
536 | Q_UNUSED(parent); | |
537 | Q_UNUSED(start); |
|
537 | Q_UNUSED(start); | |
538 | Q_UNUSED(end); |
|
538 | Q_UNUSED(end); | |
539 | initializeDataFromModel(); |
|
539 | initializeDataFromModel(); | |
540 | } |
|
540 | } | |
541 |
|
541 | |||
542 | void QBarSeriesPrivate::initializeDataFromModel() |
|
542 | void QBarSeriesPrivate::initializeDataFromModel() | |
543 | { |
|
543 | { | |
544 | Q_Q(QBarSeries); |
|
544 | Q_Q(QBarSeries); | |
545 |
|
545 | |||
546 | if (m_model == 0) |
|
546 | if (m_model == 0) | |
547 | return; |
|
547 | return; | |
548 |
|
548 | |||
549 | // connect the signals |
|
549 | // connect the signals | |
550 | // connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
550 | // connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
551 | // if (m_mapOrientation == Qt::Vertical) { |
|
551 | // if (m_mapOrientation == Qt::Vertical) { | |
552 | // connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
552 | // connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
553 | // connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
553 | // connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
554 | // } else { |
|
554 | // } else { | |
555 | // connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
555 | // connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
556 | // connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
556 | // connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
557 | // } |
|
557 | // } | |
558 |
|
558 | |||
559 | // create the initial bars |
|
559 | // create the initial bars | |
560 | m_categories.clear(); |
|
560 | m_categories.clear(); | |
561 | m_barSets.clear(); |
|
561 | m_barSets.clear(); | |
562 | // emit restructuredBars(); |
|
562 | // emit restructuredBars(); | |
563 | if (m_mapOrientation == Qt::Vertical) { |
|
563 | if (m_mapOrientation == Qt::Vertical) { | |
564 | int rowCount = 0; |
|
564 | int rowCount = 0; | |
565 | if(m_mapCount == -1) |
|
565 | if(m_mapCount == -1) | |
566 | rowCount = m_model->rowCount() - m_mapFirst; |
|
566 | rowCount = m_model->rowCount() - m_mapFirst; | |
567 | else |
|
567 | else | |
568 | rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); |
|
568 | rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); | |
569 | for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { |
|
569 | for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { | |
570 | m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
570 | m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
571 | } |
|
571 | } | |
572 |
|
572 | |||
573 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
573 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
574 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); |
|
574 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); | |
575 | for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) |
|
575 | for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) | |
576 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
576 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
577 | q->appendBarSet(barSet); |
|
577 | q->appendBarSet(barSet); | |
578 | } |
|
578 | } | |
579 | } else { |
|
579 | } else { | |
580 | int columnCount = 0; |
|
580 | int columnCount = 0; | |
581 | if(m_mapCount == -1) |
|
581 | if(m_mapCount == -1) | |
582 | columnCount = m_model->columnCount() - m_mapFirst; |
|
582 | columnCount = m_model->columnCount() - m_mapFirst; | |
583 | else |
|
583 | else | |
584 | columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); |
|
584 | columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); | |
585 | for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { |
|
585 | for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { | |
586 | m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
586 | m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
587 | } |
|
587 | } | |
588 |
|
588 | |||
589 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
589 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
590 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); |
|
590 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); | |
591 | for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) |
|
591 | for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) | |
592 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
592 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
593 | q->appendBarSet(barSet); |
|
593 | q->appendBarSet(barSet); | |
594 | } |
|
594 | } | |
595 | } |
|
595 | } | |
596 | emit restructuredBars(); |
|
596 | emit restructuredBars(); | |
597 | // emit updatedBars(); |
|
597 | // emit updatedBars(); | |
598 | } |
|
598 | } | |
599 |
|
599 | |||
600 | void QBarSeriesPrivate::insertCategory(int index, const QString category) |
|
600 | void QBarSeriesPrivate::insertCategory(int index, const QString category) | |
601 | { |
|
601 | { | |
602 | m_categories.insert(index, category); |
|
602 | m_categories.insert(index, category); | |
603 | emit categoriesUpdated(); |
|
603 | emit categoriesUpdated(); | |
604 | } |
|
604 | } | |
605 |
|
605 | |||
606 | void QBarSeriesPrivate::removeCategory(int index) |
|
606 | void QBarSeriesPrivate::removeCategory(int index) | |
607 | { |
|
607 | { | |
608 | m_categories.removeAt(index); |
|
608 | m_categories.removeAt(index); | |
609 | emit categoriesUpdated(); |
|
609 | emit categoriesUpdated(); | |
610 | } |
|
610 | } | |
611 |
|
611 | |||
612 | void QBarSeriesPrivate::barsetChanged() |
|
612 | void QBarSeriesPrivate::barsetChanged() | |
613 | { |
|
613 | { | |
614 | emit updatedBars(); |
|
614 | emit updatedBars(); | |
615 | } |
|
615 | } | |
616 |
|
616 | |||
617 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
617 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
618 | { |
|
618 | { | |
619 | qreal minX(domain.minX()); |
|
619 | qreal minX(domain.minX()); | |
620 | qreal minY(domain.minY()); |
|
620 | qreal minY(domain.minY()); | |
621 | qreal maxX(domain.maxX()); |
|
621 | qreal maxX(domain.maxX()); | |
622 | qreal maxY(domain.maxY()); |
|
622 | qreal maxY(domain.maxY()); | |
623 | int tickXCount(domain.tickXCount()); |
|
623 | int tickXCount(domain.tickXCount()); | |
624 | int tickYCount(domain.tickYCount()); |
|
624 | int tickYCount(domain.tickYCount()); | |
625 |
|
625 | |||
626 | qreal x = m_categories.count(); |
|
626 | qreal x = m_categories.count(); | |
627 | qreal y = max(); |
|
627 | qreal y = max(); | |
628 | minX = qMin(minX, x); |
|
628 | minX = qMin(minX, x); | |
629 | minY = qMin(minY, y); |
|
629 | minY = qMin(minY, y); | |
630 | maxX = qMax(maxX, x); |
|
630 | maxX = qMax(maxX, x); | |
631 | maxY = qMax(maxY, y); |
|
631 | maxY = qMax(maxY, y); | |
632 | tickXCount = x+1; |
|
632 | tickXCount = x+1; | |
633 |
|
633 | |||
634 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
634 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
635 | } |
|
635 | } | |
636 |
|
636 | |||
637 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
637 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
638 | { |
|
638 | { | |
639 | Q_Q(QBarSeries); |
|
639 | Q_Q(QBarSeries); | |
640 |
|
640 | |||
641 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
641 | BarChartItem* bar = new BarChartItem(q,presenter); | |
642 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
642 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
643 | presenter->animator()->addAnimation(bar); |
|
643 | presenter->animator()->addAnimation(bar); | |
644 | } |
|
644 | } | |
645 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
645 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
646 | return bar; |
|
646 | return bar; | |
647 |
|
647 | |||
648 | } |
|
648 | } | |
649 |
|
649 | |||
650 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
650 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
651 | { |
|
651 | { | |
652 | Q_Q(QBarSeries); |
|
652 | Q_Q(QBarSeries); | |
653 | QList<LegendMarker*> markers; |
|
653 | QList<LegendMarker*> markers; | |
654 | foreach(QBarSet* set, q->barSets()) { |
|
654 | foreach(QBarSet* set, q->barSets()) { | |
655 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
655 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
656 | markers << marker; |
|
656 | markers << marker; | |
657 | } |
|
657 | } | |
658 |
|
658 | |||
659 | return markers; |
|
659 | return markers; | |
660 | } |
|
660 | } | |
661 |
|
661 | |||
662 | #include "moc_qbarseries.cpp" |
|
662 | #include "moc_qbarseries.cpp" | |
663 | #include "moc_qbarseries_p.cpp" |
|
663 | #include "moc_qbarseries_p.cpp" | |
664 |
|
664 | |||
665 | QTCOMMERCIALCHART_END_NAMESPACE |
|
665 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,133 +1,318 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qbarseries.h> |
|
22 | #include <qbarseries.h> | |
23 | #include <qbarset> |
|
23 | #include <qbarset> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
25 | QTCOMMERCIALCHART_USE_NAMESPACE | |
26 |
|
26 | |||
27 | class tst_QBarSeries : public QObject |
|
27 | class tst_QBarSeries : public QObject | |
28 | { |
|
28 | { | |
29 | Q_OBJECT |
|
29 | Q_OBJECT | |
30 |
|
30 | |||
31 | public slots: |
|
31 | public slots: | |
32 | void initTestCase(); |
|
32 | void initTestCase(); | |
33 | void cleanupTestCase(); |
|
33 | void cleanupTestCase(); | |
34 | void init(); |
|
34 | void init(); | |
35 | void cleanup(); |
|
35 | void cleanup(); | |
36 |
|
36 | |||
37 | private slots: |
|
37 | private slots: | |
38 | void qbarseries_data(); |
|
38 | void qbarseries_data(); | |
39 | void qbarseries(); |
|
39 | void qbarseries(); | |
40 | void type_data(); |
|
40 | void type_data(); | |
41 | void type(); |
|
41 | void type(); | |
42 | void appendBarSet_data(); |
|
42 | void appendBarSet_data(); | |
43 | void appendBarSet(); |
|
43 | void appendBarSet(); | |
|
44 | void removeBarSet_data(); | |||
|
45 | void removeBarSet(); | |||
|
46 | void appendBarSets_data(); | |||
|
47 | void appendBarSets(); | |||
|
48 | void removeBarSets_data(); | |||
|
49 | void removeBarSets(); | |||
|
50 | void barsetCount_data(); | |||
|
51 | void barsetCount(); | |||
|
52 | void categoryCount_data(); | |||
|
53 | void categoryCount(); | |||
|
54 | void barSets_data(); | |||
|
55 | void barSets(); | |||
|
56 | void categories_data(); | |||
|
57 | void categories(); | |||
|
58 | void setLabelsVisible_data(); | |||
|
59 | void setLabelsVisible(); | |||
44 |
|
60 | |||
45 | private: |
|
61 | private: | |
46 | QBarSeries* m_barseries; |
|
62 | QBarSeries* m_barseries; | |
|
63 | QBarSeries* m_barseries_with_sets; | |||
|
64 | ||||
|
65 | QList<QBarSet*> m_testSets; | |||
|
66 | ||||
|
67 | QBarCategories m_categories; | |||
47 | }; |
|
68 | }; | |
48 |
|
69 | |||
49 | void tst_QBarSeries::initTestCase() |
|
70 | void tst_QBarSeries::initTestCase() | |
50 | { |
|
71 | { | |
51 | } |
|
72 | } | |
52 |
|
73 | |||
53 | void tst_QBarSeries::cleanupTestCase() |
|
74 | void tst_QBarSeries::cleanupTestCase() | |
54 | { |
|
75 | { | |
55 | } |
|
76 | } | |
56 |
|
77 | |||
57 | void tst_QBarSeries::init() |
|
78 | void tst_QBarSeries::init() | |
58 | { |
|
79 | { | |
59 | QBarCategories categories; |
|
80 | m_categories << "category0" << "category1" << "category2"; | |
60 | categories << "category0" << "category1" << "category2"; |
|
81 | m_barseries = new QBarSeries(m_categories); | |
61 | m_barseries = new QBarSeries(categories); |
|
82 | m_barseries_with_sets = new QBarSeries(m_categories); | |
|
83 | ||||
|
84 | for (int i=0; i<5; i++) { | |||
|
85 | m_testSets.append(new QBarSet("testset")); | |||
|
86 | m_barseries_with_sets->appendBarSet(m_testSets.at(i)); | |||
|
87 | } | |||
62 | } |
|
88 | } | |
63 |
|
89 | |||
64 | void tst_QBarSeries::cleanup() |
|
90 | void tst_QBarSeries::cleanup() | |
65 | { |
|
91 | { | |
|
92 | foreach(QBarSet* s, m_testSets) { | |||
|
93 | m_barseries_with_sets->removeBarSet(s); | |||
|
94 | delete s; | |||
|
95 | } | |||
|
96 | m_testSets.clear(); | |||
|
97 | ||||
66 | delete m_barseries; |
|
98 | delete m_barseries; | |
67 | m_barseries = 0; |
|
99 | m_barseries = 0; | |
|
100 | delete m_barseries_with_sets; | |||
|
101 | m_barseries_with_sets = 0; | |||
|
102 | m_categories.clear(); | |||
68 | } |
|
103 | } | |
69 |
|
104 | |||
70 | void tst_QBarSeries::qbarseries_data() |
|
105 | void tst_QBarSeries::qbarseries_data() | |
71 | { |
|
106 | { | |
72 | QTest::addColumn<QBarCategories> ("categories"); |
|
107 | QTest::addColumn<QBarCategories> ("categories"); | |
73 | QBarCategories c; |
|
108 | QBarCategories c; | |
74 | c << "category0" << "category1" << "category2"; |
|
109 | c << "category0" << "category1" << "category2"; | |
75 | QTest::newRow("categories") << c; |
|
110 | QTest::newRow("categories") << c; | |
76 | } |
|
111 | } | |
77 |
|
112 | |||
78 | void tst_QBarSeries::qbarseries() |
|
113 | void tst_QBarSeries::qbarseries() | |
79 | { |
|
114 | { | |
80 | QFETCH(QBarCategories, categories); |
|
115 | QFETCH(QBarCategories, categories); | |
81 | QBarSeries *barseries = new QBarSeries(categories); |
|
116 | QBarSeries *barseries = new QBarSeries(categories); | |
82 | QVERIFY(barseries != 0); |
|
117 | QVERIFY(barseries != 0); | |
83 | QBarCategories verifyCategories = barseries->categories(); |
|
118 | QBarCategories verifyCategories = barseries->categories(); | |
84 |
|
119 | |||
85 | QVERIFY(verifyCategories.count() == categories.count()); |
|
120 | QVERIFY(verifyCategories.count() == categories.count()); | |
86 | for (int i=0; i<categories.count(); i++) { |
|
121 | for (int i=0; i<categories.count(); i++) { | |
87 | QVERIFY(verifyCategories.at(i).compare(categories.at(i)) == 0); |
|
122 | QVERIFY(verifyCategories.at(i).compare(categories.at(i)) == 0); | |
88 | } |
|
123 | } | |
89 | } |
|
124 | } | |
90 |
|
125 | |||
91 | void tst_QBarSeries::type_data() |
|
126 | void tst_QBarSeries::type_data() | |
92 | { |
|
127 | { | |
93 |
|
128 | |||
94 | } |
|
129 | } | |
95 |
|
130 | |||
96 | void tst_QBarSeries::type() |
|
131 | void tst_QBarSeries::type() | |
97 | { |
|
132 | { | |
98 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); |
|
133 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); | |
99 | } |
|
134 | } | |
100 |
|
135 | |||
101 | void tst_QBarSeries::appendBarSet_data() |
|
136 | void tst_QBarSeries::appendBarSet_data() | |
102 | { |
|
137 | { | |
103 | } |
|
138 | } | |
104 |
|
139 | |||
105 | void tst_QBarSeries::appendBarSet() |
|
140 | void tst_QBarSeries::appendBarSet() | |
106 | { |
|
141 | { | |
107 | QVERIFY(m_barseries->barsetCount() == 0); |
|
142 | QVERIFY(m_barseries->barsetCount() == 0); | |
108 |
|
143 | |||
109 | QBarSet *barset = new QBarSet("testset"); |
|
144 | QBarSet *barset = new QBarSet("testset"); | |
110 | m_barseries->appendBarSet(barset); |
|
145 | m_barseries->appendBarSet(barset); | |
111 |
|
146 | |||
112 | QVERIFY(m_barseries->barsetCount() == 1); |
|
147 | QVERIFY(m_barseries->barsetCount() == 1); | |
|
148 | ||||
|
149 | QBarSet *barset2 = new QBarSet("testset2"); | |||
|
150 | m_barseries->appendBarSet(barset2); | |||
|
151 | ||||
|
152 | QVERIFY(m_barseries->barsetCount() == 2); | |||
|
153 | } | |||
|
154 | ||||
|
155 | void tst_QBarSeries::removeBarSet_data() | |||
|
156 | { | |||
|
157 | } | |||
|
158 | ||||
|
159 | void tst_QBarSeries::removeBarSet() | |||
|
160 | { | |||
|
161 | int count = m_testSets.count(); | |||
|
162 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |||
|
163 | ||||
|
164 | // remove some sets | |||
|
165 | m_barseries_with_sets->removeBarSet(m_testSets.at(2)); | |||
|
166 | m_barseries_with_sets->removeBarSet(m_testSets.at(3)); | |||
|
167 | m_barseries_with_sets->removeBarSet(m_testSets.at(4)); | |||
|
168 | ||||
|
169 | QVERIFY(m_barseries_with_sets->barsetCount() == 2); | |||
|
170 | ||||
|
171 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); | |||
|
172 | ||||
|
173 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); | |||
|
174 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); | |||
|
175 | ||||
|
176 | // Try removing all sets again | |||
|
177 | for (int i=0; i<count; i++) { | |||
|
178 | m_barseries_with_sets->removeBarSet(m_testSets.at(i)); | |||
|
179 | } | |||
|
180 | ||||
|
181 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |||
|
182 | } | |||
|
183 | ||||
|
184 | void tst_QBarSeries::appendBarSets_data() | |||
|
185 | { | |||
|
186 | ||||
|
187 | } | |||
|
188 | ||||
|
189 | void tst_QBarSeries::appendBarSets() | |||
|
190 | { | |||
|
191 | int count = 5; | |||
|
192 | QVERIFY(m_barseries->barsetCount() == 0); | |||
|
193 | ||||
|
194 | QList<QBarSet*> sets; | |||
|
195 | for (int i=0; i<count; i++) { | |||
|
196 | sets.append(new QBarSet("testset")); | |||
|
197 | } | |||
|
198 | ||||
|
199 | m_barseries->appendBarSets(sets); | |||
|
200 | QVERIFY(m_barseries->barsetCount() == count); | |||
|
201 | } | |||
|
202 | ||||
|
203 | void tst_QBarSeries::removeBarSets_data() | |||
|
204 | { | |||
|
205 | ||||
|
206 | } | |||
|
207 | ||||
|
208 | void tst_QBarSeries::removeBarSets() | |||
|
209 | { | |||
|
210 | int count = m_testSets.count(); | |||
|
211 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |||
|
212 | ||||
|
213 | // Try removing empty list of sets | |||
|
214 | QList<QBarSet*> empty; | |||
|
215 | m_barseries_with_sets->removeBarSets(empty); | |||
|
216 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |||
|
217 | ||||
|
218 | // remove all sets | |||
|
219 | m_barseries_with_sets->removeBarSets(m_testSets); | |||
|
220 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |||
|
221 | ||||
|
222 | // Try removing empty list again | |||
|
223 | m_barseries_with_sets->removeBarSets(empty); | |||
|
224 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |||
|
225 | ||||
|
226 | // remove all sets again | |||
|
227 | m_barseries_with_sets->removeBarSets(m_testSets); | |||
|
228 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |||
|
229 | } | |||
|
230 | ||||
|
231 | void tst_QBarSeries::barsetCount_data() | |||
|
232 | { | |||
|
233 | ||||
|
234 | } | |||
|
235 | ||||
|
236 | void tst_QBarSeries::barsetCount() | |||
|
237 | { | |||
|
238 | QVERIFY(m_barseries->barsetCount() == 0); | |||
|
239 | QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count()); | |||
|
240 | } | |||
|
241 | ||||
|
242 | void tst_QBarSeries::categoryCount_data() | |||
|
243 | { | |||
|
244 | ||||
|
245 | } | |||
|
246 | ||||
|
247 | void tst_QBarSeries::categoryCount() | |||
|
248 | { | |||
|
249 | QVERIFY(m_barseries->categoryCount() == m_categories.count()); | |||
|
250 | QVERIFY(m_barseries_with_sets->categoryCount() == m_categories.count()); | |||
|
251 | } | |||
|
252 | ||||
|
253 | void tst_QBarSeries::barSets_data() | |||
|
254 | { | |||
|
255 | ||||
|
256 | } | |||
|
257 | ||||
|
258 | void tst_QBarSeries::barSets() | |||
|
259 | { | |||
|
260 | QVERIFY(m_barseries->barSets().count() == 0); | |||
|
261 | ||||
|
262 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); | |||
|
263 | QVERIFY(sets.count() == m_testSets.count()); | |||
|
264 | ||||
|
265 | for (int i=0; i<m_testSets.count(); i++) { | |||
|
266 | QVERIFY(sets.at(i) == m_testSets.at(i)); | |||
|
267 | } | |||
|
268 | } | |||
|
269 | ||||
|
270 | void tst_QBarSeries::categories_data() | |||
|
271 | { | |||
|
272 | ||||
|
273 | } | |||
|
274 | ||||
|
275 | void tst_QBarSeries::categories() | |||
|
276 | { | |||
|
277 | QBarCategories categories = m_barseries->categories(); | |||
|
278 | ||||
|
279 | QVERIFY(categories.count() == m_categories.count()); | |||
|
280 | for (int i=0; i<m_categories.count(); i++) { | |||
|
281 | QVERIFY(categories.at(i).compare(m_categories.at(i)) == 0); | |||
|
282 | } | |||
|
283 | } | |||
|
284 | ||||
|
285 | void tst_QBarSeries::setLabelsVisible_data() | |||
|
286 | { | |||
|
287 | ||||
|
288 | } | |||
|
289 | ||||
|
290 | void tst_QBarSeries::setLabelsVisible() | |||
|
291 | { | |||
|
292 | foreach (QBarSet* s, m_testSets) { | |||
|
293 | QVERIFY(s->labelsVisible() == false); | |||
|
294 | } | |||
|
295 | ||||
|
296 | m_barseries_with_sets->setLabelsVisible(true); | |||
|
297 | foreach (QBarSet* s, m_testSets) { | |||
|
298 | QVERIFY(s->labelsVisible() == true); | |||
|
299 | } | |||
|
300 | ||||
|
301 | m_barseries_with_sets->setLabelsVisible(false); | |||
|
302 | foreach (QBarSet* s, m_testSets) { | |||
|
303 | QVERIFY(s->labelsVisible() == false); | |||
|
304 | } | |||
113 | } |
|
305 | } | |
114 |
|
306 | |||
115 | /* |
|
307 | /* | |
116 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
|||
117 | void appendBarSets(QList<QBarSet* > sets); |
|
|||
118 | void removeBarSets(QList<QBarSet* > sets); |
|
|||
119 | int barsetCount() const; |
|
|||
120 | int categoryCount() const; |
|
|||
121 | QList<QBarSet*> barSets() const; |
|
|||
122 | QBarCategories categories() const; |
|
|||
123 |
|
308 | |||
124 | void setLabelsVisible(bool visible = true); |
|
309 | void setLabelsVisible(bool visible = true); | |
125 |
|
310 | |||
126 | bool setModel(QAbstractItemModel *model); |
|
311 | bool setModel(QAbstractItemModel *model); | |
127 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); |
|
312 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |
128 | void setModelMappingRange(int first, int count = -1); |
|
313 | void setModelMappingRange(int first, int count = -1); | |
129 | */ |
|
314 | */ | |
130 | QTEST_MAIN(tst_QBarSeries) |
|
315 | QTEST_MAIN(tst_QBarSeries) | |
131 |
|
316 | |||
132 | #include "tst_qbarseries.moc" |
|
317 | #include "tst_qbarseries.moc" | |
133 |
|
318 |
General Comments 0
You need to be logged in to leave comments.
Login now