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