##// END OF EJS Templates
Adds more logic and documentation to qbarcategoryaxis for append, insert, replace, clear
Michal Klocek -
r2121:95b5b5ea3834
parent child
Show More
@@ -1,482 +1,554
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 "qbarcategoryaxis.h"
21 #include "qbarcategoryaxis.h"
22 #include "qbarcategoryaxis_p.h"
22 #include "qbarcategoryaxis_p.h"
23 #include "chartbarcategoryaxisx_p.h"
23 #include "chartbarcategoryaxisx_p.h"
24 #include "chartbarcategoryaxisy_p.h"
24 #include "chartbarcategoryaxisy_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include <qmath.h>
27 #include <qmath.h>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 /*!
30 /*!
31 \class QBarCategoryAxis
31 \class QBarCategoryAxis
32 \brief The QBarCategoryAxis class is used for manipulating chart's axis.
32 \brief The QBarCategoryAxis class is used for manipulating chart's axis.
33 \mainclass
33 \mainclass
34
34
35 BarCategoryAxis can be setup to show axis line with tick marks, grid lines and shades.
35 BarCategoryAxis can be setup to show axis line with tick marks, grid lines and shades.
36 Categories are drawn between ticks. Note that you can use this also with lineseries too.
36 Categories are drawn between ticks. Note that you can use this also with lineseries too.
37 See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that.
37 See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that.
38
38
39 Example code on how to use QBarCategoryAxis.
39 Example code on how to use QBarCategoryAxis.
40 \code
40 \code
41 QChartView *chartView = new QChartView;
41 QChartView *chartView = new QChartView;
42 QBarSeries *series = new QBarSeries;
42 QBarSeries *series = new QBarSeries;
43 // ...
43 // ...
44 chartView->chart()->addSeries(series);
44 chartView->chart()->addSeries(series);
45 chartView->chart()->createDefaultAxes();
45 chartView->chart()->createDefaultAxes();
46
46
47 QBarCategoryAxis *axisX = new QBarCategoryAxis;
47 QBarCategoryAxis *axisX = new QBarCategoryAxis;
48 QStringList categories;
48 QStringList categories;
49 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
49 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
50 axisX->append(categories);
50 axisX->append(categories);
51 axisX->setRange("Feb", "May");
51 axisX->setRange("Feb", "May");
52 chartView->chart()->setAxisX(axisX, series);
52 chartView->chart()->setAxisX(axisX, series);
53 \endcode
53 \endcode
54 */
54 */
55
55
56 /*!
56 /*!
57 \qmlclass BarCategoryAxis QBarCategoryAxis
57 \qmlclass BarCategoryAxis QBarCategoryAxis
58 \inherits AbstractAxis
58 \inherits AbstractAxis
59 \brief The Axis element is used for manipulating chart's axes.
59 \brief The Axis element is used for manipulating chart's axes.
60
60
61 Axis can be setup to show axis line with tick marks, grid lines and shades.
61 Axis can be setup to show axis line with tick marks, grid lines and shades.
62 Categories are drawn between ticks. Note that you can use this also with lineseries too.
62 Categories are drawn between ticks. Note that you can use this also with lineseries too.
63
63
64 To access BarCategoryAxis you can use ChartView API. For example:
64 To access BarCategoryAxis you can use ChartView API. For example:
65 \code
65 \code
66 ChartView {
66 ChartView {
67 BarCategoryAxis {
67 BarCategoryAxis {
68 id: categoryAxis
68 id: categoryAxis
69 categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
69 categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
70 }
70 }
71 // Add a few series...
71 // Add a few series...
72 }
72 }
73 \endcode
73 \endcode
74 */
74 */
75
75
76 /*!
76 /*!
77 \property QBarCategoryAxis::categories
77 \property QBarCategoryAxis::categories
78 Defines the categories of axis
78 Defines the categories of axis
79 */
79 */
80 /*!
80 /*!
81 \qmlproperty QStringList BarCategoryAxis::categories
81 \qmlproperty QStringList BarCategoryAxis::categories
82 Defines the categories of axis
82 Defines the categories of axis
83 */
83 */
84
84
85 /*!
85 /*!
86 \property QBarCategoryAxis::min
86 \property QBarCategoryAxis::min
87 Defines the minimum value on the axis.
87 Defines the minimum value on the axis.
88 */
88 */
89 /*!
89 /*!
90 \qmlproperty QString BarCategoryAxis::min
90 \qmlproperty QString BarCategoryAxis::min
91 Defines the minimum value on the axis.
91 Defines the minimum value on the axis.
92 */
92 */
93
93
94 /*!
94 /*!
95 \property QBarCategoryAxis::max
95 \property QBarCategoryAxis::max
96 Defines the maximum value on the axis.
96 Defines the maximum value on the axis.
97 */
97 */
98 /*!
98 /*!
99 \qmlproperty QString BarCategoryAxis::max
99 \qmlproperty QString BarCategoryAxis::max
100 Defines the maximum value on the axis.
100 Defines the maximum value on the axis.
101 */
101 */
102
102
103
103
104 /*!
104 /*!
105 \fn void QBarCategoryAxis::categoriesChanged()
105 \fn void QBarCategoryAxis::categoriesChanged()
106 Axis emits signal when the categories of the axis has changed.
106 Axis emits signal when the categories of the axis has changed.
107 */
107 */
108 /*!
108 /*!
109 \fn void QBarCategoryAxis::minChanged(const QString &min)
109 \fn void QBarCategoryAxis::minChanged(const QString &min)
110 Axis emits signal when \a min of axis has changed.
110 Axis emits signal when \a min of axis has changed.
111 */
111 */
112 /*!
112 /*!
113 \qmlsignal BarCategoryAxis::onMinChanged(const QString &min)
113 \qmlsignal BarCategoryAxis::onMinChanged(const QString &min)
114 Axis emits signal when \a min of axis has changed.
114 Axis emits signal when \a min of axis has changed.
115 */
115 */
116
116
117 /*!
117 /*!
118 \fn void QBarCategoryAxis::maxChanged(const QString &max)
118 \fn void QBarCategoryAxis::maxChanged(const QString &max)
119 Axis emits signal when \a max of axis has changed.
119 Axis emits signal when \a max of axis has changed.
120 */
120 */
121 /*!
121 /*!
122 \qmlsignal BarCategoryAxis::onMaxChanged(const QString &max)
122 \qmlsignal BarCategoryAxis::onMaxChanged(const QString &max)
123 Axis emits signal when \a max of axis has changed.
123 Axis emits signal when \a max of axis has changed.
124 */
124 */
125
125
126 /*!
126 /*!
127 \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max)
127 \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max)
128 Axis emits signal when \a min or \a max of axis has changed.
128 Axis emits signal when \a min or \a max of axis has changed.
129 */
129 */
130
130
131 /*!
131 /*!
132 Constructs an axis object which is a child of \a parent.
132 Constructs an axis object which is a child of \a parent.
133 */
133 */
134 QBarCategoryAxis::QBarCategoryAxis(QObject *parent):
134 QBarCategoryAxis::QBarCategoryAxis(QObject *parent):
135 QAbstractAxis(*new QBarCategoryAxisPrivate(this), parent)
135 QAbstractAxis(*new QBarCategoryAxisPrivate(this), parent)
136 {
136 {
137 }
137 }
138
138
139 /*!
139 /*!
140 Destroys the object
140 Destroys the object
141 */
141 */
142 QBarCategoryAxis::~QBarCategoryAxis()
142 QBarCategoryAxis::~QBarCategoryAxis()
143 {
143 {
144 Q_D(QBarCategoryAxis);
144 Q_D(QBarCategoryAxis);
145 if (d->m_dataset)
145 if (d->m_dataset)
146 d->m_dataset->removeAxis(this);
146 d->m_dataset->removeAxis(this);
147 }
147 }
148
148
149 /*!
149 /*!
150 \internal
150 \internal
151 */
151 */
152 QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d, QObject *parent)
152 QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d, QObject *parent)
153 : QAbstractAxis(d, parent)
153 : QAbstractAxis(d, parent)
154 {
154 {
155
155
156 }
156 }
157
157
158 /*!
158 /*!
159 Appends \a categories to axis
159 Appends \a categories to axis. A maximum of the axis will be changed to last category in \a categories.
160 If there were no categories previously defined, minimum of axis will be also changed to first category in \a categories.
161 A category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended.
160 */
162 */
161 void QBarCategoryAxis::append(const QStringList &categories)
163 void QBarCategoryAxis::append(const QStringList &categories)
162 {
164 {
163 if (categories.isEmpty())
165 if (categories.isEmpty())
164 return;
166 return;
165
167
166 Q_D(QBarCategoryAxis);
168 Q_D(QBarCategoryAxis);
167 if (d->m_categories.isEmpty()) {
169
168 d->m_categories.append(categories);
170 int count = d->m_categories.count();
169 setRange(categories.first(), categories.last());
171
172 foreach(QString category, categories)
173 {
174 if(!d->m_categories.contains(category) && !category.isNull()) {
175 d->m_categories.append(category);
176 }
177 }
178
179 if(d->m_categories.count() == count) return;
180
181 if (count == 0) {
182 setRange(d->m_categories.first(), d->m_categories.last());
170 } else {
183 } else {
171 d->m_categories.append(categories);
184 setRange(d->m_minCategory, d->m_categories.last());
172 d->emitUpdated();
173 }
185 }
186
174 emit categoriesChanged();
187 emit categoriesChanged();
175 }
188 }
176
189
177 /*!
190 /*!
178 Appends \a category to axis
191 Appends \a category to axis. A maximum of the axis will be changed to last \a category.
192 If there were no categories previously defined, minimum of axis will be also changed to \a category.
193 A \a category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended.
179 */
194 */
180 void QBarCategoryAxis::append(const QString &category)
195 void QBarCategoryAxis::append(const QString &category)
181 {
196 {
182 Q_D(QBarCategoryAxis);
197 Q_D(QBarCategoryAxis);
183 if (d->m_categories.isEmpty()) {
198
199 int count = d->m_categories.count();
200
201 if(!d->m_categories.contains(category) && !category.isNull()){
184 d->m_categories.append(category);
202 d->m_categories.append(category);
185 setRange(category, category);
203 }
204
205 if(d->m_categories.count() == count) return;
206
207 if (count == 0) {
208 setRange(d->m_categories.last(), d->m_categories.last());
186 } else {
209 } else {
187 d->m_categories.append(category);
210 setRange(d->m_minCategory, d->m_categories.last());
188 d->emitUpdated();
189 }
211 }
212
190 emit categoriesChanged();
213 emit categoriesChanged();
191 }
214 }
192
215
193 /*!
216 /*!
194 Removes \a category from axis
217 Removes \a category from axis. Removing category which is currently maximum or minimum
218 will affect the axis range.
195 */
219 */
196 void QBarCategoryAxis::remove(const QString &category)
220 void QBarCategoryAxis::remove(const QString &category)
197 {
221 {
198 Q_D(QBarCategoryAxis);
222 Q_D(QBarCategoryAxis);
223
199 if (d->m_categories.contains(category)) {
224 if (d->m_categories.contains(category)) {
200 d->m_categories.removeAt(d->m_categories.indexOf(category));
225 d->m_categories.removeAt(d->m_categories.indexOf(category));
201 if (!d->m_categories.isEmpty())
226 if (!d->m_categories.isEmpty()){
202 setRange(d->m_categories.first(), d->m_categories.last());
227 if(d->m_minCategory == category){
203 else
228 setRange(d->m_categories.first(), d->m_maxCategory);
229 } else if(d->m_maxCategory == category){
230 setRange(d->m_minCategory, d->m_categories.last());
231 } else {
232 d->updateCategoryDomain();
233 d->emitUpdated();
234 }
235 }else
204 setRange(QString::null, QString::null);
236 setRange(QString::null, QString::null);
205 emit categoriesChanged();
237 emit categoriesChanged();
206 }
238 }
207 }
239 }
208
240
209 /*!
241 /*!
210 Inserts \a category to axis at \a index
242 Inserts \a category to axis at \a index. A \a category has to be valid QStrings and can not be duplicated.
243 If \a category is prepended or appended to categories, minimum and maximum of axis is updated accordingly.
211 */
244 */
212 void QBarCategoryAxis::insert(int index, const QString &category)
245 void QBarCategoryAxis::insert(int index, const QString &category)
213 {
246 {
214 Q_D(QBarCategoryAxis);
247 Q_D(QBarCategoryAxis);
215 if (d->m_categories.isEmpty()) {
248
249 int count = d->m_categories.count();
250
251 if(!d->m_categories.contains(category) && !category.isNull()){
216 d->m_categories.insert(index, category);
252 d->m_categories.insert(index, category);
217 setRange(category, category);
253 }
254
255 if(d->m_categories.count() == count) return;
256
257 if (count == 0) {
258 setRange(d->m_categories.first(), d->m_categories.first());
259 } else if (index == 0) {
260 setRange(d->m_categories.first(), d->m_maxCategory);
261 } else if (index == count){
262 setRange(d->m_minCategory, d->m_categories.last());
218 } else {
263 } else {
219 d->m_categories.insert(index, category);
264 d->updateCategoryDomain();
220 d->emitUpdated();
265 d->emitUpdated();
221 }
266 }
267
222 emit categoriesChanged();
268 emit categoriesChanged();
223 }
269 }
224
270
225 /*!
271 /*!
226 Replaces \a oldCategory with \a newCategory.
272 Replaces \a oldCategory with \a newCategory. If \a oldCategory does not exits on the axis nothing is done.
227 If \a oldCategory does not exits on the axis nothing is done.
273 A \a newVategory has to be valid QStrings and can not be duplicated. In case of replacing minimum or maximum category,
274 minimum and maximum of axis is updated accordingly.
228 */
275 */
229 void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory)
276 void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory)
230 {
277 {
231 Q_D(QBarCategoryAxis);
278 Q_D(QBarCategoryAxis);
279
232 int pos = d->m_categories.indexOf(oldCategory);
280 int pos = d->m_categories.indexOf(oldCategory);
233 if (pos != -1) {
281
282 if (pos != -1 && !d->m_categories.contains(newCategory) && !newCategory.isNull()) {
234 d->m_categories.replace(pos, newCategory);
283 d->m_categories.replace(pos, newCategory);
235 d->emitUpdated();
284 if(d->m_minCategory == oldCategory) {
285 setRange(newCategory, d->m_maxCategory);
286 } else if(d->m_maxCategory == oldCategory) {
287 setRange(d->m_minCategory, newCategory);
288 } else {
289 d->emitUpdated();
290 }
236 emit categoriesChanged();
291 emit categoriesChanged();
237 }
292 }
238 }
293 }
239
294
240 /*!
295 /*!
241 Removes all categories.
296 Removes all categories. Sets the maximum and minimum of the axis's range to QString::null.
242 */
297 */
243 void QBarCategoryAxis::clear()
298 void QBarCategoryAxis::clear()
244 {
299 {
245 Q_D(QBarCategoryAxis);
300 Q_D(QBarCategoryAxis);
246 d->m_categories.clear();
301 d->m_categories.clear();
247 setRange(QString::null, QString::null);
302 setRange(QString::null, QString::null);
248 emit categoriesChanged();
303 emit categoriesChanged();
249 }
304 }
250
305
306 /*!
307 Set \a categories and discards the old ones, range of axis is adjusted to match first and last category in \a categories.
308 A category has to be valid QStrings and can not be duplicated.
309 */
251 void QBarCategoryAxis::setCategories(const QStringList &categories)
310 void QBarCategoryAxis::setCategories(const QStringList &categories)
252 {
311 {
253 Q_D(QBarCategoryAxis);
312 Q_D(QBarCategoryAxis);
254 if (d->m_categories != categories) {
313 d->m_categories.clear();
255 d->m_categories = categories;
314 d->m_minCategory = QString::null;
256 setRange(categories.first(), categories.last());
315 d->m_maxCategory = QString::null;
257 emit categoriesChanged();
316 d->m_min = 0;
258 }
317 d->m_max = 0;
318 d->m_count = 0;
319 append(categories);
259 }
320 }
260
321
322 /*!
323 Returns categories
324 */
261 QStringList QBarCategoryAxis::categories()
325 QStringList QBarCategoryAxis::categories()
262 {
326 {
263 Q_D(QBarCategoryAxis);
327 Q_D(QBarCategoryAxis);
264 return d->m_categories;
328 return d->m_categories;
265 }
329 }
266
330
267 /*!
331 /*!
268 Returns number of categories.
332 Returns number of categories.
269 */
333 */
270 int QBarCategoryAxis::count() const
334 int QBarCategoryAxis::count() const
271 {
335 {
272 Q_D(const QBarCategoryAxis);
336 Q_D(const QBarCategoryAxis);
273 return d->m_categories.count();
337 return d->m_categories.count();
274 }
338 }
275
339
276 /*!
340 /*!
277 Returns category at \a index. Index must be valid.
341 Returns category at \a index. Index must be valid.
278 */
342 */
279 QString QBarCategoryAxis::at(int index) const
343 QString QBarCategoryAxis::at(int index) const
280 {
344 {
281 Q_D(const QBarCategoryAxis);
345 Q_D(const QBarCategoryAxis);
282 return d->m_categories.at(index);
346 return d->m_categories.at(index);
283 }
347 }
284
348
285 /*!
349 /*!
286 Sets minimum category to \a min.
350 Sets minimum category to \a min.
287 */
351 */
288 void QBarCategoryAxis::setMin(const QString &min)
352 void QBarCategoryAxis::setMin(const QString &min)
289 {
353 {
290 Q_D(QBarCategoryAxis);
354 Q_D(QBarCategoryAxis);
291 setRange(min, d->m_maxCategory);
355 setRange(min, d->m_maxCategory);
292 }
356 }
293
357
294 /*!
358 /*!
295 Returns minimum category.
359 Returns minimum category.
296 */
360 */
297 QString QBarCategoryAxis::min() const
361 QString QBarCategoryAxis::min() const
298 {
362 {
299 Q_D(const QBarCategoryAxis);
363 Q_D(const QBarCategoryAxis);
300 return d->m_minCategory;
364 return d->m_minCategory;
301 }
365 }
302
366
303 /*!
367 /*!
304 Sets maximum category to \a max.
368 Sets maximum category to \a max.
305 */
369 */
306 void QBarCategoryAxis::setMax(const QString &max)
370 void QBarCategoryAxis::setMax(const QString &max)
307 {
371 {
308 Q_D(QBarCategoryAxis);
372 Q_D(QBarCategoryAxis);
309 setRange(d->m_minCategory, max);
373 setRange(d->m_minCategory, max);
310 }
374 }
311
375
312 /*!
376 /*!
313 Returns maximum category
377 Returns maximum category
314 */
378 */
315 QString QBarCategoryAxis::max() const
379 QString QBarCategoryAxis::max() const
316 {
380 {
317 Q_D(const QBarCategoryAxis);
381 Q_D(const QBarCategoryAxis);
318 return d->m_maxCategory;
382 return d->m_maxCategory;
319 }
383 }
320
384
321 /*!
385 /*!
322 Sets range from \a minCategory to \a maxCategory
386 Sets range from \a minCategory to \a maxCategory
323 */
387 */
324 void QBarCategoryAxis::setRange(const QString &minCategory, const QString &maxCategory)
388 void QBarCategoryAxis::setRange(const QString &minCategory, const QString &maxCategory)
325 {
389 {
326 Q_D(QBarCategoryAxis);
390 Q_D(QBarCategoryAxis);
327
391
328 bool changed = false;
392 bool changed = false;
329
393
330 //special case
394 //special case in case or clearing all categories
331 if (minCategory.isNull() && maxCategory.isNull()) {
395 if (minCategory.isNull() && maxCategory.isNull()) {
332 d->m_minCategory = minCategory;
396 d->m_minCategory = minCategory;
333 d->m_maxCategory = maxCategory;
397 d->m_maxCategory = maxCategory;
334 d->m_min = 0;
398 d->m_min = 0;
335 d->m_max = 0;
399 d->m_max = 0;
336 emit minChanged(minCategory);
400 emit minChanged(minCategory);
337 emit maxChanged(maxCategory);
401 emit maxChanged(maxCategory);
338 d->m_count = 0;
402 d->m_count = 0;
339 emit rangeChanged(d->m_minCategory, d->m_maxCategory);
403 emit rangeChanged(d->m_minCategory, d->m_maxCategory);
340 d->emitUpdated();
404 d->emitUpdated();
341 }
405 }
342
406
343 if (d->m_categories.indexOf(d->m_maxCategory) < d->m_categories.indexOf(d->m_minCategory))
407 if (d->m_categories.indexOf(maxCategory) < d->m_categories.indexOf(minCategory)){
344 return;
408 return;
345
409 }
346 if (!minCategory.isEmpty() && d->m_minCategory != minCategory && d->m_categories.contains(minCategory)) {
410 if (!minCategory.isEmpty() && d->m_minCategory != minCategory && d->m_categories.contains(minCategory)) {
347 d->m_minCategory = minCategory;
411 d->m_minCategory = minCategory;
348 d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5;
412 d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5;
349 changed = true;
413 changed = true;
350 emit minChanged(minCategory);
414 emit minChanged(minCategory);
351 }
415 }
352
416
353 if (!maxCategory.isEmpty() && d->m_maxCategory != maxCategory && d->m_categories.contains(maxCategory)) {
417 if (!maxCategory.isEmpty() && d->m_maxCategory != maxCategory && d->m_categories.contains(maxCategory)) {
354 d->m_maxCategory = maxCategory;
418 d->m_maxCategory = maxCategory;
355 d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5;
419 d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5;
356 changed = true;
420 changed = true;
357 emit maxChanged(maxCategory);
421 emit maxChanged(maxCategory);
358 }
422 }
359
423
360 if (changed) {
424 if (changed) {
361 d->m_count = d->m_max - d->m_min;
425 d->m_count = d->m_max - d->m_min;
362 emit rangeChanged(d->m_minCategory, d->m_maxCategory);
426 emit rangeChanged(d->m_minCategory, d->m_maxCategory);
363 d->emitUpdated();
427 d->emitUpdated();
364 }
428 }
365 }
429 }
366
430
367 /*!
431 /*!
368 Returns the type of the axis
432 Returns the type of the axis
369 */
433 */
370 QAbstractAxis::AxisType QBarCategoryAxis::type() const
434 QAbstractAxis::AxisType QBarCategoryAxis::type() const
371 {
435 {
372 return AxisTypeBarCategory;
436 return AxisTypeBarCategory;
373 }
437 }
374
438
375 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
439 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
376
440
377 QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis *q)
441 QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis *q)
378 : QAbstractAxisPrivate(q),
442 : QAbstractAxisPrivate(q),
379 m_min(0.0),
443 m_min(0.0),
380 m_max(0.0),
444 m_max(0.0),
381 m_count(0)
445 m_count(0)
382 {
446 {
383
447
384 }
448 }
385
449
386 QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate()
450 QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate()
387 {
451 {
388
452
389 }
453 }
390
454
391 void QBarCategoryAxisPrivate::setMin(const QVariant &min)
455 void QBarCategoryAxisPrivate::setMin(const QVariant &min)
392 {
456 {
393 setRange(min, m_maxCategory);
457 setRange(min, m_maxCategory);
394 }
458 }
395
459
396 void QBarCategoryAxisPrivate::setMax(const QVariant &max)
460 void QBarCategoryAxisPrivate::setMax(const QVariant &max)
397 {
461 {
398 setRange(m_minCategory, max);
462 setRange(m_minCategory, max);
399 }
463 }
400
464
401 void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max)
465 void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max)
402 {
466 {
403 Q_Q(QBarCategoryAxis);
467 Q_Q(QBarCategoryAxis);
404 QString value1 = min.toString();
468 QString value1 = min.toString();
405 QString value2 = max.toString();
469 QString value2 = max.toString();
406 q->setRange(value1, value2);
470 q->setRange(value1, value2);
407 }
471 }
408
472
409 void QBarCategoryAxisPrivate::handleDomainUpdated()
473 void QBarCategoryAxisPrivate::handleDomainUpdated()
410 {
474 {
411 Q_Q(QBarCategoryAxis);
475 Q_Q(QBarCategoryAxis);
412 Domain *domain = qobject_cast<Domain *>(sender());
476 Domain *domain = qobject_cast<Domain *>(sender());
413
477
414 if (m_orientation == Qt::Horizontal) {
478 if (m_orientation == Qt::Horizontal) {
415 m_min = domain->minX();
479 m_min = domain->minX();
416 m_max = domain->maxX();
480 m_max = domain->maxX();
417 } else if (m_orientation == Qt::Vertical) {
481 } else if (m_orientation == Qt::Vertical) {
418 m_min = domain->minY();
482 m_min = domain->minY();
419 m_max = domain->maxY();
483 m_max = domain->maxY();
420 }
484 }
421
485
422 bool changed = false;
486 bool changed = false;
423
487
424 int min = m_min + 0.5;
488 int min = m_min + 0.5;
425 if (min >= 0 && min < m_categories.count()) {
489 if (min >= 0 && min < m_categories.count()) {
426 QString minCategory = m_categories.at(min);
490 QString minCategory = m_categories.at(min);
427 if (m_minCategory != minCategory && !minCategory.isEmpty()) {
491 if (m_minCategory != minCategory && !minCategory.isEmpty()) {
428 m_minCategory = minCategory;
492 m_minCategory = minCategory;
429 changed = true;
493 changed = true;
430 emit q->minChanged(minCategory);
494 emit q->minChanged(minCategory);
431 }
495 }
432 }
496 }
433 int max = m_max - 0.5;
497 int max = m_max - 0.5;
434 if (max >= 0 && max < m_categories.count()) {
498 if (max >= 0 && max < m_categories.count()) {
435 QString maxCategory = m_categories.at(max);
499 QString maxCategory = m_categories.at(max);
436 if (m_maxCategory != maxCategory && !maxCategory.isEmpty()) {
500 if (m_maxCategory != maxCategory && !maxCategory.isEmpty()) {
437 m_maxCategory = maxCategory;
501 m_maxCategory = maxCategory;
438 emit q->maxChanged(maxCategory);
502 emit q->maxChanged(maxCategory);
439 }
503 }
440 }
504 }
441
505
442 if (changed)
506 if (changed)
443 emit q->rangeChanged(m_minCategory, m_maxCategory);
507 emit q->rangeChanged(m_minCategory, m_maxCategory);
444 }
508 }
445
509
446 ChartAxis *QBarCategoryAxisPrivate::createGraphics(ChartPresenter *presenter)
510 ChartAxis *QBarCategoryAxisPrivate::createGraphics(ChartPresenter *presenter)
447 {
511 {
448 Q_Q(QBarCategoryAxis);
512 Q_Q(QBarCategoryAxis);
449 if (m_orientation == Qt::Vertical)
513 if (m_orientation == Qt::Vertical)
450 return new ChartBarCategoryAxisY(q, presenter);
514 return new ChartBarCategoryAxisY(q, presenter);
451 return new ChartBarCategoryAxisX(q, presenter);
515 return new ChartBarCategoryAxisX(q, presenter);
452 }
516 }
453
517
518 void QBarCategoryAxisPrivate::updateCategoryDomain()
519 {
520 m_min = m_categories.indexOf(m_minCategory) - 0.5;
521 m_max = m_categories.indexOf(m_maxCategory) + 0.5;
522 m_count = m_max - m_min;
523 }
524
525
454 void QBarCategoryAxisPrivate::intializeDomain(Domain *domain)
526 void QBarCategoryAxisPrivate::intializeDomain(Domain *domain)
455 {
527 {
456
528
457 Q_Q(QBarCategoryAxis);
529 Q_Q(QBarCategoryAxis);
458 if (m_max == m_min) {
530 if (m_max == m_min) {
459 int min;
531 int min;
460 int max;
532 int max;
461 if (m_orientation == Qt::Vertical) {
533 if (m_orientation == Qt::Vertical) {
462 min = domain->minY() + 0.5;
534 min = domain->minY() + 0.5;
463 max = domain->maxY() - 0.5;
535 max = domain->maxY() - 0.5;
464 } else {
536 } else {
465 min = domain->minX() + 0.5;
537 min = domain->minX() + 0.5;
466 max = domain->maxX() - 0.5;
538 max = domain->maxX() - 0.5;
467 }
539 }
468
540
469 if (min > 0 && min < m_categories.count() && max > 0 && max < m_categories.count())
541 if (min > 0 && min < m_categories.count() && max > 0 && max < m_categories.count())
470 q->setRange(m_categories.at(min), m_categories.at(max));
542 q->setRange(m_categories.at(min), m_categories.at(max));
471 } else {
543 } else {
472 if (m_orientation == Qt::Vertical)
544 if (m_orientation == Qt::Vertical)
473 domain->setRangeY(m_min, m_max);
545 domain->setRangeY(m_min, m_max);
474 else
546 else
475 domain->setRangeX(m_min, m_max);
547 domain->setRangeX(m_min, m_max);
476 }
548 }
477 }
549 }
478
550
479 #include "moc_qbarcategoryaxis.cpp"
551 #include "moc_qbarcategoryaxis.cpp"
480 #include "moc_qbarcategoryaxis_p.cpp"
552 #include "moc_qbarcategoryaxis_p.cpp"
481
553
482 QTCOMMERCIALCHART_END_NAMESPACE
554 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,76 +1,77
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QBARCATEGORYAXIS_P_H
30 #ifndef QBARCATEGORYAXIS_P_H
31 #define QBARCATEGORYAXIS_P_H
31 #define QBARCATEGORYAXIS_P_H
32
32
33 #include "qbarcategoryaxis.h"
33 #include "qbarcategoryaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qabstractaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class Domain;
38 class Domain;
39
39
40 class QBarCategoryAxisPrivate : public QAbstractAxisPrivate
40 class QBarCategoryAxisPrivate : public QAbstractAxisPrivate
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43
43
44 public:
44 public:
45 QBarCategoryAxisPrivate(QBarCategoryAxis *q);
45 QBarCategoryAxisPrivate(QBarCategoryAxis *q);
46 ~QBarCategoryAxisPrivate();
46 ~QBarCategoryAxisPrivate();
47
47
48 public:
48 public:
49 ChartAxis *createGraphics(ChartPresenter *presenter);
49 ChartAxis *createGraphics(ChartPresenter *presenter);
50 void intializeDomain(Domain *domain);
50 void intializeDomain(Domain *domain);
51 void handleDomainUpdated();
51 void handleDomainUpdated();
52 void updateCategoryDomain();
52 qreal min() { return m_min; }
53 qreal min() { return m_min; }
53 qreal max() { return m_max; }
54 qreal max() { return m_max; }
54 int count() const { return m_count; }
55 int count() const { return m_count; }
55
56
56 private:
57 private:
57 //range handling
58 //range handling
58 void setMin(const QVariant &min);
59 void setMin(const QVariant &min);
59 void setMax(const QVariant &max);
60 void setMax(const QVariant &max);
60 void setRange(const QVariant &min, const QVariant &max);
61 void setRange(const QVariant &min, const QVariant &max);
61
62
62 private:
63 private:
63 QStringList m_categories;
64 QStringList m_categories;
64 QString m_minCategory;
65 QString m_minCategory;
65 QString m_maxCategory;
66 QString m_maxCategory;
66 qreal m_min;
67 qreal m_min;
67 qreal m_max;
68 qreal m_max;
68 int m_count;
69 int m_count;
69
70
70 private:
71 private:
71 Q_DECLARE_PUBLIC(QBarCategoryAxis);
72 Q_DECLARE_PUBLIC(QBarCategoryAxis);
72 };
73 };
73
74
74 QTCOMMERCIALCHART_END_NAMESPACE
75 QTCOMMERCIALCHART_END_NAMESPACE
75
76
76 #endif // QBARCATEGORYAXIS_P_H
77 #endif // QBARCATEGORYAXIS_P_H
@@ -1,691 +1,689
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 "../qabstractaxis/tst_qabstractaxis.h"
21 #include "../qabstractaxis/tst_qabstractaxis.h"
22 #include <qbarseries.h>
22 #include <qbarseries.h>
23 #include <qbarset.h>
23 #include <qbarset.h>
24 #include <qbarcategoryaxis.h>
24 #include <qbarcategoryaxis.h>
25
25
26 class tst_QBarCategoriesAxis: public tst_QAbstractAxis
26 class tst_QBarCategoriesAxis: public tst_QAbstractAxis
27 {
27 {
28 Q_OBJECT
28 Q_OBJECT
29
29
30 public slots:
30 public slots:
31 void initTestCase();
31 void initTestCase();
32 void cleanupTestCase();
32 void cleanupTestCase();
33 void init();
33 void init();
34 void cleanup();
34 void cleanup();
35
35
36 private slots:
36 private slots:
37 void qbarcategoryaxis_data();
37 void qbarcategoryaxis_data();
38 void qbarcategoryaxis();
38 void qbarcategoryaxis();
39
39
40 void append2_data();
40 void append2_data();
41 void append2();
41 void append2();
42 void append_data();
42 void append_data();
43 void append();
43 void append();
44 void at_data();
44 void at_data();
45 void at();
45 void at();
46 void categories_data();
46 void categories_data();
47 void categories();
47 void categories();
48 void clear_data();
48 void clear_data();
49 void clear();
49 void clear();
50 void count_data();
50 void count_data();
51 void count();
51 void count();
52 void insert_data();
52 void insert_data();
53 void insert();
53 void insert();
54 void remove_data();
54 void remove_data();
55 void remove();
55 void remove();
56 void max_raw_data();
56 void max_raw_data();
57 void max_raw();
57 void max_raw();
58 void max_data();
58 void max_data();
59 void max();
59 void max();
60 void max_animation_data();
60 void max_animation_data();
61 void max_animation();
61 void max_animation();
62 void min_raw_data();
62 void min_raw_data();
63 void min_raw();
63 void min_raw();
64 void min_data();
64 void min_data();
65 void min();
65 void min();
66 void min_animation_data();
66 void min_animation_data();
67 void min_animation();
67 void min_animation();
68 void range_raw_data();
68 void range_raw_data();
69 void range_raw();
69 void range_raw();
70 void range_data();
70 void range_data();
71 void range();
71 void range();
72 void range_animation_data();
72 void range_animation_data();
73 void range_animation();
73 void range_animation();
74 void noautoscale_data();
74 void noautoscale_data();
75 void noautoscale();
75 void noautoscale();
76 void autoscale_data();
76 void autoscale_data();
77 void autoscale();
77 void autoscale();
78
78
79 private:
79 private:
80 QBarCategoryAxis* m_baraxis;
80 QBarCategoryAxis* m_baraxis;
81 QBarSeries* m_series;
81 QBarSeries* m_series;
82 };
82 };
83
83
84 void tst_QBarCategoriesAxis::initTestCase()
84 void tst_QBarCategoriesAxis::initTestCase()
85 {
85 {
86 }
86 }
87
87
88 void tst_QBarCategoriesAxis::cleanupTestCase()
88 void tst_QBarCategoriesAxis::cleanupTestCase()
89 {
89 {
90 }
90 }
91
91
92 void tst_QBarCategoriesAxis::init()
92 void tst_QBarCategoriesAxis::init()
93 {
93 {
94 m_baraxis = new QBarCategoryAxis();
94 m_baraxis = new QBarCategoryAxis();
95 m_series = new QBarSeries();
95 m_series = new QBarSeries();
96
96
97 QBarSet *set0 = new QBarSet("Jane");
97 QBarSet *set0 = new QBarSet("Jane");
98 QBarSet *set1 = new QBarSet("John");
98 QBarSet *set1 = new QBarSet("John");
99 QBarSet *set2 = new QBarSet("Axel");
99 QBarSet *set2 = new QBarSet("Axel");
100 QBarSet *set3 = new QBarSet("Mary");
100 QBarSet *set3 = new QBarSet("Mary");
101 QBarSet *set4 = new QBarSet("Samantha");
101 QBarSet *set4 = new QBarSet("Samantha");
102
102
103 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
103 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
104 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
104 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
105 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
105 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
106 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
106 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
107 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
107 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
108
108
109 m_series->append(set0);
109 m_series->append(set0);
110 m_series->append(set1);
110 m_series->append(set1);
111 m_series->append(set2);
111 m_series->append(set2);
112 m_series->append(set3);
112 m_series->append(set3);
113 m_series->append(set4);
113 m_series->append(set4);
114
114
115 QStringList categories;
115 QStringList categories;
116 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
116 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
117
117
118 foreach(QString category, categories)
118 foreach(QString category, categories)
119 m_baraxis->append(category);
119 m_baraxis->append(category);
120
120
121 tst_QAbstractAxis::init(m_baraxis, m_series);
121 tst_QAbstractAxis::init(m_baraxis, m_series);
122 m_chart->addSeries(m_series);
122 m_chart->addSeries(m_series);
123 m_chart->createDefaultAxes();
123 m_chart->createDefaultAxes();
124 }
124 }
125
125
126 void tst_QBarCategoriesAxis::cleanup()
126 void tst_QBarCategoriesAxis::cleanup()
127 {
127 {
128 delete m_series;
128 delete m_series;
129 delete m_baraxis;
129 delete m_baraxis;
130 m_series = 0;
130 m_series = 0;
131 m_baraxis = 0;
131 m_baraxis = 0;
132 tst_QAbstractAxis::cleanup();
132 tst_QAbstractAxis::cleanup();
133 }
133 }
134
134
135 void tst_QBarCategoriesAxis::qbarcategoryaxis_data()
135 void tst_QBarCategoriesAxis::qbarcategoryaxis_data()
136 {
136 {
137 }
137 }
138
138
139 void tst_QBarCategoriesAxis::qbarcategoryaxis()
139 void tst_QBarCategoriesAxis::qbarcategoryaxis()
140 {
140 {
141 qabstractaxis();
141 qabstractaxis();
142 QBarCategoryAxis axis;
142 QBarCategoryAxis axis;
143 axis.append(QStringList());
143 axis.append(QStringList());
144 axis.append(QString());
144 axis.append(QString());
145 QCOMPARE(axis.at(0), QString());
145 QCOMPARE(axis.count(), 0);
146 QStringList test;
146 QStringList test;
147 test.append(QString());
148 QCOMPARE(axis.categories(),test);
147 QCOMPARE(axis.categories(),test);
149 axis.clear();
148 axis.clear();
150 QCOMPARE(axis.count(), 0);
149 QCOMPARE(axis.count(), 0);
151 axis.insert(-1, QString());
150 axis.insert(-1, QString());
152 QCOMPARE(axis.max(), QString());
151 QCOMPARE(axis.max(), QString());
153 QCOMPARE(axis.min(), QString());
152 QCOMPARE(axis.min(), QString());
154 axis.remove(QString());
153 axis.remove(QString());
155 axis.setCategories(QStringList());
154 axis.setCategories(QStringList());
156 axis.setMax(QString());
155 axis.setMax(QString());
157 axis.setMin(QString());
156 axis.setMin(QString());
158 axis.setRange(QString(), QString());
157 axis.setRange(QString(), QString());
159 QCOMPARE(axis.type(), QAbstractAxis::AxisTypeBarCategory);
158 QCOMPARE(axis.type(), QAbstractAxis::AxisTypeBarCategory);
160 }
159 }
161
160
162 void tst_QBarCategoriesAxis::append_data()
161 void tst_QBarCategoriesAxis::append_data()
163 {
162 {
164 QTest::addColumn<QStringList>("categories");
163 QTest::addColumn<QStringList>("categories");
165 QTest::newRow("Jan Feb Mar Apr") << (QStringList() << "Jan" << "Feb" << "Mar" << "Apr");
164 QTest::newRow("Jan Feb Mar Apr") << (QStringList() << "Jan" << "Feb" << "Mar" << "Apr");
166 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
165 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
167 }
166 }
168
167
169 void tst_QBarCategoriesAxis::append()
168 void tst_QBarCategoriesAxis::append()
170 {
169 {
171 QFETCH(QStringList, categories);
170 QFETCH(QStringList, categories);
172
171
173 QBarCategoryAxis axis;
172 QBarCategoryAxis axis;
174
173
175 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
174 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
176 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
175 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
177 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
176 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
178 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
177 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
179
178
180 axis.append(categories);
179 axis.append(categories);
181
180
182 QCOMPARE(spy0.count(), 1);
181 QCOMPARE(spy0.count(), 1);
183 QCOMPARE(spy1.count(), 1);
182 QCOMPARE(spy1.count(), 1);
184 QCOMPARE(spy2.count(), 1);
183 QCOMPARE(spy2.count(), 1);
185 QCOMPARE(spy3.count(), 1);
184 QCOMPARE(spy3.count(), 1);
186
185
187 m_chart->setAxisX(&axis, m_series);
186 m_chart->setAxisX(&axis, m_series);
188 m_view->show();
187 m_view->show();
189 QTest::qWaitForWindowShown(m_view);
188 QTest::qWaitForWindowShown(m_view);
190 QCOMPARE(axis.categories(), categories);
189 QCOMPARE(axis.categories(), categories);
191
190
192 QCOMPARE(spy0.count(), 1);
191 QCOMPARE(spy0.count(), 1);
193 QCOMPARE(spy1.count(), 1);
192 QCOMPARE(spy1.count(), 1);
194 QCOMPARE(spy2.count(), 1);
193 QCOMPARE(spy2.count(), 1);
195 QCOMPARE(spy3.count(), 1);
194 QCOMPARE(spy3.count(), 1);
196 }
195 }
197
196
198 void tst_QBarCategoriesAxis::append2_data()
197 void tst_QBarCategoriesAxis::append2_data()
199 {
198 {
200 QTest::addColumn<QStringList>("categories");
199 QTest::addColumn<QStringList>("categories");
201 QTest::newRow("Jan Feb Mar Apr") << (QStringList() << "Jan" << "Feb" << "Mar" << "Apr");
200 QTest::newRow("Jan Feb Mar Apr") << (QStringList() << "Jan" << "Feb" << "Mar" << "Apr");
202 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
201 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
203 }
202 }
204
203
205 void tst_QBarCategoriesAxis::append2()
204 void tst_QBarCategoriesAxis::append2()
206 {
205 {
207 QFETCH(QStringList, categories);
206 QFETCH(QStringList, categories);
208
207
209 QBarCategoryAxis axis;
208 QBarCategoryAxis axis;
210
209
211 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
210 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
212 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
211 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
213 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
212 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
214 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
213 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
215
214
216 foreach(QString category, categories)
215 foreach(QString category, categories)
217 axis.append(category);
216 axis.append(category);
218
217
219 QCOMPARE(spy0.count(), categories.count());
218 QCOMPARE(spy0.count(), categories.count());
220 QCOMPARE(spy1.count(), categories.count());
219 QCOMPARE(spy1.count(), categories.count());
221 QCOMPARE(spy2.count(), 1);
220 QCOMPARE(spy2.count(), 1);
222 QCOMPARE(spy3.count(), categories.count());
221 QCOMPARE(spy3.count(), categories.count());
223
222
224 m_chart->setAxisX(&axis, m_series);
223 m_chart->setAxisX(&axis, m_series);
225 m_view->show();
224 m_view->show();
226 QTest::qWaitForWindowShown(m_view);
225 QTest::qWaitForWindowShown(m_view);
227 QCOMPARE(axis.categories(), categories);
226 QCOMPARE(axis.categories(), categories);
228
227
229 QCOMPARE(spy0.count(), categories.count());
228 QCOMPARE(spy0.count(), categories.count());
230 QCOMPARE(spy1.count(), categories.count());
229 QCOMPARE(spy1.count(), categories.count());
231 QCOMPARE(spy2.count(), 1);
230 QCOMPARE(spy2.count(), 1);
232 QCOMPARE(spy3.count(), categories.count());
231 QCOMPARE(spy3.count(), categories.count());
233 }
232 }
234
233
235 void tst_QBarCategoriesAxis::at_data()
234 void tst_QBarCategoriesAxis::at_data()
236 {
235 {
237 QTest::addColumn<QStringList>("categories");
236 QTest::addColumn<QStringList>("categories");
238 QTest::addColumn<int>("index");
237 QTest::addColumn<int>("index");
239 QTest::addColumn<QString>("string");
238 QTest::addColumn<QString>("string");
240 QTest::newRow("Jul Aug Sep 0 Jul") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jul";
239 QTest::newRow("Jul Aug Sep 0 Jul") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jul";
241 QTest::newRow("Jul Aug Sep 2 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Sep";
240 QTest::newRow("Jul Aug Sep 2 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Sep";
242 QTest::newRow("Jul Aug Sep 1 Aug") << (QStringList() << "Jul" << "Aug" << "Sep") << 1 << "Aug";
241 QTest::newRow("Jul Aug Sep 1 Aug") << (QStringList() << "Jul" << "Aug" << "Sep") << 1 << "Aug";
243 }
242 }
244
243
245 void tst_QBarCategoriesAxis::at()
244 void tst_QBarCategoriesAxis::at()
246 {
245 {
247 QFETCH(int, index);
246 QFETCH(int, index);
248 QFETCH(QString, string);
247 QFETCH(QString, string);
249 QFETCH(QStringList, categories);
248 QFETCH(QStringList, categories);
250
249
251 QBarCategoryAxis axis;
250 QBarCategoryAxis axis;
252 axis.append(categories);
251 axis.append(categories);
253
252
254 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
253 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
255 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
254 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
256 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
255 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
257 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
256 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
258
257
259 QCOMPARE(axis.at(index), string);
258 QCOMPARE(axis.at(index), string);
260
259
261 QCOMPARE(spy0.count(), 0);
260 QCOMPARE(spy0.count(), 0);
262 QCOMPARE(spy1.count(), 0);
261 QCOMPARE(spy1.count(), 0);
263 QCOMPARE(spy2.count(), 0);
262 QCOMPARE(spy2.count(), 0);
264 QCOMPARE(spy3.count(), 0);
263 QCOMPARE(spy3.count(), 0);
265
264
266 m_chart->setAxisX(&axis, m_series);
265 m_chart->setAxisX(&axis, m_series);
267 m_view->show();
266 m_view->show();
268 QTest::qWaitForWindowShown(m_view);
267 QTest::qWaitForWindowShown(m_view);
269 QCOMPARE(axis.at(index), string);
268 QCOMPARE(axis.at(index), string);
270
269
271 QCOMPARE(spy0.count(), 0);
270 QCOMPARE(spy0.count(), 0);
272 QCOMPARE(spy1.count(), 0);
271 QCOMPARE(spy1.count(), 0);
273 QCOMPARE(spy2.count(), 0);
272 QCOMPARE(spy2.count(), 0);
274 QCOMPARE(spy3.count(), 0);
273 QCOMPARE(spy3.count(), 0);
275 }
274 }
276
275
277 void tst_QBarCategoriesAxis::categories_data()
276 void tst_QBarCategoriesAxis::categories_data()
278 {
277 {
279 QTest::addColumn<QStringList>("categories");
278 QTest::addColumn<QStringList>("categories");
280 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
279 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
281 }
280 }
282
281
283 void tst_QBarCategoriesAxis::categories()
282 void tst_QBarCategoriesAxis::categories()
284 {
283 {
285 QFETCH(QStringList, categories);
284 QFETCH(QStringList, categories);
286
285
287 QBarCategoryAxis axis;
286 QBarCategoryAxis axis;
288
287
289 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
288 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
290 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
289 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
291 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
290 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
292 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
291 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
293
292
294 axis.setCategories(categories);
293 axis.setCategories(categories);
295 QCOMPARE(axis.categories(), categories);
294 QCOMPARE(axis.categories(), categories);
296
295
297 QCOMPARE(spy0.count(), 1);
296 QCOMPARE(spy0.count(), 1);
298 QCOMPARE(spy1.count(), 1);
297 QCOMPARE(spy1.count(), 1);
299 QCOMPARE(spy2.count(), 1);
298 QCOMPARE(spy2.count(), 1);
300 QCOMPARE(spy3.count(), 1);
299 QCOMPARE(spy3.count(), 1);
301
300
302 m_chart->setAxisX(&axis, m_series);
301 m_chart->setAxisX(&axis, m_series);
303 m_view->show();
302 m_view->show();
304 QTest::qWaitForWindowShown(m_view);
303 QTest::qWaitForWindowShown(m_view);
305 QCOMPARE(axis.categories(), categories);
304 QCOMPARE(axis.categories(), categories);
306
305
307 QCOMPARE(spy0.count(), 1);
306 QCOMPARE(spy0.count(), 1);
308 QCOMPARE(spy1.count(), 1);
307 QCOMPARE(spy1.count(), 1);
309 QCOMPARE(spy2.count(), 1);
308 QCOMPARE(spy2.count(), 1);
310 QCOMPARE(spy3.count(), 1);
309 QCOMPARE(spy3.count(), 1);
311
310
312 }
311 }
313
312
314 void tst_QBarCategoriesAxis::clear_data()
313 void tst_QBarCategoriesAxis::clear_data()
315 {
314 {
316 QTest::addColumn<QStringList>("categories");
315 QTest::addColumn<QStringList>("categories");
317 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
316 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
318 }
317 }
319
318
320 void tst_QBarCategoriesAxis::clear()
319 void tst_QBarCategoriesAxis::clear()
321 {
320 {
322 QFETCH(QStringList, categories);
321 QFETCH(QStringList, categories);
323
322
324 QBarCategoryAxis axis;
323 QBarCategoryAxis axis;
325
324
326 axis.setCategories(categories);
325 axis.setCategories(categories);
327 QCOMPARE(axis.categories(), categories);
326 QCOMPARE(axis.categories(), categories);
328
327
329 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
328 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
330 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
329 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
331 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
330 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
332 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
331 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
333
332
334 axis.clear();
333 axis.clear();
335 QCOMPARE(axis.categories(), QStringList());
334 QCOMPARE(axis.categories(), QStringList());
336
335
337 QCOMPARE(spy0.count(), 1);
336 QCOMPARE(spy0.count(), 1);
338 QCOMPARE(spy1.count(), 1);
337 QCOMPARE(spy1.count(), 1);
339 QCOMPARE(spy2.count(), 1);
338 QCOMPARE(spy2.count(), 1);
340 QCOMPARE(spy3.count(), 1);
339 QCOMPARE(spy3.count(), 1);
341
340
342 m_chart->setAxisX(&axis, m_series);
341 m_chart->setAxisX(&axis, m_series);
343 m_view->show();
342 m_view->show();
344 QTest::qWaitForWindowShown(m_view);
343 QTest::qWaitForWindowShown(m_view);
345
344
346 QCOMPARE(spy0.count(), 2);
345 QCOMPARE(spy0.count(), 2);
347 QCOMPARE(spy1.count(), 2);
346 QCOMPARE(spy1.count(), 2);
348 QCOMPARE(spy2.count(), 2);
347 QCOMPARE(spy2.count(), 2);
349 QCOMPARE(spy3.count(), 2);
348 QCOMPARE(spy3.count(), 2);
350
349
351 axis.clear();
350 axis.clear();
352 QCOMPARE(axis.categories().count(),0);
351 QCOMPARE(axis.categories().count(),0);
353 QCOMPARE(spy0.count(), 3);
352 QCOMPARE(spy0.count(), 3);
354 QCOMPARE(spy1.count(), 3);
353 QCOMPARE(spy1.count(), 3);
355 QCOMPARE(spy2.count(), 3);
354 QCOMPARE(spy2.count(), 3);
356 QCOMPARE(spy3.count(), 3);
355 QCOMPARE(spy3.count(), 3);
357 }
356 }
358
357
359 void tst_QBarCategoriesAxis::count_data()
358 void tst_QBarCategoriesAxis::count_data()
360 {
359 {
361 QTest::addColumn<QStringList>("categories");
360 QTest::addColumn<QStringList>("categories");
362 QTest::addColumn<int>("count");
361 QTest::addColumn<int>("count");
363 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3;
362 QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3;
364 QTest::newRow("Jul Aug ") << (QStringList() << "Jul" << "Aug") << 2;
363 QTest::newRow("Jul Aug ") << (QStringList() << "Jul" << "Aug") << 2;
365 }
364 }
366
365
367 void tst_QBarCategoriesAxis::count()
366 void tst_QBarCategoriesAxis::count()
368 {
367 {
369 QFETCH(QStringList, categories);
368 QFETCH(QStringList, categories);
370 QFETCH(int, count);
369 QFETCH(int, count);
371
370
372 QBarCategoryAxis axis;
371 QBarCategoryAxis axis;
373 axis.setCategories(categories);
372 axis.setCategories(categories);
374
373
375 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
374 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
376 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
375 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
377 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
376 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
378 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
377 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
379
378
380 QCOMPARE(axis.count(), count);
379 QCOMPARE(axis.count(), count);
381
380
382 QCOMPARE(spy0.count(), 0);
381 QCOMPARE(spy0.count(), 0);
383 QCOMPARE(spy1.count(), 0);
382 QCOMPARE(spy1.count(), 0);
384 QCOMPARE(spy2.count(), 0);
383 QCOMPARE(spy2.count(), 0);
385 QCOMPARE(spy3.count(), 0);
384 QCOMPARE(spy3.count(), 0);
386
385
387 m_chart->setAxisX(&axis, m_series);
386 m_chart->setAxisX(&axis, m_series);
388 m_view->show();
387 m_view->show();
389 QTest::qWaitForWindowShown(m_view);
388 QTest::qWaitForWindowShown(m_view);
390 QCOMPARE(axis.count(), count);
389 QCOMPARE(axis.count(), count);
391 }
390 }
392
391
393 void tst_QBarCategoriesAxis::insert_data()
392 void tst_QBarCategoriesAxis::insert_data()
394 {
393 {
395 QTest::addColumn<QStringList>("categories");
394 QTest::addColumn<QStringList>("categories");
396 QTest::addColumn<int>("index");
395 QTest::addColumn<int>("index");
397 QTest::addColumn<QString>("category");
396 QTest::addColumn<QString>("category");
398 QTest::newRow("Jul Aug Sep 0 Jun") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jun";
397 QTest::newRow("Jul Aug Sep 0 Jun") << (QStringList() << "Jul" << "Aug" << "Sep") << 1 << "Jun";
399 QTest::newRow("Jul Aug Sep 3 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3 << "Sep";
400 QTest::newRow("Jul Aug Sep 2 Summer") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Summer";
398 QTest::newRow("Jul Aug Sep 2 Summer") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Summer";
401 }
399 }
402
400
403 void tst_QBarCategoriesAxis::insert()
401 void tst_QBarCategoriesAxis::insert()
404 {
402 {
405 QFETCH(QStringList, categories);
403 QFETCH(QStringList, categories);
406 QFETCH(int, index);
404 QFETCH(int, index);
407 QFETCH(QString, category);
405 QFETCH(QString, category);
408
406
409 QBarCategoryAxis axis;
407 QBarCategoryAxis axis;
410 axis.append(categories);
408 axis.append(categories);
411
409
412 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
410 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
413 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
411 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
414 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
412 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
415 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
413 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
416
414
417 axis.insert(index, category);
415 axis.insert(index, category);
418 QCOMPARE(axis.at(index),category);
416 QCOMPARE(axis.at(index),category);
419
417
420 QCOMPARE(spy0.count(), 1);
418 QCOMPARE(spy0.count(), 1);
421 QCOMPARE(spy1.count(), 0);
419 QCOMPARE(spy1.count(), 0);
422 QCOMPARE(spy2.count(), 0);
420 QCOMPARE(spy2.count(), 0);
423 QCOMPARE(spy3.count(), 0);
421 QCOMPARE(spy3.count(), 0);
424
422
425 m_chart->setAxisX(&axis, m_series);
423 m_chart->setAxisX(&axis, m_series);
426 m_view->show();
424 m_view->show();
427 QTest::qWaitForWindowShown(m_view);
425 QTest::qWaitForWindowShown(m_view);
428 }
426 }
429
427
430 void tst_QBarCategoriesAxis::remove_data()
428 void tst_QBarCategoriesAxis::remove_data()
431 {
429 {
432 QTest::addColumn<QStringList>("categories");
430 QTest::addColumn<QStringList>("categories");
433 QTest::addColumn<QString>("category");
431 QTest::addColumn<QString>("category");
434 QTest::addColumn<QStringList>("result");
432 QTest::addColumn<QStringList>("result");
435 QTest::newRow("Jul Aug Sep 0") << (QStringList() << "Jul" << "Aug" << "Sep") << "Jul" << (QStringList() << "Aug" << "Sep");
433 QTest::newRow("Jul Aug Sep 0") << (QStringList() << "Jul" << "Aug" << "Sep") << "Jul" << (QStringList() << "Aug" << "Sep");
436 QTest::newRow("Jul Aug Sep 1") << (QStringList() << "Jul" << "Aug" << "Sep") << "Aug"<< (QStringList() << "Jul" << "Sep");
434 QTest::newRow("Jul Aug Sep 1") << (QStringList() << "Jul" << "Aug" << "Sep") << "Aug"<< (QStringList() << "Jul" << "Sep");
437 }
435 }
438
436
439 void tst_QBarCategoriesAxis::remove()
437 void tst_QBarCategoriesAxis::remove()
440 {
438 {
441 QFETCH(QStringList, categories);
439 QFETCH(QStringList, categories);
442 QFETCH(QString, category);
440 QFETCH(QString, category);
443 QFETCH(QStringList, result);
441 QFETCH(QStringList, result);
444
442
445 QBarCategoryAxis axis;
443 QBarCategoryAxis axis;
446 axis.append(categories);
444 axis.append(categories);
447
445
448 int maxCount = axis.max() == category;
446 int maxCount = axis.max() == category;
449 int minCount = axis.min() == category;
447 int minCount = axis.min() == category;
450 int rangeCount = maxCount + minCount;
448 int rangeCount = maxCount + minCount;
451
449
452 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
450 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
453 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
451 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
454 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
452 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
455 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
453 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
456
454
457 axis.remove(category);
455 axis.remove(category);
458 QCOMPARE(axis.categories(),result);
456 QCOMPARE(axis.categories(),result);
459
457
460 QCOMPARE(spy0.count(), 1);
458 QCOMPARE(spy0.count(), 1);
461 QCOMPARE(spy1.count(), maxCount);
459 QCOMPARE(spy1.count(), maxCount);
462 QCOMPARE(spy2.count(), minCount);
460 QCOMPARE(spy2.count(), minCount);
463 QCOMPARE(spy3.count(), rangeCount);
461 QCOMPARE(spy3.count(), rangeCount);
464 }
462 }
465
463
466 void tst_QBarCategoriesAxis::max_raw_data()
464 void tst_QBarCategoriesAxis::max_raw_data()
467 {
465 {
468 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
466 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
469 QTest::addColumn<QString>("max");
467 QTest::addColumn<QString>("max");
470 QTest::newRow("Feb") << "Feb";
468 QTest::newRow("Feb") << "Feb";
471 QTest::newRow("Apr") << "Apr";
469 QTest::newRow("Apr") << "Apr";
472 QTest::newRow("May") << "May";
470 QTest::newRow("May") << "May";
473 }
471 }
474
472
475 void tst_QBarCategoriesAxis::max_raw()
473 void tst_QBarCategoriesAxis::max_raw()
476 {
474 {
477 QFETCH(QString, max);
475 QFETCH(QString, max);
478
476
479 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
477 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
480 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString)));
478 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString)));
481 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString)));
479 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString)));
482 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
480 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
483
481
484 m_baraxis->setMax(max);
482 m_baraxis->setMax(max);
485 QCOMPARE(m_baraxis->max(), max);
483 QCOMPARE(m_baraxis->max(), max);
486
484
487 QCOMPARE(spy0.count(), 0);
485 QCOMPARE(spy0.count(), 0);
488 QCOMPARE(spy1.count(), 1);
486 QCOMPARE(spy1.count(), 1);
489 QCOMPARE(spy2.count(), 0);
487 QCOMPARE(spy2.count(), 0);
490 QCOMPARE(spy3.count(), 1);
488 QCOMPARE(spy3.count(), 1);
491 }
489 }
492
490
493 void tst_QBarCategoriesAxis::max_data()
491 void tst_QBarCategoriesAxis::max_data()
494 {
492 {
495 max_raw_data();
493 max_raw_data();
496 }
494 }
497
495
498 void tst_QBarCategoriesAxis::max()
496 void tst_QBarCategoriesAxis::max()
499 {
497 {
500 m_chart->setAxisX(m_baraxis, m_series);
498 m_chart->setAxisX(m_baraxis, m_series);
501 m_view->show();
499 m_view->show();
502 QTest::qWaitForWindowShown(m_view);
500 QTest::qWaitForWindowShown(m_view);
503 max_raw();
501 max_raw();
504 }
502 }
505
503
506 void tst_QBarCategoriesAxis::max_animation_data()
504 void tst_QBarCategoriesAxis::max_animation_data()
507 {
505 {
508 max_data();
506 max_data();
509 }
507 }
510
508
511 void tst_QBarCategoriesAxis::max_animation()
509 void tst_QBarCategoriesAxis::max_animation()
512 {
510 {
513 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
511 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
514 max();
512 max();
515 }
513 }
516
514
517 void tst_QBarCategoriesAxis::min_raw_data()
515 void tst_QBarCategoriesAxis::min_raw_data()
518 {
516 {
519 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
517 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
520 QTest::addColumn<QString>("min");
518 QTest::addColumn<QString>("min");
521 QTest::newRow("Feb") << "Feb";
519 QTest::newRow("Feb") << "Feb";
522 QTest::newRow("Apr") << "Apr";
520 QTest::newRow("Apr") << "Apr";
523 QTest::newRow("May") << "May";
521 QTest::newRow("May") << "May";
524 }
522 }
525
523
526 void tst_QBarCategoriesAxis::min_raw()
524 void tst_QBarCategoriesAxis::min_raw()
527 {
525 {
528 QFETCH(QString, min);
526 QFETCH(QString, min);
529
527
530 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
528 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
531 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString)));
529 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString)));
532 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString)));
530 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString)));
533 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
531 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
534
532
535 m_baraxis->setMin(min);
533 m_baraxis->setMin(min);
536 QCOMPARE(m_baraxis->min(), min);
534 QCOMPARE(m_baraxis->min(), min);
537
535
538 QCOMPARE(spy0.count(), 0);
536 QCOMPARE(spy0.count(), 0);
539 QCOMPARE(spy1.count(), 0);
537 QCOMPARE(spy1.count(), 0);
540 QCOMPARE(spy2.count(), 1);
538 QCOMPARE(spy2.count(), 1);
541 QCOMPARE(spy3.count(), 1);
539 QCOMPARE(spy3.count(), 1);
542
540
543 }
541 }
544
542
545 void tst_QBarCategoriesAxis::min_data()
543 void tst_QBarCategoriesAxis::min_data()
546 {
544 {
547 min_raw_data();
545 min_raw_data();
548 }
546 }
549
547
550 void tst_QBarCategoriesAxis::min()
548 void tst_QBarCategoriesAxis::min()
551 {
549 {
552 min_raw();
550 min_raw();
553 m_chart->setAxisX(m_baraxis, m_series);
551 m_chart->setAxisX(m_baraxis, m_series);
554 m_view->show();
552 m_view->show();
555 QTest::qWaitForWindowShown(m_view);
553 QTest::qWaitForWindowShown(m_view);
556
554
557 }
555 }
558
556
559 void tst_QBarCategoriesAxis::min_animation_data()
557 void tst_QBarCategoriesAxis::min_animation_data()
560 {
558 {
561 min_data();
559 min_data();
562 }
560 }
563
561
564 void tst_QBarCategoriesAxis::min_animation()
562 void tst_QBarCategoriesAxis::min_animation()
565 {
563 {
566 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
564 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
567 min();
565 min();
568 }
566 }
569
567
570
568
571 void tst_QBarCategoriesAxis::range_raw_data()
569 void tst_QBarCategoriesAxis::range_raw_data()
572 {
570 {
573 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
571 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
574 QTest::addColumn<QString>("min");
572 QTest::addColumn<QString>("min");
575 QTest::addColumn<QString>("max");
573 QTest::addColumn<QString>("max");
576 QTest::newRow("Feb - Apr") << "Feb" << "Apr";
574 QTest::newRow("Feb - Apr") << "Feb" << "Apr";
577 QTest::newRow("Feb - May") << "Feb" << "May";
575 QTest::newRow("Feb - May") << "Feb" << "May";
578 QTest::newRow("Mar - Apr") << "Mar" << "Apr";
576 QTest::newRow("Mar - Apr") << "Mar" << "Apr";
579 }
577 }
580
578
581 void tst_QBarCategoriesAxis::range_raw()
579 void tst_QBarCategoriesAxis::range_raw()
582 {
580 {
583 QFETCH(QString, min);
581 QFETCH(QString, min);
584 QFETCH(QString, max);
582 QFETCH(QString, max);
585
583
586 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
584 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
587 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString)));
585 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString)));
588 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString)));
586 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString)));
589 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
587 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
590
588
591 m_baraxis->setRange(min, max);
589 m_baraxis->setRange(min, max);
592 QCOMPARE(m_baraxis->min(), min);
590 QCOMPARE(m_baraxis->min(), min);
593 QCOMPARE(m_baraxis->max(), max);
591 QCOMPARE(m_baraxis->max(), max);
594
592
595 QCOMPARE(spy0.count(), 0);
593 QCOMPARE(spy0.count(), 0);
596 QCOMPARE(spy1.count(), 1);
594 QCOMPARE(spy1.count(), 1);
597 QCOMPARE(spy2.count(), 1);
595 QCOMPARE(spy2.count(), 1);
598 QCOMPARE(spy3.count(), 1);
596 QCOMPARE(spy3.count(), 1);
599 }
597 }
600
598
601 void tst_QBarCategoriesAxis::range_data()
599 void tst_QBarCategoriesAxis::range_data()
602 {
600 {
603 range_raw_data();
601 range_raw_data();
604 }
602 }
605
603
606 void tst_QBarCategoriesAxis::range()
604 void tst_QBarCategoriesAxis::range()
607 {
605 {
608 range_raw();
606 range_raw();
609 m_chart->setAxisX(m_baraxis, m_series);
607 m_chart->setAxisX(m_baraxis, m_series);
610 m_view->show();
608 m_view->show();
611 QTest::qWaitForWindowShown(m_view);
609 QTest::qWaitForWindowShown(m_view);
612
610
613 }
611 }
614
612
615 void tst_QBarCategoriesAxis::range_animation_data()
613 void tst_QBarCategoriesAxis::range_animation_data()
616 {
614 {
617 range_data();
615 range_data();
618 }
616 }
619
617
620 void tst_QBarCategoriesAxis::range_animation()
618 void tst_QBarCategoriesAxis::range_animation()
621 {
619 {
622 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
620 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
623 range();
621 range();
624 }
622 }
625
623
626
624
627 void tst_QBarCategoriesAxis::noautoscale_data()
625 void tst_QBarCategoriesAxis::noautoscale_data()
628 {
626 {
629 QTest::addColumn<QString>("min");
627 QTest::addColumn<QString>("min");
630 QTest::addColumn<QString>("max");
628 QTest::addColumn<QString>("max");
631 QTest::newRow("Feb - Mar") << "Feb" << "Mar";
629 QTest::newRow("Feb - Mar") << "Feb" << "Mar";
632 QTest::newRow("Feb - May") << "Feb" << "May";
630 QTest::newRow("Feb - May") << "Feb" << "May";
633 QTest::newRow("Apr - May") << "Apr" << "May";
631 QTest::newRow("Apr - May") << "Apr" << "May";
634 }
632 }
635
633
636 void tst_QBarCategoriesAxis::noautoscale()
634 void tst_QBarCategoriesAxis::noautoscale()
637 {
635 {
638 QFETCH(QString, min);
636 QFETCH(QString, min);
639 QFETCH(QString, max);
637 QFETCH(QString, max);
640
638
641 QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString)));
639 QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString)));
642 QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString)));
640 QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString)));
643 QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
641 QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
644
642
645 m_baraxis->setRange(min, max);
643 m_baraxis->setRange(min, max);
646 QCOMPARE(m_baraxis->min(),min);
644 QCOMPARE(m_baraxis->min(),min);
647 QCOMPARE(m_baraxis->max(),max);
645 QCOMPARE(m_baraxis->max(),max);
648
646
649 QCOMPARE(spy0.count(), 1);
647 QCOMPARE(spy0.count(), 1);
650 QCOMPARE(spy1.count(), 1);
648 QCOMPARE(spy1.count(), 1);
651 QCOMPARE(spy2.count(), 1);
649 QCOMPARE(spy2.count(), 1);
652
650
653 m_chart->setAxisX(m_baraxis, m_series);
651 m_chart->setAxisX(m_baraxis, m_series);
654 m_view->show();
652 m_view->show();
655 QTest::qWaitForWindowShown(m_view);
653 QTest::qWaitForWindowShown(m_view);
656 QCOMPARE(m_baraxis->min(),min);
654 QCOMPARE(m_baraxis->min(),min);
657 QCOMPARE(m_baraxis->max(),max);
655 QCOMPARE(m_baraxis->max(),max);
658 }
656 }
659
657
660 void tst_QBarCategoriesAxis::autoscale_data()
658 void tst_QBarCategoriesAxis::autoscale_data()
661 {
659 {
662
660
663 }
661 }
664
662
665 void tst_QBarCategoriesAxis::autoscale()
663 void tst_QBarCategoriesAxis::autoscale()
666 {
664 {
667 delete m_baraxis;
665 delete m_baraxis;
668 m_baraxis = new QBarCategoryAxis();
666 m_baraxis = new QBarCategoryAxis();
669
667
670 QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString)));
668 QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString)));
671 QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString)));
669 QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString)));
672 QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
670 QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
673
671
674 QCOMPARE(m_baraxis->min(),QString());
672 QCOMPARE(m_baraxis->min(),QString());
675 QCOMPARE(m_baraxis->max(),QString());
673 QCOMPARE(m_baraxis->max(),QString());
676 m_chart->setAxisX(m_baraxis, m_series);
674 m_chart->setAxisX(m_baraxis, m_series);
677
675
678 QCOMPARE(spy0.count(), 1);
676 QCOMPARE(spy0.count(), 1);
679 QCOMPARE(spy1.count(), 1);
677 QCOMPARE(spy1.count(), 1);
680 QCOMPARE(spy2.count(), 1);
678 QCOMPARE(spy2.count(), 1);
681
679
682 m_view->show();
680 m_view->show();
683 QTest::qWaitForWindowShown(m_view);
681 QTest::qWaitForWindowShown(m_view);
684 QCOMPARE(m_baraxis->min(),QString("1"));
682 QCOMPARE(m_baraxis->min(),QString("1"));
685 QCOMPARE(m_baraxis->max(),QString("6"));
683 QCOMPARE(m_baraxis->max(),QString("6"));
686 }
684 }
687
685
688
686
689 QTEST_MAIN(tst_QBarCategoriesAxis)
687 QTEST_MAIN(tst_QBarCategoriesAxis)
690 #include "tst_qbarcategoryaxis.moc"
688 #include "tst_qbarcategoryaxis.moc"
691
689
General Comments 0
You need to be logged in to leave comments. Login now