##// END OF EJS Templates
improved set/remove barset test cases. fixed errors
sauimone -
r1122:844c2fd5d036
parent child
Show More
@@ -1,710 +1,704
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::SeriesType QBarSeries::type() const
94 QAbstractSeries::SeriesType QBarSeries::type() const
95 {
95 {
96 return QAbstractSeries::SeriesTypeBar;
96 return QAbstractSeries::SeriesTypeBar;
97 }
97 }
98
98
99 void QBarSeries::setCategories(QBarCategories categories)
99 void QBarSeries::setCategories(QBarCategories categories)
100 {
100 {
101 Q_D(QBarSeries);
101 Q_D(QBarSeries);
102 d->setCategories(categories);
102 d->setCategories(categories);
103 emit d->categoriesUpdated();
103 emit d->categoriesUpdated();
104 }
104 }
105
105
106 /*!
106 /*!
107 Adds a set of bars to series. Takes ownership of \a set.
107 Adds a set of bars to series. Takes ownership of \a set.
108 */
108 */
109 bool QBarSeries::appendBarSet(QBarSet *set)
109 bool QBarSeries::appendBarSet(QBarSet *set)
110 {
110 {
111 Q_D(QBarSeries);
111 Q_D(QBarSeries);
112 if ((d->m_barSets.contains(set)) || (set == 0)) {
112 if ((d->m_barSets.contains(set)) || (set == 0)) {
113 // Fail if set is already in list or set is null.
113 // Fail if set is already in list or set is null.
114 return false;
114 return false;
115 }
115 }
116 d->m_barSets.append(set);
116 d->m_barSets.append(set);
117 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
117 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
118 emit d->restructuredBars();
118 emit d->restructuredBars();
119 return true;
119 return true;
120 }
120 }
121
121
122 /*!
122 /*!
123 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
123 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
124 */
124 */
125 bool QBarSeries::removeBarSet(QBarSet *set)
125 bool QBarSeries::removeBarSet(QBarSet *set)
126 {
126 {
127 Q_D(QBarSeries);
127 Q_D(QBarSeries);
128 if (!d->m_barSets.contains(set)) {
128 if (!d->m_barSets.contains(set)) {
129 // Fail if set is not in list
129 // Fail if set is not in list
130 return false;
130 return false;
131 }
131 }
132 d->m_barSets.removeOne(set);
132 d->m_barSets.removeOne(set);
133 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
133 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
134 emit d->restructuredBars();
134 emit d->restructuredBars();
135 return true;
135 return true;
136 }
136 }
137
137
138 /*!
138 /*!
139 Adds a list of barsets to series. Takes ownership of \a sets.
139 Adds a list of barsets to series. Takes ownership of \a sets.
140 */
140 */
141 bool QBarSeries::appendBarSets(QList<QBarSet* > sets)
141 bool QBarSeries::appendBarSets(QList<QBarSet* > sets)
142 {
142 {
143 Q_D(QBarSeries);
143 Q_D(QBarSeries);
144 foreach (QBarSet* set, sets) {
144 foreach (QBarSet* set, sets) {
145 if ((set == 0) || (d->m_barSets.contains(set))) {
145 if ((set == 0) || (d->m_barSets.contains(set))) {
146 // Fail if any of the sets is null or is already appended.
146 // Fail if any of the sets is null or is already appended.
147 return false;
147 return false;
148 }
148 }
149 if (sets.count(set) != 1) {
149 if (sets.count(set) != 1) {
150 // Also fail if same set is more than once in given list.
150 // Also fail if same set is more than once in given list.
151 return false;
151 return false;
152 }
152 }
153 }
153 }
154
154
155 foreach (QBarSet* set, sets) {
155 foreach (QBarSet* set, sets) {
156 d->m_barSets.append(set);
156 d->m_barSets.append(set);
157 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
157 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
158 }
158 }
159 emit d->restructuredBars();
159 emit d->restructuredBars();
160 return true;
160 return true;
161 }
161 }
162
162
163 /*!
163 /*!
164 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
164 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
165 */
165 */
166 bool QBarSeries::removeBarSets(QList<QBarSet* > sets)
166 bool QBarSeries::removeBarSets(QList<QBarSet* > sets)
167 {
167 {
168 Q_D(QBarSeries);
168 Q_D(QBarSeries);
169
169
170 foreach (QBarSet* set, sets) {
170 bool setsRemoved = false;
171 if ((set == 0) || (!d->m_barSets.contains(set))) {
172 // Fail if any of the sets is null or isn't in m_barSets
173 return false;
174 }
175 if (sets.count(set) != 1) {
176 // Also fail if same set is more than once in given list.
177 return false;
178 }
179 }
180
181 foreach (QBarSet* set, sets) {
171 foreach (QBarSet* set, sets) {
182 if (d->m_barSets.contains(set)) {
172 if (d->m_barSets.contains(set)) {
183 d->m_barSets.removeOne(set);
173 d->m_barSets.removeOne(set);
184 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
174 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged()));
175 setsRemoved = true;
185 }
176 }
186 }
177 }
187 emit d->restructuredBars();
178
188 return true;
179 if (setsRemoved) {
180 emit d->restructuredBars();
181 }
182 return setsRemoved;
189 }
183 }
190
184
191 /*!
185 /*!
192 Returns number of sets in series.
186 Returns number of sets in series.
193 */
187 */
194 int QBarSeries::barsetCount() const
188 int QBarSeries::barsetCount() const
195 {
189 {
196 Q_D(const QBarSeries);
190 Q_D(const QBarSeries);
197 return d->m_barSets.count();
191 return d->m_barSets.count();
198 }
192 }
199
193
200 /*!
194 /*!
201 Returns number of categories in series
195 Returns number of categories in series
202 */
196 */
203 int QBarSeries::categoryCount() const
197 int QBarSeries::categoryCount() const
204 {
198 {
205 Q_D(const QBarSeries);
199 Q_D(const QBarSeries);
206 return d->m_categories.count();
200 return d->m_categories.count();
207 }
201 }
208
202
209 /*!
203 /*!
210 Returns a list of sets in series. Keeps ownership of sets.
204 Returns a list of sets in series. Keeps ownership of sets.
211 */
205 */
212 QList<QBarSet*> QBarSeries::barSets() const
206 QList<QBarSet*> QBarSeries::barSets() const
213 {
207 {
214 Q_D(const QBarSeries);
208 Q_D(const QBarSeries);
215 return d->m_barSets;
209 return d->m_barSets;
216 }
210 }
217
211
218 /*!
212 /*!
219 \fn bool QBarSeries::setModel(QAbstractItemModel *model)
213 \fn bool QBarSeries::setModel(QAbstractItemModel *model)
220 Sets the \a model to be used as a data source
214 Sets the \a model to be used as a data source
221 */
215 */
222 bool QBarSeries::setModel(QAbstractItemModel *model)
216 bool QBarSeries::setModel(QAbstractItemModel *model)
223 {
217 {
224 Q_D(QBarSeries);
218 Q_D(QBarSeries);
225 return d->setModel(model);
219 return d->setModel(model);
226 }
220 }
227
221
228 /*!
222 /*!
229 \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
223 \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
230 Sets column/row specified by \a categories to be used as a list of bar series categories.
224 Sets column/row specified by \a categories to be used as a list of bar series categories.
231 Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model.
225 Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model.
232 Parameter \a topBoundry indicates the column/row where the last bar set is located in the model.
226 Parameter \a topBoundry indicates the column/row where the last bar set is located in the model.
233 All the columns/rows inbetween those two values are also used as data for bar sets.
227 All the columns/rows inbetween those two values are also used as data for bar sets.
234 The \a orientation parameter specifies whether the data is in columns or in rows.
228 The \a orientation parameter specifies whether the data is in columns or in rows.
235 */
229 */
236 void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation)
230 void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation)
237 {
231 {
238 Q_D(QBarSeries);
232 Q_D(QBarSeries);
239 d->setModelMapping(categories,bottomBoundary,topBoundary,orientation);
233 d->setModelMapping(categories,bottomBoundary,topBoundary,orientation);
240 }
234 }
241
235
242 void QBarSeries::setModelMappingRange(int first, int count)
236 void QBarSeries::setModelMappingRange(int first, int count)
243 {
237 {
244 Q_D(QBarSeries);
238 Q_D(QBarSeries);
245 d->setModelMappingRange(first, count);
239 d->setModelMappingRange(first, count);
246 }
240 }
247
241
248 /*!
242 /*!
249 Returns the bar categories of the series.
243 Returns the bar categories of the series.
250 */
244 */
251 QBarCategories QBarSeries::categories() const
245 QBarCategories QBarSeries::categories() const
252 {
246 {
253 Q_D(const QBarSeries);
247 Q_D(const QBarSeries);
254 return d->m_categories;
248 return d->m_categories;
255 }
249 }
256
250
257 /*!
251 /*!
258 Sets the visibility of labels in series to \a visible
252 Sets the visibility of labels in series to \a visible
259 */
253 */
260 void QBarSeries::setLabelsVisible(bool visible)
254 void QBarSeries::setLabelsVisible(bool visible)
261 {
255 {
262 foreach (QBarSet* s, barSets()) {
256 foreach (QBarSet* s, barSets()) {
263 s->setLabelsVisible(visible);
257 s->setLabelsVisible(visible);
264 }
258 }
265 }
259 }
266
260
267 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
261 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
268
262
269 QBarSeriesPrivate::QBarSeriesPrivate(/*QBarCategories categories,*/ QBarSeries *q) :
263 QBarSeriesPrivate::QBarSeriesPrivate(/*QBarCategories categories,*/ QBarSeries *q) :
270 QAbstractSeriesPrivate(q),
264 QAbstractSeriesPrivate(q),
271 // m_categories(categories),
265 // m_categories(categories),
272 m_mapCategories(-1),
266 m_mapCategories(-1),
273 m_mapBarBottom(-1),
267 m_mapBarBottom(-1),
274 m_mapBarTop(-1)
268 m_mapBarTop(-1)
275 {
269 {
276 }
270 }
277
271
278 void QBarSeriesPrivate::setCategories(QBarCategories categories)
272 void QBarSeriesPrivate::setCategories(QBarCategories categories)
279 {
273 {
280 m_categories = categories;
274 m_categories = categories;
281 }
275 }
282
276
283
277
284 QBarSet* QBarSeriesPrivate::barsetAt(int index)
278 QBarSet* QBarSeriesPrivate::barsetAt(int index)
285 {
279 {
286 return m_barSets.at(index);
280 return m_barSets.at(index);
287 }
281 }
288
282
289 QString QBarSeriesPrivate::categoryName(int category)
283 QString QBarSeriesPrivate::categoryName(int category)
290 {
284 {
291 return m_categories.at(category);
285 return m_categories.at(category);
292 }
286 }
293
287
294 qreal QBarSeriesPrivate::min()
288 qreal QBarSeriesPrivate::min()
295 {
289 {
296 if (m_barSets.count() <= 0) {
290 if (m_barSets.count() <= 0) {
297 return 0;
291 return 0;
298 }
292 }
299 qreal min = INT_MAX;
293 qreal min = INT_MAX;
300
294
301 for (int i = 0; i < m_barSets.count(); i++) {
295 for (int i = 0; i < m_barSets.count(); i++) {
302 int categoryCount = m_barSets.at(i)->count();
296 int categoryCount = m_barSets.at(i)->count();
303 for (int j = 0; j < categoryCount; j++) {
297 for (int j = 0; j < categoryCount; j++) {
304 qreal temp = m_barSets.at(i)->at(j);
298 qreal temp = m_barSets.at(i)->at(j);
305 if (temp < min)
299 if (temp < min)
306 min = temp;
300 min = temp;
307 }
301 }
308 }
302 }
309 return min;
303 return min;
310 }
304 }
311
305
312 qreal QBarSeriesPrivate::max()
306 qreal QBarSeriesPrivate::max()
313 {
307 {
314 if (m_barSets.count() <= 0) {
308 if (m_barSets.count() <= 0) {
315 return 0;
309 return 0;
316 }
310 }
317 qreal max = INT_MIN;
311 qreal max = INT_MIN;
318
312
319 for (int i = 0; i < m_barSets.count(); i++) {
313 for (int i = 0; i < m_barSets.count(); i++) {
320 int categoryCount = m_barSets.at(i)->count();
314 int categoryCount = m_barSets.at(i)->count();
321 for (int j = 0; j < categoryCount; j++) {
315 for (int j = 0; j < categoryCount; j++) {
322 qreal temp = m_barSets.at(i)->at(j);
316 qreal temp = m_barSets.at(i)->at(j);
323 if (temp > max)
317 if (temp > max)
324 max = temp;
318 max = temp;
325 }
319 }
326 }
320 }
327
321
328 return max;
322 return max;
329 }
323 }
330
324
331 qreal QBarSeriesPrivate::valueAt(int set, int category)
325 qreal QBarSeriesPrivate::valueAt(int set, int category)
332 {
326 {
333 if ((set < 0) || (set >= m_barSets.count())) {
327 if ((set < 0) || (set >= m_barSets.count())) {
334 // No set, no value.
328 // No set, no value.
335 return 0;
329 return 0;
336 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
330 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
337 // No category, no value.
331 // No category, no value.
338 return 0;
332 return 0;
339 }
333 }
340
334
341 return m_barSets.at(set)->at(category);
335 return m_barSets.at(set)->at(category);
342 }
336 }
343
337
344 qreal QBarSeriesPrivate::percentageAt(int set, int category)
338 qreal QBarSeriesPrivate::percentageAt(int set, int category)
345 {
339 {
346 if ((set < 0) || (set >= m_barSets.count())) {
340 if ((set < 0) || (set >= m_barSets.count())) {
347 // No set, no value.
341 // No set, no value.
348 return 0;
342 return 0;
349 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
343 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
350 // No category, no value.
344 // No category, no value.
351 return 0;
345 return 0;
352 }
346 }
353
347
354 qreal value = m_barSets.at(set)->at(category);
348 qreal value = m_barSets.at(set)->at(category);
355 qreal sum = categorySum(category);
349 qreal sum = categorySum(category);
356 if ( qFuzzyIsNull(sum) ) {
350 if ( qFuzzyIsNull(sum) ) {
357 return 0;
351 return 0;
358 }
352 }
359
353
360 return value / sum;
354 return value / sum;
361 }
355 }
362
356
363 qreal QBarSeriesPrivate::categorySum(int category)
357 qreal QBarSeriesPrivate::categorySum(int category)
364 {
358 {
365 qreal sum(0);
359 qreal sum(0);
366 int count = m_barSets.count(); // Count sets
360 int count = m_barSets.count(); // Count sets
367 for (int set = 0; set < count; set++) {
361 for (int set = 0; set < count; set++) {
368 if (category < m_barSets.at(set)->count())
362 if (category < m_barSets.at(set)->count())
369 sum += m_barSets.at(set)->at(category);
363 sum += m_barSets.at(set)->at(category);
370 }
364 }
371 return sum;
365 return sum;
372 }
366 }
373
367
374 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
368 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
375 {
369 {
376 qreal sum(0);
370 qreal sum(0);
377 int count = m_barSets.count(); // Count sets
371 int count = m_barSets.count(); // Count sets
378 for (int set = 0; set < count; set++) {
372 for (int set = 0; set < count; set++) {
379 if (category < m_barSets.at(set)->count())
373 if (category < m_barSets.at(set)->count())
380 sum += qAbs(m_barSets.at(set)->at(category));
374 sum += qAbs(m_barSets.at(set)->at(category));
381 }
375 }
382 return sum;
376 return sum;
383 }
377 }
384
378
385 qreal QBarSeriesPrivate::maxCategorySum()
379 qreal QBarSeriesPrivate::maxCategorySum()
386 {
380 {
387 qreal max = INT_MIN;
381 qreal max = INT_MIN;
388 int count = m_categories.count();
382 int count = m_categories.count();
389 for (int i = 0; i < count; i++) {
383 for (int i = 0; i < count; i++) {
390 qreal sum = categorySum(i);
384 qreal sum = categorySum(i);
391 if (sum > max)
385 if (sum > max)
392 max = sum;
386 max = sum;
393 }
387 }
394 return max;
388 return max;
395 }
389 }
396
390
397 bool QBarSeriesPrivate::setModel(QAbstractItemModel *model)
391 bool QBarSeriesPrivate::setModel(QAbstractItemModel *model)
398 {
392 {
399 // disconnect signals from old model
393 // disconnect signals from old model
400 if(m_model)
394 if(m_model)
401 {
395 {
402 disconnect(m_model, 0, this, 0);
396 disconnect(m_model, 0, this, 0);
403 m_mapCategories = -1;
397 m_mapCategories = -1;
404 m_mapBarBottom = -1;
398 m_mapBarBottom = -1;
405 m_mapBarTop = -1;
399 m_mapBarTop = -1;
406 m_mapOrientation = Qt::Vertical;
400 m_mapOrientation = Qt::Vertical;
407 }
401 }
408
402
409 // set new model
403 // set new model
410 if(model)
404 if(model)
411 {
405 {
412 m_model = model;
406 m_model = model;
413 return true;
407 return true;
414 }
408 }
415 else
409 else
416 {
410 {
417 m_model = 0;
411 m_model = 0;
418 return false;
412 return false;
419 }
413 }
420 }
414 }
421
415
422 void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
416 void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation)
423 {
417 {
424 Q_Q(QBarSeries);
418 Q_Q(QBarSeries);
425
419
426 if (m_model == 0)
420 if (m_model == 0)
427 return;
421 return;
428
422
429 m_mapCategories = categories;
423 m_mapCategories = categories;
430 m_mapBarBottom = bottomBoundry;
424 m_mapBarBottom = bottomBoundry;
431 m_mapBarTop = topBoundry;
425 m_mapBarTop = topBoundry;
432 m_mapOrientation = orientation;
426 m_mapOrientation = orientation;
433
427
434 // connect the signals
428 // connect the signals
435 connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
429 connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
436 if (m_mapOrientation == Qt::Vertical) {
430 if (m_mapOrientation == Qt::Vertical) {
437 connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
431 connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
438 connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
432 connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
439 } else {
433 } else {
440 connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
434 connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
441 connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
435 connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
442 }
436 }
443
437
444 // create the initial bars
438 // create the initial bars
445 m_categories.clear();
439 m_categories.clear();
446 if (m_mapOrientation == Qt::Vertical) {
440 if (m_mapOrientation == Qt::Vertical) {
447 int rowCount = 0;
441 int rowCount = 0;
448 if(m_mapCount == -1)
442 if(m_mapCount == -1)
449 rowCount = m_model->rowCount() - m_mapFirst;
443 rowCount = m_model->rowCount() - m_mapFirst;
450 else
444 else
451 rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst);
445 rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst);
452 for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) {
446 for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) {
453 m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
447 m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
454 }
448 }
455
449
456 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
450 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
457 QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
451 QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
458 for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++)
452 for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++)
459 *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
453 *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
460 q->appendBarSet(barSet);
454 q->appendBarSet(barSet);
461 }
455 }
462 } else {
456 } else {
463 int columnCount = 0;
457 int columnCount = 0;
464 if(m_mapCount == -1)
458 if(m_mapCount == -1)
465 columnCount = m_model->columnCount() - m_mapFirst;
459 columnCount = m_model->columnCount() - m_mapFirst;
466 else
460 else
467 columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst);
461 columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst);
468 for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) {
462 for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) {
469 m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
463 m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
470 }
464 }
471
465
472 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
466 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
473 QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString());
467 QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString());
474 for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++)
468 for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++)
475 *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
469 *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
476 q->appendBarSet(barSet);
470 q->appendBarSet(barSet);
477 }
471 }
478 }
472 }
479 }
473 }
480
474
481 void QBarSeriesPrivate::setModelMappingRange(int first, int count)
475 void QBarSeriesPrivate::setModelMappingRange(int first, int count)
482 {
476 {
483 m_mapFirst = first;
477 m_mapFirst = first;
484 m_mapCount = count;
478 m_mapCount = count;
485 }
479 }
486
480
487 void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
481 void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
488 {
482 {
489 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
483 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
490 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
484 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
491 if (m_mapOrientation == Qt::Vertical)
485 if (m_mapOrientation == Qt::Vertical)
492 {
486 {
493 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
487 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
494 if ( row >= m_mapFirst && (m_mapCount == - 1 || row < m_mapFirst + m_mapCount)) {
488 if ( row >= m_mapFirst && (m_mapCount == - 1 || row < m_mapFirst + m_mapCount)) {
495 if (column >= m_mapBarBottom && column <= m_mapBarTop)
489 if (column >= m_mapBarBottom && column <= m_mapBarTop)
496 barsetAt(column - m_mapBarBottom)->replace(row - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
490 barsetAt(column - m_mapBarBottom)->replace(row - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
497 // if (column == m_mapCategories);// TODO:
491 // if (column == m_mapCategories);// TODO:
498 }
492 }
499 }
493 }
500 else
494 else
501 {
495 {
502 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
496 // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries
503 if (column >= m_mapFirst && (m_mapCount == - 1 || column < m_mapFirst + m_mapCount)) {
497 if (column >= m_mapFirst && (m_mapCount == - 1 || column < m_mapFirst + m_mapCount)) {
504 if (row >= m_mapBarBottom && row <= m_mapBarTop)
498 if (row >= m_mapBarBottom && row <= m_mapBarTop)
505 barsetAt(row - m_mapBarBottom)->replace(column - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
499 barsetAt(row - m_mapBarBottom)->replace(column - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble());
506 // if (row == m_mapCategories);// TODO:
500 // if (row == m_mapCategories);// TODO:
507 }
501 }
508 }
502 }
509 }
503 }
510 }
504 }
511 }
505 }
512
506
513 void QBarSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end)
507 void QBarSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end)
514 {
508 {
515 Q_UNUSED(parent);
509 Q_UNUSED(parent);
516 Q_UNUSED(start);
510 Q_UNUSED(start);
517 Q_UNUSED(end);
511 Q_UNUSED(end);
518 initializeDataFromModel();
512 initializeDataFromModel();
519 // // series uses model as a data sourceupda
513 // // series uses model as a data sourceupda
520 // int addedCount = end - start + 1;
514 // int addedCount = end - start + 1;
521 // if (m_mapCount != -1 && start >= m_mapFirst + m_mapCount) {
515 // if (m_mapCount != -1 && start >= m_mapFirst + m_mapCount) {
522 // return;
516 // return;
523 // } else {
517 // } else {
524
518
525 // for (int bar = m_mapBarBottom; bar <= m_mapBarTop; bar++) {
519 // for (int bar = m_mapBarBottom; bar <= m_mapBarTop; bar++) {
526 // QBarSet *barSet = barsetAt(bar - m_mapBarBottom);
520 // QBarSet *barSet = barsetAt(bar - m_mapBarBottom);
527 // // adding items to unlimited map
521 // // adding items to unlimited map
528 // if (m_mapCount == -1 && start >= m_mapFirst) {
522 // if (m_mapCount == -1 && start >= m_mapFirst) {
529 // for (int i = start; i <= end; i++) {
523 // for (int i = start; i <= end; i++) {
530 // if (bar == m_mapBarBottom)
524 // if (bar == m_mapBarBottom)
531 // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString());
525 // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString());
532 // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble());
526 // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble());
533 // }
527 // }
534 // } else if (m_mapCount == - 1 && start < m_mapFirst) {
528 // } else if (m_mapCount == - 1 && start < m_mapFirst) {
535 // // not all newly added items
529 // // not all newly added items
536 // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) {
530 // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) {
537 // if (bar == m_mapBarBottom)
531 // if (bar == m_mapBarBottom)
538 // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString());
532 // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString());
539 // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble());
533 // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble());
540 // }
534 // }
541 // }
535 // }
542
536
543 // // adding items to limited map
537 // // adding items to limited map
544 // else if (start >= m_mapFirst) {
538 // else if (start >= m_mapFirst) {
545 // // remove the items that will no longer fit into the map
539 // // remove the items that will no longer fit into the map
546 // // int toRemove = addedCount - (count - points().size());
540 // // int toRemove = addedCount - (count - points().size());
547 // for (int i = start; i <= end; i++) {
541 // for (int i = start; i <= end; i++) {
548 // if (bar == m_mapBarBottom)
542 // if (bar == m_mapBarBottom)
549 // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString());
543 // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString());
550 // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble());
544 // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble());
551 // }
545 // }
552 // if (m_barSets.size() > m_mapCount)
546 // if (m_barSets.size() > m_mapCount)
553 // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) {
547 // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) {
554 // if (bar == m_mapBarBottom)
548 // if (bar == m_mapBarBottom)
555 // removeCategory(i);
549 // removeCategory(i);
556 // barSet->remove(i);
550 // barSet->remove(i);
557 // }
551 // }
558 // } else {
552 // } else {
559 // //
553 // //
560 // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) {
554 // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) {
561 // if (bar == m_mapBarBottom)
555 // if (bar == m_mapBarBottom)
562 // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString());
556 // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString());
563 // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble());
557 // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble());
564 // }
558 // }
565 // if (m_barSets.size() > m_mapCount)
559 // if (m_barSets.size() > m_mapCount)
566 // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) {
560 // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) {
567 // if (bar == m_mapBarBottom)
561 // if (bar == m_mapBarBottom)
568 // removeCategory(i);
562 // removeCategory(i);
569 // barSet->remove(i);
563 // barSet->remove(i);
570 // }
564 // }
571 // }
565 // }
572 // }
566 // }
573 // emit restructuredBars();
567 // emit restructuredBars();
574 // emit barsetChanged();
568 // emit barsetChanged();
575 // emit categoriesUpdated();
569 // emit categoriesUpdated();
576 // }
570 // }
577 }
571 }
578
572
579 void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
573 void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
580 {
574 {
581 Q_UNUSED(parent);
575 Q_UNUSED(parent);
582 Q_UNUSED(start);
576 Q_UNUSED(start);
583 Q_UNUSED(end);
577 Q_UNUSED(end);
584 initializeDataFromModel();
578 initializeDataFromModel();
585 }
579 }
586
580
587 void QBarSeriesPrivate::initializeDataFromModel()
581 void QBarSeriesPrivate::initializeDataFromModel()
588 {
582 {
589 Q_Q(QBarSeries);
583 Q_Q(QBarSeries);
590
584
591 if (m_model == 0)
585 if (m_model == 0)
592 return;
586 return;
593
587
594 // connect the signals
588 // connect the signals
595 // connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
589 // connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
596 // if (m_mapOrientation == Qt::Vertical) {
590 // if (m_mapOrientation == Qt::Vertical) {
597 // connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
591 // connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
598 // connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
592 // connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
599 // } else {
593 // } else {
600 // connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
594 // connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
601 // connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
595 // connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
602 // }
596 // }
603
597
604 // create the initial bars
598 // create the initial bars
605 m_categories.clear();
599 m_categories.clear();
606 m_barSets.clear();
600 m_barSets.clear();
607 // emit restructuredBars();
601 // emit restructuredBars();
608 if (m_mapOrientation == Qt::Vertical) {
602 if (m_mapOrientation == Qt::Vertical) {
609 int rowCount = 0;
603 int rowCount = 0;
610 if(m_mapCount == -1)
604 if(m_mapCount == -1)
611 rowCount = m_model->rowCount() - m_mapFirst;
605 rowCount = m_model->rowCount() - m_mapFirst;
612 else
606 else
613 rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst);
607 rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst);
614 for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) {
608 for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) {
615 m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
609 m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString();
616 }
610 }
617
611
618 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
612 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
619 QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
613 QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
620 for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++)
614 for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++)
621 *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
615 *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble();
622 q->appendBarSet(barSet);
616 q->appendBarSet(barSet);
623 }
617 }
624 } else {
618 } else {
625 int columnCount = 0;
619 int columnCount = 0;
626 if(m_mapCount == -1)
620 if(m_mapCount == -1)
627 columnCount = m_model->columnCount() - m_mapFirst;
621 columnCount = m_model->columnCount() - m_mapFirst;
628 else
622 else
629 columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst);
623 columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst);
630 for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) {
624 for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) {
631 m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
625 m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString();
632 }
626 }
633
627
634 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
628 for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) {
635 QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString());
629 QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString());
636 for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++)
630 for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++)
637 *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
631 *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble();
638 q->appendBarSet(barSet);
632 q->appendBarSet(barSet);
639 }
633 }
640 }
634 }
641 emit restructuredBars();
635 emit restructuredBars();
642 // emit updatedBars();
636 // emit updatedBars();
643 }
637 }
644
638
645 void QBarSeriesPrivate::insertCategory(int index, const QString category)
639 void QBarSeriesPrivate::insertCategory(int index, const QString category)
646 {
640 {
647 m_categories.insert(index, category);
641 m_categories.insert(index, category);
648 emit categoriesUpdated();
642 emit categoriesUpdated();
649 }
643 }
650
644
651 void QBarSeriesPrivate::removeCategory(int index)
645 void QBarSeriesPrivate::removeCategory(int index)
652 {
646 {
653 m_categories.removeAt(index);
647 m_categories.removeAt(index);
654 emit categoriesUpdated();
648 emit categoriesUpdated();
655 }
649 }
656
650
657 void QBarSeriesPrivate::barsetChanged()
651 void QBarSeriesPrivate::barsetChanged()
658 {
652 {
659 emit updatedBars();
653 emit updatedBars();
660 }
654 }
661
655
662 void QBarSeriesPrivate::scaleDomain(Domain& domain)
656 void QBarSeriesPrivate::scaleDomain(Domain& domain)
663 {
657 {
664 qreal minX(domain.minX());
658 qreal minX(domain.minX());
665 qreal minY(domain.minY());
659 qreal minY(domain.minY());
666 qreal maxX(domain.maxX());
660 qreal maxX(domain.maxX());
667 qreal maxY(domain.maxY());
661 qreal maxY(domain.maxY());
668 int tickXCount(domain.tickXCount());
662 int tickXCount(domain.tickXCount());
669 int tickYCount(domain.tickYCount());
663 int tickYCount(domain.tickYCount());
670
664
671 qreal x = m_categories.count();
665 qreal x = m_categories.count();
672 qreal y = max();
666 qreal y = max();
673 minX = qMin(minX, x);
667 minX = qMin(minX, x);
674 minY = qMin(minY, y);
668 minY = qMin(minY, y);
675 maxX = qMax(maxX, x);
669 maxX = qMax(maxX, x);
676 maxY = qMax(maxY, y);
670 maxY = qMax(maxY, y);
677 tickXCount = x+1;
671 tickXCount = x+1;
678
672
679 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
673 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
680 }
674 }
681
675
682 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
676 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
683 {
677 {
684 Q_Q(QBarSeries);
678 Q_Q(QBarSeries);
685
679
686 BarChartItem* bar = new BarChartItem(q,presenter);
680 BarChartItem* bar = new BarChartItem(q,presenter);
687 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
681 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
688 presenter->animator()->addAnimation(bar);
682 presenter->animator()->addAnimation(bar);
689 }
683 }
690 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
684 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
691 return bar;
685 return bar;
692
686
693 }
687 }
694
688
695 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
689 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
696 {
690 {
697 Q_Q(QBarSeries);
691 Q_Q(QBarSeries);
698 QList<LegendMarker*> markers;
692 QList<LegendMarker*> markers;
699 foreach(QBarSet* set, q->barSets()) {
693 foreach(QBarSet* set, q->barSets()) {
700 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
694 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
701 markers << marker;
695 markers << marker;
702 }
696 }
703
697
704 return markers;
698 return markers;
705 }
699 }
706
700
707 #include "moc_qbarseries.cpp"
701 #include "moc_qbarseries.cpp"
708 #include "moc_qbarseries_p.cpp"
702 #include "moc_qbarseries_p.cpp"
709
703
710 QTCOMMERCIALCHART_END_NAMESPACE
704 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,341 +1,419
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.h>
23 #include <qbarset.h>
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 setCategories_data();
42 void setCategories_data();
43 void setCategories();
43 void setCategories();
44 void appendBarSet_data();
44 void appendBarSet_data();
45 void appendBarSet();
45 void appendBarSet();
46 void removeBarSet_data();
46 void removeBarSet_data();
47 void removeBarSet();
47 void removeBarSet();
48 void appendBarSets_data();
48 void appendBarSets_data();
49 void appendBarSets();
49 void appendBarSets();
50 void removeBarSets_data();
50 void removeBarSets_data();
51 void removeBarSets();
51 void removeBarSets();
52 void barsetCount_data();
52 void barsetCount_data();
53 void barsetCount();
53 void barsetCount();
54 void categoryCount_data();
54 void categoryCount_data();
55 void categoryCount();
55 void categoryCount();
56 void barSets_data();
56 void barSets_data();
57 void barSets();
57 void barSets();
58 void categories_data();
58 void categories_data();
59 void categories();
59 void categories();
60 void setLabelsVisible_data();
60 void setLabelsVisible_data();
61 void setLabelsVisible();
61 void setLabelsVisible();
62
62
63 private:
63 private:
64 QBarSeries* m_barseries;
64 QBarSeries* m_barseries;
65 QBarSeries* m_barseries_with_sets;
65 QBarSeries* m_barseries_with_sets;
66
66
67 QList<QBarSet*> m_testSets;
67 QList<QBarSet*> m_testSets;
68
68
69 QBarCategories m_categories;
69 QBarCategories m_categories;
70 };
70 };
71
71
72 void tst_QBarSeries::initTestCase()
72 void tst_QBarSeries::initTestCase()
73 {
73 {
74 }
74 }
75
75
76 void tst_QBarSeries::cleanupTestCase()
76 void tst_QBarSeries::cleanupTestCase()
77 {
77 {
78 }
78 }
79
79
80 void tst_QBarSeries::init()
80 void tst_QBarSeries::init()
81 {
81 {
82 m_categories << "category0" << "category1" << "category2";
82 m_categories << "category0" << "category1" << "category2";
83 m_barseries = new QBarSeries();
83 m_barseries = new QBarSeries();
84 m_barseries->setCategories(m_categories);
84 m_barseries->setCategories(m_categories);
85 m_barseries_with_sets = new QBarSeries();
85 m_barseries_with_sets = new QBarSeries();
86 m_barseries_with_sets->setCategories(m_categories);
86 m_barseries_with_sets->setCategories(m_categories);
87
87
88 for (int i=0; i<5; i++) {
88 for (int i=0; i<5; i++) {
89 m_testSets.append(new QBarSet("testset"));
89 m_testSets.append(new QBarSet("testset"));
90 m_barseries_with_sets->appendBarSet(m_testSets.at(i));
90 m_barseries_with_sets->appendBarSet(m_testSets.at(i));
91 }
91 }
92 }
92 }
93
93
94 void tst_QBarSeries::cleanup()
94 void tst_QBarSeries::cleanup()
95 {
95 {
96 foreach(QBarSet* s, m_testSets) {
96 foreach(QBarSet* s, m_testSets) {
97 m_barseries_with_sets->removeBarSet(s);
97 m_barseries_with_sets->removeBarSet(s);
98 delete s;
98 delete s;
99 }
99 }
100 m_testSets.clear();
100 m_testSets.clear();
101
101
102 delete m_barseries;
102 delete m_barseries;
103 m_barseries = 0;
103 m_barseries = 0;
104 delete m_barseries_with_sets;
104 delete m_barseries_with_sets;
105 m_barseries_with_sets = 0;
105 m_barseries_with_sets = 0;
106 m_categories.clear();
106 m_categories.clear();
107 }
107 }
108
108
109 void tst_QBarSeries::qbarseries_data()
109 void tst_QBarSeries::qbarseries_data()
110 {
110 {
111 QTest::addColumn<QBarCategories> ("categories");
111 QTest::addColumn<QBarCategories> ("categories");
112 QBarCategories c;
112 QBarCategories c;
113 c << "category0" << "category1" << "category2";
113 c << "category0" << "category1" << "category2";
114 QTest::newRow("categories") << c;
114 QTest::newRow("categories") << c;
115 }
115 }
116
116
117 void tst_QBarSeries::qbarseries()
117 void tst_QBarSeries::qbarseries()
118 {
118 {
119 QFETCH(QBarCategories, categories);
119 QFETCH(QBarCategories, categories);
120 QBarSeries *barseries = new QBarSeries();
120 QBarSeries *barseries = new QBarSeries();
121 QVERIFY(barseries != 0);
121 QVERIFY(barseries != 0);
122 barseries->setCategories(categories);
122 barseries->setCategories(categories);
123 QBarCategories verifyCategories = barseries->categories();
123 QBarCategories verifyCategories = barseries->categories();
124
124
125 QVERIFY(verifyCategories.count() == categories.count());
125 QVERIFY(verifyCategories.count() == categories.count());
126 for (int i=0; i<categories.count(); i++) {
126 for (int i=0; i<categories.count(); i++) {
127 QVERIFY(verifyCategories.at(i).compare(categories.at(i)) == 0);
127 QVERIFY(verifyCategories.at(i).compare(categories.at(i)) == 0);
128 }
128 }
129 }
129 }
130
130
131 void tst_QBarSeries::type_data()
131 void tst_QBarSeries::type_data()
132 {
132 {
133
133
134 }
134 }
135
135
136 void tst_QBarSeries::type()
136 void tst_QBarSeries::type()
137 {
137 {
138 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar);
138 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar);
139 }
139 }
140
140
141 void tst_QBarSeries::setCategories_data()
141 void tst_QBarSeries::setCategories_data()
142 {
142 {
143 QTest::addColumn<QBarCategories> ("categories");
143 QTest::addColumn<QBarCategories> ("categories");
144 QBarCategories categories;
144 QBarCategories categories;
145 categories << "c1" << "c2" << "c3" << "c4" << "c5" << "c6";
145 categories << "c1" << "c2" << "c3" << "c4" << "c5" << "c6";
146 QTest::newRow("cat") << categories;
146 QTest::newRow("cat") << categories;
147 }
147 }
148
148
149 void tst_QBarSeries::setCategories()
149 void tst_QBarSeries::setCategories()
150 {
150 {
151 QVERIFY(m_barseries->categories().count() == m_categories.count());
151 QVERIFY(m_barseries->categories().count() == m_categories.count());
152
152
153 QFETCH(QBarCategories, categories);
153 QFETCH(QBarCategories, categories);
154 m_barseries->setCategories(categories);
154 m_barseries->setCategories(categories);
155
155
156 QVERIFY(m_barseries->categories().count() == categories.count());
156 QVERIFY(m_barseries->categories().count() == categories.count());
157 for (int i=0; i<categories.count(); i++) {
157 for (int i=0; i<categories.count(); i++) {
158 QVERIFY(m_barseries->categories().at(i).compare(categories.at(i)) == 0);
158 QVERIFY(m_barseries->categories().at(i).compare(categories.at(i)) == 0);
159 }
159 }
160 }
160 }
161
161
162 void tst_QBarSeries::appendBarSet_data()
162 void tst_QBarSeries::appendBarSet_data()
163 {
163 {
164 }
164 }
165
165
166 void tst_QBarSeries::appendBarSet()
166 void tst_QBarSeries::appendBarSet()
167 {
167 {
168 QVERIFY(m_barseries->barsetCount() == 0);
168 QVERIFY(m_barseries->barsetCount() == 0);
169
169
170 bool ret = false;
171
172 // Try adding barset
170 QBarSet *barset = new QBarSet("testset");
173 QBarSet *barset = new QBarSet("testset");
171 m_barseries->appendBarSet(barset);
174 ret = m_barseries->appendBarSet(barset);
172
175
176 QVERIFY(ret == true);
173 QVERIFY(m_barseries->barsetCount() == 1);
177 QVERIFY(m_barseries->barsetCount() == 1);
174
178
179 // Try adding another set
175 QBarSet *barset2 = new QBarSet("testset2");
180 QBarSet *barset2 = new QBarSet("testset2");
176 m_barseries->appendBarSet(barset2);
181 ret = m_barseries->appendBarSet(barset2);
182
183 QVERIFY(ret == true);
184 QVERIFY(m_barseries->barsetCount() == 2);
177
185
186 // Try adding same set again
187 ret = m_barseries->appendBarSet(barset2);
188 QVERIFY(ret == false);
178 QVERIFY(m_barseries->barsetCount() == 2);
189 QVERIFY(m_barseries->barsetCount() == 2);
190
191 // Try adding null set
192 ret = m_barseries->appendBarSet(0);
193 QVERIFY(ret == false);
194 QVERIFY(m_barseries->barsetCount() == 2);
195
179 }
196 }
180
197
181 void tst_QBarSeries::removeBarSet_data()
198 void tst_QBarSeries::removeBarSet_data()
182 {
199 {
183 }
200 }
184
201
185 void tst_QBarSeries::removeBarSet()
202 void tst_QBarSeries::removeBarSet()
186 {
203 {
187 int count = m_testSets.count();
204 int count = m_testSets.count();
188 QVERIFY(m_barseries_with_sets->barsetCount() == count);
205 QVERIFY(m_barseries_with_sets->barsetCount() == count);
189
206
207 // Try to remove null pointer (should not remove, should not crash)
208 bool ret = false;
209 ret = m_barseries_with_sets->removeBarSet(0);
210 QVERIFY(ret == false);
211 QVERIFY(m_barseries_with_sets->barsetCount() == count);
212
213 // Try to remove invalid pointer (should not remove, should not crash)
214 ret = m_barseries_with_sets->removeBarSet((QBarSet*) (m_testSets.at(0) + 1) );
215 QVERIFY(ret == false);
216 QVERIFY(m_barseries_with_sets->barsetCount() == count);
217
190 // remove some sets
218 // remove some sets
191 m_barseries_with_sets->removeBarSet(m_testSets.at(2));
219 ret = m_barseries_with_sets->removeBarSet(m_testSets.at(2));
192 m_barseries_with_sets->removeBarSet(m_testSets.at(3));
220 QVERIFY(ret == true);
193 m_barseries_with_sets->removeBarSet(m_testSets.at(4));
221 ret = m_barseries_with_sets->removeBarSet(m_testSets.at(3));
222 QVERIFY(ret == true);
223 ret = m_barseries_with_sets->removeBarSet(m_testSets.at(4));
224 QVERIFY(ret == true);
194
225
195 QVERIFY(m_barseries_with_sets->barsetCount() == 2);
226 QVERIFY(m_barseries_with_sets->barsetCount() == 2);
196
227
197 QList<QBarSet*> verifysets = m_barseries_with_sets->barSets();
228 QList<QBarSet*> verifysets = m_barseries_with_sets->barSets();
198
229
199 QVERIFY(verifysets.at(0) == m_testSets.at(0));
230 QVERIFY(verifysets.at(0) == m_testSets.at(0));
200 QVERIFY(verifysets.at(1) == m_testSets.at(1));
231 QVERIFY(verifysets.at(1) == m_testSets.at(1));
201
232
202 // Try removing all sets again
233 // Try removing all sets again (should be ok, even if some sets have already been removed)
234 ret = false;
203 for (int i=0; i<count; i++) {
235 for (int i=0; i<count; i++) {
204 m_barseries_with_sets->removeBarSet(m_testSets.at(i));
236 ret |= m_barseries_with_sets->removeBarSet(m_testSets.at(i));
205 }
237 }
206
238
239 QVERIFY(ret == true);
207 QVERIFY(m_barseries_with_sets->barsetCount() == 0);
240 QVERIFY(m_barseries_with_sets->barsetCount() == 0);
208 }
241 }
209
242
210 void tst_QBarSeries::appendBarSets_data()
243 void tst_QBarSeries::appendBarSets_data()
211 {
244 {
212
245
213 }
246 }
214
247
215 void tst_QBarSeries::appendBarSets()
248 void tst_QBarSeries::appendBarSets()
216 {
249 {
217 int count = 5;
250 int count = 5;
218 QVERIFY(m_barseries->barsetCount() == 0);
251 QVERIFY(m_barseries->barsetCount() == 0);
219
252
220 QList<QBarSet*> sets;
253 QList<QBarSet*> sets;
221 for (int i=0; i<count; i++) {
254 for (int i=0; i<count; i++) {
222 sets.append(new QBarSet("testset"));
255 sets.append(new QBarSet("testset"));
223 }
256 }
224
257
225 m_barseries->appendBarSets(sets);
258 // Append new sets (should succeed, count should match the count of sets)
259 bool ret = false;
260 ret = m_barseries->appendBarSets(sets);
261 QVERIFY(ret == true);
262 QVERIFY(m_barseries->barsetCount() == count);
263
264 // Append same sets again (should fail, count should remain same)
265 ret = m_barseries->appendBarSets(sets);
266 QVERIFY(ret == false);
267 QVERIFY(m_barseries->barsetCount() == count);
268
269 // Try append empty list (should succeed, but count should remain same)
270 QList<QBarSet*> invalidList;
271 ret = m_barseries->appendBarSets(invalidList);
272 QVERIFY(ret == true);
273 QVERIFY(m_barseries->barsetCount() == count);
274
275 // Try append list with one new and one existing set (should fail, count remains same)
276 invalidList.append(new QBarSet("ok set"));
277 invalidList.append(sets.at(0));
278 ret = m_barseries->appendBarSets(invalidList);
279 QVERIFY(ret == false);
280 QVERIFY(m_barseries->barsetCount() == count);
281
282 // Try append list with null pointers (should fail, count remains same)
283 QList<QBarSet*> invalidList2;
284 invalidList2.append(0);
285 invalidList2.append(0);
286 invalidList2.append(0);
287 ret = m_barseries->appendBarSets(invalidList2);
288 QVERIFY(ret == false);
226 QVERIFY(m_barseries->barsetCount() == count);
289 QVERIFY(m_barseries->barsetCount() == count);
227 }
290 }
228
291
229 void tst_QBarSeries::removeBarSets_data()
292 void tst_QBarSeries::removeBarSets_data()
230 {
293 {
231
294
232 }
295 }
233
296
234 void tst_QBarSeries::removeBarSets()
297 void tst_QBarSeries::removeBarSets()
235 {
298 {
236 int count = m_testSets.count();
299 int count = m_testSets.count();
237 QVERIFY(m_barseries_with_sets->barsetCount() == count);
300 QVERIFY(m_barseries_with_sets->barsetCount() == count);
238
301
239 // Try removing empty list of sets
302 // Try removing empty list of sets (should return false, since no barsets were removed)
240 QList<QBarSet*> empty;
303 bool ret = false;
241 m_barseries_with_sets->removeBarSets(empty);
304 QList<QBarSet*> invalidList;
305 ret = m_barseries_with_sets->removeBarSets(invalidList);
306 QVERIFY(ret == false);
307 QVERIFY(m_barseries_with_sets->barsetCount() == count);
308
309 // Add some null pointers to list
310 invalidList.append(0);
311 invalidList.append(0);
312 invalidList.append(0);
313
314 // Try removing null pointers from list (should return false, should not crash, should not remove anything)
315 ret = m_barseries_with_sets->removeBarSets(invalidList);
316 QVERIFY(ret == false);
242 QVERIFY(m_barseries_with_sets->barsetCount() == count);
317 QVERIFY(m_barseries_with_sets->barsetCount() == count);
243
318
244 // remove all sets
319 // remove all sets (should return true, since sets were removed)
245 m_barseries_with_sets->removeBarSets(m_testSets);
320 ret = m_barseries_with_sets->removeBarSets(m_testSets);
321 QVERIFY(ret == true);
246 QVERIFY(m_barseries_with_sets->barsetCount() == 0);
322 QVERIFY(m_barseries_with_sets->barsetCount() == 0);
247
323
248 // Try removing empty list again
324 // Try removing invalid list again (should return false, since no barsets were removed)
249 m_barseries_with_sets->removeBarSets(empty);
325 ret = m_barseries_with_sets->removeBarSets(invalidList);
326 QVERIFY(ret == false);
250 QVERIFY(m_barseries_with_sets->barsetCount() == 0);
327 QVERIFY(m_barseries_with_sets->barsetCount() == 0);
251
328
252 // remove all sets again
329 // remove all sets again (should return false, since barsets were already removed)
253 m_barseries_with_sets->removeBarSets(m_testSets);
330 ret = m_barseries_with_sets->removeBarSets(m_testSets);
331 QVERIFY(ret == false);
254 QVERIFY(m_barseries_with_sets->barsetCount() == 0);
332 QVERIFY(m_barseries_with_sets->barsetCount() == 0);
255 }
333 }
256
334
257 void tst_QBarSeries::barsetCount_data()
335 void tst_QBarSeries::barsetCount_data()
258 {
336 {
259
337
260 }
338 }
261
339
262 void tst_QBarSeries::barsetCount()
340 void tst_QBarSeries::barsetCount()
263 {
341 {
264 QVERIFY(m_barseries->barsetCount() == 0);
342 QVERIFY(m_barseries->barsetCount() == 0);
265 QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count());
343 QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count());
266 }
344 }
267
345
268 void tst_QBarSeries::categoryCount_data()
346 void tst_QBarSeries::categoryCount_data()
269 {
347 {
270
348
271 }
349 }
272
350
273 void tst_QBarSeries::categoryCount()
351 void tst_QBarSeries::categoryCount()
274 {
352 {
275 QVERIFY(m_barseries->categoryCount() == m_categories.count());
353 QVERIFY(m_barseries->categoryCount() == m_categories.count());
276 QVERIFY(m_barseries_with_sets->categoryCount() == m_categories.count());
354 QVERIFY(m_barseries_with_sets->categoryCount() == m_categories.count());
277 }
355 }
278
356
279 void tst_QBarSeries::barSets_data()
357 void tst_QBarSeries::barSets_data()
280 {
358 {
281
359
282 }
360 }
283
361
284 void tst_QBarSeries::barSets()
362 void tst_QBarSeries::barSets()
285 {
363 {
286 QVERIFY(m_barseries->barSets().count() == 0);
364 QVERIFY(m_barseries->barSets().count() == 0);
287
365
288 QList<QBarSet*> sets = m_barseries_with_sets->barSets();
366 QList<QBarSet*> sets = m_barseries_with_sets->barSets();
289 QVERIFY(sets.count() == m_testSets.count());
367 QVERIFY(sets.count() == m_testSets.count());
290
368
291 for (int i=0; i<m_testSets.count(); i++) {
369 for (int i=0; i<m_testSets.count(); i++) {
292 QVERIFY(sets.at(i) == m_testSets.at(i));
370 QVERIFY(sets.at(i) == m_testSets.at(i));
293 }
371 }
294 }
372 }
295
373
296 void tst_QBarSeries::categories_data()
374 void tst_QBarSeries::categories_data()
297 {
375 {
298
376
299 }
377 }
300
378
301 void tst_QBarSeries::categories()
379 void tst_QBarSeries::categories()
302 {
380 {
303 QBarCategories categories = m_barseries->categories();
381 QBarCategories categories = m_barseries->categories();
304
382
305 QVERIFY(categories.count() == m_categories.count());
383 QVERIFY(categories.count() == m_categories.count());
306 for (int i=0; i<m_categories.count(); i++) {
384 for (int i=0; i<m_categories.count(); i++) {
307 QVERIFY(categories.at(i).compare(m_categories.at(i)) == 0);
385 QVERIFY(categories.at(i).compare(m_categories.at(i)) == 0);
308 }
386 }
309 }
387 }
310
388
311 void tst_QBarSeries::setLabelsVisible_data()
389 void tst_QBarSeries::setLabelsVisible_data()
312 {
390 {
313
391
314 }
392 }
315
393
316 void tst_QBarSeries::setLabelsVisible()
394 void tst_QBarSeries::setLabelsVisible()
317 {
395 {
318 foreach (QBarSet* s, m_testSets) {
396 foreach (QBarSet* s, m_testSets) {
319 QVERIFY(s->labelsVisible() == false);
397 QVERIFY(s->labelsVisible() == false);
320 }
398 }
321
399
322 m_barseries_with_sets->setLabelsVisible(true);
400 m_barseries_with_sets->setLabelsVisible(true);
323 foreach (QBarSet* s, m_testSets) {
401 foreach (QBarSet* s, m_testSets) {
324 QVERIFY(s->labelsVisible() == true);
402 QVERIFY(s->labelsVisible() == true);
325 }
403 }
326
404
327 m_barseries_with_sets->setLabelsVisible(false);
405 m_barseries_with_sets->setLabelsVisible(false);
328 foreach (QBarSet* s, m_testSets) {
406 foreach (QBarSet* s, m_testSets) {
329 QVERIFY(s->labelsVisible() == false);
407 QVERIFY(s->labelsVisible() == false);
330 }
408 }
331 }
409 }
332
410
333 /*
411 /*
334 bool setModel(QAbstractItemModel *model);
412 bool setModel(QAbstractItemModel *model);
335 void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
413 void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
336 void setModelMappingRange(int first, int count = -1);
414 void setModelMappingRange(int first, int count = -1);
337 */
415 */
338 QTEST_MAIN(tst_QBarSeries)
416 QTEST_MAIN(tst_QBarSeries)
339
417
340 #include "tst_qbarseries.moc"
418 #include "tst_qbarseries.moc"
341
419
General Comments 0
You need to be logged in to leave comments. Login now