##// END OF EJS Templates
Fixed documentation of signals of PieSeries...
Titta Heikkala -
r2797:e373ed9f8f65
parent child
Show More
@@ -1,1002 +1,1012
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd
3 ** Copyright (C) 2015 The Qt Company Ltd
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
6 **
6 **
7 ** This file is part of the Qt Charts module.
7 ** This file is part of the Qt Charts module.
8 **
8 **
9 ** Licensees holding valid commercial license for Qt may use this file in
9 ** Licensees holding valid commercial license for Qt may use this file in
10 ** accordance with the Qt License Agreement provided with the Software
10 ** accordance with the Qt License Agreement provided with the Software
11 ** or, alternatively, in accordance with the terms contained in a written
11 ** or, alternatively, in accordance with the terms contained in a written
12 ** agreement between you and The Qt Company.
12 ** agreement between you and The Qt Company.
13 **
13 **
14 ** If you have questions regarding the use of this file, please use
14 ** If you have questions regarding the use of this file, please use
15 ** contact form at http://qt.io
15 ** contact form at http://qt.io
16 **
16 **
17 ****************************************************************************/
17 ****************************************************************************/
18
18
19 #include <QtCharts/QPieSeries>
19 #include <QtCharts/QPieSeries>
20 #include <private/qpieseries_p.h>
20 #include <private/qpieseries_p.h>
21 #include <QtCharts/QPieSlice>
21 #include <QtCharts/QPieSlice>
22 #include <private/qpieslice_p.h>
22 #include <private/qpieslice_p.h>
23 #include <private/pieslicedata_p.h>
23 #include <private/pieslicedata_p.h>
24 #include <private/chartdataset_p.h>
24 #include <private/chartdataset_p.h>
25 #include <private/charttheme_p.h>
25 #include <private/charttheme_p.h>
26 #include <QtCharts/QAbstractAxis>
26 #include <QtCharts/QAbstractAxis>
27 #include <private/pieanimation_p.h>
27 #include <private/pieanimation_p.h>
28 #include <private/charthelpers_p.h>
28 #include <private/charthelpers_p.h>
29
29
30 #include <QtCharts/QPieLegendMarker>
30 #include <QtCharts/QPieLegendMarker>
31
31
32 QT_CHARTS_BEGIN_NAMESPACE
32 QT_CHARTS_BEGIN_NAMESPACE
33
33
34 /*!
34 /*!
35 \class QPieSeries
35 \class QPieSeries
36 \inmodule Qt Charts
36 \inmodule Qt Charts
37 \brief Pie series API for Qt Charts.
37 \brief Pie series API for Qt Charts.
38
38
39 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
39 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
40 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
40 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
41 The actual slice size is determined by that relative value.
41 The actual slice size is determined by that relative value.
42
42
43 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0.
43 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0.
44 These relate to the actual chart rectangle.
44 These relate to the actual chart rectangle.
45
45
46 By default the pie is defined as a full pie but it can also be a partial pie.
46 By default the pie is defined as a full pie but it can also be a partial pie.
47 This can be done by setting a starting angle and angle span to the series.
47 This can be done by setting a starting angle and angle span to the series.
48 Full pie is 360 degrees where 0 is at 12 a'clock.
48 Full pie is 360 degrees where 0 is at 12 a'clock.
49
49
50 See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries.
50 See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries.
51 \image examples_piechart.png
51 \image examples_piechart.png
52 \image examples_donutchart.png
52 \image examples_donutchart.png
53 */
53 */
54 /*!
54 /*!
55 \qmltype PieSeries
55 \qmltype PieSeries
56 \instantiates QPieSeries
56 \instantiates QPieSeries
57 \inqmlmodule QtCharts
57 \inqmlmodule QtCharts
58
58
59 \inherits AbstractSeries
59 \inherits AbstractSeries
60
60
61 \brief The PieSeries type is used for making pie charts.
61 \brief The PieSeries type is used for making pie charts.
62
62
63 The following QML shows how to create a simple pie chart.
63 The following QML shows how to create a simple pie chart.
64
64
65 \snippet qmlchart/qml/qmlchart/View1.qml 1
65 \snippet qmlchart/qml/qmlchart/View1.qml 1
66
66
67 \beginfloatleft
67 \beginfloatleft
68 \image examples_qmlchart1.png
68 \image examples_qmlchart1.png
69 \endfloat
69 \endfloat
70 \clearfloat
70 \clearfloat
71 */
71 */
72
72
73 /*!
73 /*!
74 \property QPieSeries::horizontalPosition
74 \property QPieSeries::horizontalPosition
75 \brief Defines the horizontal position of the pie.
75 \brief Defines the horizontal position of the pie.
76
76
77 The value is a relative value to the chart rectangle where:
77 The value is a relative value to the chart rectangle where:
78
78
79 \list
79 \list
80 \li 0.0 is the absolute left.
80 \li 0.0 is the absolute left.
81 \li 1.0 is the absolute right.
81 \li 1.0 is the absolute right.
82 \endlist
82 \endlist
83 Default value is 0.5 (center).
83 Default value is 0.5 (center).
84 \sa verticalPosition
84 \sa verticalPosition
85 */
85 */
86
86
87 /*!
87 /*!
88 \qmlproperty real PieSeries::horizontalPosition
88 \qmlproperty real PieSeries::horizontalPosition
89
89
90 Defines the horizontal position of the pie.
90 Defines the horizontal position of the pie.
91
91
92 The value is a relative value to the chart rectangle where:
92 The value is a relative value to the chart rectangle where:
93
93
94 \list
94 \list
95 \li 0.0 is the absolute left.
95 \li 0.0 is the absolute left.
96 \li 1.0 is the absolute right.
96 \li 1.0 is the absolute right.
97 \endlist
97 \endlist
98 Default value is 0.5 (center).
98 Default value is 0.5 (center).
99 \sa verticalPosition
99 \sa verticalPosition
100 */
100 */
101
101
102 /*!
102 /*!
103 \property QPieSeries::verticalPosition
103 \property QPieSeries::verticalPosition
104 \brief Defines the vertical position of the pie.
104 \brief Defines the vertical position of the pie.
105
105
106 The value is a relative value to the chart rectangle where:
106 The value is a relative value to the chart rectangle where:
107
107
108 \list
108 \list
109 \li 0.0 is the absolute top.
109 \li 0.0 is the absolute top.
110 \li 1.0 is the absolute bottom.
110 \li 1.0 is the absolute bottom.
111 \endlist
111 \endlist
112 Default value is 0.5 (center).
112 Default value is 0.5 (center).
113 \sa horizontalPosition
113 \sa horizontalPosition
114 */
114 */
115
115
116 /*!
116 /*!
117 \qmlproperty real PieSeries::verticalPosition
117 \qmlproperty real PieSeries::verticalPosition
118
118
119 Defines the vertical position of the pie.
119 Defines the vertical position of the pie.
120
120
121 The value is a relative value to the chart rectangle where:
121 The value is a relative value to the chart rectangle where:
122
122
123 \list
123 \list
124 \li 0.0 is the absolute top.
124 \li 0.0 is the absolute top.
125 \li 1.0 is the absolute bottom.
125 \li 1.0 is the absolute bottom.
126 \endlist
126 \endlist
127 Default value is 0.5 (center).
127 Default value is 0.5 (center).
128 \sa horizontalPosition
128 \sa horizontalPosition
129 */
129 */
130
130
131 /*!
131 /*!
132 \property QPieSeries::size
132 \property QPieSeries::size
133 \brief Defines the pie size.
133 \brief Defines the pie size.
134
134
135 The value is a relative value to the chart rectangle where:
135 The value is a relative value to the chart rectangle where:
136
136
137 \list
137 \list
138 \li 0.0 is the minimum size (pie not drawn).
138 \li 0.0 is the minimum size (pie not drawn).
139 \li 1.0 is the maximum size that can fit the chart.
139 \li 1.0 is the maximum size that can fit the chart.
140 \endlist
140 \endlist
141
141
142 When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size.
142 When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size.
143
143
144 Default value is 0.7.
144 Default value is 0.7.
145 */
145 */
146
146
147 /*!
147 /*!
148 \qmlproperty real PieSeries::size
148 \qmlproperty real PieSeries::size
149
149
150 Defines the pie size.
150 Defines the pie size.
151
151
152 The value is a relative value to the chart rectangle where:
152 The value is a relative value to the chart rectangle where:
153
153
154 \list
154 \list
155 \li 0.0 is the minimum size (pie not drawn).
155 \li 0.0 is the minimum size (pie not drawn).
156 \li 1.0 is the maximum size that can fit the chart.
156 \li 1.0 is the maximum size that can fit the chart.
157 \endlist
157 \endlist
158
158
159 Default value is 0.7.
159 Default value is 0.7.
160 */
160 */
161
161
162 /*!
162 /*!
163 \property QPieSeries::holeSize
163 \property QPieSeries::holeSize
164 \brief Defines the donut hole size.
164 \brief Defines the donut hole size.
165
165
166 The value is a relative value to the chart rectangle where:
166 The value is a relative value to the chart rectangle where:
167
167
168 \list
168 \list
169 \li 0.0 is the minimum size (full pie drawn, without any hole inside).
169 \li 0.0 is the minimum size (full pie drawn, without any hole inside).
170 \li 1.0 is the maximum size that can fit the chart. (donut has no width)
170 \li 1.0 is the maximum size that can fit the chart. (donut has no width)
171 \endlist
171 \endlist
172
172
173 The value is never greater then size property.
173 The value is never greater then size property.
174 Default value is 0.0.
174 Default value is 0.0.
175 */
175 */
176
176
177 /*!
177 /*!
178 \qmlproperty real PieSeries::holeSize
178 \qmlproperty real PieSeries::holeSize
179
179
180 Defines the donut hole size.
180 Defines the donut hole size.
181
181
182 The value is a relative value to the chart rectangle where:
182 The value is a relative value to the chart rectangle where:
183
183
184 \list
184 \list
185 \li 0.0 is the minimum size (full pie drawn, without any hole inside).
185 \li 0.0 is the minimum size (full pie drawn, without any hole inside).
186 \li 1.0 is the maximum size that can fit the chart. (donut has no width)
186 \li 1.0 is the maximum size that can fit the chart. (donut has no width)
187 \endlist
187 \endlist
188
188
189 When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size.
189 When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size.
190
190
191 Default value is 0.0.
191 Default value is 0.0.
192 */
192 */
193
193
194 /*!
194 /*!
195 \property QPieSeries::startAngle
195 \property QPieSeries::startAngle
196 \brief Defines the starting angle of the pie.
196 \brief Defines the starting angle of the pie.
197
197
198 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
198 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
199
199
200 Default is value is 0.
200 Default is value is 0.
201 */
201 */
202
202
203 /*!
203 /*!
204 \qmlproperty real PieSeries::startAngle
204 \qmlproperty real PieSeries::startAngle
205
205
206 Defines the starting angle of the pie.
206 Defines the starting angle of the pie.
207
207
208 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
208 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
209
209
210 Default is value is 0.
210 Default is value is 0.
211 */
211 */
212
212
213 /*!
213 /*!
214 \property QPieSeries::endAngle
214 \property QPieSeries::endAngle
215 \brief Defines the ending angle of the pie.
215 \brief Defines the ending angle of the pie.
216
216
217 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
217 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
218
218
219 Default is value is 360.
219 Default is value is 360.
220 */
220 */
221
221
222 /*!
222 /*!
223 \qmlproperty real PieSeries::endAngle
223 \qmlproperty real PieSeries::endAngle
224
224
225 Defines the ending angle of the pie.
225 Defines the ending angle of the pie.
226
226
227 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
227 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
228
228
229 Default is value is 360.
229 Default is value is 360.
230 */
230 */
231
231
232 /*!
232 /*!
233 \property QPieSeries::count
233 \property QPieSeries::count
234
234
235 Number of slices in the series.
235 Number of slices in the series.
236 */
236 */
237
237
238 /*!
238 /*!
239 \qmlproperty int PieSeries::count
239 \qmlproperty int PieSeries::count
240
240
241 Number of slices in the series.
241 Number of slices in the series.
242 */
242 */
243
243
244 /*!
244 /*!
245 \fn void QPieSeries::countChanged()
245 \fn void QPieSeries::countChanged()
246 Emitted when the slice count has changed.
246 Emitted when the slice count has changed.
247 \sa count
247 \sa count
248 */
248 */
249 /*!
249 /*!
250 \qmlsignal PieSeries::onCountChanged()
250 \qmlsignal PieSeries::onCountChanged()
251 Emitted when the slice count has changed.
251 Emitted when the slice count has changed.
252 */
252 */
253
253
254 /*!
254 /*!
255 \property QPieSeries::sum
255 \property QPieSeries::sum
256
256
257 Sum of all slices.
257 Sum of all slices.
258
258
259 The series keeps track of the sum of all slices it holds.
259 The series keeps track of the sum of all slices it holds.
260 */
260 */
261
261
262 /*!
262 /*!
263 \qmlproperty real PieSeries::sum
263 \qmlproperty real PieSeries::sum
264
264
265 Sum of all slices.
265 Sum of all slices.
266
266
267 The series keeps track of the sum of all slices it holds.
267 The series keeps track of the sum of all slices it holds.
268 */
268 */
269
269
270 /*!
270 /*!
271 \fn void QPieSeries::sumChanged()
271 \fn void QPieSeries::sumChanged()
272 Emitted when the sum of all slices has changed.
272 Emitted when the sum of all slices has changed.
273 \sa sum
273 \sa sum
274 */
274 */
275 /*!
275 /*!
276 \qmlsignal PieSeries::onSumChanged()
276 \qmlsignal PieSeries::onSumChanged()
277 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
277 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
278 change value of a slice.
278 change value of a slice.
279 */
279 */
280
280
281 /*!
281 /*!
282 \fn void QPieSeries::added(QList<QPieSlice*> slices)
282 \fn void QPieSeries::added(QList<QPieSlice*> slices)
283
283
284 This signal is emitted when \a slices have been added to the series.
284 This signal is emitted when \a slices have been added to the series.
285
285
286 \sa append(), insert()
286 \sa append(), insert()
287 */
287 */
288 /*!
288 /*!
289 \qmlsignal PieSeries::onAdded(PieSlice slice)
289 \qmlsignal PieSeries::onAdded(list<PieSlice> slices)
290 Emitted when \a slice has been added to the series.
290 Emitted when \a slices have been added to the series.
291 */
291 */
292
292
293 /*!
293 /*!
294 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
294 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
295 This signal is emitted when \a slices have been removed from the series.
295 This signal is emitted when \a slices have been removed from the series.
296 \sa remove()
296 \sa remove()
297 */
297 */
298 /*!
298 /*!
299 \qmlsignal PieSeries::onRemoved(PieSlice slice)
299 \qmlsignal PieSeries::onRemoved(list<PieSlice> slices)
300 Emitted when \a slices have been removed from the series.
301 */
302
303 /*!
304 \qmlsignal PieSeries::onSliceAdded(PieSlice slice)
305 Emitted when \a slice has been added to the series.
306 */
307
308 /*!
309 \qmlsignal PieSeries::onSliceRemoved(PieSlice slice)
300 Emitted when \a slice has been removed from the series.
310 Emitted when \a slice has been removed from the series.
301 */
311 */
302
312
303 /*!
313 /*!
304 \fn void QPieSeries::clicked(QPieSlice *slice)
314 \fn void QPieSeries::clicked(QPieSlice *slice)
305 This signal is emitted when a \a slice has been clicked.
315 This signal is emitted when a \a slice has been clicked.
306 \sa QPieSlice::clicked()
316 \sa QPieSlice::clicked()
307 */
317 */
308 /*!
318 /*!
309 \qmlsignal PieSeries::onClicked(PieSlice slice)
319 \qmlsignal PieSeries::onClicked(PieSlice slice)
310 This signal is emitted when a \a slice has been clicked.
320 This signal is emitted when a \a slice has been clicked.
311 */
321 */
312
322
313 /*!
323 /*!
314 \fn void QPieSeries::pressed(QPieSlice *slice)
324 \fn void QPieSeries::pressed(QPieSlice *slice)
315 This signal is emitted when a \a slice has been pressed.
325 This signal is emitted when a \a slice has been pressed.
316 \sa QPieSlice::pressed()
326 \sa QPieSlice::pressed()
317 */
327 */
318 /*!
328 /*!
319 \qmlsignal PieSeries::onPressed(PieSlice slice)
329 \qmlsignal PieSeries::onPressed(PieSlice slice)
320 This signal is emitted when a \a slice has been pressed.
330 This signal is emitted when a \a slice has been pressed.
321 */
331 */
322
332
323 /*!
333 /*!
324 \fn void QPieSeries::released(QPieSlice *slice)
334 \fn void QPieSeries::released(QPieSlice *slice)
325 This signal is emitted when a \a slice has been released.
335 This signal is emitted when a \a slice has been released.
326 \sa QPieSlice::released()
336 \sa QPieSlice::released()
327 */
337 */
328 /*!
338 /*!
329 \qmlsignal PieSeries::onReleased(PieSlice slice)
339 \qmlsignal PieSeries::onReleased(PieSlice slice)
330 This signal is emitted when a \a slice has been released.
340 This signal is emitted when a \a slice has been released.
331 */
341 */
332
342
333 /*!
343 /*!
334 \fn void QPieSeries::doubleClicked(QPieSlice *slice)
344 \fn void QPieSeries::doubleClicked(QPieSlice *slice)
335 This signal is emitted when a \a slice has been doubleClicked.
345 This signal is emitted when a \a slice has been doubleClicked.
336 \sa QPieSlice::doubleClicked()
346 \sa QPieSlice::doubleClicked()
337 */
347 */
338 /*!
348 /*!
339 \qmlsignal PieSeries::onDoubleClicked(PieSlice slice)
349 \qmlsignal PieSeries::onDoubleClicked(PieSlice slice)
340 This signal is emitted when a \a slice has been doubleClicked.
350 This signal is emitted when a \a slice has been doubleClicked.
341 */
351 */
342
352
343 /*!
353 /*!
344 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
354 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
345 This signal is emitted when user has hovered over or away from the \a slice.
355 This signal is emitted when user has hovered over or away from the \a slice.
346 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
356 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
347 \sa QPieSlice::hovered()
357 \sa QPieSlice::hovered()
348 */
358 */
349 /*!
359 /*!
350 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
360 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
351 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
361 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
352 over the slice and false when hover has moved away from the slice.
362 over the slice and false when hover has moved away from the slice.
353 */
363 */
354
364
355 /*!
365 /*!
356 \qmlmethod PieSlice PieSeries::at(int index)
366 \qmlmethod PieSlice PieSeries::at(int index)
357 Returns slice at \a index. Returns null if the index is not valid.
367 Returns slice at \a index. Returns null if the index is not valid.
358 */
368 */
359
369
360 /*!
370 /*!
361 \qmlmethod PieSlice PieSeries::find(string label)
371 \qmlmethod PieSlice PieSeries::find(string label)
362 Returns the first slice with \a label. Returns null if the index is not valid.
372 Returns the first slice with \a label. Returns null if the index is not valid.
363 */
373 */
364
374
365 /*!
375 /*!
366 \qmlmethod PieSlice PieSeries::append(string label, real value)
376 \qmlmethod PieSlice PieSeries::append(string label, real value)
367 Adds a new slice with \a label and \a value to the pie.
377 Adds a new slice with \a label and \a value to the pie.
368 */
378 */
369
379
370 /*!
380 /*!
371 \qmlmethod bool PieSeries::remove(PieSlice slice)
381 \qmlmethod bool PieSeries::remove(PieSlice slice)
372 Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise.
382 Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise.
373 */
383 */
374
384
375 /*!
385 /*!
376 \qmlmethod PieSeries::clear()
386 \qmlmethod PieSeries::clear()
377 Removes all slices from the pie.
387 Removes all slices from the pie.
378 */
388 */
379
389
380 /*!
390 /*!
381 Constructs a series object which is a child of \a parent.
391 Constructs a series object which is a child of \a parent.
382 */
392 */
383 QPieSeries::QPieSeries(QObject *parent)
393 QPieSeries::QPieSeries(QObject *parent)
384 : QAbstractSeries(*new QPieSeriesPrivate(this), parent)
394 : QAbstractSeries(*new QPieSeriesPrivate(this), parent)
385 {
395 {
386 Q_D(QPieSeries);
396 Q_D(QPieSeries);
387 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
397 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
388 }
398 }
389
399
390 /*!
400 /*!
391 Destroys the series and its slices.
401 Destroys the series and its slices.
392 */
402 */
393 QPieSeries::~QPieSeries()
403 QPieSeries::~QPieSeries()
394 {
404 {
395 // NOTE: d_prt destroyed by QObject
405 // NOTE: d_prt destroyed by QObject
396 clear();
406 clear();
397 }
407 }
398
408
399 /*!
409 /*!
400 Returns QAbstractSeries::SeriesTypePie.
410 Returns QAbstractSeries::SeriesTypePie.
401 */
411 */
402 QAbstractSeries::SeriesType QPieSeries::type() const
412 QAbstractSeries::SeriesType QPieSeries::type() const
403 {
413 {
404 return QAbstractSeries::SeriesTypePie;
414 return QAbstractSeries::SeriesTypePie;
405 }
415 }
406
416
407 /*!
417 /*!
408 Appends a single \a slice to the series.
418 Appends a single \a slice to the series.
409 Slice ownership is passed to the series.
419 Slice ownership is passed to the series.
410
420
411 Returns true if append was succesfull.
421 Returns true if append was succesfull.
412 */
422 */
413 bool QPieSeries::append(QPieSlice *slice)
423 bool QPieSeries::append(QPieSlice *slice)
414 {
424 {
415 return append(QList<QPieSlice *>() << slice);
425 return append(QList<QPieSlice *>() << slice);
416 }
426 }
417
427
418 /*!
428 /*!
419 Appends an array of \a slices to the series.
429 Appends an array of \a slices to the series.
420 Slice ownership is passed to the series.
430 Slice ownership is passed to the series.
421
431
422 Returns true if append was successful.
432 Returns true if append was successful.
423 */
433 */
424 bool QPieSeries::append(QList<QPieSlice *> slices)
434 bool QPieSeries::append(QList<QPieSlice *> slices)
425 {
435 {
426 Q_D(QPieSeries);
436 Q_D(QPieSeries);
427
437
428 if (slices.count() == 0)
438 if (slices.count() == 0)
429 return false;
439 return false;
430
440
431 foreach (QPieSlice *s, slices) {
441 foreach (QPieSlice *s, slices) {
432 if (!s || d->m_slices.contains(s))
442 if (!s || d->m_slices.contains(s))
433 return false;
443 return false;
434 if (s->series()) // already added to some series
444 if (s->series()) // already added to some series
435 return false;
445 return false;
436 if (!isValidValue(s->value()))
446 if (!isValidValue(s->value()))
437 return false;
447 return false;
438 }
448 }
439
449
440 foreach (QPieSlice *s, slices) {
450 foreach (QPieSlice *s, slices) {
441 s->setParent(this);
451 s->setParent(this);
442 QPieSlicePrivate::fromSlice(s)->m_series = this;
452 QPieSlicePrivate::fromSlice(s)->m_series = this;
443 d->m_slices << s;
453 d->m_slices << s;
444 }
454 }
445
455
446 d->updateDerivativeData();
456 d->updateDerivativeData();
447
457
448 foreach(QPieSlice * s, slices) {
458 foreach(QPieSlice * s, slices) {
449 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
459 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
450 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
460 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
451 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
461 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
452 connect(s, SIGNAL(pressed()), d, SLOT(slicePressed()));
462 connect(s, SIGNAL(pressed()), d, SLOT(slicePressed()));
453 connect(s, SIGNAL(released()), d, SLOT(sliceReleased()));
463 connect(s, SIGNAL(released()), d, SLOT(sliceReleased()));
454 connect(s, SIGNAL(doubleClicked()), d, SLOT(sliceDoubleClicked()));
464 connect(s, SIGNAL(doubleClicked()), d, SLOT(sliceDoubleClicked()));
455 }
465 }
456
466
457 emit added(slices);
467 emit added(slices);
458 emit countChanged();
468 emit countChanged();
459
469
460 return true;
470 return true;
461 }
471 }
462
472
463 /*!
473 /*!
464 Appends a single \a slice to the series and returns a reference to the series.
474 Appends a single \a slice to the series and returns a reference to the series.
465 Slice ownership is passed to the series.
475 Slice ownership is passed to the series.
466 */
476 */
467 QPieSeries &QPieSeries::operator << (QPieSlice *slice)
477 QPieSeries &QPieSeries::operator << (QPieSlice *slice)
468 {
478 {
469 append(slice);
479 append(slice);
470 return *this;
480 return *this;
471 }
481 }
472
482
473
483
474 /*!
484 /*!
475 Appends a single slice to the series with give \a value and \a label.
485 Appends a single slice to the series with give \a value and \a label.
476 Slice ownership is passed to the series.
486 Slice ownership is passed to the series.
477 Returns NULL if value is NaN, Inf or -Inf and no slice is added to the series.
487 Returns NULL if value is NaN, Inf or -Inf and no slice is added to the series.
478 */
488 */
479 QPieSlice *QPieSeries::append(QString label, qreal value)
489 QPieSlice *QPieSeries::append(QString label, qreal value)
480 {
490 {
481 if (isValidValue(value)) {
491 if (isValidValue(value)) {
482 QPieSlice *slice = new QPieSlice(label, value);
492 QPieSlice *slice = new QPieSlice(label, value);
483 append(slice);
493 append(slice);
484 return slice;
494 return slice;
485 } else {
495 } else {
486 return 0;
496 return 0;
487 }
497 }
488 }
498 }
489
499
490 /*!
500 /*!
491 Inserts a single \a slice to the series before the slice at \a index position.
501 Inserts a single \a slice to the series before the slice at \a index position.
492 Slice ownership is passed to the series.
502 Slice ownership is passed to the series.
493
503
494 Returns true if insert was successful.
504 Returns true if insert was successful.
495 */
505 */
496 bool QPieSeries::insert(int index, QPieSlice *slice)
506 bool QPieSeries::insert(int index, QPieSlice *slice)
497 {
507 {
498 Q_D(QPieSeries);
508 Q_D(QPieSeries);
499
509
500 if (index < 0 || index > d->m_slices.count())
510 if (index < 0 || index > d->m_slices.count())
501 return false;
511 return false;
502
512
503 if (!slice || d->m_slices.contains(slice))
513 if (!slice || d->m_slices.contains(slice))
504 return false;
514 return false;
505
515
506 if (slice->series()) // already added to some series
516 if (slice->series()) // already added to some series
507 return false;
517 return false;
508
518
509 if (!isValidValue(slice->value()))
519 if (!isValidValue(slice->value()))
510 return false;
520 return false;
511
521
512 slice->setParent(this);
522 slice->setParent(this);
513 QPieSlicePrivate::fromSlice(slice)->m_series = this;
523 QPieSlicePrivate::fromSlice(slice)->m_series = this;
514 d->m_slices.insert(index, slice);
524 d->m_slices.insert(index, slice);
515
525
516 d->updateDerivativeData();
526 d->updateDerivativeData();
517
527
518 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
528 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
519 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
529 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
520 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
530 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
521 connect(slice, SIGNAL(pressed()), d, SLOT(slicePressed()));
531 connect(slice, SIGNAL(pressed()), d, SLOT(slicePressed()));
522 connect(slice, SIGNAL(released()), d, SLOT(sliceReleased()));
532 connect(slice, SIGNAL(released()), d, SLOT(sliceReleased()));
523 connect(slice, SIGNAL(doubleClicked()), d, SLOT(sliceDoubleClicked()));
533 connect(slice, SIGNAL(doubleClicked()), d, SLOT(sliceDoubleClicked()));
524
534
525 emit added(QList<QPieSlice *>() << slice);
535 emit added(QList<QPieSlice *>() << slice);
526 emit countChanged();
536 emit countChanged();
527
537
528 return true;
538 return true;
529 }
539 }
530
540
531 /*!
541 /*!
532 Removes a single \a slice from the series and deletes the slice.
542 Removes a single \a slice from the series and deletes the slice.
533
543
534 Do not reference the pointer after this call.
544 Do not reference the pointer after this call.
535
545
536 Returns true if remove was successful.
546 Returns true if remove was successful.
537 */
547 */
538 bool QPieSeries::remove(QPieSlice *slice)
548 bool QPieSeries::remove(QPieSlice *slice)
539 {
549 {
540 Q_D(QPieSeries);
550 Q_D(QPieSeries);
541
551
542 if (!d->m_slices.removeOne(slice))
552 if (!d->m_slices.removeOne(slice))
543 return false;
553 return false;
544
554
545 d->updateDerivativeData();
555 d->updateDerivativeData();
546
556
547 emit removed(QList<QPieSlice *>() << slice);
557 emit removed(QList<QPieSlice *>() << slice);
548 emit countChanged();
558 emit countChanged();
549
559
550 delete slice;
560 delete slice;
551 slice = 0;
561 slice = 0;
552
562
553 return true;
563 return true;
554 }
564 }
555
565
556 /*!
566 /*!
557 Takes a single \a slice from the series. Does not destroy the slice object.
567 Takes a single \a slice from the series. Does not destroy the slice object.
558
568
559 \note The series remains as the slice's parent object. You must set the
569 \note The series remains as the slice's parent object. You must set the
560 parent object to take full ownership.
570 parent object to take full ownership.
561
571
562 Returns true if take was successful.
572 Returns true if take was successful.
563 */
573 */
564 bool QPieSeries::take(QPieSlice *slice)
574 bool QPieSeries::take(QPieSlice *slice)
565 {
575 {
566 Q_D(QPieSeries);
576 Q_D(QPieSeries);
567
577
568 if (!d->m_slices.removeOne(slice))
578 if (!d->m_slices.removeOne(slice))
569 return false;
579 return false;
570
580
571 QPieSlicePrivate::fromSlice(slice)->m_series = 0;
581 QPieSlicePrivate::fromSlice(slice)->m_series = 0;
572 slice->disconnect(d);
582 slice->disconnect(d);
573
583
574 d->updateDerivativeData();
584 d->updateDerivativeData();
575
585
576 emit removed(QList<QPieSlice *>() << slice);
586 emit removed(QList<QPieSlice *>() << slice);
577 emit countChanged();
587 emit countChanged();
578
588
579 return true;
589 return true;
580 }
590 }
581
591
582 /*!
592 /*!
583 Clears all slices from the series.
593 Clears all slices from the series.
584 */
594 */
585 void QPieSeries::clear()
595 void QPieSeries::clear()
586 {
596 {
587 Q_D(QPieSeries);
597 Q_D(QPieSeries);
588 if (d->m_slices.count() == 0)
598 if (d->m_slices.count() == 0)
589 return;
599 return;
590
600
591 QList<QPieSlice *> slices = d->m_slices;
601 QList<QPieSlice *> slices = d->m_slices;
592 foreach (QPieSlice *s, d->m_slices)
602 foreach (QPieSlice *s, d->m_slices)
593 d->m_slices.removeOne(s);
603 d->m_slices.removeOne(s);
594
604
595 d->updateDerivativeData();
605 d->updateDerivativeData();
596
606
597 emit removed(slices);
607 emit removed(slices);
598 emit countChanged();
608 emit countChanged();
599
609
600 foreach (QPieSlice *s, slices)
610 foreach (QPieSlice *s, slices)
601 delete s;
611 delete s;
602 }
612 }
603
613
604 /*!
614 /*!
605 Returns a list of slices that belong to this series.
615 Returns a list of slices that belong to this series.
606 */
616 */
607 QList<QPieSlice *> QPieSeries::slices() const
617 QList<QPieSlice *> QPieSeries::slices() const
608 {
618 {
609 Q_D(const QPieSeries);
619 Q_D(const QPieSeries);
610 return d->m_slices;
620 return d->m_slices;
611 }
621 }
612
622
613 /*!
623 /*!
614 returns the number of the slices in this series.
624 returns the number of the slices in this series.
615 */
625 */
616 int QPieSeries::count() const
626 int QPieSeries::count() const
617 {
627 {
618 Q_D(const QPieSeries);
628 Q_D(const QPieSeries);
619 return d->m_slices.count();
629 return d->m_slices.count();
620 }
630 }
621
631
622 /*!
632 /*!
623 Returns true is the series is empty.
633 Returns true is the series is empty.
624 */
634 */
625 bool QPieSeries::isEmpty() const
635 bool QPieSeries::isEmpty() const
626 {
636 {
627 Q_D(const QPieSeries);
637 Q_D(const QPieSeries);
628 return d->m_slices.isEmpty();
638 return d->m_slices.isEmpty();
629 }
639 }
630
640
631 /*!
641 /*!
632 Returns the sum of all slice values in this series.
642 Returns the sum of all slice values in this series.
633
643
634 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
644 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
635 */
645 */
636 qreal QPieSeries::sum() const
646 qreal QPieSeries::sum() const
637 {
647 {
638 Q_D(const QPieSeries);
648 Q_D(const QPieSeries);
639 return d->m_sum;
649 return d->m_sum;
640 }
650 }
641
651
642 void QPieSeries::setHoleSize(qreal holeSize)
652 void QPieSeries::setHoleSize(qreal holeSize)
643 {
653 {
644 Q_D(QPieSeries);
654 Q_D(QPieSeries);
645 holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0);
655 holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0);
646 d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize));
656 d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize));
647 }
657 }
648
658
649 qreal QPieSeries::holeSize() const
659 qreal QPieSeries::holeSize() const
650 {
660 {
651 Q_D(const QPieSeries);
661 Q_D(const QPieSeries);
652 return d->m_holeRelativeSize;
662 return d->m_holeRelativeSize;
653 }
663 }
654
664
655 void QPieSeries::setHorizontalPosition(qreal relativePosition)
665 void QPieSeries::setHorizontalPosition(qreal relativePosition)
656 {
666 {
657 Q_D(QPieSeries);
667 Q_D(QPieSeries);
658
668
659 if (relativePosition < 0.0)
669 if (relativePosition < 0.0)
660 relativePosition = 0.0;
670 relativePosition = 0.0;
661 if (relativePosition > 1.0)
671 if (relativePosition > 1.0)
662 relativePosition = 1.0;
672 relativePosition = 1.0;
663
673
664 if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) {
674 if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) {
665 d->m_pieRelativeHorPos = relativePosition;
675 d->m_pieRelativeHorPos = relativePosition;
666 emit d->horizontalPositionChanged();
676 emit d->horizontalPositionChanged();
667 }
677 }
668 }
678 }
669
679
670 qreal QPieSeries::horizontalPosition() const
680 qreal QPieSeries::horizontalPosition() const
671 {
681 {
672 Q_D(const QPieSeries);
682 Q_D(const QPieSeries);
673 return d->m_pieRelativeHorPos;
683 return d->m_pieRelativeHorPos;
674 }
684 }
675
685
676 void QPieSeries::setVerticalPosition(qreal relativePosition)
686 void QPieSeries::setVerticalPosition(qreal relativePosition)
677 {
687 {
678 Q_D(QPieSeries);
688 Q_D(QPieSeries);
679
689
680 if (relativePosition < 0.0)
690 if (relativePosition < 0.0)
681 relativePosition = 0.0;
691 relativePosition = 0.0;
682 if (relativePosition > 1.0)
692 if (relativePosition > 1.0)
683 relativePosition = 1.0;
693 relativePosition = 1.0;
684
694
685 if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) {
695 if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) {
686 d->m_pieRelativeVerPos = relativePosition;
696 d->m_pieRelativeVerPos = relativePosition;
687 emit d->verticalPositionChanged();
697 emit d->verticalPositionChanged();
688 }
698 }
689 }
699 }
690
700
691 qreal QPieSeries::verticalPosition() const
701 qreal QPieSeries::verticalPosition() const
692 {
702 {
693 Q_D(const QPieSeries);
703 Q_D(const QPieSeries);
694 return d->m_pieRelativeVerPos;
704 return d->m_pieRelativeVerPos;
695 }
705 }
696
706
697 void QPieSeries::setPieSize(qreal relativeSize)
707 void QPieSeries::setPieSize(qreal relativeSize)
698 {
708 {
699 Q_D(QPieSeries);
709 Q_D(QPieSeries);
700 relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0);
710 relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0);
701 d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize);
711 d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize);
702
712
703 }
713 }
704
714
705 qreal QPieSeries::pieSize() const
715 qreal QPieSeries::pieSize() const
706 {
716 {
707 Q_D(const QPieSeries);
717 Q_D(const QPieSeries);
708 return d->m_pieRelativeSize;
718 return d->m_pieRelativeSize;
709 }
719 }
710
720
711
721
712 void QPieSeries::setPieStartAngle(qreal angle)
722 void QPieSeries::setPieStartAngle(qreal angle)
713 {
723 {
714 Q_D(QPieSeries);
724 Q_D(QPieSeries);
715 if (qFuzzyCompare(d->m_pieStartAngle, angle))
725 if (qFuzzyCompare(d->m_pieStartAngle, angle))
716 return;
726 return;
717 d->m_pieStartAngle = angle;
727 d->m_pieStartAngle = angle;
718 d->updateDerivativeData();
728 d->updateDerivativeData();
719 emit d->pieStartAngleChanged();
729 emit d->pieStartAngleChanged();
720 }
730 }
721
731
722 qreal QPieSeries::pieStartAngle() const
732 qreal QPieSeries::pieStartAngle() const
723 {
733 {
724 Q_D(const QPieSeries);
734 Q_D(const QPieSeries);
725 return d->m_pieStartAngle;
735 return d->m_pieStartAngle;
726 }
736 }
727
737
728 /*!
738 /*!
729 Sets the end angle of the pie.
739 Sets the end angle of the pie.
730
740
731 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
741 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
732
742
733 \a angle must be greater than start angle.
743 \a angle must be greater than start angle.
734
744
735 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
745 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
736 */
746 */
737 void QPieSeries::setPieEndAngle(qreal angle)
747 void QPieSeries::setPieEndAngle(qreal angle)
738 {
748 {
739 Q_D(QPieSeries);
749 Q_D(QPieSeries);
740 if (qFuzzyCompare(d->m_pieEndAngle, angle))
750 if (qFuzzyCompare(d->m_pieEndAngle, angle))
741 return;
751 return;
742 d->m_pieEndAngle = angle;
752 d->m_pieEndAngle = angle;
743 d->updateDerivativeData();
753 d->updateDerivativeData();
744 emit d->pieEndAngleChanged();
754 emit d->pieEndAngleChanged();
745 }
755 }
746
756
747 /*!
757 /*!
748 Returns the end angle of the pie.
758 Returns the end angle of the pie.
749
759
750 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
760 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
751
761
752 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
762 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
753 */
763 */
754 qreal QPieSeries::pieEndAngle() const
764 qreal QPieSeries::pieEndAngle() const
755 {
765 {
756 Q_D(const QPieSeries);
766 Q_D(const QPieSeries);
757 return d->m_pieEndAngle;
767 return d->m_pieEndAngle;
758 }
768 }
759
769
760 /*!
770 /*!
761 Sets the all the slice labels \a visible or invisible.
771 Sets the all the slice labels \a visible or invisible.
762
772
763 Note that this affects only the current slices in the series.
773 Note that this affects only the current slices in the series.
764 If user adds a new slice the default label visibility is false.
774 If user adds a new slice the default label visibility is false.
765
775
766 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
776 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
767 */
777 */
768 void QPieSeries::setLabelsVisible(bool visible)
778 void QPieSeries::setLabelsVisible(bool visible)
769 {
779 {
770 Q_D(QPieSeries);
780 Q_D(QPieSeries);
771 foreach (QPieSlice *s, d->m_slices)
781 foreach (QPieSlice *s, d->m_slices)
772 s->setLabelVisible(visible);
782 s->setLabelVisible(visible);
773 }
783 }
774
784
775 /*!
785 /*!
776 Sets the all the slice labels \a position
786 Sets the all the slice labels \a position
777
787
778 Note that this affects only the current slices in the series.
788 Note that this affects only the current slices in the series.
779 If user adds a new slice the default label position is LabelOutside
789 If user adds a new slice the default label position is LabelOutside
780
790
781 \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition()
791 \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition()
782 */
792 */
783 void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
793 void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
784 {
794 {
785 Q_D(QPieSeries);
795 Q_D(QPieSeries);
786 foreach (QPieSlice *s, d->m_slices)
796 foreach (QPieSlice *s, d->m_slices)
787 s->setLabelPosition(position);
797 s->setLabelPosition(position);
788 }
798 }
789
799
790 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
800 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
791
801
792
802
793 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
803 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
794 QAbstractSeriesPrivate(parent),
804 QAbstractSeriesPrivate(parent),
795 m_pieRelativeHorPos(0.5),
805 m_pieRelativeHorPos(0.5),
796 m_pieRelativeVerPos(0.5),
806 m_pieRelativeVerPos(0.5),
797 m_pieRelativeSize(0.7),
807 m_pieRelativeSize(0.7),
798 m_pieStartAngle(0),
808 m_pieStartAngle(0),
799 m_pieEndAngle(360),
809 m_pieEndAngle(360),
800 m_sum(0),
810 m_sum(0),
801 m_holeRelativeSize(0.0)
811 m_holeRelativeSize(0.0)
802 {
812 {
803 }
813 }
804
814
805 QPieSeriesPrivate::~QPieSeriesPrivate()
815 QPieSeriesPrivate::~QPieSeriesPrivate()
806 {
816 {
807 }
817 }
808
818
809 void QPieSeriesPrivate::updateDerivativeData()
819 void QPieSeriesPrivate::updateDerivativeData()
810 {
820 {
811 // calculate sum of all slices
821 // calculate sum of all slices
812 qreal sum = 0;
822 qreal sum = 0;
813 foreach (QPieSlice *s, m_slices)
823 foreach (QPieSlice *s, m_slices)
814 sum += s->value();
824 sum += s->value();
815
825
816 if (!qFuzzyCompare(m_sum, sum)) {
826 if (!qFuzzyCompare(m_sum, sum)) {
817 m_sum = sum;
827 m_sum = sum;
818 emit q_func()->sumChanged();
828 emit q_func()->sumChanged();
819 }
829 }
820
830
821 // nothing to show..
831 // nothing to show..
822 if (qFuzzyCompare(m_sum, 0))
832 if (qFuzzyCompare(m_sum, 0))
823 return;
833 return;
824
834
825 // update slice attributes
835 // update slice attributes
826 qreal sliceAngle = m_pieStartAngle;
836 qreal sliceAngle = m_pieStartAngle;
827 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
837 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
828 QVector<QPieSlice *> changed;
838 QVector<QPieSlice *> changed;
829 foreach (QPieSlice *s, m_slices) {
839 foreach (QPieSlice *s, m_slices) {
830 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
840 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
831 d->setPercentage(s->value() / m_sum);
841 d->setPercentage(s->value() / m_sum);
832 d->setStartAngle(sliceAngle);
842 d->setStartAngle(sliceAngle);
833 d->setAngleSpan(pieSpan * s->percentage());
843 d->setAngleSpan(pieSpan * s->percentage());
834 sliceAngle += s->angleSpan();
844 sliceAngle += s->angleSpan();
835 }
845 }
836
846
837
847
838 emit calculatedDataChanged();
848 emit calculatedDataChanged();
839 }
849 }
840
850
841 void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize)
851 void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize)
842 {
852 {
843 bool changed = false;
853 bool changed = false;
844
854
845 if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) {
855 if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) {
846 m_holeRelativeSize = innerSize;
856 m_holeRelativeSize = innerSize;
847 changed = true;
857 changed = true;
848 }
858 }
849
859
850 if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) {
860 if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) {
851 m_pieRelativeSize = outerSize;
861 m_pieRelativeSize = outerSize;
852 changed = true;
862 changed = true;
853 }
863 }
854
864
855 if (changed)
865 if (changed)
856 emit pieSizeChanged();
866 emit pieSizeChanged();
857 }
867 }
858
868
859 QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series)
869 QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series)
860 {
870 {
861 return series->d_func();
871 return series->d_func();
862 }
872 }
863
873
864 void QPieSeriesPrivate::sliceValueChanged()
874 void QPieSeriesPrivate::sliceValueChanged()
865 {
875 {
866 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
876 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
867 updateDerivativeData();
877 updateDerivativeData();
868 }
878 }
869
879
870 void QPieSeriesPrivate::sliceClicked()
880 void QPieSeriesPrivate::sliceClicked()
871 {
881 {
872 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
882 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
873 Q_ASSERT(m_slices.contains(slice));
883 Q_ASSERT(m_slices.contains(slice));
874 Q_Q(QPieSeries);
884 Q_Q(QPieSeries);
875 emit q->clicked(slice);
885 emit q->clicked(slice);
876 }
886 }
877
887
878 void QPieSeriesPrivate::sliceHovered(bool state)
888 void QPieSeriesPrivate::sliceHovered(bool state)
879 {
889 {
880 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
890 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
881 if (!m_slices.isEmpty()) {
891 if (!m_slices.isEmpty()) {
882 Q_ASSERT(m_slices.contains(slice));
892 Q_ASSERT(m_slices.contains(slice));
883 Q_Q(QPieSeries);
893 Q_Q(QPieSeries);
884 emit q->hovered(slice, state);
894 emit q->hovered(slice, state);
885 }
895 }
886 }
896 }
887
897
888 void QPieSeriesPrivate::slicePressed()
898 void QPieSeriesPrivate::slicePressed()
889 {
899 {
890 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
900 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
891 Q_ASSERT(m_slices.contains(slice));
901 Q_ASSERT(m_slices.contains(slice));
892 Q_Q(QPieSeries);
902 Q_Q(QPieSeries);
893 emit q->pressed(slice);
903 emit q->pressed(slice);
894 }
904 }
895
905
896 void QPieSeriesPrivate::sliceReleased()
906 void QPieSeriesPrivate::sliceReleased()
897 {
907 {
898 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
908 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
899 Q_ASSERT(m_slices.contains(slice));
909 Q_ASSERT(m_slices.contains(slice));
900 Q_Q(QPieSeries);
910 Q_Q(QPieSeries);
901 emit q->released(slice);
911 emit q->released(slice);
902 }
912 }
903
913
904 void QPieSeriesPrivate::sliceDoubleClicked()
914 void QPieSeriesPrivate::sliceDoubleClicked()
905 {
915 {
906 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
916 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
907 Q_ASSERT(m_slices.contains(slice));
917 Q_ASSERT(m_slices.contains(slice));
908 Q_Q(QPieSeries);
918 Q_Q(QPieSeries);
909 emit q->doubleClicked(slice);
919 emit q->doubleClicked(slice);
910 }
920 }
911
921
912 void QPieSeriesPrivate::initializeDomain()
922 void QPieSeriesPrivate::initializeDomain()
913 {
923 {
914 // does not apply to pie
924 // does not apply to pie
915 }
925 }
916
926
917 void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
927 void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
918 {
928 {
919 Q_Q(QPieSeries);
929 Q_Q(QPieSeries);
920 PieChartItem *pie = new PieChartItem(q,parent);
930 PieChartItem *pie = new PieChartItem(q,parent);
921 m_item.reset(pie);
931 m_item.reset(pie);
922 QAbstractSeriesPrivate::initializeGraphics(parent);
932 QAbstractSeriesPrivate::initializeGraphics(parent);
923 }
933 }
924
934
925 void QPieSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options)
935 void QPieSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options)
926 {
936 {
927 PieChartItem *item = static_cast<PieChartItem *>(m_item.data());
937 PieChartItem *item = static_cast<PieChartItem *>(m_item.data());
928 Q_ASSERT(item);
938 Q_ASSERT(item);
929 if (item->animation())
939 if (item->animation())
930 item->animation()->stopAndDestroyLater();
940 item->animation()->stopAndDestroyLater();
931
941
932 if (options.testFlag(QChart::SeriesAnimations))
942 if (options.testFlag(QChart::SeriesAnimations))
933 item->setAnimation(new PieAnimation(item));
943 item->setAnimation(new PieAnimation(item));
934 else
944 else
935 item->setAnimation(0);
945 item->setAnimation(0);
936 QAbstractSeriesPrivate::initializeAnimations(options);
946 QAbstractSeriesPrivate::initializeAnimations(options);
937 }
947 }
938
948
939 QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend)
949 QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend)
940 {
950 {
941 Q_Q(QPieSeries);
951 Q_Q(QPieSeries);
942 QList<QLegendMarker*> markers;
952 QList<QLegendMarker*> markers;
943 foreach(QPieSlice* slice, q->slices()) {
953 foreach(QPieSlice* slice, q->slices()) {
944 QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend);
954 QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend);
945 markers << marker;
955 markers << marker;
946 }
956 }
947 return markers;
957 return markers;
948 }
958 }
949
959
950 void QPieSeriesPrivate::initializeAxes()
960 void QPieSeriesPrivate::initializeAxes()
951 {
961 {
952
962
953 }
963 }
954
964
955 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
965 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
956 {
966 {
957 Q_UNUSED(orientation);
967 Q_UNUSED(orientation);
958 return QAbstractAxis::AxisTypeNoAxis;
968 return QAbstractAxis::AxisTypeNoAxis;
959 }
969 }
960
970
961 QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
971 QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
962 {
972 {
963 Q_UNUSED(orientation);
973 Q_UNUSED(orientation);
964 return 0;
974 return 0;
965 }
975 }
966
976
967 void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
977 void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
968 {
978 {
969 //Q_Q(QPieSeries);
979 //Q_Q(QPieSeries);
970 //const QList<QColor>& colors = theme->seriesColors();
980 //const QList<QColor>& colors = theme->seriesColors();
971 const QList<QGradient>& gradients = theme->seriesGradients();
981 const QList<QGradient>& gradients = theme->seriesGradients();
972
982
973 for (int i(0); i < m_slices.count(); i++) {
983 for (int i(0); i < m_slices.count(); i++) {
974
984
975 QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
985 QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
976
986
977 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
987 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
978 qreal pos = (qreal)(i + 1) / (qreal) m_slices.count();
988 qreal pos = (qreal)(i + 1) / (qreal) m_slices.count();
979 QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos);
989 QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos);
980
990
981 QPieSlice *s = m_slices.at(i);
991 QPieSlice *s = m_slices.at(i);
982 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
992 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
983
993
984 if (forced || d->m_data.m_slicePen.isThemed())
994 if (forced || d->m_data.m_slicePen.isThemed())
985 d->setPen(penColor, true);
995 d->setPen(penColor, true);
986
996
987 if (forced || d->m_data.m_sliceBrush.isThemed())
997 if (forced || d->m_data.m_sliceBrush.isThemed())
988 d->setBrush(brushColor, true);
998 d->setBrush(brushColor, true);
989
999
990 if (forced || d->m_data.m_labelBrush.isThemed())
1000 if (forced || d->m_data.m_labelBrush.isThemed())
991 d->setLabelBrush(theme->labelBrush().color(), true);
1001 d->setLabelBrush(theme->labelBrush().color(), true);
992
1002
993 if (forced || d->m_data.m_labelFont.isThemed())
1003 if (forced || d->m_data.m_labelFont.isThemed())
994 d->setLabelFont(theme->labelFont(), true);
1004 d->setLabelFont(theme->labelFont(), true);
995 }
1005 }
996 }
1006 }
997
1007
998
1008
999 #include "moc_qpieseries.cpp"
1009 #include "moc_qpieseries.cpp"
1000 #include "moc_qpieseries_p.cpp"
1010 #include "moc_qpieseries_p.cpp"
1001
1011
1002 QT_CHARTS_END_NAMESPACE
1012 QT_CHARTS_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now