##// END OF EJS Templates
Fixed bug in initializing color of a slice
Tero Ahola -
r1830:8e5bf6056dce
parent child
Show More
@@ -1,780 +1,781
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 \qmlclass PieSlice QPieSlice
42 \qmlclass PieSlice QPieSlice
43 PieSlice defines the properties of a single slice in a PieSeries. The element should be used
43 PieSlice defines the properties of a single slice in a PieSeries. The element should be used
44 as a child for a PieSeries. For example:
44 as a child for a PieSeries. For example:
45 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
45 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
46
46
47 An alternative (dynamic) method for adding slices to a PieSeries is using PieSeries.append
47 An alternative (dynamic) method for adding slices to a PieSeries is using PieSeries.append
48 method.
48 method.
49 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 4
49 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 4
50
50
51 In that case you may want to use PieSeries.at or PieSeries.find to access the properties of
51 In that case you may want to use PieSeries.at or PieSeries.find to access the properties of
52 an individual PieSlice instance.
52 an individual PieSlice instance.
53 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 5
53 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 5
54 \sa PieSeries
54 \sa PieSeries
55 */
55 */
56
56
57 /*!
57 /*!
58 \enum QPieSlice::LabelPosition
58 \enum QPieSlice::LabelPosition
59
59
60 This enum describes the position of the slice label.
60 This enum describes the position of the slice label.
61
61
62 \value LabelOutside Label is outside the slice with an arm.
62 \value LabelOutside Label is outside the slice with an arm.
63 \value LabelInsideHorizontal Label is centered inside the slice and laid out horizontally.
63 \value LabelInsideHorizontal Label is centered inside the slice and laid out horizontally.
64 \value LabelInsideTangential Label is centered inside the slice and rotated to be parallel to the tangential of the slice's arc.
64 \value LabelInsideTangential Label is centered inside the slice and rotated to be parallel to the tangential of the slice's arc.
65 \value LabelInsideNormal Label is centered inside the slice rotated to be parallel to the normal of the slice's arc.
65 \value LabelInsideNormal Label is centered inside the slice rotated to be parallel to the normal of the slice's arc.
66 */
66 */
67
67
68 /*!
68 /*!
69 \property QPieSlice::label
69 \property QPieSlice::label
70 Label of the slice.
70 Label of the slice.
71 \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor
71 \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor
72 */
72 */
73 /*!
73 /*!
74 \qmlproperty string PieSlice::label
74 \qmlproperty string PieSlice::label
75 Label (text) of the slice.
75 Label (text) of the slice.
76 */
76 */
77
77
78 /*!
78 /*!
79 \fn void QPieSlice::labelChanged()
79 \fn void QPieSlice::labelChanged()
80 This signal emitted when the slice label has been changed.
80 This signal emitted when the slice label has been changed.
81 \sa label
81 \sa label
82 */
82 */
83 /*!
83 /*!
84 \qmlsignal PieSlice::onLabelChanged()
84 \qmlsignal PieSlice::onLabelChanged()
85 This signal emitted when the slice label has been changed.
85 This signal emitted when the slice label has been changed.
86 \sa label
86 \sa label
87 */
87 */
88
88
89 /*!
89 /*!
90 \property QPieSlice::value
90 \property QPieSlice::value
91 Value of the slice.
91 Value of the slice.
92 Note that if users sets a negative value it is converted to a positive value.
92 Note that if users sets a negative value it is converted to a positive value.
93 \sa percentage(), QPieSeries::sum()
93 \sa percentage(), QPieSeries::sum()
94 */
94 */
95 /*!
95 /*!
96 \qmlproperty real PieSlice::value
96 \qmlproperty real PieSlice::value
97 Value of the slice. Note that if users sets a negative value it is converted to a positive value.
97 Value of the slice. Note that if users sets a negative value it is converted to a positive value.
98 */
98 */
99
99
100 /*!
100 /*!
101 \fn void QPieSlice::valueChanged()
101 \fn void QPieSlice::valueChanged()
102 This signal is emitted when the slice value changes.
102 This signal is emitted when the slice value changes.
103 \sa value
103 \sa value
104 */
104 */
105 /*!
105 /*!
106 \qmlsignal PieSlice::onValueChanged()
106 \qmlsignal PieSlice::onValueChanged()
107 This signal is emitted when the slice value changes.
107 This signal is emitted when the slice value changes.
108 \sa value
108 \sa value
109 */
109 */
110
110
111 /*!
111 /*!
112 \property QPieSlice::labelVisible
112 \property QPieSlice::labelVisible
113 Defines the visibility of slice label. By default the label is not visible.
113 Defines the visibility of slice label. By default the label is not visible.
114 \sa label, labelBrush, labelFont, labelArmLengthFactor
114 \sa label, labelBrush, labelFont, labelArmLengthFactor
115 */
115 */
116 /*!
116 /*!
117 \qmlproperty bool PieSlice::labelVisible
117 \qmlproperty bool PieSlice::labelVisible
118 Defines the visibility of slice label. By default the label is not visible.
118 Defines the visibility of slice label. By default the label is not visible.
119 */
119 */
120
120
121 /*!
121 /*!
122 \fn void QPieSlice::labelVisibleChanged()
122 \fn void QPieSlice::labelVisibleChanged()
123 This signal emitted when visibility of the slice label has changed.
123 This signal emitted when visibility of the slice label has changed.
124 \sa labelVisible
124 \sa labelVisible
125 */
125 */
126 /*!
126 /*!
127 \qmlsignal PieSlice::onLabelVisibleChanged()
127 \qmlsignal PieSlice::onLabelVisibleChanged()
128 This signal emitted when visibility of the slice label has changed.
128 This signal emitted when visibility of the slice label has changed.
129 \sa labelVisible
129 \sa labelVisible
130 */
130 */
131
131
132 /*!
132 /*!
133 \property QPieSlice::exploded
133 \property QPieSlice::exploded
134 If set to true the slice is "exploded" away from the pie.
134 If set to true the slice is "exploded" away from the pie.
135 \sa explodeDistanceFactor
135 \sa explodeDistanceFactor
136 */
136 */
137 /*!
137 /*!
138 \qmlproperty bool PieSlice::exploded
138 \qmlproperty bool PieSlice::exploded
139 If set to true the slice is "exploded" away from the pie.
139 If set to true the slice is "exploded" away from the pie.
140 \sa explodeDistanceFactor
140 \sa explodeDistanceFactor
141 */
141 */
142
142
143 /*!
143 /*!
144 \property QPieSlice::pen
144 \property QPieSlice::pen
145 Pen used to draw the slice border.
145 Pen used to draw the slice border.
146 */
146 */
147
147
148 /*!
148 /*!
149 \fn void QPieSlice::penChanged()
149 \fn void QPieSlice::penChanged()
150 This signal is emitted when the pen of the slice has changed.
150 This signal is emitted when the pen of the slice has changed.
151 \sa pen
151 \sa pen
152 */
152 */
153
153
154 /*!
154 /*!
155 \property QPieSlice::borderColor
155 \property QPieSlice::borderColor
156 Color used to draw the slice border.
156 Color used to draw the slice border.
157 This is a convenience property for modifying the slice pen.
157 This is a convenience property for modifying the slice pen.
158 \sa pen, borderWidth
158 \sa pen, borderWidth
159 */
159 */
160 /*!
160 /*!
161 \qmlproperty color PieSlice::borderColor
161 \qmlproperty color PieSlice::borderColor
162 Color used to draw the slice border (pen color).
162 Color used to draw the slice border (pen color).
163 \sa borderWidth
163 \sa borderWidth
164 */
164 */
165
165
166 /*!
166 /*!
167 \fn void QPieSlice::borderColorChanged()
167 \fn void QPieSlice::borderColorChanged()
168 This signal is emitted when slice border color changes.
168 This signal is emitted when slice border color changes.
169 \sa pen, borderColor
169 \sa pen, borderColor
170 */
170 */
171 /*!
171 /*!
172 \qmlsignal PieSlice::onBorderColorChanged()
172 \qmlsignal PieSlice::onBorderColorChanged()
173 This signal is emitted when slice border color changes.
173 This signal is emitted when slice border color changes.
174 \sa borderColor
174 \sa borderColor
175 */
175 */
176
176
177 /*!
177 /*!
178 \property QPieSlice::borderWidth
178 \property QPieSlice::borderWidth
179 Width of the slice border.
179 Width of the slice border.
180 This is a convenience property for modifying the slice pen.
180 This is a convenience property for modifying the slice pen.
181 \sa pen, borderColor
181 \sa pen, borderColor
182 */
182 */
183 /*!
183 /*!
184 \qmlproperty int PieSlice::borderWidth
184 \qmlproperty int PieSlice::borderWidth
185 Width of the slice border.
185 Width of the slice border.
186 This is a convenience property for modifying the slice pen.
186 This is a convenience property for modifying the slice pen.
187 \sa borderColor
187 \sa borderColor
188 */
188 */
189
189
190 /*!
190 /*!
191 \fn void QPieSlice::borderWidthChanged()
191 \fn void QPieSlice::borderWidthChanged()
192 This signal is emitted when slice border width changes.
192 This signal is emitted when slice border width changes.
193 \sa pen, borderWidth
193 \sa pen, borderWidth
194 */
194 */
195 /*!
195 /*!
196 \qmlsignal PieSlice::onBorderWidthChanged()
196 \qmlsignal PieSlice::onBorderWidthChanged()
197 This signal is emitted when slice border width changes.
197 This signal is emitted when slice border width changes.
198 \sa borderWidth
198 \sa borderWidth
199 */
199 */
200
200
201 /*!
201 /*!
202 \property QPieSlice::brush
202 \property QPieSlice::brush
203 Brush used to draw the slice.
203 Brush used to draw the slice.
204 */
204 */
205
205
206 /*!
206 /*!
207 \fn void QPieSlice::brushChanged()
207 \fn void QPieSlice::brushChanged()
208 This signal is emitted when the brush of the slice has changed.
208 This signal is emitted when the brush of the slice has changed.
209 \sa brush
209 \sa brush
210 */
210 */
211
211
212 /*!
212 /*!
213 \property QPieSlice::color
213 \property QPieSlice::color
214 Fill (brush) color of the slice.
214 Fill (brush) color of the slice.
215 This is a convenience property for modifying the slice brush.
215 This is a convenience property for modifying the slice brush.
216 \sa brush
216 \sa brush
217 */
217 */
218 /*!
218 /*!
219 \qmlproperty color PieSlice::color
219 \qmlproperty color PieSlice::color
220 Fill (brush) color of the slice.
220 Fill (brush) color of the slice.
221 */
221 */
222
222
223 /*!
223 /*!
224 \fn void QPieSlice::colorChanged()
224 \fn void QPieSlice::colorChanged()
225 This signal is emitted when slice color changes.
225 This signal is emitted when slice color changes.
226 \sa brush
226 \sa brush
227 */
227 */
228 /*!
228 /*!
229 \qmlsignal PieSlice::onColorChanged()
229 \qmlsignal PieSlice::onColorChanged()
230 This signal is emitted when slice color changes.
230 This signal is emitted when slice color changes.
231 */
231 */
232
232
233 /*!
233 /*!
234 \property QPieSlice::labelBrush
234 \property QPieSlice::labelBrush
235 Brush used to draw label and label arm of the slice.
235 Brush used to draw label and label arm of the slice.
236 \sa label, labelVisible, labelFont, labelArmLengthFactor
236 \sa label, labelVisible, labelFont, labelArmLengthFactor
237 */
237 */
238
238
239 /*!
239 /*!
240 \fn void QPieSlice::labelBrushChanged()
240 \fn void QPieSlice::labelBrushChanged()
241 This signal is emitted when the label brush of the slice has changed.
241 This signal is emitted when the label brush of the slice has changed.
242 \sa labelBrush
242 \sa labelBrush
243 */
243 */
244
244
245 /*!
245 /*!
246 \property QPieSlice::labelColor
246 \property QPieSlice::labelColor
247 Color used to draw the slice label.
247 Color used to draw the slice label.
248 This is a convenience property for modifying the slice label brush.
248 This is a convenience property for modifying the slice label brush.
249 \sa labelBrush
249 \sa labelBrush
250 */
250 */
251 /*!
251 /*!
252 \qmlproperty color PieSlice::labelColor
252 \qmlproperty color PieSlice::labelColor
253 Color used to draw the slice label.
253 Color used to draw the slice label.
254 */
254 */
255
255
256 /*!
256 /*!
257 \fn void QPieSlice::labelColorChanged()
257 \fn void QPieSlice::labelColorChanged()
258 This signal is emitted when slice label color changes.
258 This signal is emitted when slice label color changes.
259 \sa labelColor
259 \sa labelColor
260 */
260 */
261 /*!
261 /*!
262 \qmlsignal PieSlice::onLabelColorChanged()
262 \qmlsignal PieSlice::onLabelColorChanged()
263 This signal is emitted when slice label color changes.
263 This signal is emitted when slice label color changes.
264 \sa labelColor
264 \sa labelColor
265 */
265 */
266
266
267 /*!
267 /*!
268 \property QPieSlice::labelFont
268 \property QPieSlice::labelFont
269 Font used for drawing label text.
269 Font used for drawing label text.
270 \sa label, labelVisible, labelArmLengthFactor
270 \sa label, labelVisible, labelArmLengthFactor
271 */
271 */
272
272
273 /*!
273 /*!
274 \fn void QPieSlice::labelFontChanged()
274 \fn void QPieSlice::labelFontChanged()
275 This signal is emitted when the label font of the slice has changed.
275 This signal is emitted when the label font of the slice has changed.
276 \sa labelFont
276 \sa labelFont
277 */
277 */
278
278
279 /*!
279 /*!
280 \qmlproperty Font PieSlice::labelFont
280 \qmlproperty Font PieSlice::labelFont
281
281
282 Defines the font used for slice label.
282 Defines the font used for slice label.
283
283
284 See the \l {Font} {QML Font Element} for detailed documentation.
284 See the \l {Font} {QML Font Element} for detailed documentation.
285
285
286 \sa labelVisible, labelPosition
286 \sa labelVisible, labelPosition
287 */
287 */
288
288
289 /*!
289 /*!
290 \property QPieSlice::labelPosition
290 \property QPieSlice::labelPosition
291 Position of the slice label.
291 Position of the slice label.
292 \sa label, labelVisible
292 \sa label, labelVisible
293 */
293 */
294 /*!
294 /*!
295 \qmlproperty LabelPosition PieSlice::labelPosition
295 \qmlproperty LabelPosition PieSlice::labelPosition
296 Position of the slice label. One of PieSlice.LabelOutside or PieSlice.LabelInside.
296 Position of the slice label. One of PieSlice.LabelOutside or PieSlice.LabelInside.
297 \sa labelVisible
297 \sa labelVisible
298 */
298 */
299
299
300 /*!
300 /*!
301 \property QPieSlice::labelArmLengthFactor
301 \property QPieSlice::labelArmLengthFactor
302 Defines the length of the label arm.
302 Defines the length of the label arm.
303 The factor is relative to pie radius. For example:
303 The factor is relative to pie radius. For example:
304 1.0 means the length is the same as the radius.
304 1.0 means the length is the same as the radius.
305 0.5 means the length is half of the radius.
305 0.5 means the length is half of the radius.
306 By default the arm length is 0.15
306 By default the arm length is 0.15
307 \sa label, labelVisible, labelBrush, labelFont
307 \sa label, labelVisible, labelBrush, labelFont
308 */
308 */
309 /*!
309 /*!
310 \qmlproperty real PieSlice::labelArmLengthFactor
310 \qmlproperty real PieSlice::labelArmLengthFactor
311 Defines the length of the label arm.
311 Defines the length of the label arm.
312 The factor is relative to pie radius. For example:
312 The factor is relative to pie radius. For example:
313 1.0 means the length is the same as the radius.
313 1.0 means the length is the same as the radius.
314 0.5 means the length is half of the radius.
314 0.5 means the length is half of the radius.
315 By default the arm length is 0.15
315 By default the arm length is 0.15
316 \sa labelVisible
316 \sa labelVisible
317 */
317 */
318
318
319 /*!
319 /*!
320 \property QPieSlice::explodeDistanceFactor
320 \property QPieSlice::explodeDistanceFactor
321 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
321 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
322 The factor is relative to pie radius. For example:
322 The factor is relative to pie radius. For example:
323 1.0 means the distance is the same as the radius.
323 1.0 means the distance is the same as the radius.
324 0.5 means the distance is half of the radius.
324 0.5 means the distance is half of the radius.
325 By default the distance is is 0.15
325 By default the distance is is 0.15
326 \sa exploded
326 \sa exploded
327 */
327 */
328 /*!
328 /*!
329 \qmlproperty real PieSlice::explodeDistanceFactor
329 \qmlproperty real PieSlice::explodeDistanceFactor
330 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
330 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
331 The factor is relative to pie radius. For example:
331 The factor is relative to pie radius. For example:
332 1.0 means the distance is the same as the radius.
332 1.0 means the distance is the same as the radius.
333 0.5 means the distance is half of the radius.
333 0.5 means the distance is half of the radius.
334 By default the distance is is 0.15
334 By default the distance is is 0.15
335 \sa exploded
335 \sa exploded
336 */
336 */
337
337
338 /*!
338 /*!
339 \property QPieSlice::percentage
339 \property QPieSlice::percentage
340 Percentage of the slice compared to the sum of all slices in the series.
340 Percentage of the slice compared to the sum of all slices in the series.
341 The actual value ranges from 0.0 to 1.0.
341 The actual value ranges from 0.0 to 1.0.
342 Updated automatically once the slice is added to the series.
342 Updated automatically once the slice is added to the series.
343 \sa value, QPieSeries::sum
343 \sa value, QPieSeries::sum
344 */
344 */
345 /*!
345 /*!
346 \qmlproperty real PieSlice::percentage
346 \qmlproperty real PieSlice::percentage
347 Percentage of the slice compared to the sum of all slices in the series.
347 Percentage of the slice compared to the sum of all slices in the series.
348 The actual value ranges from 0.0 to 1.0.
348 The actual value ranges from 0.0 to 1.0.
349 Updated automatically once the slice is added to the series.
349 Updated automatically once the slice is added to the series.
350 */
350 */
351
351
352 /*!
352 /*!
353 \fn void QPieSlice::percentageChanged()
353 \fn void QPieSlice::percentageChanged()
354 This signal is emitted when the percentage of the slice has changed.
354 This signal is emitted when the percentage of the slice has changed.
355 \sa percentage
355 \sa percentage
356 */
356 */
357 /*!
357 /*!
358 \qmlsignal void PieSlice::onPercentageChanged()
358 \qmlsignal void PieSlice::onPercentageChanged()
359 This signal is emitted when the percentage of the slice has changed.
359 This signal is emitted when the percentage of the slice has changed.
360 \sa percentage
360 \sa percentage
361 */
361 */
362
362
363 /*!
363 /*!
364 \property QPieSlice::startAngle
364 \property QPieSlice::startAngle
365 Defines the starting angle of this slice in the series it belongs to.
365 Defines the starting angle of this slice in the series it belongs to.
366 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
366 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
367 Updated automatically once the slice is added to the series.
367 Updated automatically once the slice is added to the series.
368 */
368 */
369 /*!
369 /*!
370 \qmlproperty real PieSlice::startAngle
370 \qmlproperty real PieSlice::startAngle
371 Defines the starting angle of this slice in the series it belongs to.
371 Defines the starting angle of this slice in the series it belongs to.
372 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
372 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
373 Updated automatically once the slice is added to the series.
373 Updated automatically once the slice is added to the series.
374 */
374 */
375
375
376 /*!
376 /*!
377 \fn void QPieSlice::startAngleChanged()
377 \fn void QPieSlice::startAngleChanged()
378 This signal is emitted when the starting angle f the slice has changed.
378 This signal is emitted when the starting angle f the slice has changed.
379 \sa startAngle
379 \sa startAngle
380 */
380 */
381 /*!
381 /*!
382 \qmlsignal PieSlice::onStartAngleChanged()
382 \qmlsignal PieSlice::onStartAngleChanged()
383 This signal is emitted when the starting angle f the slice has changed.
383 This signal is emitted when the starting angle f the slice has changed.
384 \sa startAngle
384 \sa startAngle
385 */
385 */
386
386
387 /*!
387 /*!
388 \property QPieSlice::angleSpan
388 \property QPieSlice::angleSpan
389 Span of the slice in degrees.
389 Span of the slice in degrees.
390 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
390 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
391 Updated automatically once the slice is added to the series.
391 Updated automatically once the slice is added to the series.
392 */
392 */
393 /*!
393 /*!
394 \qmlproperty real PieSlice::angleSpan
394 \qmlproperty real PieSlice::angleSpan
395 Span of the slice in degrees.
395 Span of the slice in degrees.
396 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
396 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
397 Updated automatically once the slice is added to the series.
397 Updated automatically once the slice is added to the series.
398 */
398 */
399
399
400 /*!
400 /*!
401 \fn void QPieSlice::angleSpanChanged()
401 \fn void QPieSlice::angleSpanChanged()
402 This signal is emitted when the angle span of the slice has changed.
402 This signal is emitted when the angle span of the slice has changed.
403 \sa angleSpan
403 \sa angleSpan
404 */
404 */
405 /*!
405 /*!
406 \qmlsignal PieSlice::onAngleSpanChanged()
406 \qmlsignal PieSlice::onAngleSpanChanged()
407 This signal is emitted when the angle span of the slice has changed.
407 This signal is emitted when the angle span of the slice has changed.
408 \sa angleSpan
408 \sa angleSpan
409 */
409 */
410
410
411 /*!
411 /*!
412 \fn void QPieSlice::clicked()
412 \fn void QPieSlice::clicked()
413 This signal is emitted when user has clicked the slice.
413 This signal is emitted when user has clicked the slice.
414 \sa QPieSeries::clicked()
414 \sa QPieSeries::clicked()
415 */
415 */
416 /*!
416 /*!
417 \qmlsignal PieSlice::onClicked()
417 \qmlsignal PieSlice::onClicked()
418 This signal is emitted when user has clicked the slice.
418 This signal is emitted when user has clicked the slice.
419 */
419 */
420
420
421 /*!
421 /*!
422 \fn void QPieSlice::hovered(bool state)
422 \fn void QPieSlice::hovered(bool state)
423 This signal is emitted when user has hovered over or away from the slice.
423 This signal is emitted when user has hovered over or away from the slice.
424 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
424 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
425 \sa QPieSeries::hovered()
425 \sa QPieSeries::hovered()
426 */
426 */
427 /*!
427 /*!
428 \qmlsignal PieSlice::onHovered(bool state)
428 \qmlsignal PieSlice::onHovered(bool state)
429 This signal is emitted when user has hovered over or away from the slice.
429 This signal is emitted when user has hovered over or away from the slice.
430 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
430 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
431 */
431 */
432
432
433 /*!
433 /*!
434 Constructs an empty slice with a \a parent.
434 Constructs an empty slice with a \a parent.
435 \sa QPieSeries::append(), QPieSeries::insert()
435 \sa QPieSeries::append(), QPieSeries::insert()
436 */
436 */
437 QPieSlice::QPieSlice(QObject *parent)
437 QPieSlice::QPieSlice(QObject *parent)
438 :QObject(parent),
438 :QObject(parent),
439 d_ptr(new QPieSlicePrivate(this))
439 d_ptr(new QPieSlicePrivate(this))
440 {
440 {
441
441
442 }
442 }
443
443
444 /*!
444 /*!
445 Constructs an empty slice with given \a value, \a label and a \a parent.
445 Constructs an empty slice with given \a value, \a label and a \a parent.
446 \sa QPieSeries::append(), QPieSeries::insert()
446 \sa QPieSeries::append(), QPieSeries::insert()
447 */
447 */
448 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
448 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
449 :QObject(parent),
449 :QObject(parent),
450 d_ptr(new QPieSlicePrivate(this))
450 d_ptr(new QPieSlicePrivate(this))
451 {
451 {
452 setValue(value);
452 setValue(value);
453 setLabel(label);
453 setLabel(label);
454 }
454 }
455
455
456 /*!
456 /*!
457 Destroys the slice.
457 Destroys the slice.
458 User should not delete the slice if it has been added to the series.
458 User should not delete the slice if it has been added to the series.
459 */
459 */
460 QPieSlice::~QPieSlice()
460 QPieSlice::~QPieSlice()
461 {
461 {
462
462
463 }
463 }
464
464
465 void QPieSlice::setLabel(QString label)
465 void QPieSlice::setLabel(QString label)
466 {
466 {
467 if (d_ptr->m_data.m_labelText != label) {
467 if (d_ptr->m_data.m_labelText != label) {
468 d_ptr->m_data.m_labelText = label;
468 d_ptr->m_data.m_labelText = label;
469 emit labelChanged();
469 emit labelChanged();
470 }
470 }
471 }
471 }
472
472
473 QString QPieSlice::label() const
473 QString QPieSlice::label() const
474 {
474 {
475 return d_ptr->m_data.m_labelText;
475 return d_ptr->m_data.m_labelText;
476 }
476 }
477
477
478 void QPieSlice::setValue(qreal value)
478 void QPieSlice::setValue(qreal value)
479 {
479 {
480 value = qAbs(value); // negative values not allowed
480 value = qAbs(value); // negative values not allowed
481 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
481 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
482 d_ptr->m_data.m_value = value;
482 d_ptr->m_data.m_value = value;
483 emit valueChanged();
483 emit valueChanged();
484 }
484 }
485 }
485 }
486
486
487 qreal QPieSlice::value() const
487 qreal QPieSlice::value() const
488 {
488 {
489 return d_ptr->m_data.m_value;
489 return d_ptr->m_data.m_value;
490 }
490 }
491
491
492 void QPieSlice::setLabelVisible(bool visible)
492 void QPieSlice::setLabelVisible(bool visible)
493 {
493 {
494 if (d_ptr->m_data.m_isLabelVisible != visible) {
494 if (d_ptr->m_data.m_isLabelVisible != visible) {
495 d_ptr->m_data.m_isLabelVisible = visible;
495 d_ptr->m_data.m_isLabelVisible = visible;
496 emit labelVisibleChanged();
496 emit labelVisibleChanged();
497 }
497 }
498 }
498 }
499
499
500 bool QPieSlice::isLabelVisible() const
500 bool QPieSlice::isLabelVisible() const
501 {
501 {
502 return d_ptr->m_data.m_isLabelVisible;
502 return d_ptr->m_data.m_isLabelVisible;
503 }
503 }
504
504
505 void QPieSlice::setExploded(bool exploded)
505 void QPieSlice::setExploded(bool exploded)
506 {
506 {
507 if (d_ptr->m_data.m_isExploded != exploded) {
507 if (d_ptr->m_data.m_isExploded != exploded) {
508 d_ptr->m_data.m_isExploded = exploded;
508 d_ptr->m_data.m_isExploded = exploded;
509 emit d_ptr->explodedChanged();
509 emit d_ptr->explodedChanged();
510 }
510 }
511 }
511 }
512
512
513 QPieSlice::LabelPosition QPieSlice::labelPosition()
513 QPieSlice::LabelPosition QPieSlice::labelPosition()
514 {
514 {
515 return d_ptr->m_data.m_labelPosition;
515 return d_ptr->m_data.m_labelPosition;
516 }
516 }
517
517
518 void QPieSlice::setLabelPosition(LabelPosition position)
518 void QPieSlice::setLabelPosition(LabelPosition position)
519 {
519 {
520 if (d_ptr->m_data.m_labelPosition != position) {
520 if (d_ptr->m_data.m_labelPosition != position) {
521 d_ptr->m_data.m_labelPosition = position;
521 d_ptr->m_data.m_labelPosition = position;
522 emit d_ptr->labelPositionChanged();
522 emit d_ptr->labelPositionChanged();
523 }
523 }
524 }
524 }
525
525
526 bool QPieSlice::isExploded() const
526 bool QPieSlice::isExploded() const
527 {
527 {
528 return d_ptr->m_data.m_isExploded;
528 return d_ptr->m_data.m_isExploded;
529 }
529 }
530
530
531 void QPieSlice::setPen(const QPen &pen)
531 void QPieSlice::setPen(const QPen &pen)
532 {
532 {
533 d_ptr->setPen(pen, false);
533 d_ptr->setPen(pen, false);
534 }
534 }
535
535
536 QPen QPieSlice::pen() const
536 QPen QPieSlice::pen() const
537 {
537 {
538 return d_ptr->m_data.m_slicePen;
538 return d_ptr->m_data.m_slicePen;
539 }
539 }
540
540
541 QColor QPieSlice::borderColor()
541 QColor QPieSlice::borderColor()
542 {
542 {
543 return pen().color();
543 return pen().color();
544 }
544 }
545
545
546 void QPieSlice::setBorderColor(QColor color)
546 void QPieSlice::setBorderColor(QColor color)
547 {
547 {
548 QPen p = pen();
548 QPen p = pen();
549 if (color != p.color()) {
549 if (color != p.color()) {
550 p.setColor(color);
550 p.setColor(color);
551 setPen(p);
551 setPen(p);
552 }
552 }
553 }
553 }
554
554
555 int QPieSlice::borderWidth()
555 int QPieSlice::borderWidth()
556 {
556 {
557 return pen().width();
557 return pen().width();
558 }
558 }
559
559
560 void QPieSlice::setBorderWidth(int width)
560 void QPieSlice::setBorderWidth(int width)
561 {
561 {
562 QPen p = pen();
562 QPen p = pen();
563 if (width != p.width()) {
563 if (width != p.width()) {
564 p.setWidth(width);
564 p.setWidth(width);
565 setPen(p);
565 setPen(p);
566 }
566 }
567 }
567 }
568
568
569 void QPieSlice::setBrush(const QBrush &brush)
569 void QPieSlice::setBrush(const QBrush &brush)
570 {
570 {
571 d_ptr->setBrush(brush, false);
571 d_ptr->setBrush(brush, false);
572 }
572 }
573
573
574 QBrush QPieSlice::brush() const
574 QBrush QPieSlice::brush() const
575 {
575 {
576 return d_ptr->m_data.m_sliceBrush;
576 return d_ptr->m_data.m_sliceBrush;
577 }
577 }
578
578
579 QColor QPieSlice::color()
579 QColor QPieSlice::color()
580 {
580 {
581 return brush().color();
581 return brush().color();
582 }
582 }
583
583
584 void QPieSlice::setColor(QColor color)
584 void QPieSlice::setColor(QColor color)
585 {
585 {
586 QBrush b = brush();
586 QBrush b = brush();
587 if (color != b.color()) {
587
588 b.setColor(color);
588 if (b == QBrush())
589 setBrush(b);
589 b.setStyle(Qt::SolidPattern);
590 }
590 b.setColor(color);
591 setBrush(b);
591 }
592 }
592
593
593 void QPieSlice::setLabelBrush(const QBrush &brush)
594 void QPieSlice::setLabelBrush(const QBrush &brush)
594 {
595 {
595 d_ptr->setLabelBrush(brush, false);
596 d_ptr->setLabelBrush(brush, false);
596 }
597 }
597
598
598 QBrush QPieSlice::labelBrush() const
599 QBrush QPieSlice::labelBrush() const
599 {
600 {
600 return d_ptr->m_data.m_labelBrush;
601 return d_ptr->m_data.m_labelBrush;
601 }
602 }
602
603
603 QColor QPieSlice::labelColor()
604 QColor QPieSlice::labelColor()
604 {
605 {
605 return labelBrush().color();
606 return labelBrush().color();
606 }
607 }
607
608
608 void QPieSlice::setLabelColor(QColor color)
609 void QPieSlice::setLabelColor(QColor color)
609 {
610 {
610 QBrush b = labelBrush();
611 QBrush b = labelBrush();
611 if (color != b.color()) {
612 if (color != b.color()) {
612 b.setColor(color);
613 b.setColor(color);
613 setLabelBrush(b);
614 setLabelBrush(b);
614 }
615 }
615 }
616 }
616
617
617 void QPieSlice::setLabelFont(const QFont &font)
618 void QPieSlice::setLabelFont(const QFont &font)
618 {
619 {
619 d_ptr->setLabelFont(font, false);
620 d_ptr->setLabelFont(font, false);
620 }
621 }
621
622
622 QFont QPieSlice::labelFont() const
623 QFont QPieSlice::labelFont() const
623 {
624 {
624 return d_ptr->m_data.m_labelFont;
625 return d_ptr->m_data.m_labelFont;
625 }
626 }
626
627
627 void QPieSlice::setLabelArmLengthFactor(qreal factor)
628 void QPieSlice::setLabelArmLengthFactor(qreal factor)
628 {
629 {
629 if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) {
630 if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) {
630 d_ptr->m_data.m_labelArmLengthFactor = factor;
631 d_ptr->m_data.m_labelArmLengthFactor = factor;
631 emit d_ptr->labelArmLengthFactorChanged();
632 emit d_ptr->labelArmLengthFactorChanged();
632 }
633 }
633 }
634 }
634
635
635 qreal QPieSlice::labelArmLengthFactor() const
636 qreal QPieSlice::labelArmLengthFactor() const
636 {
637 {
637 return d_ptr->m_data.m_labelArmLengthFactor;
638 return d_ptr->m_data.m_labelArmLengthFactor;
638 }
639 }
639
640
640 void QPieSlice::setExplodeDistanceFactor(qreal factor)
641 void QPieSlice::setExplodeDistanceFactor(qreal factor)
641 {
642 {
642 if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) {
643 if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) {
643 d_ptr->m_data.m_explodeDistanceFactor = factor;
644 d_ptr->m_data.m_explodeDistanceFactor = factor;
644 emit d_ptr->explodeDistanceFactorChanged();
645 emit d_ptr->explodeDistanceFactorChanged();
645 }
646 }
646 }
647 }
647
648
648 qreal QPieSlice::explodeDistanceFactor() const
649 qreal QPieSlice::explodeDistanceFactor() const
649 {
650 {
650 return d_ptr->m_data.m_explodeDistanceFactor;
651 return d_ptr->m_data.m_explodeDistanceFactor;
651 }
652 }
652
653
653 qreal QPieSlice::percentage() const
654 qreal QPieSlice::percentage() const
654 {
655 {
655 return d_ptr->m_data.m_percentage;
656 return d_ptr->m_data.m_percentage;
656 }
657 }
657
658
658 qreal QPieSlice::startAngle() const
659 qreal QPieSlice::startAngle() const
659 {
660 {
660 return d_ptr->m_data.m_startAngle;
661 return d_ptr->m_data.m_startAngle;
661 }
662 }
662
663
663 qreal QPieSlice::angleSpan() const
664 qreal QPieSlice::angleSpan() const
664 {
665 {
665 return d_ptr->m_data.m_angleSpan;
666 return d_ptr->m_data.m_angleSpan;
666 }
667 }
667
668
668 /*!
669 /*!
669 Returns the series that this slice belongs to.
670 Returns the series that this slice belongs to.
670
671
671 \sa QPieSeries::append()
672 \sa QPieSeries::append()
672 */
673 */
673 QPieSeries *QPieSlice::series() const
674 QPieSeries *QPieSlice::series() const
674 {
675 {
675 return d_ptr->m_series;
676 return d_ptr->m_series;
676 }
677 }
677
678
678 QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent)
679 QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent)
679 :QObject(parent),
680 :QObject(parent),
680 q_ptr(parent),
681 q_ptr(parent),
681 m_series(0)
682 m_series(0)
682 {
683 {
683
684
684 }
685 }
685
686
686 QPieSlicePrivate::~QPieSlicePrivate()
687 QPieSlicePrivate::~QPieSlicePrivate()
687 {
688 {
688
689
689 }
690 }
690
691
691 QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice)
692 QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice)
692 {
693 {
693 return slice->d_func();
694 return slice->d_func();
694 }
695 }
695
696
696 void QPieSlicePrivate::setPen(const QPen &pen, bool themed)
697 void QPieSlicePrivate::setPen(const QPen &pen, bool themed)
697 {
698 {
698 if (m_data.m_slicePen != pen) {
699 if (m_data.m_slicePen != pen) {
699
700
700 QPen oldPen = m_data.m_slicePen;
701 QPen oldPen = m_data.m_slicePen;
701
702
702 m_data.m_slicePen = pen;
703 m_data.m_slicePen = pen;
703 m_data.m_slicePen.setThemed(themed);
704 m_data.m_slicePen.setThemed(themed);
704
705
705 emit q_ptr->penChanged();
706 emit q_ptr->penChanged();
706 if (oldPen.color() != pen.color())
707 if (oldPen.color() != pen.color())
707 emit q_ptr->borderColorChanged();
708 emit q_ptr->borderColorChanged();
708 if (oldPen.width() != pen.width())
709 if (oldPen.width() != pen.width())
709 emit q_ptr->borderWidthChanged();
710 emit q_ptr->borderWidthChanged();
710 }
711 }
711 }
712 }
712
713
713 void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed)
714 void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed)
714 {
715 {
715 if (m_data.m_sliceBrush != brush) {
716 if (m_data.m_sliceBrush != brush) {
716
717
717 QBrush oldBrush = m_data.m_sliceBrush;
718 QBrush oldBrush = m_data.m_sliceBrush;
718
719
719 m_data.m_sliceBrush = brush;
720 m_data.m_sliceBrush = brush;
720 m_data.m_sliceBrush.setThemed(themed);
721 m_data.m_sliceBrush.setThemed(themed);
721
722
722 emit q_ptr->brushChanged();
723 emit q_ptr->brushChanged();
723 if (oldBrush.color() != brush.color())
724 if (oldBrush.color() != brush.color())
724 emit q_ptr->colorChanged();
725 emit q_ptr->colorChanged();
725 }
726 }
726 }
727 }
727
728
728 void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed)
729 void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed)
729 {
730 {
730 if (m_data.m_labelBrush != brush) {
731 if (m_data.m_labelBrush != brush) {
731
732
732 QBrush oldBrush = m_data.m_labelBrush;
733 QBrush oldBrush = m_data.m_labelBrush;
733
734
734 m_data.m_labelBrush = brush;
735 m_data.m_labelBrush = brush;
735 m_data.m_labelBrush.setThemed(themed);
736 m_data.m_labelBrush.setThemed(themed);
736
737
737 emit q_ptr->labelBrushChanged();
738 emit q_ptr->labelBrushChanged();
738 if (oldBrush.color() != brush.color())
739 if (oldBrush.color() != brush.color())
739 emit q_ptr->labelColorChanged();
740 emit q_ptr->labelColorChanged();
740 }
741 }
741 }
742 }
742
743
743 void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed)
744 void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed)
744 {
745 {
745 if (m_data.m_labelFont != font) {
746 if (m_data.m_labelFont != font) {
746 m_data.m_labelFont = font;
747 m_data.m_labelFont = font;
747 m_data.m_labelFont.setThemed(themed);
748 m_data.m_labelFont.setThemed(themed);
748 emit q_ptr->labelFontChanged();
749 emit q_ptr->labelFontChanged();
749 }
750 }
750 }
751 }
751
752
752 void QPieSlicePrivate::setPercentage(qreal percentage)
753 void QPieSlicePrivate::setPercentage(qreal percentage)
753 {
754 {
754 if (!qFuzzyIsNull(m_data.m_percentage - percentage)) {
755 if (!qFuzzyIsNull(m_data.m_percentage - percentage)) {
755 m_data.m_percentage = percentage;
756 m_data.m_percentage = percentage;
756 emit q_ptr->percentageChanged();
757 emit q_ptr->percentageChanged();
757 }
758 }
758 }
759 }
759
760
760 void QPieSlicePrivate::setStartAngle(qreal angle)
761 void QPieSlicePrivate::setStartAngle(qreal angle)
761 {
762 {
762 if (!qFuzzyIsNull(m_data.m_startAngle - angle)) {
763 if (!qFuzzyIsNull(m_data.m_startAngle - angle)) {
763 m_data.m_startAngle = angle;
764 m_data.m_startAngle = angle;
764 emit q_ptr->startAngleChanged();
765 emit q_ptr->startAngleChanged();
765 }
766 }
766 }
767 }
767
768
768 void QPieSlicePrivate::setAngleSpan(qreal span)
769 void QPieSlicePrivate::setAngleSpan(qreal span)
769 {
770 {
770 if (!qFuzzyIsNull(m_data.m_angleSpan - span)) {
771 if (!qFuzzyIsNull(m_data.m_angleSpan - span)) {
771 m_data.m_angleSpan = span;
772 m_data.m_angleSpan = span;
772 emit q_ptr->angleSpanChanged();
773 emit q_ptr->angleSpanChanged();
773 }
774 }
774 }
775 }
775
776
776 QTCOMMERCIALCHART_END_NAMESPACE
777 QTCOMMERCIALCHART_END_NAMESPACE
777
778
778 QTCOMMERCIALCHART_USE_NAMESPACE
779 QTCOMMERCIALCHART_USE_NAMESPACE
779 #include "moc_qpieslice.cpp"
780 #include "moc_qpieslice.cpp"
780 #include "moc_qpieslice_p.cpp"
781 #include "moc_qpieslice_p.cpp"
General Comments 0
You need to be logged in to leave comments. Login now