@@ -1,85 +1,86 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 PIECHARTITEM_H |
|
30 | #ifndef PIECHARTITEM_H | |
31 | #define PIECHARTITEM_H |
|
31 | #define PIECHARTITEM_H | |
32 |
|
32 | |||
33 | #include "qpieseries.h" |
|
33 | #include "qpieseries.h" | |
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "piesliceitem_p.h" |
|
35 | #include "piesliceitem_p.h" | |
|
36 | #include <QPointer> | |||
36 |
|
37 | |||
37 | class QGraphicsItem; |
|
38 | class QGraphicsItem; | |
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 | class QPieSlice; |
|
40 | class QPieSlice; | |
40 | class ChartPresenter; |
|
41 | class ChartPresenter; | |
41 | class PieAnimation; |
|
42 | class PieAnimation; | |
42 |
|
43 | |||
43 | class PieChartItem : public ChartItem |
|
44 | class PieChartItem : public ChartItem | |
44 | { |
|
45 | { | |
45 | Q_OBJECT |
|
46 | Q_OBJECT | |
46 |
|
47 | |||
47 | public: |
|
48 | public: | |
48 | explicit PieChartItem(QPieSeries *series, QGraphicsItem* item = 0); |
|
49 | explicit PieChartItem(QPieSeries *series, QGraphicsItem* item = 0); | |
49 | ~PieChartItem(); |
|
50 | ~PieChartItem(); | |
50 |
|
51 | |||
51 | // from QGraphicsItem |
|
52 | // from QGraphicsItem | |
52 | QRectF boundingRect() const { return m_rect; } |
|
53 | QRectF boundingRect() const { return m_rect; } | |
53 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} |
|
54 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} | |
54 |
|
55 | |||
55 | public Q_SLOTS: |
|
56 | public Q_SLOTS: | |
56 | // from Chart |
|
57 | // from Chart | |
57 | virtual void handleDomainUpdated(); |
|
58 | virtual void handleDomainUpdated(); | |
58 |
|
59 | |||
59 | void updateLayout(); |
|
60 | void updateLayout(); | |
60 | void handleSlicesAdded(QList<QPieSlice *> slices); |
|
61 | void handleSlicesAdded(QList<QPieSlice *> slices); | |
61 | void handleSlicesRemoved(QList<QPieSlice *> slices); |
|
62 | void handleSlicesRemoved(QList<QPieSlice *> slices); | |
62 | void handleSliceChanged(); |
|
63 | void handleSliceChanged(); | |
63 | void handleSeriesVisibleChanged(); |
|
64 | void handleSeriesVisibleChanged(); | |
64 | void handleOpacityChanged(); |
|
65 | void handleOpacityChanged(); | |
65 |
|
66 | |||
66 | void setAnimation(PieAnimation *animation); |
|
67 | void setAnimation(PieAnimation *animation); | |
67 | ChartAnimation *animation() const; |
|
68 | ChartAnimation *animation() const; | |
68 |
|
69 | |||
69 | private: |
|
70 | private: | |
70 | PieSliceData updateSliceGeometry(QPieSlice *slice); |
|
71 | PieSliceData updateSliceGeometry(QPieSlice *slice); | |
71 |
|
72 | |||
72 | private: |
|
73 | private: | |
73 | QHash<QPieSlice *, PieSliceItem *> m_sliceItems; |
|
74 | QHash<QPieSlice *, PieSliceItem *> m_sliceItems; | |
74 |
QPieSeries |
|
75 | QPointer<QPieSeries> m_series; | |
75 | QRectF m_rect; |
|
76 | QRectF m_rect; | |
76 | QPointF m_pieCenter; |
|
77 | QPointF m_pieCenter; | |
77 | qreal m_pieRadius; |
|
78 | qreal m_pieRadius; | |
78 | qreal m_holeSize; |
|
79 | qreal m_holeSize; | |
79 | PieAnimation *m_animation; |
|
80 | PieAnimation *m_animation; | |
80 |
|
81 | |||
81 | }; |
|
82 | }; | |
82 |
|
83 | |||
83 | QTCOMMERCIALCHART_END_NAMESPACE |
|
84 | QTCOMMERCIALCHART_END_NAMESPACE | |
84 |
|
85 | |||
85 | #endif // PIECHARTITEM_H |
|
86 | #endif // PIECHARTITEM_H |
@@ -1,936 +1,937 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "qabstractaxis.h" |
|
28 | #include "qabstractaxis.h" | |
29 | #include "pieanimation_p.h" |
|
29 | #include "pieanimation_p.h" | |
30 | #include "charthelpers_p.h" |
|
30 | #include "charthelpers_p.h" | |
31 |
|
31 | |||
32 | #include "qpielegendmarker.h" |
|
32 | #include "qpielegendmarker.h" | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \class QPieSeries |
|
37 | \class QPieSeries | |
38 | \brief Pie series API for QtCommercial Charts |
|
38 | \brief Pie series API for QtCommercial Charts | |
39 |
|
39 | |||
40 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. |
|
40 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. | |
41 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
41 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
42 | The actual slice size is determined by that relative value. |
|
42 | The actual slice size is determined by that relative value. | |
43 |
|
43 | |||
44 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 |
|
44 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 | |
45 | These relate to the actual chart rectangle. |
|
45 | These relate to the actual chart rectangle. | |
46 |
|
46 | |||
47 | By default the pie is defined as a full pie but it can also be a partial pie. |
|
47 | By default the pie is defined as a full pie but it can also be a partial pie. | |
48 | This can be done by setting a starting angle and angle span to the series. |
|
48 | This can be done by setting a starting angle and angle span to the series. | |
49 | Full pie is 360 degrees where 0 is at 12 a'clock. |
|
49 | Full pie is 360 degrees where 0 is at 12 a'clock. | |
50 |
|
50 | |||
51 | See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries. |
|
51 | See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries. | |
52 | \table 100% |
|
52 | \table 100% | |
53 | \row |
|
53 | \row | |
54 | \o \image examples_piechart.png |
|
54 | \o \image examples_piechart.png | |
55 | \o \image examples_donutchart.png |
|
55 | \o \image examples_donutchart.png | |
56 | \endtable |
|
56 | \endtable | |
57 | */ |
|
57 | */ | |
58 | /*! |
|
58 | /*! | |
59 | \qmlclass PieSeries QPieSeries |
|
59 | \qmlclass PieSeries QPieSeries | |
60 | \inherits AbstractSeries |
|
60 | \inherits AbstractSeries | |
61 |
|
61 | |||
62 | The following QML shows how to create a simple pie chart. |
|
62 | The following QML shows how to create a simple pie chart. | |
63 |
|
63 | |||
64 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 |
|
64 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 | |
65 |
|
65 | |||
66 | \beginfloatleft |
|
66 | \beginfloatleft | |
67 | \image demos_qmlchart1.png |
|
67 | \image demos_qmlchart1.png | |
68 | \endfloat |
|
68 | \endfloat | |
69 | \clearfloat |
|
69 | \clearfloat | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \property QPieSeries::horizontalPosition |
|
73 | \property QPieSeries::horizontalPosition | |
74 | \brief Defines the horizontal position of the pie. |
|
74 | \brief Defines the horizontal position of the pie. | |
75 |
|
75 | |||
76 | The value is a relative value to the chart rectangle where: |
|
76 | The value is a relative value to the chart rectangle where: | |
77 |
|
77 | |||
78 | \list |
|
78 | \list | |
79 | \o 0.0 is the absolute left. |
|
79 | \o 0.0 is the absolute left. | |
80 | \o 1.0 is the absolute right. |
|
80 | \o 1.0 is the absolute right. | |
81 | \endlist |
|
81 | \endlist | |
82 | Default value is 0.5 (center). |
|
82 | Default value is 0.5 (center). | |
83 | \sa verticalPosition |
|
83 | \sa verticalPosition | |
84 | */ |
|
84 | */ | |
85 |
|
85 | |||
86 | /*! |
|
86 | /*! | |
87 | \qmlproperty real PieSeries::horizontalPosition |
|
87 | \qmlproperty real PieSeries::horizontalPosition | |
88 |
|
88 | |||
89 | Defines the horizontal position of the pie. |
|
89 | Defines the horizontal position of the pie. | |
90 |
|
90 | |||
91 | The value is a relative value to the chart rectangle where: |
|
91 | The value is a relative value to the chart rectangle where: | |
92 |
|
92 | |||
93 | \list |
|
93 | \list | |
94 | \o 0.0 is the absolute left. |
|
94 | \o 0.0 is the absolute left. | |
95 | \o 1.0 is the absolute right. |
|
95 | \o 1.0 is the absolute right. | |
96 | \endlist |
|
96 | \endlist | |
97 | Default value is 0.5 (center). |
|
97 | Default value is 0.5 (center). | |
98 | \sa verticalPosition |
|
98 | \sa verticalPosition | |
99 | */ |
|
99 | */ | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | \property QPieSeries::verticalPosition |
|
102 | \property QPieSeries::verticalPosition | |
103 | \brief Defines the vertical position of the pie. |
|
103 | \brief Defines the vertical position of the pie. | |
104 |
|
104 | |||
105 | The value is a relative value to the chart rectangle where: |
|
105 | The value is a relative value to the chart rectangle where: | |
106 |
|
106 | |||
107 | \list |
|
107 | \list | |
108 | \o 0.0 is the absolute top. |
|
108 | \o 0.0 is the absolute top. | |
109 | \o 1.0 is the absolute bottom. |
|
109 | \o 1.0 is the absolute bottom. | |
110 | \endlist |
|
110 | \endlist | |
111 | Default value is 0.5 (center). |
|
111 | Default value is 0.5 (center). | |
112 | \sa horizontalPosition |
|
112 | \sa horizontalPosition | |
113 | */ |
|
113 | */ | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | \qmlproperty real PieSeries::verticalPosition |
|
116 | \qmlproperty real PieSeries::verticalPosition | |
117 |
|
117 | |||
118 | Defines the vertical position of the pie. |
|
118 | Defines the vertical position of the pie. | |
119 |
|
119 | |||
120 | The value is a relative value to the chart rectangle where: |
|
120 | The value is a relative value to the chart rectangle where: | |
121 |
|
121 | |||
122 | \list |
|
122 | \list | |
123 | \o 0.0 is the absolute top. |
|
123 | \o 0.0 is the absolute top. | |
124 | \o 1.0 is the absolute bottom. |
|
124 | \o 1.0 is the absolute bottom. | |
125 | \endlist |
|
125 | \endlist | |
126 | Default value is 0.5 (center). |
|
126 | Default value is 0.5 (center). | |
127 | \sa horizontalPosition |
|
127 | \sa horizontalPosition | |
128 | */ |
|
128 | */ | |
129 |
|
129 | |||
130 | /*! |
|
130 | /*! | |
131 | \property QPieSeries::size |
|
131 | \property QPieSeries::size | |
132 | \brief Defines the pie size. |
|
132 | \brief Defines the pie size. | |
133 |
|
133 | |||
134 | The value is a relative value to the chart rectangle where: |
|
134 | The value is a relative value to the chart rectangle where: | |
135 |
|
135 | |||
136 | \list |
|
136 | \list | |
137 | \o 0.0 is the minimum size (pie not drawn). |
|
137 | \o 0.0 is the minimum size (pie not drawn). | |
138 | \o 1.0 is the maximum size that can fit the chart. |
|
138 | \o 1.0 is the maximum size that can fit the chart. | |
139 | \endlist |
|
139 | \endlist | |
140 |
|
140 | |||
141 | When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size. |
|
141 | When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size. | |
142 |
|
142 | |||
143 | Default value is 0.7. |
|
143 | Default value is 0.7. | |
144 | */ |
|
144 | */ | |
145 |
|
145 | |||
146 | /*! |
|
146 | /*! | |
147 | \qmlproperty real PieSeries::size |
|
147 | \qmlproperty real PieSeries::size | |
148 |
|
148 | |||
149 | Defines the pie size. |
|
149 | Defines the pie size. | |
150 |
|
150 | |||
151 | The value is a relative value to the chart rectangle where: |
|
151 | The value is a relative value to the chart rectangle where: | |
152 |
|
152 | |||
153 | \list |
|
153 | \list | |
154 | \o 0.0 is the minimum size (pie not drawn). |
|
154 | \o 0.0 is the minimum size (pie not drawn). | |
155 | \o 1.0 is the maximum size that can fit the chart. |
|
155 | \o 1.0 is the maximum size that can fit the chart. | |
156 | \endlist |
|
156 | \endlist | |
157 |
|
157 | |||
158 | Default value is 0.7. |
|
158 | Default value is 0.7. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \property QPieSeries::holeSize |
|
162 | \property QPieSeries::holeSize | |
163 | \brief Defines the donut hole size. |
|
163 | \brief Defines the donut hole size. | |
164 |
|
164 | |||
165 | The value is a relative value to the chart rectangle where: |
|
165 | The value is a relative value to the chart rectangle where: | |
166 |
|
166 | |||
167 | \list |
|
167 | \list | |
168 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
168 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). | |
169 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
169 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) | |
170 | \endlist |
|
170 | \endlist | |
171 |
|
171 | |||
172 | The value is never greater then size property. |
|
172 | The value is never greater then size property. | |
173 | Default value is 0.0. |
|
173 | Default value is 0.0. | |
174 | */ |
|
174 | */ | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | \qmlproperty real PieSeries::holeSize |
|
177 | \qmlproperty real PieSeries::holeSize | |
178 |
|
178 | |||
179 | Defines the donut hole size. |
|
179 | Defines the donut hole size. | |
180 |
|
180 | |||
181 | The value is a relative value to the chart rectangle where: |
|
181 | The value is a relative value to the chart rectangle where: | |
182 |
|
182 | |||
183 | \list |
|
183 | \list | |
184 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
184 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). | |
185 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
185 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) | |
186 | \endlist |
|
186 | \endlist | |
187 |
|
187 | |||
188 | When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size. |
|
188 | When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size. | |
189 |
|
189 | |||
190 | Default value is 0.0. |
|
190 | Default value is 0.0. | |
191 | */ |
|
191 | */ | |
192 |
|
192 | |||
193 | /*! |
|
193 | /*! | |
194 | \property QPieSeries::startAngle |
|
194 | \property QPieSeries::startAngle | |
195 | \brief Defines the starting angle of the pie. |
|
195 | \brief Defines the starting angle of the pie. | |
196 |
|
196 | |||
197 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
197 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
198 |
|
198 | |||
199 | Default is value is 0. |
|
199 | Default is value is 0. | |
200 | */ |
|
200 | */ | |
201 |
|
201 | |||
202 | /*! |
|
202 | /*! | |
203 | \qmlproperty real PieSeries::startAngle |
|
203 | \qmlproperty real PieSeries::startAngle | |
204 |
|
204 | |||
205 | Defines the starting angle of the pie. |
|
205 | Defines the starting angle of the pie. | |
206 |
|
206 | |||
207 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
207 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
208 |
|
208 | |||
209 | Default is value is 0. |
|
209 | Default is value is 0. | |
210 | */ |
|
210 | */ | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | \property QPieSeries::endAngle |
|
213 | \property QPieSeries::endAngle | |
214 | \brief Defines the ending angle of the pie. |
|
214 | \brief Defines the ending angle of the pie. | |
215 |
|
215 | |||
216 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
216 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
217 |
|
217 | |||
218 | Default is value is 360. |
|
218 | Default is value is 360. | |
219 | */ |
|
219 | */ | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | \qmlproperty real PieSeries::endAngle |
|
222 | \qmlproperty real PieSeries::endAngle | |
223 |
|
223 | |||
224 | Defines the ending angle of the pie. |
|
224 | Defines the ending angle of the pie. | |
225 |
|
225 | |||
226 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
226 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
227 |
|
227 | |||
228 | Default is value is 360. |
|
228 | Default is value is 360. | |
229 | */ |
|
229 | */ | |
230 |
|
230 | |||
231 | /*! |
|
231 | /*! | |
232 | \property QPieSeries::count |
|
232 | \property QPieSeries::count | |
233 |
|
233 | |||
234 | Number of slices in the series. |
|
234 | Number of slices in the series. | |
235 | */ |
|
235 | */ | |
236 |
|
236 | |||
237 | /*! |
|
237 | /*! | |
238 | \qmlproperty int PieSeries::count |
|
238 | \qmlproperty int PieSeries::count | |
239 |
|
239 | |||
240 | Number of slices in the series. |
|
240 | Number of slices in the series. | |
241 | */ |
|
241 | */ | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | \fn void QPieSeries::countChanged() |
|
244 | \fn void QPieSeries::countChanged() | |
245 | Emitted when the slice count has changed. |
|
245 | Emitted when the slice count has changed. | |
246 | \sa count |
|
246 | \sa count | |
247 | */ |
|
247 | */ | |
248 | /*! |
|
248 | /*! | |
249 | \qmlsignal PieSeries::onCountChanged() |
|
249 | \qmlsignal PieSeries::onCountChanged() | |
250 | Emitted when the slice count has changed. |
|
250 | Emitted when the slice count has changed. | |
251 | */ |
|
251 | */ | |
252 |
|
252 | |||
253 | /*! |
|
253 | /*! | |
254 | \property QPieSeries::sum |
|
254 | \property QPieSeries::sum | |
255 |
|
255 | |||
256 | Sum of all slices. |
|
256 | Sum of all slices. | |
257 |
|
257 | |||
258 | The series keeps track of the sum of all slices it holds. |
|
258 | The series keeps track of the sum of all slices it holds. | |
259 | */ |
|
259 | */ | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | \qmlproperty real PieSeries::sum |
|
262 | \qmlproperty real PieSeries::sum | |
263 |
|
263 | |||
264 | Sum of all slices. |
|
264 | Sum of all slices. | |
265 |
|
265 | |||
266 | The series keeps track of the sum of all slices it holds. |
|
266 | The series keeps track of the sum of all slices it holds. | |
267 | */ |
|
267 | */ | |
268 |
|
268 | |||
269 | /*! |
|
269 | /*! | |
270 | \fn void QPieSeries::sumChanged() |
|
270 | \fn void QPieSeries::sumChanged() | |
271 | Emitted when the sum of all slices has changed. |
|
271 | Emitted when the sum of all slices has changed. | |
272 | \sa sum |
|
272 | \sa sum | |
273 | */ |
|
273 | */ | |
274 | /*! |
|
274 | /*! | |
275 | \qmlsignal PieSeries::onSumChanged() |
|
275 | \qmlsignal PieSeries::onSumChanged() | |
276 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you |
|
276 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you | |
277 | change value of a slice. |
|
277 | change value of a slice. | |
278 | */ |
|
278 | */ | |
279 |
|
279 | |||
280 | /*! |
|
280 | /*! | |
281 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
281 | \fn void QPieSeries::added(QList<QPieSlice*> slices) | |
282 |
|
282 | |||
283 | This signal is emitted when \a slices have been added to the series. |
|
283 | This signal is emitted when \a slices have been added to the series. | |
284 |
|
284 | |||
285 | \sa append(), insert() |
|
285 | \sa append(), insert() | |
286 | */ |
|
286 | */ | |
287 | /*! |
|
287 | /*! | |
288 | \qmlsignal PieSeries::onAdded(PieSlice slice) |
|
288 | \qmlsignal PieSeries::onAdded(PieSlice slice) | |
289 | Emitted when \a slice has been added to the series. |
|
289 | Emitted when \a slice has been added to the series. | |
290 | */ |
|
290 | */ | |
291 |
|
291 | |||
292 | /*! |
|
292 | /*! | |
293 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
293 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) | |
294 | This signal is emitted when \a slices have been removed from the series. |
|
294 | This signal is emitted when \a slices have been removed from the series. | |
295 | \sa remove() |
|
295 | \sa remove() | |
296 | */ |
|
296 | */ | |
297 | /*! |
|
297 | /*! | |
298 | \qmlsignal PieSeries::onRemoved(PieSlice slice) |
|
298 | \qmlsignal PieSeries::onRemoved(PieSlice slice) | |
299 | Emitted when \a slice has been removed from the series. |
|
299 | Emitted when \a slice has been removed from the series. | |
300 | */ |
|
300 | */ | |
301 |
|
301 | |||
302 | /*! |
|
302 | /*! | |
303 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
303 | \fn void QPieSeries::clicked(QPieSlice* slice) | |
304 | This signal is emitted when a \a slice has been clicked. |
|
304 | This signal is emitted when a \a slice has been clicked. | |
305 | \sa QPieSlice::clicked() |
|
305 | \sa QPieSlice::clicked() | |
306 | */ |
|
306 | */ | |
307 | /*! |
|
307 | /*! | |
308 | \qmlsignal PieSeries::onClicked(PieSlice slice) |
|
308 | \qmlsignal PieSeries::onClicked(PieSlice slice) | |
309 | This signal is emitted when a \a slice has been clicked. |
|
309 | This signal is emitted when a \a slice has been clicked. | |
310 | */ |
|
310 | */ | |
311 |
|
311 | |||
312 | /*! |
|
312 | /*! | |
313 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) |
|
313 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) | |
314 | This signal is emitted when user has hovered over or away from the \a slice. |
|
314 | This signal is emitted when user has hovered over or away from the \a slice. | |
315 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
315 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. | |
316 | \sa QPieSlice::hovered() |
|
316 | \sa QPieSlice::hovered() | |
317 | */ |
|
317 | */ | |
318 | /*! |
|
318 | /*! | |
319 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) |
|
319 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) | |
320 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered |
|
320 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered | |
321 | over the slice and false when hover has moved away from the slice. |
|
321 | over the slice and false when hover has moved away from the slice. | |
322 | */ |
|
322 | */ | |
323 |
|
323 | |||
324 | /*! |
|
324 | /*! | |
325 | \qmlmethod PieSlice PieSeries::at(int index) |
|
325 | \qmlmethod PieSlice PieSeries::at(int index) | |
326 | Returns slice at \a index. Returns null if the index is not valid. |
|
326 | Returns slice at \a index. Returns null if the index is not valid. | |
327 | */ |
|
327 | */ | |
328 |
|
328 | |||
329 | /*! |
|
329 | /*! | |
330 | \qmlmethod PieSlice PieSeries::find(string label) |
|
330 | \qmlmethod PieSlice PieSeries::find(string label) | |
331 | Returns the first slice with \a label. Returns null if the index is not valid. |
|
331 | Returns the first slice with \a label. Returns null if the index is not valid. | |
332 | */ |
|
332 | */ | |
333 |
|
333 | |||
334 | /*! |
|
334 | /*! | |
335 | \qmlmethod PieSlice PieSeries::append(string label, real value) |
|
335 | \qmlmethod PieSlice PieSeries::append(string label, real value) | |
336 | Adds a new slice with \a label and \a value to the pie. |
|
336 | Adds a new slice with \a label and \a value to the pie. | |
337 | */ |
|
337 | */ | |
338 |
|
338 | |||
339 | /*! |
|
339 | /*! | |
340 | \qmlmethod bool PieSeries::remove(PieSlice slice) |
|
340 | \qmlmethod bool PieSeries::remove(PieSlice slice) | |
341 | Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise. |
|
341 | Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise. | |
342 | */ |
|
342 | */ | |
343 |
|
343 | |||
344 | /*! |
|
344 | /*! | |
345 | \qmlmethod PieSeries::clear() |
|
345 | \qmlmethod PieSeries::clear() | |
346 | Removes all slices from the pie. |
|
346 | Removes all slices from the pie. | |
347 | */ |
|
347 | */ | |
348 |
|
348 | |||
349 | /*! |
|
349 | /*! | |
350 | Constructs a series object which is a child of \a parent. |
|
350 | Constructs a series object which is a child of \a parent. | |
351 | */ |
|
351 | */ | |
352 | QPieSeries::QPieSeries(QObject *parent) |
|
352 | QPieSeries::QPieSeries(QObject *parent) | |
353 | : QAbstractSeries(*new QPieSeriesPrivate(this), parent) |
|
353 | : QAbstractSeries(*new QPieSeriesPrivate(this), parent) | |
354 | { |
|
354 | { | |
355 | Q_D(QPieSeries); |
|
355 | Q_D(QPieSeries); | |
356 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); |
|
356 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | /*! |
|
359 | /*! | |
360 | Destroys the series and its slices. |
|
360 | Destroys the series and its slices. | |
361 | */ |
|
361 | */ | |
362 | QPieSeries::~QPieSeries() |
|
362 | QPieSeries::~QPieSeries() | |
363 | { |
|
363 | { | |
364 | // NOTE: d_prt destroyed by QObject |
|
364 | // NOTE: d_prt destroyed by QObject | |
|
365 | clear(); | |||
365 | } |
|
366 | } | |
366 |
|
367 | |||
367 | /*! |
|
368 | /*! | |
368 | Returns QChartSeries::SeriesTypePie. |
|
369 | Returns QChartSeries::SeriesTypePie. | |
369 | */ |
|
370 | */ | |
370 | QAbstractSeries::SeriesType QPieSeries::type() const |
|
371 | QAbstractSeries::SeriesType QPieSeries::type() const | |
371 | { |
|
372 | { | |
372 | return QAbstractSeries::SeriesTypePie; |
|
373 | return QAbstractSeries::SeriesTypePie; | |
373 | } |
|
374 | } | |
374 |
|
375 | |||
375 | /*! |
|
376 | /*! | |
376 | Appends a single \a slice to the series. |
|
377 | Appends a single \a slice to the series. | |
377 | Slice ownership is passed to the series. |
|
378 | Slice ownership is passed to the series. | |
378 |
|
379 | |||
379 | Returns true if append was succesfull. |
|
380 | Returns true if append was succesfull. | |
380 | */ |
|
381 | */ | |
381 | bool QPieSeries::append(QPieSlice *slice) |
|
382 | bool QPieSeries::append(QPieSlice *slice) | |
382 | { |
|
383 | { | |
383 | return append(QList<QPieSlice *>() << slice); |
|
384 | return append(QList<QPieSlice *>() << slice); | |
384 | } |
|
385 | } | |
385 |
|
386 | |||
386 | /*! |
|
387 | /*! | |
387 | Appends an array of \a slices to the series. |
|
388 | Appends an array of \a slices to the series. | |
388 | Slice ownership is passed to the series. |
|
389 | Slice ownership is passed to the series. | |
389 |
|
390 | |||
390 | Returns true if append was successful. |
|
391 | Returns true if append was successful. | |
391 | */ |
|
392 | */ | |
392 | bool QPieSeries::append(QList<QPieSlice *> slices) |
|
393 | bool QPieSeries::append(QList<QPieSlice *> slices) | |
393 | { |
|
394 | { | |
394 | Q_D(QPieSeries); |
|
395 | Q_D(QPieSeries); | |
395 |
|
396 | |||
396 | if (slices.count() == 0) |
|
397 | if (slices.count() == 0) | |
397 | return false; |
|
398 | return false; | |
398 |
|
399 | |||
399 | foreach (QPieSlice *s, slices) { |
|
400 | foreach (QPieSlice *s, slices) { | |
400 | if (!s || d->m_slices.contains(s)) |
|
401 | if (!s || d->m_slices.contains(s)) | |
401 | return false; |
|
402 | return false; | |
402 | if (s->series()) // already added to some series |
|
403 | if (s->series()) // already added to some series | |
403 | return false; |
|
404 | return false; | |
404 | if (!isValidValue(s->value())) |
|
405 | if (!isValidValue(s->value())) | |
405 | return false; |
|
406 | return false; | |
406 | } |
|
407 | } | |
407 |
|
408 | |||
408 | foreach (QPieSlice *s, slices) { |
|
409 | foreach (QPieSlice *s, slices) { | |
409 | s->setParent(this); |
|
410 | s->setParent(this); | |
410 | QPieSlicePrivate::fromSlice(s)->m_series = this; |
|
411 | QPieSlicePrivate::fromSlice(s)->m_series = this; | |
411 | d->m_slices << s; |
|
412 | d->m_slices << s; | |
412 | } |
|
413 | } | |
413 |
|
414 | |||
414 | d->updateDerivativeData(); |
|
415 | d->updateDerivativeData(); | |
415 |
|
416 | |||
416 | foreach(QPieSlice * s, slices) { |
|
417 | foreach(QPieSlice * s, slices) { | |
417 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
418 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
418 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
419 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
419 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
420 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
420 | } |
|
421 | } | |
421 |
|
422 | |||
422 | emit added(slices); |
|
423 | emit added(slices); | |
423 | emit countChanged(); |
|
424 | emit countChanged(); | |
424 |
|
425 | |||
425 | return true; |
|
426 | return true; | |
426 | } |
|
427 | } | |
427 |
|
428 | |||
428 | /*! |
|
429 | /*! | |
429 | Appends a single \a slice to the series and returns a reference to the series. |
|
430 | Appends a single \a slice to the series and returns a reference to the series. | |
430 | Slice ownership is passed to the series. |
|
431 | Slice ownership is passed to the series. | |
431 | */ |
|
432 | */ | |
432 | QPieSeries &QPieSeries::operator << (QPieSlice *slice) |
|
433 | QPieSeries &QPieSeries::operator << (QPieSlice *slice) | |
433 | { |
|
434 | { | |
434 | append(slice); |
|
435 | append(slice); | |
435 | return *this; |
|
436 | return *this; | |
436 | } |
|
437 | } | |
437 |
|
438 | |||
438 |
|
439 | |||
439 | /*! |
|
440 | /*! | |
440 | Appends a single slice to the series with give \a value and \a label. |
|
441 | Appends a single slice to the series with give \a value and \a label. | |
441 | Slice ownership is passed to the series. |
|
442 | Slice ownership is passed to the series. | |
442 | Returns NULL if value is NaN, Inf or -Inf and no slice is added to the series. |
|
443 | Returns NULL if value is NaN, Inf or -Inf and no slice is added to the series. | |
443 | */ |
|
444 | */ | |
444 | QPieSlice *QPieSeries::append(QString label, qreal value) |
|
445 | QPieSlice *QPieSeries::append(QString label, qreal value) | |
445 | { |
|
446 | { | |
446 | if (isValidValue(value)) { |
|
447 | if (isValidValue(value)) { | |
447 | QPieSlice *slice = new QPieSlice(label, value); |
|
448 | QPieSlice *slice = new QPieSlice(label, value); | |
448 | append(slice); |
|
449 | append(slice); | |
449 | return slice; |
|
450 | return slice; | |
450 | } else { |
|
451 | } else { | |
451 | return 0; |
|
452 | return 0; | |
452 | } |
|
453 | } | |
453 | } |
|
454 | } | |
454 |
|
455 | |||
455 | /*! |
|
456 | /*! | |
456 | Inserts a single \a slice to the series before the slice at \a index position. |
|
457 | Inserts a single \a slice to the series before the slice at \a index position. | |
457 | Slice ownership is passed to the series. |
|
458 | Slice ownership is passed to the series. | |
458 |
|
459 | |||
459 | Returns true if insert was successful. |
|
460 | Returns true if insert was successful. | |
460 | */ |
|
461 | */ | |
461 | bool QPieSeries::insert(int index, QPieSlice *slice) |
|
462 | bool QPieSeries::insert(int index, QPieSlice *slice) | |
462 | { |
|
463 | { | |
463 | Q_D(QPieSeries); |
|
464 | Q_D(QPieSeries); | |
464 |
|
465 | |||
465 | if (index < 0 || index > d->m_slices.count()) |
|
466 | if (index < 0 || index > d->m_slices.count()) | |
466 | return false; |
|
467 | return false; | |
467 |
|
468 | |||
468 | if (!slice || d->m_slices.contains(slice)) |
|
469 | if (!slice || d->m_slices.contains(slice)) | |
469 | return false; |
|
470 | return false; | |
470 |
|
471 | |||
471 | if (slice->series()) // already added to some series |
|
472 | if (slice->series()) // already added to some series | |
472 | return false; |
|
473 | return false; | |
473 |
|
474 | |||
474 | if (!isValidValue(slice->value())) |
|
475 | if (!isValidValue(slice->value())) | |
475 | return false; |
|
476 | return false; | |
476 |
|
477 | |||
477 | slice->setParent(this); |
|
478 | slice->setParent(this); | |
478 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
479 | QPieSlicePrivate::fromSlice(slice)->m_series = this; | |
479 | d->m_slices.insert(index, slice); |
|
480 | d->m_slices.insert(index, slice); | |
480 |
|
481 | |||
481 | d->updateDerivativeData(); |
|
482 | d->updateDerivativeData(); | |
482 |
|
483 | |||
483 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
484 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
484 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
485 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
485 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
486 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
486 |
|
487 | |||
487 | emit added(QList<QPieSlice *>() << slice); |
|
488 | emit added(QList<QPieSlice *>() << slice); | |
488 | emit countChanged(); |
|
489 | emit countChanged(); | |
489 |
|
490 | |||
490 | return true; |
|
491 | return true; | |
491 | } |
|
492 | } | |
492 |
|
493 | |||
493 | /*! |
|
494 | /*! | |
494 | Removes a single \a slice from the series and deletes the slice. |
|
495 | Removes a single \a slice from the series and deletes the slice. | |
495 |
|
496 | |||
496 | Do not reference the pointer after this call. |
|
497 | Do not reference the pointer after this call. | |
497 |
|
498 | |||
498 | Returns true if remove was successful. |
|
499 | Returns true if remove was successful. | |
499 | */ |
|
500 | */ | |
500 | bool QPieSeries::remove(QPieSlice *slice) |
|
501 | bool QPieSeries::remove(QPieSlice *slice) | |
501 | { |
|
502 | { | |
502 | Q_D(QPieSeries); |
|
503 | Q_D(QPieSeries); | |
503 |
|
504 | |||
504 | if (!d->m_slices.removeOne(slice)) |
|
505 | if (!d->m_slices.removeOne(slice)) | |
505 | return false; |
|
506 | return false; | |
506 |
|
507 | |||
507 | d->updateDerivativeData(); |
|
508 | d->updateDerivativeData(); | |
508 |
|
509 | |||
509 | emit removed(QList<QPieSlice *>() << slice); |
|
510 | emit removed(QList<QPieSlice *>() << slice); | |
510 | emit countChanged(); |
|
511 | emit countChanged(); | |
511 |
|
512 | |||
512 | delete slice; |
|
513 | delete slice; | |
513 | slice = 0; |
|
514 | slice = 0; | |
514 |
|
515 | |||
515 | return true; |
|
516 | return true; | |
516 | } |
|
517 | } | |
517 |
|
518 | |||
518 | /*! |
|
519 | /*! | |
519 | Takes a single \a slice from the series. Does not destroy the slice object. |
|
520 | Takes a single \a slice from the series. Does not destroy the slice object. | |
520 |
|
521 | |||
521 | NOTE: The series remains as the slice's parent object. You must set the |
|
522 | NOTE: The series remains as the slice's parent object. You must set the | |
522 | parent object to take full ownership. |
|
523 | parent object to take full ownership. | |
523 |
|
524 | |||
524 | Returns true if take was successful. |
|
525 | Returns true if take was successful. | |
525 | */ |
|
526 | */ | |
526 | bool QPieSeries::take(QPieSlice *slice) |
|
527 | bool QPieSeries::take(QPieSlice *slice) | |
527 | { |
|
528 | { | |
528 | Q_D(QPieSeries); |
|
529 | Q_D(QPieSeries); | |
529 |
|
530 | |||
530 | if (!d->m_slices.removeOne(slice)) |
|
531 | if (!d->m_slices.removeOne(slice)) | |
531 | return false; |
|
532 | return false; | |
532 |
|
533 | |||
533 | QPieSlicePrivate::fromSlice(slice)->m_series = 0; |
|
534 | QPieSlicePrivate::fromSlice(slice)->m_series = 0; | |
534 | slice->disconnect(d); |
|
535 | slice->disconnect(d); | |
535 |
|
536 | |||
536 | d->updateDerivativeData(); |
|
537 | d->updateDerivativeData(); | |
537 |
|
538 | |||
538 | emit removed(QList<QPieSlice *>() << slice); |
|
539 | emit removed(QList<QPieSlice *>() << slice); | |
539 | emit countChanged(); |
|
540 | emit countChanged(); | |
540 |
|
541 | |||
541 | return true; |
|
542 | return true; | |
542 | } |
|
543 | } | |
543 |
|
544 | |||
544 | /*! |
|
545 | /*! | |
545 | Clears all slices from the series. |
|
546 | Clears all slices from the series. | |
546 | */ |
|
547 | */ | |
547 | void QPieSeries::clear() |
|
548 | void QPieSeries::clear() | |
548 | { |
|
549 | { | |
549 | Q_D(QPieSeries); |
|
550 | Q_D(QPieSeries); | |
550 | if (d->m_slices.count() == 0) |
|
551 | if (d->m_slices.count() == 0) | |
551 | return; |
|
552 | return; | |
552 |
|
553 | |||
553 | QList<QPieSlice *> slices = d->m_slices; |
|
554 | QList<QPieSlice *> slices = d->m_slices; | |
554 | foreach (QPieSlice *s, d->m_slices) |
|
555 | foreach (QPieSlice *s, d->m_slices) | |
555 | d->m_slices.removeOne(s); |
|
556 | d->m_slices.removeOne(s); | |
556 |
|
557 | |||
557 | d->updateDerivativeData(); |
|
558 | d->updateDerivativeData(); | |
558 |
|
559 | |||
559 | emit removed(slices); |
|
560 | emit removed(slices); | |
560 | emit countChanged(); |
|
561 | emit countChanged(); | |
561 |
|
562 | |||
562 | foreach (QPieSlice *s, slices) |
|
563 | foreach (QPieSlice *s, slices) | |
563 | delete s; |
|
564 | delete s; | |
564 | } |
|
565 | } | |
565 |
|
566 | |||
566 | /*! |
|
567 | /*! | |
567 | Returns a list of slices that belong to this series. |
|
568 | Returns a list of slices that belong to this series. | |
568 | */ |
|
569 | */ | |
569 | QList<QPieSlice *> QPieSeries::slices() const |
|
570 | QList<QPieSlice *> QPieSeries::slices() const | |
570 | { |
|
571 | { | |
571 | Q_D(const QPieSeries); |
|
572 | Q_D(const QPieSeries); | |
572 | return d->m_slices; |
|
573 | return d->m_slices; | |
573 | } |
|
574 | } | |
574 |
|
575 | |||
575 | /*! |
|
576 | /*! | |
576 | returns the number of the slices in this series. |
|
577 | returns the number of the slices in this series. | |
577 | */ |
|
578 | */ | |
578 | int QPieSeries::count() const |
|
579 | int QPieSeries::count() const | |
579 | { |
|
580 | { | |
580 | Q_D(const QPieSeries); |
|
581 | Q_D(const QPieSeries); | |
581 | return d->m_slices.count(); |
|
582 | return d->m_slices.count(); | |
582 | } |
|
583 | } | |
583 |
|
584 | |||
584 | /*! |
|
585 | /*! | |
585 | Returns true is the series is empty. |
|
586 | Returns true is the series is empty. | |
586 | */ |
|
587 | */ | |
587 | bool QPieSeries::isEmpty() const |
|
588 | bool QPieSeries::isEmpty() const | |
588 | { |
|
589 | { | |
589 | Q_D(const QPieSeries); |
|
590 | Q_D(const QPieSeries); | |
590 | return d->m_slices.isEmpty(); |
|
591 | return d->m_slices.isEmpty(); | |
591 | } |
|
592 | } | |
592 |
|
593 | |||
593 | /*! |
|
594 | /*! | |
594 | Returns the sum of all slice values in this series. |
|
595 | Returns the sum of all slice values in this series. | |
595 |
|
596 | |||
596 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
597 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() | |
597 | */ |
|
598 | */ | |
598 | qreal QPieSeries::sum() const |
|
599 | qreal QPieSeries::sum() const | |
599 | { |
|
600 | { | |
600 | Q_D(const QPieSeries); |
|
601 | Q_D(const QPieSeries); | |
601 | return d->m_sum; |
|
602 | return d->m_sum; | |
602 | } |
|
603 | } | |
603 |
|
604 | |||
604 | void QPieSeries::setHoleSize(qreal holeSize) |
|
605 | void QPieSeries::setHoleSize(qreal holeSize) | |
605 | { |
|
606 | { | |
606 | Q_D(QPieSeries); |
|
607 | Q_D(QPieSeries); | |
607 | holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0); |
|
608 | holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0); | |
608 | d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize)); |
|
609 | d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize)); | |
609 | } |
|
610 | } | |
610 |
|
611 | |||
611 | qreal QPieSeries::holeSize() const |
|
612 | qreal QPieSeries::holeSize() const | |
612 | { |
|
613 | { | |
613 | Q_D(const QPieSeries); |
|
614 | Q_D(const QPieSeries); | |
614 | return d->m_holeRelativeSize; |
|
615 | return d->m_holeRelativeSize; | |
615 | } |
|
616 | } | |
616 |
|
617 | |||
617 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
618 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
618 | { |
|
619 | { | |
619 | Q_D(QPieSeries); |
|
620 | Q_D(QPieSeries); | |
620 |
|
621 | |||
621 | if (relativePosition < 0.0) |
|
622 | if (relativePosition < 0.0) | |
622 | relativePosition = 0.0; |
|
623 | relativePosition = 0.0; | |
623 | if (relativePosition > 1.0) |
|
624 | if (relativePosition > 1.0) | |
624 | relativePosition = 1.0; |
|
625 | relativePosition = 1.0; | |
625 |
|
626 | |||
626 | if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) { |
|
627 | if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) { | |
627 | d->m_pieRelativeHorPos = relativePosition; |
|
628 | d->m_pieRelativeHorPos = relativePosition; | |
628 | emit d->horizontalPositionChanged(); |
|
629 | emit d->horizontalPositionChanged(); | |
629 | } |
|
630 | } | |
630 | } |
|
631 | } | |
631 |
|
632 | |||
632 | qreal QPieSeries::horizontalPosition() const |
|
633 | qreal QPieSeries::horizontalPosition() const | |
633 | { |
|
634 | { | |
634 | Q_D(const QPieSeries); |
|
635 | Q_D(const QPieSeries); | |
635 | return d->m_pieRelativeHorPos; |
|
636 | return d->m_pieRelativeHorPos; | |
636 | } |
|
637 | } | |
637 |
|
638 | |||
638 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
639 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
639 | { |
|
640 | { | |
640 | Q_D(QPieSeries); |
|
641 | Q_D(QPieSeries); | |
641 |
|
642 | |||
642 | if (relativePosition < 0.0) |
|
643 | if (relativePosition < 0.0) | |
643 | relativePosition = 0.0; |
|
644 | relativePosition = 0.0; | |
644 | if (relativePosition > 1.0) |
|
645 | if (relativePosition > 1.0) | |
645 | relativePosition = 1.0; |
|
646 | relativePosition = 1.0; | |
646 |
|
647 | |||
647 | if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) { |
|
648 | if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) { | |
648 | d->m_pieRelativeVerPos = relativePosition; |
|
649 | d->m_pieRelativeVerPos = relativePosition; | |
649 | emit d->verticalPositionChanged(); |
|
650 | emit d->verticalPositionChanged(); | |
650 | } |
|
651 | } | |
651 | } |
|
652 | } | |
652 |
|
653 | |||
653 | qreal QPieSeries::verticalPosition() const |
|
654 | qreal QPieSeries::verticalPosition() const | |
654 | { |
|
655 | { | |
655 | Q_D(const QPieSeries); |
|
656 | Q_D(const QPieSeries); | |
656 | return d->m_pieRelativeVerPos; |
|
657 | return d->m_pieRelativeVerPos; | |
657 | } |
|
658 | } | |
658 |
|
659 | |||
659 | void QPieSeries::setPieSize(qreal relativeSize) |
|
660 | void QPieSeries::setPieSize(qreal relativeSize) | |
660 | { |
|
661 | { | |
661 | Q_D(QPieSeries); |
|
662 | Q_D(QPieSeries); | |
662 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); |
|
663 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); | |
663 | d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize); |
|
664 | d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize); | |
664 |
|
665 | |||
665 | } |
|
666 | } | |
666 |
|
667 | |||
667 | qreal QPieSeries::pieSize() const |
|
668 | qreal QPieSeries::pieSize() const | |
668 | { |
|
669 | { | |
669 | Q_D(const QPieSeries); |
|
670 | Q_D(const QPieSeries); | |
670 | return d->m_pieRelativeSize; |
|
671 | return d->m_pieRelativeSize; | |
671 | } |
|
672 | } | |
672 |
|
673 | |||
673 |
|
674 | |||
674 | void QPieSeries::setPieStartAngle(qreal angle) |
|
675 | void QPieSeries::setPieStartAngle(qreal angle) | |
675 | { |
|
676 | { | |
676 | Q_D(QPieSeries); |
|
677 | Q_D(QPieSeries); | |
677 | if (qFuzzyCompare(d->m_pieStartAngle, angle)) |
|
678 | if (qFuzzyCompare(d->m_pieStartAngle, angle)) | |
678 | return; |
|
679 | return; | |
679 | d->m_pieStartAngle = angle; |
|
680 | d->m_pieStartAngle = angle; | |
680 | d->updateDerivativeData(); |
|
681 | d->updateDerivativeData(); | |
681 | emit d->pieStartAngleChanged(); |
|
682 | emit d->pieStartAngleChanged(); | |
682 | } |
|
683 | } | |
683 |
|
684 | |||
684 | qreal QPieSeries::pieStartAngle() const |
|
685 | qreal QPieSeries::pieStartAngle() const | |
685 | { |
|
686 | { | |
686 | Q_D(const QPieSeries); |
|
687 | Q_D(const QPieSeries); | |
687 | return d->m_pieStartAngle; |
|
688 | return d->m_pieStartAngle; | |
688 | } |
|
689 | } | |
689 |
|
690 | |||
690 | /*! |
|
691 | /*! | |
691 | Sets the end angle of the pie. |
|
692 | Sets the end angle of the pie. | |
692 |
|
693 | |||
693 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
694 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
694 |
|
695 | |||
695 | \a angle must be greater than start angle. |
|
696 | \a angle must be greater than start angle. | |
696 |
|
697 | |||
697 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
698 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
698 | */ |
|
699 | */ | |
699 | void QPieSeries::setPieEndAngle(qreal angle) |
|
700 | void QPieSeries::setPieEndAngle(qreal angle) | |
700 | { |
|
701 | { | |
701 | Q_D(QPieSeries); |
|
702 | Q_D(QPieSeries); | |
702 | if (qFuzzyCompare(d->m_pieEndAngle, angle)) |
|
703 | if (qFuzzyCompare(d->m_pieEndAngle, angle)) | |
703 | return; |
|
704 | return; | |
704 | d->m_pieEndAngle = angle; |
|
705 | d->m_pieEndAngle = angle; | |
705 | d->updateDerivativeData(); |
|
706 | d->updateDerivativeData(); | |
706 | emit d->pieEndAngleChanged(); |
|
707 | emit d->pieEndAngleChanged(); | |
707 | } |
|
708 | } | |
708 |
|
709 | |||
709 | /*! |
|
710 | /*! | |
710 | Returns the end angle of the pie. |
|
711 | Returns the end angle of the pie. | |
711 |
|
712 | |||
712 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
713 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
713 |
|
714 | |||
714 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
715 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
715 | */ |
|
716 | */ | |
716 | qreal QPieSeries::pieEndAngle() const |
|
717 | qreal QPieSeries::pieEndAngle() const | |
717 | { |
|
718 | { | |
718 | Q_D(const QPieSeries); |
|
719 | Q_D(const QPieSeries); | |
719 | return d->m_pieEndAngle; |
|
720 | return d->m_pieEndAngle; | |
720 | } |
|
721 | } | |
721 |
|
722 | |||
722 | /*! |
|
723 | /*! | |
723 | Sets the all the slice labels \a visible or invisible. |
|
724 | Sets the all the slice labels \a visible or invisible. | |
724 |
|
725 | |||
725 | Note that this affects only the current slices in the series. |
|
726 | Note that this affects only the current slices in the series. | |
726 | If user adds a new slice the default label visibility is false. |
|
727 | If user adds a new slice the default label visibility is false. | |
727 |
|
728 | |||
728 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
729 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
729 | */ |
|
730 | */ | |
730 | void QPieSeries::setLabelsVisible(bool visible) |
|
731 | void QPieSeries::setLabelsVisible(bool visible) | |
731 | { |
|
732 | { | |
732 | Q_D(QPieSeries); |
|
733 | Q_D(QPieSeries); | |
733 | foreach (QPieSlice *s, d->m_slices) |
|
734 | foreach (QPieSlice *s, d->m_slices) | |
734 | s->setLabelVisible(visible); |
|
735 | s->setLabelVisible(visible); | |
735 | } |
|
736 | } | |
736 |
|
737 | |||
737 | /*! |
|
738 | /*! | |
738 | Sets the all the slice labels \a position |
|
739 | Sets the all the slice labels \a position | |
739 |
|
740 | |||
740 | Note that this affects only the current slices in the series. |
|
741 | Note that this affects only the current slices in the series. | |
741 | If user adds a new slice the default label position is LabelOutside |
|
742 | If user adds a new slice the default label position is LabelOutside | |
742 |
|
743 | |||
743 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() |
|
744 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() | |
744 | */ |
|
745 | */ | |
745 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) |
|
746 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) | |
746 | { |
|
747 | { | |
747 | Q_D(QPieSeries); |
|
748 | Q_D(QPieSeries); | |
748 | foreach (QPieSlice *s, d->m_slices) |
|
749 | foreach (QPieSlice *s, d->m_slices) | |
749 | s->setLabelPosition(position); |
|
750 | s->setLabelPosition(position); | |
750 | } |
|
751 | } | |
751 |
|
752 | |||
752 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
753 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
753 |
|
754 | |||
754 |
|
755 | |||
755 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
756 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | |
756 | QAbstractSeriesPrivate(parent), |
|
757 | QAbstractSeriesPrivate(parent), | |
757 | m_pieRelativeHorPos(0.5), |
|
758 | m_pieRelativeHorPos(0.5), | |
758 | m_pieRelativeVerPos(0.5), |
|
759 | m_pieRelativeVerPos(0.5), | |
759 | m_pieRelativeSize(0.7), |
|
760 | m_pieRelativeSize(0.7), | |
760 | m_pieStartAngle(0), |
|
761 | m_pieStartAngle(0), | |
761 | m_pieEndAngle(360), |
|
762 | m_pieEndAngle(360), | |
762 | m_sum(0), |
|
763 | m_sum(0), | |
763 | m_holeRelativeSize(0.0) |
|
764 | m_holeRelativeSize(0.0) | |
764 | { |
|
765 | { | |
765 | } |
|
766 | } | |
766 |
|
767 | |||
767 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
768 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
768 | { |
|
769 | { | |
769 | } |
|
770 | } | |
770 |
|
771 | |||
771 | void QPieSeriesPrivate::updateDerivativeData() |
|
772 | void QPieSeriesPrivate::updateDerivativeData() | |
772 | { |
|
773 | { | |
773 | // calculate sum of all slices |
|
774 | // calculate sum of all slices | |
774 | qreal sum = 0; |
|
775 | qreal sum = 0; | |
775 | foreach (QPieSlice *s, m_slices) |
|
776 | foreach (QPieSlice *s, m_slices) | |
776 | sum += s->value(); |
|
777 | sum += s->value(); | |
777 |
|
778 | |||
778 | if (!qFuzzyCompare(m_sum, sum)) { |
|
779 | if (!qFuzzyCompare(m_sum, sum)) { | |
779 | m_sum = sum; |
|
780 | m_sum = sum; | |
780 | emit q_func()->sumChanged(); |
|
781 | emit q_func()->sumChanged(); | |
781 | } |
|
782 | } | |
782 |
|
783 | |||
783 | // nothing to show.. |
|
784 | // nothing to show.. | |
784 | if (qFuzzyCompare(m_sum, 0)) |
|
785 | if (qFuzzyCompare(m_sum, 0)) | |
785 | return; |
|
786 | return; | |
786 |
|
787 | |||
787 | // update slice attributes |
|
788 | // update slice attributes | |
788 | qreal sliceAngle = m_pieStartAngle; |
|
789 | qreal sliceAngle = m_pieStartAngle; | |
789 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
790 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
790 | QVector<QPieSlice *> changed; |
|
791 | QVector<QPieSlice *> changed; | |
791 | foreach (QPieSlice *s, m_slices) { |
|
792 | foreach (QPieSlice *s, m_slices) { | |
792 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
793 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
793 | d->setPercentage(s->value() / m_sum); |
|
794 | d->setPercentage(s->value() / m_sum); | |
794 | d->setStartAngle(sliceAngle); |
|
795 | d->setStartAngle(sliceAngle); | |
795 | d->setAngleSpan(pieSpan * s->percentage()); |
|
796 | d->setAngleSpan(pieSpan * s->percentage()); | |
796 | sliceAngle += s->angleSpan(); |
|
797 | sliceAngle += s->angleSpan(); | |
797 | } |
|
798 | } | |
798 |
|
799 | |||
799 |
|
800 | |||
800 | emit calculatedDataChanged(); |
|
801 | emit calculatedDataChanged(); | |
801 | } |
|
802 | } | |
802 |
|
803 | |||
803 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) |
|
804 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) | |
804 | { |
|
805 | { | |
805 | bool changed = false; |
|
806 | bool changed = false; | |
806 |
|
807 | |||
807 | if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) { |
|
808 | if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) { | |
808 | m_holeRelativeSize = innerSize; |
|
809 | m_holeRelativeSize = innerSize; | |
809 | changed = true; |
|
810 | changed = true; | |
810 | } |
|
811 | } | |
811 |
|
812 | |||
812 | if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) { |
|
813 | if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) { | |
813 | m_pieRelativeSize = outerSize; |
|
814 | m_pieRelativeSize = outerSize; | |
814 | changed = true; |
|
815 | changed = true; | |
815 | } |
|
816 | } | |
816 |
|
817 | |||
817 | if (changed) |
|
818 | if (changed) | |
818 | emit pieSizeChanged(); |
|
819 | emit pieSizeChanged(); | |
819 | } |
|
820 | } | |
820 |
|
821 | |||
821 | QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
822 | QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series) | |
822 | { |
|
823 | { | |
823 | return series->d_func(); |
|
824 | return series->d_func(); | |
824 | } |
|
825 | } | |
825 |
|
826 | |||
826 | void QPieSeriesPrivate::sliceValueChanged() |
|
827 | void QPieSeriesPrivate::sliceValueChanged() | |
827 | { |
|
828 | { | |
828 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
829 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
829 | updateDerivativeData(); |
|
830 | updateDerivativeData(); | |
830 | } |
|
831 | } | |
831 |
|
832 | |||
832 | void QPieSeriesPrivate::sliceClicked() |
|
833 | void QPieSeriesPrivate::sliceClicked() | |
833 | { |
|
834 | { | |
834 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
835 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); | |
835 | Q_ASSERT(m_slices.contains(slice)); |
|
836 | Q_ASSERT(m_slices.contains(slice)); | |
836 | Q_Q(QPieSeries); |
|
837 | Q_Q(QPieSeries); | |
837 | emit q->clicked(slice); |
|
838 | emit q->clicked(slice); | |
838 | } |
|
839 | } | |
839 |
|
840 | |||
840 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
841 | void QPieSeriesPrivate::sliceHovered(bool state) | |
841 | { |
|
842 | { | |
842 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
843 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); | |
843 | Q_ASSERT(m_slices.contains(slice)); |
|
844 | Q_ASSERT(m_slices.contains(slice)); | |
844 | Q_Q(QPieSeries); |
|
845 | Q_Q(QPieSeries); | |
845 | emit q->hovered(slice, state); |
|
846 | emit q->hovered(slice, state); | |
846 | } |
|
847 | } | |
847 |
|
848 | |||
848 | void QPieSeriesPrivate::initializeDomain() |
|
849 | void QPieSeriesPrivate::initializeDomain() | |
849 | { |
|
850 | { | |
850 | // does not apply to pie |
|
851 | // does not apply to pie | |
851 | } |
|
852 | } | |
852 |
|
853 | |||
853 | void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
854 | void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
854 | { |
|
855 | { | |
855 | Q_Q(QPieSeries); |
|
856 | Q_Q(QPieSeries); | |
856 | PieChartItem *pie = new PieChartItem(q,parent); |
|
857 | PieChartItem *pie = new PieChartItem(q,parent); | |
857 | m_item.reset(pie); |
|
858 | m_item.reset(pie); | |
858 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
859 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
859 | } |
|
860 | } | |
860 |
|
861 | |||
861 | void QPieSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) |
|
862 | void QPieSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |
862 | { |
|
863 | { | |
863 | PieChartItem *item = static_cast<PieChartItem *>(m_item.data()); |
|
864 | PieChartItem *item = static_cast<PieChartItem *>(m_item.data()); | |
864 | Q_ASSERT(item); |
|
865 | Q_ASSERT(item); | |
865 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
866 | if (options.testFlag(QChart::SeriesAnimations)) { | |
866 | item->setAnimation(new PieAnimation(item)); |
|
867 | item->setAnimation(new PieAnimation(item)); | |
867 | }else{ |
|
868 | }else{ | |
868 | item->setAnimation(0); |
|
869 | item->setAnimation(0); | |
869 | } |
|
870 | } | |
870 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
871 | QAbstractSeriesPrivate::initializeAnimations(options); | |
871 | } |
|
872 | } | |
872 |
|
873 | |||
873 | QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
874 | QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend) | |
874 | { |
|
875 | { | |
875 | Q_Q(QPieSeries); |
|
876 | Q_Q(QPieSeries); | |
876 | QList<QLegendMarker*> markers; |
|
877 | QList<QLegendMarker*> markers; | |
877 | foreach(QPieSlice* slice, q->slices()) { |
|
878 | foreach(QPieSlice* slice, q->slices()) { | |
878 | QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend); |
|
879 | QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend); | |
879 | markers << marker; |
|
880 | markers << marker; | |
880 | } |
|
881 | } | |
881 | return markers; |
|
882 | return markers; | |
882 | } |
|
883 | } | |
883 |
|
884 | |||
884 | void QPieSeriesPrivate::initializeAxes() |
|
885 | void QPieSeriesPrivate::initializeAxes() | |
885 | { |
|
886 | { | |
886 |
|
887 | |||
887 | } |
|
888 | } | |
888 |
|
889 | |||
889 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
890 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
890 | { |
|
891 | { | |
891 | Q_UNUSED(orientation); |
|
892 | Q_UNUSED(orientation); | |
892 | return QAbstractAxis::AxisTypeNoAxis; |
|
893 | return QAbstractAxis::AxisTypeNoAxis; | |
893 | } |
|
894 | } | |
894 |
|
895 | |||
895 | QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
896 | QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |
896 | { |
|
897 | { | |
897 | Q_UNUSED(orientation); |
|
898 | Q_UNUSED(orientation); | |
898 | return 0; |
|
899 | return 0; | |
899 | } |
|
900 | } | |
900 |
|
901 | |||
901 | void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
902 | void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |
902 | { |
|
903 | { | |
903 | //Q_Q(QPieSeries); |
|
904 | //Q_Q(QPieSeries); | |
904 | //const QList<QColor>& colors = theme->seriesColors(); |
|
905 | //const QList<QColor>& colors = theme->seriesColors(); | |
905 | const QList<QGradient>& gradients = theme->seriesGradients(); |
|
906 | const QList<QGradient>& gradients = theme->seriesGradients(); | |
906 |
|
907 | |||
907 | for (int i(0); i < m_slices.count(); i++) { |
|
908 | for (int i(0); i < m_slices.count(); i++) { | |
908 |
|
909 | |||
909 | QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0); |
|
910 | QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0); | |
910 |
|
911 | |||
911 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
912 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
912 | qreal pos = (qreal)(i + 1) / (qreal) m_slices.count(); |
|
913 | qreal pos = (qreal)(i + 1) / (qreal) m_slices.count(); | |
913 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos); |
|
914 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos); | |
914 |
|
915 | |||
915 | QPieSlice *s = m_slices.at(i); |
|
916 | QPieSlice *s = m_slices.at(i); | |
916 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
917 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
917 |
|
918 | |||
918 | if (forced || d->m_data.m_slicePen.isThemed()) |
|
919 | if (forced || d->m_data.m_slicePen.isThemed()) | |
919 | d->setPen(penColor, true); |
|
920 | d->setPen(penColor, true); | |
920 |
|
921 | |||
921 | if (forced || d->m_data.m_sliceBrush.isThemed()) |
|
922 | if (forced || d->m_data.m_sliceBrush.isThemed()) | |
922 | d->setBrush(brushColor, true); |
|
923 | d->setBrush(brushColor, true); | |
923 |
|
924 | |||
924 | if (forced || d->m_data.m_labelBrush.isThemed()) |
|
925 | if (forced || d->m_data.m_labelBrush.isThemed()) | |
925 | d->setLabelBrush(theme->labelBrush().color(), true); |
|
926 | d->setLabelBrush(theme->labelBrush().color(), true); | |
926 |
|
927 | |||
927 | if (forced || d->m_data.m_labelFont.isThemed()) |
|
928 | if (forced || d->m_data.m_labelFont.isThemed()) | |
928 | d->setLabelFont(theme->labelFont(), true); |
|
929 | d->setLabelFont(theme->labelFont(), true); | |
929 | } |
|
930 | } | |
930 | } |
|
931 | } | |
931 |
|
932 | |||
932 |
|
933 | |||
933 | #include "moc_qpieseries.cpp" |
|
934 | #include "moc_qpieseries.cpp" | |
934 | #include "moc_qpieseries_p.cpp" |
|
935 | #include "moc_qpieseries_p.cpp" | |
935 |
|
936 | |||
936 | QTCOMMERCIALCHART_END_NAMESPACE |
|
937 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now