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