1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 or (at your option) any later version |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | |
30 | #include <QtCharts/QPieSlice> |
31 | #include <private/qpieslice_p.h> |
32 | |
33 | QT_CHARTS_BEGIN_NAMESPACE |
34 | |
35 | /*! |
36 | \class QPieSlice |
37 | \inmodule QtCharts |
38 | \brief The QPieSlice class represents a single slice in a pie series. |
39 | |
40 | A pie slice has a value and a label. When the slice is added to a pie series, the |
41 | QPieSeries object calculates the percentage of the slice compared with the sum of |
42 | all slices in the series to determine the actual size of the slice in the chart. |
43 | |
44 | By default, the label is hidden. If it is visible, it can be either located outside |
45 | the slice and connected to it with an arm or centered inside the slice either |
46 | horizontally or in parallel with the tangential or normal of the slice's arc. |
47 | |
48 | By default, the visual appearance of the slice is set by a theme, but the theme can be |
49 | overridden by specifying slice properties. However, if the theme is changed after the |
50 | slices are customized, all customization will be lost. |
51 | |
52 | To enable user interaction with the pie chart, some basic signals are emitted when |
53 | users click pie slices or hover the mouse over them. |
54 | |
55 | \sa QPieSeries |
56 | */ |
57 | |
58 | /*! |
59 | \qmltype PieSlice |
60 | \instantiates QPieSlice |
61 | \inqmlmodule QtCharts |
62 | |
63 | \brief Represents a single slice in a pie series. |
64 | |
65 | A pie slice has a value and a label. When the slice is added to a pie series, the |
66 | PieSeries type calculates the percentage of the slice compared with the sum of |
67 | all slices in the series to determine the actual size of the slice in the chart. |
68 | |
69 | By default, the label is hidden. If it is visible, it can be either located outside |
70 | the slice and connected to it with an arm or centered inside the slice either |
71 | horizontally or in parallel with the tangential or normal of the slice's arc. |
72 | |
73 | By default, the visual appearance of the slice is set by a theme, but the theme can be |
74 | overridden by specifying slice properties. However, if the theme is changed after the |
75 | slices are customized, all customization will be lost. |
76 | |
77 | The PieSlice type should be used as a child of a PieSeries type. For example: |
78 | \snippet qmlpiechart/qml/qmlpiechart/main.qml 2 |
79 | |
80 | Alternatively, slices can be added to a pie series by using the \l{PieSeries::append()} |
81 | {PieSeries.append()} method. |
82 | \snippet qmlpiechart/qml/qmlpiechart/main.qml 4 |
83 | |
84 | In that case, \l{PieSeries::at()}{PieSeries.at()} or \l {PieSeries::find} |
85 | {PieSeries.find} can be used to access the properties of an individual PieSlice instance. |
86 | \snippet qmlpiechart/qml/qmlpiechart/main.qml 5 |
87 | \sa PieSeries |
88 | */ |
89 | |
90 | /*! |
91 | \enum QPieSlice::LabelPosition |
92 | |
93 | This enum describes the position of the slice label. |
94 | |
95 | \value LabelOutside |
96 | The label is located outside the slice connected to it with an arm. |
97 | This is the default value. |
98 | \value LabelInsideHorizontal |
99 | The label is centered within the slice and laid out horizontally. |
100 | \value LabelInsideTangential |
101 | The label is centered within the slice and rotated to be parallel with |
102 | the tangential of the slice's arc. |
103 | \value LabelInsideNormal |
104 | The label is centered within the slice and rotated to be parallel with |
105 | the normal of the slice's arc. |
106 | */ |
107 | |
108 | /*! |
109 | \property QPieSlice::label |
110 | \brief The label of the slice. |
111 | \note The string can be HTML formatted. |
112 | \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor |
113 | */ |
114 | /*! |
115 | \qmlproperty string PieSlice::label |
116 | The label of the slice. |
117 | \note The string can be HTML formatted. |
118 | */ |
119 | |
120 | /*! |
121 | \fn void QPieSlice::labelChanged() |
122 | This signal is emitted when the slice label changes. |
123 | \sa label |
124 | */ |
125 | |
126 | /*! |
127 | \property QPieSlice::value |
128 | \brief The value of the slice. |
129 | \note A negative value is converted to a positive value. |
130 | \sa percentage(), QPieSeries::sum() |
131 | */ |
132 | /*! |
133 | \qmlproperty real PieSlice::value |
134 | The value of the slice. |
135 | |
136 | \note A negative value is converted to a positive value. |
137 | */ |
138 | |
139 | /*! |
140 | \fn void QPieSlice::valueChanged() |
141 | This signal is emitted when the slice value changes. |
142 | \sa value |
143 | */ |
144 | |
145 | /*! |
146 | \property QPieSlice::labelVisible |
147 | \brief The visibility of the slice label. By default, the label is not visible. |
148 | \sa label, labelBrush, labelFont, labelArmLengthFactor |
149 | */ |
150 | /*! |
151 | \qmlproperty bool PieSlice::labelVisible |
152 | The visibility of the slice label. By default, the label is not visible. |
153 | */ |
154 | |
155 | /*! |
156 | \fn void QPieSlice::labelVisibleChanged() |
157 | This signal is emitted when the visibility of the slice label changes. |
158 | \sa labelVisible |
159 | */ |
160 | |
161 | /*! |
162 | \property QPieSlice::exploded |
163 | \brief Whether the slice is separated from the pie. |
164 | \sa explodeDistanceFactor |
165 | */ |
166 | /*! |
167 | \qmlproperty bool PieSlice::exploded |
168 | Whether the slice is separated from the pie. |
169 | \sa explodeDistanceFactor |
170 | */ |
171 | |
172 | /*! |
173 | \property QPieSlice::pen |
174 | \brief The pen used to draw the slice border. |
175 | */ |
176 | |
177 | /*! |
178 | \fn void QPieSlice::penChanged() |
179 | This signal is emitted when the pen used to draw the slice border changes. |
180 | \sa pen |
181 | */ |
182 | |
183 | /*! |
184 | \property QPieSlice::borderColor |
185 | \brief The color used to draw the slice border. |
186 | This is a convenience property for modifying the slice pen. |
187 | \sa pen, borderWidth |
188 | */ |
189 | /*! |
190 | \qmlproperty color PieSlice::borderColor |
191 | The color used to draw the slice border (pen color). |
192 | \sa borderWidth |
193 | */ |
194 | |
195 | /*! |
196 | \fn void QPieSlice::borderColorChanged() |
197 | This signal is emitted when the slice border color changes. |
198 | \sa pen, borderColor |
199 | */ |
200 | |
201 | /*! |
202 | \property QPieSlice::borderWidth |
203 | \brief The width of the slice border. |
204 | This is a convenience property for modifying the slice pen. |
205 | \sa pen, borderColor |
206 | */ |
207 | /*! |
208 | \qmlproperty int PieSlice::borderWidth |
209 | The width of the slice border. |
210 | This is a convenience property for modifying the slice pen. |
211 | \sa borderColor |
212 | */ |
213 | |
214 | /*! |
215 | \fn void QPieSlice::borderWidthChanged() |
216 | This signal is emitted when the slice border width changes. |
217 | \sa pen, borderWidth |
218 | */ |
219 | |
220 | /*! |
221 | \property QPieSlice::brush |
222 | \brief The brush used to fill the slice. |
223 | */ |
224 | |
225 | /*! |
226 | \fn void QPieSlice::brushChanged() |
227 | This signal is emitted when the brush used to fill the slice changes. |
228 | \sa brush |
229 | */ |
230 | |
231 | /*! |
232 | \qmlproperty string PieSlice::brushFilename |
233 | The name of the file used as a brush for the slice. |
234 | */ |
235 | |
236 | /*! |
237 | \property QPieSlice::color |
238 | \brief The fill (brush) color of the slice. |
239 | This is a convenience property for modifying the slice brush. |
240 | \sa brush |
241 | */ |
242 | /*! |
243 | \qmlproperty color PieSlice::color |
244 | The fill (brush) color of the slice. |
245 | */ |
246 | |
247 | /*! |
248 | \fn void QPieSlice::colorChanged() |
249 | This signal is emitted when the slice color changes. |
250 | \sa brush |
251 | */ |
252 | |
253 | /*! |
254 | \property QPieSlice::labelBrush |
255 | \brief The brush used to draw the label and label arm of the slice. |
256 | \sa label, labelVisible, labelFont, labelArmLengthFactor |
257 | */ |
258 | |
259 | /*! |
260 | \fn void QPieSlice::labelBrushChanged() |
261 | This signal is emitted when the label brush of the slice changes. |
262 | \sa labelBrush |
263 | */ |
264 | |
265 | /*! |
266 | \property QPieSlice::labelColor |
267 | \brief The color used to draw the slice label. |
268 | This is a convenience property for modifying the slice label brush. |
269 | \sa labelBrush |
270 | */ |
271 | /*! |
272 | \qmlproperty color PieSlice::labelColor |
273 | The color used to draw the slice label. |
274 | */ |
275 | |
276 | /*! |
277 | \fn void QPieSlice::labelColorChanged() |
278 | This signal is emitted when the slice label color changes. |
279 | \sa labelColor |
280 | */ |
281 | |
282 | /*! |
283 | \property QPieSlice::labelFont |
284 | \brief The font used for drawing the label text. |
285 | \sa label, labelVisible, labelArmLengthFactor |
286 | */ |
287 | |
288 | /*! |
289 | \fn void QPieSlice::labelFontChanged() |
290 | This signal is emitted when the label font of the slice changes. |
291 | \sa labelFont |
292 | */ |
293 | |
294 | /*! |
295 | \qmlproperty font PieSlice::labelFont |
296 | |
297 | The font used for the slice label. |
298 | |
299 | For more information, see \l [QML]{font}. |
300 | |
301 | \sa labelVisible, labelPosition |
302 | */ |
303 | |
304 | /*! |
305 | \property QPieSlice::labelPosition |
306 | \brief The position of the slice label. |
307 | \sa label, labelVisible |
308 | */ |
309 | /*! |
310 | \qmlproperty enumeration PieSlice::labelPosition |
311 | |
312 | Describes the position of the slice label. |
313 | |
314 | \value PieSlice.LabelOutside |
315 | The label is located outside the slice connected to it with an arm. |
316 | This is the default value. |
317 | \value PieSlice.LabelInsideHorizontal |
318 | The label is centered within the slice and laid out horizontally. |
319 | \value PieSlice.LabelInsideTangential |
320 | The label is centered within the slice and rotated to be parallel with |
321 | the tangential of the slice's arc. |
322 | \value PieSlice.LabelInsideNormal |
323 | The label is centered within the slice and rotated to be parallel with |
324 | the normal of the slice's arc. |
325 | |
326 | \sa labelVisible |
327 | */ |
328 | |
329 | /*! |
330 | \property QPieSlice::labelArmLengthFactor |
331 | \brief The length of the label arm. |
332 | The factor is relative to the pie radius. For example: |
333 | \list |
334 | \li 1.0 means that the length is the same as the radius. |
335 | \li 0.5 means that the length is half of the radius. |
336 | \endlist |
337 | By default, the arm length is 0.15 |
338 | \sa label, labelVisible, labelBrush, labelFont |
339 | */ |
340 | /*! |
341 | \qmlproperty real PieSlice::labelArmLengthFactor |
342 | The length of the label arm. |
343 | The factor is relative to the pie radius. For example: |
344 | \list |
345 | \li 1.0 means that the length is the same as the radius. |
346 | \li 0.5 means that the length is half of the radius. |
347 | \endlist |
348 | By default, the arm length is 0.15 |
349 | |
350 | \sa labelVisible |
351 | */ |
352 | |
353 | /*! |
354 | \property QPieSlice::explodeDistanceFactor |
355 | \brief Determines how far away from the pie the slice is exploded. |
356 | \list |
357 | \li 1.0 means that the distance is the same as the radius. |
358 | \li 0.5 means that the distance is half of the radius. |
359 | \endlist |
360 | By default, the distance is 0.15 |
361 | \sa exploded |
362 | */ |
363 | /*! |
364 | \qmlproperty real PieSlice::explodeDistanceFactor |
365 | Determines how far away from the pie the slice is exploded. |
366 | \list |
367 | \li 1.0 means that the distance is the same as the radius. |
368 | \li 0.5 means that the distance is half of the radius. |
369 | \endlist |
370 | By default, the distance is 0.15 |
371 | |
372 | \sa exploded |
373 | */ |
374 | |
375 | /*! |
376 | \property QPieSlice::percentage |
377 | \brief The percentage of the slice compared to the sum of all slices in the series. |
378 | The actual value ranges from 0.0 to 1.0. |
379 | Updated automatically once the slice is added to the series. |
380 | \sa value, QPieSeries::sum |
381 | */ |
382 | /*! |
383 | \qmlproperty real PieSlice::percentage |
384 | The percentage of the slice compared to the sum of all slices in the series. |
385 | The actual value ranges from 0.0 to 1.0. |
386 | Updated automatically once the slice is added to the series. |
387 | */ |
388 | |
389 | /*! |
390 | \fn void QPieSlice::percentageChanged() |
391 | This signal is emitted when the percentage of the slice changes. |
392 | \sa percentage |
393 | */ |
394 | |
395 | /*! |
396 | \property QPieSlice::startAngle |
397 | \brief The starting angle of this slice in the series it belongs to. |
398 | A full pie is 360 degrees, where 0 degrees is at 12 a'clock. |
399 | Updated automatically once the slice is added to the series. |
400 | */ |
401 | /*! |
402 | \qmlproperty real PieSlice::startAngle |
403 | The starting angle of this slice in the series it belongs to. |
404 | A full pie is 360 degrees, where 0 degrees is at 12 a'clock. |
405 | Updated automatically once the slice is added to the series. |
406 | */ |
407 | |
408 | /*! |
409 | \fn void QPieSlice::startAngleChanged() |
410 | This signal is emitted when the starting angle of the slice changes. |
411 | \sa startAngle |
412 | */ |
413 | |
414 | /*! |
415 | \property QPieSlice::angleSpan |
416 | \brief The span of the slice in degrees. |
417 | A full pie is 360 degrees, where 0 degrees is at 12 a'clock. |
418 | Updated automatically once the slice is added to the series. |
419 | */ |
420 | /*! |
421 | \qmlproperty real PieSlice::angleSpan |
422 | The span of the slice in degrees. |
423 | A full pie is 360 degrees, where 0 degrees is at 12 a'clock. |
424 | Updated automatically once the slice is added to the series. |
425 | */ |
426 | |
427 | /*! |
428 | \fn void QPieSlice::angleSpanChanged() |
429 | This signal is emitted when the angle span of the slice changes. |
430 | \sa angleSpan |
431 | */ |
432 | |
433 | /*! |
434 | \fn void QPieSlice::clicked() |
435 | This signal is emitted when the slice is clicked. |
436 | \sa QPieSeries::clicked() |
437 | */ |
438 | /*! |
439 | \qmlsignal PieSlice::clicked() |
440 | This signal is emitted when the slice is clicked. |
441 | |
442 | The corresponding signal handler is \c onClicked(). |
443 | */ |
444 | |
445 | /*! |
446 | \fn void QPieSlice::pressed() |
447 | This signal is emitted when the user clicks the slice and holds down the mouse button. |
448 | \sa QPieSeries::pressed() |
449 | */ |
450 | /*! |
451 | \qmlsignal PieSlice::pressed() |
452 | This signal is emitted when user clicks the slice and holds down the mouse button. |
453 | |
454 | The corresponding signal handler is \c onPressed(). |
455 | */ |
456 | |
457 | /*! |
458 | \fn void QPieSlice::released() |
459 | This signal is emitted when the user releases the mouse press on the slice. |
460 | \sa QPieSeries::released() |
461 | */ |
462 | /*! |
463 | \qmlsignal PieSlice::released() |
464 | This signal is emitted when the user releases the mouse press on the slice. |
465 | |
466 | The corresponding signal handler is \c onReleased(). |
467 | */ |
468 | |
469 | /*! |
470 | \fn void QPieSlice::doubleClicked() |
471 | This signal is emitted when user double-clicks the slice. |
472 | \sa QPieSeries::doubleClicked() |
473 | */ |
474 | /*! |
475 | \qmlsignal PieSlice::doubleClicked() |
476 | This signal is emitted when user double-clicks the slice. |
477 | |
478 | The corresponding signal handler is \c onDoubleClicked(). |
479 | */ |
480 | |
481 | /*! |
482 | \fn void QPieSlice::hovered(bool state) |
483 | This signal is emitted when a mouse is hovered over the slice. When the mouse |
484 | moves over the slice, \a state turns \c true, and when the mouse moves away |
485 | again, it turns \c false. |
486 | \sa QPieSeries::hovered() |
487 | */ |
488 | /*! |
489 | \qmlsignal PieSlice::hovered(bool state) |
490 | This signal is emitted when a mouse is hovered over the slice. When the mouse |
491 | moves over the slice, \a state turns \c true, and when the mouse moves away |
492 | again, it turns \c false. |
493 | |
494 | The corresponding signal handler is \c onHovered(). |
495 | */ |
496 | |
497 | /*! |
498 | Constructs an empty slice with the parent \a parent. |
499 | \sa QPieSeries::append(), QPieSeries::insert() |
500 | */ |
501 | QPieSlice::QPieSlice(QObject *parent) |
502 | : QObject(parent), |
503 | d_ptr(new QPieSlicePrivate(this)) |
504 | { |
505 | |
506 | } |
507 | |
508 | /*! |
509 | Constructs an empty slice with the specified \a value, \a label, and \a parent. |
510 | \sa QPieSeries::append(), QPieSeries::insert() |
511 | */ |
512 | QPieSlice::QPieSlice(QString label, qreal value, QObject *parent) |
513 | : QObject(parent), |
514 | d_ptr(new QPieSlicePrivate(this)) |
515 | { |
516 | setValue(value); |
517 | setLabel(label); |
518 | } |
519 | |
520 | /*! |
521 | Removes the slice. The slice should not be removed if it has been added to a series. |
522 | */ |
523 | QPieSlice::~QPieSlice() |
524 | { |
525 | |
526 | } |
527 | |
528 | void QPieSlice::setLabel(QString label) |
529 | { |
530 | if (d_ptr->m_data.m_labelText != label) { |
531 | d_ptr->m_data.m_labelText = label; |
532 | emit labelChanged(); |
533 | } |
534 | } |
535 | |
536 | QString QPieSlice::label() const |
537 | { |
538 | return d_ptr->m_data.m_labelText; |
539 | } |
540 | |
541 | void QPieSlice::setValue(qreal value) |
542 | { |
543 | value = qAbs(t: value); // negative values not allowed |
544 | if (!qFuzzyCompare(p1: d_ptr->m_data.m_value, p2: value)) { |
545 | d_ptr->m_data.m_value = value; |
546 | emit valueChanged(); |
547 | } |
548 | } |
549 | |
550 | qreal QPieSlice::value() const |
551 | { |
552 | return d_ptr->m_data.m_value; |
553 | } |
554 | |
555 | void QPieSlice::setLabelVisible(bool visible) |
556 | { |
557 | if (d_ptr->m_data.m_isLabelVisible != visible) { |
558 | d_ptr->m_data.m_isLabelVisible = visible; |
559 | emit labelVisibleChanged(); |
560 | } |
561 | } |
562 | |
563 | bool QPieSlice::isLabelVisible() const |
564 | { |
565 | return d_ptr->m_data.m_isLabelVisible; |
566 | } |
567 | |
568 | void QPieSlice::setExploded(bool exploded) |
569 | { |
570 | if (d_ptr->m_data.m_isExploded != exploded) { |
571 | d_ptr->m_data.m_isExploded = exploded; |
572 | emit d_ptr->explodedChanged(); |
573 | } |
574 | } |
575 | |
576 | QPieSlice::LabelPosition QPieSlice::labelPosition() |
577 | { |
578 | return d_ptr->m_data.m_labelPosition; |
579 | } |
580 | |
581 | void QPieSlice::setLabelPosition(LabelPosition position) |
582 | { |
583 | if (d_ptr->m_data.m_labelPosition != position) { |
584 | d_ptr->m_data.m_labelPosition = position; |
585 | emit d_ptr->labelPositionChanged(); |
586 | } |
587 | } |
588 | |
589 | bool QPieSlice::isExploded() const |
590 | { |
591 | return d_ptr->m_data.m_isExploded; |
592 | } |
593 | |
594 | void QPieSlice::setPen(const QPen &pen) |
595 | { |
596 | d_ptr->setPen(pen, themed: false); |
597 | } |
598 | |
599 | QPen QPieSlice::pen() const |
600 | { |
601 | return d_ptr->m_data.m_slicePen; |
602 | } |
603 | |
604 | QColor QPieSlice::borderColor() |
605 | { |
606 | return pen().color(); |
607 | } |
608 | |
609 | void QPieSlice::setBorderColor(QColor color) |
610 | { |
611 | QPen p = pen(); |
612 | if (color != p.color()) { |
613 | p.setColor(color); |
614 | setPen(p); |
615 | } |
616 | } |
617 | |
618 | int QPieSlice::borderWidth() |
619 | { |
620 | return pen().width(); |
621 | } |
622 | |
623 | void QPieSlice::setBorderWidth(int width) |
624 | { |
625 | QPen p = pen(); |
626 | if (width != p.width()) { |
627 | p.setWidth(width); |
628 | setPen(p); |
629 | } |
630 | } |
631 | |
632 | void QPieSlice::setBrush(const QBrush &brush) |
633 | { |
634 | d_ptr->setBrush(brush, themed: false); |
635 | } |
636 | |
637 | QBrush QPieSlice::brush() const |
638 | { |
639 | return d_ptr->m_data.m_sliceBrush; |
640 | } |
641 | |
642 | QColor QPieSlice::color() |
643 | { |
644 | return brush().color(); |
645 | } |
646 | |
647 | void QPieSlice::setColor(QColor color) |
648 | { |
649 | QBrush b = brush(); |
650 | |
651 | if (b == QBrush()) |
652 | b.setStyle(Qt::SolidPattern); |
653 | b.setColor(color); |
654 | setBrush(b); |
655 | } |
656 | |
657 | void QPieSlice::setLabelBrush(const QBrush &brush) |
658 | { |
659 | d_ptr->setLabelBrush(brush, themed: false); |
660 | } |
661 | |
662 | QBrush QPieSlice::labelBrush() const |
663 | { |
664 | return d_ptr->m_data.m_labelBrush; |
665 | } |
666 | |
667 | QColor QPieSlice::labelColor() |
668 | { |
669 | return labelBrush().color(); |
670 | } |
671 | |
672 | void QPieSlice::setLabelColor(QColor color) |
673 | { |
674 | QBrush b = labelBrush(); |
675 | if (color != b.color()) { |
676 | b.setColor(color); |
677 | setLabelBrush(b); |
678 | } |
679 | } |
680 | |
681 | void QPieSlice::setLabelFont(const QFont &font) |
682 | { |
683 | d_ptr->setLabelFont(font, themed: false); |
684 | } |
685 | |
686 | QFont QPieSlice::labelFont() const |
687 | { |
688 | return d_ptr->m_data.m_labelFont; |
689 | } |
690 | |
691 | void QPieSlice::setLabelArmLengthFactor(qreal factor) |
692 | { |
693 | if (!qFuzzyCompare(p1: d_ptr->m_data.m_labelArmLengthFactor, p2: factor)) { |
694 | d_ptr->m_data.m_labelArmLengthFactor = factor; |
695 | emit d_ptr->labelArmLengthFactorChanged(); |
696 | } |
697 | } |
698 | |
699 | qreal QPieSlice::labelArmLengthFactor() const |
700 | { |
701 | return d_ptr->m_data.m_labelArmLengthFactor; |
702 | } |
703 | |
704 | void QPieSlice::setExplodeDistanceFactor(qreal factor) |
705 | { |
706 | if (!qFuzzyCompare(p1: d_ptr->m_data.m_explodeDistanceFactor, p2: factor)) { |
707 | d_ptr->m_data.m_explodeDistanceFactor = factor; |
708 | emit d_ptr->explodeDistanceFactorChanged(); |
709 | } |
710 | } |
711 | |
712 | qreal QPieSlice::explodeDistanceFactor() const |
713 | { |
714 | return d_ptr->m_data.m_explodeDistanceFactor; |
715 | } |
716 | |
717 | qreal QPieSlice::percentage() const |
718 | { |
719 | return d_ptr->m_data.m_percentage; |
720 | } |
721 | |
722 | qreal QPieSlice::startAngle() const |
723 | { |
724 | return d_ptr->m_data.m_startAngle; |
725 | } |
726 | |
727 | qreal QPieSlice::angleSpan() const |
728 | { |
729 | return d_ptr->m_data.m_angleSpan; |
730 | } |
731 | |
732 | /*! |
733 | Returns the series that this slice belongs to. |
734 | |
735 | \sa QPieSeries::append() |
736 | */ |
737 | QPieSeries *QPieSlice::series() const |
738 | { |
739 | return d_ptr->m_series; |
740 | } |
741 | |
742 | QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent) |
743 | : QObject(parent), |
744 | q_ptr(parent), |
745 | m_series(0) |
746 | { |
747 | |
748 | } |
749 | |
750 | QPieSlicePrivate::~QPieSlicePrivate() |
751 | { |
752 | |
753 | } |
754 | |
755 | QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice) |
756 | { |
757 | return slice->d_func(); |
758 | } |
759 | |
760 | void QPieSlicePrivate::setPen(const QPen &pen, bool themed) |
761 | { |
762 | if (m_data.m_slicePen != pen) { |
763 | |
764 | QPen oldPen = m_data.m_slicePen; |
765 | |
766 | m_data.m_slicePen = pen; |
767 | m_data.m_slicePen.setThemed(themed); |
768 | |
769 | emit q_ptr->penChanged(); |
770 | if (oldPen.color() != pen.color()) |
771 | emit q_ptr->borderColorChanged(); |
772 | if (oldPen.width() != pen.width()) |
773 | emit q_ptr->borderWidthChanged(); |
774 | } |
775 | } |
776 | |
777 | void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed) |
778 | { |
779 | if (m_data.m_sliceBrush != brush) { |
780 | |
781 | QBrush oldBrush = m_data.m_sliceBrush; |
782 | |
783 | m_data.m_sliceBrush = brush; |
784 | m_data.m_sliceBrush.setThemed(themed); |
785 | |
786 | emit q_ptr->brushChanged(); |
787 | if (oldBrush.color() != brush.color()) |
788 | emit q_ptr->colorChanged(); |
789 | } |
790 | } |
791 | |
792 | void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed) |
793 | { |
794 | if (m_data.m_labelBrush != brush) { |
795 | |
796 | QBrush oldBrush = m_data.m_labelBrush; |
797 | |
798 | m_data.m_labelBrush = brush; |
799 | m_data.m_labelBrush.setThemed(themed); |
800 | |
801 | emit q_ptr->labelBrushChanged(); |
802 | if (oldBrush.color() != brush.color()) |
803 | emit q_ptr->labelColorChanged(); |
804 | } |
805 | } |
806 | |
807 | void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed) |
808 | { |
809 | if (m_data.m_labelFont != font) { |
810 | m_data.m_labelFont = font; |
811 | m_data.m_labelFont.setThemed(themed); |
812 | emit q_ptr->labelFontChanged(); |
813 | } |
814 | } |
815 | |
816 | void QPieSlicePrivate::setPercentage(qreal percentage) |
817 | { |
818 | if (!qFuzzyCompare(p1: m_data.m_percentage, p2: percentage)) { |
819 | m_data.m_percentage = percentage; |
820 | emit q_ptr->percentageChanged(); |
821 | } |
822 | } |
823 | |
824 | void QPieSlicePrivate::setStartAngle(qreal angle) |
825 | { |
826 | if (!qFuzzyCompare(p1: m_data.m_startAngle, p2: angle)) { |
827 | m_data.m_startAngle = angle; |
828 | emit q_ptr->startAngleChanged(); |
829 | } |
830 | } |
831 | |
832 | void QPieSlicePrivate::setAngleSpan(qreal span) |
833 | { |
834 | if (!qFuzzyCompare(p1: m_data.m_angleSpan, p2: span)) { |
835 | m_data.m_angleSpan = span; |
836 | emit q_ptr->angleSpanChanged(); |
837 | } |
838 | } |
839 | |
840 | QT_CHARTS_END_NAMESPACE |
841 | |
842 | #include "moc_qpieslice.cpp" |
843 | #include "moc_qpieslice_p.cpp" |
844 | |