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