@@ -1,872 +1,897 | |||||
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 | Takes a single \a slice from the series. Does not destroy the slice object. | |||
|
515 | ||||
|
516 | NOTE: The series remains as the slice's parent object. You must set the | |||
|
517 | parent object to take full ownership. | |||
|
518 | ||||
|
519 | Returns true if take was successfull. | |||
|
520 | */ | |||
|
521 | bool QPieSeries::take(QPieSlice* slice) | |||
|
522 | { | |||
|
523 | Q_D(QPieSeries); | |||
|
524 | ||||
|
525 | if (!d->m_slices.removeOne(slice)) | |||
|
526 | return false; | |||
|
527 | ||||
|
528 | QPieSlicePrivate::fromSlice(slice)->m_series = 0; | |||
|
529 | ||||
|
530 | d->updateDerivativeData(); | |||
|
531 | ||||
|
532 | emit removed(QList<QPieSlice*>() << slice); | |||
|
533 | emit countChanged(); | |||
|
534 | ||||
|
535 | return true; | |||
|
536 | } | |||
|
537 | ||||
|
538 | /*! | |||
514 | Clears all slices from the series. |
|
539 | Clears all slices from the series. | |
515 | */ |
|
540 | */ | |
516 | void QPieSeries::clear() |
|
541 | void QPieSeries::clear() | |
517 | { |
|
542 | { | |
518 | Q_D(QPieSeries); |
|
543 | Q_D(QPieSeries); | |
519 | if (d->m_slices.count() == 0) |
|
544 | if (d->m_slices.count() == 0) | |
520 | return; |
|
545 | return; | |
521 |
|
546 | |||
522 | QList<QPieSlice*> slices = d->m_slices; |
|
547 | QList<QPieSlice*> slices = d->m_slices; | |
523 | foreach (QPieSlice* s, d->m_slices) { |
|
548 | foreach (QPieSlice* s, d->m_slices) { | |
524 | d->m_slices.removeOne(s); |
|
549 | d->m_slices.removeOne(s); | |
525 | delete s; |
|
550 | delete s; | |
526 | } |
|
551 | } | |
527 |
|
552 | |||
528 | d->updateDerivativeData(); |
|
553 | d->updateDerivativeData(); | |
529 |
|
554 | |||
530 | emit removed(slices); |
|
555 | emit removed(slices); | |
531 | emit countChanged(); |
|
556 | emit countChanged(); | |
532 | } |
|
557 | } | |
533 |
|
558 | |||
534 | /*! |
|
559 | /*! | |
535 | Returns a list of slices that belong to this series. |
|
560 | Returns a list of slices that belong to this series. | |
536 | */ |
|
561 | */ | |
537 | QList<QPieSlice*> QPieSeries::slices() const |
|
562 | QList<QPieSlice*> QPieSeries::slices() const | |
538 | { |
|
563 | { | |
539 | Q_D(const QPieSeries); |
|
564 | Q_D(const QPieSeries); | |
540 | return d->m_slices; |
|
565 | return d->m_slices; | |
541 | } |
|
566 | } | |
542 |
|
567 | |||
543 | /*! |
|
568 | /*! | |
544 | returns the number of the slices in this series. |
|
569 | returns the number of the slices in this series. | |
545 | */ |
|
570 | */ | |
546 | int QPieSeries::count() const |
|
571 | int QPieSeries::count() const | |
547 | { |
|
572 | { | |
548 | Q_D(const QPieSeries); |
|
573 | Q_D(const QPieSeries); | |
549 | return d->m_slices.count(); |
|
574 | return d->m_slices.count(); | |
550 | } |
|
575 | } | |
551 |
|
576 | |||
552 | /*! |
|
577 | /*! | |
553 | Returns true is the series is empty. |
|
578 | Returns true is the series is empty. | |
554 | */ |
|
579 | */ | |
555 | bool QPieSeries::isEmpty() const |
|
580 | bool QPieSeries::isEmpty() const | |
556 | { |
|
581 | { | |
557 | Q_D(const QPieSeries); |
|
582 | Q_D(const QPieSeries); | |
558 | return d->m_slices.isEmpty(); |
|
583 | return d->m_slices.isEmpty(); | |
559 | } |
|
584 | } | |
560 |
|
585 | |||
561 | /*! |
|
586 | /*! | |
562 | Returns the sum of all slice values in this series. |
|
587 | Returns the sum of all slice values in this series. | |
563 |
|
588 | |||
564 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
589 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() | |
565 | */ |
|
590 | */ | |
566 | qreal QPieSeries::sum() const |
|
591 | qreal QPieSeries::sum() const | |
567 | { |
|
592 | { | |
568 | Q_D(const QPieSeries); |
|
593 | Q_D(const QPieSeries); | |
569 | return d->m_sum; |
|
594 | return d->m_sum; | |
570 | } |
|
595 | } | |
571 |
|
596 | |||
572 | void QPieSeries::setDonut(bool donut) |
|
597 | void QPieSeries::setDonut(bool donut) | |
573 | { |
|
598 | { | |
574 | Q_D(QPieSeries); |
|
599 | Q_D(QPieSeries); | |
575 | d->m_donutChart = donut; |
|
600 | d->m_donutChart = donut; | |
576 | d->updateDerivativeData(); |
|
601 | d->updateDerivativeData(); | |
577 | } |
|
602 | } | |
578 |
|
603 | |||
579 | bool QPieSeries::donut() const |
|
604 | bool QPieSeries::donut() const | |
580 | { |
|
605 | { | |
581 | Q_D(const QPieSeries); |
|
606 | Q_D(const QPieSeries); | |
582 | return d->m_donutChart; |
|
607 | return d->m_donutChart; | |
583 | } |
|
608 | } | |
584 |
|
609 | |||
585 | void QPieSeries::setDonutInnerSize(qreal innerSize) |
|
610 | void QPieSeries::setDonutInnerSize(qreal innerSize) | |
586 | { |
|
611 | { | |
587 | Q_D(QPieSeries); |
|
612 | Q_D(QPieSeries); | |
588 | innerSize = qBound((qreal)0.0, innerSize, (qreal)1.0); |
|
613 | innerSize = qBound((qreal)0.0, innerSize, (qreal)1.0); | |
589 | d->setSizes(innerSize, qMax(d->m_pieRelativeSize, innerSize)); |
|
614 | d->setSizes(innerSize, qMax(d->m_pieRelativeSize, innerSize)); | |
590 | } |
|
615 | } | |
591 |
|
616 | |||
592 | qreal QPieSeries::donutInnerSize() const |
|
617 | qreal QPieSeries::donutInnerSize() const | |
593 | { |
|
618 | { | |
594 | Q_D(const QPieSeries); |
|
619 | Q_D(const QPieSeries); | |
595 | return d->m_donutRelativeInnerSize; |
|
620 | return d->m_donutRelativeInnerSize; | |
596 | } |
|
621 | } | |
597 |
|
622 | |||
598 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
623 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
599 | { |
|
624 | { | |
600 | Q_D(QPieSeries); |
|
625 | Q_D(QPieSeries); | |
601 |
|
626 | |||
602 | if (relativePosition < 0.0) |
|
627 | if (relativePosition < 0.0) | |
603 | relativePosition = 0.0; |
|
628 | relativePosition = 0.0; | |
604 | if (relativePosition > 1.0) |
|
629 | if (relativePosition > 1.0) | |
605 | relativePosition = 1.0; |
|
630 | relativePosition = 1.0; | |
606 |
|
631 | |||
607 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { |
|
632 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { | |
608 | d->m_pieRelativeHorPos = relativePosition; |
|
633 | d->m_pieRelativeHorPos = relativePosition; | |
609 | emit d->horizontalPositionChanged(); |
|
634 | emit d->horizontalPositionChanged(); | |
610 | } |
|
635 | } | |
611 | } |
|
636 | } | |
612 |
|
637 | |||
613 | qreal QPieSeries::horizontalPosition() const |
|
638 | qreal QPieSeries::horizontalPosition() const | |
614 | { |
|
639 | { | |
615 | Q_D(const QPieSeries); |
|
640 | Q_D(const QPieSeries); | |
616 | return d->m_pieRelativeHorPos; |
|
641 | return d->m_pieRelativeHorPos; | |
617 | } |
|
642 | } | |
618 |
|
643 | |||
619 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
644 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
620 | { |
|
645 | { | |
621 | Q_D(QPieSeries); |
|
646 | Q_D(QPieSeries); | |
622 |
|
647 | |||
623 | if (relativePosition < 0.0) |
|
648 | if (relativePosition < 0.0) | |
624 | relativePosition = 0.0; |
|
649 | relativePosition = 0.0; | |
625 | if (relativePosition > 1.0) |
|
650 | if (relativePosition > 1.0) | |
626 | relativePosition = 1.0; |
|
651 | relativePosition = 1.0; | |
627 |
|
652 | |||
628 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { |
|
653 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { | |
629 | d->m_pieRelativeVerPos = relativePosition; |
|
654 | d->m_pieRelativeVerPos = relativePosition; | |
630 | emit d->verticalPositionChanged(); |
|
655 | emit d->verticalPositionChanged(); | |
631 | } |
|
656 | } | |
632 | } |
|
657 | } | |
633 |
|
658 | |||
634 | qreal QPieSeries::verticalPosition() const |
|
659 | qreal QPieSeries::verticalPosition() const | |
635 | { |
|
660 | { | |
636 | Q_D(const QPieSeries); |
|
661 | Q_D(const QPieSeries); | |
637 | return d->m_pieRelativeVerPos; |
|
662 | return d->m_pieRelativeVerPos; | |
638 | } |
|
663 | } | |
639 |
|
664 | |||
640 | void QPieSeries::setPieSize(qreal relativeSize) |
|
665 | void QPieSeries::setPieSize(qreal relativeSize) | |
641 | { |
|
666 | { | |
642 | Q_D(QPieSeries); |
|
667 | Q_D(QPieSeries); | |
643 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); |
|
668 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); | |
644 | d->setSizes(qMin(d->m_donutRelativeInnerSize, relativeSize), relativeSize); |
|
669 | d->setSizes(qMin(d->m_donutRelativeInnerSize, relativeSize), relativeSize); | |
645 |
|
670 | |||
646 | } |
|
671 | } | |
647 |
|
672 | |||
648 | qreal QPieSeries::pieSize() const |
|
673 | qreal QPieSeries::pieSize() const | |
649 | { |
|
674 | { | |
650 | Q_D(const QPieSeries); |
|
675 | Q_D(const QPieSeries); | |
651 | return d->m_pieRelativeSize; |
|
676 | return d->m_pieRelativeSize; | |
652 | } |
|
677 | } | |
653 |
|
678 | |||
654 |
|
679 | |||
655 | void QPieSeries::setPieStartAngle(qreal angle) |
|
680 | void QPieSeries::setPieStartAngle(qreal angle) | |
656 | { |
|
681 | { | |
657 | Q_D(QPieSeries); |
|
682 | Q_D(QPieSeries); | |
658 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) |
|
683 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) | |
659 | return; |
|
684 | return; | |
660 | d->m_pieStartAngle = angle; |
|
685 | d->m_pieStartAngle = angle; | |
661 | d->updateDerivativeData(); |
|
686 | d->updateDerivativeData(); | |
662 | emit d->pieStartAngleChanged(); |
|
687 | emit d->pieStartAngleChanged(); | |
663 | } |
|
688 | } | |
664 |
|
689 | |||
665 | qreal QPieSeries::pieStartAngle() const |
|
690 | qreal QPieSeries::pieStartAngle() const | |
666 | { |
|
691 | { | |
667 | Q_D(const QPieSeries); |
|
692 | Q_D(const QPieSeries); | |
668 | return d->m_pieStartAngle; |
|
693 | return d->m_pieStartAngle; | |
669 | } |
|
694 | } | |
670 |
|
695 | |||
671 | /*! |
|
696 | /*! | |
672 | Sets the end angle of the pie. |
|
697 | Sets the end angle of the pie. | |
673 |
|
698 | |||
674 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
699 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
675 |
|
700 | |||
676 | \a angle must be greater than start angle. |
|
701 | \a angle must be greater than start angle. | |
677 |
|
702 | |||
678 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
703 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
679 | */ |
|
704 | */ | |
680 | void QPieSeries::setPieEndAngle(qreal angle) |
|
705 | void QPieSeries::setPieEndAngle(qreal angle) | |
681 | { |
|
706 | { | |
682 | Q_D(QPieSeries); |
|
707 | Q_D(QPieSeries); | |
683 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) |
|
708 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) | |
684 | return; |
|
709 | return; | |
685 | d->m_pieEndAngle = angle; |
|
710 | d->m_pieEndAngle = angle; | |
686 | d->updateDerivativeData(); |
|
711 | d->updateDerivativeData(); | |
687 | emit d->pieEndAngleChanged(); |
|
712 | emit d->pieEndAngleChanged(); | |
688 | } |
|
713 | } | |
689 |
|
714 | |||
690 | /*! |
|
715 | /*! | |
691 | Returns the end angle of the pie. |
|
716 | Returns the end angle of the pie. | |
692 |
|
717 | |||
693 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
718 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
694 |
|
719 | |||
695 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
720 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
696 | */ |
|
721 | */ | |
697 | qreal QPieSeries::pieEndAngle() const |
|
722 | qreal QPieSeries::pieEndAngle() const | |
698 | { |
|
723 | { | |
699 | Q_D(const QPieSeries); |
|
724 | Q_D(const QPieSeries); | |
700 | return d->m_pieEndAngle; |
|
725 | return d->m_pieEndAngle; | |
701 | } |
|
726 | } | |
702 |
|
727 | |||
703 | /*! |
|
728 | /*! | |
704 | Sets the all the slice labels \a visible or invisible. |
|
729 | Sets the all the slice labels \a visible or invisible. | |
705 |
|
730 | |||
706 | Note that this affects only the current slices in the series. |
|
731 | Note that this affects only the current slices in the series. | |
707 | If user adds a new slice the default label visibility is false. |
|
732 | If user adds a new slice the default label visibility is false. | |
708 |
|
733 | |||
709 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
734 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
710 | */ |
|
735 | */ | |
711 | void QPieSeries::setLabelsVisible(bool visible) |
|
736 | void QPieSeries::setLabelsVisible(bool visible) | |
712 | { |
|
737 | { | |
713 | Q_D(QPieSeries); |
|
738 | Q_D(QPieSeries); | |
714 | foreach (QPieSlice* s, d->m_slices) |
|
739 | foreach (QPieSlice* s, d->m_slices) | |
715 | s->setLabelVisible(visible); |
|
740 | s->setLabelVisible(visible); | |
716 | } |
|
741 | } | |
717 |
|
742 | |||
718 | /*! |
|
743 | /*! | |
719 | Sets the all the slice labels \a position |
|
744 | Sets the all the slice labels \a position | |
720 |
|
745 | |||
721 | Note that this affects only the current slices in the series. |
|
746 | Note that this affects only the current slices in the series. | |
722 | If user adds a new slice the default label position is LabelOutside |
|
747 | If user adds a new slice the default label position is LabelOutside | |
723 |
|
748 | |||
724 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() |
|
749 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() | |
725 | */ |
|
750 | */ | |
726 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) |
|
751 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) | |
727 | { |
|
752 | { | |
728 | Q_D(QPieSeries); |
|
753 | Q_D(QPieSeries); | |
729 | foreach (QPieSlice* s, d->m_slices) |
|
754 | foreach (QPieSlice* s, d->m_slices) | |
730 | s->setLabelPosition(position); |
|
755 | s->setLabelPosition(position); | |
731 | } |
|
756 | } | |
732 |
|
757 | |||
733 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
758 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
734 |
|
759 | |||
735 |
|
760 | |||
736 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
761 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | |
737 | QAbstractSeriesPrivate(parent), |
|
762 | QAbstractSeriesPrivate(parent), | |
738 | m_pieRelativeHorPos(0.5), |
|
763 | m_pieRelativeHorPos(0.5), | |
739 | m_pieRelativeVerPos(0.5), |
|
764 | m_pieRelativeVerPos(0.5), | |
740 | m_pieRelativeSize(0.7), |
|
765 | m_pieRelativeSize(0.7), | |
741 | m_pieStartAngle(0), |
|
766 | m_pieStartAngle(0), | |
742 | m_pieEndAngle(360), |
|
767 | m_pieEndAngle(360), | |
743 | m_sum(0), |
|
768 | m_sum(0), | |
744 | m_donutChart(false), |
|
769 | m_donutChart(false), | |
745 | m_donutRelativeInnerSize(0.5) |
|
770 | m_donutRelativeInnerSize(0.5) | |
746 | { |
|
771 | { | |
747 | } |
|
772 | } | |
748 |
|
773 | |||
749 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
774 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
750 | { |
|
775 | { | |
751 | } |
|
776 | } | |
752 |
|
777 | |||
753 | void QPieSeriesPrivate::updateDerivativeData() |
|
778 | void QPieSeriesPrivate::updateDerivativeData() | |
754 | { |
|
779 | { | |
755 | // calculate sum of all slices |
|
780 | // calculate sum of all slices | |
756 | qreal sum = 0; |
|
781 | qreal sum = 0; | |
757 | foreach (QPieSlice* s, m_slices) |
|
782 | foreach (QPieSlice* s, m_slices) | |
758 | sum += s->value(); |
|
783 | sum += s->value(); | |
759 |
|
784 | |||
760 | if (!qFuzzyIsNull(m_sum - sum)) { |
|
785 | if (!qFuzzyIsNull(m_sum - sum)) { | |
761 | m_sum = sum; |
|
786 | m_sum = sum; | |
762 | emit q_func()->sumChanged(); |
|
787 | emit q_func()->sumChanged(); | |
763 | } |
|
788 | } | |
764 |
|
789 | |||
765 | // nothing to show.. |
|
790 | // nothing to show.. | |
766 | if (qFuzzyIsNull(m_sum)) |
|
791 | if (qFuzzyIsNull(m_sum)) | |
767 | return; |
|
792 | return; | |
768 |
|
793 | |||
769 | // update slice attributes |
|
794 | // update slice attributes | |
770 | qreal sliceAngle = m_pieStartAngle; |
|
795 | qreal sliceAngle = m_pieStartAngle; | |
771 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
796 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
772 | QVector<QPieSlice*> changed; |
|
797 | QVector<QPieSlice*> changed; | |
773 | foreach (QPieSlice* s, m_slices) { |
|
798 | foreach (QPieSlice* s, m_slices) { | |
774 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
799 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
775 | d->setPercentage(s->value() / m_sum); |
|
800 | d->setPercentage(s->value() / m_sum); | |
776 | d->setStartAngle(sliceAngle); |
|
801 | d->setStartAngle(sliceAngle); | |
777 | d->setAngleSpan(pieSpan * s->percentage()); |
|
802 | d->setAngleSpan(pieSpan * s->percentage()); | |
778 | sliceAngle += s->angleSpan(); |
|
803 | sliceAngle += s->angleSpan(); | |
779 | } |
|
804 | } | |
780 |
|
805 | |||
781 |
|
806 | |||
782 | emit calculatedDataChanged(); |
|
807 | emit calculatedDataChanged(); | |
783 | } |
|
808 | } | |
784 |
|
809 | |||
785 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) |
|
810 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) | |
786 | { |
|
811 | { | |
787 | bool changed = false; |
|
812 | bool changed = false; | |
788 |
|
813 | |||
789 | if (!qFuzzyIsNull(m_donutRelativeInnerSize - innerSize)) { |
|
814 | if (!qFuzzyIsNull(m_donutRelativeInnerSize - innerSize)) { | |
790 | m_donutRelativeInnerSize = innerSize; |
|
815 | m_donutRelativeInnerSize = innerSize; | |
791 | changed = true; |
|
816 | changed = true; | |
792 | } |
|
817 | } | |
793 |
|
818 | |||
794 | if (!qFuzzyIsNull(m_pieRelativeSize - outerSize)) { |
|
819 | if (!qFuzzyIsNull(m_pieRelativeSize - outerSize)) { | |
795 | m_pieRelativeSize = outerSize; |
|
820 | m_pieRelativeSize = outerSize; | |
796 | changed = true; |
|
821 | changed = true; | |
797 | } |
|
822 | } | |
798 |
|
823 | |||
799 | if (changed) |
|
824 | if (changed) | |
800 | emit pieSizeChanged(); |
|
825 | emit pieSizeChanged(); | |
801 | } |
|
826 | } | |
802 |
|
827 | |||
803 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
828 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) | |
804 | { |
|
829 | { | |
805 | return series->d_func(); |
|
830 | return series->d_func(); | |
806 | } |
|
831 | } | |
807 |
|
832 | |||
808 | void QPieSeriesPrivate::sliceValueChanged() |
|
833 | void QPieSeriesPrivate::sliceValueChanged() | |
809 | { |
|
834 | { | |
810 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
835 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
811 | updateDerivativeData(); |
|
836 | updateDerivativeData(); | |
812 | } |
|
837 | } | |
813 |
|
838 | |||
814 | void QPieSeriesPrivate::sliceClicked() |
|
839 | void QPieSeriesPrivate::sliceClicked() | |
815 | { |
|
840 | { | |
816 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
841 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
817 | Q_ASSERT(m_slices.contains(slice)); |
|
842 | Q_ASSERT(m_slices.contains(slice)); | |
818 | Q_Q(QPieSeries); |
|
843 | Q_Q(QPieSeries); | |
819 | emit q->clicked(slice); |
|
844 | emit q->clicked(slice); | |
820 | } |
|
845 | } | |
821 |
|
846 | |||
822 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
847 | void QPieSeriesPrivate::sliceHovered(bool state) | |
823 | { |
|
848 | { | |
824 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
849 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
825 | Q_ASSERT(m_slices.contains(slice)); |
|
850 | Q_ASSERT(m_slices.contains(slice)); | |
826 | Q_Q(QPieSeries); |
|
851 | Q_Q(QPieSeries); | |
827 | emit q->hovered(slice, state); |
|
852 | emit q->hovered(slice, state); | |
828 | } |
|
853 | } | |
829 |
|
854 | |||
830 | void QPieSeriesPrivate::scaleDomain(Domain& domain) |
|
855 | void QPieSeriesPrivate::scaleDomain(Domain& domain) | |
831 | { |
|
856 | { | |
832 | Q_UNUSED(domain); |
|
857 | Q_UNUSED(domain); | |
833 | // does not apply to pie |
|
858 | // does not apply to pie | |
834 | } |
|
859 | } | |
835 |
|
860 | |||
836 | ChartElement* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
861 | ChartElement* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
837 | { |
|
862 | { | |
838 | Q_Q(QPieSeries); |
|
863 | Q_Q(QPieSeries); | |
839 | PieChartItem* pie = new PieChartItem(q,presenter); |
|
864 | PieChartItem* pie = new PieChartItem(q,presenter); | |
840 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
865 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
841 | pie->setAnimation(new PieAnimation(pie)); |
|
866 | pie->setAnimation(new PieAnimation(pie)); | |
842 | } |
|
867 | } | |
843 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
868 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
844 | return pie; |
|
869 | return pie; | |
845 | } |
|
870 | } | |
846 |
|
871 | |||
847 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) |
|
872 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) | |
848 | { |
|
873 | { | |
849 | Q_Q(QPieSeries); |
|
874 | Q_Q(QPieSeries); | |
850 | QList<LegendMarker*> markers; |
|
875 | QList<LegendMarker*> markers; | |
851 | foreach(QPieSlice* slice, q->slices()) { |
|
876 | foreach(QPieSlice* slice, q->slices()) { | |
852 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); |
|
877 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); | |
853 | markers << marker; |
|
878 | markers << marker; | |
854 | } |
|
879 | } | |
855 | return markers; |
|
880 | return markers; | |
856 | } |
|
881 | } | |
857 |
|
882 | |||
858 | void QPieSeriesPrivate::initializeAxis(QAbstractAxis* axis) |
|
883 | void QPieSeriesPrivate::initializeAxis(QAbstractAxis* axis) | |
859 | { |
|
884 | { | |
860 | Q_UNUSED(axis); |
|
885 | Q_UNUSED(axis); | |
861 | } |
|
886 | } | |
862 |
|
887 | |||
863 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
888 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
864 | { |
|
889 | { | |
865 | Q_UNUSED(orientation); |
|
890 | Q_UNUSED(orientation); | |
866 | return QAbstractAxis::AxisTypeNoAxis; |
|
891 | return QAbstractAxis::AxisTypeNoAxis; | |
867 | } |
|
892 | } | |
868 |
|
893 | |||
869 | #include "moc_qpieseries.cpp" |
|
894 | #include "moc_qpieseries.cpp" | |
870 | #include "moc_qpieseries_p.cpp" |
|
895 | #include "moc_qpieseries_p.cpp" | |
871 |
|
896 | |||
872 | QTCOMMERCIALCHART_END_NAMESPACE |
|
897 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,106 +1,107 | |||||
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 | #ifndef PIESERIES_H |
|
21 | #ifndef PIESERIES_H | |
22 | #define PIESERIES_H |
|
22 | #define PIESERIES_H | |
23 |
|
23 | |||
24 | #include <qabstractseries.h> |
|
24 | #include <qabstractseries.h> | |
25 | #include <QPieSlice> |
|
25 | #include <QPieSlice> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 | class QPieSeriesPrivate; |
|
28 | class QPieSeriesPrivate; | |
29 | //class QPieSlice; |
|
29 | //class QPieSlice; | |
30 |
|
30 | |||
31 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QAbstractSeries |
|
31 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QAbstractSeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | Q_PROPERTY(qreal horizontalPosition READ horizontalPosition WRITE setHorizontalPosition) |
|
34 | Q_PROPERTY(qreal horizontalPosition READ horizontalPosition WRITE setHorizontalPosition) | |
35 | Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition) |
|
35 | Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition) | |
36 | Q_PROPERTY(qreal size READ pieSize WRITE setPieSize) |
|
36 | Q_PROPERTY(qreal size READ pieSize WRITE setPieSize) | |
37 | Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle) |
|
37 | Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle) | |
38 | Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle) |
|
38 | Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle) | |
39 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
39 | Q_PROPERTY(int count READ count NOTIFY countChanged) | |
40 | Q_PROPERTY(qreal sum READ sum NOTIFY sumChanged) |
|
40 | Q_PROPERTY(qreal sum READ sum NOTIFY sumChanged) | |
41 | Q_PROPERTY(qreal donutInnerSize READ donutInnerSize WRITE setDonutInnerSize) |
|
41 | Q_PROPERTY(qreal donutInnerSize READ donutInnerSize WRITE setDonutInnerSize) | |
42 | Q_PROPERTY(bool donut READ donut WRITE setDonut) |
|
42 | Q_PROPERTY(bool donut READ donut WRITE setDonut) | |
43 |
|
43 | |||
44 | public: |
|
44 | public: | |
45 | explicit QPieSeries(QObject *parent = 0); |
|
45 | explicit QPieSeries(QObject *parent = 0); | |
46 | virtual ~QPieSeries(); |
|
46 | virtual ~QPieSeries(); | |
47 |
|
47 | |||
48 | QAbstractSeries::SeriesType type() const; |
|
48 | QAbstractSeries::SeriesType type() const; | |
49 |
|
49 | |||
50 | bool append(QPieSlice* slice); |
|
50 | bool append(QPieSlice* slice); | |
51 | bool append(QList<QPieSlice*> slices); |
|
51 | bool append(QList<QPieSlice*> slices); | |
52 | QPieSeries& operator << (QPieSlice* slice); |
|
52 | QPieSeries& operator << (QPieSlice* slice); | |
53 | QPieSlice* append(QString label, qreal value); |
|
53 | QPieSlice* append(QString label, qreal value); | |
54 |
|
54 | |||
55 | bool insert(int index, QPieSlice* slice); |
|
55 | bool insert(int index, QPieSlice* slice); | |
56 |
|
56 | |||
57 | bool remove(QPieSlice* slice); |
|
57 | bool remove(QPieSlice* slice); | |
|
58 | bool take(QPieSlice* slice); | |||
58 | void clear(); |
|
59 | void clear(); | |
59 |
|
60 | |||
60 | QList<QPieSlice*> slices() const; |
|
61 | QList<QPieSlice*> slices() const; | |
61 | int count() const; |
|
62 | int count() const; | |
62 |
|
63 | |||
63 | bool isEmpty() const; |
|
64 | bool isEmpty() const; | |
64 |
|
65 | |||
65 | qreal sum() const; |
|
66 | qreal sum() const; | |
66 |
|
67 | |||
67 | void setDonut(bool donut = true); |
|
68 | void setDonut(bool donut = true); | |
68 | bool donut() const; |
|
69 | bool donut() const; | |
69 |
|
70 | |||
70 | void setDonutInnerSize(qreal innerSize); |
|
71 | void setDonutInnerSize(qreal innerSize); | |
71 | qreal donutInnerSize() const; |
|
72 | qreal donutInnerSize() const; | |
72 |
|
73 | |||
73 | void setHorizontalPosition(qreal relativePosition); |
|
74 | void setHorizontalPosition(qreal relativePosition); | |
74 | qreal horizontalPosition() const; |
|
75 | qreal horizontalPosition() const; | |
75 |
|
76 | |||
76 | void setVerticalPosition(qreal relativePosition); |
|
77 | void setVerticalPosition(qreal relativePosition); | |
77 | qreal verticalPosition() const; |
|
78 | qreal verticalPosition() const; | |
78 |
|
79 | |||
79 | void setPieSize(qreal relativeSize); |
|
80 | void setPieSize(qreal relativeSize); | |
80 | qreal pieSize() const; |
|
81 | qreal pieSize() const; | |
81 |
|
82 | |||
82 | void setPieStartAngle(qreal startAngle); |
|
83 | void setPieStartAngle(qreal startAngle); | |
83 | qreal pieStartAngle() const; |
|
84 | qreal pieStartAngle() const; | |
84 |
|
85 | |||
85 | void setPieEndAngle(qreal endAngle); |
|
86 | void setPieEndAngle(qreal endAngle); | |
86 | qreal pieEndAngle() const; |
|
87 | qreal pieEndAngle() const; | |
87 |
|
88 | |||
88 | void setLabelsVisible(bool visible = true); |
|
89 | void setLabelsVisible(bool visible = true); | |
89 | void setLabelsPosition(QPieSlice::LabelPosition position); |
|
90 | void setLabelsPosition(QPieSlice::LabelPosition position); | |
90 |
|
91 | |||
91 | Q_SIGNALS: |
|
92 | Q_SIGNALS: | |
92 | void added(QList<QPieSlice*> slices); |
|
93 | void added(QList<QPieSlice*> slices); | |
93 | void removed(QList<QPieSlice*> slices); |
|
94 | void removed(QList<QPieSlice*> slices); | |
94 | void clicked(QPieSlice* slice); |
|
95 | void clicked(QPieSlice* slice); | |
95 | void hovered(QPieSlice* slice, bool state); |
|
96 | void hovered(QPieSlice* slice, bool state); | |
96 | void countChanged(); |
|
97 | void countChanged(); | |
97 | void sumChanged(); |
|
98 | void sumChanged(); | |
98 |
|
99 | |||
99 | private: |
|
100 | private: | |
100 | Q_DECLARE_PRIVATE(QPieSeries) |
|
101 | Q_DECLARE_PRIVATE(QPieSeries) | |
101 | Q_DISABLE_COPY(QPieSeries) |
|
102 | Q_DISABLE_COPY(QPieSeries) | |
102 | }; |
|
103 | }; | |
103 |
|
104 | |||
104 | QTCOMMERCIALCHART_END_NAMESPACE |
|
105 | QTCOMMERCIALCHART_END_NAMESPACE | |
105 |
|
106 | |||
106 | #endif // PIESERIES_H |
|
107 | #endif // PIESERIES_H |
@@ -1,601 +1,640 | |||||
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 <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qchartview.h> |
|
22 | #include <qchartview.h> | |
23 | #include <qchart.h> |
|
23 | #include <qchart.h> | |
24 | #include <qpieseries.h> |
|
24 | #include <qpieseries.h> | |
25 | #include <qpieslice.h> |
|
25 | #include <qpieslice.h> | |
26 | #include <qpiemodelmapper.h> |
|
26 | #include <qpiemodelmapper.h> | |
27 | #include <QStandardItemModel> |
|
27 | #include <QStandardItemModel> | |
28 | #include <tst_definitions.h> |
|
28 | #include <tst_definitions.h> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
30 | QTCOMMERCIALCHART_USE_NAMESPACE | |
31 |
|
31 | |||
32 | Q_DECLARE_METATYPE(QPieSlice*) |
|
32 | Q_DECLARE_METATYPE(QPieSlice*) | |
33 | Q_DECLARE_METATYPE(QList<QPieSlice*>) |
|
33 | Q_DECLARE_METATYPE(QList<QPieSlice*>) | |
34 |
|
34 | |||
35 | class tst_qpieseries : public QObject |
|
35 | class tst_qpieseries : public QObject | |
36 | { |
|
36 | { | |
37 | Q_OBJECT |
|
37 | Q_OBJECT | |
38 |
|
38 | |||
39 | public slots: |
|
39 | public slots: | |
40 | void initTestCase(); |
|
40 | void initTestCase(); | |
41 | void cleanupTestCase(); |
|
41 | void cleanupTestCase(); | |
42 | void init(); |
|
42 | void init(); | |
43 | void cleanup(); |
|
43 | void cleanup(); | |
44 |
|
44 | |||
45 | private slots: |
|
45 | private slots: | |
46 | void properties(); |
|
46 | void properties(); | |
47 | void append(); |
|
47 | void append(); | |
48 | void appendAnimated(); |
|
48 | void appendAnimated(); | |
49 | void insert(); |
|
49 | void insert(); | |
50 | void insertAnimated(); |
|
50 | void insertAnimated(); | |
51 | void remove(); |
|
51 | void remove(); | |
52 | void removeAnimated(); |
|
52 | void removeAnimated(); | |
|
53 | void take(); | |||
|
54 | void takeAnimated(); | |||
53 | void calculatedValues(); |
|
55 | void calculatedValues(); | |
54 | void clickedSignal(); |
|
56 | void clickedSignal(); | |
55 | void hoverSignal(); |
|
57 | void hoverSignal(); | |
56 | void sliceSeries(); |
|
58 | void sliceSeries(); | |
57 | void destruction(); |
|
59 | void destruction(); | |
58 |
|
60 | |||
59 | private: |
|
61 | private: | |
60 | void verifyCalculatedData(const QPieSeries &series, bool *ok); |
|
62 | void verifyCalculatedData(const QPieSeries &series, bool *ok); | |
61 |
|
63 | |||
62 | private: |
|
64 | private: | |
63 | QChartView *m_view; |
|
65 | QChartView *m_view; | |
64 | QPieSeries *m_series; |
|
66 | QPieSeries *m_series; | |
65 | }; |
|
67 | }; | |
66 |
|
68 | |||
67 | void tst_qpieseries::initTestCase() |
|
69 | void tst_qpieseries::initTestCase() | |
68 | { |
|
70 | { | |
69 | qRegisterMetaType<QPieSlice*>("QPieSlice*"); |
|
71 | qRegisterMetaType<QPieSlice*>("QPieSlice*"); | |
70 | qRegisterMetaType<QList<QPieSlice*> >("QList<QPieSlice*>"); |
|
72 | qRegisterMetaType<QList<QPieSlice*> >("QList<QPieSlice*>"); | |
71 | } |
|
73 | } | |
72 |
|
74 | |||
73 | void tst_qpieseries::cleanupTestCase() |
|
75 | void tst_qpieseries::cleanupTestCase() | |
74 | { |
|
76 | { | |
75 | } |
|
77 | } | |
76 |
|
78 | |||
77 | void tst_qpieseries::init() |
|
79 | void tst_qpieseries::init() | |
78 | { |
|
80 | { | |
79 | m_view = new QChartView(); |
|
81 | m_view = new QChartView(); | |
80 | m_series = new QPieSeries(m_view); |
|
82 | m_series = new QPieSeries(m_view); | |
81 | m_view->show(); |
|
83 | m_view->show(); | |
82 | QTest::qWaitForWindowShown(m_view); |
|
84 | QTest::qWaitForWindowShown(m_view); | |
83 |
|
85 | |||
84 | } |
|
86 | } | |
85 |
|
87 | |||
86 | void tst_qpieseries::cleanup() |
|
88 | void tst_qpieseries::cleanup() | |
87 | { |
|
89 | { | |
88 | delete m_view; |
|
90 | delete m_view; | |
89 | m_view = 0; |
|
91 | m_view = 0; | |
90 | m_series = 0; |
|
92 | m_series = 0; | |
91 | } |
|
93 | } | |
92 |
|
94 | |||
93 | void tst_qpieseries::properties() |
|
95 | void tst_qpieseries::properties() | |
94 | { |
|
96 | { | |
95 | QSignalSpy countSpy(m_series, SIGNAL(countChanged())); |
|
97 | QSignalSpy countSpy(m_series, SIGNAL(countChanged())); | |
96 | QSignalSpy sumSpy(m_series, SIGNAL(sumChanged())); |
|
98 | QSignalSpy sumSpy(m_series, SIGNAL(sumChanged())); | |
97 |
|
99 | |||
98 | QVERIFY(m_series->type() == QAbstractSeries::SeriesTypePie); |
|
100 | QVERIFY(m_series->type() == QAbstractSeries::SeriesTypePie); | |
99 | QVERIFY(m_series->count() == 0); |
|
101 | QVERIFY(m_series->count() == 0); | |
100 | QVERIFY(m_series->isEmpty()); |
|
102 | QVERIFY(m_series->isEmpty()); | |
101 | QCOMPARE(m_series->sum(), 0.0); |
|
103 | QCOMPARE(m_series->sum(), 0.0); | |
102 | QCOMPARE(m_series->horizontalPosition(), 0.5); |
|
104 | QCOMPARE(m_series->horizontalPosition(), 0.5); | |
103 | QCOMPARE(m_series->verticalPosition(), 0.5); |
|
105 | QCOMPARE(m_series->verticalPosition(), 0.5); | |
104 | QCOMPARE(m_series->pieSize(), 0.7); |
|
106 | QCOMPARE(m_series->pieSize(), 0.7); | |
105 | QCOMPARE(m_series->pieStartAngle(), 0.0); |
|
107 | QCOMPARE(m_series->pieStartAngle(), 0.0); | |
106 | QCOMPARE(m_series->pieEndAngle(), 360.0); |
|
108 | QCOMPARE(m_series->pieEndAngle(), 360.0); | |
107 |
|
109 | |||
108 | m_series->append("s1", 1); |
|
110 | m_series->append("s1", 1); | |
109 | m_series->append("s2", 1); |
|
111 | m_series->append("s2", 1); | |
110 | m_series->append("s3", 1); |
|
112 | m_series->append("s3", 1); | |
111 | m_series->insert(1, new QPieSlice("s4", 1)); |
|
113 | m_series->insert(1, new QPieSlice("s4", 1)); | |
112 | m_series->remove(m_series->slices().first()); |
|
114 | m_series->remove(m_series->slices().first()); | |
113 | QCOMPARE(m_series->count(), 3); |
|
115 | QCOMPARE(m_series->count(), 3); | |
114 | QCOMPARE(m_series->sum(), 3.0); |
|
116 | QCOMPARE(m_series->sum(), 3.0); | |
115 | m_series->clear(); |
|
117 | m_series->clear(); | |
116 | QCOMPARE(m_series->count(), 0); |
|
118 | QCOMPARE(m_series->count(), 0); | |
117 | QCOMPARE(m_series->sum(), 0.0); |
|
119 | QCOMPARE(m_series->sum(), 0.0); | |
118 | QCOMPARE(countSpy.count(), 6); |
|
120 | QCOMPARE(countSpy.count(), 6); | |
119 | QCOMPARE(sumSpy.count(), 6); |
|
121 | QCOMPARE(sumSpy.count(), 6); | |
120 |
|
122 | |||
121 | m_series->setPieSize(-1.0); |
|
123 | m_series->setPieSize(-1.0); | |
122 | QCOMPARE(m_series->pieSize(), 0.0); |
|
124 | QCOMPARE(m_series->pieSize(), 0.0); | |
123 | m_series->setPieSize(0.0); |
|
125 | m_series->setPieSize(0.0); | |
124 | m_series->setPieSize(0.9); |
|
126 | m_series->setPieSize(0.9); | |
125 | m_series->setPieSize(2.0); |
|
127 | m_series->setPieSize(2.0); | |
126 | QCOMPARE(m_series->pieSize(), 1.0); |
|
128 | QCOMPARE(m_series->pieSize(), 1.0); | |
127 |
|
129 | |||
128 | m_series->setPieSize(0.7); |
|
130 | m_series->setPieSize(0.7); | |
129 | QCOMPARE(m_series->pieSize(), 0.7); |
|
131 | QCOMPARE(m_series->pieSize(), 0.7); | |
130 | m_series->setDonut(); |
|
132 | m_series->setDonut(); | |
131 | QVERIFY(m_series->donut()); |
|
133 | QVERIFY(m_series->donut()); | |
132 |
|
134 | |||
133 | m_series->setDonutInnerSize(-1.0); |
|
135 | m_series->setDonutInnerSize(-1.0); | |
134 | QCOMPARE(m_series->donutInnerSize(), 0.0); |
|
136 | QCOMPARE(m_series->donutInnerSize(), 0.0); | |
135 | m_series->setDonutInnerSize(0.5); |
|
137 | m_series->setDonutInnerSize(0.5); | |
136 | QCOMPARE(m_series->donutInnerSize(), 0.5); |
|
138 | QCOMPARE(m_series->donutInnerSize(), 0.5); | |
137 |
|
139 | |||
138 | m_series->setDonutInnerSize(0.8); |
|
140 | m_series->setDonutInnerSize(0.8); | |
139 | QCOMPARE(m_series->donutInnerSize(), 0.8); |
|
141 | QCOMPARE(m_series->donutInnerSize(), 0.8); | |
140 | QCOMPARE(m_series->pieSize(), 0.8); |
|
142 | QCOMPARE(m_series->pieSize(), 0.8); | |
141 |
|
143 | |||
142 | m_series->setPieSize(0.4); |
|
144 | m_series->setPieSize(0.4); | |
143 | QCOMPARE(m_series->pieSize(), 0.4); |
|
145 | QCOMPARE(m_series->pieSize(), 0.4); | |
144 | QCOMPARE(m_series->donutInnerSize(), 0.4); |
|
146 | QCOMPARE(m_series->donutInnerSize(), 0.4); | |
145 |
|
147 | |||
146 | m_series->setPieStartAngle(0); |
|
148 | m_series->setPieStartAngle(0); | |
147 | m_series->setPieStartAngle(-180); |
|
149 | m_series->setPieStartAngle(-180); | |
148 | m_series->setPieStartAngle(180); |
|
150 | m_series->setPieStartAngle(180); | |
149 | QCOMPARE(m_series->pieStartAngle(), 180.0); |
|
151 | QCOMPARE(m_series->pieStartAngle(), 180.0); | |
150 |
|
152 | |||
151 | m_series->setPieEndAngle(360); |
|
153 | m_series->setPieEndAngle(360); | |
152 | m_series->setPieEndAngle(-180); |
|
154 | m_series->setPieEndAngle(-180); | |
153 | m_series->setPieEndAngle(180); |
|
155 | m_series->setPieEndAngle(180); | |
154 | QCOMPARE(m_series->pieEndAngle(), 180.0); |
|
156 | QCOMPARE(m_series->pieEndAngle(), 180.0); | |
155 |
|
157 | |||
156 | m_series->setHorizontalPosition(0.5); |
|
158 | m_series->setHorizontalPosition(0.5); | |
157 | m_series->setHorizontalPosition(-1.0); |
|
159 | m_series->setHorizontalPosition(-1.0); | |
158 | QCOMPARE(m_series->horizontalPosition(), 0.0); |
|
160 | QCOMPARE(m_series->horizontalPosition(), 0.0); | |
159 | m_series->setHorizontalPosition(1.0); |
|
161 | m_series->setHorizontalPosition(1.0); | |
160 | m_series->setHorizontalPosition(2.0); |
|
162 | m_series->setHorizontalPosition(2.0); | |
161 | QCOMPARE(m_series->horizontalPosition(), 1.0); |
|
163 | QCOMPARE(m_series->horizontalPosition(), 1.0); | |
162 |
|
164 | |||
163 | m_series->setVerticalPosition(0.5); |
|
165 | m_series->setVerticalPosition(0.5); | |
164 | m_series->setVerticalPosition(-1.0); |
|
166 | m_series->setVerticalPosition(-1.0); | |
165 | QCOMPARE(m_series->verticalPosition(), 0.0); |
|
167 | QCOMPARE(m_series->verticalPosition(), 0.0); | |
166 | m_series->setVerticalPosition(1.0); |
|
168 | m_series->setVerticalPosition(1.0); | |
167 | m_series->setVerticalPosition(2.0); |
|
169 | m_series->setVerticalPosition(2.0); | |
168 | QCOMPARE(m_series->verticalPosition(), 1.0); |
|
170 | QCOMPARE(m_series->verticalPosition(), 1.0); | |
169 | } |
|
171 | } | |
170 |
|
172 | |||
171 | void tst_qpieseries::append() |
|
173 | void tst_qpieseries::append() | |
172 | { |
|
174 | { | |
173 | m_view->chart()->addSeries(m_series); |
|
175 | m_view->chart()->addSeries(m_series); | |
174 | QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>))); |
|
176 | QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>))); | |
175 |
|
177 | |||
176 | // append pointer |
|
178 | // append pointer | |
177 | QPieSlice *slice1 = 0; |
|
179 | QPieSlice *slice1 = 0; | |
178 | QVERIFY(!m_series->append(slice1)); |
|
180 | QVERIFY(!m_series->append(slice1)); | |
179 | slice1 = new QPieSlice("slice 1", 1); |
|
181 | slice1 = new QPieSlice("slice 1", 1); | |
180 | QVERIFY(m_series->append(slice1)); |
|
182 | QVERIFY(m_series->append(slice1)); | |
181 | QVERIFY(!m_series->append(slice1)); |
|
183 | QVERIFY(!m_series->append(slice1)); | |
182 | QCOMPARE(m_series->count(), 1); |
|
184 | QCOMPARE(m_series->count(), 1); | |
183 | QCOMPARE(addedSpy.count(), 1); |
|
185 | QCOMPARE(addedSpy.count(), 1); | |
184 | QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); |
|
186 | QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); | |
185 | QCOMPARE(added.count(), 1); |
|
187 | QCOMPARE(added.count(), 1); | |
186 | QCOMPARE(added.first(), slice1); |
|
188 | QCOMPARE(added.first(), slice1); | |
187 |
|
189 | |||
188 | // try to append same slice to another series |
|
190 | // try to append same slice to another series | |
189 | QPieSeries series2; |
|
191 | QPieSeries series2; | |
190 | QVERIFY(!series2.append(slice1)); |
|
192 | QVERIFY(!series2.append(slice1)); | |
191 |
|
193 | |||
192 | // append pointer list |
|
194 | // append pointer list | |
193 | QList<QPieSlice *> list; |
|
195 | QList<QPieSlice *> list; | |
194 | QVERIFY(!m_series->append(list)); |
|
196 | QVERIFY(!m_series->append(list)); | |
195 | list << (QPieSlice *) 0; |
|
197 | list << (QPieSlice *) 0; | |
196 | QVERIFY(!m_series->append(list)); |
|
198 | QVERIFY(!m_series->append(list)); | |
197 | list.clear(); |
|
199 | list.clear(); | |
198 | list << new QPieSlice("slice 2", 2); |
|
200 | list << new QPieSlice("slice 2", 2); | |
199 | list << new QPieSlice("slice 3", 3); |
|
201 | list << new QPieSlice("slice 3", 3); | |
200 | QVERIFY(m_series->append(list)); |
|
202 | QVERIFY(m_series->append(list)); | |
201 | QVERIFY(!m_series->append(list)); |
|
203 | QVERIFY(!m_series->append(list)); | |
202 | QCOMPARE(m_series->count(), 3); |
|
204 | QCOMPARE(m_series->count(), 3); | |
203 | QCOMPARE(addedSpy.count(), 2); |
|
205 | QCOMPARE(addedSpy.count(), 2); | |
204 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); |
|
206 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); | |
205 | QCOMPARE(added.count(), 2); |
|
207 | QCOMPARE(added.count(), 2); | |
206 | QCOMPARE(added, list); |
|
208 | QCOMPARE(added, list); | |
207 |
|
209 | |||
208 | // append operator |
|
210 | // append operator | |
209 | QPieSlice *slice4 = new QPieSlice("slice 4", 4); |
|
211 | QPieSlice *slice4 = new QPieSlice("slice 4", 4); | |
210 | *m_series << slice4; |
|
212 | *m_series << slice4; | |
211 | *m_series << slice1; // fails because already added |
|
213 | *m_series << slice1; // fails because already added | |
212 | QCOMPARE(m_series->count(), 4); |
|
214 | QCOMPARE(m_series->count(), 4); | |
213 | QCOMPARE(addedSpy.count(), 3); |
|
215 | QCOMPARE(addedSpy.count(), 3); | |
214 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); |
|
216 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); | |
215 | QCOMPARE(added.count(), 1); |
|
217 | QCOMPARE(added.count(), 1); | |
216 | QCOMPARE(added.first(), slice4); |
|
218 | QCOMPARE(added.first(), slice4); | |
217 |
|
219 | |||
218 | // append with params |
|
220 | // append with params | |
219 | QPieSlice *slice5 = m_series->append("slice 5", 5); |
|
221 | QPieSlice *slice5 = m_series->append("slice 5", 5); | |
220 | QVERIFY(slice5 != 0); |
|
222 | QVERIFY(slice5 != 0); | |
221 | QCOMPARE(slice5->value(), 5.0); |
|
223 | QCOMPARE(slice5->value(), 5.0); | |
222 | QCOMPARE(slice5->label(), QString("slice 5")); |
|
224 | QCOMPARE(slice5->label(), QString("slice 5")); | |
223 | QCOMPARE(m_series->count(), 5); |
|
225 | QCOMPARE(m_series->count(), 5); | |
224 | QCOMPARE(addedSpy.count(), 4); |
|
226 | QCOMPARE(addedSpy.count(), 4); | |
225 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); |
|
227 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); | |
226 | QCOMPARE(added.count(), 1); |
|
228 | QCOMPARE(added.count(), 1); | |
227 | QCOMPARE(added.first(), slice5); |
|
229 | QCOMPARE(added.first(), slice5); | |
228 |
|
230 | |||
229 | // check slices |
|
231 | // check slices | |
230 | QVERIFY(!m_series->isEmpty()); |
|
232 | QVERIFY(!m_series->isEmpty()); | |
231 | for (int i=0; i<m_series->count(); i++) { |
|
233 | for (int i=0; i<m_series->count(); i++) { | |
232 | QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1); |
|
234 | QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1); | |
233 | QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1)); |
|
235 | QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1)); | |
234 | } |
|
236 | } | |
235 | } |
|
237 | } | |
236 |
|
238 | |||
237 | void tst_qpieseries::appendAnimated() |
|
239 | void tst_qpieseries::appendAnimated() | |
238 | { |
|
240 | { | |
239 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); |
|
241 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); | |
240 | append(); |
|
242 | append(); | |
241 | } |
|
243 | } | |
242 |
|
244 | |||
243 | void tst_qpieseries::insert() |
|
245 | void tst_qpieseries::insert() | |
244 | { |
|
246 | { | |
245 | m_view->chart()->addSeries(m_series); |
|
247 | m_view->chart()->addSeries(m_series); | |
246 | QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>))); |
|
248 | QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>))); | |
247 |
|
249 | |||
248 | // insert one slice |
|
250 | // insert one slice | |
249 | QPieSlice *slice1 = 0; |
|
251 | QPieSlice *slice1 = 0; | |
250 | QVERIFY(!m_series->insert(0, slice1)); |
|
252 | QVERIFY(!m_series->insert(0, slice1)); | |
251 | slice1 = new QPieSlice("slice 1", 1); |
|
253 | slice1 = new QPieSlice("slice 1", 1); | |
252 | QVERIFY(!m_series->insert(-1, slice1)); |
|
254 | QVERIFY(!m_series->insert(-1, slice1)); | |
253 | QVERIFY(!m_series->insert(5, slice1)); |
|
255 | QVERIFY(!m_series->insert(5, slice1)); | |
254 | QVERIFY(m_series->insert(0, slice1)); |
|
256 | QVERIFY(m_series->insert(0, slice1)); | |
255 | QVERIFY(!m_series->insert(0, slice1)); |
|
257 | QVERIFY(!m_series->insert(0, slice1)); | |
256 | QCOMPARE(m_series->count(), 1); |
|
258 | QCOMPARE(m_series->count(), 1); | |
257 | QCOMPARE(addedSpy.count(), 1); |
|
259 | QCOMPARE(addedSpy.count(), 1); | |
258 | QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); |
|
260 | QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); | |
259 | QCOMPARE(added.count(), 1); |
|
261 | QCOMPARE(added.count(), 1); | |
260 | QCOMPARE(added.first(), slice1); |
|
262 | QCOMPARE(added.first(), slice1); | |
261 |
|
263 | |||
262 | // try to insert same slice to another series |
|
264 | // try to insert same slice to another series | |
263 | QPieSeries series2; |
|
265 | QPieSeries series2; | |
264 | QVERIFY(!series2.insert(0, slice1)); |
|
266 | QVERIFY(!series2.insert(0, slice1)); | |
265 |
|
267 | |||
266 | // add some more slices |
|
268 | // add some more slices | |
267 | QPieSlice *slice2 = m_series->append("slice 2", 2); |
|
269 | QPieSlice *slice2 = m_series->append("slice 2", 2); | |
268 | QPieSlice *slice4 = m_series->append("slice 4", 4); |
|
270 | QPieSlice *slice4 = m_series->append("slice 4", 4); | |
269 | QCOMPARE(m_series->count(), 3); |
|
271 | QCOMPARE(m_series->count(), 3); | |
270 | QCOMPARE(addedSpy.count(), 3); |
|
272 | QCOMPARE(addedSpy.count(), 3); | |
271 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); |
|
273 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); | |
272 | QCOMPARE(added.count(), 1); |
|
274 | QCOMPARE(added.count(), 1); | |
273 | QCOMPARE(added.first(), slice2); |
|
275 | QCOMPARE(added.first(), slice2); | |
274 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); |
|
276 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); | |
275 | QCOMPARE(added.count(), 1); |
|
277 | QCOMPARE(added.count(), 1); | |
276 | QCOMPARE(added.first(), slice4); |
|
278 | QCOMPARE(added.first(), slice4); | |
277 |
|
279 | |||
278 | // insert between slices |
|
280 | // insert between slices | |
279 | QPieSlice *slice3 = new QPieSlice("slice 3", 3); |
|
281 | QPieSlice *slice3 = new QPieSlice("slice 3", 3); | |
280 | m_series->insert(2, slice3); |
|
282 | m_series->insert(2, slice3); | |
281 | QCOMPARE(m_series->count(), 4); |
|
283 | QCOMPARE(m_series->count(), 4); | |
282 | QCOMPARE(addedSpy.count(), 4); |
|
284 | QCOMPARE(addedSpy.count(), 4); | |
283 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); |
|
285 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); | |
284 | QCOMPARE(added.count(), 1); |
|
286 | QCOMPARE(added.count(), 1); | |
285 | QCOMPARE(added.first(), slice3); |
|
287 | QCOMPARE(added.first(), slice3); | |
286 |
|
288 | |||
287 | // check slices |
|
289 | // check slices | |
288 | for (int i=0; i<m_series->count(); i++) { |
|
290 | for (int i=0; i<m_series->count(); i++) { | |
289 | QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1); |
|
291 | QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1); | |
290 | QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1)); |
|
292 | QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1)); | |
291 | QVERIFY(m_series->slices().at(i)->parent() == m_series); |
|
293 | QVERIFY(m_series->slices().at(i)->parent() == m_series); | |
292 | } |
|
294 | } | |
293 | } |
|
295 | } | |
294 |
|
296 | |||
295 | void tst_qpieseries::insertAnimated() |
|
297 | void tst_qpieseries::insertAnimated() | |
296 | { |
|
298 | { | |
297 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); |
|
299 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); | |
298 | insert(); |
|
300 | insert(); | |
299 | } |
|
301 | } | |
300 |
|
302 | |||
301 | void tst_qpieseries::remove() |
|
303 | void tst_qpieseries::remove() | |
302 | { |
|
304 | { | |
303 | m_view->chart()->addSeries(m_series); |
|
305 | m_view->chart()->addSeries(m_series); | |
304 | QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>))); |
|
306 | QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>))); | |
305 |
|
307 | |||
306 | // add some slices |
|
308 | // add some slices | |
307 | QPieSlice *slice1 = m_series->append("slice 1", 1); |
|
309 | QPieSlice *slice1 = m_series->append("slice 1", 1); | |
308 | QPieSlice *slice2 = m_series->append("slice 2", 2); |
|
310 | QPieSlice *slice2 = m_series->append("slice 2", 2); | |
309 | QPieSlice *slice3 = m_series->append("slice 3", 3); |
|
311 | QPieSlice *slice3 = m_series->append("slice 3", 3); | |
310 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); |
|
312 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); | |
311 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); |
|
313 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); | |
312 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); |
|
314 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); | |
313 | QCOMPARE(m_series->count(), 3); |
|
315 | QCOMPARE(m_series->count(), 3); | |
314 |
|
316 | |||
315 | // null pointer remove |
|
317 | // null pointer remove | |
316 | QVERIFY(!m_series->remove(0)); |
|
318 | QVERIFY(!m_series->remove(0)); | |
317 |
|
319 | |||
318 | // remove first |
|
320 | // remove first | |
319 | QVERIFY(m_series->remove(slice1)); |
|
321 | QVERIFY(m_series->remove(slice1)); | |
320 | QVERIFY(!m_series->remove(slice1)); |
|
322 | QVERIFY(!m_series->remove(slice1)); | |
321 | QCOMPARE(m_series->count(), 2); |
|
323 | QCOMPARE(m_series->count(), 2); | |
322 | QCOMPARE(m_series->slices().at(0)->label(), slice2->label()); |
|
324 | QCOMPARE(m_series->slices().at(0)->label(), slice2->label()); | |
323 | QCOMPARE(removedSpy.count(), 1); |
|
325 | QCOMPARE(removedSpy.count(), 1); | |
324 | QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0)); |
|
326 | QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0)); | |
325 | QCOMPARE(removed.count(), 1); |
|
327 | QCOMPARE(removed.count(), 1); | |
326 | QCOMPARE(removed.first(), slice1); |
|
328 | QCOMPARE(removed.first(), slice1); | |
327 |
|
329 | |||
328 | // remove all |
|
330 | // remove all | |
329 | m_series->clear(); |
|
331 | m_series->clear(); | |
330 | QVERIFY(m_series->isEmpty()); |
|
332 | QVERIFY(m_series->isEmpty()); | |
331 | QVERIFY(m_series->slices().isEmpty()); |
|
333 | QVERIFY(m_series->slices().isEmpty()); | |
332 | QCOMPARE(m_series->count(), 0); |
|
334 | QCOMPARE(m_series->count(), 0); | |
333 | QCOMPARE(removedSpy.count(), 2); |
|
335 | QCOMPARE(removedSpy.count(), 2); | |
334 | removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0)); |
|
336 | removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0)); | |
335 | QCOMPARE(removed.count(), 2); |
|
337 | QCOMPARE(removed.count(), 2); | |
336 | QCOMPARE(removed.first(), slice2); |
|
338 | QCOMPARE(removed.first(), slice2); | |
337 | QCOMPARE(removed.last(), slice3); |
|
339 | QCOMPARE(removed.last(), slice3); | |
338 |
|
340 | |||
339 | // check that slices were actually destroyed |
|
341 | // check that slices were actually destroyed | |
340 | TRY_COMPARE(spy1.count(), 1); |
|
342 | TRY_COMPARE(spy1.count(), 1); | |
341 | TRY_COMPARE(spy2.count(), 1); |
|
343 | TRY_COMPARE(spy2.count(), 1); | |
342 | TRY_COMPARE(spy3.count(), 1); |
|
344 | TRY_COMPARE(spy3.count(), 1); | |
343 | } |
|
345 | } | |
344 |
|
346 | |||
345 | void tst_qpieseries::removeAnimated() |
|
347 | void tst_qpieseries::removeAnimated() | |
346 | { |
|
348 | { | |
347 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); |
|
349 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); | |
348 | remove(); |
|
350 | remove(); | |
349 | } |
|
351 | } | |
350 |
|
352 | |||
|
353 | void tst_qpieseries::take() | |||
|
354 | { | |||
|
355 | m_view->chart()->addSeries(m_series); | |||
|
356 | QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>))); | |||
|
357 | ||||
|
358 | // add some slices | |||
|
359 | QPieSlice *slice1 = m_series->append("slice 1", 1); | |||
|
360 | QPieSlice *slice2 = m_series->append("slice 2", 2); | |||
|
361 | m_series->append("slice 3", 3); | |||
|
362 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); | |||
|
363 | QCOMPARE(m_series->count(), 3); | |||
|
364 | ||||
|
365 | // null pointer remove | |||
|
366 | QVERIFY(!m_series->take(0)); | |||
|
367 | ||||
|
368 | // take first | |||
|
369 | QVERIFY(m_series->take(slice1)); | |||
|
370 | TRY_COMPARE(spy1.count(), 0); | |||
|
371 | QVERIFY(slice1->parent() == m_series); // series is still the parent object | |||
|
372 | QVERIFY(!m_series->take(slice1)); | |||
|
373 | QCOMPARE(m_series->count(), 2); | |||
|
374 | QCOMPARE(m_series->slices().at(0)->label(), slice2->label()); | |||
|
375 | QCOMPARE(removedSpy.count(), 1); | |||
|
376 | QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0)); | |||
|
377 | QCOMPARE(removed.count(), 1); | |||
|
378 | QCOMPARE(removed.first(), slice1); | |||
|
379 | } | |||
|
380 | ||||
|
381 | void tst_qpieseries::takeAnimated() | |||
|
382 | { | |||
|
383 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); | |||
|
384 | take(); | |||
|
385 | } | |||
|
386 | ||||
351 | void tst_qpieseries::calculatedValues() |
|
387 | void tst_qpieseries::calculatedValues() | |
352 | { |
|
388 | { | |
353 | m_view->chart()->addSeries(m_series); |
|
389 | m_view->chart()->addSeries(m_series); | |
354 |
|
390 | |||
355 | QPieSlice *slice1 = new QPieSlice("slice 1", 1); |
|
391 | QPieSlice *slice1 = new QPieSlice("slice 1", 1); | |
356 | QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged())); |
|
392 | QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged())); | |
357 | QSignalSpy startAngleSpy(slice1, SIGNAL(startAngleChanged())); |
|
393 | QSignalSpy startAngleSpy(slice1, SIGNAL(startAngleChanged())); | |
358 | QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged())); |
|
394 | QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged())); | |
359 |
|
395 | |||
360 | // add a slice |
|
396 | // add a slice | |
361 | m_series->append(slice1); |
|
397 | m_series->append(slice1); | |
362 | bool ok; |
|
398 | bool ok; | |
363 | verifyCalculatedData(*m_series, &ok); |
|
399 | verifyCalculatedData(*m_series, &ok); | |
364 | if (!ok) |
|
400 | if (!ok) | |
365 | return; |
|
401 | return; | |
366 | QCOMPARE(percentageSpy.count(), 1); |
|
402 | QCOMPARE(percentageSpy.count(), 1); | |
367 | QCOMPARE(startAngleSpy.count(), 0); |
|
403 | QCOMPARE(startAngleSpy.count(), 0); | |
368 | QCOMPARE(angleSpanSpy.count(), 1); |
|
404 | QCOMPARE(angleSpanSpy.count(), 1); | |
369 |
|
405 | |||
370 | // add some more slices |
|
406 | // add some more slices | |
371 | QList<QPieSlice *> list; |
|
407 | QList<QPieSlice *> list; | |
372 | list << new QPieSlice("slice 2", 2); |
|
408 | list << new QPieSlice("slice 2", 2); | |
373 | list << new QPieSlice("slice 3", 3); |
|
409 | list << new QPieSlice("slice 3", 3); | |
374 | m_series->append(list); |
|
410 | m_series->append(list); | |
375 | verifyCalculatedData(*m_series, &ok); |
|
411 | verifyCalculatedData(*m_series, &ok); | |
376 | if (!ok) |
|
412 | if (!ok) | |
377 | return; |
|
413 | return; | |
378 | QCOMPARE(percentageSpy.count(), 2); |
|
414 | QCOMPARE(percentageSpy.count(), 2); | |
379 | QCOMPARE(startAngleSpy.count(), 0); |
|
415 | QCOMPARE(startAngleSpy.count(), 0); | |
380 | QCOMPARE(angleSpanSpy.count(), 2); |
|
416 | QCOMPARE(angleSpanSpy.count(), 2); | |
381 |
|
417 | |||
382 | // remove a slice |
|
418 | // remove a slice | |
383 | m_series->remove(list.first()); // remove slice 2 |
|
419 | m_series->remove(list.first()); // remove slice 2 | |
384 | verifyCalculatedData(*m_series, &ok); |
|
420 | verifyCalculatedData(*m_series, &ok); | |
385 | if (!ok) |
|
421 | if (!ok) | |
386 | return; |
|
422 | return; | |
387 | QCOMPARE(percentageSpy.count(), 3); |
|
423 | QCOMPARE(percentageSpy.count(), 3); | |
388 | QCOMPARE(startAngleSpy.count(), 0); |
|
424 | QCOMPARE(startAngleSpy.count(), 0); | |
389 | QCOMPARE(angleSpanSpy.count(), 3); |
|
425 | QCOMPARE(angleSpanSpy.count(), 3); | |
390 |
|
426 | |||
391 | // insert a slice |
|
427 | // insert a slice | |
392 | m_series->insert(0, new QPieSlice("Slice 4", 4)); |
|
428 | m_series->insert(0, new QPieSlice("Slice 4", 4)); | |
393 | verifyCalculatedData(*m_series, &ok); |
|
429 | verifyCalculatedData(*m_series, &ok); | |
394 | if (!ok) |
|
430 | if (!ok) | |
395 | return; |
|
431 | return; | |
396 | QCOMPARE(percentageSpy.count(), 4); |
|
432 | QCOMPARE(percentageSpy.count(), 4); | |
397 | QCOMPARE(startAngleSpy.count(), 1); |
|
433 | QCOMPARE(startAngleSpy.count(), 1); | |
398 | QCOMPARE(angleSpanSpy.count(), 4); |
|
434 | QCOMPARE(angleSpanSpy.count(), 4); | |
399 |
|
435 | |||
400 | // modify pie angles |
|
436 | // modify pie angles | |
401 | m_series->setPieStartAngle(-90); |
|
437 | m_series->setPieStartAngle(-90); | |
402 | m_series->setPieEndAngle(90); |
|
438 | m_series->setPieEndAngle(90); | |
403 | verifyCalculatedData(*m_series, &ok); |
|
439 | verifyCalculatedData(*m_series, &ok); | |
404 | if (!ok) |
|
440 | if (!ok) | |
405 | return; |
|
441 | return; | |
406 | QCOMPARE(percentageSpy.count(), 4); |
|
442 | QCOMPARE(percentageSpy.count(), 4); | |
407 | QCOMPARE(startAngleSpy.count(), 3); |
|
443 | QCOMPARE(startAngleSpy.count(), 3); | |
408 | QCOMPARE(angleSpanSpy.count(), 6); |
|
444 | QCOMPARE(angleSpanSpy.count(), 6); | |
409 |
|
445 | |||
410 | // clear all |
|
446 | // clear all | |
411 | m_series->clear(); |
|
447 | m_series->clear(); | |
412 | verifyCalculatedData(*m_series, &ok); |
|
448 | verifyCalculatedData(*m_series, &ok); | |
413 | if (!ok) |
|
449 | if (!ok) | |
414 | return; |
|
450 | return; | |
415 | QCOMPARE(percentageSpy.count(), 4); |
|
451 | QCOMPARE(percentageSpy.count(), 4); | |
416 | QCOMPARE(startAngleSpy.count(), 3); |
|
452 | QCOMPARE(startAngleSpy.count(), 3); | |
417 | QCOMPARE(angleSpanSpy.count(), 6); |
|
453 | QCOMPARE(angleSpanSpy.count(), 6); | |
418 | } |
|
454 | } | |
419 |
|
455 | |||
420 | void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) |
|
456 | void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) | |
421 | { |
|
457 | { | |
422 | *ok = false; |
|
458 | *ok = false; | |
423 |
|
459 | |||
424 | qreal sum = 0; |
|
460 | qreal sum = 0; | |
425 | foreach (const QPieSlice *slice, series.slices()) |
|
461 | foreach (const QPieSlice *slice, series.slices()) | |
426 | sum += slice->value(); |
|
462 | sum += slice->value(); | |
427 | QCOMPARE(series.sum(), sum); |
|
463 | QCOMPARE(series.sum(), sum); | |
428 |
|
464 | |||
429 | qreal startAngle = series.pieStartAngle(); |
|
465 | qreal startAngle = series.pieStartAngle(); | |
430 | qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle(); |
|
466 | qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle(); | |
431 | foreach (const QPieSlice *slice, series.slices()) { |
|
467 | foreach (const QPieSlice *slice, series.slices()) { | |
432 | qreal ratio = slice->value() / sum; |
|
468 | qreal ratio = slice->value() / sum; | |
433 | qreal sliceSpan = pieAngleSpan * ratio; |
|
469 | qreal sliceSpan = pieAngleSpan * ratio; | |
434 | QCOMPARE(slice->startAngle(), startAngle); |
|
470 | QCOMPARE(slice->startAngle(), startAngle); | |
435 | QCOMPARE(slice->angleSpan(), sliceSpan); |
|
471 | QCOMPARE(slice->angleSpan(), sliceSpan); | |
436 | QCOMPARE(slice->percentage(), ratio); |
|
472 | QCOMPARE(slice->percentage(), ratio); | |
437 | startAngle += sliceSpan; |
|
473 | startAngle += sliceSpan; | |
438 | } |
|
474 | } | |
439 |
|
475 | |||
440 | if (!series.isEmpty()) |
|
476 | if (!series.isEmpty()) | |
441 | QCOMPARE(series.slices().last()->startAngle() + series.slices().last()->angleSpan(), series.pieEndAngle()); |
|
477 | QCOMPARE(series.slices().last()->startAngle() + series.slices().last()->angleSpan(), series.pieEndAngle()); | |
442 |
|
478 | |||
443 | *ok = true; |
|
479 | *ok = true; | |
444 | } |
|
480 | } | |
445 |
|
481 | |||
446 |
|
482 | |||
447 | void tst_qpieseries::clickedSignal() |
|
483 | void tst_qpieseries::clickedSignal() | |
448 | { |
|
484 | { | |
449 | // add some slices |
|
485 | // add some slices | |
450 | QPieSlice *s1 = m_series->append("slice 1", 1); |
|
486 | QPieSlice *s1 = m_series->append("slice 1", 1); | |
451 | QPieSlice *s2 = m_series->append("slice 2", 1); |
|
487 | QPieSlice *s2 = m_series->append("slice 2", 1); | |
452 | QPieSlice *s3 = m_series->append("slice 3", 1); |
|
488 | QPieSlice *s3 = m_series->append("slice 3", 1); | |
453 | QPieSlice *s4 = m_series->append("slice 4", 1); |
|
489 | QPieSlice *s4 = m_series->append("slice 4", 1); | |
454 | QSignalSpy clickSpy(m_series, SIGNAL(clicked(QPieSlice*))); |
|
490 | QSignalSpy clickSpy(m_series, SIGNAL(clicked(QPieSlice*))); | |
455 |
|
491 | |||
456 | // add series to the chart |
|
492 | // add series to the chart | |
457 | m_view->chart()->legend()->setVisible(false); |
|
493 | m_view->chart()->legend()->setVisible(false); | |
458 | m_view->resize(200, 200); |
|
494 | m_view->resize(200, 200); | |
459 | m_view->chart()->addSeries(m_series); |
|
495 | m_view->chart()->addSeries(m_series); | |
460 | m_view->show(); |
|
496 | m_view->show(); | |
461 | QTest::qWaitForWindowShown(m_view); |
|
497 | QTest::qWaitForWindowShown(m_view); | |
462 |
|
498 | |||
463 | // if you devide the chart in four equal tiles these |
|
499 | // if you devide the chart in four equal tiles these | |
464 | // are the center points of those tiles |
|
500 | // are the center points of those tiles | |
465 | QPoint p1(90.25, 90); |
|
501 | QPoint p1(90.25, 90); | |
466 | QPoint p2(150, 90); |
|
502 | QPoint p2(150, 90); | |
467 | QPoint p3(90, 150); |
|
503 | QPoint p3(90, 150); | |
468 | QPoint p4(150, 150); |
|
504 | QPoint p4(150, 150); | |
469 |
|
505 | |||
470 | QPoint center(120, 120); |
|
506 | QPoint center(120, 120); | |
471 |
|
507 | |||
472 | m_series->setPieSize(1.0); |
|
508 | m_series->setPieSize(1.0); | |
473 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); |
|
509 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); | |
474 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); |
|
510 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); | |
475 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); |
|
511 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); | |
476 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); |
|
512 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); | |
477 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); |
|
513 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); | |
478 | TRY_COMPARE(clickSpy.count(), 5); // all hit |
|
514 | TRY_COMPARE(clickSpy.count(), 5); // all hit | |
479 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s4); |
|
515 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s4); | |
480 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s1); |
|
516 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s1); | |
481 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3); |
|
517 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3); | |
482 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s2); |
|
518 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s2); | |
483 | clickSpy.clear(); |
|
519 | clickSpy.clear(); | |
484 |
|
520 | |||
485 | m_series->setPieSize(0.5); |
|
521 | m_series->setPieSize(0.5); | |
486 | m_series->setVerticalPosition(0.25); |
|
522 | m_series->setVerticalPosition(0.25); | |
487 | m_series->setHorizontalPosition(0.25); |
|
523 | m_series->setHorizontalPosition(0.25); | |
488 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); // hits |
|
524 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); // hits | |
489 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); |
|
525 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); | |
490 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); |
|
526 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); | |
491 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); |
|
527 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); | |
492 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); |
|
528 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); | |
493 | TRY_COMPARE(clickSpy.count(), 1); |
|
529 | TRY_COMPARE(clickSpy.count(), 1); | |
494 | clickSpy.clear(); |
|
530 | clickSpy.clear(); | |
495 |
|
531 | |||
496 | m_series->setVerticalPosition(0.25); |
|
532 | m_series->setVerticalPosition(0.25); | |
497 | m_series->setHorizontalPosition(0.75); |
|
533 | m_series->setHorizontalPosition(0.75); | |
498 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); |
|
534 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); | |
499 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); // hits |
|
535 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); // hits | |
500 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); |
|
536 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); | |
501 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); |
|
537 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); | |
502 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); |
|
538 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); | |
503 | TRY_COMPARE(clickSpy.count(), 1); |
|
539 | TRY_COMPARE(clickSpy.count(), 1); | |
504 | clickSpy.clear(); |
|
540 | clickSpy.clear(); | |
505 |
|
541 | |||
506 | m_series->setVerticalPosition(0.75); |
|
542 | m_series->setVerticalPosition(0.75); | |
507 | m_series->setHorizontalPosition(0.25); |
|
543 | m_series->setHorizontalPosition(0.25); | |
508 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); |
|
544 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); | |
509 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); |
|
545 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); | |
510 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); // hits |
|
546 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); // hits | |
511 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); |
|
547 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); | |
512 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); |
|
548 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); | |
513 | TRY_COMPARE(clickSpy.count(), 1); |
|
549 | TRY_COMPARE(clickSpy.count(), 1); | |
514 | clickSpy.clear(); |
|
550 | clickSpy.clear(); | |
515 |
|
551 | |||
516 | m_series->setVerticalPosition(0.75); |
|
552 | m_series->setVerticalPosition(0.75); | |
517 | m_series->setHorizontalPosition(0.75); |
|
553 | m_series->setHorizontalPosition(0.75); | |
518 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); |
|
554 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); | |
519 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); |
|
555 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); | |
520 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); |
|
556 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); | |
521 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); // hits |
|
557 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); // hits | |
522 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); |
|
558 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); | |
523 | TRY_COMPARE(clickSpy.count(), 1); |
|
559 | TRY_COMPARE(clickSpy.count(), 1); | |
524 | clickSpy.clear(); |
|
560 | clickSpy.clear(); | |
525 | } |
|
561 | } | |
526 |
|
562 | |||
527 | void tst_qpieseries::hoverSignal() |
|
563 | void tst_qpieseries::hoverSignal() | |
528 | { |
|
564 | { | |
529 | // add some slices |
|
565 | // add some slices | |
530 | m_series->setPieSize(1.0); |
|
566 | m_series->setPieSize(1.0); | |
531 | QPieSlice *s1 = m_series->append("slice 1", 1); |
|
567 | QPieSlice *s1 = m_series->append("slice 1", 1); | |
532 | m_series->append("slice 2", 2); |
|
568 | m_series->append("slice 2", 2); | |
533 | m_series->append("slice 3", 3); |
|
569 | m_series->append("slice 3", 3); | |
534 |
|
570 | |||
535 | // add series to the chart |
|
571 | // add series to the chart | |
536 | m_view->chart()->legend()->setVisible(false); |
|
572 | m_view->chart()->legend()->setVisible(false); | |
537 | m_view->resize(200, 200); |
|
573 | m_view->resize(200, 200); | |
538 | m_view->chart()->addSeries(m_series); |
|
574 | m_view->chart()->addSeries(m_series); | |
539 | m_view->show(); |
|
575 | m_view->show(); | |
540 | QTest::qWaitForWindowShown(m_view); |
|
576 | QTest::qWaitForWindowShown(m_view); | |
541 |
|
577 | |||
542 | // first move to right top corner |
|
578 | // first move to right top corner | |
543 | QTest::mouseMove(m_view->viewport(), QPoint(200, 0)); |
|
579 | QTest::mouseMove(m_view->viewport(), QPoint(200, 0)); | |
544 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
580 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
545 |
|
581 | |||
546 | // move inside the slice |
|
582 | // move inside the slice | |
547 | // pie rectangle: QRectF(60,60 121x121) |
|
583 | // pie rectangle: QRectF(60,60 121x121) | |
548 | QSignalSpy hoverSpy(m_series, SIGNAL(hovered(QPieSlice*,bool))); |
|
584 | QSignalSpy hoverSpy(m_series, SIGNAL(hovered(QPieSlice*,bool))); | |
549 | QTest::mouseMove(m_view->viewport(), QPoint(139, 85)); |
|
585 | QTest::mouseMove(m_view->viewport(), QPoint(139, 85)); | |
550 | TRY_COMPARE(hoverSpy.count(), 1); |
|
586 | TRY_COMPARE(hoverSpy.count(), 1); | |
551 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1); |
|
587 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1); | |
552 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true); |
|
588 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true); | |
553 |
|
589 | |||
554 | // move outside the slice |
|
590 | // move outside the slice | |
555 | QTest::mouseMove(m_view->viewport(), QPoint(200, 0)); |
|
591 | QTest::mouseMove(m_view->viewport(), QPoint(200, 0)); | |
556 | TRY_COMPARE(hoverSpy.count(), 2); |
|
592 | TRY_COMPARE(hoverSpy.count(), 2); | |
557 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1); |
|
593 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1); | |
558 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false); |
|
594 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false); | |
559 | } |
|
595 | } | |
560 |
|
596 | |||
561 | void tst_qpieseries::sliceSeries() |
|
597 | void tst_qpieseries::sliceSeries() | |
562 | { |
|
598 | { | |
563 | QPieSlice *slice = new QPieSlice(); |
|
599 | QPieSlice *slice = new QPieSlice(); | |
564 | QVERIFY(!slice->series()); |
|
600 | QVERIFY(!slice->series()); | |
565 | delete slice; |
|
601 | delete slice; | |
566 |
|
602 | |||
567 | slice = new QPieSlice(m_series); |
|
603 | slice = new QPieSlice(m_series); | |
568 | QVERIFY(!slice->series()); |
|
604 | QVERIFY(!slice->series()); | |
569 |
|
605 | |||
570 | m_series->append(slice); |
|
606 | m_series->append(slice); | |
571 | QCOMPARE(slice->series(), m_series); |
|
607 | QCOMPARE(slice->series(), m_series); | |
572 |
|
608 | |||
573 | slice = new QPieSlice(); |
|
609 | slice = new QPieSlice(); | |
574 | m_series->insert(0, slice); |
|
610 | m_series->insert(0, slice); | |
575 | QCOMPARE(slice->series(), m_series); |
|
611 | QCOMPARE(slice->series(), m_series); | |
|
612 | ||||
|
613 | m_series->take(slice); | |||
|
614 | QCOMPARE(slice->series(), (QPieSeries*) 0); | |||
576 | } |
|
615 | } | |
577 |
|
616 | |||
578 | void tst_qpieseries::destruction() |
|
617 | void tst_qpieseries::destruction() | |
579 | { |
|
618 | { | |
580 | // add some slices |
|
619 | // add some slices | |
581 | QPieSlice *slice1 = m_series->append("slice 1", 1); |
|
620 | QPieSlice *slice1 = m_series->append("slice 1", 1); | |
582 | QPieSlice *slice2 = m_series->append("slice 2", 2); |
|
621 | QPieSlice *slice2 = m_series->append("slice 2", 2); | |
583 | QPieSlice *slice3 = m_series->append("slice 3", 3); |
|
622 | QPieSlice *slice3 = m_series->append("slice 3", 3); | |
584 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); |
|
623 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); | |
585 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); |
|
624 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); | |
586 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); |
|
625 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); | |
587 |
|
626 | |||
588 | // destroy series |
|
627 | // destroy series | |
589 | delete m_series; |
|
628 | delete m_series; | |
590 | m_series = 0; |
|
629 | m_series = 0; | |
591 |
|
630 | |||
592 | // check that series has destroyed its slices |
|
631 | // check that series has destroyed its slices | |
593 | QCOMPARE(spy1.count(), 1); |
|
632 | QCOMPARE(spy1.count(), 1); | |
594 | QCOMPARE(spy2.count(), 1); |
|
633 | QCOMPARE(spy2.count(), 1); | |
595 | QCOMPARE(spy3.count(), 1); |
|
634 | QCOMPARE(spy3.count(), 1); | |
596 | } |
|
635 | } | |
597 |
|
636 | |||
598 | QTEST_MAIN(tst_qpieseries) |
|
637 | QTEST_MAIN(tst_qpieseries) | |
599 |
|
638 | |||
600 | #include "tst_qpieseries.moc" |
|
639 | #include "tst_qpieseries.moc" | |
601 |
|
640 |
General Comments 0
You need to be logged in to leave comments.
Login now