1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#include "../qabstractaxis/tst_qabstractaxis.h"
31#include <QtCharts/QBarSeries>
32#include <QtCharts/QBarSet>
33#include <QtCharts/QBarCategoryAxis>
34
35class tst_QBarCategoriesAxis: public tst_QAbstractAxis
36{
37Q_OBJECT
38
39public slots:
40 void init();
41 void cleanup() override;
42
43private slots:
44 void qbarcategoryaxis_data();
45 void qbarcategoryaxis();
46
47 void append2_data();
48 void append2();
49 void append_data();
50 void append();
51 void at_data();
52 void at();
53 void categories_data();
54 void categories();
55 void clear_data();
56 void clear();
57 void count_data();
58 void count();
59 void insert_data();
60 void insert();
61 void remove_data();
62 void remove();
63 void max_raw_data();
64 void max_raw();
65 void max_data();
66 void max();
67 void max_animation_data();
68 void max_animation();
69 void min_raw_data();
70 void min_raw();
71 void min_data();
72 void min();
73 void min_animation_data();
74 void min_animation();
75 void range_raw_data();
76 void range_raw();
77 void range_data();
78 void range();
79 void range_animation_data();
80 void range_animation();
81 void noautoscale_data();
82 void noautoscale();
83 void autoscale_data();
84 void autoscale();
85
86private:
87 QBarCategoryAxis* m_baraxis;
88 QBarSeries* m_series;
89};
90
91void tst_QBarCategoriesAxis::init()
92{
93 m_baraxis = new QBarCategoryAxis();
94 m_series = new QBarSeries();
95
96 QBarSet *set0 = new QBarSet("Jane");
97 QBarSet *set1 = new QBarSet("John");
98 QBarSet *set2 = new QBarSet("Axel");
99 QBarSet *set3 = new QBarSet("Mary");
100 QBarSet *set4 = new QBarSet("Samantha");
101
102 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
103 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
104 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
105 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
106 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
107
108 m_series->append(set: set0);
109 m_series->append(set: set1);
110 m_series->append(set: set2);
111 m_series->append(set: set3);
112 m_series->append(set: set4);
113
114 QStringList categories;
115 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
116
117 foreach(QString category, categories)
118 m_baraxis->append(category);
119
120 tst_QAbstractAxis::initAxes(axis: m_baraxis, series: m_series);
121 m_chart->addSeries(series: m_series);
122 m_chart->createDefaultAxes();
123}
124
125void tst_QBarCategoriesAxis::cleanup()
126{
127 delete m_series;
128 delete m_baraxis;
129 m_series = 0;
130 m_baraxis = 0;
131 tst_QAbstractAxis::cleanup();
132}
133
134void tst_QBarCategoriesAxis::qbarcategoryaxis_data()
135{
136}
137
138void tst_QBarCategoriesAxis::qbarcategoryaxis()
139{
140 qabstractaxis();
141 QBarCategoryAxis axis;
142 axis.append(categories: QStringList());
143 axis.append(category: QString());
144 QCOMPARE(axis.count(), 0);
145 QStringList test;
146 QCOMPARE(axis.categories(),test);
147 axis.clear();
148 QCOMPARE(axis.count(), 0);
149 axis.insert(index: -1, category: QString());
150 QCOMPARE(axis.max(), QString());
151 QCOMPARE(axis.min(), QString());
152 axis.remove(category: QString());
153 axis.setCategories(QStringList());
154 axis.setMax(QString());
155 axis.setMin(QString());
156 axis.setRange(minCategory: QString(), maxCategory: QString());
157 QCOMPARE(axis.type(), QAbstractAxis::AxisTypeBarCategory);
158}
159
160void tst_QBarCategoriesAxis::append_data()
161{
162 QTest::addColumn<QStringList>(name: "categories");
163 QTest::newRow(dataTag: "Jan Feb Mar Apr") << (QStringList() << "Jan" << "Feb" << "Mar" << "Apr");
164 QTest::newRow(dataTag: "Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
165}
166
167void tst_QBarCategoriesAxis::append()
168{
169 QFETCH(QStringList, categories);
170
171 QBarCategoryAxis axis;
172
173 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
174 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
175 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
176 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
177 QSignalSpy spy4(&axis, SIGNAL(countChanged()));
178
179 axis.append(categories);
180
181 QCOMPARE(spy0.count(), 1);
182 QCOMPARE(spy1.count(), 1);
183 QCOMPARE(spy2.count(), 1);
184 QCOMPARE(spy3.count(), 1);
185
186 m_chart->addAxis(axis: &axis, alignment: Qt::AlignBottom);
187 m_series->attachAxis(axis: &axis);
188 m_view->show();
189 QVERIFY(QTest::qWaitForWindowExposed(m_view));
190 QCOMPARE(axis.categories(), categories);
191
192 QCOMPARE(spy0.count(), 1);
193 QCOMPARE(spy1.count(), 1);
194 QCOMPARE(spy2.count(), 1);
195 QCOMPARE(spy3.count(), 1);
196 QCOMPARE(spy4.count(), 1);
197}
198
199void tst_QBarCategoriesAxis::append2_data()
200{
201 QTest::addColumn<QStringList>(name: "categories");
202 QTest::newRow(dataTag: "Jan Feb Mar Apr") << (QStringList() << "Jan" << "Feb" << "Mar" << "Apr");
203 QTest::newRow(dataTag: "Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
204}
205
206void tst_QBarCategoriesAxis::append2()
207{
208 QFETCH(QStringList, categories);
209
210 QBarCategoryAxis axis;
211
212 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
213 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
214 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
215 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
216 QSignalSpy spy4(&axis, SIGNAL(countChanged()));
217
218 foreach(QString category, categories)
219 axis.append(category);
220
221 QCOMPARE(spy0.count(), categories.count());
222 QCOMPARE(spy1.count(), categories.count());
223 QCOMPARE(spy2.count(), 1);
224 QCOMPARE(spy3.count(), categories.count());
225
226 m_chart->addAxis(axis: &axis, alignment: Qt::AlignBottom);
227 m_series->attachAxis(axis: &axis);
228 m_view->show();
229 QVERIFY(QTest::qWaitForWindowExposed(m_view));
230 QCOMPARE(axis.categories(), categories);
231
232 QCOMPARE(spy0.count(), categories.count());
233 QCOMPARE(spy1.count(), categories.count());
234 QCOMPARE(spy2.count(), 1);
235 QCOMPARE(spy3.count(), categories.count());
236 QCOMPARE(spy4.count(), categories.count());
237}
238
239void tst_QBarCategoriesAxis::at_data()
240{
241 QTest::addColumn<QStringList>(name: "categories");
242 QTest::addColumn<int>(name: "index");
243 QTest::addColumn<QString>(name: "string");
244 QTest::newRow(dataTag: "Jul Aug Sep 0 Jul") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jul";
245 QTest::newRow(dataTag: "Jul Aug Sep 2 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Sep";
246 QTest::newRow(dataTag: "Jul Aug Sep 1 Aug") << (QStringList() << "Jul" << "Aug" << "Sep") << 1 << "Aug";
247}
248
249void tst_QBarCategoriesAxis::at()
250{
251 QFETCH(int, index);
252 QFETCH(QString, string);
253 QFETCH(QStringList, categories);
254
255 QBarCategoryAxis axis;
256 axis.append(categories);
257
258 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
259 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
260 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
261 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
262 QSignalSpy spy4(&axis, SIGNAL(countChanged()));
263
264 QCOMPARE(axis.at(index), string);
265
266 QCOMPARE(spy0.count(), 0);
267 QCOMPARE(spy1.count(), 0);
268 QCOMPARE(spy2.count(), 0);
269 QCOMPARE(spy3.count(), 0);
270
271 m_chart->addAxis(axis: &axis, alignment: Qt::AlignBottom);
272 m_series->attachAxis(axis: &axis);
273 m_view->show();
274 QVERIFY(QTest::qWaitForWindowExposed(m_view));
275 QCOMPARE(axis.at(index), string);
276
277 QCOMPARE(spy0.count(), 0);
278 QCOMPARE(spy1.count(), 0);
279 QCOMPARE(spy2.count(), 0);
280 QCOMPARE(spy3.count(), 0);
281 QCOMPARE(spy4.count(), 0);
282}
283
284void tst_QBarCategoriesAxis::categories_data()
285{
286 QTest::addColumn<QStringList>(name: "categories");
287 QTest::newRow(dataTag: "Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
288}
289
290void tst_QBarCategoriesAxis::categories()
291{
292 QFETCH(QStringList, categories);
293
294 QBarCategoryAxis axis;
295
296 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
297 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
298 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
299 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
300 QSignalSpy spy4(&axis, SIGNAL(countChanged()));
301
302 axis.setCategories(categories);
303 QCOMPARE(axis.categories(), categories);
304
305 QCOMPARE(spy0.count(), 1);
306 QCOMPARE(spy1.count(), 1);
307 QCOMPARE(spy2.count(), 1);
308 QCOMPARE(spy3.count(), 1);
309
310 m_chart->addAxis(axis: &axis, alignment: Qt::AlignBottom);
311 m_series->attachAxis(axis: &axis);
312 m_view->show();
313 QVERIFY(QTest::qWaitForWindowExposed(m_view));
314 QCOMPARE(axis.categories(), categories);
315
316 QCOMPARE(spy0.count(), 1);
317 QCOMPARE(spy1.count(), 1);
318 QCOMPARE(spy2.count(), 1);
319 QCOMPARE(spy3.count(), 1);
320 QCOMPARE(spy4.count(), 1);
321}
322
323void tst_QBarCategoriesAxis::clear_data()
324{
325 QTest::addColumn<QStringList>(name: "categories");
326 QTest::newRow(dataTag: "Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep");
327}
328
329void tst_QBarCategoriesAxis::clear()
330{
331 QFETCH(QStringList, categories);
332
333 QBarCategoryAxis axis;
334
335 axis.setCategories(categories);
336 QCOMPARE(axis.categories(), categories);
337
338 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
339 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
340 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
341 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
342 QSignalSpy spy4(&axis, SIGNAL(countChanged()));
343
344 axis.clear();
345 QCOMPARE(axis.categories(), QStringList());
346
347 QCOMPARE(spy0.count(), 1);
348 QCOMPARE(spy1.count(), 1);
349 QCOMPARE(spy2.count(), 1);
350 QCOMPARE(spy3.count(), 1);
351
352 m_chart->addAxis(axis: &axis, alignment: Qt::AlignBottom);
353 m_series->attachAxis(axis: &axis);
354 m_view->show();
355 QVERIFY(QTest::qWaitForWindowExposed(m_view));
356
357 QCOMPARE(spy0.count(), 2);
358 QCOMPARE(spy1.count(), 2);
359 QCOMPARE(spy2.count(), 2);
360 QCOMPARE(spy3.count(), 2);
361
362 axis.clear();
363 QCOMPARE(axis.categories().count(),0);
364 QCOMPARE(spy0.count(), 3);
365 QCOMPARE(spy1.count(), 3);
366 QCOMPARE(spy2.count(), 3);
367 QCOMPARE(spy3.count(), 3);
368 QCOMPARE(spy4.count(), 3);
369}
370
371void tst_QBarCategoriesAxis::count_data()
372{
373 QTest::addColumn<QStringList>(name: "categories");
374 QTest::addColumn<int>(name: "count");
375 QTest::newRow(dataTag: "Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3;
376 QTest::newRow(dataTag: "Jul Aug ") << (QStringList() << "Jul" << "Aug") << 2;
377}
378
379void tst_QBarCategoriesAxis::count()
380{
381 QFETCH(QStringList, categories);
382 QFETCH(int, count);
383
384 QBarCategoryAxis axis;
385 axis.setCategories(categories);
386
387 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
388 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
389 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
390 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
391 QSignalSpy spy4(&axis, SIGNAL(countChanged()));
392
393 QCOMPARE(axis.count(), count);
394
395 QCOMPARE(spy0.count(), 0);
396 QCOMPARE(spy1.count(), 0);
397 QCOMPARE(spy2.count(), 0);
398 QCOMPARE(spy3.count(), 0);
399 QCOMPARE(spy4.count(), 0);
400
401 m_chart->addAxis(axis: &axis, alignment: Qt::AlignBottom);
402 m_series->attachAxis(axis: &axis);
403 m_view->show();
404 QVERIFY(QTest::qWaitForWindowExposed(m_view));
405 QCOMPARE(axis.count(), count);
406}
407
408void tst_QBarCategoriesAxis::insert_data()
409{
410 QTest::addColumn<QStringList>(name: "categories");
411 QTest::addColumn<int>(name: "index");
412 QTest::addColumn<QString>(name: "category");
413 QTest::newRow(dataTag: "Jul Aug Sep 0 Jun") << (QStringList() << "Jul" << "Aug" << "Sep") << 1 << "Jun";
414 QTest::newRow(dataTag: "Jul Aug Sep 2 Summer") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Summer";
415}
416
417void tst_QBarCategoriesAxis::insert()
418{
419 QFETCH(QStringList, categories);
420 QFETCH(int, index);
421 QFETCH(QString, category);
422
423 QBarCategoryAxis axis;
424 axis.append(categories);
425
426 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
427 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
428 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
429 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
430 QSignalSpy spy4(&axis, SIGNAL(countChanged()));
431
432 axis.insert(index, category);
433 QCOMPARE(axis.at(index),category);
434
435 QCOMPARE(spy0.count(), 1);
436 QCOMPARE(spy1.count(), 0);
437 QCOMPARE(spy2.count(), 0);
438 QCOMPARE(spy3.count(), 0);
439 QCOMPARE(spy4.count(), 1);
440
441 m_chart->addAxis(axis: &axis, alignment: Qt::AlignBottom);
442 m_series->attachAxis(axis: &axis);
443 m_view->show();
444 QVERIFY(QTest::qWaitForWindowExposed(m_view));
445}
446
447void tst_QBarCategoriesAxis::remove_data()
448{
449 QTest::addColumn<QStringList>(name: "categories");
450 QTest::addColumn<QString>(name: "category");
451 QTest::addColumn<QStringList>(name: "result");
452 QTest::newRow(dataTag: "Jul Aug Sep 0") << (QStringList() << "Jul" << "Aug" << "Sep") << "Jul" << (QStringList() << "Aug" << "Sep");
453 QTest::newRow(dataTag: "Jul Aug Sep 1") << (QStringList() << "Jul" << "Aug" << "Sep") << "Aug"<< (QStringList() << "Jul" << "Sep");
454}
455
456void tst_QBarCategoriesAxis::remove()
457{
458 QFETCH(QStringList, categories);
459 QFETCH(QString, category);
460 QFETCH(QStringList, result);
461
462 QBarCategoryAxis axis;
463 axis.append(categories);
464
465 int maxCount = axis.max() == category;
466 int minCount = axis.min() == category;
467 int rangeCount = maxCount + minCount;
468
469 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
470 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString)));
471 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString)));
472 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString)));
473 QSignalSpy spy4(&axis, SIGNAL(countChanged()));
474
475 axis.remove(category);
476 QCOMPARE(axis.categories(),result);
477
478 QCOMPARE(spy0.count(), 1);
479 QCOMPARE(spy1.count(), maxCount);
480 QCOMPARE(spy2.count(), minCount);
481 QCOMPARE(spy3.count(), rangeCount);
482 QCOMPARE(spy4.count(), 1);
483}
484
485void tst_QBarCategoriesAxis::max_raw_data()
486{
487 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
488 QTest::addColumn<QString>(name: "max");
489 QTest::newRow(dataTag: "Feb") << "Feb";
490 QTest::newRow(dataTag: "Apr") << "Apr";
491 QTest::newRow(dataTag: "May") << "May";
492}
493
494void tst_QBarCategoriesAxis::max_raw()
495{
496 QFETCH(QString, max);
497
498 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
499 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString)));
500 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString)));
501 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
502 QSignalSpy spy4(m_baraxis, SIGNAL(countChanged()));
503
504 m_baraxis->setMax(max);
505 QCOMPARE(m_baraxis->max(), max);
506
507 QCOMPARE(spy0.count(), 0);
508 QCOMPARE(spy1.count(), 1);
509 QCOMPARE(spy2.count(), 0);
510 QCOMPARE(spy3.count(), 1);
511 QCOMPARE(spy4.count(), 0);
512}
513
514void tst_QBarCategoriesAxis::max_data()
515{
516 max_raw_data();
517}
518
519void tst_QBarCategoriesAxis::max()
520{
521 m_chart->addAxis(axis: m_baraxis, alignment: Qt::AlignBottom);
522 m_series->attachAxis(axis: m_baraxis);
523 m_view->show();
524 QVERIFY(QTest::qWaitForWindowExposed(m_view));
525 max_raw();
526}
527
528void tst_QBarCategoriesAxis::max_animation_data()
529{
530 max_data();
531}
532
533void tst_QBarCategoriesAxis::max_animation()
534{
535 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
536 max();
537}
538
539void tst_QBarCategoriesAxis::min_raw_data()
540{
541 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
542 QTest::addColumn<QString>(name: "min");
543 QTest::newRow(dataTag: "Feb") << "Feb";
544 QTest::newRow(dataTag: "Apr") << "Apr";
545 QTest::newRow(dataTag: "May") << "May";
546}
547
548void tst_QBarCategoriesAxis::min_raw()
549{
550 QFETCH(QString, min);
551
552 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
553 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString)));
554 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString)));
555 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
556 QSignalSpy spy4(m_baraxis, SIGNAL(countChanged()));
557
558 m_baraxis->setMin(min);
559 QCOMPARE(m_baraxis->min(), min);
560
561 QCOMPARE(spy0.count(), 0);
562 QCOMPARE(spy1.count(), 0);
563 QCOMPARE(spy2.count(), 1);
564 QCOMPARE(spy3.count(), 1);
565 QCOMPARE(spy4.count(), 0);
566}
567
568void tst_QBarCategoriesAxis::min_data()
569{
570 min_raw_data();
571}
572
573void tst_QBarCategoriesAxis::min()
574{
575 min_raw();
576 m_chart->addAxis(axis: m_baraxis, alignment: Qt::AlignBottom);
577 m_series->attachAxis(axis: m_baraxis);
578 m_view->show();
579 QVERIFY(QTest::qWaitForWindowExposed(m_view));
580
581}
582
583void tst_QBarCategoriesAxis::min_animation_data()
584{
585 min_data();
586}
587
588void tst_QBarCategoriesAxis::min_animation()
589{
590 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
591 min();
592}
593
594
595void tst_QBarCategoriesAxis::range_raw_data()
596{
597 //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
598 QTest::addColumn<QString>(name: "min");
599 QTest::addColumn<QString>(name: "max");
600 QTest::newRow(dataTag: "Feb - Apr") << "Feb" << "Apr";
601 QTest::newRow(dataTag: "Feb - May") << "Feb" << "May";
602 QTest::newRow(dataTag: "Mar - Apr") << "Mar" << "Apr";
603}
604
605void tst_QBarCategoriesAxis::range_raw()
606{
607 QFETCH(QString, min);
608 QFETCH(QString, max);
609
610 QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged()));
611 QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString)));
612 QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString)));
613 QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
614 QSignalSpy spy4(m_baraxis, SIGNAL(countChanged()));
615
616 m_baraxis->setRange(minCategory: min, maxCategory: max);
617 QCOMPARE(m_baraxis->min(), min);
618 QCOMPARE(m_baraxis->max(), max);
619
620 QCOMPARE(spy0.count(), 0);
621 QCOMPARE(spy1.count(), 1);
622 QCOMPARE(spy2.count(), 1);
623 QCOMPARE(spy3.count(), 1);
624 QCOMPARE(spy4.count(), 0);
625}
626
627void tst_QBarCategoriesAxis::range_data()
628{
629 range_raw_data();
630}
631
632void tst_QBarCategoriesAxis::range()
633{
634 range_raw();
635 m_chart->addAxis(axis: m_baraxis, alignment: Qt::AlignBottom);
636 m_series->attachAxis(axis: m_baraxis);
637 m_view->show();
638 QVERIFY(QTest::qWaitForWindowExposed(m_view));
639
640}
641
642void tst_QBarCategoriesAxis::range_animation_data()
643{
644 range_data();
645}
646
647void tst_QBarCategoriesAxis::range_animation()
648{
649 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
650 range();
651}
652
653
654void tst_QBarCategoriesAxis::noautoscale_data()
655{
656 QTest::addColumn<QString>(name: "min");
657 QTest::addColumn<QString>(name: "max");
658 QTest::newRow(dataTag: "Feb - Mar") << "Feb" << "Mar";
659 QTest::newRow(dataTag: "Feb - May") << "Feb" << "May";
660 QTest::newRow(dataTag: "Apr - May") << "Apr" << "May";
661}
662
663void tst_QBarCategoriesAxis::noautoscale()
664{
665 QFETCH(QString, min);
666 QFETCH(QString, max);
667
668 QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString)));
669 QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString)));
670 QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
671
672 m_baraxis->setRange(minCategory: min, maxCategory: max);
673 QCOMPARE(m_baraxis->min(),min);
674 QCOMPARE(m_baraxis->max(),max);
675
676 QCOMPARE(spy0.count(), 1);
677 QCOMPARE(spy1.count(), 1);
678 QCOMPARE(spy2.count(), 1);
679
680 m_chart->addAxis(axis: m_baraxis, alignment: Qt::AlignBottom);
681 m_series->attachAxis(axis: m_baraxis);
682 m_view->show();
683 QVERIFY(QTest::qWaitForWindowExposed(m_view));
684 QCOMPARE(m_baraxis->min(),min);
685 QCOMPARE(m_baraxis->max(),max);
686}
687
688void tst_QBarCategoriesAxis::autoscale_data()
689{
690
691}
692
693void tst_QBarCategoriesAxis::autoscale()
694{
695 delete m_baraxis;
696 m_baraxis = new QBarCategoryAxis();
697
698 QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString)));
699 QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString)));
700 QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString,QString)));
701
702 QCOMPARE(m_baraxis->min(),QString());
703 QCOMPARE(m_baraxis->max(),QString());
704 m_chart->addAxis(axis: m_baraxis, alignment: Qt::AlignBottom);
705 m_series->attachAxis(axis: m_baraxis);
706
707 QCOMPARE(spy0.count(), 1);
708 QCOMPARE(spy1.count(), 1);
709 QCOMPARE(spy2.count(), 1);
710
711 m_view->show();
712 QVERIFY(QTest::qWaitForWindowExposed(m_view));
713 QCOMPARE(m_baraxis->min(),QString("1"));
714 QCOMPARE(m_baraxis->max(),QString("6"));
715}
716
717
718QTEST_MAIN(tst_QBarCategoriesAxis)
719#include "tst_qbarcategoryaxis.moc"
720
721

source code of qtcharts/tests/auto/qbarcategoryaxis/tst_qbarcategoryaxis.cpp