@@ -1,442 +1,456 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarcategoriesaxis.h" |
|
22 | 22 | #include "qbarcategoriesaxis_p.h" |
|
23 | 23 | #include "chartcategoriesaxisx_p.h" |
|
24 | 24 | #include "chartcategoriesaxisy_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include <qmath.h> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | /*! |
|
31 | 31 | \class QBarCategoriesAxis |
|
32 | 32 | \brief The QBarCategoriesAxis class is used for manipulating chart's axis. |
|
33 | 33 | \mainclass |
|
34 | 34 | |
|
35 | 35 | BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
36 | 36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
37 | 37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. |
|
38 | 38 | */ |
|
39 | 39 | |
|
40 | 40 | /*! |
|
41 | 41 | \qmlclass BarCategoriesAxis QBarCategoriesAxis |
|
42 | 42 | \brief The Axis element is used for manipulating chart's axes. |
|
43 | 43 | |
|
44 | 44 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
45 | 45 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
46 | 46 | |
|
47 | 47 | To access BarCategoriesAxis you can use ChartView API. For example: |
|
48 | 48 | \code |
|
49 | 49 | ChartView { |
|
50 | 50 | BarCategoriesAxis { |
|
51 | 51 | id: categoryAxis |
|
52 | 52 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] |
|
53 | 53 | } |
|
54 | 54 | // Add a few series... |
|
55 | 55 | } |
|
56 | 56 | \endcode |
|
57 | 57 | */ |
|
58 | 58 | |
|
59 | 59 | /*! |
|
60 | 60 | \property QBarCategoriesAxis::categories |
|
61 | 61 | Defines the categories of axis |
|
62 | 62 | */ |
|
63 | 63 | /*! |
|
64 | 64 | \qmlproperty QStringList BarCategoriesAxis::categories |
|
65 | 65 | Defines the categories of axis |
|
66 | 66 | */ |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | \property QBarCategoriesAxis::min |
|
70 | 70 | Defines the minimum value on the axis. |
|
71 | 71 | */ |
|
72 | 72 | /*! |
|
73 | 73 | \qmlproperty QString BarCategoriesAxis::min |
|
74 | 74 | Defines the minimum value on the axis. |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \property QBarCategoriesAxis::max |
|
79 | 79 | Defines the maximum value on the axis. |
|
80 | 80 | */ |
|
81 | 81 | /*! |
|
82 | 82 | \qmlproperty QString BarCategoriesAxis::max |
|
83 | 83 | Defines the maximum value on the axis. |
|
84 | 84 | */ |
|
85 | 85 | |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \fn void QBarCategoriesAxis::categoriesChanged() |
|
89 | 89 | Axis emits signal when the categories of the axis has changed. |
|
90 | 90 | */ |
|
91 | 91 | /*! |
|
92 | 92 | \fn void QBarCategoriesAxis::minChanged(const QString &min) |
|
93 | 93 | Axis emits signal when \a min of axis has changed. |
|
94 | 94 | */ |
|
95 | 95 | /*! |
|
96 | 96 | \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min) |
|
97 | 97 | Axis emits signal when \a min of axis has changed. |
|
98 | 98 | */ |
|
99 | 99 | |
|
100 | 100 | /*! |
|
101 | 101 | \fn void QBarCategoriesAxis::maxChanged(const QString &max) |
|
102 | 102 | Axis emits signal when \a max of axis has changed. |
|
103 | 103 | */ |
|
104 | 104 | /*! |
|
105 | 105 | \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max) |
|
106 | 106 | Axis emits signal when \a max of axis has changed. |
|
107 | 107 | */ |
|
108 | 108 | |
|
109 | 109 | /*! |
|
110 | 110 | \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max) |
|
111 | 111 | Axis emits signal when \a min or \a max of axis has changed. |
|
112 | 112 | */ |
|
113 | 113 | |
|
114 | 114 | /*! |
|
115 | 115 | Constructs an axis object which is a child of \a parent. |
|
116 | 116 | */ |
|
117 | 117 | QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent): |
|
118 | 118 | QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent) |
|
119 | 119 | { |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | Destroys the object |
|
124 | 124 | */ |
|
125 | 125 | QBarCategoriesAxis::~QBarCategoriesAxis() |
|
126 | 126 | { |
|
127 | 127 | Q_D(QBarCategoriesAxis); |
|
128 | 128 | if(d->m_dataset){ |
|
129 | 129 | d->m_dataset->removeAxis(this); |
|
130 | 130 | } |
|
131 | 131 | } |
|
132 | 132 | |
|
133 | 133 | /*! |
|
134 | 134 | \internal |
|
135 | 135 | */ |
|
136 | 136 | QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) |
|
137 | 137 | { |
|
138 | 138 | |
|
139 | 139 | } |
|
140 | 140 | |
|
141 | 141 | /*! |
|
142 | 142 | Appends \a categories to axis |
|
143 | 143 | */ |
|
144 | 144 | void QBarCategoriesAxis::append(const QStringList &categories) |
|
145 | 145 | { |
|
146 | 146 | if(categories.isEmpty()) return; |
|
147 | 147 | |
|
148 | 148 | Q_D(QBarCategoriesAxis); |
|
149 | 149 | if (d->m_categories.isEmpty()) { |
|
150 | 150 | d->m_categories.append(categories); |
|
151 | 151 | setRange(categories.first(),categories.last()); |
|
152 | 152 | }else{ |
|
153 | 153 | d->m_categories.append(categories); |
|
154 | 154 | d->emitUpdated(); |
|
155 | 155 | } |
|
156 | 156 | emit categoriesChanged(); |
|
157 | 157 | } |
|
158 | 158 | |
|
159 | 159 | /*! |
|
160 | 160 | Appends \a category to axis |
|
161 | 161 | */ |
|
162 | 162 | void QBarCategoriesAxis::append(const QString &category) |
|
163 | 163 | { |
|
164 | 164 | Q_D(QBarCategoriesAxis); |
|
165 | 165 | if (d->m_categories.isEmpty()) { |
|
166 | 166 | d->m_categories.append(category); |
|
167 | 167 | setRange(category,category); |
|
168 | 168 | }else{ |
|
169 | 169 | d->m_categories.append(category); |
|
170 | 170 | d->emitUpdated(); |
|
171 | 171 | } |
|
172 | 172 | emit categoriesChanged(); |
|
173 | 173 | } |
|
174 | 174 | |
|
175 | 175 | /*! |
|
176 | 176 | Removes \a category from axis |
|
177 | 177 | */ |
|
178 | 178 | void QBarCategoriesAxis::remove(const QString &category) |
|
179 | 179 | { |
|
180 | 180 | Q_D(QBarCategoriesAxis); |
|
181 | 181 | if (d->m_categories.contains(category)) { |
|
182 | 182 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
183 | 183 | if(!d->m_categories.isEmpty()) |
|
184 | 184 | setRange(d->m_categories.first(),d->m_categories.last()); |
|
185 | 185 | else |
|
186 | 186 | setRange(QString::null,QString::null); |
|
187 | 187 | emit categoriesChanged(); |
|
188 | 188 | } |
|
189 | 189 | } |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | Inserts \a category to axis at \a index |
|
193 | 193 | */ |
|
194 | 194 | void QBarCategoriesAxis::insert(int index, const QString &category) |
|
195 | 195 | { |
|
196 | 196 | Q_D(QBarCategoriesAxis); |
|
197 | 197 | if (d->m_categories.isEmpty()) { |
|
198 | 198 | d->m_categories.insert(index,category); |
|
199 | 199 | setRange(category,category); |
|
200 | 200 | }else{ |
|
201 | 201 | d->m_categories.insert(index,category); |
|
202 | 202 | d->emitUpdated(); |
|
203 | 203 | } |
|
204 | 204 | emit categoriesChanged(); |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | /*! |
|
208 | 208 | Removes all categories. |
|
209 | 209 | */ |
|
210 | 210 | void QBarCategoriesAxis::clear() |
|
211 | 211 | { |
|
212 | 212 | Q_D(QBarCategoriesAxis); |
|
213 | 213 | d->m_categories.clear(); |
|
214 | 214 | setRange(QString::null,QString::null); |
|
215 | 215 | emit categoriesChanged(); |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | void QBarCategoriesAxis::setCategories(const QStringList &categories) |
|
219 | 219 | { |
|
220 | 220 | Q_D(QBarCategoriesAxis); |
|
221 | 221 | if(d->m_categories!=categories) { |
|
222 | 222 | d->m_categories = categories; |
|
223 | 223 | setRange(categories.first(),categories.last()); |
|
224 | 224 | emit categoriesChanged(); |
|
225 | 225 | } |
|
226 | 226 | } |
|
227 | 227 | |
|
228 | 228 | QStringList QBarCategoriesAxis::categories() |
|
229 | 229 | { |
|
230 | 230 | Q_D(QBarCategoriesAxis); |
|
231 | 231 | return d->m_categories; |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | /*! |
|
235 | 235 | Returns number of categories. |
|
236 | 236 | */ |
|
237 | 237 | int QBarCategoriesAxis::count() const |
|
238 | 238 | { |
|
239 | 239 | Q_D(const QBarCategoriesAxis); |
|
240 | 240 | return d->m_categories.count(); |
|
241 | 241 | } |
|
242 | 242 | |
|
243 | 243 | /*! |
|
244 | 244 | Returns category at \a index. Index must be valid. |
|
245 | 245 | */ |
|
246 | 246 | QString QBarCategoriesAxis::at(int index) const |
|
247 | 247 | { |
|
248 | 248 | Q_D(const QBarCategoriesAxis); |
|
249 | 249 | return d->m_categories.at(index); |
|
250 | 250 | } |
|
251 | 251 | |
|
252 | 252 | /*! |
|
253 | 253 | Sets minimum category to \a min. |
|
254 | 254 | */ |
|
255 | 255 | void QBarCategoriesAxis::setMin(const QString& min) |
|
256 | 256 | { |
|
257 | 257 | Q_D(QBarCategoriesAxis); |
|
258 | 258 | setRange(min,d->m_maxCategory); |
|
259 | 259 | } |
|
260 | 260 | |
|
261 | 261 | /*! |
|
262 | 262 | Returns minimum category. |
|
263 | 263 | */ |
|
264 | 264 | QString QBarCategoriesAxis::min() const |
|
265 | 265 | { |
|
266 | 266 | Q_D(const QBarCategoriesAxis); |
|
267 | 267 | return d->m_minCategory; |
|
268 | 268 | } |
|
269 | 269 | |
|
270 | 270 | /*! |
|
271 | 271 | Sets maximum category to \a max. |
|
272 | 272 | */ |
|
273 | 273 | void QBarCategoriesAxis::setMax(const QString& max) |
|
274 | 274 | { |
|
275 | 275 | Q_D(QBarCategoriesAxis); |
|
276 | 276 | setRange(d->m_minCategory,max); |
|
277 | 277 | } |
|
278 | 278 | |
|
279 | 279 | /*! |
|
280 | 280 | Returns maximum category |
|
281 | 281 | */ |
|
282 | 282 | QString QBarCategoriesAxis::max() const |
|
283 | 283 | { |
|
284 | 284 | Q_D(const QBarCategoriesAxis); |
|
285 | 285 | return d->m_maxCategory; |
|
286 | 286 | } |
|
287 | 287 | |
|
288 | 288 | /*! |
|
289 | 289 | Sets range from \a minCategory to \a maxCategory |
|
290 | 290 | */ |
|
291 | 291 | void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) |
|
292 | 292 | { |
|
293 | 293 | Q_D(QBarCategoriesAxis); |
|
294 | 294 | |
|
295 | 295 | bool changed = false; |
|
296 | 296 | |
|
297 | 297 | //special case |
|
298 | 298 | if(minCategory.isNull() && maxCategory.isNull()){ |
|
299 | 299 | d->m_minCategory = minCategory; |
|
300 | 300 | d->m_maxCategory = maxCategory; |
|
301 | 301 | d->m_min = 0; |
|
302 | 302 | d->m_max = 0; |
|
303 | 303 | emit minChanged(minCategory); |
|
304 | 304 | emit maxChanged(maxCategory); |
|
305 | 305 | d->m_count=0; |
|
306 | 306 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); |
|
307 | 307 | d->emitUpdated(); |
|
308 | 308 | } |
|
309 | 309 | |
|
310 | 310 | if(d->m_categories.indexOf(d->m_maxCategory)<d->m_categories.indexOf(d->m_minCategory)) return; |
|
311 | 311 | |
|
312 | 312 | if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) { |
|
313 | 313 | d->m_minCategory = minCategory; |
|
314 | 314 | d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5; |
|
315 | 315 | changed = true; |
|
316 | 316 | emit minChanged(minCategory); |
|
317 | 317 | } |
|
318 | 318 | |
|
319 | 319 | if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) { |
|
320 | 320 | d->m_maxCategory = maxCategory; |
|
321 | 321 | d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5; |
|
322 | 322 | changed = true; |
|
323 | 323 | emit maxChanged(maxCategory); |
|
324 | 324 | } |
|
325 | 325 | |
|
326 | 326 | if (changed) { |
|
327 | 327 | d->m_count=d->m_max - d->m_min; |
|
328 | 328 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); |
|
329 | 329 | d->emitUpdated(); |
|
330 | 330 | } |
|
331 | 331 | } |
|
332 | 332 | |
|
333 | 333 | /*! |
|
334 | 334 | Returns the type of the axis |
|
335 | 335 | */ |
|
336 | 336 | QAbstractAxis::AxisType QBarCategoriesAxis::type() const |
|
337 | 337 | { |
|
338 | 338 | return AxisTypeCategories; |
|
339 | 339 | } |
|
340 | 340 | |
|
341 | 341 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
342 | 342 | |
|
343 | 343 | QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): |
|
344 | 344 | QAbstractAxisPrivate(q), |
|
345 | 345 | m_min(0.0), |
|
346 | 346 | m_max(0.0), |
|
347 | 347 | m_count(0) |
|
348 | 348 | { |
|
349 | 349 | |
|
350 | 350 | } |
|
351 | 351 | |
|
352 | 352 | QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() |
|
353 | 353 | { |
|
354 | 354 | |
|
355 | 355 | } |
|
356 | 356 | |
|
357 | 357 | void QBarCategoriesAxisPrivate::setMin(const QVariant &min) |
|
358 | 358 | { |
|
359 | 359 | setRange(min,m_maxCategory); |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 362 | void QBarCategoriesAxisPrivate::setMax(const QVariant &max) |
|
363 | 363 | { |
|
364 | 364 | setRange(m_minCategory,max); |
|
365 | 365 | } |
|
366 | 366 | |
|
367 | 367 | void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
368 | 368 | { |
|
369 | 369 | Q_Q(QBarCategoriesAxis); |
|
370 | 370 | QString value1 = min.toString(); |
|
371 | 371 | QString value2 = max.toString(); |
|
372 | 372 | q->setRange(value1,value2); |
|
373 | 373 | } |
|
374 | 374 | |
|
375 | 375 | void QBarCategoriesAxisPrivate::handleDomainUpdated() |
|
376 | 376 | { |
|
377 | 377 | Q_Q(QBarCategoriesAxis); |
|
378 | 378 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
379 | 379 | |
|
380 | 380 | if(m_orientation==Qt::Horizontal) { |
|
381 | 381 | m_min = domain->minX(); |
|
382 | 382 | m_max = domain->maxX(); |
|
383 | 383 | } |
|
384 | 384 | else if(m_orientation==Qt::Vertical) { |
|
385 | 385 | m_min = domain->minY(); |
|
386 | 386 | m_max = domain->maxY(); |
|
387 | 387 | } |
|
388 | 388 | |
|
389 | 389 | bool changed = false; |
|
390 | 390 | |
|
391 | 391 | int min = m_min + 0.5; |
|
392 | 392 | if(min>=0 && min<m_categories.count()) { |
|
393 | 393 | QString minCategory = m_categories.at(min); |
|
394 | 394 | if(m_minCategory!=minCategory && !minCategory.isEmpty()) { |
|
395 | 395 | m_minCategory=minCategory; |
|
396 | 396 | changed=true; |
|
397 | 397 | emit q->minChanged(minCategory); |
|
398 | 398 | } |
|
399 | 399 | } |
|
400 | 400 | int max = m_max - 0.5; |
|
401 | 401 | if(max>=0 && max<m_categories.count()) { |
|
402 | 402 | QString maxCategory = m_categories.at(max); |
|
403 | 403 | if(m_maxCategory!=maxCategory && !maxCategory.isEmpty()) { |
|
404 | 404 | m_maxCategory=maxCategory; |
|
405 | 405 | emit q->maxChanged(maxCategory); |
|
406 | 406 | } |
|
407 | 407 | } |
|
408 | 408 | |
|
409 | 409 | if (changed) { |
|
410 | 410 | emit q->rangeChanged(m_minCategory,m_maxCategory); |
|
411 | 411 | } |
|
412 | 412 | } |
|
413 | 413 | |
|
414 | 414 | ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
415 | 415 | { |
|
416 | 416 | Q_Q(QBarCategoriesAxis); |
|
417 | 417 | if(m_orientation == Qt::Vertical){ |
|
418 | 418 | return new ChartCategoriesAxisY(q,presenter); |
|
419 | 419 | }else{ |
|
420 | 420 | return new ChartCategoriesAxisX(q,presenter); |
|
421 | 421 | } |
|
422 | 422 | } |
|
423 | 423 | |
|
424 | 424 | void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain) |
|
425 | 425 | { |
|
426 | Q_UNUSED(domain); | |
|
427 | // TODO: this causes crash now. added to known issues. | |
|
428 | /* | |
|
429 | if (qFuzzyCompare(m_max, m_min)) { | |
|
430 | if(m_orientation==Qt::Vertical){ | |
|
431 | handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount()); | |
|
432 | }else{ | |
|
433 | handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount()); | |
|
426 | ||
|
427 | Q_Q(QBarCategoriesAxis); | |
|
428 | if(m_max==m_min) { | |
|
429 | int min; | |
|
430 | int max; | |
|
431 | if(m_orientation==Qt::Vertical) { | |
|
432 | min = domain->minY() + 0.5; | |
|
433 | max = domain->maxY() - 0.5; | |
|
434 | } | |
|
435 | else { | |
|
436 | min = domain->minX() + 0.5; | |
|
437 | max = domain->maxX() - 0.5; | |
|
438 | } | |
|
439 | ||
|
440 | if(min>0 && min<m_categories.count() && max>0 && max<m_categories.count()) | |
|
441 | q->setRange(m_categories.at(min),m_categories.at(max)); | |
|
442 | } | |
|
443 | else { | |
|
444 | if(m_orientation==Qt::Vertical) { | |
|
445 | domain->setRangeY(m_min, m_max); | |
|
446 | } | |
|
447 | else { | |
|
448 | domain->setRangeX(m_min, m_max); | |
|
434 | 449 | } |
|
435 | 450 | } |
|
436 | */ | |
|
437 | 451 | } |
|
438 | 452 | |
|
439 | 453 | #include "moc_qbarcategoriesaxis.cpp" |
|
440 | 454 | #include "moc_qbarcategoriesaxis_p.cpp" |
|
441 | 455 | |
|
442 | 456 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,484 +1,484 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "chartdataset_p.h" |
|
22 | 22 | #include "qchart.h" |
|
23 | 23 | #include "qvaluesaxis.h" |
|
24 | 24 | #include "qbarcategoriesaxis.h" |
|
25 | 25 | #include "qvaluesaxis_p.h" |
|
26 | 26 | #include "qintervalsaxis.h" |
|
27 | 27 | #include "qdatetimeaxis.h" |
|
28 | 28 | #include "qabstractseries_p.h" |
|
29 | 29 | #include "qabstractbarseries.h" |
|
30 | 30 | #include "qstackedbarseries.h" |
|
31 | 31 | #include "qpercentbarseries.h" |
|
32 | 32 | #include "qpieseries.h" |
|
33 | 33 | |
|
34 | 34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent) |
|
37 | 37 | { |
|
38 | 38 | |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | ChartDataSet::~ChartDataSet() |
|
42 | 42 | { |
|
43 | 43 | removeAllSeries(); |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | void ChartDataSet::addSeries(QAbstractSeries* series) |
|
47 | 47 | { |
|
48 | 48 | Domain* domain = m_seriesDomainMap.value(series); |
|
49 | 49 | |
|
50 | 50 | if(domain) { |
|
51 | 51 | qWarning() << "Can not add series. Series already on the chart"; |
|
52 | 52 | return; |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | domain = new Domain(series); |
|
56 | 56 | m_seriesDomainMap.insert(series,domain); |
|
57 | 57 | series->d_ptr->scaleDomain(*domain); |
|
58 | 58 | |
|
59 | 59 | createSeriesIndex(series); |
|
60 | 60 | |
|
61 | 61 | series->setParent(this); // take ownership |
|
62 | 62 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); |
|
63 | 63 | series->d_ptr->m_dataset = this; |
|
64 | 64 | |
|
65 | 65 | emit seriesAdded(series,domain); |
|
66 | 66 | |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | void ChartDataSet::removeSeries(QAbstractSeries* series) |
|
70 | 70 | { |
|
71 | 71 | |
|
72 | 72 | if(!m_seriesDomainMap.contains(series)) { |
|
73 | 73 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
74 | 74 | return; |
|
75 | 75 | } |
|
76 | 76 | |
|
77 | 77 | emit seriesRemoved(series); |
|
78 | 78 | |
|
79 | 79 | Domain* domain = m_seriesDomainMap.take(series); |
|
80 | 80 | delete domain; |
|
81 | 81 | domain = 0; |
|
82 | 82 | |
|
83 | 83 | removeSeriesIndex(series); |
|
84 | 84 | |
|
85 | 85 | series->setParent(0); |
|
86 | 86 | series->d_ptr->m_chart = 0; |
|
87 | 87 | series->d_ptr->m_dataset = 0; |
|
88 | 88 | |
|
89 | 89 | removeAxes(series); |
|
90 | 90 | } |
|
91 | 91 | |
|
92 | 92 | |
|
93 | 93 | |
|
94 | 94 | void ChartDataSet::createSeriesIndex(QAbstractSeries* series) |
|
95 | 95 | { |
|
96 | 96 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
97 | 97 | |
|
98 | 98 | int key=0; |
|
99 | 99 | while (i.hasNext()) { |
|
100 | 100 | i.next(); |
|
101 | 101 | if(i.key()!=key) { |
|
102 | 102 | break; |
|
103 | 103 | } |
|
104 | 104 | key++; |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | m_indexSeriesMap.insert(key,series); |
|
108 | 108 | } |
|
109 | 109 | |
|
110 | 110 | void ChartDataSet::removeSeriesIndex(QAbstractSeries* series) |
|
111 | 111 | { |
|
112 | 112 | int key = seriesIndex(series); |
|
113 | 113 | Q_ASSERT(key!=-1); |
|
114 | 114 | m_indexSeriesMap.remove(key); |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | 117 | void ChartDataSet::createDefaultAxes() |
|
118 | 118 | { |
|
119 | 119 | |
|
120 | 120 | if(m_seriesDomainMap.isEmpty()) return; |
|
121 | 121 | |
|
122 | 122 | QAbstractAxis::AxisTypes typeX(0); |
|
123 | 123 | QAbstractAxis::AxisTypes typeY(0); |
|
124 | 124 | |
|
125 | 125 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
126 | 126 | while (i.hasNext()) { |
|
127 | 127 | i.next(); |
|
128 | 128 | removeAxes(i.key()); |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | i.toFront(); |
|
132 | 132 | |
|
133 | 133 | while (i.hasNext()) { |
|
134 | 134 | i.next(); |
|
135 | 135 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); |
|
136 | 136 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); |
|
137 | 137 | if(axisX) typeX&=axisX->type(); |
|
138 | 138 | else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal); |
|
139 | 139 | if(axisY) typeY&=axisY->type(); |
|
140 | 140 | else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical); |
|
141 | 141 | } |
|
142 | 142 | |
|
143 | 143 | createAxes(typeX,Qt::Horizontal); |
|
144 | 144 | createAxes(typeY,Qt::Vertical); |
|
145 | 145 | } |
|
146 | 146 | |
|
147 | 147 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation) |
|
148 | 148 | { |
|
149 | 149 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
150 | 150 | |
|
151 | 151 | if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories)) |
|
152 | 152 | { |
|
153 | 153 | while (i.hasNext()) { |
|
154 | 154 | i.next(); |
|
155 | 155 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation); |
|
156 | 156 | if(!axis) continue; |
|
157 | 157 | initializeAxis(axis,i.key()); |
|
158 | 158 | emit axisAdded(axis,i.value()); |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | } |
|
162 | 162 | else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { |
|
163 | 163 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation); |
|
164 | 164 | i.toFront(); |
|
165 | 165 | while (i.hasNext()) { |
|
166 | 166 | i.next(); |
|
167 | 167 | initializeAxis(axis,i.key()); |
|
168 | 168 | } |
|
169 | 169 | emit axisAdded(axis,i.value()); |
|
170 | 170 | } |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | |
|
174 | 174 | QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation) |
|
175 | 175 | { |
|
176 | 176 | QAbstractAxis* axis =0; |
|
177 | 177 | |
|
178 | 178 | switch(type) { |
|
179 | 179 | case QAbstractAxis::AxisTypeValues: |
|
180 | 180 | axis = new QValuesAxis(this); |
|
181 | 181 | break; |
|
182 | 182 | case QAbstractAxis::AxisTypeCategories: |
|
183 | 183 | axis = new QBarCategoriesAxis(this); |
|
184 | 184 | break; |
|
185 | 185 | case QAbstractAxis::AxisTypeIntervals: |
|
186 | 186 | axis = new QIntervalsAxis(this); |
|
187 | 187 | break; |
|
188 | 188 | case QAbstractAxis::AxisTypeDateTime: |
|
189 | 189 | axis = new QDateTimeAxis(this); |
|
190 | 190 | break; |
|
191 | 191 | default: |
|
192 | 192 | axis = 0; |
|
193 | 193 | break; |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | if(axis) |
|
197 | 197 | axis->d_ptr->setOrientation(orientation); |
|
198 | 198 | |
|
199 | 199 | return axis; |
|
200 | 200 | } |
|
201 | 201 | |
|
202 | 202 | void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series) |
|
203 | 203 | { |
|
204 | 204 | Domain* domain = m_seriesDomainMap.value(series); |
|
205 | 205 | axis->d_ptr->m_dataset = this; |
|
206 | axis->d_ptr->intializeDomain(domain); | |
|
207 | 206 | series->d_ptr->initializeAxis(axis); |
|
207 | axis->d_ptr->intializeDomain(domain); | |
|
208 | 208 | if(axis->orientation()==Qt::Horizontal) { |
|
209 | 209 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); |
|
210 | 210 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); |
|
211 | 211 | m_seriesAxisXMap.insert(series,axis); |
|
212 | 212 | } |
|
213 | 213 | else { |
|
214 | 214 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); |
|
215 | 215 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); |
|
216 | 216 | m_seriesAxisYMap.insert(series,axis); |
|
217 | 217 | } |
|
218 | 218 | axis->d_ptr->emitUpdated(); |
|
219 | 219 | } |
|
220 | 220 | |
|
221 | 221 | void ChartDataSet::removeAxes(QAbstractSeries* series) |
|
222 | 222 | { |
|
223 | 223 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); |
|
224 | 224 | |
|
225 | 225 | if(axisX) { |
|
226 | 226 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
227 | 227 | int x = axesX.indexOf(axisX); |
|
228 | 228 | |
|
229 | 229 | if(x==-1) { |
|
230 | 230 | emit axisRemoved(axisX); |
|
231 | 231 | axisX->d_ptr->m_dataset=0; |
|
232 | 232 | axisX->deleteLater(); |
|
233 | 233 | } |
|
234 | 234 | } |
|
235 | 235 | |
|
236 | 236 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); |
|
237 | 237 | |
|
238 | 238 | if(axisY) { |
|
239 | 239 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
240 | 240 | |
|
241 | 241 | int y = axesY.indexOf(axisY); |
|
242 | 242 | |
|
243 | 243 | if(y==-1) { |
|
244 | 244 | emit axisRemoved(axisY); |
|
245 | 245 | axisY->d_ptr->m_dataset=0; |
|
246 | 246 | axisY->deleteLater(); |
|
247 | 247 | } |
|
248 | 248 | } |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | void ChartDataSet::removeAxis(QAbstractAxis* axis) |
|
252 | 252 | { |
|
253 | 253 | if(!axis->d_ptr->m_dataset) { |
|
254 | 254 | qWarning()<<"UnBound axis found !"; |
|
255 | 255 | return; |
|
256 | 256 | } |
|
257 | 257 | |
|
258 | 258 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; |
|
259 | 259 | |
|
260 | 260 | if(axis->orientation()==Qt::Vertical) { |
|
261 | 261 | seriesAxisMap= &m_seriesAxisYMap; |
|
262 | 262 | } |
|
263 | 263 | else { |
|
264 | 264 | seriesAxisMap= &m_seriesAxisXMap; |
|
265 | 265 | } |
|
266 | 266 | |
|
267 | 267 | QMapIterator<QAbstractSeries*, QAbstractAxis*> i(*seriesAxisMap); |
|
268 | 268 | |
|
269 | 269 | while (i.hasNext()) { |
|
270 | 270 | i.next(); |
|
271 | 271 | if(i.value()==axis) { |
|
272 | 272 | removeSeries(i.key()); |
|
273 | 273 | } |
|
274 | 274 | } |
|
275 | 275 | } |
|
276 | 276 | |
|
277 | 277 | void ChartDataSet::removeAllSeries() |
|
278 | 278 | { |
|
279 | 279 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); |
|
280 | 280 | foreach(QAbstractSeries *s , series) { |
|
281 | 281 | removeSeries(s); |
|
282 | 282 | } |
|
283 | 283 | |
|
284 | 284 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
285 | 285 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
286 | 286 | Q_ASSERT(m_seriesDomainMap.count()==0); |
|
287 | 287 | |
|
288 | 288 | qDeleteAll(series); |
|
289 | 289 | } |
|
290 | 290 | |
|
291 | 291 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
292 | 292 | { |
|
293 | 293 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
294 | 294 | |
|
295 | 295 | |
|
296 | 296 | blockAxisSignals(true); |
|
297 | 297 | |
|
298 | 298 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
299 | 299 | |
|
300 | 300 | while (i.hasNext()) { |
|
301 | 301 | i.next(); |
|
302 | 302 | i.value()->zoomIn(rect,size); |
|
303 | 303 | } |
|
304 | 304 | |
|
305 | 305 | blockAxisSignals(false); |
|
306 | 306 | |
|
307 | 307 | } |
|
308 | 308 | |
|
309 | 309 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
310 | 310 | { |
|
311 | 311 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
312 | 312 | |
|
313 | 313 | blockAxisSignals(true); |
|
314 | 314 | |
|
315 | 315 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
316 | 316 | |
|
317 | 317 | while (i.hasNext()) { |
|
318 | 318 | i.next(); |
|
319 | 319 | i.value()->zoomOut(rect,size); |
|
320 | 320 | } |
|
321 | 321 | |
|
322 | 322 | blockAxisSignals(false); |
|
323 | 323 | } |
|
324 | 324 | |
|
325 | 325 | void ChartDataSet::blockAxisSignals(bool enabled) |
|
326 | 326 | { |
|
327 | 327 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
328 | 328 | while (i.hasNext()) { |
|
329 | 329 | i.next(); |
|
330 | 330 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); |
|
331 | 331 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); |
|
332 | 332 | if(axisX) { |
|
333 | 333 | axisX->d_ptr->blockSignals(enabled); |
|
334 | 334 | if(!enabled) { |
|
335 | 335 | axisX->d_ptr->setDirty(false); |
|
336 | 336 | axisX->d_ptr->emitUpdated(); |
|
337 | 337 | } |
|
338 | 338 | } |
|
339 | 339 | if(axisY) { |
|
340 | 340 | axisY->d_ptr->blockSignals(enabled); |
|
341 | 341 | if(!enabled) { |
|
342 | 342 | axisY->d_ptr->setDirty(false); |
|
343 | 343 | axisY->d_ptr->emitUpdated(); |
|
344 | 344 | } |
|
345 | 345 | } |
|
346 | 346 | } |
|
347 | 347 | } |
|
348 | 348 | |
|
349 | 349 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
350 | 350 | { |
|
351 | 351 | int count=0; |
|
352 | 352 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
353 | 353 | while (i.hasNext()) { |
|
354 | 354 | i.next(); |
|
355 | 355 | if(i.key()->type()==type) count++; |
|
356 | 356 | } |
|
357 | 357 | return count; |
|
358 | 358 | } |
|
359 | 359 | |
|
360 | 360 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
361 | 361 | { |
|
362 | 362 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
363 | 363 | while (i.hasNext()) { |
|
364 | 364 | i.next(); |
|
365 | 365 | if (i.value() == series) |
|
366 | 366 | return i.key(); |
|
367 | 367 | } |
|
368 | 368 | return -1; |
|
369 | 369 | } |
|
370 | 370 | |
|
371 | 371 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const |
|
372 | 372 | { |
|
373 | 373 | if(series == 0) { |
|
374 | 374 | |
|
375 | 375 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap); |
|
376 | 376 | |
|
377 | 377 | while (i.hasNext()) { |
|
378 | 378 | i.next(); |
|
379 | 379 | if(i.value()->isVisible()) return i.value(); |
|
380 | 380 | } |
|
381 | 381 | return 0; |
|
382 | 382 | } |
|
383 | 383 | return m_seriesAxisXMap.value(series); |
|
384 | 384 | } |
|
385 | 385 | |
|
386 | 386 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
387 | 387 | { |
|
388 | 388 | if(series == 0) { |
|
389 | 389 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap); |
|
390 | 390 | |
|
391 | 391 | while (i.hasNext()) { |
|
392 | 392 | i.next(); |
|
393 | 393 | if(i.value()->isVisible()) return i.value(); |
|
394 | 394 | } |
|
395 | 395 | return 0; |
|
396 | 396 | } |
|
397 | 397 | return m_seriesAxisYMap.value(series); |
|
398 | 398 | } |
|
399 | 399 | |
|
400 | 400 | void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation) |
|
401 | 401 | { |
|
402 | 402 | Q_ASSERT(axis); |
|
403 | 403 | |
|
404 | 404 | if(!series) { |
|
405 | 405 | qWarning() << "Series not found on the chart."; |
|
406 | 406 | return; |
|
407 | 407 | } |
|
408 | 408 | |
|
409 | 409 | Domain* domain = m_seriesDomainMap.value(series); |
|
410 | 410 | |
|
411 | 411 | if(!domain) { |
|
412 | 412 | qWarning() << "Series not found on the chart."; |
|
413 | 413 | return; |
|
414 | 414 | } |
|
415 | 415 | |
|
416 | 416 | if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) { |
|
417 | 417 | qWarning()<<"Axis already defined as axis Y"; |
|
418 | 418 | return; |
|
419 | 419 | } |
|
420 | 420 | |
|
421 | 421 | if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) { |
|
422 | 422 | qWarning()<<"Axis already defined as axis X"; |
|
423 | 423 | return; |
|
424 | 424 | } |
|
425 | 425 | |
|
426 | 426 | axis->d_ptr->setOrientation(orientation); |
|
427 | 427 | |
|
428 | 428 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; |
|
429 | 429 | |
|
430 | 430 | if(orientation==Qt::Vertical) { |
|
431 | 431 | seriesAxisMap= &m_seriesAxisYMap; |
|
432 | 432 | }else{ |
|
433 | 433 | seriesAxisMap= &m_seriesAxisXMap; |
|
434 | 434 | } |
|
435 | 435 | |
|
436 | 436 | QAbstractAxis *oldAxis = seriesAxisMap->take(series); |
|
437 | 437 | QList<QAbstractAxis*> axes = seriesAxisMap->values(); |
|
438 | 438 | if(oldAxis) { |
|
439 | 439 | if(axes.indexOf(oldAxis)==-1) { |
|
440 | 440 | emit axisRemoved(oldAxis); |
|
441 | 441 | oldAxis->disconnect(); |
|
442 | 442 | QObject::disconnect(domain,0,oldAxis,0); |
|
443 | 443 | oldAxis->d_ptr->m_dataset=0; |
|
444 | 444 | oldAxis->deleteLater(); |
|
445 | 445 | } |
|
446 | 446 | } |
|
447 | 447 | |
|
448 | 448 | if(axes.indexOf(axis)==-1) { |
|
449 | 449 | initializeAxis(axis,series); |
|
450 | 450 | emit axisAdded(axis,domain); |
|
451 | 451 | }else{ |
|
452 | 452 | initializeAxis(axis,series); |
|
453 | 453 | } |
|
454 | 454 | } |
|
455 | 455 | |
|
456 | 456 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
457 | 457 | { |
|
458 | 458 | return m_seriesDomainMap.value(series); |
|
459 | 459 | } |
|
460 | 460 | |
|
461 | 461 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) |
|
462 | 462 | { |
|
463 | 463 | blockAxisSignals(true); |
|
464 | 464 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
465 | 465 | while (i.hasNext()) { |
|
466 | 466 | i.next(); |
|
467 | 467 | i.value()->move(dx,dy,size); |
|
468 | 468 | } |
|
469 | 469 | blockAxisSignals(false); |
|
470 | 470 | } |
|
471 | 471 | |
|
472 | 472 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
473 | 473 | { |
|
474 | 474 | return m_seriesDomainMap.keys(); |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | void ChartDataSet::updateSeries(QAbstractSeries *series) |
|
478 | 478 | { |
|
479 | 479 | emit seriesUpdated(series); |
|
480 | 480 | } |
|
481 | 481 | |
|
482 | 482 | #include "moc_chartdataset_p.cpp" |
|
483 | 483 | |
|
484 | 484 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,582 +1,649 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "../qabstractaxis/tst_qabstractaxis.h" |
|
22 | 22 | #include <qbarseries.h> |
|
23 | 23 | #include <qbarset.h> |
|
24 | 24 | #include <qbarcategoriesaxis.h> |
|
25 | 25 | |
|
26 | 26 | class tst_QBarCategoriesAxis: public tst_QAbstractAxis |
|
27 | 27 | { |
|
28 | 28 | Q_OBJECT |
|
29 | 29 | |
|
30 | 30 | public slots: |
|
31 | 31 | void initTestCase(); |
|
32 | 32 | void cleanupTestCase(); |
|
33 | 33 | void init(); |
|
34 | 34 | void cleanup(); |
|
35 | 35 | |
|
36 | 36 | private slots: |
|
37 | 37 | void qbarcategoriesaxis_data(); |
|
38 | 38 | void qbarcategoriesaxis(); |
|
39 | 39 | |
|
40 | 40 | void append_data(); |
|
41 | 41 | void append(); |
|
42 | 42 | void at_data(); |
|
43 | 43 | void at(); |
|
44 | 44 | void categories_data(); |
|
45 | 45 | void categories(); |
|
46 | 46 | void clear_data(); |
|
47 | 47 | void clear(); |
|
48 | 48 | void count_data(); |
|
49 | 49 | void count(); |
|
50 | 50 | void insert_data(); |
|
51 | 51 | void insert(); |
|
52 | 52 | void remove_data(); |
|
53 | 53 | void remove(); |
|
54 | 54 | void max_raw_data(); |
|
55 | 55 | void max_raw(); |
|
56 | 56 | void max_data(); |
|
57 | 57 | void max(); |
|
58 | 58 | void max_animation_data(); |
|
59 | 59 | void max_animation(); |
|
60 | 60 | void min_raw_data(); |
|
61 | 61 | void min_raw(); |
|
62 | 62 | void min_data(); |
|
63 | 63 | void min(); |
|
64 | 64 | void min_animation_data(); |
|
65 | 65 | void min_animation(); |
|
66 | 66 | void range_raw_data(); |
|
67 | 67 | void range_raw(); |
|
68 | 68 | void range_data(); |
|
69 | 69 | void range(); |
|
70 | 70 | void range_animation_data(); |
|
71 | 71 | void range_animation(); |
|
72 | void noautoscale_data(); | |
|
73 | void noautoscale(); | |
|
74 | void autoscale_data(); | |
|
75 | void autoscale(); | |
|
72 | 76 | |
|
73 | 77 | private: |
|
74 | 78 | QBarCategoriesAxis* m_baraxis; |
|
75 | 79 | QBarSeries* m_series; |
|
76 | 80 | }; |
|
77 | 81 | |
|
78 | 82 | void tst_QBarCategoriesAxis::initTestCase() |
|
79 | 83 | { |
|
80 | 84 | } |
|
81 | 85 | |
|
82 | 86 | void tst_QBarCategoriesAxis::cleanupTestCase() |
|
83 | 87 | { |
|
84 | 88 | } |
|
85 | 89 | |
|
86 | 90 | void tst_QBarCategoriesAxis::init() |
|
87 | 91 | { |
|
88 | 92 | m_baraxis = new QBarCategoriesAxis(); |
|
89 | 93 | m_series = new QBarSeries(); |
|
90 | 94 | |
|
91 | 95 | QBarSet *set0 = new QBarSet("Jane"); |
|
92 | 96 | QBarSet *set1 = new QBarSet("John"); |
|
93 | 97 | QBarSet *set2 = new QBarSet("Axel"); |
|
94 | 98 | QBarSet *set3 = new QBarSet("Mary"); |
|
95 | 99 | QBarSet *set4 = new QBarSet("Samantha"); |
|
96 | 100 | |
|
97 | 101 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
98 | 102 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
99 | 103 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
100 | 104 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
101 | 105 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
102 | 106 | |
|
103 | 107 | m_series->append(set0); |
|
104 | 108 | m_series->append(set1); |
|
105 | 109 | m_series->append(set2); |
|
106 | 110 | m_series->append(set3); |
|
107 | 111 | m_series->append(set4); |
|
108 | 112 | |
|
109 | 113 | QStringList categories; |
|
110 | 114 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
111 | 115 | |
|
112 | 116 | m_baraxis->append(categories); |
|
113 | 117 | |
|
114 | 118 | tst_QAbstractAxis::init(m_baraxis, m_series); |
|
115 | 119 | m_chart->addSeries(m_series); |
|
116 | 120 | m_chart->createDefaultAxes(); |
|
117 | 121 | } |
|
118 | 122 | |
|
119 | 123 | void tst_QBarCategoriesAxis::cleanup() |
|
120 | 124 | { |
|
121 | 125 | delete m_series; |
|
122 | 126 | delete m_baraxis; |
|
123 | 127 | m_series = 0; |
|
124 | 128 | m_baraxis = 0; |
|
125 | 129 | tst_QAbstractAxis::cleanup(); |
|
126 | 130 | } |
|
127 | 131 | |
|
128 | 132 | void tst_QBarCategoriesAxis::qbarcategoriesaxis_data() |
|
129 | 133 | { |
|
130 | 134 | } |
|
131 | 135 | |
|
132 | 136 | void tst_QBarCategoriesAxis::qbarcategoriesaxis() |
|
133 | 137 | { |
|
134 | 138 | qabstractaxis(); |
|
135 | 139 | QBarCategoriesAxis axis; |
|
136 | 140 | axis.append(QStringList()); |
|
137 | 141 | axis.append(QString()); |
|
138 | 142 | QCOMPARE(axis.at(0), QString()); |
|
139 | 143 | QStringList test; |
|
140 | 144 | test.append(QString()); |
|
141 | 145 | QCOMPARE(axis.categories(),test); |
|
142 | 146 | axis.clear(); |
|
143 | 147 | QCOMPARE(axis.count(), 0); |
|
144 | 148 | axis.insert(-1, QString()); |
|
145 | 149 | QCOMPARE(axis.max(), QString()); |
|
146 | 150 | QCOMPARE(axis.min(), QString()); |
|
147 | 151 | axis.remove(QString()); |
|
148 | 152 | axis.setCategories(QStringList()); |
|
149 | 153 | axis.setMax(QString()); |
|
150 | 154 | axis.setMin(QString()); |
|
151 | 155 | axis.setRange(QString(), QString()); |
|
152 | 156 | QCOMPARE(axis.type(), QAbstractAxis::AxisTypeCategories); |
|
153 | 157 | } |
|
154 | 158 | |
|
155 | 159 | void tst_QBarCategoriesAxis::append_data() |
|
156 | 160 | { |
|
157 | 161 | QTest::addColumn<QStringList>("categories"); |
|
158 | 162 | QTest::newRow("Jan Feb Mar Apr") << (QStringList() << "Jan" << "Feb" << "Mar" << "Apr"); |
|
159 | 163 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep"); |
|
160 | 164 | } |
|
161 | 165 | |
|
162 | 166 | void tst_QBarCategoriesAxis::append() |
|
163 | 167 | { |
|
164 | 168 | QFETCH(QStringList, categories); |
|
165 | 169 | |
|
166 | 170 | QBarCategoriesAxis axis; |
|
167 | 171 | |
|
168 | 172 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
169 | 173 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); |
|
170 | 174 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); |
|
171 | 175 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
172 | 176 | |
|
173 | 177 | axis.append(categories); |
|
174 | 178 | |
|
175 | 179 | QCOMPARE(spy0.count(), 1); |
|
176 | 180 | QCOMPARE(spy1.count(), 1); |
|
177 | 181 | QCOMPARE(spy2.count(), 1); |
|
178 | 182 | QCOMPARE(spy3.count(), 1); |
|
179 | 183 | |
|
180 | 184 | m_chart->setAxisX(&axis, m_series); |
|
181 | 185 | m_view->show(); |
|
182 | 186 | QTest::qWaitForWindowShown(m_view); |
|
183 | 187 | QCOMPARE(axis.categories(), categories); |
|
184 | 188 | |
|
185 | 189 | QCOMPARE(spy0.count(), 1); |
|
186 | 190 | QCOMPARE(spy1.count(), 1); |
|
187 | 191 | QCOMPARE(spy2.count(), 1); |
|
188 | 192 | QCOMPARE(spy3.count(), 1); |
|
189 | 193 | } |
|
190 | 194 | |
|
191 | 195 | void tst_QBarCategoriesAxis::at_data() |
|
192 | 196 | { |
|
193 | 197 | QTest::addColumn<QStringList>("categories"); |
|
194 | 198 | QTest::addColumn<int>("index"); |
|
195 | 199 | QTest::addColumn<QString>("string"); |
|
196 | 200 | QTest::newRow("Jul Aug Sep 0 Jul") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jul"; |
|
197 | 201 | QTest::newRow("Jul Aug Sep 2 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Sep"; |
|
198 | 202 | QTest::newRow("Jul Aug Sep 1 Aug") << (QStringList() << "Jul" << "Aug" << "Sep") << 1 << "Aug"; |
|
199 | 203 | } |
|
200 | 204 | |
|
201 | 205 | void tst_QBarCategoriesAxis::at() |
|
202 | 206 | { |
|
203 | 207 | QFETCH(int, index); |
|
204 | 208 | QFETCH(QString, string); |
|
205 | 209 | QFETCH(QStringList, categories); |
|
206 | 210 | |
|
207 | 211 | QBarCategoriesAxis axis; |
|
208 | 212 | axis.append(categories); |
|
209 | 213 | |
|
210 | 214 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
211 | 215 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); |
|
212 | 216 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); |
|
213 | 217 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
214 | 218 | |
|
215 | 219 | QCOMPARE(axis.at(index), string); |
|
216 | 220 | |
|
217 | 221 | QCOMPARE(spy0.count(), 0); |
|
218 | 222 | QCOMPARE(spy1.count(), 0); |
|
219 | 223 | QCOMPARE(spy2.count(), 0); |
|
220 | 224 | QCOMPARE(spy3.count(), 0); |
|
221 | 225 | |
|
222 | 226 | m_chart->setAxisX(&axis, m_series); |
|
223 | 227 | m_view->show(); |
|
224 | 228 | QTest::qWaitForWindowShown(m_view); |
|
225 | 229 | QCOMPARE(axis.at(index), string); |
|
226 | 230 | |
|
227 | 231 | QCOMPARE(spy0.count(), 0); |
|
228 | 232 | QCOMPARE(spy1.count(), 0); |
|
229 | 233 | QCOMPARE(spy2.count(), 0); |
|
230 | 234 | QCOMPARE(spy3.count(), 0); |
|
231 | 235 | } |
|
232 | 236 | |
|
233 | 237 | void tst_QBarCategoriesAxis::categories_data() |
|
234 | 238 | { |
|
235 | 239 | QTest::addColumn<QStringList>("categories"); |
|
236 | 240 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep"); |
|
237 | 241 | } |
|
238 | 242 | |
|
239 | 243 | void tst_QBarCategoriesAxis::categories() |
|
240 | 244 | { |
|
241 | 245 | QFETCH(QStringList, categories); |
|
242 | 246 | |
|
243 | 247 | QBarCategoriesAxis axis; |
|
244 | 248 | |
|
245 | 249 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
246 | 250 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); |
|
247 | 251 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); |
|
248 | 252 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
249 | 253 | |
|
250 | 254 | axis.setCategories(categories); |
|
251 | 255 | QCOMPARE(axis.categories(), categories); |
|
252 | 256 | |
|
253 | 257 | QCOMPARE(spy0.count(), 1); |
|
254 | 258 | QCOMPARE(spy1.count(), 1); |
|
255 | 259 | QCOMPARE(spy2.count(), 1); |
|
256 | 260 | QCOMPARE(spy3.count(), 1); |
|
257 | 261 | |
|
258 | 262 | m_chart->setAxisX(&axis, m_series); |
|
259 | 263 | m_view->show(); |
|
260 | 264 | QTest::qWaitForWindowShown(m_view); |
|
261 | 265 | QCOMPARE(axis.categories(), categories); |
|
262 | 266 | |
|
263 | 267 | QCOMPARE(spy0.count(), 1); |
|
264 | 268 | QCOMPARE(spy1.count(), 1); |
|
265 | 269 | QCOMPARE(spy2.count(), 1); |
|
266 | 270 | QCOMPARE(spy3.count(), 1); |
|
267 | 271 | |
|
268 | 272 | } |
|
269 | 273 | |
|
270 | 274 | void tst_QBarCategoriesAxis::clear_data() |
|
271 | 275 | { |
|
272 | 276 | QTest::addColumn<QStringList>("categories"); |
|
273 | 277 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep"); |
|
274 | 278 | } |
|
275 | 279 | |
|
276 | 280 | void tst_QBarCategoriesAxis::clear() |
|
277 | 281 | { |
|
278 | 282 | QFETCH(QStringList, categories); |
|
279 | 283 | |
|
280 | 284 | QBarCategoriesAxis axis; |
|
281 | 285 | |
|
282 | 286 | axis.setCategories(categories); |
|
283 | 287 | QCOMPARE(axis.categories(), categories); |
|
284 | 288 | |
|
285 | 289 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
286 | 290 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); |
|
287 | 291 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); |
|
288 | 292 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
289 | 293 | |
|
290 | 294 | axis.clear(); |
|
291 | 295 | QCOMPARE(axis.categories(), QStringList()); |
|
292 | 296 | |
|
293 | 297 | QCOMPARE(spy0.count(), 1); |
|
294 | 298 | QCOMPARE(spy1.count(), 1); |
|
295 | 299 | QCOMPARE(spy2.count(), 1); |
|
296 | 300 | QCOMPARE(spy3.count(), 1); |
|
297 | 301 | |
|
298 | 302 | m_chart->setAxisX(&axis, m_series); |
|
299 | 303 | m_view->show(); |
|
300 | 304 | QTest::qWaitForWindowShown(m_view); |
|
301 | 305 | |
|
302 | 306 | QCOMPARE(spy0.count(), 2); |
|
303 | 307 | QCOMPARE(spy1.count(), 2); |
|
304 | 308 | QCOMPARE(spy2.count(), 2); |
|
305 | 309 | QCOMPARE(spy3.count(), 2); |
|
306 | 310 | |
|
307 | 311 | axis.clear(); |
|
308 | 312 | QCOMPARE(axis.categories().count(),0); |
|
309 | 313 | QCOMPARE(spy0.count(), 3); |
|
310 | 314 | QCOMPARE(spy1.count(), 3); |
|
311 | 315 | QCOMPARE(spy2.count(), 3); |
|
312 | 316 | QCOMPARE(spy3.count(), 3); |
|
313 | 317 | } |
|
314 | 318 | |
|
315 | 319 | void tst_QBarCategoriesAxis::count_data() |
|
316 | 320 | { |
|
317 | 321 | QTest::addColumn<QStringList>("categories"); |
|
318 | 322 | QTest::addColumn<int>("count"); |
|
319 | 323 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3; |
|
320 | 324 | QTest::newRow("Jul Aug ") << (QStringList() << "Jul" << "Aug") << 2; |
|
321 | 325 | } |
|
322 | 326 | |
|
323 | 327 | void tst_QBarCategoriesAxis::count() |
|
324 | 328 | { |
|
325 | 329 | QFETCH(QStringList, categories); |
|
326 | 330 | QFETCH(int, count); |
|
327 | 331 | |
|
328 | 332 | QBarCategoriesAxis axis; |
|
329 | 333 | axis.setCategories(categories); |
|
330 | 334 | |
|
331 | 335 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
332 | 336 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); |
|
333 | 337 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); |
|
334 | 338 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
335 | 339 | |
|
336 | 340 | QCOMPARE(axis.count(), count); |
|
337 | 341 | |
|
338 | 342 | QCOMPARE(spy0.count(), 0); |
|
339 | 343 | QCOMPARE(spy1.count(), 0); |
|
340 | 344 | QCOMPARE(spy2.count(), 0); |
|
341 | 345 | QCOMPARE(spy3.count(), 0); |
|
342 | 346 | |
|
343 | 347 | m_chart->setAxisX(&axis, m_series); |
|
344 | 348 | m_view->show(); |
|
345 | 349 | QTest::qWaitForWindowShown(m_view); |
|
346 | 350 | QCOMPARE(axis.count(), count); |
|
347 | 351 | } |
|
348 | 352 | |
|
349 | 353 | void tst_QBarCategoriesAxis::insert_data() |
|
350 | 354 | { |
|
351 | 355 | QTest::addColumn<QStringList>("categories"); |
|
352 | 356 | QTest::addColumn<int>("index"); |
|
353 | 357 | QTest::addColumn<QString>("category"); |
|
354 | 358 | QTest::newRow("Jul Aug Sep 0 Jun") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jun"; |
|
355 | 359 | QTest::newRow("Jul Aug Sep 3 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3 << "Sep"; |
|
356 | 360 | QTest::newRow("Jul Aug Sep 2 Summer") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Summer"; |
|
357 | 361 | } |
|
358 | 362 | |
|
359 | 363 | void tst_QBarCategoriesAxis::insert() |
|
360 | 364 | { |
|
361 | 365 | QFETCH(QStringList, categories); |
|
362 | 366 | QFETCH(int, index); |
|
363 | 367 | QFETCH(QString, category); |
|
364 | 368 | |
|
365 | 369 | QBarCategoriesAxis axis; |
|
366 | 370 | axis.append(categories); |
|
367 | 371 | |
|
368 | 372 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
369 | 373 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); |
|
370 | 374 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); |
|
371 | 375 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
372 | 376 | |
|
373 | 377 | axis.insert(index, category); |
|
374 | 378 | QCOMPARE(axis.at(index),category); |
|
375 | 379 | |
|
376 | 380 | QCOMPARE(spy0.count(), 1); |
|
377 | 381 | QCOMPARE(spy1.count(), 0); |
|
378 | 382 | QCOMPARE(spy2.count(), 0); |
|
379 | 383 | QCOMPARE(spy3.count(), 0); |
|
380 | 384 | |
|
381 | 385 | m_chart->setAxisX(&axis, m_series); |
|
382 | 386 | m_view->show(); |
|
383 | 387 | QTest::qWaitForWindowShown(m_view); |
|
384 | 388 | } |
|
385 | 389 | |
|
386 | 390 | void tst_QBarCategoriesAxis::remove_data() |
|
387 | 391 | { |
|
388 | 392 | QTest::addColumn<QStringList>("categories"); |
|
389 | 393 | QTest::addColumn<QString>("category"); |
|
390 | 394 | QTest::addColumn<QStringList>("result"); |
|
391 | 395 | QTest::newRow("Jul Aug Sep 0") << (QStringList() << "Jul" << "Aug" << "Sep") << "Jul" << (QStringList() << "Aug" << "Sep"); |
|
392 | 396 | QTest::newRow("Jul Aug Sep 1") << (QStringList() << "Jul" << "Aug" << "Sep") << "Aug"<< (QStringList() << "Jul" << "Sep"); |
|
393 | 397 | } |
|
394 | 398 | |
|
395 | 399 | void tst_QBarCategoriesAxis::remove() |
|
396 | 400 | { |
|
397 | 401 | QFETCH(QStringList, categories); |
|
398 | 402 | QFETCH(QString, category); |
|
399 | 403 | QFETCH(QStringList, result); |
|
400 | 404 | |
|
401 | 405 | QBarCategoriesAxis axis; |
|
402 | 406 | axis.append(categories); |
|
403 | 407 | |
|
404 | 408 | int maxCount = axis.max() == category; |
|
405 | 409 | int minCount = axis.min() == category; |
|
406 | 410 | int rangeCount = maxCount + minCount; |
|
407 | 411 | |
|
408 | 412 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
409 | 413 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); |
|
410 | 414 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); |
|
411 | 415 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
412 | 416 | |
|
413 | 417 | axis.remove(category); |
|
414 | 418 | QCOMPARE(axis.categories(),result); |
|
415 | 419 | |
|
416 | 420 | QCOMPARE(spy0.count(), 1); |
|
417 | 421 | QCOMPARE(spy1.count(), maxCount); |
|
418 | 422 | QCOMPARE(spy2.count(), minCount); |
|
419 | 423 | QCOMPARE(spy3.count(), rangeCount); |
|
420 | 424 | } |
|
421 | 425 | |
|
422 | 426 | void tst_QBarCategoriesAxis::max_raw_data() |
|
423 | 427 | { |
|
424 | 428 | //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
425 | 429 | QTest::addColumn<QString>("max"); |
|
426 | 430 | QTest::newRow("Feb") << "Feb"; |
|
427 | 431 | QTest::newRow("Apr") << "Apr"; |
|
428 | 432 | QTest::newRow("May") << "May"; |
|
429 | 433 | } |
|
430 | 434 | |
|
431 | 435 | void tst_QBarCategoriesAxis::max_raw() |
|
432 | 436 | { |
|
433 | 437 | QFETCH(QString, max); |
|
434 | 438 | |
|
435 | 439 | QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged())); |
|
436 | 440 | QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&))); |
|
437 | 441 | QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&))); |
|
438 | 442 | QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
439 | 443 | |
|
440 | 444 | m_baraxis->setMax(max); |
|
441 | 445 | QCOMPARE(m_baraxis->max(), max); |
|
442 | 446 | |
|
443 | 447 | QCOMPARE(spy0.count(), 0); |
|
444 | 448 | QCOMPARE(spy1.count(), 1); |
|
445 | 449 | QCOMPARE(spy2.count(), 0); |
|
446 | 450 | QCOMPARE(spy3.count(), 1); |
|
447 | 451 | } |
|
448 | 452 | |
|
449 | 453 | void tst_QBarCategoriesAxis::max_data() |
|
450 | 454 | { |
|
451 | 455 | max_raw_data(); |
|
452 | 456 | } |
|
453 | 457 | |
|
454 | 458 | void tst_QBarCategoriesAxis::max() |
|
455 | 459 | { |
|
456 | 460 | m_chart->setAxisX(m_baraxis, m_series); |
|
457 | 461 | m_view->show(); |
|
458 | 462 | QTest::qWaitForWindowShown(m_view); |
|
459 | 463 | max_raw(); |
|
460 | 464 | } |
|
461 | 465 | |
|
462 | 466 | void tst_QBarCategoriesAxis::max_animation_data() |
|
463 | 467 | { |
|
464 | 468 | max_data(); |
|
465 | 469 | } |
|
466 | 470 | |
|
467 | 471 | void tst_QBarCategoriesAxis::max_animation() |
|
468 | 472 | { |
|
469 | 473 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
470 | 474 | max(); |
|
471 | 475 | } |
|
472 | 476 | |
|
473 | 477 | void tst_QBarCategoriesAxis::min_raw_data() |
|
474 | 478 | { |
|
475 | 479 | //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
476 | 480 | QTest::addColumn<QString>("min"); |
|
477 | 481 | QTest::newRow("Feb") << "Feb"; |
|
478 | 482 | QTest::newRow("Apr") << "Apr"; |
|
479 | 483 | QTest::newRow("May") << "May"; |
|
480 | 484 | } |
|
481 | 485 | |
|
482 | 486 | void tst_QBarCategoriesAxis::min_raw() |
|
483 | 487 | { |
|
484 | 488 | QFETCH(QString, min); |
|
485 | 489 | |
|
486 | 490 | QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged())); |
|
487 | 491 | QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&))); |
|
488 | 492 | QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&))); |
|
489 | 493 | QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
490 | 494 | |
|
491 | 495 | m_baraxis->setMin(min); |
|
492 | 496 | QCOMPARE(m_baraxis->min(), min); |
|
493 | 497 | |
|
494 | 498 | QCOMPARE(spy0.count(), 0); |
|
495 | 499 | QCOMPARE(spy1.count(), 0); |
|
496 | 500 | QCOMPARE(spy2.count(), 1); |
|
497 | 501 | QCOMPARE(spy3.count(), 1); |
|
498 | 502 | |
|
499 | 503 | } |
|
500 | 504 | |
|
501 | 505 | void tst_QBarCategoriesAxis::min_data() |
|
502 | 506 | { |
|
503 | 507 | min_raw_data(); |
|
504 | 508 | } |
|
505 | 509 | |
|
506 | 510 | void tst_QBarCategoriesAxis::min() |
|
507 | 511 | { |
|
508 | 512 | m_chart->setAxisX(m_baraxis, m_series); |
|
509 | 513 | m_view->show(); |
|
510 | 514 | QTest::qWaitForWindowShown(m_view); |
|
511 | 515 | min_raw(); |
|
512 | 516 | } |
|
513 | 517 | |
|
514 | 518 | void tst_QBarCategoriesAxis::min_animation_data() |
|
515 | 519 | { |
|
516 | 520 | min_data(); |
|
517 | 521 | } |
|
518 | 522 | |
|
519 | 523 | void tst_QBarCategoriesAxis::min_animation() |
|
520 | 524 | { |
|
521 | 525 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
522 | 526 | min(); |
|
523 | 527 | } |
|
524 | 528 | |
|
525 | 529 | |
|
526 | 530 | void tst_QBarCategoriesAxis::range_raw_data() |
|
527 | 531 | { |
|
528 | 532 | //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
529 | 533 | QTest::addColumn<QString>("min"); |
|
530 | 534 | QTest::addColumn<QString>("max"); |
|
531 | 535 | QTest::newRow("Feb - Apr") << "Feb" << "Apr"; |
|
532 | 536 | QTest::newRow("Feb - May") << "Feb" << "May"; |
|
533 | 537 | QTest::newRow("Mar - Apr") << "Mar" << "Apr"; |
|
534 | 538 | } |
|
535 | 539 | |
|
536 | 540 | void tst_QBarCategoriesAxis::range_raw() |
|
537 | 541 | { |
|
538 | 542 | QFETCH(QString, min); |
|
539 | 543 | QFETCH(QString, max); |
|
540 | 544 | |
|
541 | 545 | QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged())); |
|
542 | 546 | QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&))); |
|
543 | 547 | QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&))); |
|
544 | 548 | QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
545 | 549 | |
|
546 | 550 | m_baraxis->setRange(min, max); |
|
547 | 551 | QCOMPARE(m_baraxis->min(), min); |
|
548 | 552 | QCOMPARE(m_baraxis->max(), max); |
|
549 | 553 | |
|
550 | 554 | QCOMPARE(spy0.count(), 0); |
|
551 | 555 | QCOMPARE(spy1.count(), 1); |
|
552 | 556 | QCOMPARE(spy2.count(), 1); |
|
553 | 557 | QCOMPARE(spy3.count(), 1); |
|
554 | 558 | } |
|
555 | 559 | |
|
556 | 560 | void tst_QBarCategoriesAxis::range_data() |
|
557 | 561 | { |
|
558 | 562 | range_raw_data(); |
|
559 | 563 | } |
|
560 | 564 | |
|
561 | 565 | void tst_QBarCategoriesAxis::range() |
|
562 | 566 | { |
|
563 | 567 | m_chart->setAxisX(m_baraxis, m_series); |
|
564 | 568 | m_view->show(); |
|
565 | 569 | QTest::qWaitForWindowShown(m_view); |
|
566 | 570 | range_raw(); |
|
567 | 571 | } |
|
568 | 572 | |
|
569 | 573 | void tst_QBarCategoriesAxis::range_animation_data() |
|
570 | 574 | { |
|
571 | 575 | range_data(); |
|
572 | 576 | } |
|
573 | 577 | |
|
574 | 578 | void tst_QBarCategoriesAxis::range_animation() |
|
575 | 579 | { |
|
576 | 580 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
577 | 581 | range(); |
|
578 | 582 | } |
|
579 | 583 | |
|
584 | ||
|
585 | void tst_QBarCategoriesAxis::noautoscale_data() | |
|
586 | { | |
|
587 | QTest::addColumn<QString>("min"); | |
|
588 | QTest::addColumn<QString>("max"); | |
|
589 | QTest::newRow("Feb - Mar") << "Feb" << "Mar"; | |
|
590 | QTest::newRow("Feb - May") << "Feb" << "May"; | |
|
591 | QTest::newRow("Apr - May") << "Apr" << "May"; | |
|
592 | } | |
|
593 | ||
|
594 | void tst_QBarCategoriesAxis::noautoscale() | |
|
595 | { | |
|
596 | QFETCH(QString, min); | |
|
597 | QFETCH(QString, max); | |
|
598 | ||
|
599 | QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString))); | |
|
600 | QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString))); | |
|
601 | QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString, QString))); | |
|
602 | ||
|
603 | m_baraxis->setRange(min, max); | |
|
604 | QCOMPARE(m_baraxis->min(),min); | |
|
605 | QCOMPARE(m_baraxis->max(),max); | |
|
606 | ||
|
607 | QCOMPARE(spy0.count(), 1); | |
|
608 | QCOMPARE(spy1.count(), 1); | |
|
609 | QCOMPARE(spy2.count(), 1); | |
|
610 | ||
|
611 | m_chart->setAxisX(m_baraxis, m_series); | |
|
612 | m_view->show(); | |
|
613 | QTest::qWaitForWindowShown(m_view); | |
|
614 | QCOMPARE(m_baraxis->min(),min); | |
|
615 | QCOMPARE(m_baraxis->max(),max); | |
|
616 | } | |
|
617 | ||
|
618 | void tst_QBarCategoriesAxis::autoscale_data() | |
|
619 | { | |
|
620 | ||
|
621 | } | |
|
622 | ||
|
623 | void tst_QBarCategoriesAxis::autoscale() | |
|
624 | { | |
|
625 | delete m_baraxis; | |
|
626 | m_baraxis = new QBarCategoriesAxis(); | |
|
627 | ||
|
628 | QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString))); | |
|
629 | QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString))); | |
|
630 | QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString, QString))); | |
|
631 | ||
|
632 | QCOMPARE(m_baraxis->min(),QString()); | |
|
633 | QCOMPARE(m_baraxis->max(),QString()); | |
|
634 | m_chart->setAxisX(m_baraxis, m_series); | |
|
635 | ||
|
636 | QCOMPARE(spy0.count(), 1); | |
|
637 | QCOMPARE(spy1.count(), 1); | |
|
638 | QCOMPARE(spy2.count(), 1); | |
|
639 | ||
|
640 | m_view->show(); | |
|
641 | QTest::qWaitForWindowShown(m_view); | |
|
642 | QCOMPARE(m_baraxis->min(),QString("1")); | |
|
643 | QCOMPARE(m_baraxis->max(),QString("6")); | |
|
644 | } | |
|
645 | ||
|
646 | ||
|
580 | 647 | QTEST_MAIN(tst_QBarCategoriesAxis) |
|
581 | 648 | #include "tst_qbarcategoriesaxis.moc" |
|
582 | 649 |
General Comments 0
You need to be logged in to leave comments.
Login now