##// END OF EJS Templates
Implements qbarcategoriesaxis logic...
Michal Klocek -
r1725:251205c7e45d
parent child
Show More
@@ -0,0 +1,5
1 !include( ../auto.pri ) {
2 error( "Couldn't find the auto.pri file!" )
3 }
4 HEADERS += ../qabstractaxis/tst_qabstractaxis.h
5 SOURCES += tst_qbarcategoriesaxis.cpp ../qabstractaxis/tst_qabstractaxis.cpp
This diff has been collapsed as it changes many lines, (702 lines changed) Show them Hide them
@@ -0,0 +1,702
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "../qabstractaxis/tst_qabstractaxis.h"
22 #include <qbarseries.h>
23 #include <qbarset.h>
24 #include <qbarcategoriesaxis.h>
25
26 class tst_QBarCategoriesAxis: public tst_QAbstractAxis
27 {
28 Q_OBJECT
29
30 public slots:
31 void initTestCase();
32 void cleanupTestCase();
33 void init();
34 void cleanup();
35
36 private slots:
37 void qbarcategoriesaxis_data();
38 void qbarcategoriesaxis();
39
40 void append_data();
41 void append();
42 void at_data();
43 void at();
44 void categories_data();
45 void categories();
46 void clear_data();
47 void clear();
48 void count_data();
49 void count();
50 void insert_data();
51 void insert();
52 void max_data();
53 void max();
54 void min_data();
55 void min();
56 void remove_data();
57 void remove();
58 void setCategories_data();
59 void setCategories();
60 void setMax_data();
61 void setMax();
62 void setMin_data();
63 void setMin();
64 void setRange_data();
65 void setRange();
66 void type_data();
67 void type();
68 void categoriesChanged_data();
69 void categoriesChanged();
70 void maxChanged_data();
71 void maxChanged();
72 void minChanged_data();
73 void minChanged();
74 void rangeChanged_data();
75 void rangeChanged();
76 private:
77 QBarCategoriesAxis* m_baraxis;
78 QBarSeries* m_series;
79 };
80
81 void tst_QBarCategoriesAxis::initTestCase()
82 {
83 }
84
85 void tst_QBarCategoriesAxis::cleanupTestCase()
86 {
87 }
88
89 void tst_QBarCategoriesAxis::init()
90 {
91 m_baraxis = new QBarCategoriesAxis();
92 m_series = new QBarSeries();
93
94 QBarSet *set0 = new QBarSet("Jane");
95 QBarSet *set1 = new QBarSet("John");
96 QBarSet *set2 = new QBarSet("Axel");
97 QBarSet *set3 = new QBarSet("Mary");
98 QBarSet *set4 = new QBarSet("Samantha");
99
100 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
101 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
102 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
103 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
104 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
105
106 m_series->append(set0);
107 m_series->append(set1);
108 m_series->append(set2);
109 m_series->append(set3);
110 m_series->append(set4);
111
112 QStringList categories;
113 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
114
115 m_baraxis->append(categories);
116
117 tst_QAbstractAxis::init(m_baraxis, m_series);
118 m_chart->addSeries(m_series);
119 m_chart->createDefaultAxes();
120 }
121
122 void tst_QBarCategoriesAxis::cleanup()
123 {
124 delete m_series;
125 delete m_baraxis;
126 m_series = 0;
127 m_baraxis = 0;
128 tst_QAbstractAxis::cleanup();
129 }
130
131 void tst_QBarCategoriesAxis::qbarcategoriesaxis_data()
132 {
133 }
134
135 void tst_QBarCategoriesAxis::qbarcategoriesaxis()
136 {
137 qabstractaxis();
138 QBarCategoriesAxis axis;
139 axis.append(QStringList());
140 axis.append(QString());
141 QCOMPARE(axis.at(0), QString());
142 QStringList test;
143 test.append(QString());
144 QCOMPARE(axis.categories(),test);
145 axis.clear();
146 QCOMPARE(axis.count(), 0);
147 axis.insert(-1, QString());
148 QCOMPARE(axis.max(), QString());
149 QCOMPARE(axis.min(), QString());
150 axis.remove(QString());
151 axis.setCategories(QStringList());
152 axis.setMax(QString());
153 axis.setMin(QString());
154 axis.setRange(QString(), QString());
155 QCOMPARE(axis.type(), QAbstractAxis::AxisTypeCategories);
156 }
157
158 void tst_QBarCategoriesAxis::append_data()
159 {
160 QTest::addColumn<QStringList>("categories");
161 QTest::newRow("null") << QStringList();
162 }
163
164 // public void append(QStringList const& categories)
165 void tst_QBarCategoriesAxis::append()
166 {
167 #if 0
168 QFETCH(QStringList, categories);
169
170 SubQBarCategoriesAxis axis;
171
172 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
173 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
174 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
175 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
176
177 axis.append(categories);
178
179 QCOMPARE(spy0.count(), 0);
180 QCOMPARE(spy1.count(), 0);
181 QCOMPARE(spy2.count(), 0);
182 QCOMPARE(spy3.count(), 0);
183 #endif
184 QSKIP("Test is not implemented.", SkipAll);
185 }
186
187 void tst_QBarCategoriesAxis::at_data()
188 {
189 QTest::addColumn<int>("index");
190 QTest::addColumn<QString>("at");
191 QTest::newRow("null") << 0 << QString();
192 }
193
194 // public QString at(int index) const
195 void tst_QBarCategoriesAxis::at()
196 {
197 #if 0
198 QFETCH(int, index);
199 QFETCH(QString, at);
200
201 SubQBarCategoriesAxis axis;
202
203 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
204 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
205 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
206 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
207
208 QCOMPARE(axis.at(index), at);
209
210 QCOMPARE(spy0.count(), 0);
211 QCOMPARE(spy1.count(), 0);
212 QCOMPARE(spy2.count(), 0);
213 QCOMPARE(spy3.count(), 0);
214 #endif
215 QSKIP("Test is not implemented.", SkipAll);
216 }
217
218 void tst_QBarCategoriesAxis::categories_data()
219 {
220 QTest::addColumn<QStringList>("categories");
221 QTest::newRow("null") << QStringList();
222 }
223
224 // public QStringList categories()
225 void tst_QBarCategoriesAxis::categories()
226 {
227 #if 0
228 QFETCH(QStringList, categories);
229
230 SubQBarCategoriesAxis axis;
231
232 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
233 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
234 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
235 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
236
237 QCOMPARE(axis.categories(), categories);
238
239 QCOMPARE(spy0.count(), 0);
240 QCOMPARE(spy1.count(), 0);
241 QCOMPARE(spy2.count(), 0);
242 QCOMPARE(spy3.count(), 0);
243 #endif
244 QSKIP("Test is not implemented.", SkipAll);
245 }
246
247 void tst_QBarCategoriesAxis::clear_data()
248 {
249 QTest::addColumn<int>("foo");
250 QTest::newRow("0") << 0;
251 QTest::newRow("-1") << -1;
252 }
253
254 // public void clear()
255 void tst_QBarCategoriesAxis::clear()
256 {
257 #if 0
258 QFETCH(int, foo);
259
260 SubQBarCategoriesAxis axis;
261
262 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
263 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
264 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
265 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
266
267 axis.clear();
268
269 QCOMPARE(spy0.count(), 0);
270 QCOMPARE(spy1.count(), 0);
271 QCOMPARE(spy2.count(), 0);
272 QCOMPARE(spy3.count(), 0);
273 #endif
274 QSKIP("Test is not implemented.", SkipAll);
275 }
276
277 void tst_QBarCategoriesAxis::count_data()
278 {
279 QTest::addColumn<int>("count");
280 QTest::newRow("0") << 0;
281 QTest::newRow("-1") << -1;
282 }
283
284 // public int count() const
285 void tst_QBarCategoriesAxis::count()
286 {
287 #if 0
288 QFETCH(int, count);
289
290 SubQBarCategoriesAxis axis;
291
292 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
293 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
294 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
295 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
296
297 QCOMPARE(axis.count(), count);
298
299 QCOMPARE(spy0.count(), 0);
300 QCOMPARE(spy1.count(), 0);
301 QCOMPARE(spy2.count(), 0);
302 QCOMPARE(spy3.count(), 0);
303 #endif
304 QSKIP("Test is not implemented.", SkipAll);
305 }
306
307 void tst_QBarCategoriesAxis::insert_data()
308 {
309 QTest::addColumn<int>("index");
310 QTest::addColumn<QString>("category");
311 QTest::newRow("null") << 0 << QString();
312 }
313
314 // public void insert(int index, QString const& category)
315 void tst_QBarCategoriesAxis::insert()
316 {
317 #if 0
318 QFETCH(int, index);
319 QFETCH(QString, category);
320
321 SubQBarCategoriesAxis axis;
322
323 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
324 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
325 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
326 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
327
328 axis.insert(index, category);
329
330 QCOMPARE(spy0.count(), 0);
331 QCOMPARE(spy1.count(), 0);
332 QCOMPARE(spy2.count(), 0);
333 QCOMPARE(spy3.count(), 0);
334 #endif
335 QSKIP("Test is not implemented.", SkipAll);
336 }
337
338 void tst_QBarCategoriesAxis::max_data()
339 {
340 QTest::addColumn<QString>("max");
341 QTest::newRow("null") << QString();
342 QTest::newRow("foo") << QString("foo");
343 }
344
345 // public QString max() const
346 void tst_QBarCategoriesAxis::max()
347 {
348 #if 0
349 QFETCH(QString, max);
350
351 SubQBarCategoriesAxis axis;
352
353 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
354 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
355 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
356 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
357
358 QCOMPARE(axis.max(), max);
359
360 QCOMPARE(spy0.count(), 0);
361 QCOMPARE(spy1.count(), 0);
362 QCOMPARE(spy2.count(), 0);
363 QCOMPARE(spy3.count(), 0);
364 #endif
365 QSKIP("Test is not implemented.", SkipAll);
366 }
367
368 void tst_QBarCategoriesAxis::min_data()
369 {
370 QTest::addColumn<QString>("min");
371 QTest::newRow("null") << QString();
372 QTest::newRow("foo") << QString("foo");
373 }
374
375 // public QString min() const
376 void tst_QBarCategoriesAxis::min()
377 {
378 #if 0
379 QFETCH(QString, min);
380
381 SubQBarCategoriesAxis axis;
382
383 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
384 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
385 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
386 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
387
388 QCOMPARE(axis.min(), min);
389
390 QCOMPARE(spy0.count(), 0);
391 QCOMPARE(spy1.count(), 0);
392 QCOMPARE(spy2.count(), 0);
393 QCOMPARE(spy3.count(), 0);
394 #endif
395 QSKIP("Test is not implemented.", SkipAll);
396 }
397
398 void tst_QBarCategoriesAxis::remove_data()
399 {
400 QTest::addColumn<QString>("category");
401 QTest::newRow("null") << QString();
402 QTest::newRow("foo") << QString("foo");
403 }
404
405 // public void remove(QString const& category)
406 void tst_QBarCategoriesAxis::remove()
407 {
408 #if 0
409 QFETCH(QString, category);
410
411 SubQBarCategoriesAxis axis;
412
413 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
414 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
415 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
416 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
417
418 axis.remove(category);
419
420 QCOMPARE(spy0.count(), 0);
421 QCOMPARE(spy1.count(), 0);
422 QCOMPARE(spy2.count(), 0);
423 QCOMPARE(spy3.count(), 0);
424 #endif
425 QSKIP("Test is not implemented.", SkipAll);
426 }
427
428 void tst_QBarCategoriesAxis::setCategories_data()
429 {
430 QTest::addColumn<QStringList>("categories");
431 QTest::newRow("null") << QStringList();
432 }
433
434 // public void setCategories(QStringList const& categories)
435 void tst_QBarCategoriesAxis::setCategories()
436 {
437 #if 0
438 QFETCH(QStringList, categories);
439
440 SubQBarCategoriesAxis axis;
441
442 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
443 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
444 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
445 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
446
447 axis.setCategories(categories);
448
449 QCOMPARE(spy0.count(), 0);
450 QCOMPARE(spy1.count(), 0);
451 QCOMPARE(spy2.count(), 0);
452 QCOMPARE(spy3.count(), 0);
453 #endif
454 QSKIP("Test is not implemented.", SkipAll);
455 }
456
457 void tst_QBarCategoriesAxis::setMax_data()
458 {
459 QTest::addColumn<QString>("maxCategory");
460 QTest::newRow("null") << QString();
461 QTest::newRow("foo") << QString("foo");
462 }
463
464 // public void setMax(QString const& maxCategory)
465 void tst_QBarCategoriesAxis::setMax()
466 {
467 #if 0
468 QFETCH(QString, maxCategory);
469
470 SubQBarCategoriesAxis axis;
471
472 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
473 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
474 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
475 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
476
477 axis.setMax(maxCategory);
478
479 QCOMPARE(spy0.count(), 0);
480 QCOMPARE(spy1.count(), 0);
481 QCOMPARE(spy2.count(), 0);
482 QCOMPARE(spy3.count(), 0);
483 #endif
484 QSKIP("Test is not implemented.", SkipAll);
485 }
486
487 void tst_QBarCategoriesAxis::setMin_data()
488 {
489 QTest::addColumn<QString>("minCategory");
490 QTest::newRow("null") << QString();
491 QTest::newRow("foo") << QString("foo");
492 }
493
494 // public void setMin(QString const& minCategory)
495 void tst_QBarCategoriesAxis::setMin()
496 {
497 #if 0
498 QFETCH(QString, minCategory);
499
500 SubQBarCategoriesAxis axis;
501
502 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
503 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
504 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
505 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
506
507 axis.setMin(minCategory);
508
509 QCOMPARE(spy0.count(), 0);
510 QCOMPARE(spy1.count(), 0);
511 QCOMPARE(spy2.count(), 0);
512 QCOMPARE(spy3.count(), 0);
513 #endif
514 QSKIP("Test is not implemented.", SkipAll);
515 }
516
517 void tst_QBarCategoriesAxis::setRange_data()
518 {
519 QTest::addColumn<QString>("minCategory");
520 QTest::addColumn<QString>("maxCategory");
521 QTest::newRow("null") << QString() << QString();
522 }
523
524 // public void setRange(QString const& minCategory, QString const& maxCategory)
525 void tst_QBarCategoriesAxis::setRange()
526 {
527 #if 0
528 QFETCH(QString, minCategory);
529 QFETCH(QString, maxCategory);
530
531 SubQBarCategoriesAxis axis;
532
533 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
534 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
535 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
536 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
537
538 axis.setRange(minCategory, maxCategory);
539
540 QCOMPARE(spy0.count(), 0);
541 QCOMPARE(spy1.count(), 0);
542 QCOMPARE(spy2.count(), 0);
543 QCOMPARE(spy3.count(), 0);
544 #endif
545 QSKIP("Test is not implemented.", SkipAll);
546 }
547
548 void tst_QBarCategoriesAxis::type_data()
549 {
550 #if 0
551 QTest::addColumn<AxisType>("type");
552 QTest::newRow("null") << AxisType();
553 #endif
554 }
555
556 // public AxisType type() const
557 void tst_QBarCategoriesAxis::type()
558 {
559 #if 0
560 QFETCH(AxisType, type);
561
562 SubQBarCategoriesAxis axis;
563
564 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
565 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
566 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
567 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
568
569 QCOMPARE(axis.type(), type);
570
571 QCOMPARE(spy0.count(), 0);
572 QCOMPARE(spy1.count(), 0);
573 QCOMPARE(spy2.count(), 0);
574 QCOMPARE(spy3.count(), 0);
575 #endif
576 QSKIP("Test is not implemented.", SkipAll);
577 }
578
579 void tst_QBarCategoriesAxis::categoriesChanged_data()
580 {
581 QTest::addColumn<int>("foo");
582 QTest::newRow("0") << 0;
583 QTest::newRow("-1") << -1;
584 }
585
586 // protected void categoriesChanged()
587 void tst_QBarCategoriesAxis::categoriesChanged()
588 {
589 #if 0
590 QFETCH(int, foo);
591
592 SubQBarCategoriesAxis axis;
593
594 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
595 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
596 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
597 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
598
599 axis.call_categoriesChanged();
600
601 QCOMPARE(spy0.count(), 0);
602 QCOMPARE(spy1.count(), 0);
603 QCOMPARE(spy2.count(), 0);
604 QCOMPARE(spy3.count(), 0);
605 #endif
606 QSKIP("Test is not implemented.", SkipAll);
607 }
608
609 void tst_QBarCategoriesAxis::maxChanged_data()
610 {
611 QTest::addColumn<QString>("max");
612 QTest::newRow("null") << QString();
613 QTest::newRow("foo") << QString("foo");
614 }
615
616 // protected void maxChanged(QString const& max)
617 void tst_QBarCategoriesAxis::maxChanged()
618 {
619 #if 0
620 QFETCH(QString, max);
621
622 SubQBarCategoriesAxis axis;
623
624 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
625 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
626 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
627 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
628
629 axis.call_maxChanged(max);
630
631 QCOMPARE(spy0.count(), 0);
632 QCOMPARE(spy1.count(), 0);
633 QCOMPARE(spy2.count(), 0);
634 QCOMPARE(spy3.count(), 0);
635 #endif
636 QSKIP("Test is not implemented.", SkipAll);
637 }
638
639 void tst_QBarCategoriesAxis::minChanged_data()
640 {
641 QTest::addColumn<QString>("min");
642 QTest::newRow("null") << QString();
643 QTest::newRow("foo") << QString("foo");
644 }
645
646 // protected void minChanged(QString const& min)
647 void tst_QBarCategoriesAxis::minChanged()
648 {
649 #if 0
650 QFETCH(QString, min);
651
652 SubQBarCategoriesAxis axis;
653
654 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
655 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
656 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
657 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
658
659 axis.call_minChanged(min);
660
661 QCOMPARE(spy0.count(), 0);
662 QCOMPARE(spy1.count(), 0);
663 QCOMPARE(spy2.count(), 0);
664 QCOMPARE(spy3.count(), 0);
665 #endif
666 QSKIP("Test is not implemented.", SkipAll);
667 }
668
669 void tst_QBarCategoriesAxis::rangeChanged_data()
670 {
671 QTest::addColumn<QString>("min");
672 QTest::addColumn<QString>("max");
673 QTest::newRow("null") << QString() << QString();
674 }
675
676 // protected void rangeChanged(QString const& min, QString const& max)
677 void tst_QBarCategoriesAxis::rangeChanged()
678 {
679 #if 0
680 QFETCH(QString, min);
681 QFETCH(QString, max);
682
683 SubQBarCategoriesAxis axis;
684
685 QSignalSpy spy0(&axis, SIGNAL(categoriesChanged()));
686 QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&)));
687 QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&)));
688 QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&)));
689
690 axis.call_rangeChanged(min, max);
691
692 QCOMPARE(spy0.count(), 0);
693 QCOMPARE(spy1.count(), 0);
694 QCOMPARE(spy2.count(), 0);
695 QCOMPARE(spy3.count(), 0);
696 #endif
697 QSKIP("Test is not implemented.", SkipAll);
698 }
699
700 QTEST_MAIN(tst_QBarCategoriesAxis)
701 #include "tst_qbarcategoriesaxis.moc"
702
@@ -1,157 +1,159
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 "chartcategoriesaxisx_p.h"
22 22 #include "chartpresenter_p.h"
23 23 #include "qbarcategoriesaxis_p.h"
24 24 #include <QDebug>
25 25 #include <qmath.h>
26 26
27 27 static int label_padding = 5;
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 ChartCategoriesAxisX::ChartCategoriesAxisX(QBarCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
32 32 m_categoriesAxis(axis)
33 33 {
34 34
35 35 }
36 36
37 37 ChartCategoriesAxisX::~ChartCategoriesAxisX()
38 38 {
39 39 }
40 40
41 41 QVector<qreal> ChartCategoriesAxisX::calculateLayout() const
42 42 {
43 Q_ASSERT(m_categoriesAxis->categories().count()>=1);
43 int count = m_categoriesAxis->d_ptr->count();
44
45 Q_ASSERT(count>=1);
44 46
45 47 QVector<qreal> points;
46 points.resize(m_categoriesAxis->categories().count()+2);
48 points.resize(count+2);
47 49
48 const qreal delta = m_rect.width()/(m_categoriesAxis->categories().count());
50 const qreal delta = m_rect.width()/(count);
49 51 qreal offset =-m_min-0.5;
50 52
51 53 if(offset<=0) {
52 54 offset = int(offset * m_rect.width()/(m_max - m_min))%int(delta) + delta;
53 55 }
54 56 else {
55 57 offset = int(offset * m_rect.width()/(m_max - m_min))%int(delta);
56 58 }
57 59
58 60 points[0] = m_rect.left();
59 points[m_categoriesAxis->categories().count()+1] = m_rect.right();
61 points[count+1] = m_rect.right();
60 62
61 for (int i = 0; i < m_categoriesAxis->categories().count(); ++i) {
63 for (int i = 0; i < count; ++i) {
62 64 qreal x = offset + i * delta + m_rect.left();
63 65 points[i+1] = x;
64 66 }
65 67 return points;
66 68 }
67 69
68 70 QStringList ChartCategoriesAxisX::createCategoryLabels(const QVector<qreal>& layout) const
69 71 {
70 72 QStringList result;
71 73 qreal d = (m_max - m_min)/m_rect.width();
72 74 for (int i = 0;i < layout.count()-1; ++i) {
73 75 qreal x = qFloor((((layout[i+1] + layout[i])/2-m_rect.left())*d + m_min+0.5));
74 76 if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) {
75 77 result << m_categoriesAxis->categories().at(x);
76 78 }
77 79 else {
78 80 // No label for x coordinate
79 81 result << "";
80 82 }
81 83 }
82 84 result << "";
83 85 return result;
84 86 }
85 87
86 88
87 89 void ChartCategoriesAxisX::updateGeometry()
88 90 {
89 91 const QVector<qreal>& layout = ChartAxis::layout();
90 92
91 93 m_minWidth = 0;
92 94 m_minHeight = 0;
93 95
94 96 if(layout.isEmpty()) return;
95 97
96 98 QStringList ticksList = createCategoryLabels(layout);
97 99
98 100 QList<QGraphicsItem *> lines = m_grid->childItems();
99 101 QList<QGraphicsItem *> labels = m_labels->childItems();
100 102 QList<QGraphicsItem *> shades = m_shades->childItems();
101 103 QList<QGraphicsItem *> axis = m_axis->childItems();
102 104
103 105 Q_ASSERT(labels.size() == ticksList.size());
104 106 Q_ASSERT(layout.size() == ticksList.size());
105 107
106 const qreal delta = m_rect.width()/(m_categoriesAxis->categories().count());
108 const qreal delta = m_rect.width()/(m_categoriesAxis->d_ptr->count());
107 109
108 110 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
109 111 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
110 112
111 113 qreal width = m_rect.left();
112 114 for (int i = 0; i < layout.size(); ++i) {
113 115 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
114 116 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
115 117 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
116 118 labelItem->setText(ticksList.at(i));
117 119 const QRectF& rect = labelItem->boundingRect();
118 120 QPointF center = rect.center();
119 121 labelItem->setTransformOriginPoint(center.x(), center.y());
120 122
121 123 if(i==0){
122 124 labelItem->setPos(layout[i+1] - (delta)/2 - center.x(), m_rect.bottom() + label_padding);
123 125 }else{
124 126 labelItem->setPos(layout[i] + (delta)/2 - center.x(), m_rect.bottom() + label_padding);
125 127 }
126 128
127 129 if(labelItem->pos().x()<=width || labelItem->pos().x()+ rect.width()>m_rect.right()) {
128 130 labelItem->setVisible(false);
129 131 }
130 132 else {
131 133 labelItem->setVisible(true);
132 134 width=rect.width()+labelItem->pos().x();
133 135 }
134 136
135 137 m_minWidth+=rect.width();
136 138 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
137 139
138 140 if ((i+1)%2 && i>1) {
139 141 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
140 142 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
141 143 }
142 144 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
143 145 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
144 146 }
145 147 }
146 148
147 149 void ChartCategoriesAxisX::handleAxisUpdated()
148 150 {
149 151 if(m_categoriesAxis->categories()!=m_categories)
150 152 {
151 153 m_categories=m_categoriesAxis->categories();
152 if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry();
154 if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) updateGeometry();
153 155 }
154 156 ChartAxis::handleAxisUpdated();
155 157 }
156 158
157 159 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,159 +1,160
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 "chartcategoriesaxisy_p.h"
22 22 #include "chartpresenter_p.h"
23 23 #include "qbarcategoriesaxis_p.h"
24 24 #include <qmath.h>
25 25
26 26 static int label_padding = 5;
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 ChartCategoriesAxisY::ChartCategoriesAxisY(QBarCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
31 31 m_categoriesAxis(axis)
32 32 {
33 33 }
34 34
35 35 ChartCategoriesAxisY::~ChartCategoriesAxisY()
36 36 {
37 37 }
38 38
39 39 QVector<qreal> ChartCategoriesAxisY::calculateLayout() const
40 40 {
41 Q_ASSERT(m_categoriesAxis->categories().count()>=1);
41 int count = m_categoriesAxis->d_ptr->count();
42
43 Q_ASSERT(count>=1);
42 44
43 45 QVector<qreal> points;
44 points.resize(m_categoriesAxis->categories().count()+2);
46 points.resize(count+2);
45 47
46 const qreal delta = m_rect.height()/(m_categoriesAxis->categories().count());
48 const qreal delta = m_rect.height()/(count);
47 49 qreal offset = - m_min - 0.5;
48 50
49 51 if(offset<=0) {
50 52 offset = int(offset * m_rect.height()/(m_max - m_min))%int(delta) + delta;
51 53 }
52 54 else {
53 55 offset = int(offset * m_rect.height()/(m_max - m_min))%int(delta);
54 56 }
55 57
56 58 points[0] = m_rect.bottom();
57 points[m_categoriesAxis->categories().count()+1] = m_rect.top();
59 points[count+1] = m_rect.top();
58 60
59 for (int i = 0; i < m_categoriesAxis->categories().count(); ++i) {
61 for (int i = 0; i < count; ++i) {
60 62 int y = m_rect.bottom() - i * delta - offset;
61 63 points[i+1] = y;
62 64 }
63 65 return points;
64 66 }
65 67
66 68 QStringList ChartCategoriesAxisY::createCategoryLabels(const QVector<qreal>& layout) const
67 69 {
68 70 QStringList result;
69 71 qreal d = (m_max - m_min)/m_rect.height();
70 72 for (int i = 0;i < layout.count()-1; ++i) {
71 73 qreal x = qFloor(((m_rect.height()- (layout[i+1] + layout[i])/2 + m_rect.top())*d + m_min+0.5));
72 74 if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) {
73 75 result << m_categoriesAxis->categories().at(x);
74 76 }
75 77 else {
76 78 // No label for x coordinate
77 79 result << "";
78 80 }
79 81 }
80 82 result << "";
81 83 return result;
82 84 }
83 85
84 86 void ChartCategoriesAxisY::updateGeometry()
85 87 {
86 88 const QVector<qreal>& layout = ChartAxis::layout();
87 89
88 90 m_minWidth = 0;
89 91 m_minHeight = 0;
90 92
91 93 if(layout.isEmpty()) return;
92 94
93 95 QStringList ticksList = createCategoryLabels(layout);
94 96
95 97 QList<QGraphicsItem *> lines = m_grid->childItems();
96 98 QList<QGraphicsItem *> labels = m_labels->childItems();
97 99 QList<QGraphicsItem *> shades = m_shades->childItems();
98 100 QList<QGraphicsItem *> axis = m_axis->childItems();
99 101
100 102 Q_ASSERT(labels.size() == ticksList.size());
101 103 Q_ASSERT(layout.size() == ticksList.size());
102 104
103 const qreal delta = m_rect.height()/(m_categoriesAxis->categories().count());
105 const qreal delta = m_rect.height()/(m_categoriesAxis->d_ptr->count());
104 106
105 107 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
106 108 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
107 109
108 110 qreal height = m_rect.bottom();
109 111 for (int i = 0; i < layout.size(); ++i) {
110 112 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
111 113 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
112 114 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
113 115 labelItem->setText(ticksList.at(i));
114 116 const QRectF& rect = labelItem->boundingRect();
115 117 QPointF center = rect.center();
116 118 labelItem->setTransformOriginPoint(center.x(), center.y());
117 119
118 120 if(i==0) {
119 121 labelItem->setPos(m_rect.left() - rect.width() - label_padding ,layout[i+1] + (delta)/2 - center.y());
120 122 }
121 123 else {
122 124 labelItem->setPos(m_rect.left() - rect.width() - label_padding ,layout[i] - (delta)/2 - center.y());
123 125 }
124 126
125 127 if(labelItem->pos().y()+rect.height()>= height || labelItem->pos().y() < m_rect.top()) {
126 128 labelItem->setVisible(false);
127 129 }
128 130 else {
129 131 labelItem->setVisible(true);
130 132 height=labelItem->pos().y();
131 133 }
132 134
133 135 m_minWidth+=rect.width();
134 136 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
135 137
136 138 if ((i+1)%2 && i>1) {
137 139 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
138 140 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
139 141 }
140 142 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
141 143 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
142 144 }
143 145 }
144 146
145 147 void ChartCategoriesAxisY::handleAxisUpdated()
146 148 {
147 149
148 150 if(m_categoriesAxis->categories()!=m_categories)
149 151 {
150 152 m_categories=m_categoriesAxis->categories();
151 if(ChartAxis::layout().count()==m_categories.size()+1) {
152
153 if(ChartAxis::layout().count()==m_categoriesAxis->d_ptr->count()+2) {
153 154 updateGeometry();
154 155 }
155 156 }
156 157 ChartAxis::handleAxisUpdated();
157 158 }
158 159
159 160 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,64 +1,63
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 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef CHARTCATEGORIESAXISY_H
31 31 #define CHARTCATEGORIESAXISY_H
32 32
33 33 #include "chartaxis_p.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class QAbstractAxis;
38 38 class QBarCategoriesAxis;
39 39 class ChartPresenter;
40 40
41 41 class ChartCategoriesAxisY : public ChartAxis
42 42 {
43 43 public:
44 44 ChartCategoriesAxisY(QBarCategoriesAxis *axis, ChartPresenter *presenter);
45 45 ~ChartCategoriesAxisY();
46 46
47 47 AxisType axisType() const { return Y_AXIS;}
48 48
49 49 protected:
50 50 QVector<qreal> calculateLayout() const;
51 51 void updateGeometry();
52 52 private:
53 53 QStringList createCategoryLabels(const QVector<qreal>& layout) const;
54 54 Q_SLOTS
55 55 void handleAxisUpdated();
56 56 private:
57 57 QStringList m_categories;
58 QVector<int> m_labelIndex;
59 58 QBarCategoriesAxis *m_categoriesAxis;
60 59 };
61 60
62 61 QTCOMMERCIALCHART_END_NAMESPACE
63 62
64 63 #endif /* CHARTCATEGORIESAXISY_H */
@@ -1,439 +1,432
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 #include "chartdataset_p.h"
26 27 #include <qmath.h>
27 #include <QDebug>
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 Q_D(QBarCategoriesAxis);
128 if(d->m_dataset){
129 d->m_dataset->removeAxis(this);
130 }
127 131 }
128 132
129 133 /*!
130 134 \internal
131 135 */
132 136 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
133 137 {
134 138
135 139 }
136 140
137 141 /*!
138 142 Appends \a categories to axis
139 143 */
140 144 void QBarCategoriesAxis::append(const QStringList &categories)
141 145 {
142 146 if(categories.isEmpty()) return;
143 147
144 148 Q_D(QBarCategoriesAxis);
145 149 if (d->m_categories.isEmpty()) {
146 150 d->m_categories.append(categories);
147 151 setRange(categories.first(),categories.last());
148 152 }else{
149 153 d->m_categories.append(categories);
150 154 }
151 155 emit d->updated();
152 156 emit categoriesChanged();
153 157 }
154 158
155 159 /*!
156 160 Appends \a category to axis
157 161 */
158 162 void QBarCategoriesAxis::append(const QString &category)
159 163 {
160 164 Q_D(QBarCategoriesAxis);
161 165 if (d->m_categories.isEmpty()) {
162 166 d->m_categories.append(category);
163 167 setRange(category,category);
164 168 }else{
165 169 d->m_categories.append(category);
166 170 }
167 171 emit d->updated();
168 172 emit categoriesChanged();
169 173 }
170 174
171 175 /*!
172 176 Removes \a category from axis
173 177 */
174 178 void QBarCategoriesAxis::remove(const QString &category)
175 179 {
176 180 Q_D(QBarCategoriesAxis);
177 181 if (d->m_categories.contains(category)) {
178 182 d->m_categories.removeAt(d->m_categories.indexOf(category));
179 setRange(d->m_categories.first(),d->m_categories.last());
183 if(!d->m_categories.isEmpty())
184 setRange(d->m_categories.first(),d->m_categories.last());
185 else
186 setRange(QString::null,QString::null);
180 187 emit d->updated();
181 188 emit categoriesChanged();
182 189 }
183 190 }
184 191
185 192 /*!
186 193 Inserts \a category to axis at \a index
187 194 */
188 195 void QBarCategoriesAxis::insert(int index, const QString &category)
189 196 {
190 197 Q_D(QBarCategoriesAxis);
191 198 if (d->m_categories.isEmpty()) {
192 199 d->m_categories.insert(index,category);
193 200 setRange(category,category);
194 201 }else{
195 202 d->m_categories.insert(index,category);
196 203 }
197 204 emit d->updated();
198 205 emit categoriesChanged();
199 206 }
200 207
201 208 /*!
202 209 Removes all categories.
203 210 */
204 211 void QBarCategoriesAxis::clear()
205 212 {
206 213 Q_D(QBarCategoriesAxis);
207 214 d->m_categories.clear();
208 215 setRange(QString::null,QString::null);
209 216 emit d->updated();
210 217 emit categoriesChanged();
211 218 }
212 219
213 220 void QBarCategoriesAxis::setCategories(const QStringList &categories)
214 221 {
215 222 Q_D(QBarCategoriesAxis);
216 223 if(d->m_categories!=categories){
217 224 d->m_categories = categories;
218 225 setRange(categories.first(),categories.last());
219 226 emit d->updated();
220 227 emit categoriesChanged();
221 228 }
222 229 }
223 230
224 231 QStringList QBarCategoriesAxis::categories()
225 232 {
226 233 Q_D(QBarCategoriesAxis);
227 234 return d->m_categories;
228 235 }
229 236
230 237 /*!
231 238 Returns number of categories.
232 239 */
233 240 int QBarCategoriesAxis::count() const
234 241 {
235 242 Q_D(const QBarCategoriesAxis);
236 243 return d->m_categories.count();
237 244 }
238 245
239 246 /*!
240 247 Returns category at \a index. Index must be valid.
241 248 */
242 249 QString QBarCategoriesAxis::at(int index) const
243 250 {
244 251 Q_D(const QBarCategoriesAxis);
245 252 return d->m_categories.at(index);
246 253 }
247 254
248 255 /*!
249 256 Sets minimum category to \a min.
250 257 */
251 258 void QBarCategoriesAxis::setMin(const QString& min)
252 259 {
253 260 Q_D(QBarCategoriesAxis);
254 if (d->m_minCategory!=min && d->m_categories.contains(min)) {
255 d->m_minCategory = min;
256 d->emitUpdated();
257 emit minChanged(min);
258 }
259
261 setRange(min,d->m_maxCategory);
260 262 }
261 263
262 264 /*!
263 265 Returns minimum category.
264 266 */
265 267 QString QBarCategoriesAxis::min() const
266 268 {
267 269 Q_D(const QBarCategoriesAxis);
268 270 return d->m_minCategory;
269 271 }
270 272
271 273 /*!
272 274 Sets maximum category to \a max.
273 275 */
274 276 void QBarCategoriesAxis::setMax(const QString& max)
275 277 {
276 278 Q_D(QBarCategoriesAxis);
277 if (d->m_maxCategory!=max && d->m_categories.contains(max)) {
278 d->m_maxCategory = max;
279 d->emitUpdated();
280 emit maxChanged(max);
281 }
282
279 setRange(d->m_minCategory,max);
283 280 }
284 281
285 282 /*!
286 283 Returns maximum category
287 284 */
288 285 QString QBarCategoriesAxis::max() const
289 286 {
290 287 Q_D(const QBarCategoriesAxis);
291 288 return d->m_maxCategory;
292 289 }
293 290
294 291 /*!
295 292 Sets range from \a minCategory to \a maxCategory
296 293 */
297 294 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
298 295 {
299 setMin(minCategory);
300 setMax(maxCategory);
296 Q_D(QBarCategoriesAxis);
297
298 if(d->m_categories.indexOf(d->m_maxCategory)<d->m_categories.indexOf(d->m_minCategory)) return;
299
300 bool changed = false;
301
302 if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) {
303 d->m_minCategory = minCategory;
304 d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5;
305 changed = true;
306 emit minChanged(minCategory);
307 }
308
309 if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) {
310 d->m_maxCategory = maxCategory;
311 d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5;
312 changed = true;
313 emit maxChanged(maxCategory);
314 }
315
316 if (changed) {
317 d->m_count=d->m_max - d->m_min;
318 emit rangeChanged(d->m_minCategory,d->m_maxCategory);
319 d->emitUpdated();
320 }
301 321 }
302 322
303 323 /*!
304 324 Returns the type of the axis
305 325 */
306 326 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
307 327 {
308 328 return AxisTypeCategories;
309 329 }
310 330
311 331 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
312 332
313 333 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
314 334 QAbstractAxisPrivate(q),
315 335 m_min(0.0),
316 m_max(0.0)
336 m_max(0.0),
337 m_count(0)
317 338 {
318 339
319 340 }
320 341
321 342 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
322 343 {
323 344
324 345 }
325 346
326 347 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
327 348 {
328 349 setRange(min,m_maxCategory);
329 350 }
330 351
331 352 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
332 353 {
333 354 setRange(m_minCategory,max);
334 355 }
335 356
336 357 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
337 358 {
338 359 Q_Q(QBarCategoriesAxis);
339 360 QString value1 = min.toString();
340 361 QString value2 = max.toString();
341 362 q->setRange(value1,value2);
342 363 }
343 364
344 qreal QBarCategoriesAxisPrivate::min()
345 {
346 //TODO:: cache it
347 return m_min;//m_categories.indexOf(m_minCategory) - 0.5;
348 }
349
350 qreal QBarCategoriesAxisPrivate::max()
351 {
352 //TODO:: cache it
353 return m_max;//m_categories.indexOf(m_maxCategory) + 0.5;
354 }
355
356 365 void QBarCategoriesAxisPrivate::handleDomainUpdated()
357 366 {
367 Q_Q(QBarCategoriesAxis);
358 368 Domain* domain = qobject_cast<Domain*>(sender());
359 369
360 if(m_orientation==Qt::Horizontal){
370 if(m_orientation==Qt::Horizontal) {
361 371 m_min = domain->minX();
362 372 m_max = domain->maxX();
363 }else if(m_orientation==Qt::Vertical){
373 }
374 else if(m_orientation==Qt::Vertical) {
364 375 m_min = domain->minY();
365 376 m_max = domain->maxY();
366 377 }
367 378
368 // Q_Q(QBarCategoriesAxis);
369
370 // TODO: causes crash in some situations. added to known issues
371 /*
372 int minIndex = qFloor(min);
373 int maxIndex = qFloor(max);
379 bool changed = false;
374 380
375 if (minIndex < 0) {
376 minIndex = 0;
377 }
378 if (maxIndex > m_categories.count()-1){
379 maxIndex = m_categories.count()-1;
380 if (maxIndex<0) {
381 maxIndex = 0;
381 int min = m_min + 0.5;
382 if(min>=0 && min<m_categories.count()) {
383 QString minCategory = m_categories.at(min);
384 if(m_minCategory!=minCategory && !minCategory.isEmpty()) {
385 m_minCategory=minCategory;
386 changed=true;
387 emit q->minChanged(minCategory);
382 388 }
383 389 }
384
385 bool changed = false;
386 if (m_minCategory != m_categories.at(minIndex)) {
387 m_minCategory = m_categories.at(minIndex);
388 emit q->minChanged(m_minCategory);
389 changed = true;
390 }
391
392 if (m_maxCategory != m_categories.at(maxIndex)) {
393 m_maxCategory = m_categories.at(maxIndex);
394 emit q->maxChanged(m_maxCategory);
395 changed = true;
390 int max = m_max - 0.5;
391 if(max>=0 && max<m_categories.count()) {
392 QString maxCategory = m_categories.at(max);
393 if(m_maxCategory!=maxCategory && !maxCategory.isEmpty()) {
394 m_maxCategory=maxCategory;
395 emit q->maxChanged(maxCategory);
396 }
396 397 }
397 398
398 399 if (changed) {
399 emit q->rangeChanged(m_minCategory, m_maxCategory);
400 emit q->rangeChanged(m_minCategory,m_maxCategory);
400 401 }
401 */
402 402 }
403 403
404 404 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
405 405 {
406 406 Q_Q(QBarCategoriesAxis);
407 407 if(m_orientation == Qt::Vertical){
408 408 return new ChartCategoriesAxisY(q,presenter);
409 409 }else{
410 410 return new ChartCategoriesAxisX(q,presenter);
411 411 }
412 412 }
413 413
414 /*
415 void QBarCategoriesAxisPrivate::emitRange()
416 {
417 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
418 }
419 */
420
421 414 void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain)
422 415 {
423 416 Q_UNUSED(domain);
424 417 // TODO: this causes crash now. added to known issues.
425 418 /*
426 419 if (qFuzzyCompare(m_max, m_min)) {
427 420 if(m_orientation==Qt::Vertical){
428 421 handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount());
429 422 }else{
430 423 handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount());
431 424 }
432 425 }
433 426 */
434 427 }
435 428
436 429 #include "moc_qbarcategoriesaxis.cpp"
437 430 #include "moc_qbarcategoriesaxis_p.cpp"
438 431
439 432 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,76 +1,78
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 #ifndef QBARCATEGORIESAXIS_H
22 22 #define QBARCATEGORIESAXIS_H
23 23
24 24 #include "qabstractaxis.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 class QBarCategoriesAxisPrivate;
29 29
30 30 class QTCOMMERCIALCHART_EXPORT QBarCategoriesAxis : public QAbstractAxis
31 31 {
32 32 Q_OBJECT
33 33 Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged)
34 34 Q_PROPERTY(QString min READ min WRITE setMin NOTIFY minChanged)
35 35 Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged)
36 36
37 37 public:
38 38 explicit QBarCategoriesAxis(QObject *parent = 0);
39 39 ~QBarCategoriesAxis();
40 40
41 41 protected:
42 42 QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent = 0);
43 43
44 44 public:
45 45 AxisType type() const;
46 46 void append(const QStringList &categories);
47 47 void append(const QString &category);
48 48 void remove(const QString &category);
49 49 void insert(int index, const QString &category);
50 50 void clear();
51 51 void setCategories(const QStringList &categories);
52 52 QStringList categories();
53 53 int count() const;
54 54 QString at(int index) const;
55 55
56 56 //range handling
57 57 void setMin(const QString& minCategory);
58 58 QString min() const;
59 59 void setMax(const QString& maxCategory);
60 60 QString max() const;
61 61 void setRange(const QString& minCategory, const QString& maxCategory);
62 62
63 63 Q_SIGNALS:
64 64 void categoriesChanged();
65 65 void minChanged(const QString &min);
66 66 void maxChanged(const QString &max);
67 67 void rangeChanged(const QString &min, const QString &max);
68 68
69 69 private:
70 70 Q_DECLARE_PRIVATE(QBarCategoriesAxis)
71 71 Q_DISABLE_COPY(QBarCategoriesAxis)
72 friend class ChartCategoriesAxisX;
73 friend class ChartCategoriesAxisY;
72 74 };
73 75
74 76 QTCOMMERCIALCHART_END_NAMESPACE
75 77
76 78 #endif // QCATEGORIESAXIS_H
@@ -1,74 +1,76
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 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QBARCATEGORIESAXIS_P_H
31 31 #define QBARCATEGORIESAXIS_P_H
32 32
33 33 #include "qbarcategoriesaxis.h"
34 34 #include "qabstractaxis_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class Domain;
39 39
40 40 class QBarCategoriesAxisPrivate : public QAbstractAxisPrivate
41 41 {
42 42 Q_OBJECT
43 43
44 44 public:
45 45 QBarCategoriesAxisPrivate(QBarCategoriesAxis *q);
46 46 ~QBarCategoriesAxisPrivate();
47 47
48 48 public:
49 49 ChartAxis* createGraphics(ChartPresenter* presenter);
50 50 void intializeDomain(Domain* domain);
51 51 void handleDomainUpdated();
52 qreal min();
53 qreal max();
52 qreal min() { return m_min;};
53 qreal max() { return m_max;};
54 int count() const { return m_count; };
54 55
55 56 private:
56 57 //range handling
57 58 void setMin(const QVariant &min);
58 59 void setMax(const QVariant &max);
59 60 void setRange(const QVariant &min, const QVariant &max);
60 61
61 62 private:
62 63 QStringList m_categories;
63 64 QString m_minCategory;
64 65 QString m_maxCategory;
65 66 qreal m_min;
66 67 qreal m_max;
68 int m_count;
67 69
68 70 private:
69 Q_DECLARE_PUBLIC(QBarCategoriesAxis)
71 Q_DECLARE_PUBLIC(QBarCategoriesAxis);
70 72 };
71 73
72 74 QTCOMMERCIALCHART_END_NAMESPACE
73 75
74 76 #endif // QBARCATEGORIESAXIS_P_H
@@ -1,69 +1,70
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 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QVALUESAXIS_P_H
31 31 #define QVALUESAXIS_P_H
32 32
33 33 #include "qdatetimeaxis.h"
34 34 #include "qabstractaxis_p.h"
35 35 #include <QDateTime>
36 36
37 37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 38
39 39 class QDateTimeAxisPrivate : public QAbstractAxisPrivate
40 40 {
41 41 Q_OBJECT
42 42 public:
43 43 QDateTimeAxisPrivate(QDateTimeAxis *q);
44 44 ~QDateTimeAxisPrivate();
45 45
46 46 public:
47 47 ChartAxis* createGraphics(ChartPresenter* presenter);
48 48 void intializeDomain(Domain* domain);
49 49 void handleDomainUpdated();
50 50 qreal min(){ return m_min.toMSecsSinceEpoch(); }
51 51 qreal max(){ return m_max.toMSecsSinceEpoch(); }
52 int count() const { /*TODO:*/ return 0;};
52 53
53 54 protected:
54 55 void setMin(const QVariant &min);
55 56 void setMax(const QVariant &max);
56 57 void setRange(const QVariant &min, const QVariant &max);
57 58 int ticksCount() const;
58 59
59 60 protected:
60 61 QDateTime m_min;
61 62 QDateTime m_max;
62 63 int m_tickCount;
63 64 QString m_format;
64 65 Q_DECLARE_PUBLIC(QDateTimeAxis)
65 66 };
66 67
67 68 QTCOMMERCIALCHART_END_NAMESPACE
68 69
69 70 #endif // QVALUESAXIS_P_H
@@ -1,210 +1,212
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 "qintervalsaxis.h"
22 22 #include "qintervalsaxis_p.h"
23 23 #include "chartintervalsaxisx_p.h"
24 24 #include "chartintervalsaxisy_p.h"
25 25 #include <qmath.h>
26 26 #include <QDebug>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29 /*!
30 30 \internal
31 31 \class QIntervalsAxis
32 32 \brief The QIntervalsAxis class is used for manipulating chart's axis.
33 33 \mainclass
34 34
35 35 Axis can be setup to show axis line with tick marks, grid lines and shades.
36 36 */
37 37
38 38 /*!
39 39 \qmlclass Axis QIntervalsAxis
40 40 \brief The Axis element is used for manipulating chart's axes.
41 41
42 42 Axis can be setup to show axis line with tick marks, grid lines and shades.
43 43
44 44 To access Axes you can use ChartView API. For example:
45 45 \code
46 46 // TODO :)
47 47 \endcode
48 48 */
49 49
50 50 /*!
51 51 Constructs an axis object which is a child of \a parent.
52 52 */
53 53 QIntervalsAxis::QIntervalsAxis(QObject *parent):
54 54 QValuesAxis(*new QIntervalsAxisPrivate(this),parent)
55 55 {
56 56 }
57 57
58 58 /*!
59 59 Destroys the object
60 60 */
61 61 QIntervalsAxis::~QIntervalsAxis()
62 62 {
63 63 }
64 64
65 65 /*!
66 66 \internal
67 67 */
68 68 QIntervalsAxis::QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
69 69 {
70 70
71 71 }
72 72
73 73 /*!
74 74 Appends \a category to axis
75 75 */
76 76 void QIntervalsAxis::append(const QString& intervalLabel, qreal interval)
77 77 {
78 78 Q_D(QIntervalsAxis);
79 79
80 80 if (!d->m_intervals.contains(intervalLabel))
81 81 {
82 82 if(d->m_intervals.isEmpty()){
83 83 Range range(d->m_categoryMinimum,interval);
84 84 d->m_intervalsMap.insert(intervalLabel, range);
85 85 d->m_intervals.append(intervalLabel);
86 86 }else if (interval > intervalMax(d->m_intervals.last())){
87 87 Range range = d->m_intervalsMap.value(d->m_intervals.last());
88 88 d->m_intervalsMap.insert(intervalLabel, Range(range.second,interval));
89 89 d->m_intervals.append(intervalLabel);
90 90 }
91 91 }
92 92 }
93 93
94 94 void QIntervalsAxis::setFisrtIntervalMinimum(qreal min)
95 95 {
96 96 Q_D(QIntervalsAxis);
97 97 if(d->m_intervals.isEmpty()){
98 98 d->m_categoryMinimum = min;
99 99 }else{
100 100 Range range = d->m_intervalsMap.value(d->m_intervals.first());
101 101 d->m_intervalsMap.insert(d->m_intervals.first(), Range(min, range.second));
102 102 // setRange(min, d->m_min);
103 103 }
104 104 }
105 105
106 106 qreal QIntervalsAxis::intervalMin(const QString& intervalLabel) const
107 107 {
108 108 Q_D(const QIntervalsAxis);
109 109 return d->m_intervalsMap.value(intervalLabel).first;
110 110 }
111 111
112 112 qreal QIntervalsAxis::intervalMax(const QString& intervalLabel) const
113 113 {
114 114 Q_D(const QIntervalsAxis);
115 115 return d->m_intervalsMap.value(intervalLabel).second;
116 116 }
117 117
118 118 /*!
119 119 Removes \a category from axis
120 120 */
121 121 void QIntervalsAxis::remove(const QString &intervalLabel)
122 122 {
123 123 Q_D(QIntervalsAxis);
124 124 int labelIndex = d->m_intervals.indexOf(intervalLabel);
125 125
126 126 // check if such label exists
127 127 if (labelIndex != -1) {
128 128 d->m_intervals.removeAt(labelIndex);
129 129 d->m_intervalsMap.remove(intervalLabel);
130 130
131 131 // the range of the interval that follows (if exists) needs to be updated
132 132 if (labelIndex < d->m_intervals.count()) {
133 133 QString label = d->m_intervals.at(labelIndex);
134 134 Range range = d->m_intervalsMap.value(label);
135 135
136 136 // set the range
137 137 if (labelIndex == 0) {
138 138 range.first = d->m_categoryMinimum;
139 139 d->m_intervalsMap.insert(label, range);
140 140 } else {
141 141 range.first = d->m_intervalsMap.value(d->m_intervals.at(labelIndex - 1)).second;
142 142 d->m_intervalsMap.insert(label, range);
143 143 }
144 144 }
145 145 }
146 146 }
147 147
148 148 QStringList QIntervalsAxis::intervalsLabels()
149 149 {
150 150 Q_D(QIntervalsAxis);
151 151 return d->m_intervals;
152 152 }
153 153
154 154 /*!
155 155 Returns number of categories.
156 156 */
157 157 int QIntervalsAxis::count() const
158 158 {
159 159 Q_D(const QIntervalsAxis);
160 160 return d->m_intervals.count();
161 161 }
162 162
163 163 /*!
164 164 Returns the type of the axis
165 165 */
166 166 QAbstractAxis::AxisType QIntervalsAxis::type() const
167 167 {
168 168 return QAbstractAxis::AxisTypeIntervals;
169 169 }
170 170
171 171 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
172 172
173 173 QIntervalsAxisPrivate::QIntervalsAxisPrivate(QIntervalsAxis* q):
174 174 QValuesAxisPrivate(q),
175 175 m_categoryMinimum(0)
176 176 {
177 177
178 178 }
179 179
180 180 QIntervalsAxisPrivate::~QIntervalsAxisPrivate()
181 181 {
182 182
183 183 }
184 184
185 185 int QIntervalsAxisPrivate::ticksCount() const
186 186 {
187 187 return m_intervals.count() + 1;
188 188 }
189 189
190 190 void QIntervalsAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
191 191 {
192 192 Q_UNUSED(count);
193 m_min = min;
194 m_max = max;
193 Q_UNUSED(min);
194 Q_UNUSED(max);
195 //m_min = min;
196 //m_max = max;
195 197 }
196 198
197 199 ChartAxis* QIntervalsAxisPrivate::createGraphics(ChartPresenter* presenter)
198 200 {
199 201 Q_Q(QIntervalsAxis);
200 202 if(m_orientation == Qt::Vertical){
201 203 return new ChartIntervalAxisY(q,presenter);
202 204 }else{
203 205 return new ChartIntervalAxisX(q,presenter);
204 206 }
205 207 }
206 208
207 209 #include "moc_qintervalsaxis.cpp"
208 210 #include "moc_qintervalsaxis_p.cpp"
209 211
210 212 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,651 +1,653
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.h"
22 22 #include "qabstractaxis_p.h"
23 23
24 24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 25
26 26 /*!
27 27 \class QAbstractAxis
28 28 \brief The QAbstractAxis class is used for manipulating chart's axis.
29 29 \mainclass
30 30
31 31 There is only one x Axis visible at the time, however there can be multiple y axes.
32 32 Each chart series can be bound to exactly one Y axis and the shared common X axis.
33 33 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 34 */
35 35
36 36 /*!
37 37 \qmlclass AbstractAxis QAbstractAxis
38 38 \brief The Axis element is used for manipulating chart's axes
39 39
40 40 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
41 41 Each chart series can be bound to exactly one Y axis and the shared common X axis.
42 42 Axis can be setup to show axis line with tick marks, grid lines and shades.
43 43
44 44 To access Axes you can use ChartView API. For example:
45 45 \code
46 46 ChartView {
47 47 axisX.min: 0
48 48 axisX.max: 3
49 49 axisX.ticksCount: 4
50 50 axisY.min: 0
51 51 axisY.max: 4
52 52 // Add a few series...
53 53 }
54 54 \endcode
55 55 */
56 56
57 57 /*!
58 58 \enum QAbstractAxis::AxisType
59 59
60 60 The type of the series object.
61 61
62 62 \value AxisTypeNoAxis
63 63 \value AxisTypeValues
64 64 \value AxisTypeCategories
65 65 */
66 66
67 67 /*!
68 68 *\fn void QAbstractAxis::type() const
69 69 Returns the type of the axis
70 70 */
71 71
72 72 /*!
73 73 \property QAbstractAxis::arrowVisible
74 74 The visibility of the axis arrow
75 75 */
76 76 /*!
77 77 \qmlproperty bool AbstractAxis::arrrowVisible
78 78 The visibility of the axis arrow
79 79 */
80 80
81 81 /*!
82 82 \property QAbstractAxis::labelsVisible
83 83 Defines if axis labels are visible.
84 84 */
85 85 /*!
86 86 \qmlproperty bool AbstractAxis::labelsVisible
87 87 Defines if axis labels are visible.
88 88 */
89 89
90 90 /*!
91 91 \property QAbstractAxis::visible
92 92 The visibility of the axis.
93 93 */
94 94 /*!
95 95 \qmlproperty bool AbstractAxis::visible
96 96 The visibility of the axis.
97 97 */
98 98
99 99 /*!
100 100 \property QAbstractAxis::gridVisible
101 101 The visibility of the grid lines.
102 102 */
103 103 /*!
104 104 \qmlproperty bool AbstractAxis::gridVisible
105 105 The visibility of the grid lines.
106 106 */
107 107
108 108 /*!
109 109 \property QAbstractAxis::color
110 110 The color of the axis and ticks.
111 111 */
112 112 /*!
113 113 \qmlproperty color AbstractAxis::color
114 114 The color of the axis and ticks.
115 115 */
116 116
117 117 /*!
118 118 \property QAbstractAxis::labelsFont
119 119 The font of the axis labels.
120 120 */
121 121
122 122 /*!
123 123 \qmlproperty Font AbstractAxis::labelsFont
124 124 The font of the axis labels.
125 125
126 126 See the \l {Font} {QML Font Element} for detailed documentation.
127 127 */
128 128
129 129 /*!
130 130 \property QAbstractAxis::labelsColor
131 131 The color of the axis labels.
132 132 */
133 133 /*!
134 134 \qmlproperty color AbstractAxis::labelsColor
135 135 The color of the axis labels.
136 136 */
137 137
138 138 /*!
139 139 \property QAbstractAxis::labelsAngle
140 140 The angle of the axis labels in degrees.
141 141 */
142 142 /*!
143 143 \qmlproperty int AbstractAxis::labelsAngle
144 144 The angle of the axis labels in degrees.
145 145 */
146 146
147 147 /*!
148 148 \property QAbstractAxis::shadesVisible
149 149 The visibility of the axis shades.
150 150 */
151 151 /*!
152 152 \qmlproperty bool AbstractAxis::shadesVisible
153 153 The visibility of the axis shades.
154 154 */
155 155
156 156 /*!
157 157 \property QAbstractAxis::shadesColor
158 158 The fill (brush) color of the axis shades.
159 159 */
160 160 /*!
161 161 \qmlproperty color AbstractAxis::shadesColor
162 162 The fill (brush) color of the axis shades.
163 163 */
164 164
165 165 /*!
166 166 \property QAbstractAxis::shadesBorderColor
167 167 The border (pen) color of the axis shades.
168 168 */
169 169 /*!
170 170 \qmlproperty color AbstractAxis::shadesBorderColor
171 171 The border (pen) color of the axis shades.
172 172 */
173 173
174 174 /*!
175 175 \fn void QAbstractAxis::visibleChanged(bool visible)
176 176 Visiblity of the axis has changed to \a visible.
177 177 */
178 178 /*!
179 179 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
180 180 Visiblity of the axis has changed to \a visible.
181 181 */
182 182
183 183 /*!
184 184 \fn void QAbstractAxis::arrowVisibleChanged(bool visible)
185 185 Visiblity of the axis arrow has changed to \a visible.
186 186 */
187 187 /*!
188 188 \qmlsignal AbstractAxis::onArrowVisibleChanged(bool visible)
189 189 Visiblity of the axis arrow has changed to \a visible.
190 190 */
191 191
192 192 /*!
193 193 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
194 194 Visiblity of the labels of the axis has changed to \a visible.
195 195 */
196 196 /*!
197 197 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
198 198 Visiblity of the labels of the axis has changed to \a visible.
199 199 */
200 200
201 201 /*!
202 202 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
203 203 Visiblity of the grid lines of the axis has changed to \a visible.
204 204 */
205 205 /*!
206 206 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
207 207 Visiblity of the grid lines of the axis has changed to \a visible.
208 208 */
209 209
210 210 /*!
211 211 \fn void QAbstractAxis::colorChanged(QColor color)
212 212 Emitted if the \a color of the axis is changed.
213 213 */
214 214 /*!
215 215 \qmlsignal AbstractAxis::onColorChanged(QColor color)
216 216 Emitted if the \a color of the axis is changed.
217 217 */
218 218
219 219 /*!
220 220 \fn void QAbstractAxis::labelsColorChanged(QColor color)
221 221 Emitted if the \a color of the axis labels is changed.
222 222 */
223 223 /*!
224 224 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
225 225 Emitted if the \a color of the axis labels is changed.
226 226 */
227 227
228 228 /*!
229 229 \fn void QAbstractAxis::shadesVisibleChanged(bool)
230 230 Emitted if the visibility of the axis shades is changed to \a visible.
231 231 */
232 232 /*!
233 233 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
234 234 Emitted if the visibility of the axis shades is changed to \a visible.
235 235 */
236 236
237 237 /*!
238 238 \fn void QAbstractAxis::shadesColorChanged(QColor color)
239 239 Emitted if the \a color of the axis shades is changed.
240 240 */
241 241 /*!
242 242 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
243 243 Emitted if the \a color of the axis shades is changed.
244 244 */
245 245
246 246 /*!
247 247 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
248 248 Emitted if the border \a color of the axis shades is changed.
249 249 */
250 250 /*!
251 251 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
252 252 Emitted if the border \a color of the axis shades is changed.
253 253 */
254 254
255 255 /*!
256 256 \internal
257 257 Constructs new axis object which is a child of \a parent. Ownership is taken by
258 258 QChart when axis added.
259 259 */
260 260
261 261 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) :
262 262 QObject(parent),
263 263 d_ptr(&d)
264 264 {
265 265 }
266 266
267 267 /*!
268 268 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
269 269 */
270 270
271 271 QAbstractAxis::~QAbstractAxis()
272 272 {
273 if(d_ptr->m_dataset) qFatal("Still binded axis detected !");
273 274 }
274 275
275 276 /*!
276 277 Sets \a pen used to draw axis line and ticks.
277 278 */
278 279 void QAbstractAxis::setAxisPen(const QPen &pen)
279 280 {
280 281 if (d_ptr->m_axisPen!=pen) {
281 282 d_ptr->m_axisPen = pen;
282 283 d_ptr->emitUpdated();
283 284 }
284 285 }
285 286
286 287 /*!
287 288 Returns pen used to draw axis and ticks.
288 289 */
289 290 QPen QAbstractAxis::axisPen() const
290 291 {
291 292 return d_ptr->m_axisPen;
292 293 }
293 294
294 295 void QAbstractAxis::setAxisPenColor(QColor color)
295 296 {
296 297 QPen p = d_ptr->m_axisPen;
297 298 if (p.color() != color) {
298 299 p.setColor(color);
299 300 setAxisPen(p);
300 301 emit colorChanged(color);
301 302 }
302 303 }
303 304
304 305 QColor QAbstractAxis::axisPenColor() const
305 306 {
306 307 return d_ptr->m_axisPen.color();
307 308 }
308 309
309 310 /*!
310 311 Sets if axis and ticks are \a visible.
311 312 */
312 313 void QAbstractAxis::setArrowVisible(bool visible)
313 314 {
314 315 if (d_ptr->m_arrowVisible != visible) {
315 316 d_ptr->m_arrowVisible = visible;
316 317 d_ptr->emitUpdated();
317 318 emit arrowVisibleChanged(visible);
318 319 }
319 320 }
320 321
321 322 bool QAbstractAxis::isArrowVisible() const
322 323 {
323 324 return d_ptr->m_arrowVisible;
324 325 }
325 326
326 327 void QAbstractAxis::setGridLineVisible(bool visible)
327 328 {
328 329 if (d_ptr->m_gridLineVisible != visible) {
329 330 d_ptr->m_gridLineVisible = visible;
330 331 d_ptr->emitUpdated();
331 332 emit gridVisibleChanged(visible);
332 333 }
333 334 }
334 335
335 336 bool QAbstractAxis::isGridLineVisible() const
336 337 {
337 338 return d_ptr->m_gridLineVisible;
338 339 }
339 340
340 341 /*!
341 342 Sets \a pen used to draw grid line.
342 343 */
343 344 void QAbstractAxis::setGridLinePen(const QPen &pen)
344 345 {
345 346 if (d_ptr->m_gridLinePen != pen) {
346 347 d_ptr->m_gridLinePen = pen;
347 348 d_ptr->emitUpdated();
348 349 }
349 350 }
350 351
351 352 /*!
352 353 Returns pen used to draw grid.
353 354 */
354 355 QPen QAbstractAxis::gridLinePen() const
355 356 {
356 357 return d_ptr->m_gridLinePen;
357 358 }
358 359
359 360 void QAbstractAxis::setLabelsVisible(bool visible)
360 361 {
361 362 if (d_ptr->m_labelsVisible != visible) {
362 363 d_ptr->m_labelsVisible = visible;
363 364 d_ptr->emitUpdated();
364 365 emit labelsVisibleChanged(visible);
365 366 }
366 367 }
367 368
368 369 bool QAbstractAxis::labelsVisible() const
369 370 {
370 371 return d_ptr->m_labelsVisible;
371 372 }
372 373
373 374 /*!
374 375 Sets \a pen used to draw labels.
375 376 */
376 377 void QAbstractAxis::setLabelsPen(const QPen &pen)
377 378 {
378 379 if (d_ptr->m_labelsPen != pen) {
379 380 d_ptr->m_labelsPen = pen;
380 381 d_ptr->emitUpdated();
381 382 }
382 383 }
383 384
384 385 /*!
385 386 Returns the pen used to labels.
386 387 */
387 388 QPen QAbstractAxis::labelsPen() const
388 389 {
389 390 return d_ptr->m_labelsPen;
390 391 }
391 392
392 393 /*!
393 394 Sets \a brush used to draw labels.
394 395 */
395 396 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
396 397 {
397 398 if (d_ptr->m_labelsBrush != brush) {
398 399 d_ptr->m_labelsBrush = brush;
399 400 d_ptr->emitUpdated();
400 401 }
401 402 }
402 403
403 404 /*!
404 405 Returns brush used to draw labels.
405 406 */
406 407 QBrush QAbstractAxis::labelsBrush() const
407 408 {
408 409 return d_ptr->m_labelsBrush;
409 410 }
410 411
411 412 /*!
412 413 Sets \a font used to draw labels.
413 414 */
414 415 void QAbstractAxis::setLabelsFont(const QFont &font)
415 416 {
416 417 if (d_ptr->m_labelsFont != font) {
417 418 d_ptr->m_labelsFont = font;
418 419 d_ptr->emitUpdated();
419 420 }
420 421 }
421 422
422 423 /*!
423 424 Returns font used to draw labels.
424 425 */
425 426 QFont QAbstractAxis::labelsFont() const
426 427 {
427 428 return d_ptr->m_labelsFont;
428 429 }
429 430
430 431 void QAbstractAxis::setLabelsAngle(int angle)
431 432 {
432 433 if (d_ptr->m_labelsAngle != angle) {
433 434 d_ptr->m_labelsAngle = angle;
434 435 d_ptr->emitUpdated();
435 436 }
436 437 }
437 438
438 439 int QAbstractAxis::labelsAngle() const
439 440 {
440 441 return d_ptr->m_labelsAngle;
441 442 }
442 443
443 444 void QAbstractAxis::setLabelsColor(QColor color)
444 445 {
445 446 QBrush b = d_ptr->m_labelsBrush;
446 447 if (b.color() != color) {
447 448 b.setColor(color);
448 449 setLabelsBrush(b);
449 450 emit labelsColorChanged(color);
450 451 }
451 452 }
452 453
453 454 QColor QAbstractAxis::labelsColor() const
454 455 {
455 456 return d_ptr->m_labelsBrush.color();
456 457 }
457 458
458 459 void QAbstractAxis::setShadesVisible(bool visible)
459 460 {
460 461 if (d_ptr->m_shadesVisible != visible) {
461 462 d_ptr->m_shadesVisible = visible;
462 463 d_ptr->emitUpdated();
463 464 emit shadesVisibleChanged(visible);
464 465 }
465 466 }
466 467
467 468 bool QAbstractAxis::shadesVisible() const
468 469 {
469 470 return d_ptr->m_shadesVisible;
470 471 }
471 472
472 473 /*!
473 474 Sets \a pen used to draw shades.
474 475 */
475 476 void QAbstractAxis::setShadesPen(const QPen &pen)
476 477 {
477 478 if (d_ptr->m_shadesPen != pen) {
478 479 d_ptr->m_shadesPen = pen;
479 480 d_ptr->emitUpdated();
480 481 }
481 482 }
482 483
483 484 /*!
484 485 Returns pen used to draw shades.
485 486 */
486 487 QPen QAbstractAxis::shadesPen() const
487 488 {
488 489 return d_ptr->m_shadesPen;
489 490 }
490 491
491 492 /*!
492 493 Sets \a brush used to draw shades.
493 494 */
494 495 void QAbstractAxis::setShadesBrush(const QBrush &brush)
495 496 {
496 497 if (d_ptr->m_shadesBrush != brush) {
497 498 d_ptr->m_shadesBrush = brush;
498 499 d_ptr->emitUpdated();
499 500 emit shadesColorChanged(brush.color());
500 501 }
501 502 }
502 503
503 504 /*!
504 505 Returns brush used to draw shades.
505 506 */
506 507 QBrush QAbstractAxis::shadesBrush() const
507 508 {
508 509 return d_ptr->m_shadesBrush;
509 510 }
510 511
511 512 void QAbstractAxis::setShadesColor(QColor color)
512 513 {
513 514 QBrush b = d_ptr->m_shadesBrush;
514 515 b.setColor(color);
515 516 setShadesBrush(b);
516 517 }
517 518
518 519 QColor QAbstractAxis::shadesColor() const
519 520 {
520 521 return d_ptr->m_shadesBrush.color();
521 522 }
522 523
523 524 void QAbstractAxis::setShadesBorderColor(QColor color)
524 525 {
525 526 QPen p = d_ptr->m_shadesPen;
526 527 p.setColor(color);
527 528 setShadesPen(p);
528 529 }
529 530
530 531 QColor QAbstractAxis::shadesBorderColor() const
531 532 {
532 533 return d_ptr->m_shadesPen.color();
533 534 }
534 535
535 536
536 537 bool QAbstractAxis::isVisible() const
537 538 {
538 539 return d_ptr->m_visible;
539 540 }
540 541
541 542 /*!
542 543 Sets axis, shades, labels and grid lines to be visible.
543 544 */
544 545 void QAbstractAxis::setVisible(bool visible)
545 546 {
546 547 if(d_ptr->m_visible!=visible){
547 548 d_ptr->m_visible=visible;
548 549 d_ptr->emitUpdated();
549 550 emit visibleChanged(visible);
550 551 }
551 552 }
552 553
553 554
554 555 /*!
555 556 Sets axis, shades, labels and grid lines to be visible.
556 557 */
557 558 void QAbstractAxis::show()
558 559 {
559 560 setVisible(true);
560 561 }
561 562
562 563 /*!
563 564 Sets axis, shades, labels and grid lines to not be visible.
564 565 */
565 566 void QAbstractAxis::hide()
566 567 {
567 568 setVisible(false);
568 569 }
569 570
570 571 /*!
571 572 Sets the minimum value shown on the axis.
572 573 Depending on the actual axis type the \a min paramter is converted to appropriate type.
573 574 If the conversion is impossible then the function call does nothing
574 575 */
575 576 void QAbstractAxis::setMin(const QVariant &min)
576 577 {
577 578 d_ptr->setMin(min);
578 579 }
579 580
580 581 /*!
581 582 Sets the maximum value shown on the axis.
582 583 Depending on the actual axis type the \a max paramter is converted to appropriate type.
583 584 If the conversion is impossible then the function call does nothing
584 585 */
585 586 void QAbstractAxis::setMax(const QVariant &max)
586 587 {
587 588 d_ptr->setMax(max);
588 589 }
589 590
590 591 /*!
591 592 Sets the range shown on the axis.
592 593 Depending on the actual axis type the \a min and \a max paramters are converted to appropriate types.
593 594 If the conversion is impossible then the function call does nothing.
594 595 */
595 596 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
596 597 {
597 598 d_ptr->setRange(min,max);
598 599 }
599 600
600 601
601 602 Qt::Orientation QAbstractAxis::orientation()
602 603 {
603 604 return d_ptr->m_orientation;
604 605 }
605 606
606 607 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
607 608
608 609 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
609 610 q_ptr(q),
610 611 m_orientation(Qt::Orientation(0)),
612 m_dataset(0),
611 613 m_visible(false),
612 614 m_arrowVisible(true),
613 615 m_gridLineVisible(true),
614 616 m_labelsVisible(true),
615 617 m_labelsAngle(0),
616 618 m_shadesVisible(false),
617 619 m_shadesBrush(Qt::SolidPattern),
618 620 m_shadesOpacity(1.0),
619 621 m_dirty(false)
620 622 {
621 623
622 624 }
623 625
624 626 QAbstractAxisPrivate::~QAbstractAxisPrivate()
625 627 {
626 628
627 629 }
628 630
629 631 void QAbstractAxisPrivate::emitUpdated()
630 632 {
631 633 if(!m_dirty){
632 634 m_dirty=true;
633 635 emit updated();
634 636 }
635 637 }
636 638
637 639 void QAbstractAxisPrivate::setDirty(bool dirty)
638 640 {
639 641 m_dirty=dirty;
640 642 }
641 643
642 644 void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation)
643 645 {
644 646 m_orientation=orientation;
645 647 }
646 648
647 649
648 650 #include "moc_qabstractaxis.cpp"
649 651 #include "moc_qabstractaxis_p.cpp"
650 652
651 653 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,105 +1,110
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 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QABSTRACTAXIS_P_H
31 31 #define QABSTRACTAXIS_P_H
32 32
33 33 #include "qabstractaxis.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class ChartPresenter;
38 38 class ChartAxis;
39 39 class Domain;
40 class ChartDataSet;
40 41
41 42 class QTCOMMERCIALCHART_AUTOTEST_EXPORT QAbstractAxisPrivate : public QObject
42 43 {
43 44 Q_OBJECT
44 45 public:
45 46 QAbstractAxisPrivate(QAbstractAxis *q);
46 47 ~QAbstractAxisPrivate();
47 48
48 49 public:
49 50
50 51 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
51 52 virtual void intializeDomain(Domain* domain) = 0;
52 53
53 54 void emitUpdated();
54 55 void setDirty(bool dirty);
55 56 bool isDirty(){ return m_dirty; };
56 57 void setOrientation(Qt::Orientation orientation);
57 58 Qt::Orientation orientation() const { return m_orientation; }
58 59
59 60 virtual void setMin(const QVariant &min) = 0;
60 61 virtual qreal min() = 0;
61 62
62 63 virtual void setMax(const QVariant &max) = 0;
63 64 virtual qreal max() = 0;
64 65
66 virtual int count() const = 0;
67
65 68 virtual void setRange(const QVariant &min, const QVariant &max) = 0;
66 69
67 70 public Q_SLOTS:
68 71 virtual void handleDomainUpdated() = 0;
69 72
70 73 Q_SIGNALS:
71 74 void updated();
72 75
73 76 protected:
74 77 QAbstractAxis *q_ptr;
75 78 Qt::Orientation m_orientation;
79 ChartDataSet *m_dataset;
76 80
77 81 private:
78 82 bool m_visible;
79 83
80 84 bool m_arrowVisible;
81 85 QPen m_axisPen;
82 86 QBrush m_axisBrush;
83 87
84 88 bool m_gridLineVisible;
85 89 QPen m_gridLinePen;
86 90
87 91 bool m_labelsVisible;
88 92 QPen m_labelsPen;
89 93 QBrush m_labelsBrush;
90 94 QFont m_labelsFont;
91 95 int m_labelsAngle;
92 96
93 97 bool m_shadesVisible;
94 98 QPen m_shadesPen;
95 99 QBrush m_shadesBrush;
96 100 qreal m_shadesOpacity;
97 101
98 102 bool m_dirty;
99 103
100 104 friend class QAbstractAxis;
105 friend class ChartDataSet;
101 106 };
102 107
103 108 QTCOMMERCIALCHART_END_NAMESPACE
104 109
105 110 #endif
@@ -1,367 +1,373
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 "qvaluesaxis.h"
22 22 #include "qvaluesaxis_p.h"
23 23 #include "chartvaluesaxisx_p.h"
24 24 #include "chartvaluesaxisy_p.h"
25 25 #include "domain_p.h"
26 #include <cmath>
27 #include <QDebug>
26 #include "chartdataset_p.h"
27 #include <qmath.h>
28
28 29
29 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 31 /*!
31 32 \class QValuesAxis
32 33 \brief The QValuesAxis class is used for manipulating chart's axis.
33 34 \mainclass
34 35
35 36 ValuesAxis can be setup to show axis line with tick marks, grid lines and shades.
36 37 Values of axis are drawn to position of ticks
37 38 */
38 39
39 40 /*!
40 41 \qmlclass ValuesAxis QValuesAxis
41 42 \brief The ValuesAxis element is used for manipulating chart's axes
42 43
43 44 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
44 45 Values of axis are drawn to position of ticks
45 46
46 47 To access Axes you can use ChartView API. For example:
47 48 \code
48 49 ChartView {
49 50 ValuesAxis {
50 51 id: xAxis
51 52 min: 0
52 53 max: 10
53 54 }
54 55 // Add a few series...
55 56 }
56 57 \endcode
57 58 */
58 59
59 60 /*!
60 61 \property QValuesAxis::min
61 62 Defines the minimum value on the axis.
62 63 */
63 64 /*!
64 65 \qmlproperty real ValuesAxis::min
65 66 Defines the minimum value on the axis.
66 67 */
67 68
68 69 /*!
69 70 \property QValuesAxis::max
70 71 Defines the maximum value on the axis.
71 72 */
72 73 /*!
73 74 \qmlproperty real ValuesAxis::max
74 75 Defines the maximum value on the axis.
75 76 */
76 77
77 78 /*!
78 79 \fn void QValuesAxis::minChanged(qreal min)
79 80 Axis emits signal when \a min of axis has changed.
80 81 */
81 82 /*!
82 83 \qmlsignal ValuesAxis::onMinChanged(real min)
83 84 Axis emits signal when \a min of axis has changed.
84 85 */
85 86
86 87 /*!
87 88 \fn void QValuesAxis::maxChanged(qreal max)
88 89 Axis emits signal when \a max of axis has changed.
89 90 */
90 91 /*!
91 92 \qmlsignal ValuesAxis::onMaxChanged(real max)
92 93 Axis emits signal when \a max of axis has changed.
93 94 */
94 95
95 96 /*!
96 97 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
97 98 Axis emits signal when \a min or \a max of axis has changed.
98 99 */
99 100
100 101 /*!
101 102 \property QValuesAxis::ticksCount
102 103 The number of tick marks for the axis.
103 104 */
104 105
105 106 /*!
106 107 \qmlproperty int ValuesAxis::ticksCount
107 108 The number of tick marks for the axis.
108 109 */
109 110
110 111 /*!
111 112 \property QValuesAxis::niceNumbersEnabled
112 113 Whether the nice numbers algorithm is enabled or not for the axis.
113 114 */
114 115
115 116 /*!
116 117 \qmlproperty bool ValuesAxis::niceNumbersEnabled
117 118 Whether the nice numbers algorithm is enabled or not for the axis.
118 119 */
119 120
120 121 /*!
121 122 Constructs an axis object which is a child of \a parent.
122 123 */
123 124 QValuesAxis::QValuesAxis(QObject *parent) :
124 125 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
125 126 {
126 127
127 128 }
128 129
129 130 /*!
130 131 \internal
131 132 */
132 133 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
133 134 {
134 135
135 136 }
136 137
137 138 /*!
138 139 Destroys the object
139 140 */
140 141 QValuesAxis::~QValuesAxis()
141 142 {
142
143 Q_D(QValuesAxis);
144 if(d->m_dataset) {
145 d->m_dataset->removeAxis(this);
146 }
143 147 }
144 148
145 149 void QValuesAxis::setMin(qreal min)
146 150 {
147 151 Q_D(QValuesAxis);
148 152 setRange(min,d->m_max);
149 153 }
150 154
151 155 qreal QValuesAxis::min() const
152 156 {
153 157 Q_D(const QValuesAxis);
154 158 return d->m_min;
155 159 }
156 160
157 161 void QValuesAxis::setMax(qreal max)
158 162 {
159 163 Q_D(QValuesAxis);
160 164 setRange(d->m_min,max);
161 165 }
162 166
163 167 qreal QValuesAxis::max() const
164 168 {
165 169 Q_D(const QValuesAxis);
166 170 return d->m_max;
167 171 }
168 172
169 173 /*!
170 174 Sets range from \a min to \a max on the axis.
171 175 */
172 176 void QValuesAxis::setRange(qreal min, qreal max)
173 177 {
178 if(max<min) return;
179
174 180 Q_D(QValuesAxis);
175 181 bool changed = false;
176 182
177 183 if (!qFuzzyIsNull(d->m_min - min)) {
178 184 d->m_min = min;
179 185 changed = true;
180 186 emit minChanged(min);
181 187 }
182 188
183 189 if (!qFuzzyIsNull(d->m_max - max)) {
184 190 d->m_max = max;
185 191 changed = true;
186 192 emit maxChanged(max);
187 193 }
188 194
189 195 if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount);
190 196
191 197 if (changed) {
192 198 emit rangeChanged(d->m_min,d->m_max);
193 199 d->emitUpdated();
194 200 }
195 201 }
196 202
197 203 /*!
198 204 Sets \a count for ticks on the axis.
199 205 */
200 206 void QValuesAxis::setTicksCount(int count)
201 207 {
202 208 Q_D(QValuesAxis);
203 209 if (d->m_tickCount != count && count >=2) {
204 210 d->m_tickCount = count;
205 211 d->emitUpdated();
206 212 }
207 213 }
208 214
209 215 /*!
210 216 \fn int QValuesAxis::ticksCount() const
211 217 Return number of ticks on the axis
212 218 */
213 219 int QValuesAxis::ticksCount() const
214 220 {
215 221 Q_D(const QValuesAxis);
216 222 return d->m_tickCount;
217 223 }
218 224
219 225 void QValuesAxis::setNiceNumbersEnabled(bool enable)
220 226 {
221 227 Q_D(QValuesAxis);
222 228 if (d->m_niceNumbers != enable){
223 229 d->m_niceNumbers = enable;
224 230 if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) setRange(d->min(),d->max());
225 231 }
226 232 }
227 233
228 234 bool QValuesAxis::niceNumbersEnabled() const
229 235 {
230 236 Q_D(const QValuesAxis);
231 237 return d->m_niceNumbers;
232 238 }
233 239
234 240 /*!
235 241 Returns the type of the axis
236 242 */
237 243 QAbstractAxis::AxisType QValuesAxis::type() const
238 244 {
239 245 return AxisTypeValues;
240 246 }
241 247
242 248 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
243 249
244 250 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
245 251 QAbstractAxisPrivate(q),
246 252 m_min(0),
247 253 m_max(0),
248 254 m_tickCount(5),
249 255 m_niceNumbers(false)
250 256 {
251 257
252 258 }
253 259
254 260 QValuesAxisPrivate::~QValuesAxisPrivate()
255 261 {
256 262
257 263 }
258 264
259 265 void QValuesAxisPrivate::handleDomainUpdated()
260 266 {
261 267 Q_Q(QValuesAxis);
262 268 Domain* domain = qobject_cast<Domain*>(sender());
263 269 Q_ASSERT(domain);
264 270
265 271 if(orientation()==Qt::Horizontal){
266 272 q->setRange(domain->minX(),domain->maxX());
267 273 }else if(orientation()==Qt::Vertical){
268 274 q->setRange(domain->minY(),domain->maxY());
269 275 }
270 276 }
271 277
272 278
273 279 void QValuesAxisPrivate::setMin(const QVariant &min)
274 280 {
275 281 Q_Q(QValuesAxis);
276 282 bool ok;
277 283 qreal value = min.toReal(&ok);
278 284 if(ok) q->setMin(value);
279 285 }
280 286
281 287 void QValuesAxisPrivate::setMax(const QVariant &max)
282 288 {
283 289
284 290 Q_Q(QValuesAxis);
285 291 bool ok;
286 292 qreal value = max.toReal(&ok);
287 293 if(ok) q->setMax(value);
288 294 }
289 295
290 296 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
291 297 {
292 298 Q_Q(QValuesAxis);
293 299 bool ok1;
294 300 bool ok2;
295 301 qreal value1 = min.toReal(&ok1);
296 302 qreal value2 = max.toReal(&ok2);
297 303 if(ok1&&ok2) q->setRange(value1,value2);
298 304 }
299 305
300 306 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
301 307 {
302 308 Q_Q(QValuesAxis);
303 309 if(m_orientation == Qt::Vertical){
304 310 return new ChartValuesAxisY(q,presenter);
305 311 }else{
306 312 return new ChartValuesAxisX(q,presenter);
307 313 }
308 314
309 315 }
310 316
311 317 void QValuesAxisPrivate::intializeDomain(Domain* domain)
312 318 {
313 319 Q_Q(QValuesAxis);
314 320 if(qFuzzyCompare(m_max,m_min)) {
315 321 if(m_orientation==Qt::Vertical){
316 322 q->setRange(domain->minY(),domain->maxY());
317 323 }else{
318 324 q->setRange(domain->minX(), domain->maxX());
319 325 }
320 326 } else {
321 327 if(m_orientation==Qt::Vertical){
322 328 domain->setRangeY(m_min, m_max);
323 329 }else{
324 330 domain->setRangeX(m_min, m_max);
325 331 }
326 332 }
327 333 }
328 334
329 335 //algorithm defined by Paul S.Heckbert GraphicalGems I
330 336
331 337 void QValuesAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
332 338 {
333 339 qreal range = niceNumber(max-min,true); //range with ceiling
334 340 qreal step = niceNumber(range/(ticksCount-1),false);
335 min = floor(min/step);
336 max = ceil(max/step);
341 min = qFloor(min/step);
342 max = qCeil(max/step);
337 343 ticksCount = int(max-min) +1;
338 344 min*=step;
339 345 max*=step;
340 346 }
341 347
342 348 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
343 349
344 350 qreal QValuesAxisPrivate::niceNumber(qreal x,bool ceiling) const
345 351 {
346 qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
352 qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
347 353 qreal q = x/z;//q<10 && q>=1;
348 354
349 355 if(ceiling) {
350 356 if(q <= 1.0) q=1;
351 357 else if(q <= 2.0) q=2;
352 358 else if(q <= 5.0) q=5;
353 359 else q=10;
354 360 }
355 361 else {
356 362 if(q < 1.5) q=1;
357 363 else if(q < 3.0) q=2;
358 364 else if(q < 7.0) q=5;
359 365 else q=10;
360 366 }
361 367 return q*z;
362 368 }
363 369
364 370 #include "moc_qvaluesaxis.cpp"
365 371 #include "moc_qvaluesaxis_p.cpp"
366 372
367 373 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,72 +1,72
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 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QVALUESAXIS_P_H
31 31 #define QVALUESAXIS_P_H
32 32
33 33 #include "qvaluesaxis.h"
34 34 #include "qabstractaxis_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class QValuesAxisPrivate : public QAbstractAxisPrivate
39 39 {
40 40 Q_OBJECT
41 41 public:
42 42 QValuesAxisPrivate(QValuesAxis *q);
43 43 ~QValuesAxisPrivate();
44 44
45 45 public:
46 46 ChartAxis* createGraphics(ChartPresenter* presenter);
47 47 void intializeDomain(Domain* domain);
48 48 void handleDomainUpdated();
49 49 qreal min(){ return m_min; };
50 50 qreal max(){ return m_max; };
51 int count() const { return m_tickCount;}
51 52
52 53 protected:
53 54 void setMin(const QVariant &min);
54 55 void setMax(const QVariant &max);
55 56 void setRange(const QVariant &min, const QVariant &max);
56 int ticksCount() const;
57 57
58 58 private:
59 59 void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const;
60 60 qreal niceNumber(qreal x,bool ceiling) const;
61 61
62 protected:
62 private:
63 63 qreal m_min;
64 64 qreal m_max;
65 65 int m_tickCount;
66 66 bool m_niceNumbers;
67 67 Q_DECLARE_PUBLIC(QValuesAxis)
68 68 };
69 69
70 70 QTCOMMERCIALCHART_END_NAMESPACE
71 71
72 72 #endif // QVALUESAXIS_P_H
@@ -1,786 +1,783
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 "qabstractbarseries.h"
22 22 #include "qabstractbarseries_p.h"
23 23 #include "qbarset.h"
24 24 #include "qbarset_p.h"
25 25 #include "domain_p.h"
26 26 #include "legendmarker_p.h"
27 27 #include "chartdataset_p.h"
28 28 #include "charttheme_p.h"
29 29 #include "chartanimator_p.h"
30 30 #include "qvaluesaxis.h"
31 31 #include "qbarcategoriesaxis.h"
32 32
33 33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 34
35 35 /*!
36 36 \class QAbstractBarSeries
37 37 \brief Series for creating a bar chart
38 38 \mainclass
39 39
40 40 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
41 41 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
42 42 and y-value is the height of the bar. The category names are ignored with this series and x-axis
43 43 shows the x-values.
44 44
45 45 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
46 46 \image examples_barchart.png
47 47
48 48 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
49 49 */
50 50 /*!
51 51 \qmlclass AbstractBarSeries QAbstractBarSeries
52 52 \inherits QAbstractSeries
53 53
54 54 The following QML shows how to create a simple bar chart:
55 55 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
56 56
57 57 \beginfloatleft
58 58 \image demos_qmlchart6.png
59 59 \endfloat
60 60 \clearfloat
61 61 */
62 62
63 63 /*!
64 64 \property QAbstractBarSeries::barWidth
65 65 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
66 66 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
67 67 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
68 68 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
69 69 \sa QBarSeries
70 70 */
71 71 /*!
72 72 \qmlproperty real AbstractBarSeries::barWidth
73 73 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
74 74 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
75 75 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
76 76 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
77 77 */
78 78
79 79 /*!
80 80 \property QAbstractBarSeries::count
81 81 Holds the number of sets in series.
82 82 */
83 83 /*!
84 84 \qmlproperty int AbstractBarSeries::count
85 85 Holds the number of sets in series.
86 86 */
87 87
88 88 /*!
89 89 \property QAbstractBarSeries::labelsVisible
90 90 Defines the visibility of the labels in series
91 91 */
92 92 /*!
93 93 \qmlproperty bool AbstractBarSeries::labelsVisible
94 94 Defines the visibility of the labels in series
95 95 */
96 96
97 97 /*!
98 98 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
99 99 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
100 100 Clicked bar inside set is indexed by \a index
101 101 */
102 102 /*!
103 103 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
104 104 The signal is emitted if the user clicks with a mouse on top of BarSet.
105 105 Clicked bar inside set is indexed by \a index
106 106 */
107 107
108 108 /*!
109 109 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
110 110
111 111 The signal is emitted if mouse is hovered on top of series.
112 112 Parameter \a barset is the pointer of barset, where hover happened.
113 113 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
114 114 */
115 115 /*!
116 116 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
117 117
118 118 The signal is emitted if mouse is hovered on top of series.
119 119 Parameter \a barset is the pointer of barset, where hover happened.
120 120 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
121 121 */
122 122
123 123 /*!
124 124 \fn void QAbstractBarSeries::countChanged()
125 125 This signal is emitted when barset count has been changed, for example by append or remove.
126 126 */
127 127 /*!
128 128 \qmlsignal AbstractBarSeries::onCountChanged()
129 129 This signal is emitted when barset count has been changed, for example by append or remove.
130 130 */
131 131
132 132 /*!
133 133 \fn void QAbstractBarSeries::labelsVisibleChanged()
134 134 This signal is emitted when labels visibility have changed.
135 135 \sa isLabelsVisible(), setLabelsVisible()
136 136 */
137 137
138 138 /*!
139 139 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
140 140 This signal is emitted when \a sets have been added to the series.
141 141 \sa append(), insert()
142 142 */
143 143 /*!
144 144 \qmlsignal AbstractBarSeries::onAdded(BarSet barset)
145 145 Emitted when \a barset has been added to the series.
146 146 */
147 147
148 148 /*!
149 149 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
150 150 This signal is emitted when \a sets have been removed from the series.
151 151 \sa remove()
152 152 */
153 153 /*!
154 154 \qmlsignal AbstractBarSeries::onRemoved(BarSet barset)
155 155 Emitted when \a barset has been removed from the series.
156 156 */
157 157
158 158 /*!
159 159 \qmlmethod BarSet AbstractBarSeries::at(int index)
160 160 Returns bar set at \a index. Returns null if the index is not valid.
161 161 */
162 162
163 163 /*!
164 164 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
165 165 Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
166 166 For example:
167 167 \code
168 168 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
169 169 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
170 170 \endcode
171 171 */
172 172
173 173 /*!
174 174 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
175 175 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
176 176 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
177 177 appended.
178 178 \sa AbstractBarSeries::append()
179 179 */
180 180
181 181 /*!
182 182 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
183 183 Removes the barset from the series. Returns true if successfull, false otherwise.
184 184 */
185 185
186 186 /*!
187 187 \qmlmethod AbstractBarSeries::clear()
188 188 Removes all barsets from the series.
189 189 */
190 190
191 191 /*!
192 192 This is depreciated constructor.
193 193 */
194 194 QAbstractBarSeries::QAbstractBarSeries(QObject *parent) :
195 195 QAbstractSeries(*(QAbstractBarSeriesPrivate*)(0),parent)
196 196 {
197 197 }
198 198
199 199 /*!
200 200 Destructs abstractbarseries and owned barsets.
201 201 */
202 202 QAbstractBarSeries::~QAbstractBarSeries()
203 203 {
204 Q_D(QAbstractBarSeries);
205 if(d->m_dataset){
206 d->m_dataset->removeSeries(this);
207 }
204
208 205 }
209 206
210 207 /*!
211 208 \internal
212 209 */
213 210 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
214 211 QAbstractSeries(d,parent)
215 212 {
216 213 }
217 214
218 215 /*!
219 216 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
220 217 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
221 218 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
222 219 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
223 220 */
224 221 void QAbstractBarSeries::setBarWidth(qreal width)
225 222 {
226 223 Q_D(QAbstractBarSeries);
227 224 d->setBarWidth(width);
228 225 }
229 226
230 227 /*!
231 228 Returns the width of the bars of the series.
232 229 \sa setBarWidth()
233 230 */
234 231 qreal QAbstractBarSeries::barWidth() const
235 232 {
236 233 Q_D(const QAbstractBarSeries);
237 234 return d->barWidth();
238 235 }
239 236
240 237 /*!
241 238 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
242 239 Returns true, if appending succeeded.
243 240 */
244 241 bool QAbstractBarSeries::append(QBarSet *set)
245 242 {
246 243 Q_D(QAbstractBarSeries);
247 244 bool success = d->append(set);
248 245 if (success) {
249 246 QList<QBarSet*> sets;
250 247 sets.append(set);
251 248 emit barsetsAdded(sets);
252 249 emit countChanged();
253 250 }
254 251 return success;
255 252 }
256 253
257 254 /*!
258 255 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
259 256 Returns true, if set was removed.
260 257 */
261 258 bool QAbstractBarSeries::remove(QBarSet *set)
262 259 {
263 260 Q_D(QAbstractBarSeries);
264 261 bool success = d->remove(set);
265 262 if (success) {
266 263 QList<QBarSet*> sets;
267 264 sets.append(set);
268 265 emit barsetsRemoved(sets);
269 266 emit countChanged();
270 267 }
271 268 return success;
272 269 }
273 270
274 271 /*!
275 272 Adds a list of barsets to series. Takes ownership of \a sets.
276 273 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
277 274 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
278 275 and function returns false.
279 276 */
280 277 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
281 278 {
282 279 Q_D(QAbstractBarSeries);
283 280 bool success = d->append(sets);
284 281 if (success) {
285 282 emit barsetsAdded(sets);
286 283 emit countChanged();
287 284 }
288 285 return success;
289 286 }
290 287
291 288 /*!
292 289 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
293 290 Returns true, if inserting succeeded.
294 291
295 292 */
296 293 bool QAbstractBarSeries::insert(int index, QBarSet *set)
297 294 {
298 295 Q_D(QAbstractBarSeries);
299 296 bool success = d->insert(index, set);
300 297 if (success) {
301 298 QList<QBarSet*> sets;
302 299 sets.append(set);
303 300 emit barsetsAdded(sets);
304 301 emit countChanged();
305 302 }
306 303 return success;
307 304 }
308 305
309 306 /*!
310 307 Removes all of the bar sets from the series
311 308 */
312 309 void QAbstractBarSeries::clear()
313 310 {
314 311 Q_D(QAbstractBarSeries);
315 312 QList<QBarSet *> sets = barSets();
316 313 bool success = d->remove(sets);
317 314 if (success) {
318 315 emit barsetsRemoved(sets);
319 316 emit countChanged();
320 317 }
321 318 }
322 319
323 320 /*!
324 321 Returns number of sets in series.
325 322 */
326 323 int QAbstractBarSeries::count() const
327 324 {
328 325 Q_D(const QAbstractBarSeries);
329 326 return d->m_barSets.count();
330 327 }
331 328
332 329 /*!
333 330 Returns a list of sets in series. Keeps ownership of sets.
334 331 */
335 332 QList<QBarSet*> QAbstractBarSeries::barSets() const
336 333 {
337 334 Q_D(const QAbstractBarSeries);
338 335 return d->m_barSets;
339 336 }
340 337
341 338 /*!
342 339 Sets the visibility of labels in series to \a visible
343 340 */
344 341 void QAbstractBarSeries::setLabelsVisible(bool visible)
345 342 {
346 343 Q_D(QAbstractBarSeries);
347 344 if (d->m_labelsVisible != visible) {
348 345 d->setLabelsVisible(visible);
349 346 emit labelsVisibleChanged();
350 347 }
351 348 }
352 349
353 350 /*!
354 351 Returns the visibility of labels
355 352 */
356 353 bool QAbstractBarSeries::isLabelsVisible() const
357 354 {
358 355 Q_D(const QAbstractBarSeries);
359 356 return d->m_labelsVisible;
360 357 }
361 358
362 359 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
363 360
364 361 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
365 362 QAbstractSeriesPrivate(q),
366 363 m_barWidth(0.5), // Default value is 50% of category width
367 364 m_labelsVisible(false),
368 365 m_visible(true)
369 366 {
370 367 }
371 368
372 369 int QAbstractBarSeriesPrivate::categoryCount() const
373 370 {
374 371 // No categories defined. return count of longest set.
375 372 int count = 0;
376 373 for (int i=0; i<m_barSets.count(); i++) {
377 374 if (m_barSets.at(i)->count() > count) {
378 375 count = m_barSets.at(i)->count();
379 376 }
380 377 }
381 378
382 379 return count;
383 380 }
384 381
385 382 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
386 383 {
387 384 if (width < 0.0) {
388 385 width = 0.0;
389 386 }
390 387 m_barWidth = width;
391 388 emit updatedBars();
392 389 }
393 390
394 391 qreal QAbstractBarSeriesPrivate::barWidth() const
395 392 {
396 393 return m_barWidth;
397 394 }
398 395
399 396 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
400 397 {
401 398 return m_barSets.at(index);
402 399 }
403 400
404 401 void QAbstractBarSeriesPrivate::setVisible(bool visible)
405 402 {
406 403 m_visible = visible;
407 404 emit updatedBars();
408 405 }
409 406
410 407 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
411 408 {
412 409 m_labelsVisible = visible;
413 410 emit labelsVisibleChanged(visible);
414 411 }
415 412
416 413 qreal QAbstractBarSeriesPrivate::min()
417 414 {
418 415 if (m_barSets.count() <= 0) {
419 416 return 0;
420 417 }
421 418 qreal min = INT_MAX;
422 419
423 420 for (int i = 0; i < m_barSets.count(); i++) {
424 421 int categoryCount = m_barSets.at(i)->count();
425 422 for (int j = 0; j < categoryCount; j++) {
426 423 qreal temp = m_barSets.at(i)->at(j);
427 424 if (temp < min)
428 425 min = temp;
429 426 }
430 427 }
431 428 return min;
432 429 }
433 430
434 431 qreal QAbstractBarSeriesPrivate::max()
435 432 {
436 433 if (m_barSets.count() <= 0) {
437 434 return 0;
438 435 }
439 436 qreal max = INT_MIN;
440 437
441 438 for (int i = 0; i < m_barSets.count(); i++) {
442 439 int categoryCount = m_barSets.at(i)->count();
443 440 for (int j = 0; j < categoryCount; j++) {
444 441 qreal temp = m_barSets.at(i)->at(j);
445 442 if (temp > max)
446 443 max = temp;
447 444 }
448 445 }
449 446
450 447 return max;
451 448 }
452 449
453 450 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
454 451 {
455 452 if ((set < 0) || (set >= m_barSets.count())) {
456 453 // No set, no value.
457 454 return 0;
458 455 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
459 456 // No category, no value.
460 457 return 0;
461 458 }
462 459
463 460 return m_barSets.at(set)->at(category);
464 461 }
465 462
466 463 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
467 464 {
468 465 if ((set < 0) || (set >= m_barSets.count())) {
469 466 // No set, no value.
470 467 return 0;
471 468 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
472 469 // No category, no value.
473 470 return 0;
474 471 }
475 472
476 473 qreal value = m_barSets.at(set)->at(category);
477 474 qreal sum = categorySum(category);
478 475 if ( qFuzzyIsNull(sum) ) {
479 476 return 0;
480 477 }
481 478
482 479 return value / sum;
483 480 }
484 481
485 482 qreal QAbstractBarSeriesPrivate::categorySum(int category)
486 483 {
487 484 qreal sum(0);
488 485 int count = m_barSets.count(); // Count sets
489 486 for (int set = 0; set < count; set++) {
490 487 if (category < m_barSets.at(set)->count())
491 488 sum += m_barSets.at(set)->at(category);
492 489 }
493 490 return sum;
494 491 }
495 492
496 493 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
497 494 {
498 495 qreal sum(0);
499 496 int count = m_barSets.count(); // Count sets
500 497 for (int set = 0; set < count; set++) {
501 498 if (category < m_barSets.at(set)->count())
502 499 sum += qAbs(m_barSets.at(set)->at(category));
503 500 }
504 501 return sum;
505 502 }
506 503
507 504 qreal QAbstractBarSeriesPrivate::maxCategorySum()
508 505 {
509 506 qreal max = INT_MIN;
510 507 int count = categoryCount();
511 508 for (int i = 0; i < count; i++) {
512 509 qreal sum = categorySum(i);
513 510 if (sum > max)
514 511 max = sum;
515 512 }
516 513 return max;
517 514 }
518 515
519 516 qreal QAbstractBarSeriesPrivate::minX()
520 517 {
521 518 if (m_barSets.count() <= 0) {
522 519 return 0;
523 520 }
524 521 qreal min = INT_MAX;
525 522
526 523 for (int i = 0; i < m_barSets.count(); i++) {
527 524 int categoryCount = m_barSets.at(i)->count();
528 525 for (int j = 0; j < categoryCount; j++) {
529 526 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
530 527 if (temp < min)
531 528 min = temp;
532 529 }
533 530 }
534 531 return min;
535 532 }
536 533
537 534 qreal QAbstractBarSeriesPrivate::maxX()
538 535 {
539 536 if (m_barSets.count() <= 0) {
540 537 return 0;
541 538 }
542 539 qreal max = INT_MIN;
543 540
544 541 for (int i = 0; i < m_barSets.count(); i++) {
545 542 int categoryCount = m_barSets.at(i)->count();
546 543 for (int j = 0; j < categoryCount; j++) {
547 544 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
548 545 if (temp > max)
549 546 max = temp;
550 547 }
551 548 }
552 549
553 550 return max;
554 551 }
555 552
556 553
557 554 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
558 555 {
559 556 qreal minX(domain.minX());
560 557 qreal minY(domain.minY());
561 558 qreal maxX(domain.maxX());
562 559 qreal maxY(domain.maxY());
563 560
564 561 qreal seriesMinX = this->minX();
565 562 qreal seriesMaxX = this->maxX();
566 563 qreal y = max();
567 564 minX = qMin(minX, seriesMinX - (qreal)0.5);
568 565 minY = qMin(minY, y);
569 566 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
570 567 maxY = qMax(maxY, y);
571 568
572 569 domain.setRange(minX,maxX,minY,maxY);
573 570 }
574 571
575 572 Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
576 573 {
577 574 Q_UNUSED(presenter);
578 575 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
579 576 return 0;
580 577 }
581 578
582 579 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
583 580 {
584 581 Q_Q(QAbstractBarSeries);
585 582 QList<LegendMarker*> markers;
586 583 foreach(QBarSet* set, q->barSets()) {
587 584 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
588 585 markers << marker;
589 586 }
590 587
591 588 return markers;
592 589 }
593 590
594 591 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
595 592 {
596 593 Q_Q(QAbstractBarSeries);
597 594 if ((m_barSets.contains(set)) || (set == 0)) {
598 595 // Fail if set is already in list or set is null.
599 596 return false;
600 597 }
601 598 m_barSets.append(set);
602 599 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
603 600 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
604 601 emit restructuredBars(); // this notifies barchartitem
605 602 if (m_dataset) {
606 603 m_dataset->updateSeries(q); // this notifies legend
607 604 }
608 605 return true;
609 606 }
610 607
611 608 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
612 609 {
613 610 Q_Q(QAbstractBarSeries);
614 611 if (!m_barSets.contains(set)) {
615 612 // Fail if set is not in list
616 613 return false;
617 614 }
618 615 m_barSets.removeOne(set);
619 616 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
620 617 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
621 618 emit restructuredBars(); // this notifies barchartitem
622 619 if (m_dataset) {
623 620 m_dataset->updateSeries(q); // this notifies legend
624 621 }
625 622 return true;
626 623 }
627 624
628 625 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
629 626 {
630 627 Q_Q(QAbstractBarSeries);
631 628 foreach (QBarSet* set, sets) {
632 629 if ((set == 0) || (m_barSets.contains(set))) {
633 630 // Fail if any of the sets is null or is already appended.
634 631 return false;
635 632 }
636 633 if (sets.count(set) != 1) {
637 634 // Also fail if same set is more than once in given list.
638 635 return false;
639 636 }
640 637 }
641 638
642 639 foreach (QBarSet* set, sets) {
643 640 m_barSets.append(set);
644 641 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
645 642 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
646 643 }
647 644 emit restructuredBars(); // this notifies barchartitem
648 645 if (m_dataset) {
649 646 m_dataset->updateSeries(q); // this notifies legend
650 647 }
651 648 return true;
652 649 }
653 650
654 651 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
655 652 {
656 653 Q_Q(QAbstractBarSeries);
657 654 if (sets.count() == 0) {
658 655 return false;
659 656 }
660 657 foreach (QBarSet* set, sets) {
661 658 if ((set == 0) || (!m_barSets.contains(set))) {
662 659 // Fail if any of the sets is null or is not in series
663 660 return false;
664 661 }
665 662 if (sets.count(set) != 1) {
666 663 // Also fail if same set is more than once in given list.
667 664 return false;
668 665 }
669 666 }
670 667
671 668 foreach (QBarSet* set, sets) {
672 669 m_barSets.removeOne(set);
673 670 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
674 671 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
675 672 }
676 673
677 674 emit restructuredBars(); // this notifies barchartitem
678 675 if (m_dataset) {
679 676 m_dataset->updateSeries(q); // this notifies legend
680 677 }
681 678 return true;
682 679 }
683 680
684 681 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
685 682 {
686 683 Q_Q(QAbstractBarSeries);
687 684 if ((m_barSets.contains(set)) || (set == 0)) {
688 685 // Fail if set is already in list or set is null.
689 686 return false;
690 687 }
691 688 m_barSets.insert(index, set);
692 689 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
693 690 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
694 691 emit restructuredBars(); // this notifies barchartitem
695 692 if (m_dataset) {
696 693 m_dataset->updateSeries(q); // this notifies legend
697 694 }
698 695 return true;
699 696 }
700 697
701 698 void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis)
702 699 {
703 700 Q_Q(QAbstractBarSeries);
704 701
705 702 if(axis->type()==QAbstractAxis::AxisTypeCategories) {
706 703
707 704 switch(q->type()) {
708 705
709 706 case QAbstractSeries::SeriesTypeHorizontalBar:
710 707 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
711 708 case QAbstractSeries::SeriesTypeHorizontalStackedBar: {
712 709
713 710 if(axis->orientation()==Qt::Vertical)
714 711 {
715 712 populateCategories(qobject_cast<QBarCategoriesAxis*>(axis));
716 713 }
717 714 break;
718 715 }
719 716 case QAbstractSeries::SeriesTypeBar:
720 717 case QAbstractSeries::SeriesTypePercentBar:
721 718 case QAbstractSeries::SeriesTypeStackedBar: {
722 719
723 720 if(axis->orientation()==Qt::Horizontal)
724 721 {
725 722 populateCategories(qobject_cast<QBarCategoriesAxis*>(axis));
726 723 }
727 724 break;
728 725 }
729 726 default:
730 727 qWarning()<<"Unexpected series type";
731 728 break;
732 729
733 730 }
734 731 }
735 732 }
736 733
737 734 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
738 735 {
739 736 Q_Q(const QAbstractBarSeries);
740 737
741 738 switch(q->type()) {
742 739
743 740 case QAbstractSeries::SeriesTypeHorizontalBar:
744 741 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
745 742 case QAbstractSeries::SeriesTypeHorizontalStackedBar: {
746 743
747 744 if(orientation==Qt::Vertical)
748 745 {
749 746 return QAbstractAxis::AxisTypeCategories;
750 747 }
751 748 break;
752 749 }
753 750 case QAbstractSeries::SeriesTypeBar:
754 751 case QAbstractSeries::SeriesTypePercentBar:
755 752 case QAbstractSeries::SeriesTypeStackedBar: {
756 753
757 754 if(orientation==Qt::Horizontal)
758 755 {
759 756 return QAbstractAxis::AxisTypeCategories;
760 757 }
761 758 break;
762 759 }
763 760 default:
764 761 qWarning()<<"Unexpected series type";
765 762 break;
766 763
767 764 }
768 765 return QAbstractAxis::AxisTypeValues;
769 766
770 767 }
771 768
772 769 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoriesAxis* axis)
773 770 {
774 771 QStringList categories;
775 772 if(axis->categories().isEmpty()) {
776 773 for (int i(1); i < categoryCount()+1; i++)
777 774 categories << QString::number(i);
778 775 axis->append(categories);
779 776 }
780 777 }
781 778
782 779 #include "moc_qabstractbarseries.cpp"
783 780 #include "moc_qabstractbarseries_p.cpp"
784 781
785 782
786 783 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,117 +1,125
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 "qbarseries.h"
22 22 #include "qbarseries_p.h"
23 23 #include "barchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "chartanimator_p.h"
27 27 #include "baranimation_p.h"
28 28 #include "qvaluesaxis.h"
29 29 #include "qbarcategoriesaxis.h"
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 /*!
34 34 \class QBarSeries
35 35 \brief Series for creating bar chart
36 36 \mainclass
37 37
38 38 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
39 39 as groups, where bars in same category are grouped next to each other. QBarSeries groups the data
40 40 from sets to categories, which are defined by a QStringList.
41 41
42 42 See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart.
43 43 \image examples_barchart.png
44 44
45 45 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries
46 46 */
47 47 /*!
48 48 \qmlclass BarSeries QBarSeries
49 49 \inherits AbstractBarSeries
50 50
51 51 The following QML shows how to create a simple grouped bar chart:
52 52 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
53 53 \beginfloatleft
54 54 \image demos_qmlchart6.png
55 55 \endfloat
56 56 \clearfloat
57 57 */
58 58
59 59 /*!
60 60 Constructs empty QBarSeries.
61 61 QBarSeries is QObject which is a child of a \a parent.
62 62 */
63 63 QBarSeries::QBarSeries(QObject *parent)
64 64 : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent)
65 65 {
66 66 }
67 67
68 68 /*!
69 69 Returns QChartSeries::SeriesTypeBar.
70 70 */
71 71 QAbstractSeries::SeriesType QBarSeries::type() const
72 72 {
73 73 return QAbstractSeries::SeriesTypeBar;
74 74 }
75 75
76 QBarSeries::~QBarSeries() {
77
78 Q_D(QBarSeries);
79 if(d->m_dataset) {
80 d->m_dataset->removeSeries(this);
81 }
82
83 }
76 84 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77 85
78 86 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q)
79 87 {
80 88
81 89 }
82 90
83 91 void QBarSeriesPrivate::scaleDomain(Domain& domain)
84 92 {
85 93 qreal minX(domain.minX());
86 94 qreal minY(domain.minY());
87 95 qreal maxX(domain.maxX());
88 96 qreal maxY(domain.maxY());
89 97
90 98 qreal x = categoryCount();
91 99 qreal y = max();
92 100 minX = qMin(minX, - (qreal)0.5);
93 101 minY = qMin(minY, y);
94 102 maxX = qMax(maxX, x - (qreal)0.5);
95 103 maxY = qMax(maxY, y);
96 104
97 105 domain.setRange(minX,maxX,minY,maxY);
98 106 }
99 107
100 108
101 109 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
102 110 {
103 111 Q_Q(QBarSeries);
104 112
105 113 BarChartItem* bar = new BarChartItem(q,presenter);
106 114 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
107 115 bar->setAnimator(presenter->animator());
108 116 bar->setAnimation(new BarAnimation(bar));
109 117 }
110 118 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
111 119 return bar;
112 120 }
113 121
114 122 #include "moc_qbarseries.cpp"
115 123
116 124 QTCOMMERCIALCHART_END_NAMESPACE
117 125
@@ -1,44 +1,45
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 #ifndef QBARSERIES_H
22 22 #define QBARSERIES_H
23 23
24 24 #include <qabstractbarseries.h>
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 class QBarSeriesPrivate;
29 29
30 30 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractBarSeries
31 31 {
32 32 Q_OBJECT
33 33 public:
34 34 explicit QBarSeries(QObject *parent = 0);
35 ~QBarSeries();
35 36 QAbstractSeries::SeriesType type() const;
36 37
37 38 private:
38 39 Q_DECLARE_PRIVATE(QBarSeries)
39 40 Q_DISABLE_COPY(QBarSeries)
40 41 };
41 42
42 43 QTCOMMERCIALCHART_END_NAMESPACE
43 44
44 45 #endif // QBARSERIES_H
@@ -1,441 +1,471
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 axis->d_ptr->m_dataset = this;
205 206 axis->d_ptr->intializeDomain(domain);
206 207 series->d_ptr->initializeAxis(axis);
207 208 if(axis->orientation()==Qt::Horizontal) {
208 209 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
209 210 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
210 211 m_seriesAxisXMap.insert(series,axis);
211 212 }
212 213 else {
213 214 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
214 215 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
215 216 m_seriesAxisYMap.insert(series,axis);
216 217 }
217 218 axis->d_ptr->emitUpdated();
218 219 }
219 220
220 221 void ChartDataSet::removeAxes(QAbstractSeries* series)
221 222 {
222 223 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
223 224
224 225 if(axisX) {
225 226 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
226 227 int x = axesX.indexOf(axisX);
227 228
228 229 if(x==-1) {
229 230 emit axisRemoved(axisX);
231 axisX->d_ptr->m_dataset=0;
230 232 axisX->deleteLater();
231 233 }
232 234 }
233 235
234 236 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
235 237
236 238 if(axisY) {
237 239 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
238 240
239 241 int y = axesY.indexOf(axisY);
240 242
241 243 if(y==-1) {
242 244 emit axisRemoved(axisY);
245 axisY->d_ptr->m_dataset=0;
243 246 axisY->deleteLater();
244 247 }
245 248 }
246 249 }
247 250
251 void ChartDataSet::removeAxis(QAbstractAxis* axis)
252 {
253 if(!axis->d_ptr->m_dataset) {
254 qWarning()<<"UnBound axis found !";
255 return;
256 }
257
258 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
259
260 if(axis->orientation()==Qt::Vertical) {
261 seriesAxisMap= &m_seriesAxisYMap;
262 }
263 else {
264 seriesAxisMap= &m_seriesAxisXMap;
265 }
266
267 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(*seriesAxisMap);
268
269 while (i.hasNext()) {
270 i.next();
271 if(i.value()==axis) {
272 removeSeries(i.key());
273 }
274 }
275 }
276
248 277 void ChartDataSet::removeAllSeries()
249 278 {
250 279 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
251 280 foreach(QAbstractSeries *s , series) {
252 281 removeSeries(s);
253 282 }
254 283
255 284 Q_ASSERT(m_seriesAxisXMap.count()==0);
256 285 Q_ASSERT(m_seriesAxisXMap.count()==0);
257 286 Q_ASSERT(m_seriesDomainMap.count()==0);
258 287
259 288 qDeleteAll(series);
260 289 }
261 290
262 291 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
263 292 {
264 293 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
265 294
266 295
267 296 blockAxisSignals(true);
268 297
269 298 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
270 299
271 300 while (i.hasNext()) {
272 301 i.next();
273 302 i.value()->zoomIn(rect,size);
274 303 }
275 304
276 305 blockAxisSignals(false);
277 306
278 307 }
279 308
280 309 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
281 310 {
282 311 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
283 312
284 313 blockAxisSignals(true);
285 314
286 315 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
287 316
288 317 while (i.hasNext()) {
289 318 i.next();
290 319 i.value()->zoomOut(rect,size);
291 320 }
292 321
293 322 blockAxisSignals(false);
294 323 }
295 324
296 325 void ChartDataSet::blockAxisSignals(bool enabled)
297 326 {
298 327 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
299 328 while (i.hasNext()) {
300 329 i.next();
301 330 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
302 331 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
303 332 if(axisX) axisX->d_ptr->blockSignals(enabled);
304 333 if(axisY) axisY->d_ptr->blockSignals(enabled);
305 334 }
306 335 }
307 336
308 337 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
309 338 {
310 339 int count=0;
311 340 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
312 341 while (i.hasNext()) {
313 342 i.next();
314 343 if(i.key()->type()==type) count++;
315 344 }
316 345 return count;
317 346 }
318 347
319 348 int ChartDataSet::seriesIndex(QAbstractSeries *series)
320 349 {
321 350 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
322 351 while (i.hasNext()) {
323 352 i.next();
324 353 if (i.value() == series)
325 354 return i.key();
326 355 }
327 356 return -1;
328 357 }
329 358
330 359 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
331 360 {
332 361 if(series == 0) {
333 362
334 363 QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap);
335 364
336 365 while (i.hasNext()) {
337 366 i.next();
338 367 if(i.value()->isVisible()) return i.value();
339 368 }
340 369 return 0;
341 370 }
342 371 return m_seriesAxisXMap.value(series);
343 372 }
344 373
345 374 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
346 375 {
347 376 if(series == 0) {
348 377 QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap);
349 378
350 379 while (i.hasNext()) {
351 380 i.next();
352 381 if(i.value()->isVisible()) return i.value();
353 382 }
354 383 return 0;
355 384 }
356 385 return m_seriesAxisYMap.value(series);
357 386 }
358 387
359 388 void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation)
360 389 {
361 390 Q_ASSERT(axis);
362 391
363 392 if(!series) {
364 393 qWarning() << "Series not found on the chart.";
365 394 return;
366 395 }
367 396
368 397 Domain* domain = m_seriesDomainMap.value(series);
369 398
370 399 if(!domain) {
371 400 qWarning() << "Series not found on the chart.";
372 401 return;
373 402 }
374 403
375 404 if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) {
376 405 qWarning()<<"Axis already defined as axis Y";
377 406 return;
378 407 }
379 408
380 409 if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) {
381 410 qWarning()<<"Axis already defined as axis X";
382 411 return;
383 412 }
384 413
385 414 axis->d_ptr->setOrientation(orientation);
386 415
387 416 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
388 417
389 418 if(orientation==Qt::Vertical) {
390 419 seriesAxisMap= &m_seriesAxisYMap;
391 420 }else{
392 421 seriesAxisMap= &m_seriesAxisXMap;
393 422 }
394 423
395 424 QAbstractAxis *oldAxis = seriesAxisMap->take(series);
396 425 QList<QAbstractAxis*> axes = seriesAxisMap->values();
397 426
398 427 if(oldAxis) {
399 428 if(axes.indexOf(oldAxis)==-1) {
400 429 emit axisRemoved(oldAxis);
430 oldAxis->d_ptr->m_dataset=0;
401 431 oldAxis->deleteLater();
402 432 }
403 433 }
404 434
405 435 if(axes.indexOf(axis)==-1) {
406 436 initializeAxis(axis,series);
407 437 emit axisAdded(axis,domain);
408 438 }else{
409 439 initializeAxis(axis,series);
410 440 }
411 441 }
412 442
413 443 Domain* ChartDataSet::domain(QAbstractSeries *series) const
414 444 {
415 445 return m_seriesDomainMap.value(series);
416 446 }
417 447
418 448 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
419 449 {
420 450 blockAxisSignals(true);
421 451 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
422 452 while (i.hasNext()) {
423 453 i.next();
424 454 i.value()->move(dx,dy,size);
425 455 }
426 456 blockAxisSignals(false);
427 457 }
428 458
429 459 QList<QAbstractSeries*> ChartDataSet::series() const
430 460 {
431 461 return m_seriesDomainMap.keys();
432 462 }
433 463
434 464 void ChartDataSet::updateSeries(QAbstractSeries *series)
435 465 {
436 466 emit seriesUpdated(series);
437 467 }
438 468
439 469 #include "moc_chartdataset_p.cpp"
440 470
441 471 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,99 +1,100
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 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef CHARTDATASET_P_H
31 31 #define CHARTDATASET_P_H
32 32
33 33 #include "qabstractseries.h"
34 34 #include "domain_p.h"
35 35 #include "qabstractaxis_p.h"
36 36 #include <QVector>
37 37
38 38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 39
40 40 class QAbstractAxis;
41 41
42 42 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
43 43 {
44 44 Q_OBJECT
45 45 public:
46 46 ChartDataSet(QChart* parent=0);
47 47 virtual ~ChartDataSet();
48 48
49 49 void addSeries(QAbstractSeries* series);
50 50 void removeSeries(QAbstractSeries* series);
51 51 void removeAllSeries();
52 52 void updateSeries(QAbstractSeries* series);
53 53
54 54 void zoomInDomain(const QRectF& rect, const QSizeF& size);
55 55 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
56 56 void scrollDomain(qreal dx,qreal dy,const QSizeF& size);
57 57
58 58 int seriesCount(QAbstractSeries::SeriesType type);
59 59 int seriesIndex(QAbstractSeries *series);
60 60
61 61 QAbstractAxis* axisX(QAbstractSeries *series) const;
62 62 QAbstractAxis* axisY(QAbstractSeries *series) const;
63 63
64 64 void setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation);
65 65
66 66 QList<QAbstractSeries*> series() const;
67 67 Domain* domain(QAbstractSeries *series) const;
68 68
69 void removeAxis(QAbstractAxis* axis);
69 70 void createDefaultAxes();
70 71
71 72 Q_SIGNALS:
72 73 void seriesAdded(QAbstractSeries* series, Domain* domain);
73 74 void seriesRemoved(QAbstractSeries* series);
74 75 void seriesUpdated(QAbstractSeries* series);
75 76 void axisAdded(QAbstractAxis* axis,Domain* domain);
76 77 void axisRemoved(QAbstractAxis* axis);
77 78
78 79 private:
79 80 void calculateDomain(QAbstractSeries* series,Domain* domain);
80 81 void createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation);
81 82 QAbstractAxis* createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation);
82 83 void initializeAxis(QAbstractAxis* axis,QAbstractSeries* series);
83 84 void removeAxes(QAbstractSeries* series);
84 85 void blockAxisSignals(bool enabled);
85 86 void createSeriesIndex(QAbstractSeries* series);
86 87 void removeSeriesIndex(QAbstractSeries* series);
87 88
88 89 private:
89 90 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap;
90 91 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap;
91 92 QMap<QAbstractSeries*, Domain*> m_seriesDomainMap;
92 93 QMap<int, QAbstractSeries*> m_indexSeriesMap;
93 94 int m_domainIndex;
94 95
95 96 };
96 97
97 98 QTCOMMERCIALCHART_END_NAMESPACE
98 99
99 100 #endif /* CHARTENGINE_P_H_ */
@@ -1,29 +1,30
1 1 !include( ../tests.pri ) {
2 2 error( "Couldn't find the tests.pri file!" )
3 3 }
4 4
5 5 TEMPLATE = subdirs
6 6 SUBDIRS += \
7 7 qchartview \
8 8 qchart \
9 9 qlineseries \
10 10 qbarset \
11 11 qbarseries \
12 12 qstackedbarseries \
13 13 qpercentbarseries \
14 14 qpieslice qpieseries \
15 15 qpiemodelmapper \
16 16 qsplineseries \
17 17 qscatterseries \
18 18 qxymodelmapper \
19 19 qbarmodelmapper \
20 20 qhorizontalbarseries \
21 21 qhorizontalstackedbarseries \
22 22 qhorizontalpercentbarseries \
23 23 qvaluesaxis \
24 24 qintervalsaxis \
25 qdatetimeaxis
25 qdatetimeaxis \
26 qbarcategoriesaxis
26 27
27 28 test_private:{
28 29 SUBDIRS += domain chartdataset
29 30 }
@@ -1,848 +1,847
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 "tst_qabstractaxis.h"
22 22
23 23 Q_DECLARE_METATYPE(QPen)
24 24 Q_DECLARE_METATYPE(Qt::Orientation)
25 25
26 26 void tst_QAbstractAxis::initTestCase()
27 27 {
28 28 }
29 29
30 30 void tst_QAbstractAxis::cleanupTestCase()
31 31 {
32 32 }
33 33
34 34 void tst_QAbstractAxis::init(QAbstractAxis* axis, QAbstractSeries* series)
35 35 {
36 36 m_axis = axis;
37 37 m_series = series;
38 38 m_view = new QChartView(new QChart());
39 39 m_chart = m_view->chart();
40 40 }
41 41
42 42 void tst_QAbstractAxis::cleanup()
43 43 {
44
45 44 delete m_view;
46 45 m_view = 0;
47 46 m_chart = 0;
48 47 m_axis = 0;
49 48 }
50 49
51 50 void tst_QAbstractAxis::qabstractaxis()
52 51 {
53 52 QCOMPARE(m_axis->axisPen(), QPen());
54 53 //TODO QCOMPARE(m_axis->axisPenColor(), QColor());
55 54 QCOMPARE(m_axis->gridLinePen(), QPen());
56 55 QCOMPARE(m_axis->isArrowVisible(), true);
57 56 QCOMPARE(m_axis->isGridLineVisible(), true);
58 57 QCOMPARE(m_axis->isVisible(), false);
59 58 QCOMPARE(m_axis->labelsAngle(), 0);
60 59 QCOMPARE(m_axis->labelsBrush(), QBrush());
61 60 //TODO QCOMPARE(m_axis->labelsColor(), QColor());
62 61 QCOMPARE(m_axis->labelsFont(), QFont());
63 62 QCOMPARE(m_axis->labelsPen(), QPen());
64 63 QCOMPARE(m_axis->labelsVisible(), true);
65 64 QCOMPARE(m_axis->orientation(), Qt::Orientation(0));
66 65 m_axis->setArrowVisible(false);
67 66 m_axis->setAxisPen(QPen());
68 67 m_axis->setAxisPenColor(QColor());
69 68 m_axis->setGridLinePen(QPen());
70 69 m_axis->setGridLineVisible(false);
71 70 m_axis->setLabelsAngle(-1);
72 71 m_axis->setLabelsBrush(QBrush());
73 72 m_axis->setLabelsColor(QColor());
74 73 m_axis->setLabelsFont(QFont());
75 74 m_axis->setLabelsPen(QPen());
76 75 m_axis->setLabelsVisible(false);
77 76 m_axis->setMax(QVariant());
78 77 m_axis->setMin(QVariant());
79 78 m_axis->setRange(QVariant(), QVariant());
80 79 m_axis->setShadesBorderColor(QColor());
81 80 m_axis->setShadesBrush(QBrush());
82 81 m_axis->setShadesColor(QColor());
83 82 m_axis->setShadesPen(QPen());
84 83 m_axis->setShadesVisible(false);
85 84 m_axis->setVisible(false);
86 85 //TODO QCOMPARE(m_axis->shadesBorderColor(), QColor());
87 86 //TODO QCOMPARE(m_axis->shadesBrush(), QBrush());
88 87 //TODO QCOMPARE(m_axis->shadesColor(), QColor());
89 88 QCOMPARE(m_axis->shadesPen(), QPen());
90 89 QCOMPARE(m_axis->shadesVisible(), false);
91 90 m_axis->show();
92 91 m_axis->hide();
93 92 }
94 93
95 94 void tst_QAbstractAxis::axisPen_data()
96 95 {
97 96 QTest::addColumn<QPen>("axisPen");
98 97 QTest::newRow("null") << QPen();
99 98 QTest::newRow("blue") << QPen(Qt::blue);
100 99 QTest::newRow("black") << QPen(Qt::black);
101 100 QTest::newRow("red") << QPen(Qt::red);
102 101 }
103 102
104 103 void tst_QAbstractAxis::axisPen()
105 104 {
106 105 QFETCH(QPen, axisPen);
107 106
108 107 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
109 108 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
110 109 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
111 110 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
112 111 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
113 112 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
114 113 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
115 114 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
116 115 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
117 116
118 117 m_axis->setAxisPen(axisPen);
119 118 QCOMPARE(m_axis->axisPen(), axisPen);
120 119
121 120 QCOMPARE(spy0.count(), 0);
122 121 QCOMPARE(spy1.count(), 0);
123 122 QCOMPARE(spy2.count(), 0);
124 123 QCOMPARE(spy3.count(), 0);
125 124 QCOMPARE(spy4.count(), 0);
126 125 QCOMPARE(spy5.count(), 0);
127 126 QCOMPARE(spy6.count(), 0);
128 127 QCOMPARE(spy7.count(), 0);
129 128 QCOMPARE(spy8.count(), 0);
130 129
131 130 m_chart->setAxisX(m_axis, m_series);
132 131 m_view->show();
133 132 QTest::qWaitForWindowShown(m_view);
134 133 //TODO QCOMPARE(m_axis->axisPen(), axisPen);
135 134 }
136 135
137 136 void tst_QAbstractAxis::axisPenColor_data()
138 137 {
139 138 }
140 139
141 140 void tst_QAbstractAxis::axisPenColor()
142 141 {
143 142 QSKIP("Test is not implemented. This is depreciated function", SkipAll);
144 143 }
145 144
146 145 void tst_QAbstractAxis::gridLinePen_data()
147 146 {
148 147
149 148 QTest::addColumn<QPen>("gridLinePen");
150 149 QTest::newRow("null") << QPen();
151 150 QTest::newRow("blue") << QPen(Qt::blue);
152 151 QTest::newRow("black") << QPen(Qt::black);
153 152 QTest::newRow("red") << QPen(Qt::red);
154 153
155 154 }
156 155
157 156 void tst_QAbstractAxis::gridLinePen()
158 157 {
159 158 QFETCH(QPen, gridLinePen);
160 159
161 160 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
162 161 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
163 162 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
164 163 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
165 164 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
166 165 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
167 166 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
168 167 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
169 168 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
170 169
171 170 m_axis->setGridLinePen(gridLinePen);
172 171 QCOMPARE(m_axis->gridLinePen(), gridLinePen);
173 172
174 173 QCOMPARE(spy0.count(), 0);
175 174 QCOMPARE(spy1.count(), 0);
176 175 QCOMPARE(spy2.count(), 0);
177 176 QCOMPARE(spy3.count(), 0);
178 177 QCOMPARE(spy4.count(), 0);
179 178 QCOMPARE(spy5.count(), 0);
180 179 QCOMPARE(spy6.count(), 0);
181 180 QCOMPARE(spy7.count(), 0);
182 181 QCOMPARE(spy8.count(), 0);
183 182
184 183 m_chart->setAxisX(m_axis, m_series);
185 184 m_view->show();
186 185 QTest::qWaitForWindowShown(m_view);
187 186 //TODO QCOMPARE(m_axis->gridLinePen(), gridLinePen);
188 187 }
189 188
190 189 void tst_QAbstractAxis::arrowVisible_data()
191 190 {
192 191 QTest::addColumn<bool>("arrowVisible");
193 192 QTest::newRow("true") << true;
194 193 QTest::newRow("false") << false;
195 194 }
196 195
197 196 void tst_QAbstractAxis::arrowVisible()
198 197 {
199 198 QFETCH(bool, arrowVisible);
200 199
201 200 m_axis->setArrowVisible(!arrowVisible);
202 201
203 202 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
204 203 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
205 204 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
206 205 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
207 206 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
208 207 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
209 208 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
210 209 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
211 210 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
212 211
213 212 m_axis->setArrowVisible(arrowVisible);
214 213 QCOMPARE(m_axis->isArrowVisible(), arrowVisible);
215 214
216 215 QCOMPARE(spy0.count(), 1);
217 216 QCOMPARE(spy1.count(), 0);
218 217 QCOMPARE(spy2.count(), 0);
219 218 QCOMPARE(spy3.count(), 0);
220 219 QCOMPARE(spy4.count(), 0);
221 220 QCOMPARE(spy5.count(), 0);
222 221 QCOMPARE(spy6.count(), 0);
223 222 QCOMPARE(spy7.count(), 0);
224 223 QCOMPARE(spy8.count(), 0);
225 224
226 225 m_chart->setAxisX(m_axis, m_series);
227 226 m_view->show();
228 227 QTest::qWaitForWindowShown(m_view);
229 228 QCOMPARE(m_axis->isArrowVisible(), arrowVisible);
230 229 }
231 230
232 231 void tst_QAbstractAxis::gridLineVisible_data()
233 232 {
234 233 QTest::addColumn<bool>("gridLineVisible");
235 234 QTest::newRow("true") << true;
236 235 QTest::newRow("false") << false;
237 236 }
238 237
239 238 void tst_QAbstractAxis::gridLineVisible()
240 239 {
241 240 QFETCH(bool, gridLineVisible);
242 241
243 242 m_axis->setGridLineVisible(!gridLineVisible);
244 243
245 244 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
246 245 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
247 246 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
248 247 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
249 248 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
250 249 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
251 250 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
252 251 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
253 252 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
254 253
255 254 m_axis->setGridLineVisible(gridLineVisible);
256 255 QCOMPARE(m_axis->isGridLineVisible(), gridLineVisible);
257 256
258 257 QCOMPARE(spy0.count(), 0);
259 258 QCOMPARE(spy1.count(), 0);
260 259 QCOMPARE(spy2.count(), 1);
261 260 QCOMPARE(spy3.count(), 0);
262 261 QCOMPARE(spy4.count(), 0);
263 262 QCOMPARE(spy5.count(), 0);
264 263 QCOMPARE(spy6.count(), 0);
265 264 QCOMPARE(spy7.count(), 0);
266 265 QCOMPARE(spy8.count(), 0);
267 266
268 267 m_chart->setAxisX(m_axis, m_series);
269 268 m_view->show();
270 269 QTest::qWaitForWindowShown(m_view);
271 270 QCOMPARE(m_axis->isGridLineVisible(), gridLineVisible);
272 271
273 272 }
274 273
275 274 void tst_QAbstractAxis::visible_data()
276 275 {
277 276 QTest::addColumn<bool>("visible");
278 277 QTest::newRow("true") << true;
279 278 QTest::newRow("false") << false;
280 279 }
281 280
282 281 void tst_QAbstractAxis::visible()
283 282 {
284 283 QFETCH(bool, visible);
285 284
286 285 m_axis->setVisible(!visible);
287 286
288 287 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
289 288 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
290 289 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
291 290 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
292 291 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
293 292 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
294 293 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
295 294 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
296 295 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
297 296
298 297 m_axis->setVisible(visible);
299 298 QCOMPARE(m_axis->isVisible(), visible);
300 299
301 300 QCOMPARE(spy0.count(), 0);
302 301 QCOMPARE(spy1.count(), 0);
303 302 QCOMPARE(spy2.count(), 0);
304 303 QCOMPARE(spy3.count(), 0);
305 304 QCOMPARE(spy4.count(), 0);
306 305 QCOMPARE(spy5.count(), 0);
307 306 QCOMPARE(spy6.count(), 0);
308 307 QCOMPARE(spy7.count(), 0);
309 308 QCOMPARE(spy8.count(), 1);
310 309
311 310 m_chart->setAxisX(m_axis, m_series);
312 311 m_view->show();
313 312 QTest::qWaitForWindowShown(m_view);
314 313 QCOMPARE(m_axis->isVisible(), true);
315 314 }
316 315
317 316 void tst_QAbstractAxis::labelsAngle_data()
318 317 {
319 318 QTest::addColumn<int>("labelsAngle");
320 319 QTest::newRow("0") << 0;
321 320 QTest::newRow("45") << 45;
322 321 QTest::newRow("90") << 90;
323 322 }
324 323
325 324 void tst_QAbstractAxis::labelsAngle()
326 325 {
327 326 QFETCH(int, labelsAngle);
328 327
329 328 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
330 329 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
331 330 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
332 331 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
333 332 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
334 333 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
335 334 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
336 335 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
337 336 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
338 337
339 338 m_axis->setLabelsAngle(labelsAngle);
340 339 QCOMPARE(m_axis->labelsAngle(), labelsAngle);
341 340
342 341 QCOMPARE(spy0.count(), 0);
343 342 QCOMPARE(spy1.count(), 0);
344 343 QCOMPARE(spy2.count(), 0);
345 344 QCOMPARE(spy3.count(), 0);
346 345 QCOMPARE(spy4.count(), 0);
347 346 QCOMPARE(spy5.count(), 0);
348 347 QCOMPARE(spy6.count(), 0);
349 348 QCOMPARE(spy7.count(), 0);
350 349 QCOMPARE(spy8.count(), 0);
351 350
352 351 m_chart->setAxisX(m_axis, m_series);
353 352 m_view->show();
354 353 QTest::qWaitForWindowShown(m_view);
355 354 QCOMPARE(m_axis->labelsAngle(), labelsAngle);
356 355 }
357 356
358 357 void tst_QAbstractAxis::labelsBrush_data()
359 358 {
360 359 QTest::addColumn<QBrush>("labelsBrush");
361 360 QTest::newRow("null") << QBrush();
362 361 QTest::newRow("blue") << QBrush(Qt::blue);
363 362 QTest::newRow("black") << QBrush(Qt::black);
364 363
365 364 }
366 365
367 366 void tst_QAbstractAxis::labelsBrush()
368 367 {
369 368
370 369 QFETCH(QBrush, labelsBrush);
371 370
372 371 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
373 372 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
374 373 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
375 374 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
376 375 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
377 376 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
378 377 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
379 378 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
380 379 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
381 380
382 381 m_axis->setLabelsBrush(labelsBrush);
383 382 QCOMPARE(m_axis->labelsBrush(), labelsBrush);
384 383
385 384 QCOMPARE(spy0.count(), 0);
386 385 QCOMPARE(spy1.count(), 0);
387 386 QCOMPARE(spy2.count(), 0);
388 387 QCOMPARE(spy3.count(), 0);
389 388 QCOMPARE(spy4.count(), 0);
390 389 QCOMPARE(spy5.count(), 0);
391 390 //TODO QCOMPARE(spy6.count(), 0);
392 391 QCOMPARE(spy7.count(), 0);
393 392 QCOMPARE(spy8.count(), 0);
394 393
395 394 m_view->show();
396 395 QTest::qWaitForWindowShown(m_view);
397 396 QCOMPARE(m_axis->labelsBrush(), labelsBrush);
398 397
399 398 }
400 399
401 400 void tst_QAbstractAxis::labelsColor_data()
402 401 {
403 402
404 403 }
405 404
406 405 void tst_QAbstractAxis::labelsColor()
407 406 {
408 407 QSKIP("Test is not implemented. This is depreciated function", SkipAll);
409 408 }
410 409
411 410 void tst_QAbstractAxis::labelsFont_data()
412 411 {
413 412 QTest::addColumn<QFont>("labelsFont");
414 413 QTest::newRow("null") << QFont();
415 414 QTest::newRow("serif") << QFont("SansSerif");
416 415 }
417 416
418 417 void tst_QAbstractAxis::labelsFont()
419 418 {
420 419
421 420 QFETCH(QFont, labelsFont);
422 421
423 422 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
424 423 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
425 424 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
426 425 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
427 426 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
428 427 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
429 428 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
430 429 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
431 430 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
432 431
433 432 m_axis->setLabelsFont(labelsFont);
434 433 QCOMPARE(m_axis->labelsFont(), labelsFont);
435 434
436 435 QCOMPARE(spy0.count(), 0);
437 436 QCOMPARE(spy1.count(), 0);
438 437 QCOMPARE(spy2.count(), 0);
439 438 QCOMPARE(spy3.count(), 0);
440 439 QCOMPARE(spy4.count(), 0);
441 440 QCOMPARE(spy5.count(), 0);
442 441 QCOMPARE(spy6.count(), 0);
443 442 QCOMPARE(spy7.count(), 0);
444 443 QCOMPARE(spy8.count(), 0);
445 444
446 445 m_view->show();
447 446 QTest::qWaitForWindowShown(m_view);
448 447 QCOMPARE(m_axis->labelsFont(), labelsFont);
449 448
450 449 }
451 450
452 451 void tst_QAbstractAxis::labelsPen_data()
453 452 {
454 453 QTest::addColumn<QPen>("labelsPen");
455 454 QTest::newRow("null") << QPen();
456 455 QTest::newRow("blue") << QPen(Qt::blue);
457 456 QTest::newRow("black") << QPen(Qt::black);
458 457 QTest::newRow("red") << QPen(Qt::red);
459 458 }
460 459
461 460 void tst_QAbstractAxis::labelsPen()
462 461 {
463 462 QFETCH(QPen, labelsPen);
464 463
465 464 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
466 465 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
467 466 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
468 467 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
469 468 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
470 469 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
471 470 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
472 471 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
473 472 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
474 473
475 474 m_axis->setLabelsPen(labelsPen);
476 475 QCOMPARE(m_axis->labelsPen(), labelsPen);
477 476
478 477 QCOMPARE(spy0.count(), 0);
479 478 QCOMPARE(spy1.count(), 0);
480 479 QCOMPARE(spy2.count(), 0);
481 480 QCOMPARE(spy3.count(), 0);
482 481 QCOMPARE(spy4.count(), 0);
483 482 QCOMPARE(spy5.count(), 0);
484 483 QCOMPARE(spy6.count(), 0);
485 484 QCOMPARE(spy7.count(), 0);
486 485 QCOMPARE(spy8.count(), 0);
487 486
488 487 m_chart->setAxisX(m_axis, m_series);
489 488 m_view->show();
490 489 QTest::qWaitForWindowShown(m_view);
491 490 //TODO QCOMPARE(m_axis->labelsPen(), labelsPen);
492 491 }
493 492
494 493 void tst_QAbstractAxis::labelsVisible_data()
495 494 {
496 495 QTest::addColumn<bool>("labelsVisible");
497 496 QTest::newRow("true") << true;
498 497 QTest::newRow("false") << false;
499 498 }
500 499
501 500 void tst_QAbstractAxis::labelsVisible()
502 501 {
503 502 QFETCH(bool, labelsVisible);
504 503
505 504 m_axis->setLabelsVisible(!labelsVisible);
506 505
507 506 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
508 507 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
509 508 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
510 509 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
511 510 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
512 511 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
513 512 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
514 513 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
515 514 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
516 515
517 516 m_axis->setLabelsVisible(labelsVisible);
518 517 QCOMPARE(m_axis->labelsVisible(), labelsVisible);
519 518
520 519 QCOMPARE(spy0.count(), 0);
521 520 QCOMPARE(spy1.count(), 0);
522 521 QCOMPARE(spy2.count(), 0);
523 522 QCOMPARE(spy3.count(), 0);
524 523 QCOMPARE(spy4.count(), 1);
525 524 QCOMPARE(spy5.count(), 0);
526 525 QCOMPARE(spy6.count(), 0);
527 526 QCOMPARE(spy7.count(), 0);
528 527 QCOMPARE(spy8.count(), 0);
529 528
530 529 m_chart->setAxisX(m_axis, m_series);
531 530 m_view->show();
532 531 QTest::qWaitForWindowShown(m_view);
533 532 QCOMPARE(m_axis->labelsVisible(), labelsVisible);
534 533 }
535 534
536 535 void tst_QAbstractAxis::orientation_data()
537 536 {
538 537 QTest::addColumn<Qt::Orientation>("orientation");
539 538 QTest::newRow("Vertical") << Qt::Vertical;
540 539 QTest::newRow("Horizontal") << Qt::Horizontal;
541 540 }
542 541
543 542 void tst_QAbstractAxis::orientation()
544 543 {
545 544 QFETCH(Qt::Orientation, orientation);
546 545
547 546 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
548 547 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
549 548 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
550 549 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
551 550 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
552 551 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
553 552 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
554 553 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
555 554 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
556 555
557 556 if(orientation==Qt::Vertical){
558 557 m_chart->setAxisY(m_axis,m_series);
559 558 }else{
560 559 m_chart->setAxisX(m_axis,m_series);
561 560 }
562 561 QCOMPARE(m_axis->orientation(), orientation);
563 562
564 563 QCOMPARE(spy0.count(), 0);
565 564 QCOMPARE(spy1.count(), 0);
566 565 QCOMPARE(spy2.count(), 0);
567 566 QCOMPARE(spy3.count(), 0);
568 567 QCOMPARE(spy4.count(), 0);
569 568 QCOMPARE(spy5.count(), 0);
570 569 QCOMPARE(spy6.count(), 0);
571 570 QCOMPARE(spy7.count(), 0);
572 571 QCOMPARE(spy8.count(), 1);
573 572
574 573 m_view->show();
575 574 QTest::qWaitForWindowShown(m_view);
576 575 QCOMPARE(m_axis->orientation(), orientation);
577 576 }
578 577
579 578 void tst_QAbstractAxis::setMax_data()
580 579 {
581 580 //just check if it does not crash
582 581 QTest::addColumn<QVariant>("max");
583 582 QTest::newRow("something") << QVariant("something");
584 583 QTest::newRow("1.0") << QVariant(1.0);
585 584 }
586 585
587 586 void tst_QAbstractAxis::setMax()
588 587 {
589 588 QFETCH(QVariant, max);
590 589 m_axis->setMax(max);
591 590 }
592 591
593 592 void tst_QAbstractAxis::setMin_data()
594 593 {
595 594 //just check if it does not crash
596 595 QTest::addColumn<QVariant>("min");
597 596 QTest::newRow("something") << QVariant("something");
598 597 QTest::newRow("1.0") << QVariant(1.0);
599 598 }
600 599
601 600 // public void setMin(QVariant const& min)
602 601 void tst_QAbstractAxis::setMin()
603 602 {
604 603 QFETCH(QVariant, min);
605 604 m_axis->setMin(min);
606 605 }
607 606
608 607 void tst_QAbstractAxis::setRange_data()
609 608 {
610 609 //just check if it does not crash
611 610 QTest::addColumn<QVariant>("min");
612 611 QTest::addColumn<QVariant>("max");
613 612 QTest::newRow("something") << QVariant("something0") << QVariant("something1");
614 613 QTest::newRow("-1 1") << QVariant(-1.0) << QVariant(1.0);
615 614 }
616 615
617 616 // public void setRange(QVariant const& min, QVariant const& max)
618 617 void tst_QAbstractAxis::setRange()
619 618 {
620 619
621 620 QFETCH(QVariant, min);
622 621 QFETCH(QVariant, max);
623 622 m_axis->setRange(min,max);
624 623 }
625 624
626 625 void tst_QAbstractAxis::shadesBorderColor_data()
627 626 {
628 627
629 628 }
630 629
631 630 void tst_QAbstractAxis::shadesBorderColor()
632 631 {
633 632 QSKIP("Test is not implemented. This is depreciated function", SkipAll);
634 633 }
635 634
636 635 void tst_QAbstractAxis::shadesBrush_data()
637 636 {
638 637 QTest::addColumn<QBrush>("shadesBrush");
639 638 QTest::newRow("null") << QBrush();
640 639 QTest::newRow("blue") << QBrush(Qt::blue);
641 640 QTest::newRow("black") << QBrush(Qt::black);
642 641 }
643 642
644 643 void tst_QAbstractAxis::shadesBrush()
645 644 {
646 645 QFETCH(QBrush, shadesBrush);
647 646
648 647 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
649 648 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
650 649 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
651 650 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
652 651 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
653 652 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
654 653 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
655 654 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
656 655 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
657 656
658 657 m_axis->setShadesBrush(shadesBrush);
659 658 QCOMPARE(m_axis->shadesBrush(), shadesBrush);
660 659
661 660 QCOMPARE(spy0.count(), 0);
662 661 QCOMPARE(spy1.count(), 0);
663 662 QCOMPARE(spy2.count(), 0);
664 663 QCOMPARE(spy3.count(), 0);
665 664 QCOMPARE(spy4.count(), 0);
666 665 QCOMPARE(spy5.count(), 0);
667 666 //TODO QCOMPARE(spy6.count(), 0);
668 667 QCOMPARE(spy7.count(), 0);
669 668 QCOMPARE(spy8.count(), 0);
670 669
671 670 m_view->show();
672 671 QTest::qWaitForWindowShown(m_view);
673 672 QCOMPARE(m_axis->shadesBrush(), shadesBrush);
674 673 }
675 674
676 675 void tst_QAbstractAxis::shadesColor_data()
677 676 {
678 677 }
679 678
680 679 // public QColor shadesColor() const
681 680 void tst_QAbstractAxis::shadesColor()
682 681 {
683 682 QSKIP("Test is not implemented. This is depreciated function", SkipAll);
684 683 }
685 684
686 685 void tst_QAbstractAxis::shadesPen_data()
687 686 {
688 687 QTest::addColumn<QPen>("shadesPen");
689 688 QTest::newRow("null") << QPen();
690 689 QTest::newRow("blue") << QPen(Qt::blue);
691 690 QTest::newRow("black") << QPen(Qt::black);
692 691 QTest::newRow("red") << QPen(Qt::red);
693 692 }
694 693
695 694 void tst_QAbstractAxis::shadesPen()
696 695 {
697 696 QFETCH(QPen, shadesPen);
698 697
699 698 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
700 699 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
701 700 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
702 701 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
703 702 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
704 703 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
705 704 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
706 705 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
707 706 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
708 707
709 708 m_axis->setShadesPen(shadesPen);
710 709 QCOMPARE(m_axis->shadesPen(), shadesPen);
711 710
712 711 QCOMPARE(spy0.count(), 0);
713 712 QCOMPARE(spy1.count(), 0);
714 713 QCOMPARE(spy2.count(), 0);
715 714 QCOMPARE(spy3.count(), 0);
716 715 QCOMPARE(spy4.count(), 0);
717 716 QCOMPARE(spy5.count(), 0);
718 717 QCOMPARE(spy6.count(), 0);
719 718 QCOMPARE(spy7.count(), 0);
720 719 QCOMPARE(spy8.count(), 0);
721 720
722 721 m_chart->setAxisX(m_axis, m_series);
723 722 m_view->show();
724 723 QTest::qWaitForWindowShown(m_view);
725 724 QCOMPARE(m_axis->shadesPen(), shadesPen);
726 725 }
727 726
728 727 void tst_QAbstractAxis::shadesVisible_data()
729 728 {
730 729 QTest::addColumn<bool>("shadesVisible");
731 730 QTest::newRow("true") << true;
732 731 QTest::newRow("false") << false;
733 732 }
734 733
735 734 void tst_QAbstractAxis::shadesVisible()
736 735 {
737 736 QFETCH(bool, shadesVisible);
738 737
739 738 m_axis->setShadesVisible(!shadesVisible);
740 739
741 740 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
742 741 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
743 742 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
744 743 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
745 744 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
746 745 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
747 746 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
748 747 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
749 748 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
750 749
751 750 m_axis->setShadesVisible(shadesVisible);
752 751 QCOMPARE(m_axis->shadesVisible(), shadesVisible);
753 752
754 753 QCOMPARE(spy0.count(), 0);
755 754 QCOMPARE(spy1.count(), 0);
756 755 QCOMPARE(spy2.count(), 0);
757 756 QCOMPARE(spy3.count(), 0);
758 757 QCOMPARE(spy4.count(), 0);
759 758 QCOMPARE(spy5.count(), 0);
760 759 QCOMPARE(spy6.count(), 0);
761 760 QCOMPARE(spy7.count(), 1);
762 761 QCOMPARE(spy8.count(), 0);
763 762
764 763 m_chart->setAxisX(m_axis, m_series);
765 764 m_view->show();
766 765 QTest::qWaitForWindowShown(m_view);
767 766 QCOMPARE(m_axis->shadesVisible(), shadesVisible);
768 767 }
769 768
770 769 void tst_QAbstractAxis::show_data()
771 770 {
772 771
773 772 }
774 773
775 774 void tst_QAbstractAxis::show()
776 775 {
777 776 m_axis->hide();
778 777 QCOMPARE(m_axis->isVisible(), false);
779 778
780 779 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
781 780 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
782 781 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
783 782 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
784 783 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
785 784 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
786 785 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
787 786 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
788 787 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
789 788
790 789 m_axis->show();
791 790
792 791 QCOMPARE(spy0.count(), 0);
793 792 QCOMPARE(spy1.count(), 0);
794 793 QCOMPARE(spy2.count(), 0);
795 794 QCOMPARE(spy3.count(), 0);
796 795 QCOMPARE(spy4.count(), 0);
797 796 QCOMPARE(spy5.count(), 0);
798 797 QCOMPARE(spy6.count(), 0);
799 798 QCOMPARE(spy7.count(), 0);
800 799 QCOMPARE(spy8.count(), 1);
801 800 QCOMPARE(m_axis->isVisible(), true);
802 801 }
803 802
804 803 void tst_QAbstractAxis::hide_data()
805 804 {
806 805
807 806 }
808 807
809 808 void tst_QAbstractAxis::hide()
810 809 {
811 810 m_axis->show();
812 811 QCOMPARE(m_axis->isVisible(),true);
813 812
814 813 QSignalSpy spy0(m_axis, SIGNAL(arrowVisibleChanged(bool)));
815 814 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
816 815 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
817 816 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
818 817 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
819 818 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
820 819 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
821 820 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
822 821 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
823 822
824 823 m_axis->hide();
825 824
826 825 QCOMPARE(spy0.count(), 0);
827 826 QCOMPARE(spy1.count(), 0);
828 827 QCOMPARE(spy2.count(), 0);
829 828 QCOMPARE(spy3.count(), 0);
830 829 QCOMPARE(spy4.count(), 0);
831 830 QCOMPARE(spy5.count(), 0);
832 831 QCOMPARE(spy6.count(), 0);
833 832 QCOMPARE(spy7.count(), 0);
834 833 QCOMPARE(spy8.count(), 1);
835 834 QCOMPARE(m_axis->isVisible(),false);
836 835 }
837 836
838 837
839 838
840 839
841 840
842 841
843 842
844 843
845 844
846 845
847 846
848 847
General Comments 0
You need to be logged in to leave comments. Login now