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