##// END OF EJS Templates
Fix issues with pen/brush convenience properties and update docs
Jani Honkonen -
r1338:12de1da93c51
parent child
Show More
@@ -1,612 +1,695
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qpieslice.h"
21 #include "qpieslice.h"
22 #include "qpieslice_p.h"
22 #include "qpieslice_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QPieSlice
27 \class QPieSlice
28 \brief Defines a slice in pie series.
28 \brief Defines a slice in pie series.
29
29
30 This object defines the properties of a single slice in a QPieSeries.
30 This object defines the properties of a single slice in a QPieSeries.
31
31
32 In addition to the obvious value and label properties the user can also control
32 In addition to the obvious value and label properties the user can also control
33 the visual appearance of a slice. By modifying the visual appearance also means that
33 the visual appearance of a slice. By modifying the visual appearance also means that
34 the user is overriding the default appearance set by the theme.
34 the user is overriding the default appearance set by the theme.
35
35
36 Note that if the user has customized slices and theme is changed all customizations will be lost.
36 Note that if the user has customized slices and theme is changed all customizations will be lost.
37
37
38 To enable user interaction with the pie some basic signals are provided about clicking and hovering.
38 To enable user interaction with the pie some basic signals are provided about clicking and hovering.
39 */
39 */
40
40
41 /*!
41 /*!
42 \property QPieSlice::label
42 \property QPieSlice::label
43
43
44 Label of the slice.
44 Label of the slice.
45
45
46 \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor
46 \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor
47 */
47 */
48
48
49 /*!
49 /*!
50 \fn void QPieSlice::labelChanged()
50 \fn void QPieSlice::labelChanged()
51
51
52 This signal emitted when the slice label has been changed.
52 This signal emitted when the slice label has been changed.
53
53
54 \sa label
54 \sa label
55 */
55 */
56
56
57 /*!
57 /*!
58 \property QPieSlice::value
58 \property QPieSlice::value
59
59
60 Value of the slice.
60 Value of the slice.
61
61
62 Note that if users sets a negative value it is converted to a positive value.
62 Note that if users sets a negative value it is converted to a positive value.
63
63
64 \sa percentage(), QPieSeries::sum()
64 \sa percentage(), QPieSeries::sum()
65 */
65 */
66
66
67 /*!
67 /*!
68 \fn void QPieSlice::valueChanged()
68 \fn void QPieSlice::valueChanged()
69
69
70 This signal is emitted when the slice value changes.
70 This signal is emitted when the slice value changes.
71
71
72 \sa value
72 \sa value
73 */
73 */
74
74
75 /*!
75 /*!
76 \property QPieSlice::labelVisible
76 \property QPieSlice::labelVisible
77
77
78 Defienes the visibility of the slice label.
78 Defienes the visibility of the slice label.
79
79
80 Default is not visible.
80 Default is not visible.
81
81
82 \sa label, labelBrush, labelFont, labelArmLengthFactor
82 \sa label, labelBrush, labelFont, labelArmLengthFactor
83 */
83 */
84
84
85 /*!
85 /*!
86 \fn void QPieSlice::labelVisibleChanged()
86 \fn void QPieSlice::labelVisibleChanged()
87
87
88 This signal emitted when visibility of the slice label has changed.
88 This signal emitted when visibility of the slice label has changed.
89
89
90 \sa labelVisible
90 \sa labelVisible
91 */
91 */
92
92
93 /*!
93 /*!
94 \property QPieSlice::exploded
94 \property QPieSlice::exploded
95
95
96 Defines if the slice is exploded from the pie.
96 Defines if the slice is exploded from the pie.
97
97
98 \sa explodeDistanceFactor
98 \sa explodeDistanceFactor
99 */
99 */
100
100
101 /*!
101 /*!
102 \fn void QPieSlice::explodedChanged()
102 \fn void QPieSlice::explodedChanged()
103
103
104 This signal is emitted the the slice has been exploded from the pie or is returned back to the pie.
104 This signal is emitted the the slice has been exploded from the pie or is returned back to the pie.
105
105
106 \sa exploded
106 \sa exploded
107 */
107 */
108
108
109 /*!
109 /*!
110 \property QPieSlice::pen
110 \property QPieSlice::pen
111
111
112 Pen used to draw the slice border.
112 Pen used to draw the slice border.
113 */
113 */
114
114
115 /*!
115 /*!
116 \fn void QPieSlice::penChanged()
116 \fn void QPieSlice::penChanged()
117
117
118 This signal is emitted when the pen of the slice has changed.
118 This signal is emitted when the pen of the slice has changed.
119
119
120 \sa pen
120 \sa pen
121 */
121 */
122
122
123 /*!
123 /*!
124 \property QPieSlice::borderColor
125
126 Color used to draw the slice border.
127
128 This is a convenience property for modifying the slice pen.
129
130 \sa pen, borderWidth
131 */
132
133 /*!
134 \fn void QPieSlice::borderColorChanged()
135
136 This signal is emitted when slice border color changes.
137
138 \sa pen, borderColor
139 */
140
141 /*!
142 \property QPieSlice::borderWidth
143
144 Width of the slice border.
145
146 This is a convenience property for modifying the slice pen.
147
148 \sa pen, borderColor
149 */
150
151 /*!
152 \fn void QPieSlice::borderWidthChanged()
153
154 This signal is emitted when slice border width changes.
155
156 \sa pen, borderWidth
157 */
158
159 /*!
124 \property QPieSlice::brush
160 \property QPieSlice::brush
125
161
126 Brush used to draw the slice.
162 Brush used to draw the slice.
127 */
163 */
128
164
129 /*!
165 /*!
130 \fn void QPieSlice::brushChanged()
166 \fn void QPieSlice::brushChanged()
131
167
132 This signal is emitted when the brush of the slice has changed.
168 This signal is emitted when the brush of the slice has changed.
133
169
134 \sa brush
170 \sa brush
135 */
171 */
136
172
137 /*!
173 /*!
174 \property QPieSlice::color
175
176 Color used to draw the slice.
177
178 This is a convenience property for modifying the slice brush.
179
180 \sa brush
181 */
182
183 /*!
184 \fn void QPieSlice::colorChanged()
185
186 This signal is emitted when slice color changes.
187
188 \sa brush
189 */
190
191 /*!
138 \property QPieSlice::labelBrush
192 \property QPieSlice::labelBrush
139
193
140 Pen used to draw label and label arm of the slice.
194 Pen used to draw label and label arm of the slice.
141
195
142 \sa label, labelVisible, labelFont, labelArmLengthFactor
196 \sa label, labelVisible, labelFont, labelArmLengthFactor
143 */
197 */
144
198
145 /*!
199 /*!
146 \fn void QPieSlice::labelBrushChanged()
200 \fn void QPieSlice::labelBrushChanged()
147
201
148 This signal is emitted when the label pen of the slice has changed.
202 This signal is emitted when the label pen of the slice has changed.
149
203
150 \sa labelBrush
204 \sa labelBrush
151 */
205 */
152
206
153 /*!
207 /*!
208 \property QPieSlice::labelColor
209
210 Color used to draw the slice label.
211
212 This is a convenience property for modifying the slice label brush.
213
214 \sa labelBrush
215 */
216
217 /*!
218 \fn void QPieSlice::labelColorChanged()
219
220 This signal is emitted when slice label color changes.
221
222 \sa labelColor
223 */
224
225 /*!
154 \property QPieSlice::labelFont
226 \property QPieSlice::labelFont
155
227
156 Font used for drawing label text.
228 Font used for drawing label text.
157
229
158 \sa label, labelVisible, labelArmLengthFactor
230 \sa label, labelVisible, labelArmLengthFactor
159 */
231 */
160
232
161 /*!
233 /*!
162 \fn void QPieSlice::labelFontChanged()
234 \fn void QPieSlice::labelFontChanged()
163
235
164 This signal is emitted when the label font of the slice has changed.
236 This signal is emitted when the label font of the slice has changed.
165
237
166 \sa labelFont
238 \sa labelFont
167 */
239 */
168
240
169 /*!
241 /*!
170 \property QPieSlice::labelArmLengthFactor
242 \property QPieSlice::labelArmLengthFactor
171
243
172 Defines the length of the label arm.
244 Defines the length of the label arm.
173
245
174 The factor is relative to pie radius. For example:
246 The factor is relative to pie radius. For example:
175 1.0 means the length is the same as the radius.
247 1.0 means the length is the same as the radius.
176 0.5 means the length is half of the radius.
248 0.5 means the length is half of the radius.
177
249
178 Default value is 0.15
250 Default value is 0.15
179
251
180 \sa label, labelVisible, labelBrush, labelFont
252 \sa label, labelVisible, labelBrush, labelFont
181 */
253 */
182
254
183 /*!
255 /*!
184 \fn void QPieSlice::labelArmLengthFactorChanged()
256 \fn void QPieSlice::labelArmLengthFactorChanged()
185
257
186 This signal is emitted when the label arm factor of the slice has changed.
258 This signal is emitted when the label arm factor of the slice has changed.
187
259
188 \sa labelArmLengthFactor
260 \sa labelArmLengthFactor
189 */
261 */
190
262
191 /*!
263 /*!
192 \property QPieSlice::explodeDistanceFactor
264 \property QPieSlice::explodeDistanceFactor
193
265
194 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
266 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
195
267
196 The factor is relative to pie radius. For example:
268 The factor is relative to pie radius. For example:
197 1.0 means the distance is the same as the radius.
269 1.0 means the distance is the same as the radius.
198 0.5 means the distance is half of the radius.
270 0.5 means the distance is half of the radius.
199
271
200 Default value is 0.15
272 Default value is 0.15
201
273
202 \sa exploded
274 \sa exploded
203 */
275 */
204
276
205 /*!
277 /*!
206 \fn void QPieSlice::explodeDistanceFactorChanged()
278 \fn void QPieSlice::explodeDistanceFactorChanged()
207
279
208 This signal is emitted when the explode distance factor of the slice has changed.
280 This signal is emitted when the explode distance factor of the slice has changed.
209
281
210 \sa explodeDistanceFactor
282 \sa explodeDistanceFactor
211 */
283 */
212
284
213 /*!
285 /*!
214 \property QPieSlice::percentage
286 \property QPieSlice::percentage
215
287
216 Percentage of the slice compared to the sum of all slices in the series.
288 Percentage of the slice compared to the sum of all slices in the series.
217
289
218 The actual value ranges from 0.0 to 1.0.
290 The actual value ranges from 0.0 to 1.0.
219
291
220 Updated automatically once the slice is added to the series.
292 Updated automatically once the slice is added to the series.
221
293
222 \sa value, QPieSeries::sum
294 \sa value, QPieSeries::sum
223 */
295 */
224
296
225 /*!
297 /*!
226 \fn void QPieSlice::percentageChanged()
298 \fn void QPieSlice::percentageChanged()
227
299
228 This signal is emitted when the percentage of the slice has changed.
300 This signal is emitted when the percentage of the slice has changed.
229
301
230 \sa percentage
302 \sa percentage
231 */
303 */
232
304
233 /*!
305 /*!
234 \property QPieSlice::startAngle
306 \property QPieSlice::startAngle
235
307
236 Defines the starting angle of this slice in the series it belongs to.
308 Defines the starting angle of this slice in the series it belongs to.
237
309
238 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
310 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
239
311
240 Updated automatically once the slice is added to the series.
312 Updated automatically once the slice is added to the series.
241 */
313 */
242
314
243 /*!
315 /*!
244 \fn void QPieSlice::startAngleChanged()
316 \fn void QPieSlice::startAngleChanged()
245
317
246 This signal is emitted when the starting angle f the slice has changed.
318 This signal is emitted when the starting angle f the slice has changed.
247
319
248 \sa startAngle
320 \sa startAngle
249 */
321 */
250
322
251 /*!
323 /*!
252 \property QPieSlice::angleSpan
324 \property QPieSlice::angleSpan
253
325
254 Span of the slice in degrees.
326 Span of the slice in degrees.
255
327
256 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
328 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
257
329
258 Updated automatically once the slice is added to the series.
330 Updated automatically once the slice is added to the series.
259 */
331 */
260
332
261 /*!
333 /*!
262 \fn void QPieSlice::angleSpanChanged()
334 \fn void QPieSlice::angleSpanChanged()
263
335
264 This signal is emitted when the angle span of the slice has changed.
336 This signal is emitted when the angle span of the slice has changed.
265
337
266 \sa angleSpan
338 \sa angleSpan
267 */
339 */
268
340
269
341
270 /*!
342 /*!
271 \fn void QPieSlice::clicked()
343 \fn void QPieSlice::clicked()
272
344
273 This signal is emitted when user has clicked the slice.
345 This signal is emitted when user has clicked the slice.
274
346
275 \sa QPieSeries::clicked()
347 \sa QPieSeries::clicked()
276 */
348 */
277
349
278 /*!
350 /*!
279 \fn void QPieSlice::hovered(bool state)
351 \fn void QPieSlice::hovered(bool state)
280
352
281 This signal is emitted when user has hovered over or away from the slice.
353 This signal is emitted when user has hovered over or away from the slice.
282
354
283 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
355 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
284
356
285 \sa QPieSeries::hovered()
357 \sa QPieSeries::hovered()
286 */
358 */
287
359
288 /*!
360 /*!
289 Constructs an empty slice with a \a parent.
361 Constructs an empty slice with a \a parent.
290
362
291 \sa QPieSeries::append(), QPieSeries::insert()
363 \sa QPieSeries::append(), QPieSeries::insert()
292 */
364 */
293 QPieSlice::QPieSlice(QObject *parent)
365 QPieSlice::QPieSlice(QObject *parent)
294 :QObject(parent),
366 :QObject(parent),
295 d_ptr(new QPieSlicePrivate(this))
367 d_ptr(new QPieSlicePrivate(this))
296 {
368 {
297
369
298 }
370 }
299
371
300 /*!
372 /*!
301 Constructs an empty slice with given \a value, \a label and a \a parent.
373 Constructs an empty slice with given \a value, \a label and a \a parent.
302 \sa QPieSeries::append(), QPieSeries::insert()
374 \sa QPieSeries::append(), QPieSeries::insert()
303 */
375 */
304 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
376 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
305 :QObject(parent),
377 :QObject(parent),
306 d_ptr(new QPieSlicePrivate(this))
378 d_ptr(new QPieSlicePrivate(this))
307 {
379 {
308 setValue(value);
380 setValue(value);
309 setLabel(label);
381 setLabel(label);
310 }
382 }
311
383
312 /*!
384 /*!
313 Destroys the slice.
385 Destroys the slice.
314 User should not delete the slice if it has been added to the series.
386 User should not delete the slice if it has been added to the series.
315 */
387 */
316 QPieSlice::~QPieSlice()
388 QPieSlice::~QPieSlice()
317 {
389 {
318
390
319 }
391 }
320
392
321 void QPieSlice::setLabel(QString label)
393 void QPieSlice::setLabel(QString label)
322 {
394 {
323 if (d_ptr->m_data.m_labelText != label) {
395 if (d_ptr->m_data.m_labelText != label) {
324 d_ptr->m_data.m_labelText = label;
396 d_ptr->m_data.m_labelText = label;
325 emit labelChanged();
397 emit labelChanged();
326 }
398 }
327 }
399 }
328
400
329 QString QPieSlice::label() const
401 QString QPieSlice::label() const
330 {
402 {
331 return d_ptr->m_data.m_labelText;
403 return d_ptr->m_data.m_labelText;
332 }
404 }
333
405
334 void QPieSlice::setValue(qreal value)
406 void QPieSlice::setValue(qreal value)
335 {
407 {
336 value = qAbs(value); // negative values not allowed
408 value = qAbs(value); // negative values not allowed
337 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
409 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
338 d_ptr->m_data.m_value = value;
410 d_ptr->m_data.m_value = value;
339 emit valueChanged();
411 emit valueChanged();
340 }
412 }
341 }
413 }
342
414
343 qreal QPieSlice::value() const
415 qreal QPieSlice::value() const
344 {
416 {
345 return d_ptr->m_data.m_value;
417 return d_ptr->m_data.m_value;
346 }
418 }
347
419
348 void QPieSlice::setLabelVisible(bool visible)
420 void QPieSlice::setLabelVisible(bool visible)
349 {
421 {
350 if (d_ptr->m_data.m_isLabelVisible != visible) {
422 if (d_ptr->m_data.m_isLabelVisible != visible) {
351 d_ptr->m_data.m_isLabelVisible = visible;
423 d_ptr->m_data.m_isLabelVisible = visible;
352 emit labelVisibleChanged();
424 emit labelVisibleChanged();
353 }
425 }
354 }
426 }
355
427
356 bool QPieSlice::isLabelVisible() const
428 bool QPieSlice::isLabelVisible() const
357 {
429 {
358 return d_ptr->m_data.m_isLabelVisible;
430 return d_ptr->m_data.m_isLabelVisible;
359 }
431 }
360
432
361 void QPieSlice::setExploded(bool exploded)
433 void QPieSlice::setExploded(bool exploded)
362 {
434 {
363 if (d_ptr->m_data.m_isExploded != exploded) {
435 if (d_ptr->m_data.m_isExploded != exploded) {
364 d_ptr->m_data.m_isExploded = exploded;
436 d_ptr->m_data.m_isExploded = exploded;
365 emit explodedChanged();
437 emit explodedChanged();
366 }
438 }
367 }
439 }
368
440
369 bool QPieSlice::isExploded() const
441 bool QPieSlice::isExploded() const
370 {
442 {
371 return d_ptr->m_data.m_isExploded;
443 return d_ptr->m_data.m_isExploded;
372 }
444 }
373
445
374 void QPieSlice::setPen(const QPen &pen)
446 void QPieSlice::setPen(const QPen &pen)
375 {
447 {
376 d_ptr->setPen(pen, false);
448 d_ptr->setPen(pen, false);
377 }
449 }
378
450
379 QPen QPieSlice::pen() const
451 QPen QPieSlice::pen() const
380 {
452 {
381 return d_ptr->m_data.m_slicePen;
453 return d_ptr->m_data.m_slicePen;
382 }
454 }
383
455
456 QColor QPieSlice::borderColor()
457 {
458 return pen().color();
459 }
460
461 void QPieSlice::setBorderColor(QColor color)
462 {
463 QPen p = pen();
464 if (color != p.color()) {
465 p.setColor(color);
466 setPen(p);
467 }
468 }
469
470 int QPieSlice::borderWidth()
471 {
472 return pen().width();
473 }
474
475 void QPieSlice::setBorderWidth(int width)
476 {
477 QPen p = pen();
478 if (width != p.width()) {
479 p.setWidth(width);
480 setPen(p);
481 }
482 }
483
384 void QPieSlice::setBrush(const QBrush &brush)
484 void QPieSlice::setBrush(const QBrush &brush)
385 {
485 {
386 d_ptr->setBrush(brush, false);
486 d_ptr->setBrush(brush, false);
387 }
487 }
388
488
389 QBrush QPieSlice::brush() const
489 QBrush QPieSlice::brush() const
390 {
490 {
391 return d_ptr->m_data.m_sliceBrush;
491 return d_ptr->m_data.m_sliceBrush;
392 }
492 }
393
493
494 QColor QPieSlice::color()
495 {
496 return brush().color();
497 }
498
499 void QPieSlice::setColor(QColor color)
500 {
501 QBrush b = brush();
502 if (color != b.color()) {
503 b.setColor(color);
504 setBrush(b);
505 }
506 }
507
394 void QPieSlice::setLabelBrush(const QBrush &brush)
508 void QPieSlice::setLabelBrush(const QBrush &brush)
395 {
509 {
396 d_ptr->setLabelBrush(brush, false);
510 d_ptr->setLabelBrush(brush, false);
397 }
511 }
398
512
399 QBrush QPieSlice::labelBrush() const
513 QBrush QPieSlice::labelBrush() const
400 {
514 {
401 return d_ptr->m_data.m_labelBrush;
515 return d_ptr->m_data.m_labelBrush;
402 }
516 }
403
517
518 QColor QPieSlice::labelColor()
519 {
520 return labelBrush().color();
521 }
522
523 void QPieSlice::setLabelColor(QColor color)
524 {
525 QBrush b = labelBrush();
526 if (color != b.color()) {
527 b.setColor(color);
528 setLabelBrush(b);
529 }
530 }
531
404 void QPieSlice::setLabelFont(const QFont &font)
532 void QPieSlice::setLabelFont(const QFont &font)
405 {
533 {
406 d_ptr->setLabelFont(font, false);
534 d_ptr->setLabelFont(font, false);
407 }
535 }
408
536
409 QFont QPieSlice::labelFont() const
537 QFont QPieSlice::labelFont() const
410 {
538 {
411 return d_ptr->m_data.m_labelFont;
539 return d_ptr->m_data.m_labelFont;
412 }
540 }
413
541
414 void QPieSlice::setLabelArmLengthFactor(qreal factor)
542 void QPieSlice::setLabelArmLengthFactor(qreal factor)
415 {
543 {
416 if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) {
544 if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) {
417 d_ptr->m_data.m_labelArmLengthFactor = factor;
545 d_ptr->m_data.m_labelArmLengthFactor = factor;
418 emit labelArmLengthFactorChanged();
546 emit labelArmLengthFactorChanged();
419 }
547 }
420 }
548 }
421
549
422 qreal QPieSlice::labelArmLengthFactor() const
550 qreal QPieSlice::labelArmLengthFactor() const
423 {
551 {
424 return d_ptr->m_data.m_labelArmLengthFactor;
552 return d_ptr->m_data.m_labelArmLengthFactor;
425 }
553 }
426
554
427 void QPieSlice::setExplodeDistanceFactor(qreal factor)
555 void QPieSlice::setExplodeDistanceFactor(qreal factor)
428 {
556 {
429 if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) {
557 if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) {
430 d_ptr->m_data.m_explodeDistanceFactor = factor;
558 d_ptr->m_data.m_explodeDistanceFactor = factor;
431 emit explodeDistanceFactorChanged();
559 emit explodeDistanceFactorChanged();
432 }
560 }
433 }
561 }
434
562
435 qreal QPieSlice::explodeDistanceFactor() const
563 qreal QPieSlice::explodeDistanceFactor() const
436 {
564 {
437 return d_ptr->m_data.m_explodeDistanceFactor;
565 return d_ptr->m_data.m_explodeDistanceFactor;
438 }
566 }
439
567
440 qreal QPieSlice::percentage() const
568 qreal QPieSlice::percentage() const
441 {
569 {
442 return d_ptr->m_data.m_percentage;
570 return d_ptr->m_data.m_percentage;
443 }
571 }
444
572
445 qreal QPieSlice::startAngle() const
573 qreal QPieSlice::startAngle() const
446 {
574 {
447 return d_ptr->m_data.m_startAngle;
575 return d_ptr->m_data.m_startAngle;
448 }
576 }
449
577
450 qreal QPieSlice::angleSpan() const
578 qreal QPieSlice::angleSpan() const
451 {
579 {
452 return d_ptr->m_data.m_angleSpan;
580 return d_ptr->m_data.m_angleSpan;
453 }
581 }
454
582
455 QColor QPieSlice::color()
456 {
457 return brush().color();
458 }
459
460 void QPieSlice::setColor(QColor color)
461 {
462 QBrush b = brush();
463 if (color != b.color()) {
464 b.setColor(color);
465 setBrush(b);
466 }
467 }
468
469 QColor QPieSlice::borderColor()
470 {
471 return pen().color();
472 }
473
474 void QPieSlice::setBorderColor(QColor color)
475 {
476 QPen p = pen();
477 if (color != p.color()) {
478 p.setColor(color);
479 setPen(p);
480 emit borderColorChanged();
481 }
482 }
483
484 int QPieSlice::borderWidth()
485 {
486 return pen().width();
487 }
488
489 void QPieSlice::setBorderWidth(int width)
490 {
491 QPen p = pen();
492 if (width != p.width()) {
493 p.setWidth(width);
494 setPen(p);
495 }
496 }
497
498 QColor QPieSlice::labelColor()
499 {
500 return labelBrush().color();
501 }
502
503 void QPieSlice::setLabelColor(QColor color)
504 {
505 QBrush b = labelBrush();
506 if (color != b.color()) {
507 b.setColor(color);
508 setLabelBrush(b);
509 }
510 }
511
512 /*!
583 /*!
513 Returns the series that this slice belongs to.
584 Returns the series that this slice belongs to.
514
585
515 \sa QPieSeries::append()
586 \sa QPieSeries::append()
516 */
587 */
517 QPieSeries *QPieSlice::series() const
588 QPieSeries *QPieSlice::series() const
518 {
589 {
519 return d_ptr->m_series;
590 return d_ptr->m_series;
520 }
591 }
521
592
522 QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent)
593 QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent)
523 :QObject(parent),
594 :QObject(parent),
524 q_ptr(parent),
595 q_ptr(parent),
525 m_series(0)
596 m_series(0)
526 {
597 {
527
598
528 }
599 }
529
600
530 QPieSlicePrivate::~QPieSlicePrivate()
601 QPieSlicePrivate::~QPieSlicePrivate()
531 {
602 {
532
603
533 }
604 }
534
605
535 QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice)
606 QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice)
536 {
607 {
537 return slice->d_func();
608 return slice->d_func();
538 }
609 }
539
610
540 void QPieSlicePrivate::setPen(const QPen &pen, bool themed)
611 void QPieSlicePrivate::setPen(const QPen &pen, bool themed)
541 {
612 {
542 if (m_data.m_slicePen != pen) {
613 if (m_data.m_slicePen != pen) {
543 if (m_data.m_slicePen.color() != pen.color())
614
544 emit q_ptr->borderColorChanged();
615 QPen oldPen = m_data.m_slicePen;
545 if (m_data.m_slicePen.width() != pen.width())
616
546 emit q_ptr->borderWidthChanged();
547 m_data.m_slicePen = pen;
617 m_data.m_slicePen = pen;
548 m_data.m_slicePen.setThemed(themed);
618 m_data.m_slicePen.setThemed(themed);
619
549 emit q_ptr->penChanged();
620 emit q_ptr->penChanged();
621 if (oldPen.color() != pen.color())
622 emit q_ptr->borderColorChanged();
623 if (oldPen.width() != pen.width())
624 emit q_ptr->borderWidthChanged();
550 }
625 }
551 }
626 }
552
627
553 void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed)
628 void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed)
554 {
629 {
555 if (m_data.m_sliceBrush != brush) {
630 if (m_data.m_sliceBrush != brush) {
556 if (m_data.m_sliceBrush.color() != brush.color())
631
557 emit q_ptr->colorChanged();
632 QBrush oldBrush = m_data.m_sliceBrush;
633
558 m_data.m_sliceBrush = brush;
634 m_data.m_sliceBrush = brush;
559 m_data.m_sliceBrush.setThemed(themed);
635 m_data.m_sliceBrush.setThemed(themed);
636
560 emit q_ptr->brushChanged();
637 emit q_ptr->brushChanged();
638 if (oldBrush.color() != brush.color())
639 emit q_ptr->colorChanged();
561 }
640 }
562 }
641 }
563
642
564 void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed)
643 void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed)
565 {
644 {
566 if (m_data.m_labelBrush != brush) {
645 if (m_data.m_labelBrush != brush) {
567 if (m_data.m_labelBrush.color() != brush.color())
646
568 emit q_ptr->labelColorChanged();
647 QBrush oldBrush = m_data.m_labelBrush;
648
569 m_data.m_labelBrush = brush;
649 m_data.m_labelBrush = brush;
570 m_data.m_labelBrush.setThemed(themed);
650 m_data.m_labelBrush.setThemed(themed);
651
571 emit q_ptr->labelBrushChanged();
652 emit q_ptr->labelBrushChanged();
653 if (oldBrush.color() != brush.color())
654 emit q_ptr->labelColorChanged();
572 }
655 }
573 }
656 }
574
657
575 void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed)
658 void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed)
576 {
659 {
577 if (m_data.m_labelFont != font) {
660 if (m_data.m_labelFont != font) {
578 m_data.m_labelFont = font;
661 m_data.m_labelFont = font;
579 m_data.m_labelFont.setThemed(themed);
662 m_data.m_labelFont.setThemed(themed);
580 emit q_ptr->labelFontChanged();
663 emit q_ptr->labelFontChanged();
581 }
664 }
582 }
665 }
583
666
584 void QPieSlicePrivate::setPercentage(qreal percentage)
667 void QPieSlicePrivate::setPercentage(qreal percentage)
585 {
668 {
586 if (!qFuzzyIsNull(m_data.m_percentage - percentage)) {
669 if (!qFuzzyIsNull(m_data.m_percentage - percentage)) {
587 m_data.m_percentage = percentage;
670 m_data.m_percentage = percentage;
588 emit q_ptr->percentageChanged();
671 emit q_ptr->percentageChanged();
589 }
672 }
590 }
673 }
591
674
592 void QPieSlicePrivate::setStartAngle(qreal angle)
675 void QPieSlicePrivate::setStartAngle(qreal angle)
593 {
676 {
594 if (!qFuzzyIsNull(m_data.m_startAngle - angle)) {
677 if (!qFuzzyIsNull(m_data.m_startAngle - angle)) {
595 m_data.m_startAngle = angle;
678 m_data.m_startAngle = angle;
596 emit q_ptr->startAngleChanged();
679 emit q_ptr->startAngleChanged();
597 }
680 }
598 }
681 }
599
682
600 void QPieSlicePrivate::setAngleSpan(qreal span)
683 void QPieSlicePrivate::setAngleSpan(qreal span)
601 {
684 {
602 if (!qFuzzyIsNull(m_data.m_angleSpan - span)) {
685 if (!qFuzzyIsNull(m_data.m_angleSpan - span)) {
603 m_data.m_angleSpan = span;
686 m_data.m_angleSpan = span;
604 emit q_ptr->angleSpanChanged();
687 emit q_ptr->angleSpanChanged();
605 }
688 }
606 }
689 }
607
690
608 QTCOMMERCIALCHART_END_NAMESPACE
691 QTCOMMERCIALCHART_END_NAMESPACE
609
692
610 QTCOMMERCIALCHART_USE_NAMESPACE
693 QTCOMMERCIALCHART_USE_NAMESPACE
611 #include "moc_qpieslice.cpp"
694 #include "moc_qpieslice.cpp"
612 #include "moc_qpieslice_p.cpp"
695 #include "moc_qpieslice_p.cpp"
@@ -1,134 +1,137
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QPIESLICE_H
21 #ifndef QPIESLICE_H
22 #define QPIESLICE_H
22 #define QPIESLICE_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QObject>
25 #include <QObject>
26 #include <QPen>
26 #include <QPen>
27 #include <QBrush>
27 #include <QBrush>
28 #include <QFont>
28 #include <QFont>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 class QPieSlicePrivate;
31 class QPieSlicePrivate;
32 class QPieSeries;
32 class QPieSeries;
33
33
34 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
34 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
35 {
35 {
36 Q_OBJECT
36 Q_OBJECT
37 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
37 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
38 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
38 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
39 Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY labelVisibleChanged)
39 Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY labelVisibleChanged)
40 Q_PROPERTY(bool exploded READ isExploded WRITE setExploded NOTIFY explodedChanged)
40 Q_PROPERTY(bool exploded READ isExploded WRITE setExploded NOTIFY explodedChanged)
41 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
41 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
42 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
43 Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged)
42 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
44 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
45 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
43 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
46 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
47 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
44 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
48 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
45 Q_PROPERTY(qreal labelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor)
49 Q_PROPERTY(qreal labelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor)
46 Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor)
50 Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor)
47 Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged)
51 Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged)
48 Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged)
52 Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged)
49 Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged)
53 Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged)
50 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
51 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
52 Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged)
53 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
54
54
55 public:
55 public:
56 explicit QPieSlice(QObject *parent = 0);
56 explicit QPieSlice(QObject *parent = 0);
57 QPieSlice(QString label, qreal value, QObject *parent = 0);
57 QPieSlice(QString label, qreal value, QObject *parent = 0);
58 virtual ~QPieSlice();
58 virtual ~QPieSlice();
59
59
60 void setLabel(QString label);
60 void setLabel(QString label);
61 QString label() const;
61 QString label() const;
62
62
63 void setValue(qreal value);
63 void setValue(qreal value);
64 qreal value() const;
64 qreal value() const;
65
65
66 void setLabelVisible(bool visible = true);
66 void setLabelVisible(bool visible = true);
67 bool isLabelVisible() const;
67 bool isLabelVisible() const;
68
68
69 void setExploded(bool exploded = true);
69 void setExploded(bool exploded = true);
70 bool isExploded() const;
70 bool isExploded() const;
71
71
72 void setPen(const QPen &pen);
72 void setPen(const QPen &pen);
73 QPen pen() const;
73 QPen pen() const;
74
74
75 QColor borderColor();
76 void setBorderColor(QColor color);
77
78 int borderWidth();
79 void setBorderWidth(int width);
80
75 void setBrush(const QBrush &brush);
81 void setBrush(const QBrush &brush);
76 QBrush brush() const;
82 QBrush brush() const;
77
83
84 QColor color();
85 void setColor(QColor color);
86
78 void setLabelBrush(const QBrush &brush);
87 void setLabelBrush(const QBrush &brush);
79 QBrush labelBrush() const;
88 QBrush labelBrush() const;
80
89
90 QColor labelColor();
91 void setLabelColor(QColor color);
92
81 void setLabelFont(const QFont &font);
93 void setLabelFont(const QFont &font);
82 QFont labelFont() const;
94 QFont labelFont() const;
83
95
84 void setLabelArmLengthFactor(qreal factor);
96 void setLabelArmLengthFactor(qreal factor);
85 qreal labelArmLengthFactor() const;
97 qreal labelArmLengthFactor() const;
86
98
87 void setExplodeDistanceFactor(qreal factor);
99 void setExplodeDistanceFactor(qreal factor);
88 qreal explodeDistanceFactor() const;
100 qreal explodeDistanceFactor() const;
89
101
90 qreal percentage() const;
102 qreal percentage() const;
91 qreal startAngle() const;
103 qreal startAngle() const;
92 qreal angleSpan() const;
104 qreal angleSpan() const;
93
105
94 QColor color();
95 void setColor(QColor color);
96 QColor borderColor();
97 void setBorderColor(QColor color);
98 int borderWidth();
99 void setBorderWidth(int width);
100 QColor labelColor();
101 void setLabelColor(QColor color);
102
103 QPieSeries *series() const;
106 QPieSeries *series() const;
104
107
105 Q_SIGNALS:
108 Q_SIGNALS:
106 void labelChanged();
109 void labelChanged();
107 void valueChanged();
110 void valueChanged();
108 void labelVisibleChanged();
111 void labelVisibleChanged();
109 void explodedChanged();
112 void explodedChanged();
110 void penChanged();
113 void penChanged();
111 void brushChanged();
114 void brushChanged();
112 void labelBrushChanged();
115 void labelBrushChanged();
113 void labelFontChanged();
116 void labelFontChanged();
114 void labelArmLengthFactorChanged();
117 void labelArmLengthFactorChanged();
115 void explodeDistanceFactorChanged();
118 void explodeDistanceFactorChanged();
116 void percentageChanged();
119 void percentageChanged();
117 void startAngleChanged();
120 void startAngleChanged();
118 void angleSpanChanged();
121 void angleSpanChanged();
119 void colorChanged();
122 void colorChanged();
120 void borderColorChanged();
123 void borderColorChanged();
121 void borderWidthChanged();
124 void borderWidthChanged();
122 void labelColorChanged();
125 void labelColorChanged();
123 void clicked();
126 void clicked();
124 void hovered(bool state);
127 void hovered(bool state);
125
128
126 private:
129 private:
127 QPieSlicePrivate * const d_ptr;
130 QPieSlicePrivate * const d_ptr;
128 Q_DECLARE_PRIVATE(QPieSlice)
131 Q_DECLARE_PRIVATE(QPieSlice)
129 Q_DISABLE_COPY(QPieSlice)
132 Q_DISABLE_COPY(QPieSlice)
130 };
133 };
131
134
132 QTCOMMERCIALCHART_END_NAMESPACE
135 QTCOMMERCIALCHART_END_NAMESPACE
133
136
134 #endif // QPIESLICE_H
137 #endif // QPIESLICE_H
General Comments 0
You need to be logged in to leave comments. Login now