##// END OF EJS Templates
Inner pie (donut) size cannot be smaller than the outer pie size
Marek Rosa -
r1741:5e93b5bfe418
parent child
Show More
@@ -1,82 +1,76
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 <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QLineSeries>
24 #include <QLineSeries>
25 #include <QDateTime>
25 #include <QDateTime>
26 #include <QDateTimeAxis>
26 #include <QDateTimeAxis>
27
27
28 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
29
29
30 int main(int argc, char *argv[])
30 int main(int argc, char *argv[])
31 {
31 {
32 QApplication a(argc, argv);
32 QApplication a(argc, argv);
33 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
33 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
34
34
35 //![1]
35 //![1]
36 QLineSeries* series = new QLineSeries();
36 QLineSeries* series = new QLineSeries();
37 //![1]
37 //![1]
38
38
39 //![2]
39 //![2]
40 QDateTime momentInTime;
40 QDateTime momentInTime;
41 for (int i = 0; i < 100; i++) {
41 for (int i = 0; i < 200; i++) {
42 momentInTime.setDate(QDate(2012, 1 , (1 + i / 9) % 28));
42 momentInTime.setDate(QDate(2012, 1 , (1 + i / 9) % 28));
43 momentInTime.setTime(QTime(9 + i % 9, 0));
43 momentInTime.setTime(QTime(9 + i % 9, 0));
44 if (i > 0)
44 if (i > 0)
45 series->append(momentInTime.toMSecsSinceEpoch(), series->points().at(i - 1).y() * (0.95 + (qrand() % 11) / 100.0));
45 series->append(momentInTime.toMSecsSinceEpoch(), series->points().at(i - 1).y() * (0.99 + (qrand() % 3) / 100.0));
46 else
46 else
47 series->append(momentInTime.toMSecsSinceEpoch(), 45);
47 series->append(momentInTime.toMSecsSinceEpoch(), 45);
48 }
48 }
49 //![2]
49 //![2]
50
50
51 //![3]
51 //![3]
52 QChart* chart = new QChart();
52 QChart* chart = new QChart();
53 chart->legend()->hide();
53 chart->legend()->hide();
54 chart->addSeries(series);
54 chart->addSeries(series);
55 chart->createDefaultAxes();
55 chart->createDefaultAxes();
56 QDateTimeAxis *axisX = new QDateTimeAxis;
56 QDateTimeAxis *axisX = new QDateTimeAxis;
57 axisX->setTicksCount(20);
57 // axisX->setTicksCount(10);
58 momentInTime.setDate(QDate(2012,1,1));
59 momentInTime.setTime(QTime(6, 0));
60 axisX->setMin(momentInTime);
61 momentInTime.setDate(QDate(2012,1,7));
62 momentInTime.setTime(QTime(18, 0));
63 axisX->setMax(momentInTime);
64 chart->setAxisX(axisX, series);
58 chart->setAxisX(axisX, series);
65 chart->setTitle("Date and Time axis chart example");
59 chart->setTitle("Date and Time axis chart example");
66 //![3]
60 //![3]
67
61
68 //![4]
62 //![4]
69 QChartView* chartView = new QChartView(chart);
63 QChartView* chartView = new QChartView(chart);
70 chartView->setRenderHint(QPainter::Antialiasing);
64 chartView->setRenderHint(QPainter::Antialiasing);
71 //![4]
65 //![4]
72
66
73
67
74 //![5]
68 //![5]
75 QMainWindow window;
69 QMainWindow window;
76 window.setCentralWidget(chartView);
70 window.setCentralWidget(chartView);
77 window.resize(800, 600);
71 window.resize(800, 600);
78 window.show();
72 window.show();
79 //![5]
73 //![5]
80
74
81 return a.exec();
75 return a.exec();
82 }
76 }
@@ -1,857 +1,864
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.
136
135 Default value is 0.7.
137 Default value is 0.7.
136 */
138 */
137
139
138 /*!
140 /*!
139 \qmlproperty real PieSeries::size
141 \qmlproperty real PieSeries::size
140
142
141 Defines the pie size.
143 Defines the pie size.
142
144
143 The value is a relative value to the chart rectangle where:
145 The value is a relative value to the chart rectangle where:
144
146
145 \list
147 \list
146 \o 0.0 is the minimum size (pie not drawn).
148 \o 0.0 is the minimum size (pie not drawn).
147 \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.
148 \endlist
150 \endlist
149
151
150 Default value is 0.7.
152 Default value is 0.7.
151 */
153 */
152
154
153 /*!
155 /*!
154 \property QPieSeries::donutInnerSize
156 \property QPieSeries::donutInnerSize
155 \brief Defines the donut inner size.
157 \brief Defines the donut inner size.
156
158
157 The value is a relative value to the chart rectangle where:
159 The value is a relative value to the chart rectangle where:
158
160
159 \list
161 \list
160 \o 0.0 is the minimum size (pie not drawn).
162 \o 0.0 is the minimum size (pie not drawn).
161 \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)
162 \endlist
164 \endlist
163
165
164 The value is never greater then size property.
166 The value is never greater then size property.
165 Default value is 0.5.
167 Default value is 0.5.
166 */
168 */
167
169
168 /*!
170 /*!
169 \qmlproperty real PieSeries::donutInnerSize
171 \qmlproperty real PieSeries::donutInnerSize
170
172
171 Defines the donut inner size.
173 Defines the donut inner size.
172
174
173 The value is a relative value to the chart rectangle where:
175 The value is a relative value to the chart rectangle where:
174
176
175 \list
177 \list
176 \o 0.0 is the minimum size (donut is a pie).
178 \o 0.0 is the minimum size (donut is a pie).
177 \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)
178 \endlist
180 \endlist
179
181
180 The value is never greater then size property.
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
181 Default value is 0.5.
184 Default value is 0.5.
182 */
185 */
183
186
184 /*!
187 /*!
185 \property QPieSeries::startAngle
188 \property QPieSeries::startAngle
186 \brief Defines the starting angle of the pie.
189 \brief Defines the starting angle of the pie.
187
190
188 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.
189
192
190 Default is value is 0.
193 Default is value is 0.
191 */
194 */
192
195
193 /*!
196 /*!
194 \qmlproperty real PieSeries::startAngle
197 \qmlproperty real PieSeries::startAngle
195
198
196 Defines the starting angle of the pie.
199 Defines the starting angle of the pie.
197
200
198 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.
199
202
200 Default is value is 0.
203 Default is value is 0.
201 */
204 */
202
205
203 /*!
206 /*!
204 \property QPieSeries::endAngle
207 \property QPieSeries::endAngle
205 \brief Defines the ending angle of the pie.
208 \brief Defines the ending angle of the pie.
206
209
207 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.
208
211
209 Default is value is 360.
212 Default is value is 360.
210 */
213 */
211
214
212 /*!
215 /*!
213 \qmlproperty real PieSeries::endAngle
216 \qmlproperty real PieSeries::endAngle
214
217
215 Defines the ending angle of the pie.
218 Defines the ending angle of the pie.
216
219
217 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.
218
221
219 Default is value is 360.
222 Default is value is 360.
220 */
223 */
221
224
222 /*!
225 /*!
223 \property QPieSeries::count
226 \property QPieSeries::count
224
227
225 Number of slices in the series.
228 Number of slices in the series.
226 */
229 */
227
230
228 /*!
231 /*!
229 \qmlproperty int PieSeries::count
232 \qmlproperty int PieSeries::count
230
233
231 Number of slices in the series.
234 Number of slices in the series.
232 */
235 */
233
236
234 /*!
237 /*!
235 \property QPieSeries::donut
238 \property QPieSeries::donut
236
239
237 Defines whether the series should be drawn as a donut
240 Defines whether the series should be drawn as a donut
238 */
241 */
239
242
240 /*!
243 /*!
241 \qmlproperty int PieSeries::donut
244 \qmlproperty int PieSeries::donut
242
245
243 Defines whether the series should be drawn as a donut
246 Defines whether the series should be drawn as a donut
244 */
247 */
245
248
246 /*!
249 /*!
247 \fn void QPieSeries::countChanged()
250 \fn void QPieSeries::countChanged()
248 Emitted when the slice count has changed.
251 Emitted when the slice count has changed.
249 \sa count
252 \sa count
250 */
253 */
251 /*!
254 /*!
252 \qmlsignal PieSeries::onCountChanged()
255 \qmlsignal PieSeries::onCountChanged()
253 Emitted when the slice count has changed.
256 Emitted when the slice count has changed.
254 */
257 */
255
258
256 /*!
259 /*!
257 \property QPieSeries::sum
260 \property QPieSeries::sum
258
261
259 Sum of all slices.
262 Sum of all slices.
260
263
261 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.
262 */
265 */
263
266
264 /*!
267 /*!
265 \qmlproperty real PieSeries::sum
268 \qmlproperty real PieSeries::sum
266
269
267 Sum of all slices.
270 Sum of all slices.
268
271
269 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.
270 */
273 */
271
274
272 /*!
275 /*!
273 \fn void QPieSeries::sumChanged()
276 \fn void QPieSeries::sumChanged()
274 Emitted when the sum of all slices has changed.
277 Emitted when the sum of all slices has changed.
275 \sa sum
278 \sa sum
276 */
279 */
277 /*!
280 /*!
278 \qmlsignal PieSeries::onSumChanged()
281 \qmlsignal PieSeries::onSumChanged()
279 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
280 change value of a slice.
283 change value of a slice.
281 */
284 */
282
285
283 /*!
286 /*!
284 \fn void QPieSeries::added(QList<QPieSlice*> slices)
287 \fn void QPieSeries::added(QList<QPieSlice*> slices)
285
288
286 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.
287
290
288 \sa append(), insert()
291 \sa append(), insert()
289 */
292 */
290 /*!
293 /*!
291 \qmlsignal PieSeries::onAdded(PieSlice slice)
294 \qmlsignal PieSeries::onAdded(PieSlice slice)
292 Emitted when \a slice has been added to the series.
295 Emitted when \a slice has been added to the series.
293 */
296 */
294
297
295 /*!
298 /*!
296 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
299 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
297 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.
298 \sa remove()
301 \sa remove()
299 */
302 */
300 /*!
303 /*!
301 \qmlsignal PieSeries::onRemoved(PieSlice slice)
304 \qmlsignal PieSeries::onRemoved(PieSlice slice)
302 Emitted when \a slice has been removed from the series.
305 Emitted when \a slice has been removed from the series.
303 */
306 */
304
307
305 /*!
308 /*!
306 \fn void QPieSeries::clicked(QPieSlice* slice)
309 \fn void QPieSeries::clicked(QPieSlice* slice)
307 This signal is emitted when a \a slice has been clicked.
310 This signal is emitted when a \a slice has been clicked.
308 \sa QPieSlice::clicked()
311 \sa QPieSlice::clicked()
309 */
312 */
310 /*!
313 /*!
311 \qmlsignal PieSeries::onClicked(PieSlice slice)
314 \qmlsignal PieSeries::onClicked(PieSlice slice)
312 This signal is emitted when a \a slice has been clicked.
315 This signal is emitted when a \a slice has been clicked.
313 */
316 */
314
317
315 /*!
318 /*!
316 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
319 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
317 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.
318 \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.
319 \sa QPieSlice::hovered()
322 \sa QPieSlice::hovered()
320 */
323 */
321 /*!
324 /*!
322 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
325 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
323 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
324 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.
325 */
328 */
326
329
327 /*!
330 /*!
328 \qmlmethod PieSlice PieSeries::at(int index)
331 \qmlmethod PieSlice PieSeries::at(int index)
329 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.
330 */
333 */
331
334
332 /*!
335 /*!
333 \qmlmethod PieSlice PieSeries::find(string label)
336 \qmlmethod PieSlice PieSeries::find(string label)
334 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.
335 */
338 */
336
339
337 /*!
340 /*!
338 \qmlmethod PieSlice PieSeries::append(string label, real value)
341 \qmlmethod PieSlice PieSeries::append(string label, real value)
339 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.
340 */
343 */
341
344
342 /*!
345 /*!
343 \qmlmethod bool PieSeries::remove(PieSlice slice)
346 \qmlmethod bool PieSeries::remove(PieSlice slice)
344 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.
345 */
348 */
346
349
347 /*!
350 /*!
348 \qmlmethod PieSeries::clear()
351 \qmlmethod PieSeries::clear()
349 Removes all slices from the pie.
352 Removes all slices from the pie.
350 */
353 */
351
354
352 /*!
355 /*!
353 Constructs a series object which is a child of \a parent.
356 Constructs a series object which is a child of \a parent.
354 */
357 */
355 QPieSeries::QPieSeries(QObject *parent) :
358 QPieSeries::QPieSeries(QObject *parent) :
356 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
359 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
357 {
360 {
358
361
359 }
362 }
360
363
361 /*!
364 /*!
362 Destroys the series and its slices.
365 Destroys the series and its slices.
363 */
366 */
364 QPieSeries::~QPieSeries()
367 QPieSeries::~QPieSeries()
365 {
368 {
366 // NOTE: d_prt destroyed by QObject
369 // NOTE: d_prt destroyed by QObject
367 }
370 }
368
371
369 /*!
372 /*!
370 Returns QChartSeries::SeriesTypePie.
373 Returns QChartSeries::SeriesTypePie.
371 */
374 */
372 QAbstractSeries::SeriesType QPieSeries::type() const
375 QAbstractSeries::SeriesType QPieSeries::type() const
373 {
376 {
374 return QAbstractSeries::SeriesTypePie;
377 return QAbstractSeries::SeriesTypePie;
375 }
378 }
376
379
377 /*!
380 /*!
378 Appends a single \a slice to the series.
381 Appends a single \a slice to the series.
379 Slice ownership is passed to the series.
382 Slice ownership is passed to the series.
380
383
381 Returns true if append was succesfull.
384 Returns true if append was succesfull.
382 */
385 */
383 bool QPieSeries::append(QPieSlice* slice)
386 bool QPieSeries::append(QPieSlice* slice)
384 {
387 {
385 return append(QList<QPieSlice*>() << slice);
388 return append(QList<QPieSlice*>() << slice);
386 }
389 }
387
390
388 /*!
391 /*!
389 Appends an array of \a slices to the series.
392 Appends an array of \a slices to the series.
390 Slice ownership is passed to the series.
393 Slice ownership is passed to the series.
391
394
392 Returns true if append was successfull.
395 Returns true if append was successfull.
393 */
396 */
394 bool QPieSeries::append(QList<QPieSlice*> slices)
397 bool QPieSeries::append(QList<QPieSlice*> slices)
395 {
398 {
396 Q_D(QPieSeries);
399 Q_D(QPieSeries);
397
400
398 if (slices.count() == 0)
401 if (slices.count() == 0)
399 return false;
402 return false;
400
403
401 foreach (QPieSlice* s, slices) {
404 foreach (QPieSlice* s, slices) {
402 if (!s || d->m_slices.contains(s))
405 if (!s || d->m_slices.contains(s))
403 return false;
406 return false;
404 if (s->series()) // already added to some series
407 if (s->series()) // already added to some series
405 return false;
408 return false;
406 }
409 }
407
410
408 foreach (QPieSlice* s, slices) {
411 foreach (QPieSlice* s, slices) {
409 s->setParent(this);
412 s->setParent(this);
410 QPieSlicePrivate::fromSlice(s)->m_series = this;
413 QPieSlicePrivate::fromSlice(s)->m_series = this;
411 d->m_slices << s;
414 d->m_slices << s;
412 }
415 }
413
416
414 d->updateDerivativeData();
417 d->updateDerivativeData();
415
418
416 foreach (QPieSlice* s, slices) {
419 foreach (QPieSlice* s, slices) {
417 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
420 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
418 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
421 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
419 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
422 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
420 }
423 }
421
424
422 emit added(slices);
425 emit added(slices);
423 emit countChanged();
426 emit countChanged();
424
427
425 return true;
428 return true;
426 }
429 }
427
430
428 /*!
431 /*!
429 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.
430 Slice ownership is passed to the series.
433 Slice ownership is passed to the series.
431 */
434 */
432 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
435 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
433 {
436 {
434 append(slice);
437 append(slice);
435 return *this;
438 return *this;
436 }
439 }
437
440
438
441
439 /*!
442 /*!
440 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.
441 Slice ownership is passed to the series.
444 Slice ownership is passed to the series.
442 */
445 */
443 QPieSlice* QPieSeries::append(QString label, qreal value)
446 QPieSlice* QPieSeries::append(QString label, qreal value)
444 {
447 {
445 QPieSlice* slice = new QPieSlice(label, value);
448 QPieSlice* slice = new QPieSlice(label, value);
446 append(slice);
449 append(slice);
447 return slice;
450 return slice;
448 }
451 }
449
452
450 /*!
453 /*!
451 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.
452 Slice ownership is passed to the series.
455 Slice ownership is passed to the series.
453
456
454 Returns true if insert was successfull.
457 Returns true if insert was successfull.
455 */
458 */
456 bool QPieSeries::insert(int index, QPieSlice* slice)
459 bool QPieSeries::insert(int index, QPieSlice* slice)
457 {
460 {
458 Q_D(QPieSeries);
461 Q_D(QPieSeries);
459
462
460 if (index < 0 || index > d->m_slices.count())
463 if (index < 0 || index > d->m_slices.count())
461 return false;
464 return false;
462
465
463 if (!slice || d->m_slices.contains(slice))
466 if (!slice || d->m_slices.contains(slice))
464 return false;
467 return false;
465
468
466 if (slice->series()) // already added to some series
469 if (slice->series()) // already added to some series
467 return false;
470 return false;
468
471
469 slice->setParent(this);
472 slice->setParent(this);
470 QPieSlicePrivate::fromSlice(slice)->m_series = this;
473 QPieSlicePrivate::fromSlice(slice)->m_series = this;
471 d->m_slices.insert(index, slice);
474 d->m_slices.insert(index, slice);
472
475
473 d->updateDerivativeData();
476 d->updateDerivativeData();
474
477
475 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
478 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
476 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
479 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
477 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
480 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
478
481
479 emit added(QList<QPieSlice*>() << slice);
482 emit added(QList<QPieSlice*>() << slice);
480 emit countChanged();
483 emit countChanged();
481
484
482 return true;
485 return true;
483 }
486 }
484
487
485 /*!
488 /*!
486 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.
487
490
488 Do not reference the pointer after this call.
491 Do not reference the pointer after this call.
489
492
490 Returns true if remove was successfull.
493 Returns true if remove was successfull.
491 */
494 */
492 bool QPieSeries::remove(QPieSlice* slice)
495 bool QPieSeries::remove(QPieSlice* slice)
493 {
496 {
494 Q_D(QPieSeries);
497 Q_D(QPieSeries);
495
498
496 if (!d->m_slices.removeOne(slice))
499 if (!d->m_slices.removeOne(slice))
497 return false;
500 return false;
498
501
499 d->updateDerivativeData();
502 d->updateDerivativeData();
500
503
501 emit removed(QList<QPieSlice*>() << slice);
504 emit removed(QList<QPieSlice*>() << slice);
502 emit countChanged();
505 emit countChanged();
503
506
504 delete slice;
507 delete slice;
505 slice = 0;
508 slice = 0;
506
509
507 return true;
510 return true;
508 }
511 }
509
512
510 /*!
513 /*!
511 Clears all slices from the series.
514 Clears all slices from the series.
512 */
515 */
513 void QPieSeries::clear()
516 void QPieSeries::clear()
514 {
517 {
515 Q_D(QPieSeries);
518 Q_D(QPieSeries);
516 if (d->m_slices.count() == 0)
519 if (d->m_slices.count() == 0)
517 return;
520 return;
518
521
519 QList<QPieSlice*> slices = d->m_slices;
522 QList<QPieSlice*> slices = d->m_slices;
520 foreach (QPieSlice* s, d->m_slices) {
523 foreach (QPieSlice* s, d->m_slices) {
521 d->m_slices.removeOne(s);
524 d->m_slices.removeOne(s);
522 delete s;
525 delete s;
523 }
526 }
524
527
525 d->updateDerivativeData();
528 d->updateDerivativeData();
526
529
527 emit removed(slices);
530 emit removed(slices);
528 emit countChanged();
531 emit countChanged();
529 }
532 }
530
533
531 /*!
534 /*!
532 Returns a list of slices that belong to this series.
535 Returns a list of slices that belong to this series.
533 */
536 */
534 QList<QPieSlice*> QPieSeries::slices() const
537 QList<QPieSlice*> QPieSeries::slices() const
535 {
538 {
536 Q_D(const QPieSeries);
539 Q_D(const QPieSeries);
537 return d->m_slices;
540 return d->m_slices;
538 }
541 }
539
542
540 /*!
543 /*!
541 returns the number of the slices in this series.
544 returns the number of the slices in this series.
542 */
545 */
543 int QPieSeries::count() const
546 int QPieSeries::count() const
544 {
547 {
545 Q_D(const QPieSeries);
548 Q_D(const QPieSeries);
546 return d->m_slices.count();
549 return d->m_slices.count();
547 }
550 }
548
551
549 /*!
552 /*!
550 Returns true is the series is empty.
553 Returns true is the series is empty.
551 */
554 */
552 bool QPieSeries::isEmpty() const
555 bool QPieSeries::isEmpty() const
553 {
556 {
554 Q_D(const QPieSeries);
557 Q_D(const QPieSeries);
555 return d->m_slices.isEmpty();
558 return d->m_slices.isEmpty();
556 }
559 }
557
560
558 /*!
561 /*!
559 Returns the sum of all slice values in this series.
562 Returns the sum of all slice values in this series.
560
563
561 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
564 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
562 */
565 */
563 qreal QPieSeries::sum() const
566 qreal QPieSeries::sum() const
564 {
567 {
565 Q_D(const QPieSeries);
568 Q_D(const QPieSeries);
566 return d->m_sum;
569 return d->m_sum;
567 }
570 }
568
571
569 void QPieSeries::setDonut(bool donut)
572 void QPieSeries::setDonut(bool donut)
570 {
573 {
571 Q_D(QPieSeries);
574 Q_D(QPieSeries);
572 d->m_donutChart = donut;
575 d->m_donutChart = donut;
573 d->updateDerivativeData();
576 d->updateDerivativeData();
574 }
577 }
575
578
576 bool QPieSeries::donut() const
579 bool QPieSeries::donut() const
577 {
580 {
578 Q_D(const QPieSeries);
581 Q_D(const QPieSeries);
579 return d->m_donutChart;
582 return d->m_donutChart;
580 }
583 }
581
584
582 void QPieSeries::setDonutInnerSize(qreal innerSize)
585 void QPieSeries::setDonutInnerSize(qreal innerSize)
583 {
586 {
584 Q_D(QPieSeries);
587 Q_D(QPieSeries);
585
588 innerSize = qBound(0.0, innerSize, 1.0);
586 if (innerSize < 0.0)
589 d->setSizes(innerSize, qMax(d->m_pieRelativeSize, innerSize));
587 innerSize = 0.0;
588 if (innerSize > d->m_pieRelativeSize)
589 innerSize = d->m_pieRelativeSize;
590
591 d->m_donutRelativeInnerSize = innerSize;
592 d->updateDerivativeData();
593 emit d->pieSizeChanged();
594 }
590 }
595
591
596 qreal QPieSeries::donutInnerSize() const
592 qreal QPieSeries::donutInnerSize() const
597 {
593 {
598 Q_D(const QPieSeries);
594 Q_D(const QPieSeries);
599 return d->m_donutRelativeInnerSize;
595 return d->m_donutRelativeInnerSize;
600 }
596 }
601
597
602 void QPieSeries::setHorizontalPosition(qreal relativePosition)
598 void QPieSeries::setHorizontalPosition(qreal relativePosition)
603 {
599 {
604 Q_D(QPieSeries);
600 Q_D(QPieSeries);
605
601
606 if (relativePosition < 0.0)
602 if (relativePosition < 0.0)
607 relativePosition = 0.0;
603 relativePosition = 0.0;
608 if (relativePosition > 1.0)
604 if (relativePosition > 1.0)
609 relativePosition = 1.0;
605 relativePosition = 1.0;
610
606
611 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
607 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
612 d->m_pieRelativeHorPos = relativePosition;
608 d->m_pieRelativeHorPos = relativePosition;
613 emit d->horizontalPositionChanged();
609 emit d->horizontalPositionChanged();
614 }
610 }
615 }
611 }
616
612
617 qreal QPieSeries::horizontalPosition() const
613 qreal QPieSeries::horizontalPosition() const
618 {
614 {
619 Q_D(const QPieSeries);
615 Q_D(const QPieSeries);
620 return d->m_pieRelativeHorPos;
616 return d->m_pieRelativeHorPos;
621 }
617 }
622
618
623 void QPieSeries::setVerticalPosition(qreal relativePosition)
619 void QPieSeries::setVerticalPosition(qreal relativePosition)
624 {
620 {
625 Q_D(QPieSeries);
621 Q_D(QPieSeries);
626
622
627 if (relativePosition < 0.0)
623 if (relativePosition < 0.0)
628 relativePosition = 0.0;
624 relativePosition = 0.0;
629 if (relativePosition > 1.0)
625 if (relativePosition > 1.0)
630 relativePosition = 1.0;
626 relativePosition = 1.0;
631
627
632 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
628 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
633 d->m_pieRelativeVerPos = relativePosition;
629 d->m_pieRelativeVerPos = relativePosition;
634 emit d->verticalPositionChanged();
630 emit d->verticalPositionChanged();
635 }
631 }
636 }
632 }
637
633
638 qreal QPieSeries::verticalPosition() const
634 qreal QPieSeries::verticalPosition() const
639 {
635 {
640 Q_D(const QPieSeries);
636 Q_D(const QPieSeries);
641 return d->m_pieRelativeVerPos;
637 return d->m_pieRelativeVerPos;
642 }
638 }
643
639
644 void QPieSeries::setPieSize(qreal relativeSize)
640 void QPieSeries::setPieSize(qreal relativeSize)
645 {
641 {
646 Q_D(QPieSeries);
642 Q_D(QPieSeries);
643 relativeSize = qBound(0.0, relativeSize, 1.0);
644 d->setSizes(qMin(d->m_donutRelativeInnerSize, relativeSize), relativeSize);
647
645
648 if (relativeSize < 0.0)
649 relativeSize = 0.0;
650 if (relativeSize > 1.0)
651 relativeSize = 1.0;
652
653 if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) {
654 d->m_pieRelativeSize = relativeSize;
655 emit d->pieSizeChanged();
656 }
657 }
646 }
658
647
659 qreal QPieSeries::pieSize() const
648 qreal QPieSeries::pieSize() const
660 {
649 {
661 Q_D(const QPieSeries);
650 Q_D(const QPieSeries);
662 return d->m_pieRelativeSize;
651 return d->m_pieRelativeSize;
663 }
652 }
664
653
665
654
666 void QPieSeries::setPieStartAngle(qreal angle)
655 void QPieSeries::setPieStartAngle(qreal angle)
667 {
656 {
668 Q_D(QPieSeries);
657 Q_D(QPieSeries);
669 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
658 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
670 return;
659 return;
671 d->m_pieStartAngle = angle;
660 d->m_pieStartAngle = angle;
672 d->updateDerivativeData();
661 d->updateDerivativeData();
673 emit d->pieStartAngleChanged();
662 emit d->pieStartAngleChanged();
674 }
663 }
675
664
676 qreal QPieSeries::pieStartAngle() const
665 qreal QPieSeries::pieStartAngle() const
677 {
666 {
678 Q_D(const QPieSeries);
667 Q_D(const QPieSeries);
679 return d->m_pieStartAngle;
668 return d->m_pieStartAngle;
680 }
669 }
681
670
682 /*!
671 /*!
683 Sets the end angle of the pie.
672 Sets the end angle of the pie.
684
673
685 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
674 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
686
675
687 \a angle must be greater than start angle.
676 \a angle must be greater than start angle.
688
677
689 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
678 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
690 */
679 */
691 void QPieSeries::setPieEndAngle(qreal angle)
680 void QPieSeries::setPieEndAngle(qreal angle)
692 {
681 {
693 Q_D(QPieSeries);
682 Q_D(QPieSeries);
694 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
683 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
695 return;
684 return;
696 d->m_pieEndAngle = angle;
685 d->m_pieEndAngle = angle;
697 d->updateDerivativeData();
686 d->updateDerivativeData();
698 emit d->pieEndAngleChanged();
687 emit d->pieEndAngleChanged();
699 }
688 }
700
689
701 /*!
690 /*!
702 Returns the end angle of the pie.
691 Returns the end angle of the pie.
703
692
704 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
693 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
705
694
706 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
695 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
707 */
696 */
708 qreal QPieSeries::pieEndAngle() const
697 qreal QPieSeries::pieEndAngle() const
709 {
698 {
710 Q_D(const QPieSeries);
699 Q_D(const QPieSeries);
711 return d->m_pieEndAngle;
700 return d->m_pieEndAngle;
712 }
701 }
713
702
714 /*!
703 /*!
715 Sets the all the slice labels \a visible or invisible.
704 Sets the all the slice labels \a visible or invisible.
716
705
717 Note that this affects only the current slices in the series.
706 Note that this affects only the current slices in the series.
718 If user adds a new slice the default label visibility is false.
707 If user adds a new slice the default label visibility is false.
719
708
720 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
709 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
721 */
710 */
722 void QPieSeries::setLabelsVisible(bool visible)
711 void QPieSeries::setLabelsVisible(bool visible)
723 {
712 {
724 Q_D(QPieSeries);
713 Q_D(QPieSeries);
725 foreach (QPieSlice* s, d->m_slices)
714 foreach (QPieSlice* s, d->m_slices)
726 s->setLabelVisible(visible);
715 s->setLabelVisible(visible);
727 }
716 }
728
717
729 void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
718 void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
730 {
719 {
731 Q_D(QPieSeries);
720 Q_D(QPieSeries);
732 foreach (QPieSlice* s, d->m_slices)
721 foreach (QPieSlice* s, d->m_slices)
733 s->setLabelPosition(position);
722 s->setLabelPosition(position);
734 }
723 }
735
724
736 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
725 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
737
726
738
727
739 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
728 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
740 QAbstractSeriesPrivate(parent),
729 QAbstractSeriesPrivate(parent),
741 m_pieRelativeHorPos(0.5),
730 m_pieRelativeHorPos(0.5),
742 m_pieRelativeVerPos(0.5),
731 m_pieRelativeVerPos(0.5),
743 m_pieRelativeSize(0.7),
732 m_pieRelativeSize(0.7),
744 m_pieStartAngle(0),
733 m_pieStartAngle(0),
745 m_pieEndAngle(360),
734 m_pieEndAngle(360),
746 m_sum(0),
735 m_sum(0),
747 m_donutChart(false),
736 m_donutChart(false),
748 m_donutRelativeInnerSize(0.5)
737 m_donutRelativeInnerSize(0.5)
749 {
738 {
750 }
739 }
751
740
752 QPieSeriesPrivate::~QPieSeriesPrivate()
741 QPieSeriesPrivate::~QPieSeriesPrivate()
753 {
742 {
754 }
743 }
755
744
756 void QPieSeriesPrivate::updateDerivativeData()
745 void QPieSeriesPrivate::updateDerivativeData()
757 {
746 {
758 // calculate sum of all slices
747 // calculate sum of all slices
759 qreal sum = 0;
748 qreal sum = 0;
760 foreach (QPieSlice* s, m_slices)
749 foreach (QPieSlice* s, m_slices)
761 sum += s->value();
750 sum += s->value();
762
751
763 if (!qFuzzyIsNull(m_sum - sum)) {
752 if (!qFuzzyIsNull(m_sum - sum)) {
764 m_sum = sum;
753 m_sum = sum;
765 emit q_func()->sumChanged();
754 emit q_func()->sumChanged();
766 }
755 }
767
756
768 // nothing to show..
757 // nothing to show..
769 if (qFuzzyIsNull(m_sum))
758 if (qFuzzyIsNull(m_sum))
770 return;
759 return;
771
760
772 // update slice attributes
761 // update slice attributes
773 qreal sliceAngle = m_pieStartAngle;
762 qreal sliceAngle = m_pieStartAngle;
774 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
763 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
775 QVector<QPieSlice*> changed;
764 QVector<QPieSlice*> changed;
776 foreach (QPieSlice* s, m_slices) {
765 foreach (QPieSlice* s, m_slices) {
777 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
766 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
778 d->setPercentage(s->value() / m_sum);
767 d->setPercentage(s->value() / m_sum);
779 d->setStartAngle(sliceAngle);
768 d->setStartAngle(sliceAngle);
780 d->setAngleSpan(pieSpan * s->percentage());
769 d->setAngleSpan(pieSpan * s->percentage());
781 sliceAngle += s->angleSpan();
770 sliceAngle += s->angleSpan();
782 }
771 }
783
772
784
773
785 emit calculatedDataChanged();
774 emit calculatedDataChanged();
786 }
775 }
787
776
777 void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize)
778 {
779 bool changed = false;
780
781 if (!qFuzzyIsNull(m_donutRelativeInnerSize - innerSize)) {
782 m_donutRelativeInnerSize = innerSize;
783 changed = true;
784 }
785
786 if (!qFuzzyIsNull(m_pieRelativeSize - outerSize)) {
787 m_pieRelativeSize = outerSize;
788 changed = true;
789 }
790
791 if (changed)
792 emit pieSizeChanged();
793 }
794
788 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
795 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
789 {
796 {
790 return series->d_func();
797 return series->d_func();
791 }
798 }
792
799
793 void QPieSeriesPrivate::sliceValueChanged()
800 void QPieSeriesPrivate::sliceValueChanged()
794 {
801 {
795 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
802 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
796 updateDerivativeData();
803 updateDerivativeData();
797 }
804 }
798
805
799 void QPieSeriesPrivate::sliceClicked()
806 void QPieSeriesPrivate::sliceClicked()
800 {
807 {
801 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
808 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
802 Q_ASSERT(m_slices.contains(slice));
809 Q_ASSERT(m_slices.contains(slice));
803 Q_Q(QPieSeries);
810 Q_Q(QPieSeries);
804 emit q->clicked(slice);
811 emit q->clicked(slice);
805 }
812 }
806
813
807 void QPieSeriesPrivate::sliceHovered(bool state)
814 void QPieSeriesPrivate::sliceHovered(bool state)
808 {
815 {
809 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
816 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
810 Q_ASSERT(m_slices.contains(slice));
817 Q_ASSERT(m_slices.contains(slice));
811 Q_Q(QPieSeries);
818 Q_Q(QPieSeries);
812 emit q->hovered(slice, state);
819 emit q->hovered(slice, state);
813 }
820 }
814
821
815 void QPieSeriesPrivate::scaleDomain(Domain& domain)
822 void QPieSeriesPrivate::scaleDomain(Domain& domain)
816 {
823 {
817 Q_UNUSED(domain);
824 Q_UNUSED(domain);
818 // does not apply to pie
825 // does not apply to pie
819 }
826 }
820
827
821 ChartElement* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
828 ChartElement* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
822 {
829 {
823 Q_Q(QPieSeries);
830 Q_Q(QPieSeries);
824 PieChartItem* pie = new PieChartItem(q,presenter);
831 PieChartItem* pie = new PieChartItem(q,presenter);
825 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
832 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
826 pie->setAnimation(new PieAnimation(pie));
833 pie->setAnimation(new PieAnimation(pie));
827 }
834 }
828 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
835 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
829 return pie;
836 return pie;
830 }
837 }
831
838
832 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
839 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
833 {
840 {
834 Q_Q(QPieSeries);
841 Q_Q(QPieSeries);
835 QList<LegendMarker*> markers;
842 QList<LegendMarker*> markers;
836 foreach(QPieSlice* slice, q->slices()) {
843 foreach(QPieSlice* slice, q->slices()) {
837 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
844 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
838 markers << marker;
845 markers << marker;
839 }
846 }
840 return markers;
847 return markers;
841 }
848 }
842
849
843 void QPieSeriesPrivate::initializeAxis(QAbstractAxis* axis)
850 void QPieSeriesPrivate::initializeAxis(QAbstractAxis* axis)
844 {
851 {
845 Q_UNUSED(axis);
852 Q_UNUSED(axis);
846 }
853 }
847
854
848 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
855 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
849 {
856 {
850 Q_UNUSED(orientation);
857 Q_UNUSED(orientation);
851 return QAbstractAxis::AxisTypeNoAxis;
858 return QAbstractAxis::AxisTypeNoAxis;
852 }
859 }
853
860
854 #include "moc_qpieseries.cpp"
861 #include "moc_qpieseries.cpp"
855 #include "moc_qpieseries_p.cpp"
862 #include "moc_qpieseries_p.cpp"
856
863
857 QTCOMMERCIALCHART_END_NAMESPACE
864 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,88 +1,89
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QPIESERIES_P_H
30 #ifndef QPIESERIES_P_H
31 #define QPIESERIES_P_H
31 #define QPIESERIES_P_H
32
32
33 #include "qpieseries.h"
33 #include "qpieseries.h"
34 #include "qabstractseries_p.h"
34 #include "qabstractseries_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 class QLegendPrivate;
37 class QLegendPrivate;
38
38
39 class QPieSeriesPrivate : public QAbstractSeriesPrivate
39 class QPieSeriesPrivate : public QAbstractSeriesPrivate
40 {
40 {
41 Q_OBJECT
41 Q_OBJECT
42
42
43 public:
43 public:
44 QPieSeriesPrivate(QPieSeries *parent);
44 QPieSeriesPrivate(QPieSeries *parent);
45 ~QPieSeriesPrivate();
45 ~QPieSeriesPrivate();
46
46
47 void scaleDomain(Domain& domain);
47 void scaleDomain(Domain& domain);
48 ChartElement* createGraphics(ChartPresenter *presenter);
48 ChartElement* createGraphics(ChartPresenter *presenter);
49 QList<LegendMarker*> createLegendMarker(QLegend *legend);
49 QList<LegendMarker*> createLegendMarker(QLegend *legend);
50 void initializeAxis(QAbstractAxis* axis);
50 void initializeAxis(QAbstractAxis* axis);
51 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
51 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
52
52
53 void updateDerivativeData();
53 void updateDerivativeData();
54 void setSizes(qreal innerSize, qreal outerSize);
54
55
55 static QPieSeriesPrivate* fromSeries(QPieSeries *series);
56 static QPieSeriesPrivate* fromSeries(QPieSeries *series);
56
57
57 signals:
58 signals:
58 void calculatedDataChanged();
59 void calculatedDataChanged();
59 void pieSizeChanged();
60 void pieSizeChanged();
60 void pieStartAngleChanged();
61 void pieStartAngleChanged();
61 void pieEndAngleChanged();
62 void pieEndAngleChanged();
62 void horizontalPositionChanged();
63 void horizontalPositionChanged();
63 void verticalPositionChanged();
64 void verticalPositionChanged();
64
65
65 public Q_SLOTS:
66 public Q_SLOTS:
66 void sliceValueChanged();
67 void sliceValueChanged();
67 void sliceClicked();
68 void sliceClicked();
68 void sliceHovered(bool state);
69 void sliceHovered(bool state);
69
70
70 private:
71 private:
71 QList<QPieSlice*> m_slices;
72 QList<QPieSlice*> m_slices;
72 qreal m_pieRelativeHorPos;
73 qreal m_pieRelativeHorPos;
73 qreal m_pieRelativeVerPos;
74 qreal m_pieRelativeVerPos;
74 qreal m_pieRelativeSize;
75 qreal m_pieRelativeSize;
75 qreal m_pieStartAngle;
76 qreal m_pieStartAngle;
76 qreal m_pieEndAngle;
77 qreal m_pieEndAngle;
77 qreal m_sum;
78 qreal m_sum;
78 bool m_donutChart;
79 bool m_donutChart;
79 qreal m_donutRelativeInnerSize;
80 qreal m_donutRelativeInnerSize;
80
81
81 private:
82 private:
82 friend class QLegendPrivate;
83 friend class QLegendPrivate;
83 Q_DECLARE_PUBLIC(QPieSeries)
84 Q_DECLARE_PUBLIC(QPieSeries)
84 };
85 };
85
86
86 QTCOMMERCIALCHART_END_NAMESPACE
87 QTCOMMERCIALCHART_END_NAMESPACE
87
88
88 #endif // QPIESERIES_P_H
89 #endif // QPIESERIES_P_H
@@ -1,147 +1,147
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 QPIESLICE_H
21 #ifndef QPIESLICE_H
22 #define QPIESLICE_H
22 #define QPIESLICE_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QObject>
25 #include <QObject>
26 #include <QPen>
26 #include <QPen>
27 #include <QBrush>
27 #include <QBrush>
28 #include <QFont>
28 #include <QFont>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 class QPieSlicePrivate;
31 class QPieSlicePrivate;
32 class QPieSeries;
32 class QPieSeries;
33
33
34 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
34 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
35 {
35 {
36 Q_OBJECT
36 Q_OBJECT
37 Q_ENUMS(LabelPosition)
37 Q_ENUMS(LabelPosition)
38 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
38 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
39 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
39 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
40 Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY labelVisibleChanged)
40 Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY labelVisibleChanged)
41 Q_PROPERTY(LabelPosition labelPosition READ labelPosition WRITE setLabelPosition)
41 Q_PROPERTY(LabelPosition labelPosition READ labelPosition WRITE setLabelPosition)
42 Q_PROPERTY(bool exploded READ isExploded WRITE setExploded)
42 Q_PROPERTY(bool exploded READ isExploded WRITE setExploded)
43 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
43 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
44 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
44 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
45 Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged)
45 Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged)
46 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
46 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
47 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
47 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
48 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
48 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
49 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
49 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
50 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
50 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
51 Q_PROPERTY(qreal labelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor)
51 Q_PROPERTY(qreal labelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor)
52 Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor)
52 Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor)
53 Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged)
53 Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged)
54 Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged)
54 Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged)
55 Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged)
55 Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged)
56
56
57 public:
57 public:
58 enum LabelPosition {
58 enum LabelPosition {
59 LabelOutside,
59 LabelOutside,
60 LabelInside,
60 LabelInside,
61 LabelInsideTangential,
61 LabelInsideTangential, // better name needed
62 LabelInsideNormal
62 LabelInsideNormal // better name needed
63 };
63 };
64
64
65 public:
65 public:
66 explicit QPieSlice(QObject *parent = 0);
66 explicit QPieSlice(QObject *parent = 0);
67 QPieSlice(QString label, qreal value, QObject *parent = 0);
67 QPieSlice(QString label, qreal value, QObject *parent = 0);
68 virtual ~QPieSlice();
68 virtual ~QPieSlice();
69
69
70 void setLabel(QString label);
70 void setLabel(QString label);
71 QString label() const;
71 QString label() const;
72
72
73 void setValue(qreal value);
73 void setValue(qreal value);
74 qreal value() const;
74 qreal value() const;
75
75
76 void setLabelVisible(bool visible = true);
76 void setLabelVisible(bool visible = true);
77 bool isLabelVisible() const;
77 bool isLabelVisible() const;
78
78
79 LabelPosition labelPosition();
79 LabelPosition labelPosition();
80 void setLabelPosition(LabelPosition position);
80 void setLabelPosition(LabelPosition position);
81
81
82 void setExploded(bool exploded = true);
82 void setExploded(bool exploded = true);
83 bool isExploded() const;
83 bool isExploded() const;
84
84
85 void setPen(const QPen &pen);
85 void setPen(const QPen &pen);
86 QPen pen() const;
86 QPen pen() const;
87
87
88 QColor borderColor();
88 QColor borderColor();
89 void setBorderColor(QColor color);
89 void setBorderColor(QColor color);
90
90
91 int borderWidth();
91 int borderWidth();
92 void setBorderWidth(int width);
92 void setBorderWidth(int width);
93
93
94 void setBrush(const QBrush &brush);
94 void setBrush(const QBrush &brush);
95 QBrush brush() const;
95 QBrush brush() const;
96
96
97 QColor color();
97 QColor color();
98 void setColor(QColor color);
98 void setColor(QColor color);
99
99
100 void setLabelBrush(const QBrush &brush);
100 void setLabelBrush(const QBrush &brush);
101 QBrush labelBrush() const;
101 QBrush labelBrush() const;
102
102
103 QColor labelColor();
103 QColor labelColor();
104 void setLabelColor(QColor color);
104 void setLabelColor(QColor color);
105
105
106 void setLabelFont(const QFont &font);
106 void setLabelFont(const QFont &font);
107 QFont labelFont() const;
107 QFont labelFont() const;
108
108
109 void setLabelArmLengthFactor(qreal factor);
109 void setLabelArmLengthFactor(qreal factor);
110 qreal labelArmLengthFactor() const;
110 qreal labelArmLengthFactor() const;
111
111
112 void setExplodeDistanceFactor(qreal factor);
112 void setExplodeDistanceFactor(qreal factor);
113 qreal explodeDistanceFactor() const;
113 qreal explodeDistanceFactor() const;
114
114
115 qreal percentage() const;
115 qreal percentage() const;
116 qreal startAngle() const;
116 qreal startAngle() const;
117 qreal angleSpan() const;
117 qreal angleSpan() const;
118
118
119 QPieSeries *series() const;
119 QPieSeries *series() const;
120
120
121 Q_SIGNALS:
121 Q_SIGNALS:
122 void clicked();
122 void clicked();
123 void hovered(bool state);
123 void hovered(bool state);
124 void labelChanged();
124 void labelChanged();
125 void valueChanged();
125 void valueChanged();
126 void labelVisibleChanged();
126 void labelVisibleChanged();
127 void penChanged();
127 void penChanged();
128 void brushChanged();
128 void brushChanged();
129 void labelBrushChanged();
129 void labelBrushChanged();
130 void labelFontChanged();
130 void labelFontChanged();
131 void percentageChanged();
131 void percentageChanged();
132 void startAngleChanged();
132 void startAngleChanged();
133 void angleSpanChanged();
133 void angleSpanChanged();
134 void colorChanged();
134 void colorChanged();
135 void borderColorChanged();
135 void borderColorChanged();
136 void borderWidthChanged();
136 void borderWidthChanged();
137 void labelColorChanged();
137 void labelColorChanged();
138
138
139 private:
139 private:
140 QPieSlicePrivate * const d_ptr;
140 QPieSlicePrivate * const d_ptr;
141 Q_DECLARE_PRIVATE(QPieSlice)
141 Q_DECLARE_PRIVATE(QPieSlice)
142 Q_DISABLE_COPY(QPieSlice)
142 Q_DISABLE_COPY(QPieSlice)
143 };
143 };
144
144
145 QTCOMMERCIALCHART_END_NAMESPACE
145 QTCOMMERCIALCHART_END_NAMESPACE
146
146
147 #endif // QPIESLICE_H
147 #endif // QPIESLICE_H
General Comments 0
You need to be logged in to leave comments. Login now