##// END OF EJS Templates
Docs and dateTime test updated
Marek Rosa -
r1733:51dc153251d2
parent child
Show More
@@ -1,653 +1,655
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 \value AxisTypeIntervals
66 \value AxisTypeDateTime
65 67 */
66 68
67 69 /*!
68 70 *\fn void QAbstractAxis::type() const
69 71 Returns the type of the axis
70 72 */
71 73
72 74 /*!
73 75 \property QAbstractAxis::arrowVisible
74 76 The visibility of the axis arrow
75 77 */
76 78 /*!
77 79 \qmlproperty bool AbstractAxis::arrrowVisible
78 80 The visibility of the axis arrow
79 81 */
80 82
81 83 /*!
82 84 \property QAbstractAxis::labelsVisible
83 85 Defines if axis labels are visible.
84 86 */
85 87 /*!
86 88 \qmlproperty bool AbstractAxis::labelsVisible
87 89 Defines if axis labels are visible.
88 90 */
89 91
90 92 /*!
91 93 \property QAbstractAxis::visible
92 94 The visibility of the axis.
93 95 */
94 96 /*!
95 97 \qmlproperty bool AbstractAxis::visible
96 98 The visibility of the axis.
97 99 */
98 100
99 101 /*!
100 102 \property QAbstractAxis::gridVisible
101 103 The visibility of the grid lines.
102 104 */
103 105 /*!
104 106 \qmlproperty bool AbstractAxis::gridVisible
105 107 The visibility of the grid lines.
106 108 */
107 109
108 110 /*!
109 111 \property QAbstractAxis::color
110 112 The color of the axis and ticks.
111 113 */
112 114 /*!
113 115 \qmlproperty color AbstractAxis::color
114 116 The color of the axis and ticks.
115 117 */
116 118
117 119 /*!
118 120 \property QAbstractAxis::labelsFont
119 121 The font of the axis labels.
120 122 */
121 123
122 124 /*!
123 125 \qmlproperty Font AbstractAxis::labelsFont
124 126 The font of the axis labels.
125 127
126 128 See the \l {Font} {QML Font Element} for detailed documentation.
127 129 */
128 130
129 131 /*!
130 132 \property QAbstractAxis::labelsColor
131 133 The color of the axis labels.
132 134 */
133 135 /*!
134 136 \qmlproperty color AbstractAxis::labelsColor
135 137 The color of the axis labels.
136 138 */
137 139
138 140 /*!
139 141 \property QAbstractAxis::labelsAngle
140 142 The angle of the axis labels in degrees.
141 143 */
142 144 /*!
143 145 \qmlproperty int AbstractAxis::labelsAngle
144 146 The angle of the axis labels in degrees.
145 147 */
146 148
147 149 /*!
148 150 \property QAbstractAxis::shadesVisible
149 151 The visibility of the axis shades.
150 152 */
151 153 /*!
152 154 \qmlproperty bool AbstractAxis::shadesVisible
153 155 The visibility of the axis shades.
154 156 */
155 157
156 158 /*!
157 159 \property QAbstractAxis::shadesColor
158 160 The fill (brush) color of the axis shades.
159 161 */
160 162 /*!
161 163 \qmlproperty color AbstractAxis::shadesColor
162 164 The fill (brush) color of the axis shades.
163 165 */
164 166
165 167 /*!
166 168 \property QAbstractAxis::shadesBorderColor
167 169 The border (pen) color of the axis shades.
168 170 */
169 171 /*!
170 172 \qmlproperty color AbstractAxis::shadesBorderColor
171 173 The border (pen) color of the axis shades.
172 174 */
173 175
174 176 /*!
175 177 \fn void QAbstractAxis::visibleChanged(bool visible)
176 178 Visiblity of the axis has changed to \a visible.
177 179 */
178 180 /*!
179 181 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
180 182 Visiblity of the axis has changed to \a visible.
181 183 */
182 184
183 185 /*!
184 186 \fn void QAbstractAxis::arrowVisibleChanged(bool visible)
185 187 Visiblity of the axis arrow has changed to \a visible.
186 188 */
187 189 /*!
188 190 \qmlsignal AbstractAxis::onArrowVisibleChanged(bool visible)
189 191 Visiblity of the axis arrow has changed to \a visible.
190 192 */
191 193
192 194 /*!
193 195 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
194 196 Visiblity of the labels of the axis has changed to \a visible.
195 197 */
196 198 /*!
197 199 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
198 200 Visiblity of the labels of the axis has changed to \a visible.
199 201 */
200 202
201 203 /*!
202 204 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
203 205 Visiblity of the grid lines of the axis has changed to \a visible.
204 206 */
205 207 /*!
206 208 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
207 209 Visiblity of the grid lines of the axis has changed to \a visible.
208 210 */
209 211
210 212 /*!
211 213 \fn void QAbstractAxis::colorChanged(QColor color)
212 214 Emitted if the \a color of the axis is changed.
213 215 */
214 216 /*!
215 217 \qmlsignal AbstractAxis::onColorChanged(QColor color)
216 218 Emitted if the \a color of the axis is changed.
217 219 */
218 220
219 221 /*!
220 222 \fn void QAbstractAxis::labelsColorChanged(QColor color)
221 223 Emitted if the \a color of the axis labels is changed.
222 224 */
223 225 /*!
224 226 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
225 227 Emitted if the \a color of the axis labels is changed.
226 228 */
227 229
228 230 /*!
229 231 \fn void QAbstractAxis::shadesVisibleChanged(bool)
230 232 Emitted if the visibility of the axis shades is changed to \a visible.
231 233 */
232 234 /*!
233 235 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
234 236 Emitted if the visibility of the axis shades is changed to \a visible.
235 237 */
236 238
237 239 /*!
238 240 \fn void QAbstractAxis::shadesColorChanged(QColor color)
239 241 Emitted if the \a color of the axis shades is changed.
240 242 */
241 243 /*!
242 244 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
243 245 Emitted if the \a color of the axis shades is changed.
244 246 */
245 247
246 248 /*!
247 249 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
248 250 Emitted if the border \a color of the axis shades is changed.
249 251 */
250 252 /*!
251 253 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
252 254 Emitted if the border \a color of the axis shades is changed.
253 255 */
254 256
255 257 /*!
256 258 \internal
257 259 Constructs new axis object which is a child of \a parent. Ownership is taken by
258 260 QChart when axis added.
259 261 */
260 262
261 263 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) :
262 264 QObject(parent),
263 265 d_ptr(&d)
264 266 {
265 267 }
266 268
267 269 /*!
268 270 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
269 271 */
270 272
271 273 QAbstractAxis::~QAbstractAxis()
272 274 {
273 275 if(d_ptr->m_dataset) qFatal("Still binded axis detected !");
274 276 }
275 277
276 278 /*!
277 279 Sets \a pen used to draw axis line and ticks.
278 280 */
279 281 void QAbstractAxis::setAxisPen(const QPen &pen)
280 282 {
281 283 if (d_ptr->m_axisPen!=pen) {
282 284 d_ptr->m_axisPen = pen;
283 285 d_ptr->emitUpdated();
284 286 }
285 287 }
286 288
287 289 /*!
288 290 Returns pen used to draw axis and ticks.
289 291 */
290 292 QPen QAbstractAxis::axisPen() const
291 293 {
292 294 return d_ptr->m_axisPen;
293 295 }
294 296
295 297 void QAbstractAxis::setAxisPenColor(QColor color)
296 298 {
297 299 QPen p = d_ptr->m_axisPen;
298 300 if (p.color() != color) {
299 301 p.setColor(color);
300 302 setAxisPen(p);
301 303 emit colorChanged(color);
302 304 }
303 305 }
304 306
305 307 QColor QAbstractAxis::axisPenColor() const
306 308 {
307 309 return d_ptr->m_axisPen.color();
308 310 }
309 311
310 312 /*!
311 313 Sets if axis and ticks are \a visible.
312 314 */
313 315 void QAbstractAxis::setArrowVisible(bool visible)
314 316 {
315 317 if (d_ptr->m_arrowVisible != visible) {
316 318 d_ptr->m_arrowVisible = visible;
317 319 d_ptr->emitUpdated();
318 320 emit arrowVisibleChanged(visible);
319 321 }
320 322 }
321 323
322 324 bool QAbstractAxis::isArrowVisible() const
323 325 {
324 326 return d_ptr->m_arrowVisible;
325 327 }
326 328
327 329 void QAbstractAxis::setGridLineVisible(bool visible)
328 330 {
329 331 if (d_ptr->m_gridLineVisible != visible) {
330 332 d_ptr->m_gridLineVisible = visible;
331 333 d_ptr->emitUpdated();
332 334 emit gridVisibleChanged(visible);
333 335 }
334 336 }
335 337
336 338 bool QAbstractAxis::isGridLineVisible() const
337 339 {
338 340 return d_ptr->m_gridLineVisible;
339 341 }
340 342
341 343 /*!
342 344 Sets \a pen used to draw grid line.
343 345 */
344 346 void QAbstractAxis::setGridLinePen(const QPen &pen)
345 347 {
346 348 if (d_ptr->m_gridLinePen != pen) {
347 349 d_ptr->m_gridLinePen = pen;
348 350 d_ptr->emitUpdated();
349 351 }
350 352 }
351 353
352 354 /*!
353 355 Returns pen used to draw grid.
354 356 */
355 357 QPen QAbstractAxis::gridLinePen() const
356 358 {
357 359 return d_ptr->m_gridLinePen;
358 360 }
359 361
360 362 void QAbstractAxis::setLabelsVisible(bool visible)
361 363 {
362 364 if (d_ptr->m_labelsVisible != visible) {
363 365 d_ptr->m_labelsVisible = visible;
364 366 d_ptr->emitUpdated();
365 367 emit labelsVisibleChanged(visible);
366 368 }
367 369 }
368 370
369 371 bool QAbstractAxis::labelsVisible() const
370 372 {
371 373 return d_ptr->m_labelsVisible;
372 374 }
373 375
374 376 /*!
375 377 Sets \a pen used to draw labels.
376 378 */
377 379 void QAbstractAxis::setLabelsPen(const QPen &pen)
378 380 {
379 381 if (d_ptr->m_labelsPen != pen) {
380 382 d_ptr->m_labelsPen = pen;
381 383 d_ptr->emitUpdated();
382 384 }
383 385 }
384 386
385 387 /*!
386 388 Returns the pen used to labels.
387 389 */
388 390 QPen QAbstractAxis::labelsPen() const
389 391 {
390 392 return d_ptr->m_labelsPen;
391 393 }
392 394
393 395 /*!
394 396 Sets \a brush used to draw labels.
395 397 */
396 398 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
397 399 {
398 400 if (d_ptr->m_labelsBrush != brush) {
399 401 d_ptr->m_labelsBrush = brush;
400 402 d_ptr->emitUpdated();
401 403 }
402 404 }
403 405
404 406 /*!
405 407 Returns brush used to draw labels.
406 408 */
407 409 QBrush QAbstractAxis::labelsBrush() const
408 410 {
409 411 return d_ptr->m_labelsBrush;
410 412 }
411 413
412 414 /*!
413 415 Sets \a font used to draw labels.
414 416 */
415 417 void QAbstractAxis::setLabelsFont(const QFont &font)
416 418 {
417 419 if (d_ptr->m_labelsFont != font) {
418 420 d_ptr->m_labelsFont = font;
419 421 d_ptr->emitUpdated();
420 422 }
421 423 }
422 424
423 425 /*!
424 426 Returns font used to draw labels.
425 427 */
426 428 QFont QAbstractAxis::labelsFont() const
427 429 {
428 430 return d_ptr->m_labelsFont;
429 431 }
430 432
431 433 void QAbstractAxis::setLabelsAngle(int angle)
432 434 {
433 435 if (d_ptr->m_labelsAngle != angle) {
434 436 d_ptr->m_labelsAngle = angle;
435 437 d_ptr->emitUpdated();
436 438 }
437 439 }
438 440
439 441 int QAbstractAxis::labelsAngle() const
440 442 {
441 443 return d_ptr->m_labelsAngle;
442 444 }
443 445
444 446 void QAbstractAxis::setLabelsColor(QColor color)
445 447 {
446 448 QBrush b = d_ptr->m_labelsBrush;
447 449 if (b.color() != color) {
448 450 b.setColor(color);
449 451 setLabelsBrush(b);
450 452 emit labelsColorChanged(color);
451 453 }
452 454 }
453 455
454 456 QColor QAbstractAxis::labelsColor() const
455 457 {
456 458 return d_ptr->m_labelsBrush.color();
457 459 }
458 460
459 461 void QAbstractAxis::setShadesVisible(bool visible)
460 462 {
461 463 if (d_ptr->m_shadesVisible != visible) {
462 464 d_ptr->m_shadesVisible = visible;
463 465 d_ptr->emitUpdated();
464 466 emit shadesVisibleChanged(visible);
465 467 }
466 468 }
467 469
468 470 bool QAbstractAxis::shadesVisible() const
469 471 {
470 472 return d_ptr->m_shadesVisible;
471 473 }
472 474
473 475 /*!
474 476 Sets \a pen used to draw shades.
475 477 */
476 478 void QAbstractAxis::setShadesPen(const QPen &pen)
477 479 {
478 480 if (d_ptr->m_shadesPen != pen) {
479 481 d_ptr->m_shadesPen = pen;
480 482 d_ptr->emitUpdated();
481 483 }
482 484 }
483 485
484 486 /*!
485 487 Returns pen used to draw shades.
486 488 */
487 489 QPen QAbstractAxis::shadesPen() const
488 490 {
489 491 return d_ptr->m_shadesPen;
490 492 }
491 493
492 494 /*!
493 495 Sets \a brush used to draw shades.
494 496 */
495 497 void QAbstractAxis::setShadesBrush(const QBrush &brush)
496 498 {
497 499 if (d_ptr->m_shadesBrush != brush) {
498 500 d_ptr->m_shadesBrush = brush;
499 501 d_ptr->emitUpdated();
500 502 emit shadesColorChanged(brush.color());
501 503 }
502 504 }
503 505
504 506 /*!
505 507 Returns brush used to draw shades.
506 508 */
507 509 QBrush QAbstractAxis::shadesBrush() const
508 510 {
509 511 return d_ptr->m_shadesBrush;
510 512 }
511 513
512 514 void QAbstractAxis::setShadesColor(QColor color)
513 515 {
514 516 QBrush b = d_ptr->m_shadesBrush;
515 517 b.setColor(color);
516 518 setShadesBrush(b);
517 519 }
518 520
519 521 QColor QAbstractAxis::shadesColor() const
520 522 {
521 523 return d_ptr->m_shadesBrush.color();
522 524 }
523 525
524 526 void QAbstractAxis::setShadesBorderColor(QColor color)
525 527 {
526 528 QPen p = d_ptr->m_shadesPen;
527 529 p.setColor(color);
528 530 setShadesPen(p);
529 531 }
530 532
531 533 QColor QAbstractAxis::shadesBorderColor() const
532 534 {
533 535 return d_ptr->m_shadesPen.color();
534 536 }
535 537
536 538
537 539 bool QAbstractAxis::isVisible() const
538 540 {
539 541 return d_ptr->m_visible;
540 542 }
541 543
542 544 /*!
543 545 Sets axis, shades, labels and grid lines to be visible.
544 546 */
545 547 void QAbstractAxis::setVisible(bool visible)
546 548 {
547 549 if(d_ptr->m_visible!=visible){
548 550 d_ptr->m_visible=visible;
549 551 d_ptr->emitUpdated();
550 552 emit visibleChanged(visible);
551 553 }
552 554 }
553 555
554 556
555 557 /*!
556 558 Sets axis, shades, labels and grid lines to be visible.
557 559 */
558 560 void QAbstractAxis::show()
559 561 {
560 562 setVisible(true);
561 563 }
562 564
563 565 /*!
564 566 Sets axis, shades, labels and grid lines to not be visible.
565 567 */
566 568 void QAbstractAxis::hide()
567 569 {
568 570 setVisible(false);
569 571 }
570 572
571 573 /*!
572 574 Sets the minimum value shown on the axis.
573 575 Depending on the actual axis type the \a min paramter is converted to appropriate type.
574 576 If the conversion is impossible then the function call does nothing
575 577 */
576 578 void QAbstractAxis::setMin(const QVariant &min)
577 579 {
578 580 d_ptr->setMin(min);
579 581 }
580 582
581 583 /*!
582 584 Sets the maximum value shown on the axis.
583 585 Depending on the actual axis type the \a max paramter is converted to appropriate type.
584 586 If the conversion is impossible then the function call does nothing
585 587 */
586 588 void QAbstractAxis::setMax(const QVariant &max)
587 589 {
588 590 d_ptr->setMax(max);
589 591 }
590 592
591 593 /*!
592 594 Sets the range shown on the axis.
593 595 Depending on the actual axis type the \a min and \a max paramters are converted to appropriate types.
594 596 If the conversion is impossible then the function call does nothing.
595 597 */
596 598 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
597 599 {
598 600 d_ptr->setRange(min,max);
599 601 }
600 602
601 603
602 604 Qt::Orientation QAbstractAxis::orientation()
603 605 {
604 606 return d_ptr->m_orientation;
605 607 }
606 608
607 609 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
608 610
609 611 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
610 612 q_ptr(q),
611 613 m_orientation(Qt::Orientation(0)),
612 614 m_dataset(0),
613 615 m_visible(false),
614 616 m_arrowVisible(true),
615 617 m_gridLineVisible(true),
616 618 m_labelsVisible(true),
617 619 m_labelsAngle(0),
618 620 m_shadesVisible(false),
619 621 m_shadesBrush(Qt::SolidPattern),
620 622 m_shadesOpacity(1.0),
621 623 m_dirty(false)
622 624 {
623 625
624 626 }
625 627
626 628 QAbstractAxisPrivate::~QAbstractAxisPrivate()
627 629 {
628 630
629 631 }
630 632
631 633 void QAbstractAxisPrivate::emitUpdated()
632 634 {
633 635 if(!m_dirty){
634 636 m_dirty=true;
635 637 emit updated();
636 638 }
637 639 }
638 640
639 641 void QAbstractAxisPrivate::setDirty(bool dirty)
640 642 {
641 643 m_dirty=dirty;
642 644 }
643 645
644 646 void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation)
645 647 {
646 648 m_orientation=orientation;
647 649 }
648 650
649 651
650 652 #include "moc_qabstractaxis.cpp"
651 653 #include "moc_qabstractaxis_p.cpp"
652 654
653 655 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,845 +1,857
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 "qpieseries.h"
22 22 #include "qpieseries_p.h"
23 23 #include "qpieslice.h"
24 24 #include "qpieslice_p.h"
25 25 #include "pieslicedata_p.h"
26 26 #include "chartdataset_p.h"
27 27 #include "charttheme_p.h"
28 28 #include "chartanimator_p.h"
29 29 #include "legendmarker_p.h"
30 30 #include "qabstractaxis.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 /*!
35 35 \class QPieSeries
36 36 \brief Pie series API for QtCommercial Charts
37 37
38 38 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
39 39 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
40 40 The actual slice size is determined by that relative value.
41 41
42 42 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
43 43 These relate to the actual chart rectangle.
44 44
45 45 By default the pie is defined as a full pie but it can also be a partial pie.
46 46 This can be done by setting a starting angle and angle span to the series.
47 47 Full pie is 360 degrees where 0 is at 12 a'clock.
48 48
49 49 See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
50 50 \image examples_piechart.png
51 51 */
52 52 /*!
53 53 \qmlclass PieSeries QPieSeries
54 54 \inherits AbstractSeries
55 55
56 56 The following QML shows how to create a simple pie chart.
57 57
58 58 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
59 59
60 60 \beginfloatleft
61 61 \image demos_qmlchart1.png
62 62 \endfloat
63 63 \clearfloat
64 64 */
65 65
66 66 /*!
67 67 \property QPieSeries::horizontalPosition
68 68 \brief Defines the horizontal position of the pie.
69 69
70 70 The value is a relative value to the chart rectangle where:
71 71
72 72 \list
73 73 \o 0.0 is the absolute left.
74 74 \o 1.0 is the absolute right.
75 75 \endlist
76 76 Default value is 0.5 (center).
77 77 \sa verticalPosition
78 78 */
79 79
80 80 /*!
81 81 \qmlproperty real PieSeries::horizontalPosition
82 82
83 83 Defines the horizontal position of the pie.
84 84
85 85 The value is a relative value to the chart rectangle where:
86 86
87 87 \list
88 88 \o 0.0 is the absolute left.
89 89 \o 1.0 is the absolute right.
90 90 \endlist
91 91 Default value is 0.5 (center).
92 92 \sa verticalPosition
93 93 */
94 94
95 95 /*!
96 96 \property QPieSeries::verticalPosition
97 97 \brief Defines the vertical position of the pie.
98 98
99 99 The value is a relative value to the chart rectangle where:
100 100
101 101 \list
102 102 \o 0.0 is the absolute top.
103 103 \o 1.0 is the absolute bottom.
104 104 \endlist
105 105 Default value is 0.5 (center).
106 106 \sa horizontalPosition
107 107 */
108 108
109 109 /*!
110 110 \qmlproperty real PieSeries::verticalPosition
111 111
112 112 Defines the vertical position of the pie.
113 113
114 114 The value is a relative value to the chart rectangle where:
115 115
116 116 \list
117 117 \o 0.0 is the absolute top.
118 118 \o 1.0 is the absolute bottom.
119 119 \endlist
120 120 Default value is 0.5 (center).
121 121 \sa horizontalPosition
122 122 */
123 123
124 124 /*!
125 125 \property QPieSeries::size
126 126 \brief Defines the pie size.
127 127
128 128 The value is a relative value to the chart rectangle where:
129 129
130 130 \list
131 131 \o 0.0 is the minimum size (pie not drawn).
132 132 \o 1.0 is the maximum size that can fit the chart.
133 133 \endlist
134 134
135 135 Default value is 0.7.
136 136 */
137 137
138 138 /*!
139 139 \qmlproperty real PieSeries::size
140 140
141 141 Defines the pie size.
142 142
143 143 The value is a relative value to the chart rectangle where:
144 144
145 145 \list
146 146 \o 0.0 is the minimum size (pie not drawn).
147 147 \o 1.0 is the maximum size that can fit the chart.
148 148 \endlist
149 149
150 150 Default value is 0.7.
151 151 */
152 152
153 153 /*!
154 154 \property QPieSeries::donutInnerSize
155 155 \brief Defines the donut inner size.
156 156
157 157 The value is a relative value to the chart rectangle where:
158 158
159 159 \list
160 160 \o 0.0 is the minimum size (pie not drawn).
161 161 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
162 162 \endlist
163 163
164 164 The value is never greater then size property.
165 165 Default value is 0.5.
166 166 */
167 167
168 168 /*!
169 169 \qmlproperty real PieSeries::donutInnerSize
170 170
171 171 Defines the donut inner size.
172 172
173 173 The value is a relative value to the chart rectangle where:
174 174
175 175 \list
176 176 \o 0.0 is the minimum size (donut is a pie).
177 177 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
178 178 \endlist
179 179
180 180 The value is never greater then size property.
181 181 Default value is 0.5.
182 182 */
183 183
184 184 /*!
185 185 \property QPieSeries::startAngle
186 186 \brief Defines the starting angle of the pie.
187 187
188 188 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
189 189
190 190 Default is value is 0.
191 191 */
192 192
193 193 /*!
194 194 \qmlproperty real PieSeries::startAngle
195 195
196 196 Defines the starting angle of the pie.
197 197
198 198 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
199 199
200 200 Default is value is 0.
201 201 */
202 202
203 203 /*!
204 204 \property QPieSeries::endAngle
205 205 \brief Defines the ending angle of the pie.
206 206
207 207 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
208 208
209 209 Default is value is 360.
210 210 */
211 211
212 212 /*!
213 213 \qmlproperty real PieSeries::endAngle
214 214
215 215 Defines the ending angle of the pie.
216 216
217 217 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
218 218
219 219 Default is value is 360.
220 220 */
221 221
222 222 /*!
223 223 \property QPieSeries::count
224 224
225 225 Number of slices in the series.
226 226 */
227 227
228 228 /*!
229 229 \qmlproperty int PieSeries::count
230 230
231 231 Number of slices in the series.
232 232 */
233 233
234 234 /*!
235 \property QPieSeries::donut
236
237 Defines whether the series should be drawn as a donut
238 */
239
240 /*!
241 \qmlproperty int PieSeries::donut
242
243 Defines whether the series should be drawn as a donut
244 */
245
246 /*!
235 247 \fn void QPieSeries::countChanged()
236 248 Emitted when the slice count has changed.
237 249 \sa count
238 250 */
239 251 /*!
240 252 \qmlsignal PieSeries::onCountChanged()
241 253 Emitted when the slice count has changed.
242 254 */
243 255
244 256 /*!
245 257 \property QPieSeries::sum
246 258
247 259 Sum of all slices.
248 260
249 261 The series keeps track of the sum of all slices it holds.
250 262 */
251 263
252 264 /*!
253 265 \qmlproperty real PieSeries::sum
254 266
255 267 Sum of all slices.
256 268
257 269 The series keeps track of the sum of all slices it holds.
258 270 */
259 271
260 272 /*!
261 273 \fn void QPieSeries::sumChanged()
262 274 Emitted when the sum of all slices has changed.
263 275 \sa sum
264 276 */
265 277 /*!
266 278 \qmlsignal PieSeries::onSumChanged()
267 279 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
268 280 change value of a slice.
269 281 */
270 282
271 283 /*!
272 284 \fn void QPieSeries::added(QList<QPieSlice*> slices)
273 285
274 286 This signal is emitted when \a slices have been added to the series.
275 287
276 288 \sa append(), insert()
277 289 */
278 290 /*!
279 291 \qmlsignal PieSeries::onAdded(PieSlice slice)
280 292 Emitted when \a slice has been added to the series.
281 293 */
282 294
283 295 /*!
284 296 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
285 297 This signal is emitted when \a slices have been removed from the series.
286 298 \sa remove()
287 299 */
288 300 /*!
289 301 \qmlsignal PieSeries::onRemoved(PieSlice slice)
290 302 Emitted when \a slice has been removed from the series.
291 303 */
292 304
293 305 /*!
294 306 \fn void QPieSeries::clicked(QPieSlice* slice)
295 307 This signal is emitted when a \a slice has been clicked.
296 308 \sa QPieSlice::clicked()
297 309 */
298 310 /*!
299 311 \qmlsignal PieSeries::onClicked(PieSlice slice)
300 312 This signal is emitted when a \a slice has been clicked.
301 313 */
302 314
303 315 /*!
304 316 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
305 317 This signal is emitted when user has hovered over or away from the \a slice.
306 318 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
307 319 \sa QPieSlice::hovered()
308 320 */
309 321 /*!
310 322 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
311 323 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
312 324 over the slice and false when hover has moved away from the slice.
313 325 */
314 326
315 327 /*!
316 328 \qmlmethod PieSlice PieSeries::at(int index)
317 329 Returns slice at \a index. Returns null if the index is not valid.
318 330 */
319 331
320 332 /*!
321 333 \qmlmethod PieSlice PieSeries::find(string label)
322 334 Returns the first slice with \a label. Returns null if the index is not valid.
323 335 */
324 336
325 337 /*!
326 338 \qmlmethod PieSlice PieSeries::append(string label, real value)
327 339 Adds a new slice with \a label and \a value to the pie.
328 340 */
329 341
330 342 /*!
331 343 \qmlmethod bool PieSeries::remove(PieSlice slice)
332 344 Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise.
333 345 */
334 346
335 347 /*!
336 348 \qmlmethod PieSeries::clear()
337 349 Removes all slices from the pie.
338 350 */
339 351
340 352 /*!
341 353 Constructs a series object which is a child of \a parent.
342 354 */
343 355 QPieSeries::QPieSeries(QObject *parent) :
344 356 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
345 357 {
346 358
347 359 }
348 360
349 361 /*!
350 362 Destroys the series and its slices.
351 363 */
352 364 QPieSeries::~QPieSeries()
353 365 {
354 366 // NOTE: d_prt destroyed by QObject
355 367 }
356 368
357 369 /*!
358 370 Returns QChartSeries::SeriesTypePie.
359 371 */
360 372 QAbstractSeries::SeriesType QPieSeries::type() const
361 373 {
362 374 return QAbstractSeries::SeriesTypePie;
363 375 }
364 376
365 377 /*!
366 378 Appends a single \a slice to the series.
367 379 Slice ownership is passed to the series.
368 380
369 381 Returns true if append was succesfull.
370 382 */
371 383 bool QPieSeries::append(QPieSlice* slice)
372 384 {
373 385 return append(QList<QPieSlice*>() << slice);
374 386 }
375 387
376 388 /*!
377 389 Appends an array of \a slices to the series.
378 390 Slice ownership is passed to the series.
379 391
380 392 Returns true if append was successfull.
381 393 */
382 394 bool QPieSeries::append(QList<QPieSlice*> slices)
383 395 {
384 396 Q_D(QPieSeries);
385 397
386 398 if (slices.count() == 0)
387 399 return false;
388 400
389 401 foreach (QPieSlice* s, slices) {
390 402 if (!s || d->m_slices.contains(s))
391 403 return false;
392 404 if (s->series()) // already added to some series
393 405 return false;
394 406 }
395 407
396 408 foreach (QPieSlice* s, slices) {
397 409 s->setParent(this);
398 410 QPieSlicePrivate::fromSlice(s)->m_series = this;
399 411 d->m_slices << s;
400 412 }
401 413
402 414 d->updateDerivativeData();
403 415
404 416 foreach (QPieSlice* s, slices) {
405 417 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
406 418 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
407 419 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
408 420 }
409 421
410 422 emit added(slices);
411 423 emit countChanged();
412 424
413 425 return true;
414 426 }
415 427
416 428 /*!
417 429 Appends a single \a slice to the series and returns a reference to the series.
418 430 Slice ownership is passed to the series.
419 431 */
420 432 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
421 433 {
422 434 append(slice);
423 435 return *this;
424 436 }
425 437
426 438
427 439 /*!
428 440 Appends a single slice to the series with give \a value and \a label.
429 441 Slice ownership is passed to the series.
430 442 */
431 443 QPieSlice* QPieSeries::append(QString label, qreal value)
432 444 {
433 445 QPieSlice* slice = new QPieSlice(label, value);
434 446 append(slice);
435 447 return slice;
436 448 }
437 449
438 450 /*!
439 451 Inserts a single \a slice to the series before the slice at \a index position.
440 452 Slice ownership is passed to the series.
441 453
442 454 Returns true if insert was successfull.
443 455 */
444 456 bool QPieSeries::insert(int index, QPieSlice* slice)
445 457 {
446 458 Q_D(QPieSeries);
447 459
448 460 if (index < 0 || index > d->m_slices.count())
449 461 return false;
450 462
451 463 if (!slice || d->m_slices.contains(slice))
452 464 return false;
453 465
454 466 if (slice->series()) // already added to some series
455 467 return false;
456 468
457 469 slice->setParent(this);
458 470 QPieSlicePrivate::fromSlice(slice)->m_series = this;
459 471 d->m_slices.insert(index, slice);
460 472
461 473 d->updateDerivativeData();
462 474
463 475 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
464 476 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
465 477 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
466 478
467 479 emit added(QList<QPieSlice*>() << slice);
468 480 emit countChanged();
469 481
470 482 return true;
471 483 }
472 484
473 485 /*!
474 486 Removes a single \a slice from the series and deletes the slice.
475 487
476 488 Do not reference the pointer after this call.
477 489
478 490 Returns true if remove was successfull.
479 491 */
480 492 bool QPieSeries::remove(QPieSlice* slice)
481 493 {
482 494 Q_D(QPieSeries);
483 495
484 496 if (!d->m_slices.removeOne(slice))
485 497 return false;
486 498
487 499 d->updateDerivativeData();
488 500
489 501 emit removed(QList<QPieSlice*>() << slice);
490 502 emit countChanged();
491 503
492 504 delete slice;
493 505 slice = 0;
494 506
495 507 return true;
496 508 }
497 509
498 510 /*!
499 511 Clears all slices from the series.
500 512 */
501 513 void QPieSeries::clear()
502 514 {
503 515 Q_D(QPieSeries);
504 516 if (d->m_slices.count() == 0)
505 517 return;
506 518
507 519 QList<QPieSlice*> slices = d->m_slices;
508 520 foreach (QPieSlice* s, d->m_slices) {
509 521 d->m_slices.removeOne(s);
510 522 delete s;
511 523 }
512 524
513 525 d->updateDerivativeData();
514 526
515 527 emit removed(slices);
516 528 emit countChanged();
517 529 }
518 530
519 531 /*!
520 532 Returns a list of slices that belong to this series.
521 533 */
522 534 QList<QPieSlice*> QPieSeries::slices() const
523 535 {
524 536 Q_D(const QPieSeries);
525 537 return d->m_slices;
526 538 }
527 539
528 540 /*!
529 541 returns the number of the slices in this series.
530 542 */
531 543 int QPieSeries::count() const
532 544 {
533 545 Q_D(const QPieSeries);
534 546 return d->m_slices.count();
535 547 }
536 548
537 549 /*!
538 550 Returns true is the series is empty.
539 551 */
540 552 bool QPieSeries::isEmpty() const
541 553 {
542 554 Q_D(const QPieSeries);
543 555 return d->m_slices.isEmpty();
544 556 }
545 557
546 558 /*!
547 559 Returns the sum of all slice values in this series.
548 560
549 561 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
550 562 */
551 563 qreal QPieSeries::sum() const
552 564 {
553 565 Q_D(const QPieSeries);
554 566 return d->m_sum;
555 567 }
556 568
557 569 void QPieSeries::setDonut(bool donut)
558 570 {
559 571 Q_D(QPieSeries);
560 572 d->m_donutChart = donut;
561 573 d->updateDerivativeData();
562 574 }
563 575
564 576 bool QPieSeries::donut() const
565 577 {
566 578 Q_D(const QPieSeries);
567 579 return d->m_donutChart;
568 580 }
569 581
570 582 void QPieSeries::setDonutInnerSize(qreal innerSize)
571 583 {
572 584 Q_D(QPieSeries);
573 585
574 586 if (innerSize < 0.0)
575 587 innerSize = 0.0;
576 588 if (innerSize > d->m_pieRelativeSize)
577 589 innerSize = d->m_pieRelativeSize;
578 590
579 591 d->m_donutRelativeInnerSize = innerSize;
580 592 d->updateDerivativeData();
581 593 emit d->pieSizeChanged();
582 594 }
583 595
584 596 qreal QPieSeries::donutInnerSize() const
585 597 {
586 598 Q_D(const QPieSeries);
587 599 return d->m_donutRelativeInnerSize;
588 600 }
589 601
590 602 void QPieSeries::setHorizontalPosition(qreal relativePosition)
591 603 {
592 604 Q_D(QPieSeries);
593 605
594 606 if (relativePosition < 0.0)
595 607 relativePosition = 0.0;
596 608 if (relativePosition > 1.0)
597 609 relativePosition = 1.0;
598 610
599 611 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
600 612 d->m_pieRelativeHorPos = relativePosition;
601 613 emit d->horizontalPositionChanged();
602 614 }
603 615 }
604 616
605 617 qreal QPieSeries::horizontalPosition() const
606 618 {
607 619 Q_D(const QPieSeries);
608 620 return d->m_pieRelativeHorPos;
609 621 }
610 622
611 623 void QPieSeries::setVerticalPosition(qreal relativePosition)
612 624 {
613 625 Q_D(QPieSeries);
614 626
615 627 if (relativePosition < 0.0)
616 628 relativePosition = 0.0;
617 629 if (relativePosition > 1.0)
618 630 relativePosition = 1.0;
619 631
620 632 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
621 633 d->m_pieRelativeVerPos = relativePosition;
622 634 emit d->verticalPositionChanged();
623 635 }
624 636 }
625 637
626 638 qreal QPieSeries::verticalPosition() const
627 639 {
628 640 Q_D(const QPieSeries);
629 641 return d->m_pieRelativeVerPos;
630 642 }
631 643
632 644 void QPieSeries::setPieSize(qreal relativeSize)
633 645 {
634 646 Q_D(QPieSeries);
635 647
636 648 if (relativeSize < 0.0)
637 649 relativeSize = 0.0;
638 650 if (relativeSize > 1.0)
639 651 relativeSize = 1.0;
640 652
641 653 if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) {
642 654 d->m_pieRelativeSize = relativeSize;
643 655 emit d->pieSizeChanged();
644 656 }
645 657 }
646 658
647 659 qreal QPieSeries::pieSize() const
648 660 {
649 661 Q_D(const QPieSeries);
650 662 return d->m_pieRelativeSize;
651 663 }
652 664
653 665
654 666 void QPieSeries::setPieStartAngle(qreal angle)
655 667 {
656 668 Q_D(QPieSeries);
657 669 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
658 670 return;
659 671 d->m_pieStartAngle = angle;
660 672 d->updateDerivativeData();
661 673 emit d->pieStartAngleChanged();
662 674 }
663 675
664 676 qreal QPieSeries::pieStartAngle() const
665 677 {
666 678 Q_D(const QPieSeries);
667 679 return d->m_pieStartAngle;
668 680 }
669 681
670 682 /*!
671 683 Sets the end angle of the pie.
672 684
673 685 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
674 686
675 687 \a angle must be greater than start angle.
676 688
677 689 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
678 690 */
679 691 void QPieSeries::setPieEndAngle(qreal angle)
680 692 {
681 693 Q_D(QPieSeries);
682 694 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
683 695 return;
684 696 d->m_pieEndAngle = angle;
685 697 d->updateDerivativeData();
686 698 emit d->pieEndAngleChanged();
687 699 }
688 700
689 701 /*!
690 702 Returns the end angle of the pie.
691 703
692 704 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
693 705
694 706 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
695 707 */
696 708 qreal QPieSeries::pieEndAngle() const
697 709 {
698 710 Q_D(const QPieSeries);
699 711 return d->m_pieEndAngle;
700 712 }
701 713
702 714 /*!
703 715 Sets the all the slice labels \a visible or invisible.
704 716
705 717 Note that this affects only the current slices in the series.
706 718 If user adds a new slice the default label visibility is false.
707 719
708 720 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
709 721 */
710 722 void QPieSeries::setLabelsVisible(bool visible)
711 723 {
712 724 Q_D(QPieSeries);
713 725 foreach (QPieSlice* s, d->m_slices)
714 726 s->setLabelVisible(visible);
715 727 }
716 728
717 729 void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
718 730 {
719 731 Q_D(QPieSeries);
720 732 foreach (QPieSlice* s, d->m_slices)
721 733 s->setLabelPosition(position);
722 734 }
723 735
724 736 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
725 737
726 738
727 739 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
728 740 QAbstractSeriesPrivate(parent),
729 741 m_pieRelativeHorPos(0.5),
730 742 m_pieRelativeVerPos(0.5),
731 743 m_pieRelativeSize(0.7),
732 744 m_pieStartAngle(0),
733 745 m_pieEndAngle(360),
734 746 m_sum(0),
735 747 m_donutChart(false),
736 748 m_donutRelativeInnerSize(0.5)
737 749 {
738 750 }
739 751
740 752 QPieSeriesPrivate::~QPieSeriesPrivate()
741 753 {
742 754 }
743 755
744 756 void QPieSeriesPrivate::updateDerivativeData()
745 757 {
746 758 // calculate sum of all slices
747 759 qreal sum = 0;
748 760 foreach (QPieSlice* s, m_slices)
749 761 sum += s->value();
750 762
751 763 if (!qFuzzyIsNull(m_sum - sum)) {
752 764 m_sum = sum;
753 765 emit q_func()->sumChanged();
754 766 }
755 767
756 768 // nothing to show..
757 769 if (qFuzzyIsNull(m_sum))
758 770 return;
759 771
760 772 // update slice attributes
761 773 qreal sliceAngle = m_pieStartAngle;
762 774 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
763 775 QVector<QPieSlice*> changed;
764 776 foreach (QPieSlice* s, m_slices) {
765 777 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
766 778 d->setPercentage(s->value() / m_sum);
767 779 d->setStartAngle(sliceAngle);
768 780 d->setAngleSpan(pieSpan * s->percentage());
769 781 sliceAngle += s->angleSpan();
770 782 }
771 783
772 784
773 785 emit calculatedDataChanged();
774 786 }
775 787
776 788 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
777 789 {
778 790 return series->d_func();
779 791 }
780 792
781 793 void QPieSeriesPrivate::sliceValueChanged()
782 794 {
783 795 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
784 796 updateDerivativeData();
785 797 }
786 798
787 799 void QPieSeriesPrivate::sliceClicked()
788 800 {
789 801 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
790 802 Q_ASSERT(m_slices.contains(slice));
791 803 Q_Q(QPieSeries);
792 804 emit q->clicked(slice);
793 805 }
794 806
795 807 void QPieSeriesPrivate::sliceHovered(bool state)
796 808 {
797 809 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
798 810 Q_ASSERT(m_slices.contains(slice));
799 811 Q_Q(QPieSeries);
800 812 emit q->hovered(slice, state);
801 813 }
802 814
803 815 void QPieSeriesPrivate::scaleDomain(Domain& domain)
804 816 {
805 817 Q_UNUSED(domain);
806 818 // does not apply to pie
807 819 }
808 820
809 821 Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
810 822 {
811 823 Q_Q(QPieSeries);
812 824 PieChartItem* pie = new PieChartItem(q,presenter);
813 825 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
814 826 presenter->animator()->addAnimation(pie);
815 827 }
816 828 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
817 829 return pie;
818 830 }
819 831
820 832 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
821 833 {
822 834 Q_Q(QPieSeries);
823 835 QList<LegendMarker*> markers;
824 836 foreach(QPieSlice* slice, q->slices()) {
825 837 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
826 838 markers << marker;
827 839 }
828 840 return markers;
829 841 }
830 842
831 843 void QPieSeriesPrivate::initializeAxis(QAbstractAxis* axis)
832 844 {
833 845 Q_UNUSED(axis);
834 846 }
835 847
836 848 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
837 849 {
838 850 Q_UNUSED(orientation);
839 851 return QAbstractAxis::AxisTypeNoAxis;
840 852 }
841 853
842 854 #include "moc_qpieseries.cpp"
843 855 #include "moc_qpieseries_p.cpp"
844 856
845 857 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,294 +1,317
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "../qabstractaxis/tst_qabstractaxis.h"
22 22 #include <qdatetimeaxis.h>
23 23 #include <qlineseries.h>
24 24
25 25 class tst_QDateTimeAxis : public QObject//: public tst_QAbstractAxis
26 26 {
27 27 Q_OBJECT
28 28
29 29 public slots:
30 30 void initTestCase();
31 31 void cleanupTestCase();
32 32 void init();
33 33 void cleanup();
34 34
35 35 private slots:
36 36 void qdatetimeaxis_data();
37 37 void qdatetimeaxis();
38 38
39 39 void max_raw_data();
40 40 void max_raw();
41 41 void max_data();
42 42 void max();
43 43 // void max_animation_data();
44 44 // void max_animation();
45 45 void min_raw_data();
46 46 void min_raw();
47 47 void min_data();
48 48 void min();
49 49 // void min_animation_data();
50 50 // void min_animation();
51 // void range_raw_data();
52 // void range_raw();
53 // void range_data();
54 // void range();
51 void range_raw_data();
52 void range_raw();
53 void range_data();
54 void range();
55 55 // void range_animation_data();
56 56 // void range_animation();
57 57
58 58 private:
59 59 QDateTimeAxis *m_dateTimeAxisX;
60 60 QDateTimeAxis *m_dateTimeAxisY;
61 61 QLineSeries* m_series;
62 62 QChartView* m_view;
63 63 QChart* m_chart;
64 64 };
65 65
66 66 void tst_QDateTimeAxis::initTestCase()
67 67 {
68 68 }
69 69
70 70 void tst_QDateTimeAxis::cleanupTestCase()
71 71 {
72 72 }
73 73
74 74 void tst_QDateTimeAxis::init()
75 75 {
76 76 m_dateTimeAxisX = new QDateTimeAxis();
77 77 m_dateTimeAxisY = new QDateTimeAxis();
78 78 m_series = new QLineSeries();
79 79 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
80 80 // tst_QAbstractAxis::init(m_datetimeaxis, m_series);
81 81
82 82 m_view = new QChartView(new QChart());
83 83 m_chart = m_view->chart();
84 84 m_chart->addSeries(m_series);
85 85 m_chart->setAxisY(m_dateTimeAxisY, m_series);
86 86 m_chart->setAxisX(m_dateTimeAxisX, m_series);
87 87 }
88 88
89 89 void tst_QDateTimeAxis::cleanup()
90 90 {
91 91 delete m_series;
92 92 delete m_dateTimeAxisX;
93 93 delete m_dateTimeAxisY;
94 94 m_series = 0;
95 95 m_dateTimeAxisX = 0;
96 96 m_dateTimeAxisY = 0;
97 97 delete m_view;
98 98 m_view = 0;
99 99 m_chart = 0;
100 100 // tst_QAbstractAxis::cleanup();
101 101 }
102 102
103 103 void tst_QDateTimeAxis::qdatetimeaxis_data()
104 104 {
105 105 }
106 106
107 107 void tst_QDateTimeAxis::qdatetimeaxis()
108 108 {
109 109 // qabstractaxis();
110 110
111 111 // QVERIFY(m_datetimeaxis->max().toMSecsSinceEpoch() == 0);
112 112 // QVERIFY(m_datetimeaxis->min().toMSecsSinceEpoch() == 0);
113 113 QCOMPARE(m_dateTimeAxisX->type(), QAbstractAxis::AxisTypeDateTime);
114 114
115 115 m_view->show();
116 116 QTest::qWaitForWindowShown(m_view);
117 117
118 118 QVERIFY(m_dateTimeAxisX->max().toMSecsSinceEpoch() != 0);
119 119 QVERIFY(m_dateTimeAxisX->min().toMSecsSinceEpoch() != 0);
120 120 }
121 121
122 122 void tst_QDateTimeAxis::max_raw_data()
123 123 {
124 124 QTest::addColumn<QDateTime>("max");
125 125 QTest::addColumn<bool>("valid");
126 126 QDateTime dateTime;
127 127 dateTime.setDate(QDate(2012, 7, 19));
128 128 QTest::newRow("19.7.2012 - Valid") << dateTime << true;
129 129 dateTime.setDate(QDate(2012, 17, 32));
130 130 QTest::newRow("32.17.2012 - Invalid") << dateTime << false;
131 131 }
132 132
133 133 void tst_QDateTimeAxis::max_raw()
134 134 {
135 135 QFETCH(QDateTime, max);
136 136 QFETCH(bool, valid);
137 137
138 138 QSignalSpy spy0(m_dateTimeAxisX, SIGNAL(maxChanged(QDateTime)));
139 139 QSignalSpy spy1(m_dateTimeAxisX, SIGNAL(minChanged(QDateTime)));
140 140 QSignalSpy spy2(m_dateTimeAxisX, SIGNAL(rangeChanged(QDateTime, QDateTime)));
141 141
142 142 m_dateTimeAxisX->setMax(max);
143 143
144 144
145 145 if (valid) {
146 146 QVERIFY2(m_dateTimeAxisX->max() == max, "Not equal");
147 147 QCOMPARE(spy0.count(), 1);
148 148 QCOMPARE(spy1.count(), 0);
149 149 QCOMPARE(spy2.count(), 1);
150 150 } else {
151 QVERIFY2(m_dateTimeAxisX->max() != max, "Date is invalid");
151 QVERIFY2(m_dateTimeAxisX->max() != max, "Date is invalid and should not be set");
152 152 QCOMPARE(spy0.count(), 0);
153 153 QCOMPARE(spy1.count(), 0);
154 154 QCOMPARE(spy2.count(), 0);
155 155 }
156 156 }
157 157
158 158 void tst_QDateTimeAxis::max_data()
159 159 {
160 160 max_raw_data();
161 161 }
162 162
163 163 void tst_QDateTimeAxis::max()
164 164 {
165 165 m_chart->setAxisX(m_dateTimeAxisX, m_series);
166 166 m_view->show();
167 167 QTest::qWaitForWindowShown(m_view);
168 168 max_raw();
169 169 }
170 170
171 171 //void tst_QDateTimeAxis::max_animation_data()
172 172 //{
173 173 // max_data();
174 174 //}
175 175
176 176 //void tst_QDateTimeAxis::max_animation()
177 177 //{
178 178 // m_chart->setAnimationOptions(QChart::GridAxisAnimations);
179 179 // max();
180 180 //}
181 181
182 182 void tst_QDateTimeAxis::min_raw_data()
183 183 {
184 184 QTest::addColumn<QDateTime>("min");
185 185 QTest::addColumn<bool>("valid");
186 186 QDateTime dateTime;
187 187 dateTime.setDate(QDate(1908, 1, 11));
188 188 QTest::newRow("11.1.1908 - Valid") << dateTime << true; // negative MSecs from Epoch
189 189 dateTime.setDate(QDate(2012, 17, 32));
190 190 QTest::newRow("32.17.2012 - Invalid") << dateTime << false;
191 191 }
192 192
193 193 void tst_QDateTimeAxis::min_raw()
194 194 {
195 195 QFETCH(QDateTime, min);
196 196 QFETCH(bool, valid);
197 197
198 198 QSignalSpy spy0(m_dateTimeAxisX, SIGNAL(maxChanged(QDateTime)));
199 199 QSignalSpy spy1(m_dateTimeAxisX, SIGNAL(minChanged(QDateTime)));
200 200 QSignalSpy spy2(m_dateTimeAxisX, SIGNAL(rangeChanged(QDateTime, QDateTime)));
201 201
202 202 m_dateTimeAxisX->setMin(min);
203 203
204 204 if (valid) {
205 205 QVERIFY2(m_dateTimeAxisX->min() == min, "Not equal");
206 206 QCOMPARE(spy0.count(), 0);
207 207 QCOMPARE(spy1.count(), 1);
208 208 QCOMPARE(spy2.count(), 1);
209 209 } else {
210 QVERIFY2(m_dateTimeAxisX->min() != min, "Date is invalid");
210 QVERIFY2(m_dateTimeAxisX->min() != min, "Date is invalid and should not be set");
211 211 QCOMPARE(spy0.count(), 0);
212 212 QCOMPARE(spy1.count(), 0);
213 213 QCOMPARE(spy2.count(), 0);
214 214 }
215 215 }
216 216
217 217 void tst_QDateTimeAxis::min_data()
218 218 {
219 219 min_raw_data();
220 220 }
221 221
222 222 void tst_QDateTimeAxis::min()
223 223 {
224 224 m_chart->setAxisX(m_dateTimeAxisX, m_series);
225 225 m_view->show();
226 226 QTest::qWaitForWindowShown(m_view);
227 227 min_raw();
228 228 }
229 229
230 230 //void tst_QDateTimeAxis::min_animation_data()
231 231 //{
232 232 // min_data();
233 233 //}
234 234
235 235 //void tst_QDateTimeAxis::min_animation()
236 236 //{
237 237 // m_chart->setAnimationOptions(QChart::GridAxisAnimations);
238 238 // min();
239 239 //}
240 240
241 //void tst_QDateTimeAxis::range_raw_data()
242 //{
243 // QTest::addColumn<qreal>("min");
244 // QTest::addColumn<qreal>("max");
245 // QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
246 // QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
247 // QTest::newRow("101.0") << 40.0 << 60.0;
248 //}
241 void tst_QDateTimeAxis::range_raw_data()
242 {
243 QTest::addColumn<QDateTime>("min");
244 QTest::addColumn<bool>("minValid");
245 QTest::addColumn<QDateTime>("max");
246 QTest::addColumn<bool>("maxValid");
249 247
250 //void tst_QDateTimeAxis::range_raw()
251 //{
252 // QFETCH(qreal, min);
253 // QFETCH(qreal, max);
248 QDateTime minDateTime;
249 QDateTime maxDateTime;
250 minDateTime.setDate(QDate(1908, 1, 11));
251 maxDateTime.setDate(QDate(1958, 11, 21));
252 QTest::newRow("11.1.1908 - min valid, 21.12.1958 - max valid") << minDateTime << true << maxDateTime << true; // negative MSecs from Epoch, min < max
254 253
255 // QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal)));
256 // QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal)));
257 // QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal)));
254 minDateTime.setDate(QDate(2012, 17, 32));
255 QTest::newRow("32.17.2012 - min invalid, 21.12.1958 - max valid") << minDateTime << false << maxDateTime << true;
258 256
259 // m_intervalsaxis->setRange(min, max);
260 // QVERIFY2(qFuzzyIsNull(m_intervalsaxis->min() - min), "Min not equal");
261 // QVERIFY2(qFuzzyIsNull(m_intervalsaxis->max() - max), "Max not equal");
257 maxDateTime.setDate(QDate(2017, 0, 1));
258 QTest::newRow("32.17.2012 - min invalid, 1.0.2017 - max invalid") << minDateTime << false << maxDateTime << false;
262 259
263 // QCOMPARE(spy0.count(), 1);
264 // QCOMPARE(spy1.count(), 1);
265 // QCOMPARE(spy2.count(), 1);
266 //}
260 minDateTime.setDate(QDate(2012, 1, 1));
261 QTest::newRow("1.1.2012 - min valid, 1.0.2017 - max invalid") << minDateTime << true << maxDateTime << false;
267 262
268 //void tst_QDateTimeAxis::range_data()
269 //{
270 // range_raw_data();
271 //}
263 maxDateTime.setDate(QDate(2005, 2, 5));
264 QTest::newRow("1.1.2012 - min valid, 5.2.2005 - max valid") << minDateTime << true << maxDateTime << true; // min > max
265 }
272 266
273 //void tst_QDateTimeAxis::range()
274 //{
275 // m_chart->setAxisX(m_intervalsaxis, m_series);
276 // m_view->show();
277 // QTest::qWaitForWindowShown(m_view);
278 // range_raw();
279 //}
267 void tst_QDateTimeAxis::range_raw()
268 {
269 QFETCH(QDateTime, min);
270 QFETCH(bool, minValid);
271 QFETCH(QDateTime, max);
272 QFETCH(bool, maxValid);
273
274 QSignalSpy spy0(m_dateTimeAxisX, SIGNAL(maxChanged(QDateTime)));
275 QSignalSpy spy1(m_dateTimeAxisX, SIGNAL(minChanged(QDateTime)));
276 QSignalSpy spy2(m_dateTimeAxisX, SIGNAL(rangeChanged(QDateTime, QDateTime)));
277
278 m_dateTimeAxisX->setRange(min, max);
279
280 if (minValid && maxValid && min < max) {
281 QCOMPARE(spy0.count(), 1);
282 QCOMPARE(spy1.count(), 1);
283 QCOMPARE(spy2.count(), 1);
284 } else {
285 QCOMPARE(spy0.count(), 0);
286 QCOMPARE(spy1.count(), 0);
287 QCOMPARE(spy2.count(), 0);
288 }
289 }
290
291 void tst_QDateTimeAxis::range_data()
292 {
293 range_raw_data();
294 }
295
296 void tst_QDateTimeAxis::range()
297 {
298 m_chart->setAxisX(m_dateTimeAxisX, m_series);
299 m_view->show();
300 QTest::qWaitForWindowShown(m_view);
301 range_raw();
302 }
280 303
281 304 //void tst_QDateTimeAxis::range_animation_data()
282 305 //{
283 306 // range_data();
284 307 //}
285 308
286 309 //void tst_QDateTimeAxis::range_animation()
287 310 //{
288 311 // m_chart->setAnimationOptions(QChart::GridAxisAnimations);
289 312 // range();
290 313 //}
291 314
292 315 QTEST_MAIN(tst_QDateTimeAxis)
293 316 #include "tst_qdatetimeaxis.moc"
294 317
General Comments 0
You need to be logged in to leave comments. Login now