##// END OF EJS Templates
Added simple donut chart example docs
Marek Rosa -
r1842:8212e3091e6d
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,8
1 /*!
2 \example examples/donutchart
3 \title Donutchart Example
4 \subtitle
5
6 The example shows how to create simple donut chart and do some customizations to a slice.
7 \image examples_donut.png
8 */
@@ -1,44 +1,45
1 1 /*!
2 2 \page examples.html
3 3 \title Examples
4 4 \keyword Examples
5 5
6 6 \raw HTML
7 7 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
8 8 <tr>
9 9 <th class="titleheader" width="33%">
10 10 List of examples
11 11 </th>
12 12 </tr>
13 13 <tr>
14 14 <td valign="top">
15 15 <ul>
16 16 <li><a href="examples-areachart.html">Area chart</a></li>
17 17 <li><a href="examples-barchart.html">Bar chart</a></li>
18 18 <li><a href="examples-customchart.html">Custom chart</a></li>
19 19 <li><a href="examples-horizontalbarchart.html">Horizontal bar chart</a></li>
20 20 <li><a href="examples-horizontalstackedbarchart.html">Horizontal stacked bar chart</a></li>
21 21 <li><a href="examples-horizontalpercentbarchart.html">Horizontal percent bar chart</a></li>
22 22 <li><a href="examples-legend.html">Legend</a></li>
23 23 <li><a href="examples-linechart.html">Line chart</a></li>
24 24 <li><a href="examples-lineandbar.html">Line and barchart</a></li>
25 25 <li><a href="examples-modeldata.html">Model data</a></li>
26 26 <li><a href="examples-barmodelmapper.html">Bar chart from model</a></li>
27 27 <li><a href="examples-percentbarchart.html">Percent bar chart</a></li>
28 28 <li><a href="examples-piechart.html">Pie chart</a></li>
29 <li><a href="examples-donutchart.html">Donut chart</a></li>
29 30 <li><a href="examples-piechartdrilldown.html">Pie chart drilldown</a></li>
30 <li><a href="examples-donut.html">Donut chart</a></li>
31 <li><a href="examples-donut.html">Nested donuts chart</a></li>
31 32 <li><a href="examples-donutbreakdown.html">Donut chart drilldown</a></li>
32 33 <li><a href="examples-presenterchart.html">Presenter chart</a></li>
33 34 <li><a href="examples-scatterchart.html">Scatter chart</a></li>
34 35 <li><a href="examples-scatterinteractions.html">Scatter interactions</a></li>
35 36 <li><a href="examples-splinechart.html">Spline chart</a></li>
36 37 <li><a href="examples-stackedbarchart.html">Stacked bar chart</a></li>
37 38 <li><a href="examples-stackedbarchartdrilldown.html">Stacked bar chart drilldown</a></li>
38 39 <li><a href="examples-zoomlinechart.html">Zoom line</a></li>
39 40 </ul>
40 41 </td>
41 42 </tr>
42 43 </table>
43 44 \endraw
44 45 */
@@ -1,70 +1,71
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 <QApplication>
22 22 #include <QMainWindow>
23 23 #include <QChartView>
24 24 #include <QPieSeries>
25 25 #include <QPieSlice>
26 26
27 27 QTCOMMERCIALCHART_USE_NAMESPACE
28 28
29 29 int main(int argc, char *argv[])
30 30 {
31 31 QApplication a(argc, argv);
32 32
33 33 //![1]
34 34 QPieSeries *series = new QPieSeries();
35 35 series->setHoleSize(0.35);
36 36 series->append("Jane", 1);
37 37 series->append("Joe", 2);
38 38 series->append("Andy", 3);
39 39 series->append("Barbara", 4);
40 40 series->append("Axel", 5);
41 41 //![1]
42 42
43 43 //![2]
44 44 QPieSlice *slice = series->slices().at(1);
45 45 slice->setExploded();
46 46 slice->setLabelVisible();
47 47 slice->setPen(QPen(Qt::darkGreen, 2));
48 48 slice->setBrush(Qt::green);
49 49 //![2]
50 50
51 51 //![3]
52 52 QChart* chart = new QChart();
53 53 chart->addSeries(series);
54 54 chart->setTitle("Simple donutchart example");
55 chart->legend()->hide();
55 56 //![3]
56 57
57 58 //![4]
58 59 QChartView* chartView = new QChartView(chart);
59 60 chartView->setRenderHint(QPainter::Antialiasing);
60 61 //![4]
61 62
62 63 //![5]
63 64 QMainWindow window;
64 65 window.setCentralWidget(chartView);
65 66 window.resize(400, 300);
66 67 window.show();
67 68 //![5]
68 69
69 70 return a.exec();
70 71 }
@@ -1,69 +1,70
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 <QApplication>
22 22 #include <QMainWindow>
23 23 #include <QChartView>
24 24 #include <QPieSeries>
25 25 #include <QPieSlice>
26 26
27 27 QTCOMMERCIALCHART_USE_NAMESPACE
28 28
29 29 int main(int argc, char *argv[])
30 30 {
31 31 QApplication a(argc, argv);
32 32
33 33 //![1]
34 34 QPieSeries *series = new QPieSeries();
35 35 series->append("Jane", 1);
36 36 series->append("Joe", 2);
37 37 series->append("Andy", 3);
38 38 series->append("Barbara", 4);
39 39 series->append("Axel", 5);
40 40 //![1]
41 41
42 42 //![2]
43 43 QPieSlice *slice = series->slices().at(1);
44 44 slice->setExploded();
45 45 slice->setLabelVisible();
46 46 slice->setPen(QPen(Qt::darkGreen, 2));
47 47 slice->setBrush(Qt::green);
48 48 //![2]
49 49
50 50 //![3]
51 51 QChart* chart = new QChart();
52 52 chart->addSeries(series);
53 53 chart->setTitle("Simple piechart example");
54 chart->legend()->hide();
54 55 //![3]
55 56
56 57 //![4]
57 58 QChartView* chartView = new QChartView(chart);
58 59 chartView->setRenderHint(QPainter::Antialiasing);
59 60 //![4]
60 61
61 62 //![5]
62 63 QMainWindow window;
63 64 window.setCentralWidget(chartView);
64 65 window.resize(400, 300);
65 66 window.show();
66 67 //![5]
67 68
68 69 return a.exec();
69 70 }
@@ -1,871 +1,875
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 "qpieseries.h"
22 22 #include "qpieseries_p.h"
23 23 #include "qpieslice.h"
24 24 #include "qpieslice_p.h"
25 25 #include "pieslicedata_p.h"
26 26 #include "chartdataset_p.h"
27 27 #include "charttheme_p.h"
28 28 #include "legendmarker_p.h"
29 29 #include "qabstractaxis.h"
30 30 #include "pieanimation_p.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 /*!
35 35 \class QPieSeries
36 36 \brief Pie series API for QtCommercial Charts
37 37
38 38 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
39 39 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
40 40 The actual slice size is determined by that relative value.
41 41
42 42 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
43 43 These relate to the actual chart rectangle.
44 44
45 45 By default the pie is defined as a full pie but it can also be a partial pie.
46 46 This can be done by setting a starting angle and angle span to the series.
47 47 Full pie is 360 degrees where 0 is at 12 a'clock.
48 48
49 See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
50 \image examples_piechart.png
49 See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries.
50 \table 100%
51 \row
52 \o \image examples_piechart.png
53 \o \image examples_donut.png
54 \endtable
51 55 */
52 56 /*!
53 57 \qmlclass PieSeries QPieSeries
54 58 \inherits AbstractSeries
55 59
56 60 The following QML shows how to create a simple pie chart.
57 61
58 62 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
59 63
60 64 \beginfloatleft
61 65 \image demos_qmlchart1.png
62 66 \endfloat
63 67 \clearfloat
64 68 */
65 69
66 70 /*!
67 71 \property QPieSeries::horizontalPosition
68 72 \brief Defines the horizontal position of the pie.
69 73
70 74 The value is a relative value to the chart rectangle where:
71 75
72 76 \list
73 77 \o 0.0 is the absolute left.
74 78 \o 1.0 is the absolute right.
75 79 \endlist
76 80 Default value is 0.5 (center).
77 81 \sa verticalPosition
78 82 */
79 83
80 84 /*!
81 85 \qmlproperty real PieSeries::horizontalPosition
82 86
83 87 Defines the horizontal position of the pie.
84 88
85 89 The value is a relative value to the chart rectangle where:
86 90
87 91 \list
88 92 \o 0.0 is the absolute left.
89 93 \o 1.0 is the absolute right.
90 94 \endlist
91 95 Default value is 0.5 (center).
92 96 \sa verticalPosition
93 97 */
94 98
95 99 /*!
96 100 \property QPieSeries::verticalPosition
97 101 \brief Defines the vertical position of the pie.
98 102
99 103 The value is a relative value to the chart rectangle where:
100 104
101 105 \list
102 106 \o 0.0 is the absolute top.
103 107 \o 1.0 is the absolute bottom.
104 108 \endlist
105 109 Default value is 0.5 (center).
106 110 \sa horizontalPosition
107 111 */
108 112
109 113 /*!
110 114 \qmlproperty real PieSeries::verticalPosition
111 115
112 116 Defines the vertical position of the pie.
113 117
114 118 The value is a relative value to the chart rectangle where:
115 119
116 120 \list
117 121 \o 0.0 is the absolute top.
118 122 \o 1.0 is the absolute bottom.
119 123 \endlist
120 124 Default value is 0.5 (center).
121 125 \sa horizontalPosition
122 126 */
123 127
124 128 /*!
125 129 \property QPieSeries::size
126 130 \brief Defines the pie size.
127 131
128 132 The value is a relative value to the chart rectangle where:
129 133
130 134 \list
131 135 \o 0.0 is the minimum size (pie not drawn).
132 136 \o 1.0 is the maximum size that can fit the chart.
133 137 \endlist
134 138
135 139 When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size.
136 140
137 141 Default value is 0.7.
138 142 */
139 143
140 144 /*!
141 145 \qmlproperty real PieSeries::size
142 146
143 147 Defines the pie size.
144 148
145 149 The value is a relative value to the chart rectangle where:
146 150
147 151 \list
148 152 \o 0.0 is the minimum size (pie not drawn).
149 153 \o 1.0 is the maximum size that can fit the chart.
150 154 \endlist
151 155
152 156 Default value is 0.7.
153 157 */
154 158
155 159 /*!
156 160 \property QPieSeries::holeSize
157 161 \brief Defines the donut hole size.
158 162
159 163 The value is a relative value to the chart rectangle where:
160 164
161 165 \list
162 166 \o 0.0 is the minimum size (full pie drawn, without any hole inside).
163 167 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
164 168 \endlist
165 169
166 170 The value is never greater then size property.
167 171 Default value is 0.0.
168 172 */
169 173
170 174 /*!
171 175 \qmlproperty real PieSeries::holeSize
172 176
173 177 Defines the donut hole size.
174 178
175 179 The value is a relative value to the chart rectangle where:
176 180
177 181 \list
178 182 \o 0.0 is the minimum size (full pie drawn, without any hole inside).
179 183 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
180 184 \endlist
181 185
182 186 When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size.
183 187
184 188 Default value is 0.0.
185 189 */
186 190
187 191 /*!
188 192 \property QPieSeries::startAngle
189 193 \brief Defines the starting angle of the pie.
190 194
191 195 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
192 196
193 197 Default is value is 0.
194 198 */
195 199
196 200 /*!
197 201 \qmlproperty real PieSeries::startAngle
198 202
199 203 Defines the starting angle of the pie.
200 204
201 205 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
202 206
203 207 Default is value is 0.
204 208 */
205 209
206 210 /*!
207 211 \property QPieSeries::endAngle
208 212 \brief Defines the ending angle of the pie.
209 213
210 214 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
211 215
212 216 Default is value is 360.
213 217 */
214 218
215 219 /*!
216 220 \qmlproperty real PieSeries::endAngle
217 221
218 222 Defines the ending angle of the pie.
219 223
220 224 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
221 225
222 226 Default is value is 360.
223 227 */
224 228
225 229 /*!
226 230 \property QPieSeries::count
227 231
228 232 Number of slices in the series.
229 233 */
230 234
231 235 /*!
232 236 \qmlproperty int PieSeries::count
233 237
234 238 Number of slices in the series.
235 239 */
236 240
237 241 /*!
238 242 \fn void QPieSeries::countChanged()
239 243 Emitted when the slice count has changed.
240 244 \sa count
241 245 */
242 246 /*!
243 247 \qmlsignal PieSeries::onCountChanged()
244 248 Emitted when the slice count has changed.
245 249 */
246 250
247 251 /*!
248 252 \property QPieSeries::sum
249 253
250 254 Sum of all slices.
251 255
252 256 The series keeps track of the sum of all slices it holds.
253 257 */
254 258
255 259 /*!
256 260 \qmlproperty real PieSeries::sum
257 261
258 262 Sum of all slices.
259 263
260 264 The series keeps track of the sum of all slices it holds.
261 265 */
262 266
263 267 /*!
264 268 \fn void QPieSeries::sumChanged()
265 269 Emitted when the sum of all slices has changed.
266 270 \sa sum
267 271 */
268 272 /*!
269 273 \qmlsignal PieSeries::onSumChanged()
270 274 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
271 275 change value of a slice.
272 276 */
273 277
274 278 /*!
275 279 \fn void QPieSeries::added(QList<QPieSlice*> slices)
276 280
277 281 This signal is emitted when \a slices have been added to the series.
278 282
279 283 \sa append(), insert()
280 284 */
281 285 /*!
282 286 \qmlsignal PieSeries::onAdded(PieSlice slice)
283 287 Emitted when \a slice has been added to the series.
284 288 */
285 289
286 290 /*!
287 291 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
288 292 This signal is emitted when \a slices have been removed from the series.
289 293 \sa remove()
290 294 */
291 295 /*!
292 296 \qmlsignal PieSeries::onRemoved(PieSlice slice)
293 297 Emitted when \a slice has been removed from the series.
294 298 */
295 299
296 300 /*!
297 301 \fn void QPieSeries::clicked(QPieSlice* slice)
298 302 This signal is emitted when a \a slice has been clicked.
299 303 \sa QPieSlice::clicked()
300 304 */
301 305 /*!
302 306 \qmlsignal PieSeries::onClicked(PieSlice slice)
303 307 This signal is emitted when a \a slice has been clicked.
304 308 */
305 309
306 310 /*!
307 311 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
308 312 This signal is emitted when user has hovered over or away from the \a slice.
309 313 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
310 314 \sa QPieSlice::hovered()
311 315 */
312 316 /*!
313 317 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
314 318 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
315 319 over the slice and false when hover has moved away from the slice.
316 320 */
317 321
318 322 /*!
319 323 \qmlmethod PieSlice PieSeries::at(int index)
320 324 Returns slice at \a index. Returns null if the index is not valid.
321 325 */
322 326
323 327 /*!
324 328 \qmlmethod PieSlice PieSeries::find(string label)
325 329 Returns the first slice with \a label. Returns null if the index is not valid.
326 330 */
327 331
328 332 /*!
329 333 \qmlmethod PieSlice PieSeries::append(string label, real value)
330 334 Adds a new slice with \a label and \a value to the pie.
331 335 */
332 336
333 337 /*!
334 338 \qmlmethod bool PieSeries::remove(PieSlice slice)
335 339 Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise.
336 340 */
337 341
338 342 /*!
339 343 \qmlmethod PieSeries::clear()
340 344 Removes all slices from the pie.
341 345 */
342 346
343 347 /*!
344 348 Constructs a series object which is a child of \a parent.
345 349 */
346 350 QPieSeries::QPieSeries(QObject *parent) :
347 351 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
348 352 {
349 353
350 354 }
351 355
352 356 /*!
353 357 Destroys the series and its slices.
354 358 */
355 359 QPieSeries::~QPieSeries()
356 360 {
357 361 // NOTE: d_prt destroyed by QObject
358 362 }
359 363
360 364 /*!
361 365 Returns QChartSeries::SeriesTypePie.
362 366 */
363 367 QAbstractSeries::SeriesType QPieSeries::type() const
364 368 {
365 369 return QAbstractSeries::SeriesTypePie;
366 370 }
367 371
368 372 /*!
369 373 Appends a single \a slice to the series.
370 374 Slice ownership is passed to the series.
371 375
372 376 Returns true if append was succesfull.
373 377 */
374 378 bool QPieSeries::append(QPieSlice* slice)
375 379 {
376 380 return append(QList<QPieSlice*>() << slice);
377 381 }
378 382
379 383 /*!
380 384 Appends an array of \a slices to the series.
381 385 Slice ownership is passed to the series.
382 386
383 387 Returns true if append was successfull.
384 388 */
385 389 bool QPieSeries::append(QList<QPieSlice*> slices)
386 390 {
387 391 Q_D(QPieSeries);
388 392
389 393 if (slices.count() == 0)
390 394 return false;
391 395
392 396 foreach (QPieSlice* s, slices) {
393 397 if (!s || d->m_slices.contains(s))
394 398 return false;
395 399 if (s->series()) // already added to some series
396 400 return false;
397 401 }
398 402
399 403 foreach (QPieSlice* s, slices) {
400 404 s->setParent(this);
401 405 QPieSlicePrivate::fromSlice(s)->m_series = this;
402 406 d->m_slices << s;
403 407 }
404 408
405 409 d->updateDerivativeData();
406 410
407 411 foreach (QPieSlice* s, slices) {
408 412 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
409 413 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
410 414 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
411 415 }
412 416
413 417 emit added(slices);
414 418 emit countChanged();
415 419
416 420 return true;
417 421 }
418 422
419 423 /*!
420 424 Appends a single \a slice to the series and returns a reference to the series.
421 425 Slice ownership is passed to the series.
422 426 */
423 427 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
424 428 {
425 429 append(slice);
426 430 return *this;
427 431 }
428 432
429 433
430 434 /*!
431 435 Appends a single slice to the series with give \a value and \a label.
432 436 Slice ownership is passed to the series.
433 437 */
434 438 QPieSlice* QPieSeries::append(QString label, qreal value)
435 439 {
436 440 QPieSlice* slice = new QPieSlice(label, value);
437 441 append(slice);
438 442 return slice;
439 443 }
440 444
441 445 /*!
442 446 Inserts a single \a slice to the series before the slice at \a index position.
443 447 Slice ownership is passed to the series.
444 448
445 449 Returns true if insert was successfull.
446 450 */
447 451 bool QPieSeries::insert(int index, QPieSlice* slice)
448 452 {
449 453 Q_D(QPieSeries);
450 454
451 455 if (index < 0 || index > d->m_slices.count())
452 456 return false;
453 457
454 458 if (!slice || d->m_slices.contains(slice))
455 459 return false;
456 460
457 461 if (slice->series()) // already added to some series
458 462 return false;
459 463
460 464 slice->setParent(this);
461 465 QPieSlicePrivate::fromSlice(slice)->m_series = this;
462 466 d->m_slices.insert(index, slice);
463 467
464 468 d->updateDerivativeData();
465 469
466 470 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
467 471 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
468 472 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
469 473
470 474 emit added(QList<QPieSlice*>() << slice);
471 475 emit countChanged();
472 476
473 477 return true;
474 478 }
475 479
476 480 /*!
477 481 Removes a single \a slice from the series and deletes the slice.
478 482
479 483 Do not reference the pointer after this call.
480 484
481 485 Returns true if remove was successfull.
482 486 */
483 487 bool QPieSeries::remove(QPieSlice* slice)
484 488 {
485 489 Q_D(QPieSeries);
486 490
487 491 if (!d->m_slices.removeOne(slice))
488 492 return false;
489 493
490 494 d->updateDerivativeData();
491 495
492 496 emit removed(QList<QPieSlice*>() << slice);
493 497 emit countChanged();
494 498
495 499 delete slice;
496 500 slice = 0;
497 501
498 502 return true;
499 503 }
500 504
501 505 /*!
502 506 Takes a single \a slice from the series. Does not destroy the slice object.
503 507
504 508 NOTE: The series remains as the slice's parent object. You must set the
505 509 parent object to take full ownership.
506 510
507 511 Returns true if take was successfull.
508 512 */
509 513 bool QPieSeries::take(QPieSlice* slice)
510 514 {
511 515 Q_D(QPieSeries);
512 516
513 517 if (!d->m_slices.removeOne(slice))
514 518 return false;
515 519
516 520 QPieSlicePrivate::fromSlice(slice)->m_series = 0;
517 521
518 522 d->updateDerivativeData();
519 523
520 524 emit removed(QList<QPieSlice*>() << slice);
521 525 emit countChanged();
522 526
523 527 return true;
524 528 }
525 529
526 530 /*!
527 531 Clears all slices from the series.
528 532 */
529 533 void QPieSeries::clear()
530 534 {
531 535 Q_D(QPieSeries);
532 536 if (d->m_slices.count() == 0)
533 537 return;
534 538
535 539 QList<QPieSlice*> slices = d->m_slices;
536 540 foreach (QPieSlice* s, d->m_slices) {
537 541 d->m_slices.removeOne(s);
538 542 delete s;
539 543 }
540 544
541 545 d->updateDerivativeData();
542 546
543 547 emit removed(slices);
544 548 emit countChanged();
545 549 }
546 550
547 551 /*!
548 552 Returns a list of slices that belong to this series.
549 553 */
550 554 QList<QPieSlice*> QPieSeries::slices() const
551 555 {
552 556 Q_D(const QPieSeries);
553 557 return d->m_slices;
554 558 }
555 559
556 560 /*!
557 561 returns the number of the slices in this series.
558 562 */
559 563 int QPieSeries::count() const
560 564 {
561 565 Q_D(const QPieSeries);
562 566 return d->m_slices.count();
563 567 }
564 568
565 569 /*!
566 570 Returns true is the series is empty.
567 571 */
568 572 bool QPieSeries::isEmpty() const
569 573 {
570 574 Q_D(const QPieSeries);
571 575 return d->m_slices.isEmpty();
572 576 }
573 577
574 578 /*!
575 579 Returns the sum of all slice values in this series.
576 580
577 581 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
578 582 */
579 583 qreal QPieSeries::sum() const
580 584 {
581 585 Q_D(const QPieSeries);
582 586 return d->m_sum;
583 587 }
584 588
585 589 void QPieSeries::setHoleSize(qreal holeSize)
586 590 {
587 591 Q_D(QPieSeries);
588 592 holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0);
589 593 d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize));
590 594 }
591 595
592 596 qreal QPieSeries::holeSize() const
593 597 {
594 598 Q_D(const QPieSeries);
595 599 return d->m_holeRelativeSize;
596 600 }
597 601
598 602 void QPieSeries::setHorizontalPosition(qreal relativePosition)
599 603 {
600 604 Q_D(QPieSeries);
601 605
602 606 if (relativePosition < 0.0)
603 607 relativePosition = 0.0;
604 608 if (relativePosition > 1.0)
605 609 relativePosition = 1.0;
606 610
607 611 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
608 612 d->m_pieRelativeHorPos = relativePosition;
609 613 emit d->horizontalPositionChanged();
610 614 }
611 615 }
612 616
613 617 qreal QPieSeries::horizontalPosition() const
614 618 {
615 619 Q_D(const QPieSeries);
616 620 return d->m_pieRelativeHorPos;
617 621 }
618 622
619 623 void QPieSeries::setVerticalPosition(qreal relativePosition)
620 624 {
621 625 Q_D(QPieSeries);
622 626
623 627 if (relativePosition < 0.0)
624 628 relativePosition = 0.0;
625 629 if (relativePosition > 1.0)
626 630 relativePosition = 1.0;
627 631
628 632 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
629 633 d->m_pieRelativeVerPos = relativePosition;
630 634 emit d->verticalPositionChanged();
631 635 }
632 636 }
633 637
634 638 qreal QPieSeries::verticalPosition() const
635 639 {
636 640 Q_D(const QPieSeries);
637 641 return d->m_pieRelativeVerPos;
638 642 }
639 643
640 644 void QPieSeries::setPieSize(qreal relativeSize)
641 645 {
642 646 Q_D(QPieSeries);
643 647 relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0);
644 648 d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize);
645 649
646 650 }
647 651
648 652 qreal QPieSeries::pieSize() const
649 653 {
650 654 Q_D(const QPieSeries);
651 655 return d->m_pieRelativeSize;
652 656 }
653 657
654 658
655 659 void QPieSeries::setPieStartAngle(qreal angle)
656 660 {
657 661 Q_D(QPieSeries);
658 662 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
659 663 return;
660 664 d->m_pieStartAngle = angle;
661 665 d->updateDerivativeData();
662 666 emit d->pieStartAngleChanged();
663 667 }
664 668
665 669 qreal QPieSeries::pieStartAngle() const
666 670 {
667 671 Q_D(const QPieSeries);
668 672 return d->m_pieStartAngle;
669 673 }
670 674
671 675 /*!
672 676 Sets the end angle of the pie.
673 677
674 678 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
675 679
676 680 \a angle must be greater than start angle.
677 681
678 682 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
679 683 */
680 684 void QPieSeries::setPieEndAngle(qreal angle)
681 685 {
682 686 Q_D(QPieSeries);
683 687 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
684 688 return;
685 689 d->m_pieEndAngle = angle;
686 690 d->updateDerivativeData();
687 691 emit d->pieEndAngleChanged();
688 692 }
689 693
690 694 /*!
691 695 Returns the end angle of the pie.
692 696
693 697 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
694 698
695 699 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
696 700 */
697 701 qreal QPieSeries::pieEndAngle() const
698 702 {
699 703 Q_D(const QPieSeries);
700 704 return d->m_pieEndAngle;
701 705 }
702 706
703 707 /*!
704 708 Sets the all the slice labels \a visible or invisible.
705 709
706 710 Note that this affects only the current slices in the series.
707 711 If user adds a new slice the default label visibility is false.
708 712
709 713 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
710 714 */
711 715 void QPieSeries::setLabelsVisible(bool visible)
712 716 {
713 717 Q_D(QPieSeries);
714 718 foreach (QPieSlice* s, d->m_slices)
715 719 s->setLabelVisible(visible);
716 720 }
717 721
718 722 /*!
719 723 Sets the all the slice labels \a position
720 724
721 725 Note that this affects only the current slices in the series.
722 726 If user adds a new slice the default label position is LabelOutside
723 727
724 728 \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition()
725 729 */
726 730 void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
727 731 {
728 732 Q_D(QPieSeries);
729 733 foreach (QPieSlice* s, d->m_slices)
730 734 s->setLabelPosition(position);
731 735 }
732 736
733 737 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
734 738
735 739
736 740 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
737 741 QAbstractSeriesPrivate(parent),
738 742 m_pieRelativeHorPos(0.5),
739 743 m_pieRelativeVerPos(0.5),
740 744 m_pieRelativeSize(0.7),
741 745 m_pieStartAngle(0),
742 746 m_pieEndAngle(360),
743 747 m_sum(0),
744 748 m_holeRelativeSize(0.0)
745 749 {
746 750 }
747 751
748 752 QPieSeriesPrivate::~QPieSeriesPrivate()
749 753 {
750 754 }
751 755
752 756 void QPieSeriesPrivate::updateDerivativeData()
753 757 {
754 758 // calculate sum of all slices
755 759 qreal sum = 0;
756 760 foreach (QPieSlice* s, m_slices)
757 761 sum += s->value();
758 762
759 763 if (!qFuzzyIsNull(m_sum - sum)) {
760 764 m_sum = sum;
761 765 emit q_func()->sumChanged();
762 766 }
763 767
764 768 // nothing to show..
765 769 if (qFuzzyIsNull(m_sum))
766 770 return;
767 771
768 772 // update slice attributes
769 773 qreal sliceAngle = m_pieStartAngle;
770 774 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
771 775 QVector<QPieSlice*> changed;
772 776 foreach (QPieSlice* s, m_slices) {
773 777 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
774 778 d->setPercentage(s->value() / m_sum);
775 779 d->setStartAngle(sliceAngle);
776 780 d->setAngleSpan(pieSpan * s->percentage());
777 781 sliceAngle += s->angleSpan();
778 782 }
779 783
780 784
781 785 emit calculatedDataChanged();
782 786 }
783 787
784 788 void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize)
785 789 {
786 790 bool changed = false;
787 791
788 792 if (!qFuzzyIsNull(m_holeRelativeSize - innerSize)) {
789 793 m_holeRelativeSize = innerSize;
790 794 changed = true;
791 795 }
792 796
793 797 if (!qFuzzyIsNull(m_pieRelativeSize - outerSize)) {
794 798 m_pieRelativeSize = outerSize;
795 799 changed = true;
796 800 }
797 801
798 802 if (changed)
799 803 emit pieSizeChanged();
800 804 }
801 805
802 806 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
803 807 {
804 808 return series->d_func();
805 809 }
806 810
807 811 void QPieSeriesPrivate::sliceValueChanged()
808 812 {
809 813 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
810 814 updateDerivativeData();
811 815 }
812 816
813 817 void QPieSeriesPrivate::sliceClicked()
814 818 {
815 819 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
816 820 Q_ASSERT(m_slices.contains(slice));
817 821 Q_Q(QPieSeries);
818 822 emit q->clicked(slice);
819 823 }
820 824
821 825 void QPieSeriesPrivate::sliceHovered(bool state)
822 826 {
823 827 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
824 828 Q_ASSERT(m_slices.contains(slice));
825 829 Q_Q(QPieSeries);
826 830 emit q->hovered(slice, state);
827 831 }
828 832
829 833 void QPieSeriesPrivate::scaleDomain(Domain& domain)
830 834 {
831 835 Q_UNUSED(domain);
832 836 // does not apply to pie
833 837 }
834 838
835 839 ChartElement* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
836 840 {
837 841 Q_Q(QPieSeries);
838 842 PieChartItem* pie = new PieChartItem(q,presenter);
839 843 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
840 844 pie->setAnimation(new PieAnimation(pie));
841 845 }
842 846 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
843 847 return pie;
844 848 }
845 849
846 850 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
847 851 {
848 852 Q_Q(QPieSeries);
849 853 QList<LegendMarker*> markers;
850 854 foreach(QPieSlice* slice, q->slices()) {
851 855 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
852 856 markers << marker;
853 857 }
854 858 return markers;
855 859 }
856 860
857 861 void QPieSeriesPrivate::initializeAxis(QAbstractAxis* axis)
858 862 {
859 863 Q_UNUSED(axis);
860 864 }
861 865
862 866 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
863 867 {
864 868 Q_UNUSED(orientation);
865 869 return QAbstractAxis::AxisTypeNoAxis;
866 870 }
867 871
868 872 #include "moc_qpieseries.cpp"
869 873 #include "moc_qpieseries_p.cpp"
870 874
871 875 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now