@@ -1,660 +1,725 | |||||
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 "chartanimator_p.h" |
|
28 | #include "chartanimator_p.h" | |
29 | #include "legendmarker_p.h" |
|
29 | #include "legendmarker_p.h" | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \class QPieSeries |
|
34 | \class QPieSeries | |
35 | \brief Pie series API for QtCommercial Charts |
|
35 | \brief Pie series API for QtCommercial Charts | |
36 |
|
36 | |||
37 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. |
|
37 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. | |
38 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
38 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
39 | The actual slice size is determined by that relative value. |
|
39 | The actual slice size is determined by that relative value. | |
40 |
|
40 | |||
41 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 |
|
41 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 | |
42 | These relate to the actual chart rectangle. |
|
42 | These relate to the actual chart rectangle. | |
43 |
|
43 | |||
44 | By default the pie is defined as a full pie but it can also be a partial pie. |
|
44 | By default the pie is defined as a full pie but it can also be a partial pie. | |
45 | This can be done by setting a starting angle and angle span to the series. |
|
45 | This can be done by setting a starting angle and angle span to the series. | |
46 | Full pie is 360 degrees where 0 is at 12 a'clock. |
|
46 | Full pie is 360 degrees where 0 is at 12 a'clock. | |
47 |
|
47 | |||
48 | See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart. |
|
48 | See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart. | |
49 | \image examples_piechart.png |
|
49 | \image examples_piechart.png | |
50 | */ |
|
50 | */ | |
51 | /*! |
|
51 | /*! | |
52 | \qmlclass PieSeries QPieSeries |
|
52 | \qmlclass PieSeries QPieSeries | |
53 |
|
53 | |||
54 | The following QML shows how to create a simple pie chart. |
|
54 | The following QML shows how to create a simple pie chart. | |
|
55 | ||||
55 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 |
|
56 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 | |
|
57 | ||||
56 | \beginfloatleft |
|
58 | \beginfloatleft | |
57 | \image demos_qmlchart1.png |
|
59 | \image demos_qmlchart1.png | |
58 | \endfloat |
|
60 | \endfloat | |
59 | \clearfloat |
|
61 | \clearfloat | |
60 | */ |
|
62 | */ | |
61 |
|
63 | |||
62 | /*! |
|
64 | /*! | |
63 | \property QPieSeries::horizontalPosition |
|
65 | \property QPieSeries::horizontalPosition | |
64 | \brief Defines the horizontal position of the pie. |
|
66 | \brief Defines the horizontal position of the pie. | |
|
67 | ||||
65 | The value is a relative value to the chart rectangle where: |
|
68 | The value is a relative value to the chart rectangle where: | |
|
69 | ||||
66 | \list |
|
70 | \list | |
67 | \o 0.0 is the absolute left. |
|
71 | \o 0.0 is the absolute left. | |
68 | \o 1.0 is the absolute right. |
|
72 | \o 1.0 is the absolute right. | |
69 | \endlist |
|
73 | \endlist | |
70 | Default value is 0.5 (center). |
|
74 | Default value is 0.5 (center). | |
71 | \sa verticalPosition |
|
75 | \sa verticalPosition | |
72 | */ |
|
76 | */ | |
|
77 | ||||
73 | /*! |
|
78 | /*! | |
74 | \qmlproperty real PieSeries::horizontalPosition |
|
79 | \qmlproperty real PieSeries::horizontalPosition | |
75 | Defines the horizontal position of the pie. The value is a relative value to the chart rectangle where: |
|
80 | ||
|
81 | Defines the horizontal position of the pie. | |||
|
82 | ||||
|
83 | The value is a relative value to the chart rectangle where: | |||
|
84 | ||||
76 | \list |
|
85 | \list | |
77 | \o 0.0 is the absolute left. |
|
86 | \o 0.0 is the absolute left. | |
78 | \o 1.0 is the absolute right. |
|
87 | \o 1.0 is the absolute right. | |
79 | \endlist |
|
88 | \endlist | |
80 | Default value is 0.5 (center). |
|
89 | Default value is 0.5 (center). | |
81 | \sa verticalPosition |
|
90 | \sa verticalPosition | |
82 | */ |
|
91 | */ | |
83 |
|
92 | |||
84 | /*! |
|
93 | /*! | |
85 | \property QPieSeries::verticalPosition |
|
94 | \property QPieSeries::verticalPosition | |
86 | \brief Defines the vertical position of the pie. |
|
95 | \brief Defines the vertical position of the pie. | |
|
96 | ||||
87 | The value is a relative value to the chart rectangle where: |
|
97 | The value is a relative value to the chart rectangle where: | |
|
98 | ||||
88 | \list |
|
99 | \list | |
89 | \o 0.0 is the absolute top. |
|
100 | \o 0.0 is the absolute top. | |
90 | \o 1.0 is the absolute bottom. |
|
101 | \o 1.0 is the absolute bottom. | |
91 | \endlist |
|
102 | \endlist | |
92 | Default value is 0.5 (center). |
|
103 | Default value is 0.5 (center). | |
93 | \sa horizontalPosition |
|
104 | \sa horizontalPosition | |
94 | */ |
|
105 | */ | |
|
106 | ||||
95 | /*! |
|
107 | /*! | |
96 | \qmlproperty real PieSeries::verticalPosition |
|
108 | \qmlproperty real PieSeries::verticalPosition | |
97 | Defines the vertical position of the pie. The value is a relative value to the chart rectangle where: |
|
109 | ||
|
110 | Defines the vertical position of the pie. | |||
|
111 | ||||
|
112 | The value is a relative value to the chart rectangle where: | |||
|
113 | ||||
98 | \list |
|
114 | \list | |
99 | \o 0.0 is the absolute top. |
|
115 | \o 0.0 is the absolute top. | |
100 | \o 1.0 is the absolute bottom. |
|
116 | \o 1.0 is the absolute bottom. | |
101 | \endlist |
|
117 | \endlist | |
102 | Default value is 0.5 (center). |
|
118 | Default value is 0.5 (center). | |
103 | \sa horizontalPosition |
|
119 | \sa horizontalPosition | |
104 | */ |
|
120 | */ | |
105 |
|
121 | |||
106 | /*! |
|
122 | /*! | |
107 | \property QPieSeries::size |
|
123 | \property QPieSeries::size | |
108 | \brief Defines the pie size. |
|
124 | \brief Defines the pie size. | |
109 |
|
125 | |||
110 | The value is a relative value to the chart rectangle where: |
|
126 | The value is a relative value to the chart rectangle where: | |
111 |
|
127 | |||
112 | \list |
|
128 | \list | |
113 | \o 0.0 is the minimum size (pie not drawn). |
|
129 | \o 0.0 is the minimum size (pie not drawn). | |
114 | \o 1.0 is the maximum size that can fit the chart. |
|
130 | \o 1.0 is the maximum size that can fit the chart. | |
115 | \endlist |
|
131 | \endlist | |
116 |
|
132 | |||
117 | Default value is 0.7. |
|
133 | Default value is 0.7. | |
118 | */ |
|
134 | */ | |
119 |
|
135 | |||
120 | /*! |
|
136 | /*! | |
|
137 | \qmlproperty real PieSeries::size | |||
|
138 | ||||
|
139 | Defines the pie size. | |||
|
140 | ||||
|
141 | The value is a relative value to the chart rectangle where: | |||
|
142 | ||||
|
143 | \list | |||
|
144 | \o 0.0 is the minimum size (pie not drawn). | |||
|
145 | \o 1.0 is the maximum size that can fit the chart. | |||
|
146 | \endlist | |||
|
147 | ||||
|
148 | Default value is 0.7. | |||
|
149 | */ | |||
|
150 | ||||
|
151 | /*! | |||
121 | \property QPieSeries::startAngle |
|
152 | \property QPieSeries::startAngle | |
122 | \brief Defines the starting angle of the pie. |
|
153 | \brief Defines the starting angle of the pie. | |
123 |
|
154 | |||
124 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
155 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
125 |
|
156 | |||
126 | Default is value is 0. |
|
157 | Default is value is 0. | |
127 | */ |
|
158 | */ | |
128 |
|
159 | |||
129 | /*! |
|
160 | /*! | |
|
161 | \qmlproperty real PieSeries::startAngle | |||
|
162 | ||||
|
163 | Defines the starting angle of the pie. | |||
|
164 | ||||
|
165 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |||
|
166 | ||||
|
167 | Default is value is 0. | |||
|
168 | */ | |||
|
169 | ||||
|
170 | /*! | |||
130 | \property QPieSeries::endAngle |
|
171 | \property QPieSeries::endAngle | |
131 | \brief Defines the ending angle of the pie. |
|
172 | \brief Defines the ending angle of the pie. | |
132 |
|
173 | |||
133 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
174 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
134 |
|
175 | |||
135 | Default is value is 360. |
|
176 | Default is value is 360. | |
136 | */ |
|
177 | */ | |
137 |
|
178 | |||
138 | /*! |
|
179 | /*! | |
|
180 | \qmlproperty real PieSeries::endAngle | |||
|
181 | ||||
|
182 | Defines the ending angle of the pie. | |||
|
183 | ||||
|
184 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |||
|
185 | ||||
|
186 | Default is value is 360. | |||
|
187 | */ | |||
|
188 | ||||
|
189 | /*! | |||
139 | \property QPieSeries::count |
|
190 | \property QPieSeries::count | |
140 |
|
191 | |||
141 | Number of slices in the series. |
|
192 | Number of slices in the series. | |
142 | */ |
|
193 | */ | |
143 |
|
194 | |||
144 | /*! |
|
195 | /*! | |
|
196 | \qmlproperty int PieSeries::count | |||
|
197 | ||||
|
198 | Number of slices in the series. | |||
|
199 | */ | |||
|
200 | ||||
|
201 | /*! | |||
145 | \fn void QPieSeries::countChanged() |
|
202 | \fn void QPieSeries::countChanged() | |
146 |
|
203 | |||
147 | Emitted when the slice count has changed. |
|
204 | Emitted when the slice count has changed. | |
148 |
|
205 | |||
149 | \sa count |
|
206 | \sa count | |
150 | */ |
|
207 | */ | |
151 |
|
208 | |||
152 | /*! |
|
209 | /*! | |
153 | \property QPieSeries::sum |
|
210 | \property QPieSeries::sum | |
154 |
|
211 | |||
155 | Sum of all slices. |
|
212 | Sum of all slices. | |
156 |
|
213 | |||
157 | The series keeps track of the sum of all slices it holds. |
|
214 | The series keeps track of the sum of all slices it holds. | |
158 | */ |
|
215 | */ | |
159 |
|
216 | |||
160 | /*! |
|
217 | /*! | |
|
218 | \qmlproperty real PieSeries::sum | |||
|
219 | ||||
|
220 | Sum of all slices. | |||
|
221 | ||||
|
222 | The series keeps track of the sum of all slices it holds. | |||
|
223 | */ | |||
|
224 | ||||
|
225 | /*! | |||
161 | \fn void QPieSeries::sumChanged() |
|
226 | \fn void QPieSeries::sumChanged() | |
162 |
|
227 | |||
163 | Emitted when the sum of all slices has changed. |
|
228 | Emitted when the sum of all slices has changed. | |
164 |
|
229 | |||
165 | \sa sum |
|
230 | \sa sum | |
166 | */ |
|
231 | */ | |
167 |
|
232 | |||
168 | /*! |
|
233 | /*! | |
169 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
234 | \fn void QPieSeries::added(QList<QPieSlice*> slices) | |
170 |
|
235 | |||
171 | This signal is emitted when \a slices have been added to the series. |
|
236 | This signal is emitted when \a slices have been added to the series. | |
172 |
|
237 | |||
173 | \sa append(), insert() |
|
238 | \sa append(), insert() | |
174 | */ |
|
239 | */ | |
175 | /*! |
|
240 | /*! | |
176 | \qmlsignal PieSeries::added(PieSlice slice) |
|
241 | \qmlsignal PieSeries::added(PieSlice slice) | |
177 | Emitted when \a slice has been added to the series. |
|
242 | Emitted when \a slice has been added to the series. | |
178 | */ |
|
243 | */ | |
179 |
|
244 | |||
180 | /*! |
|
245 | /*! | |
181 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
246 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) | |
182 | This signal is emitted when \a slices have been removed from the series. |
|
247 | This signal is emitted when \a slices have been removed from the series. | |
183 | \sa remove() |
|
248 | \sa remove() | |
184 | */ |
|
249 | */ | |
185 | /*! |
|
250 | /*! | |
186 | \qmlsignal PieSeries::removed(PieSlice slice) |
|
251 | \qmlsignal PieSeries::removed(PieSlice slice) | |
187 | Emitted when \a slice has been removed from the series. |
|
252 | Emitted when \a slice has been removed from the series. | |
188 | */ |
|
253 | */ | |
189 |
|
254 | |||
190 | /*! |
|
255 | /*! | |
191 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
256 | \fn void QPieSeries::clicked(QPieSlice* slice) | |
192 |
|
257 | |||
193 | This signal is emitted when a \a slice has been clicked. |
|
258 | This signal is emitted when a \a slice has been clicked. | |
194 |
|
259 | |||
195 | \sa QPieSlice::clicked() |
|
260 | \sa QPieSlice::clicked() | |
196 | */ |
|
261 | */ | |
197 |
|
262 | |||
198 | /*! |
|
263 | /*! | |
199 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) |
|
264 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) | |
200 |
|
265 | |||
201 | This signal is emitted when user has hovered over or away from the \a slice. |
|
266 | This signal is emitted when user has hovered over or away from the \a slice. | |
202 |
|
267 | |||
203 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
268 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. | |
204 |
|
269 | |||
205 | \sa QPieSlice::hovered() |
|
270 | \sa QPieSlice::hovered() | |
206 | */ |
|
271 | */ | |
207 |
|
272 | |||
208 | /*! |
|
273 | /*! | |
209 | Constructs a series object which is a child of \a parent. |
|
274 | Constructs a series object which is a child of \a parent. | |
210 | */ |
|
275 | */ | |
211 | QPieSeries::QPieSeries(QObject *parent) : |
|
276 | QPieSeries::QPieSeries(QObject *parent) : | |
212 | QAbstractSeries(*new QPieSeriesPrivate(this),parent) |
|
277 | QAbstractSeries(*new QPieSeriesPrivate(this),parent) | |
213 | { |
|
278 | { | |
214 |
|
279 | |||
215 | } |
|
280 | } | |
216 |
|
281 | |||
217 | /*! |
|
282 | /*! | |
218 | Destroys the series and its slices. |
|
283 | Destroys the series and its slices. | |
219 | */ |
|
284 | */ | |
220 | QPieSeries::~QPieSeries() |
|
285 | QPieSeries::~QPieSeries() | |
221 | { |
|
286 | { | |
222 | // NOTE: d_prt destroyed by QObject |
|
287 | // NOTE: d_prt destroyed by QObject | |
223 | } |
|
288 | } | |
224 |
|
289 | |||
225 | /*! |
|
290 | /*! | |
226 | Returns QChartSeries::SeriesTypePie. |
|
291 | Returns QChartSeries::SeriesTypePie. | |
227 | */ |
|
292 | */ | |
228 | QAbstractSeries::SeriesType QPieSeries::type() const |
|
293 | QAbstractSeries::SeriesType QPieSeries::type() const | |
229 | { |
|
294 | { | |
230 | return QAbstractSeries::SeriesTypePie; |
|
295 | return QAbstractSeries::SeriesTypePie; | |
231 | } |
|
296 | } | |
232 |
|
297 | |||
233 | /*! |
|
298 | /*! | |
234 | Appends a single \a slice to the series. |
|
299 | Appends a single \a slice to the series. | |
235 | Slice ownership is passed to the series. |
|
300 | Slice ownership is passed to the series. | |
236 |
|
301 | |||
237 | Returns true if append was succesfull. |
|
302 | Returns true if append was succesfull. | |
238 | */ |
|
303 | */ | |
239 | bool QPieSeries::append(QPieSlice* slice) |
|
304 | bool QPieSeries::append(QPieSlice* slice) | |
240 | { |
|
305 | { | |
241 | return append(QList<QPieSlice*>() << slice); |
|
306 | return append(QList<QPieSlice*>() << slice); | |
242 | } |
|
307 | } | |
243 |
|
308 | |||
244 | /*! |
|
309 | /*! | |
245 | Appends an array of \a slices to the series. |
|
310 | Appends an array of \a slices to the series. | |
246 | Slice ownership is passed to the series. |
|
311 | Slice ownership is passed to the series. | |
247 |
|
312 | |||
248 | Returns true if append was successfull. |
|
313 | Returns true if append was successfull. | |
249 | */ |
|
314 | */ | |
250 | bool QPieSeries::append(QList<QPieSlice*> slices) |
|
315 | bool QPieSeries::append(QList<QPieSlice*> slices) | |
251 | { |
|
316 | { | |
252 | Q_D(QPieSeries); |
|
317 | Q_D(QPieSeries); | |
253 |
|
318 | |||
254 | if (slices.count() == 0) |
|
319 | if (slices.count() == 0) | |
255 | return false; |
|
320 | return false; | |
256 |
|
321 | |||
257 | foreach (QPieSlice* s, slices) { |
|
322 | foreach (QPieSlice* s, slices) { | |
258 | if (!s || d->m_slices.contains(s)) |
|
323 | if (!s || d->m_slices.contains(s)) | |
259 | return false; |
|
324 | return false; | |
260 | if (s->series()) // already added to some series |
|
325 | if (s->series()) // already added to some series | |
261 | return false; |
|
326 | return false; | |
262 | } |
|
327 | } | |
263 |
|
328 | |||
264 | foreach (QPieSlice* s, slices) { |
|
329 | foreach (QPieSlice* s, slices) { | |
265 | s->setParent(this); |
|
330 | s->setParent(this); | |
266 | QPieSlicePrivate::fromSlice(s)->m_series = this; |
|
331 | QPieSlicePrivate::fromSlice(s)->m_series = this; | |
267 | d->m_slices << s; |
|
332 | d->m_slices << s; | |
268 | } |
|
333 | } | |
269 |
|
334 | |||
270 | d->updateDerivativeData(); |
|
335 | d->updateDerivativeData(); | |
271 |
|
336 | |||
272 | foreach (QPieSlice* s, slices) { |
|
337 | foreach (QPieSlice* s, slices) { | |
273 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
338 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
274 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
339 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
275 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
340 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
276 | } |
|
341 | } | |
277 |
|
342 | |||
278 | emit added(slices); |
|
343 | emit added(slices); | |
279 | emit countChanged(); |
|
344 | emit countChanged(); | |
280 |
|
345 | |||
281 | return true; |
|
346 | return true; | |
282 | } |
|
347 | } | |
283 |
|
348 | |||
284 | /*! |
|
349 | /*! | |
285 | Appends a single \a slice to the series and returns a reference to the series. |
|
350 | Appends a single \a slice to the series and returns a reference to the series. | |
286 | Slice ownership is passed to the series. |
|
351 | Slice ownership is passed to the series. | |
287 | */ |
|
352 | */ | |
288 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) |
|
353 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) | |
289 | { |
|
354 | { | |
290 | append(slice); |
|
355 | append(slice); | |
291 | return *this; |
|
356 | return *this; | |
292 | } |
|
357 | } | |
293 |
|
358 | |||
294 |
|
359 | |||
295 | /*! |
|
360 | /*! | |
296 | Appends a single slice to the series with give \a value and \a label. |
|
361 | Appends a single slice to the series with give \a value and \a label. | |
297 | Slice ownership is passed to the series. |
|
362 | Slice ownership is passed to the series. | |
298 | */ |
|
363 | */ | |
299 | QPieSlice* QPieSeries::append(QString label, qreal value) |
|
364 | QPieSlice* QPieSeries::append(QString label, qreal value) | |
300 | { |
|
365 | { | |
301 | QPieSlice* slice = new QPieSlice(label, value); |
|
366 | QPieSlice* slice = new QPieSlice(label, value); | |
302 | append(slice); |
|
367 | append(slice); | |
303 | return slice; |
|
368 | return slice; | |
304 | } |
|
369 | } | |
305 |
|
370 | |||
306 | /*! |
|
371 | /*! | |
307 | Inserts a single \a slice to the series before the slice at \a index position. |
|
372 | Inserts a single \a slice to the series before the slice at \a index position. | |
308 | Slice ownership is passed to the series. |
|
373 | Slice ownership is passed to the series. | |
309 |
|
374 | |||
310 | Returns true if insert was successfull. |
|
375 | Returns true if insert was successfull. | |
311 | */ |
|
376 | */ | |
312 | bool QPieSeries::insert(int index, QPieSlice* slice) |
|
377 | bool QPieSeries::insert(int index, QPieSlice* slice) | |
313 | { |
|
378 | { | |
314 | Q_D(QPieSeries); |
|
379 | Q_D(QPieSeries); | |
315 |
|
380 | |||
316 | if (index < 0 || index > d->m_slices.count()) |
|
381 | if (index < 0 || index > d->m_slices.count()) | |
317 | return false; |
|
382 | return false; | |
318 |
|
383 | |||
319 | if (!slice || d->m_slices.contains(slice)) |
|
384 | if (!slice || d->m_slices.contains(slice)) | |
320 | return false; |
|
385 | return false; | |
321 |
|
386 | |||
322 | if (slice->series()) // already added to some series |
|
387 | if (slice->series()) // already added to some series | |
323 | return false; |
|
388 | return false; | |
324 |
|
389 | |||
325 | slice->setParent(this); |
|
390 | slice->setParent(this); | |
326 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
391 | QPieSlicePrivate::fromSlice(slice)->m_series = this; | |
327 | d->m_slices.insert(index, slice); |
|
392 | d->m_slices.insert(index, slice); | |
328 |
|
393 | |||
329 | d->updateDerivativeData(); |
|
394 | d->updateDerivativeData(); | |
330 |
|
395 | |||
331 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
396 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
332 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
397 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
333 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
398 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
334 |
|
399 | |||
335 | emit added(QList<QPieSlice*>() << slice); |
|
400 | emit added(QList<QPieSlice*>() << slice); | |
336 | emit countChanged(); |
|
401 | emit countChanged(); | |
337 |
|
402 | |||
338 | return true; |
|
403 | return true; | |
339 | } |
|
404 | } | |
340 |
|
405 | |||
341 | /*! |
|
406 | /*! | |
342 | Removes a single \a slice from the series and deletes the slice. |
|
407 | Removes a single \a slice from the series and deletes the slice. | |
343 |
|
408 | |||
344 | Do not reference the pointer after this call. |
|
409 | Do not reference the pointer after this call. | |
345 |
|
410 | |||
346 | Returns true if remove was successfull. |
|
411 | Returns true if remove was successfull. | |
347 | */ |
|
412 | */ | |
348 | bool QPieSeries::remove(QPieSlice* slice) |
|
413 | bool QPieSeries::remove(QPieSlice* slice) | |
349 | { |
|
414 | { | |
350 | Q_D(QPieSeries); |
|
415 | Q_D(QPieSeries); | |
351 |
|
416 | |||
352 | if (!d->m_slices.removeOne(slice)) |
|
417 | if (!d->m_slices.removeOne(slice)) | |
353 | return false; |
|
418 | return false; | |
354 |
|
419 | |||
355 | d->updateDerivativeData(); |
|
420 | d->updateDerivativeData(); | |
356 |
|
421 | |||
357 | emit removed(QList<QPieSlice*>() << slice); |
|
422 | emit removed(QList<QPieSlice*>() << slice); | |
358 | emit countChanged(); |
|
423 | emit countChanged(); | |
359 |
|
424 | |||
360 | delete slice; |
|
425 | delete slice; | |
361 | slice = 0; |
|
426 | slice = 0; | |
362 |
|
427 | |||
363 | return true; |
|
428 | return true; | |
364 | } |
|
429 | } | |
365 |
|
430 | |||
366 | /*! |
|
431 | /*! | |
367 | Clears all slices from the series. |
|
432 | Clears all slices from the series. | |
368 | */ |
|
433 | */ | |
369 | void QPieSeries::clear() |
|
434 | void QPieSeries::clear() | |
370 | { |
|
435 | { | |
371 | Q_D(QPieSeries); |
|
436 | Q_D(QPieSeries); | |
372 | if (d->m_slices.count() == 0) |
|
437 | if (d->m_slices.count() == 0) | |
373 | return; |
|
438 | return; | |
374 |
|
439 | |||
375 | QList<QPieSlice*> slices = d->m_slices; |
|
440 | QList<QPieSlice*> slices = d->m_slices; | |
376 | foreach (QPieSlice* s, d->m_slices) { |
|
441 | foreach (QPieSlice* s, d->m_slices) { | |
377 | d->m_slices.removeOne(s); |
|
442 | d->m_slices.removeOne(s); | |
378 | delete s; |
|
443 | delete s; | |
379 | } |
|
444 | } | |
380 |
|
445 | |||
381 | d->updateDerivativeData(); |
|
446 | d->updateDerivativeData(); | |
382 |
|
447 | |||
383 | emit removed(slices); |
|
448 | emit removed(slices); | |
384 | emit countChanged(); |
|
449 | emit countChanged(); | |
385 | } |
|
450 | } | |
386 |
|
451 | |||
387 | /*! |
|
452 | /*! | |
388 | Returns a list of slices that belong to this series. |
|
453 | Returns a list of slices that belong to this series. | |
389 | */ |
|
454 | */ | |
390 | QList<QPieSlice*> QPieSeries::slices() const |
|
455 | QList<QPieSlice*> QPieSeries::slices() const | |
391 | { |
|
456 | { | |
392 | Q_D(const QPieSeries); |
|
457 | Q_D(const QPieSeries); | |
393 | return d->m_slices; |
|
458 | return d->m_slices; | |
394 | } |
|
459 | } | |
395 |
|
460 | |||
396 | /*! |
|
461 | /*! | |
397 | returns the number of the slices in this series. |
|
462 | returns the number of the slices in this series. | |
398 | */ |
|
463 | */ | |
399 | int QPieSeries::count() const |
|
464 | int QPieSeries::count() const | |
400 | { |
|
465 | { | |
401 | Q_D(const QPieSeries); |
|
466 | Q_D(const QPieSeries); | |
402 | return d->m_slices.count(); |
|
467 | return d->m_slices.count(); | |
403 | } |
|
468 | } | |
404 |
|
469 | |||
405 | /*! |
|
470 | /*! | |
406 | Returns true is the series is empty. |
|
471 | Returns true is the series is empty. | |
407 | */ |
|
472 | */ | |
408 | bool QPieSeries::isEmpty() const |
|
473 | bool QPieSeries::isEmpty() const | |
409 | { |
|
474 | { | |
410 | Q_D(const QPieSeries); |
|
475 | Q_D(const QPieSeries); | |
411 | return d->m_slices.isEmpty(); |
|
476 | return d->m_slices.isEmpty(); | |
412 | } |
|
477 | } | |
413 |
|
478 | |||
414 | /*! |
|
479 | /*! | |
415 | Returns the sum of all slice values in this series. |
|
480 | Returns the sum of all slice values in this series. | |
416 |
|
481 | |||
417 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
482 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() | |
418 | */ |
|
483 | */ | |
419 | qreal QPieSeries::sum() const |
|
484 | qreal QPieSeries::sum() const | |
420 | { |
|
485 | { | |
421 | Q_D(const QPieSeries); |
|
486 | Q_D(const QPieSeries); | |
422 | return d->m_sum; |
|
487 | return d->m_sum; | |
423 | } |
|
488 | } | |
424 |
|
489 | |||
425 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
490 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
426 | { |
|
491 | { | |
427 | Q_D(QPieSeries); |
|
492 | Q_D(QPieSeries); | |
428 |
|
493 | |||
429 | if (relativePosition < 0.0) |
|
494 | if (relativePosition < 0.0) | |
430 | relativePosition = 0.0; |
|
495 | relativePosition = 0.0; | |
431 | if (relativePosition > 1.0) |
|
496 | if (relativePosition > 1.0) | |
432 | relativePosition = 1.0; |
|
497 | relativePosition = 1.0; | |
433 |
|
498 | |||
434 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { |
|
499 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { | |
435 | d->m_pieRelativeHorPos = relativePosition; |
|
500 | d->m_pieRelativeHorPos = relativePosition; | |
436 | emit d->horizontalPositionChanged(); |
|
501 | emit d->horizontalPositionChanged(); | |
437 | } |
|
502 | } | |
438 | } |
|
503 | } | |
439 |
|
504 | |||
440 | qreal QPieSeries::horizontalPosition() const |
|
505 | qreal QPieSeries::horizontalPosition() const | |
441 | { |
|
506 | { | |
442 | Q_D(const QPieSeries); |
|
507 | Q_D(const QPieSeries); | |
443 | return d->m_pieRelativeHorPos; |
|
508 | return d->m_pieRelativeHorPos; | |
444 | } |
|
509 | } | |
445 |
|
510 | |||
446 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
511 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
447 | { |
|
512 | { | |
448 | Q_D(QPieSeries); |
|
513 | Q_D(QPieSeries); | |
449 |
|
514 | |||
450 | if (relativePosition < 0.0) |
|
515 | if (relativePosition < 0.0) | |
451 | relativePosition = 0.0; |
|
516 | relativePosition = 0.0; | |
452 | if (relativePosition > 1.0) |
|
517 | if (relativePosition > 1.0) | |
453 | relativePosition = 1.0; |
|
518 | relativePosition = 1.0; | |
454 |
|
519 | |||
455 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { |
|
520 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { | |
456 | d->m_pieRelativeVerPos = relativePosition; |
|
521 | d->m_pieRelativeVerPos = relativePosition; | |
457 | emit d->verticalPositionChanged(); |
|
522 | emit d->verticalPositionChanged(); | |
458 | } |
|
523 | } | |
459 | } |
|
524 | } | |
460 |
|
525 | |||
461 | qreal QPieSeries::verticalPosition() const |
|
526 | qreal QPieSeries::verticalPosition() const | |
462 | { |
|
527 | { | |
463 | Q_D(const QPieSeries); |
|
528 | Q_D(const QPieSeries); | |
464 | return d->m_pieRelativeVerPos; |
|
529 | return d->m_pieRelativeVerPos; | |
465 | } |
|
530 | } | |
466 |
|
531 | |||
467 | void QPieSeries::setPieSize(qreal relativeSize) |
|
532 | void QPieSeries::setPieSize(qreal relativeSize) | |
468 | { |
|
533 | { | |
469 | Q_D(QPieSeries); |
|
534 | Q_D(QPieSeries); | |
470 |
|
535 | |||
471 | if (relativeSize < 0.0) |
|
536 | if (relativeSize < 0.0) | |
472 | relativeSize = 0.0; |
|
537 | relativeSize = 0.0; | |
473 | if (relativeSize > 1.0) |
|
538 | if (relativeSize > 1.0) | |
474 | relativeSize = 1.0; |
|
539 | relativeSize = 1.0; | |
475 |
|
540 | |||
476 | if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) { |
|
541 | if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) { | |
477 | d->m_pieRelativeSize = relativeSize; |
|
542 | d->m_pieRelativeSize = relativeSize; | |
478 | emit d->pieSizeChanged(); |
|
543 | emit d->pieSizeChanged(); | |
479 | } |
|
544 | } | |
480 | } |
|
545 | } | |
481 |
|
546 | |||
482 | qreal QPieSeries::pieSize() const |
|
547 | qreal QPieSeries::pieSize() const | |
483 | { |
|
548 | { | |
484 | Q_D(const QPieSeries); |
|
549 | Q_D(const QPieSeries); | |
485 | return d->m_pieRelativeSize; |
|
550 | return d->m_pieRelativeSize; | |
486 | } |
|
551 | } | |
487 |
|
552 | |||
488 |
|
553 | |||
489 | void QPieSeries::setPieStartAngle(qreal angle) |
|
554 | void QPieSeries::setPieStartAngle(qreal angle) | |
490 | { |
|
555 | { | |
491 | Q_D(QPieSeries); |
|
556 | Q_D(QPieSeries); | |
492 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) |
|
557 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) | |
493 | return; |
|
558 | return; | |
494 | d->m_pieStartAngle = angle; |
|
559 | d->m_pieStartAngle = angle; | |
495 | d->updateDerivativeData(); |
|
560 | d->updateDerivativeData(); | |
496 | emit d->pieStartAngleChanged(); |
|
561 | emit d->pieStartAngleChanged(); | |
497 | } |
|
562 | } | |
498 |
|
563 | |||
499 | qreal QPieSeries::pieStartAngle() const |
|
564 | qreal QPieSeries::pieStartAngle() const | |
500 | { |
|
565 | { | |
501 | Q_D(const QPieSeries); |
|
566 | Q_D(const QPieSeries); | |
502 | return d->m_pieStartAngle; |
|
567 | return d->m_pieStartAngle; | |
503 | } |
|
568 | } | |
504 |
|
569 | |||
505 | /*! |
|
570 | /*! | |
506 | Sets the end angle of the pie. |
|
571 | Sets the end angle of the pie. | |
507 |
|
572 | |||
508 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
573 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
509 |
|
574 | |||
510 | \a angle must be greater than start angle. |
|
575 | \a angle must be greater than start angle. | |
511 |
|
576 | |||
512 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
577 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
513 | */ |
|
578 | */ | |
514 | void QPieSeries::setPieEndAngle(qreal angle) |
|
579 | void QPieSeries::setPieEndAngle(qreal angle) | |
515 | { |
|
580 | { | |
516 | Q_D(QPieSeries); |
|
581 | Q_D(QPieSeries); | |
517 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) |
|
582 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) | |
518 | return; |
|
583 | return; | |
519 | d->m_pieEndAngle = angle; |
|
584 | d->m_pieEndAngle = angle; | |
520 | d->updateDerivativeData(); |
|
585 | d->updateDerivativeData(); | |
521 | emit d->pieEndAngleChanged(); |
|
586 | emit d->pieEndAngleChanged(); | |
522 | } |
|
587 | } | |
523 |
|
588 | |||
524 | /*! |
|
589 | /*! | |
525 | Returns the end angle of the pie. |
|
590 | Returns the end angle of the pie. | |
526 |
|
591 | |||
527 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
592 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
528 |
|
593 | |||
529 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
594 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
530 | */ |
|
595 | */ | |
531 | qreal QPieSeries::pieEndAngle() const |
|
596 | qreal QPieSeries::pieEndAngle() const | |
532 | { |
|
597 | { | |
533 | Q_D(const QPieSeries); |
|
598 | Q_D(const QPieSeries); | |
534 | return d->m_pieEndAngle; |
|
599 | return d->m_pieEndAngle; | |
535 | } |
|
600 | } | |
536 |
|
601 | |||
537 | /*! |
|
602 | /*! | |
538 | Sets the all the slice labels \a visible or invisible. |
|
603 | Sets the all the slice labels \a visible or invisible. | |
539 |
|
604 | |||
540 | Note that this affects only the current slices in the series. |
|
605 | Note that this affects only the current slices in the series. | |
541 | If user adds a new slice the default label visibility is false. |
|
606 | If user adds a new slice the default label visibility is false. | |
542 |
|
607 | |||
543 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
608 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
544 | */ |
|
609 | */ | |
545 | void QPieSeries::setLabelsVisible(bool visible) |
|
610 | void QPieSeries::setLabelsVisible(bool visible) | |
546 | { |
|
611 | { | |
547 | Q_D(QPieSeries); |
|
612 | Q_D(QPieSeries); | |
548 | foreach (QPieSlice* s, d->m_slices) |
|
613 | foreach (QPieSlice* s, d->m_slices) | |
549 | s->setLabelVisible(visible); |
|
614 | s->setLabelVisible(visible); | |
550 | } |
|
615 | } | |
551 |
|
616 | |||
552 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
617 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
553 |
|
618 | |||
554 |
|
619 | |||
555 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
620 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | |
556 | QAbstractSeriesPrivate(parent), |
|
621 | QAbstractSeriesPrivate(parent), | |
557 | m_pieRelativeHorPos(0.5), |
|
622 | m_pieRelativeHorPos(0.5), | |
558 | m_pieRelativeVerPos(0.5), |
|
623 | m_pieRelativeVerPos(0.5), | |
559 | m_pieRelativeSize(0.7), |
|
624 | m_pieRelativeSize(0.7), | |
560 | m_pieStartAngle(0), |
|
625 | m_pieStartAngle(0), | |
561 | m_pieEndAngle(360), |
|
626 | m_pieEndAngle(360), | |
562 | m_sum(0) |
|
627 | m_sum(0) | |
563 | { |
|
628 | { | |
564 | } |
|
629 | } | |
565 |
|
630 | |||
566 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
631 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
567 | { |
|
632 | { | |
568 | } |
|
633 | } | |
569 |
|
634 | |||
570 | void QPieSeriesPrivate::updateDerivativeData() |
|
635 | void QPieSeriesPrivate::updateDerivativeData() | |
571 | { |
|
636 | { | |
572 | // calculate sum of all slices |
|
637 | // calculate sum of all slices | |
573 | qreal sum = 0; |
|
638 | qreal sum = 0; | |
574 | foreach (QPieSlice* s, m_slices) |
|
639 | foreach (QPieSlice* s, m_slices) | |
575 | sum += s->value(); |
|
640 | sum += s->value(); | |
576 |
|
641 | |||
577 | if (!qFuzzyIsNull(m_sum - sum)) { |
|
642 | if (!qFuzzyIsNull(m_sum - sum)) { | |
578 | m_sum = sum; |
|
643 | m_sum = sum; | |
579 | emit q_func()->sumChanged(); |
|
644 | emit q_func()->sumChanged(); | |
580 | } |
|
645 | } | |
581 |
|
646 | |||
582 | // nothing to show.. |
|
647 | // nothing to show.. | |
583 | if (qFuzzyIsNull(m_sum)) |
|
648 | if (qFuzzyIsNull(m_sum)) | |
584 | return; |
|
649 | return; | |
585 |
|
650 | |||
586 | // update slice attributes |
|
651 | // update slice attributes | |
587 | qreal sliceAngle = m_pieStartAngle; |
|
652 | qreal sliceAngle = m_pieStartAngle; | |
588 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
653 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
589 | QVector<QPieSlice*> changed; |
|
654 | QVector<QPieSlice*> changed; | |
590 | foreach (QPieSlice* s, m_slices) { |
|
655 | foreach (QPieSlice* s, m_slices) { | |
591 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
656 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
592 | d->setPercentage(s->value() / m_sum); |
|
657 | d->setPercentage(s->value() / m_sum); | |
593 | d->setStartAngle(sliceAngle); |
|
658 | d->setStartAngle(sliceAngle); | |
594 | d->setAngleSpan(pieSpan * s->percentage()); |
|
659 | d->setAngleSpan(pieSpan * s->percentage()); | |
595 | sliceAngle += s->angleSpan(); |
|
660 | sliceAngle += s->angleSpan(); | |
596 | } |
|
661 | } | |
597 |
|
662 | |||
598 |
|
663 | |||
599 | emit calculatedDataChanged(); |
|
664 | emit calculatedDataChanged(); | |
600 | } |
|
665 | } | |
601 |
|
666 | |||
602 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
667 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) | |
603 | { |
|
668 | { | |
604 | return series->d_func(); |
|
669 | return series->d_func(); | |
605 | } |
|
670 | } | |
606 |
|
671 | |||
607 | void QPieSeriesPrivate::sliceValueChanged() |
|
672 | void QPieSeriesPrivate::sliceValueChanged() | |
608 | { |
|
673 | { | |
609 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
674 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
610 | updateDerivativeData(); |
|
675 | updateDerivativeData(); | |
611 | } |
|
676 | } | |
612 |
|
677 | |||
613 | void QPieSeriesPrivate::sliceClicked() |
|
678 | void QPieSeriesPrivate::sliceClicked() | |
614 | { |
|
679 | { | |
615 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
680 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
616 | Q_ASSERT(m_slices.contains(slice)); |
|
681 | Q_ASSERT(m_slices.contains(slice)); | |
617 | Q_Q(QPieSeries); |
|
682 | Q_Q(QPieSeries); | |
618 | emit q->clicked(slice); |
|
683 | emit q->clicked(slice); | |
619 | } |
|
684 | } | |
620 |
|
685 | |||
621 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
686 | void QPieSeriesPrivate::sliceHovered(bool state) | |
622 | { |
|
687 | { | |
623 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
688 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
624 | Q_ASSERT(m_slices.contains(slice)); |
|
689 | Q_ASSERT(m_slices.contains(slice)); | |
625 | Q_Q(QPieSeries); |
|
690 | Q_Q(QPieSeries); | |
626 | emit q->hovered(slice, state); |
|
691 | emit q->hovered(slice, state); | |
627 | } |
|
692 | } | |
628 |
|
693 | |||
629 | void QPieSeriesPrivate::scaleDomain(Domain& domain) |
|
694 | void QPieSeriesPrivate::scaleDomain(Domain& domain) | |
630 | { |
|
695 | { | |
631 | Q_UNUSED(domain); |
|
696 | Q_UNUSED(domain); | |
632 | // does not apply to pie |
|
697 | // does not apply to pie | |
633 | } |
|
698 | } | |
634 |
|
699 | |||
635 | Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
700 | Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
636 | { |
|
701 | { | |
637 | Q_Q(QPieSeries); |
|
702 | Q_Q(QPieSeries); | |
638 | PieChartItem* pie = new PieChartItem(q,presenter); |
|
703 | PieChartItem* pie = new PieChartItem(q,presenter); | |
639 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
704 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
640 | presenter->animator()->addAnimation(pie); |
|
705 | presenter->animator()->addAnimation(pie); | |
641 | } |
|
706 | } | |
642 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
707 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
643 | return pie; |
|
708 | return pie; | |
644 | } |
|
709 | } | |
645 |
|
710 | |||
646 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) |
|
711 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) | |
647 | { |
|
712 | { | |
648 | Q_Q(QPieSeries); |
|
713 | Q_Q(QPieSeries); | |
649 | QList<LegendMarker*> markers; |
|
714 | QList<LegendMarker*> markers; | |
650 | foreach(QPieSlice* slice, q->slices()) { |
|
715 | foreach(QPieSlice* slice, q->slices()) { | |
651 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); |
|
716 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); | |
652 | markers << marker; |
|
717 | markers << marker; | |
653 | } |
|
718 | } | |
654 | return markers; |
|
719 | return markers; | |
655 | } |
|
720 | } | |
656 |
|
721 | |||
657 | #include "moc_qpieseries.cpp" |
|
722 | #include "moc_qpieseries.cpp" | |
658 | #include "moc_qpieseries_p.cpp" |
|
723 | #include "moc_qpieseries_p.cpp" | |
659 |
|
724 | |||
660 | QTCOMMERCIALCHART_END_NAMESPACE |
|
725 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now