@@ -1,401 +1,402 | |||
|
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 "pieslicedata_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 | Holds all the data of a single slice in a QPieSeries and provides the means |
|
31 | 31 | to modify slice data and customize the visual appearance of the slice. |
|
32 | 32 | |
|
33 | 33 | It also provides the means to customize user interaction with the slice by |
|
34 | 34 | providing signals for clicking and hover events. |
|
35 | 35 | */ |
|
36 | 36 | |
|
37 | 37 | /*! |
|
38 | 38 | \property QPieSlice::label |
|
39 | 39 | |
|
40 | 40 | Label of the slice. |
|
41 | 41 | */ |
|
42 | 42 | |
|
43 | 43 | /*! |
|
44 | 44 | \property QPieSlice::value |
|
45 | 45 | |
|
46 | 46 | Value of the slice. |
|
47 | 47 | */ |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | Constructs an empty slice with a \a parent. |
|
51 | 51 | |
|
52 | 52 | Note that QPieSeries takes ownership of the slice when it is set/added. |
|
53 | 53 | |
|
54 | 54 | \sa QPieSeries::replace(), QPieSeries::append() |
|
55 | 55 | */ |
|
56 | 56 | QPieSlice::QPieSlice(QObject *parent) |
|
57 | 57 | :QObject(parent), |
|
58 | 58 | d(new PieSliceData()) |
|
59 | 59 | { |
|
60 | 60 | |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | Constructs an empty slice with given \a value, \a label and a \a parent. |
|
65 | 65 | Note that QPieSeries takes ownership of the slice when it is set/added. |
|
66 | 66 | \sa QPieSeries::replace(), QPieSeries::append() |
|
67 | 67 | */ |
|
68 | 68 | QPieSlice::QPieSlice(qreal value, QString label, QObject *parent) |
|
69 | 69 | :QObject(parent), |
|
70 | 70 | d(new PieSliceData()) |
|
71 | 71 | { |
|
72 | 72 | d->m_value = value; |
|
73 | 73 | d->m_labelText = label; |
|
74 | 74 | } |
|
75 | 75 | |
|
76 | 76 | /*! |
|
77 | 77 | Destroys the slice. |
|
78 | 78 | User should not delete the slice if it has been added to the series. |
|
79 | 79 | */ |
|
80 | 80 | QPieSlice::~QPieSlice() |
|
81 | 81 | { |
|
82 | 82 | delete d; |
|
83 | 83 | } |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | Gets the value of the slice. |
|
87 | 87 | Note that all values in the series |
|
88 | 88 | \sa setValue() |
|
89 | 89 | */ |
|
90 | 90 | qreal QPieSlice::value() const |
|
91 | 91 | { |
|
92 | 92 | return d->m_value; |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | 95 | /*! |
|
96 | 96 | Gets the label of the slice. |
|
97 | 97 | \sa setLabel() |
|
98 | 98 | */ |
|
99 | 99 | QString QPieSlice::label() const |
|
100 | 100 | { |
|
101 | 101 | return d->m_labelText; |
|
102 | 102 | } |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | Returns true if label is set as visible. |
|
106 | 106 | \sa setLabelVisible() |
|
107 | 107 | */ |
|
108 | 108 | bool QPieSlice::isLabelVisible() const |
|
109 | 109 | { |
|
110 | 110 | return d->m_isLabelVisible; |
|
111 | 111 | } |
|
112 | 112 | |
|
113 | 113 | /*! |
|
114 | 114 | Returns true if slice is exloded from the pie. |
|
115 | 115 | \sa setExploded(), setExplodeDistanceFactor() |
|
116 | 116 | */ |
|
117 | 117 | bool QPieSlice::isExploded() const |
|
118 | 118 | { |
|
119 | 119 | return d->m_isExploded; |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | Returns the explode distance factor. |
|
124 | 124 | |
|
125 | 125 | The factor is relative to pie radius. For example: |
|
126 | 126 | 1.0 means the distance is the same as the radius. |
|
127 | 127 | 0.5 means the distance is half of the radius. |
|
128 | 128 | |
|
129 | 129 | Default value is 0.15. |
|
130 | 130 | |
|
131 | 131 | \sa setExplodeDistanceFactor() |
|
132 | 132 | */ |
|
133 | 133 | qreal QPieSlice::explodeDistanceFactor() const |
|
134 | 134 | { |
|
135 | 135 | return d->m_explodeDistanceFactor; |
|
136 | 136 | } |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | Returns the percentage of this slice compared to all slices in the same series. |
|
140 | 140 | The returned value ranges from 0 to 1.0. |
|
141 | 141 | |
|
142 | 142 | Updated internally after the slice is added to the series. |
|
143 | 143 | */ |
|
144 | 144 | qreal QPieSlice::percentage() const |
|
145 | 145 | { |
|
146 | 146 | return d->m_percentage; |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | Returns the starting angle of this slice in the series it belongs to. |
|
151 | 151 | |
|
152 | 152 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
153 | 153 | |
|
154 | 154 | Updated internally after the slice is added to the series. |
|
155 | 155 | */ |
|
156 | 156 | qreal QPieSlice::startAngle() const |
|
157 | 157 | { |
|
158 | 158 | return d->m_startAngle; |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | Returns the end angle of this slice in the series it belongs to. |
|
163 | 163 | |
|
164 | 164 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
165 | 165 | |
|
166 | 166 | Updated internally after the slice is added to the series. |
|
167 | 167 | */ |
|
168 | 168 | qreal QPieSlice::endAngle() const |
|
169 | 169 | { |
|
170 | 170 | return d->m_startAngle + d->m_angleSpan; |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | /*! |
|
174 | 174 | Returns the pen used to draw this slice. |
|
175 | 175 | \sa setPen() |
|
176 | 176 | */ |
|
177 | 177 | QPen QPieSlice::pen() const |
|
178 | 178 | { |
|
179 | 179 | return d->m_slicePen; |
|
180 | 180 | } |
|
181 | 181 | |
|
182 | 182 | /*! |
|
183 | 183 | Returns the brush used to draw this slice. |
|
184 | 184 | \sa setBrush() |
|
185 | 185 | */ |
|
186 | 186 | QBrush QPieSlice::brush() const |
|
187 | 187 | { |
|
188 | 188 | return d->m_sliceBrush; |
|
189 | 189 | } |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | Returns the pen used to draw the label in this slice. |
|
193 | 193 | \sa setLabelPen() |
|
194 | 194 | */ |
|
195 | 195 | QPen QPieSlice::labelPen() const |
|
196 | 196 | { |
|
197 | 197 | return d->m_labelPen; |
|
198 | 198 | } |
|
199 | 199 | |
|
200 | 200 | /*! |
|
201 | 201 | Returns the font used to draw label in this slice. |
|
202 | 202 | \sa setLabelFont() |
|
203 | 203 | */ |
|
204 | 204 | QFont QPieSlice::labelFont() const |
|
205 | 205 | { |
|
206 | 206 | return d->m_labelFont; |
|
207 | 207 | } |
|
208 | 208 | |
|
209 | 209 | /*! |
|
210 | 210 | Gets the label arm length factor. |
|
211 | 211 | |
|
212 | 212 | The factor is relative to pie radius. For example: |
|
213 | 213 | 1.0 means the length is the same as the radius. |
|
214 | 214 | 0.5 means the length is half of the radius. |
|
215 | 215 | |
|
216 | 216 | Default value is 0.15 |
|
217 | 217 | |
|
218 | 218 | \sa setLabelArmLengthFactor() |
|
219 | 219 | */ |
|
220 | 220 | qreal QPieSlice::labelArmLengthFactor() const |
|
221 | 221 | { |
|
222 | 222 | return d->m_labelArmLengthFactor; |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | /*! |
|
226 | 226 | \fn void QPieSlice::clicked(Qt::MouseButtons buttons) |
|
227 | 227 | |
|
228 | 228 | This signal is emitted when user has clicked the slice. |
|
229 | 229 | |
|
230 | 230 | \sa QPieSeries::clicked() |
|
231 | 231 | */ |
|
232 | 232 | |
|
233 | 233 | /*! |
|
234 | 234 | \fn void QPieSlice::hoverEnter() |
|
235 | 235 | |
|
236 | 236 | This signal is emitted when user has hovered over the slice. |
|
237 | 237 | |
|
238 | 238 | \sa QPieSeries::hoverEnter() |
|
239 | 239 | */ |
|
240 | 240 | |
|
241 | 241 | /*! |
|
242 | 242 | \fn void QPieSlice::hoverLeave() |
|
243 | 243 | |
|
244 | 244 | This signal is emitted when user has hovered away from the slice. |
|
245 | 245 | |
|
246 | 246 | \sa QPieSeries::hoverLeave() |
|
247 | 247 | */ |
|
248 | 248 | |
|
249 | 249 | /*! |
|
250 | 250 | \fn void QPieSlice::changed() |
|
251 | 251 | |
|
252 | 252 | This signal emitted when something has changed in the slice. |
|
253 | 253 | |
|
254 | 254 | \sa QPieSeries::changed() |
|
255 | 255 | */ |
|
256 | 256 | |
|
257 | 257 | /*! |
|
258 | 258 | Sets the \a value of this slice. |
|
259 | 259 | \sa value() |
|
260 | 260 | */ |
|
261 | 261 | void QPieSlice::setValue(qreal value) |
|
262 | 262 | { |
|
263 | 263 | if (!qFuzzyIsNull(d->m_value - value)) { |
|
264 | 264 | d->m_value = value; |
|
265 | 265 | emit changed(); |
|
266 | 266 | } |
|
267 | 267 | } |
|
268 | 268 | |
|
269 | 269 | /*! |
|
270 | 270 | Sets the \a label of the slice. |
|
271 | 271 | \sa label() |
|
272 | 272 | */ |
|
273 | 273 | void QPieSlice::setLabel(QString label) |
|
274 | 274 | { |
|
275 | 275 | if (d->m_labelText != label) { |
|
276 | 276 | d->m_labelText = label; |
|
277 | 277 | emit changed(); |
|
278 | 278 | } |
|
279 | 279 | } |
|
280 | 280 | |
|
281 | 281 | /*! |
|
282 | 282 | Sets the label \a visible in this slice. |
|
283 | 283 | \sa isLabelVisible(), QPieSeries::setLabelsVisible() |
|
284 | 284 | */ |
|
285 | 285 | void QPieSlice::setLabelVisible(bool visible) |
|
286 | 286 | { |
|
287 | 287 | if (d->m_isLabelVisible != visible) { |
|
288 | 288 | d->m_isLabelVisible = visible; |
|
289 | 289 | emit changed(); |
|
290 | 290 | } |
|
291 | 291 | } |
|
292 | 292 | |
|
293 | 293 | /*! |
|
294 | 294 | Sets this slice \a exploded. |
|
295 | 295 | \sa isExploded(), explodeDistanceFactor() |
|
296 | 296 | */ |
|
297 | 297 | void QPieSlice::setExploded(bool exploded) |
|
298 | 298 | { |
|
299 | 299 | if (d->m_isExploded != exploded) { |
|
300 | 300 | d->m_isExploded = exploded; |
|
301 | 301 | emit changed(); |
|
302 | 302 | } |
|
303 | 303 | } |
|
304 | 304 | |
|
305 | 305 | /*! |
|
306 | 306 | Sets the explode distance \a factor. |
|
307 | 307 | |
|
308 | 308 | The factor is relative to pie radius. For example: |
|
309 | 309 | 1.0 means the distance is the same as the radius. |
|
310 | 310 | 0.5 means the distance is half of the radius. |
|
311 | 311 | |
|
312 | 312 | Default value is 0.15 |
|
313 | 313 | |
|
314 | 314 | \sa explodeDistanceFactor() |
|
315 | 315 | */ |
|
316 | 316 | void QPieSlice::setExplodeDistanceFactor(qreal factor) |
|
317 | 317 | { |
|
318 | 318 | if (!qFuzzyIsNull(d->m_explodeDistanceFactor - factor)) { |
|
319 | 319 | d->m_explodeDistanceFactor = factor; |
|
320 | 320 | emit changed(); |
|
321 | 321 | } |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | 324 | /*! |
|
325 | 325 | Sets the \a pen used to draw this slice. |
|
326 | 326 | Note that applying a theme will override this. |
|
327 | 327 | \sa pen() |
|
328 | 328 | */ |
|
329 | 329 | void QPieSlice::setPen(const QPen &pen) |
|
330 | 330 | { |
|
331 | 331 | if (d->m_slicePen != pen) { |
|
332 | 332 | d->m_slicePen = pen; |
|
333 | 333 | d->m_slicePen.setThemed(false); |
|
334 | 334 | emit changed(); |
|
335 | 335 | } |
|
336 | 336 | } |
|
337 | 337 | |
|
338 | 338 | /*! |
|
339 | 339 | Sets the \a brush used to draw this slice. |
|
340 | 340 | Note that applying a theme will override this. |
|
341 | 341 | \sa brush() |
|
342 | 342 | */ |
|
343 | 343 | void QPieSlice::setBrush(const QBrush &brush) |
|
344 | 344 | { |
|
345 | 345 | if (d->m_sliceBrush != brush) { |
|
346 | 346 | d->m_sliceBrush = brush; |
|
347 | 347 | d->m_sliceBrush.setThemed(false); |
|
348 | 348 | emit changed(); |
|
349 | 349 | } |
|
350 | 350 | } |
|
351 | 351 | |
|
352 | 352 | /*! |
|
353 | 353 | Sets the \a pen used to draw the label in this slice. |
|
354 | 354 | Note that applying a theme will override this. |
|
355 | 355 | \sa labelPen() |
|
356 | 356 | */ |
|
357 | 357 | void QPieSlice::setLabelPen(const QPen &pen) |
|
358 | 358 | { |
|
359 | 359 | if (d->m_labelPen != pen) { |
|
360 | 360 | d->m_labelPen = pen; |
|
361 | 361 | d->m_labelPen.setThemed(false); |
|
362 | 362 | emit changed(); |
|
363 | 363 | } |
|
364 | 364 | } |
|
365 | 365 | |
|
366 | 366 | /*! |
|
367 | 367 | Sets the \a font used to draw the label in this slice. |
|
368 | 368 | Note that applying a theme will override this. |
|
369 | 369 | \sa labelFont() |
|
370 | 370 | */ |
|
371 | 371 | void QPieSlice::setLabelFont(const QFont &font) |
|
372 | 372 | { |
|
373 | 373 | if (d->m_labelFont != font) { |
|
374 | 374 | d->m_labelFont = font; |
|
375 | 375 | d->m_labelFont.setThemed(false); |
|
376 | 376 | emit changed(); |
|
377 | 377 | } |
|
378 | 378 | } |
|
379 | 379 | |
|
380 | 380 | /*! |
|
381 | 381 | Sets the label arm length \a factor. |
|
382 | 382 | |
|
383 | 383 | The factor is relative to pie radius. For example: |
|
384 | 384 | 1.0 means the length is the same as the radius. |
|
385 | 385 | 0.5 means the length is half of the radius. |
|
386 | 386 | |
|
387 | 387 | Default value is 0.15 |
|
388 | 388 | |
|
389 | 389 | \sa labelArmLengthFactor() |
|
390 | 390 | */ |
|
391 | 391 | void QPieSlice::setLabelArmLengthFactor(qreal factor) |
|
392 | 392 | { |
|
393 | 393 | if (!qFuzzyIsNull(d->m_labelArmLengthFactor - factor)) { |
|
394 | 394 | d->m_labelArmLengthFactor = factor; |
|
395 | 395 | emit changed(); |
|
396 | 396 | } |
|
397 | 397 | } |
|
398 | 398 | |
|
399 | #include "moc_qpieslice.cpp" | |
|
400 | ||
|
401 | 399 | QTCOMMERCIALCHART_END_NAMESPACE |
|
400 | ||
|
401 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
402 | #include "moc_qpieslice.cpp" |
General Comments 0
You need to be logged in to leave comments.
Login now