##// END OF EJS Templates
Docs update
Marek Rosa -
r1731:d59786143197
parent child
Show More
@@ -1,332 +1,332
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qdatetimeaxis.h"
22 22 #include "qdatetimeaxis_p.h"
23 23 #include "chartdatetimeaxisx_p.h"
24 24 #include "chartdatetimeaxisy_p.h"
25 25 #include "domain_p.h"
26 26 #include <cmath>
27 27 #include <QDebug>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30 /*!
31 31 \class QDateTimeAxis
32 32 \brief The QDateTimeAxis class is used for manipulating chart's axis.
33 33 \mainclass
34 34
35 35 ValuesAxis can be setup to show axis line with tick marks, grid lines and shades.
36 36 Values of axis are drawn to position of ticks
37 37 */
38 38
39 39 /*!
40 40 \qmlclass ValuesAxis QDateTimeAxis
41 41 \brief The ValuesAxis element is used for manipulating chart's axes
42 42
43 43 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
44 44 Values of axis are drawn to position of ticks
45 45
46 46 To access Axes you can use ChartView API. For example:
47 47 \code
48 48 ChartView {
49 49 ValuesAxis {
50 50 id: xAxis
51 51 min: 0
52 52 max: 10
53 53 }
54 54 // Add a few series...
55 55 }
56 56 \endcode
57 57 */
58 58
59 59 /*!
60 60 \property QDateTimeAxis::min
61 61 Defines the minimum value on the axis.
62 62 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
63 63 */
64 64 /*!
65 65 \qmlproperty real ValuesAxis::min
66 66 Defines the minimum value on the axis.
67 67 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
68 68 */
69 69
70 70 /*!
71 71 \property QDateTimeAxis::max
72 72 Defines the maximum value on the axis.
73 73 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
74 74 */
75 75 /*!
76 76 \qmlproperty real ValuesAxis::max
77 77 Defines the maximum value on the axis.
78 78 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
79 79 */
80 80
81 81 /*!
82 \fn void QDateTimeAxis::minChanged(qreal min)
82 \fn void QDateTimeAxis::minChanged(QDateTime min)
83 83 Axis emits signal when \a min of axis has changed.
84 84 */
85 85 /*!
86 \qmlsignal ValuesAxis::onMinChanged(real min)
86 \qmlsignal ValuesAxis::onMinChanged(QDateTime min)
87 87 Axis emits signal when \a min of axis has changed.
88 88 */
89 89
90 90 /*!
91 \fn void QDateTimeAxis::maxChanged(qreal max)
91 \fn void QDateTimeAxis::maxChanged(QDateTime max)
92 92 Axis emits signal when \a max of axis has changed.
93 93 */
94 94 /*!
95 \qmlsignal ValuesAxis::onMaxChanged(real max)
95 \qmlsignal ValuesAxis::onMaxChanged(QDateTime max)
96 96 Axis emits signal when \a max of axis has changed.
97 97 */
98 98
99 99 /*!
100 \fn void QDateTimeAxis::rangeChanged(qreal min, qreal max)
100 \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max)
101 101 Axis emits signal when \a min or \a max of axis has changed.
102 102 */
103 103
104 104 /*!
105 105 \property QDateTimeAxis::ticksCount
106 106 The number of tick marks for the axis.
107 107 */
108 108
109 109 /*!
110 110 \qmlproperty int ValuesAxis::ticksCount
111 111 The number of tick marks for the axis.
112 112 */
113 113
114 114 /*!
115 \property QDateTimeAxis::niceNumbersEnabled
116 Whether the nice numbers algorithm is enabled or not for the axis.
117 */
118
119 /*!
120 \qmlproperty bool ValuesAxis::niceNumbersEnabled
121 Whether the nice numbers algorithm is enabled or not for the axis.
122 */
123
124 /*!
125 115 Constructs an axis object which is a child of \a parent.
126 116 */
127 117 QDateTimeAxis::QDateTimeAxis(QObject *parent) :
128 118 QAbstractAxis(*new QDateTimeAxisPrivate(this),parent)
129 119 {
130 120
131 121 }
132 122
133 123 /*!
134 124 \internal
135 125 */
136 126 QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
137 127 {
138 128
139 129 }
140 130
141 131 /*!
142 132 Destroys the object
143 133 */
144 134 QDateTimeAxis::~QDateTimeAxis()
145 135 {
146 136
147 137 }
148 138
149 139 void QDateTimeAxis::setMin(QDateTime min)
150 140 {
151 141 Q_D(QDateTimeAxis);
152 142 if (min.isValid())
153 143 setRange(min, qMax(d->m_max, min));
154 144 }
155 145
156 146 QDateTime QDateTimeAxis::min() const
157 147 {
158 148 Q_D(const QDateTimeAxis);
159 149 return d->m_min;
160 150 }
161 151
162 152 void QDateTimeAxis::setMax(QDateTime max)
163 153 {
164 154 Q_D(QDateTimeAxis);
165 155 if (max.isValid())
166 156 setRange(qMin(d->m_min, max), max);
167 157 }
168 158
169 159 QDateTime QDateTimeAxis::max() const
170 160 {
171 161 Q_D(const QDateTimeAxis);
172 162 return d->m_max;
173 163 }
174 164
175 165 /*!
176 166 Sets range from \a min to \a max on the axis.
177 167 If min is greater than max then this function returns without making any changes.
178 168 */
179 169 void QDateTimeAxis::setRange(QDateTime min, QDateTime max)
180 170 {
181 171 Q_D(QDateTimeAxis);
182 172 if (!min.isValid() || !max.isValid() || min > max)
183 173 return;
184 174
185 175 bool changed = false;
186 176 if (d->m_min != min) {
187 177 d->m_min = min;
188 178 changed = true;
189 179 emit minChanged(min);
190 180 }
191 181
192 182 if (d->m_max != max) {
193 183 d->m_max = max;
194 184 changed = true;
195 185 emit maxChanged(max);
196 186 }
197 187
198 188 // if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount);
199 189
200 190 if (changed) {
201 191 emit rangeChanged(d->m_min,d->m_max);
202 192 d->emitUpdated();
203 193 }
204 194 }
205 195
196 /*!
197 Sets \a format string that is used when creating label for the axis out of the QDateTime object.
198 Check QDateTime documentation for information on how the string should be defined.
199 \sa formatString()
200 */
206 201 void QDateTimeAxis::setFormatString(QString format)
207 202 {
208 203 Q_D(QDateTimeAxis);
209 204 d->m_format = format;
210 205 }
211 206
207 /*!
208 Returns the format string that is used when creating label for the axis out of the QDateTime object.
209 Check QDateTime documentation for information on how the string should be defined.
210 \sa setFormatString()
211 */
212 212 QString QDateTimeAxis::formatString() const
213 213 {
214 214 Q_D(const QDateTimeAxis);
215 215 return d->m_format;
216 216 }
217 217
218 218 /*!
219 219 Sets \a count for ticks on the axis.
220 220 */
221 221 void QDateTimeAxis::setTicksCount(int count)
222 222 {
223 223 Q_D(QDateTimeAxis);
224 224 if (d->m_tickCount != count && count >=2) {
225 225 d->m_tickCount = count;
226 226 d->emitUpdated();
227 227 }
228 228 }
229 229
230 230 /*!
231 231 \fn int QDateTimeAxis::ticksCount() const
232 232 Return number of ticks on the axis
233 233 */
234 234 int QDateTimeAxis::ticksCount() const
235 235 {
236 236 Q_D(const QDateTimeAxis);
237 237 return d->m_tickCount;
238 238 }
239 239
240 240 /*!
241 241 Returns the type of the axis
242 242 */
243 243 QAbstractAxis::AxisType QDateTimeAxis::type() const
244 244 {
245 245 return AxisTypeDateTime;
246 246 }
247 247
248 248 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
249 249
250 250 QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis* q):
251 251 QAbstractAxisPrivate(q),
252 252 m_tickCount(5)
253 253 {
254 254 m_min = QDateTime::fromMSecsSinceEpoch(0);
255 255 m_max = QDateTime::fromMSecsSinceEpoch(0);
256 256 m_format = "hh:mm:ss\ndd-mm-yyyy";
257 257 }
258 258
259 259 QDateTimeAxisPrivate::~QDateTimeAxisPrivate()
260 260 {
261 261
262 262 }
263 263
264 264 void QDateTimeAxisPrivate::handleDomainUpdated()
265 265 {
266 266 Q_Q(QDateTimeAxis);
267 267 Domain* domain = qobject_cast<Domain*>(sender());
268 268 Q_ASSERT(domain);
269 269
270 270 if(orientation()==Qt::Horizontal){
271 271 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX()));
272 272 }else if(orientation()==Qt::Vertical){
273 273 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY()));
274 274 }
275 275 }
276 276
277 277
278 278 void QDateTimeAxisPrivate::setMin(const QVariant &min)
279 279 {
280 280 Q_Q(QDateTimeAxis);
281 281 if (min.canConvert(QVariant::DateTime))
282 282 q->setMin(min.toDateTime());
283 283 }
284 284
285 285 void QDateTimeAxisPrivate::setMax(const QVariant &max)
286 286 {
287 287
288 288 Q_Q(QDateTimeAxis);
289 289 if (max.canConvert(QVariant::DateTime))
290 290 q->setMax(max.toDateTime());
291 291 }
292 292
293 293 void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max)
294 294 {
295 295 Q_Q(QDateTimeAxis);
296 296 if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime))
297 297 q->setRange(min.toDateTime(), max.toDateTime());
298 298 }
299 299
300 300 ChartAxis* QDateTimeAxisPrivate::createGraphics(ChartPresenter* presenter)
301 301 {
302 302 Q_Q(QDateTimeAxis);
303 303 if(m_orientation == Qt::Vertical){
304 304 return new ChartDateTimeAxisY(q,presenter);
305 305 }else{
306 306 return new ChartDateTimeAxisX(q,presenter);
307 307 }
308 308
309 309 }
310 310
311 311 void QDateTimeAxisPrivate::intializeDomain(Domain* domain)
312 312 {
313 313 Q_Q(QDateTimeAxis);
314 314 if(m_max == m_min) {
315 315 if(m_orientation==Qt::Vertical){
316 316 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY()));
317 317 }else{
318 318 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX()));
319 319 }
320 320 } else {
321 321 if(m_orientation==Qt::Vertical){
322 322 domain->setRangeY(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch());
323 323 }else{
324 324 domain->setRangeX(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch());
325 325 }
326 326 }
327 327 }
328 328
329 329 #include "moc_qdatetimeaxis.cpp"
330 330 #include "moc_qdatetimeaxis_p.cpp"
331 331
332 332 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,212 +1,221
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qintervalsaxis.h"
22 22 #include "qintervalsaxis_p.h"
23 23 #include "chartintervalsaxisx_p.h"
24 24 #include "chartintervalsaxisy_p.h"
25 25 #include <qmath.h>
26 26 #include <QDebug>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29 /*!
30 30 \internal
31 31 \class QIntervalsAxis
32 32 \brief The QIntervalsAxis class is used for manipulating chart's axis.
33 33 \mainclass
34 34
35 35 Axis can be setup to show axis line with tick marks, grid lines and shades.
36 36 */
37 37
38 38 /*!
39 39 \qmlclass Axis QIntervalsAxis
40 40 \brief The Axis element is used for manipulating chart's axes.
41 41
42 42 Axis can be setup to show axis line with tick marks, grid lines and shades.
43 43
44 44 To access Axes you can use ChartView API. For example:
45 45 \code
46 46 // TODO :)
47 47 \endcode
48 48 */
49 49
50 50 /*!
51 51 Constructs an axis object which is a child of \a parent.
52 52 */
53 53 QIntervalsAxis::QIntervalsAxis(QObject *parent):
54 54 QValuesAxis(*new QIntervalsAxisPrivate(this),parent)
55 55 {
56 56 }
57 57
58 58 /*!
59 59 Destroys the object
60 60 */
61 61 QIntervalsAxis::~QIntervalsAxis()
62 62 {
63 63 }
64 64
65 65 /*!
66 66 \internal
67 67 */
68 68 QIntervalsAxis::QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
69 69 {
70 70
71 71 }
72 72
73 73 /*!
74 Appends \a category to axis
74 Appends new interval to the axis with an \a intervalLabel.
75 Parameter \a interval specifies the high end limit of the interval.
75 76 */
76 77 void QIntervalsAxis::append(const QString& intervalLabel, qreal interval)
77 78 {
78 79 Q_D(QIntervalsAxis);
79 80
80 81 if (!d->m_intervals.contains(intervalLabel))
81 82 {
82 83 if(d->m_intervals.isEmpty()){
83 84 Range range(d->m_categoryMinimum,interval);
84 85 d->m_intervalsMap.insert(intervalLabel, range);
85 86 d->m_intervals.append(intervalLabel);
86 87 }else if (interval > intervalMax(d->m_intervals.last())){
87 88 Range range = d->m_intervalsMap.value(d->m_intervals.last());
88 89 d->m_intervalsMap.insert(intervalLabel, Range(range.second,interval));
89 90 d->m_intervals.append(intervalLabel);
90 91 }
91 92 }
92 93 }
93 94
95 /*!
96 Sets to \a min the low end limit of the first interval on the axis.
97 */
94 98 void QIntervalsAxis::setFisrtIntervalMinimum(qreal min)
95 99 {
96 100 Q_D(QIntervalsAxis);
97 101 if(d->m_intervals.isEmpty()){
98 102 d->m_categoryMinimum = min;
99 103 }else{
100 104 Range range = d->m_intervalsMap.value(d->m_intervals.first());
101 105 d->m_intervalsMap.insert(d->m_intervals.first(), Range(min, range.second));
102 // setRange(min, d->m_min);
103 106 }
104 107 }
105 108
109 /*!
110 Returns the low end limit of the interval specified by an \a intervalLabel
111 */
106 112 qreal QIntervalsAxis::intervalMin(const QString& intervalLabel) const
107 113 {
108 114 Q_D(const QIntervalsAxis);
109 115 return d->m_intervalsMap.value(intervalLabel).first;
110 116 }
111 117
118 /*!
119 Returns the high end limit of the interval specified by an \a intervalLabel
120 */
112 121 qreal QIntervalsAxis::intervalMax(const QString& intervalLabel) const
113 122 {
114 123 Q_D(const QIntervalsAxis);
115 124 return d->m_intervalsMap.value(intervalLabel).second;
116 125 }
117 126
118 127 /*!
119 Removes \a category from axis
128 Removes \a interval from axis
120 129 */
121 130 void QIntervalsAxis::remove(const QString &intervalLabel)
122 131 {
123 132 Q_D(QIntervalsAxis);
124 133 int labelIndex = d->m_intervals.indexOf(intervalLabel);
125 134
126 135 // check if such label exists
127 136 if (labelIndex != -1) {
128 137 d->m_intervals.removeAt(labelIndex);
129 138 d->m_intervalsMap.remove(intervalLabel);
130 139
131 140 // the range of the interval that follows (if exists) needs to be updated
132 141 if (labelIndex < d->m_intervals.count()) {
133 142 QString label = d->m_intervals.at(labelIndex);
134 143 Range range = d->m_intervalsMap.value(label);
135 144
136 145 // set the range
137 146 if (labelIndex == 0) {
138 147 range.first = d->m_categoryMinimum;
139 148 d->m_intervalsMap.insert(label, range);
140 149 } else {
141 150 range.first = d->m_intervalsMap.value(d->m_intervals.at(labelIndex - 1)).second;
142 151 d->m_intervalsMap.insert(label, range);
143 152 }
144 153 }
145 154 }
146 155 }
147 156
148 157 QStringList QIntervalsAxis::intervalsLabels()
149 158 {
150 159 Q_D(QIntervalsAxis);
151 160 return d->m_intervals;
152 161 }
153 162
154 163 /*!
155 164 Returns number of categories.
156 165 */
157 166 int QIntervalsAxis::count() const
158 167 {
159 168 Q_D(const QIntervalsAxis);
160 169 return d->m_intervals.count();
161 170 }
162 171
163 172 /*!
164 173 Returns the type of the axis
165 174 */
166 175 QAbstractAxis::AxisType QIntervalsAxis::type() const
167 176 {
168 177 return QAbstractAxis::AxisTypeIntervals;
169 178 }
170 179
171 180 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
172 181
173 182 QIntervalsAxisPrivate::QIntervalsAxisPrivate(QIntervalsAxis* q):
174 183 QValuesAxisPrivate(q),
175 184 m_categoryMinimum(0)
176 185 {
177 186
178 187 }
179 188
180 189 QIntervalsAxisPrivate::~QIntervalsAxisPrivate()
181 190 {
182 191
183 192 }
184 193
185 194 int QIntervalsAxisPrivate::ticksCount() const
186 195 {
187 196 return m_intervals.count() + 1;
188 197 }
189 198
190 199 void QIntervalsAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
191 200 {
192 201 Q_UNUSED(count);
193 202 Q_UNUSED(min);
194 203 Q_UNUSED(max);
195 204 //m_min = min;
196 205 //m_max = max;
197 206 }
198 207
199 208 ChartAxis* QIntervalsAxisPrivate::createGraphics(ChartPresenter* presenter)
200 209 {
201 210 Q_Q(QIntervalsAxis);
202 211 if(m_orientation == Qt::Vertical){
203 212 return new ChartIntervalAxisY(q,presenter);
204 213 }else{
205 214 return new ChartIntervalAxisX(q,presenter);
206 215 }
207 216 }
208 217
209 218 #include "moc_qintervalsaxis.cpp"
210 219 #include "moc_qintervalsaxis_p.cpp"
211 220
212 221 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,814 +1,845
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qpieseries.h"
22 22 #include "qpieseries_p.h"
23 23 #include "qpieslice.h"
24 24 #include "qpieslice_p.h"
25 25 #include "pieslicedata_p.h"
26 26 #include "chartdataset_p.h"
27 27 #include "charttheme_p.h"
28 28 #include "chartanimator_p.h"
29 29 #include "legendmarker_p.h"
30 30 #include "qabstractaxis.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 /*!
35 35 \class QPieSeries
36 36 \brief Pie series API for QtCommercial Charts
37 37
38 38 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
39 39 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
40 40 The actual slice size is determined by that relative value.
41 41
42 42 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
43 43 These relate to the actual chart rectangle.
44 44
45 45 By default the pie is defined as a full pie but it can also be a partial pie.
46 46 This can be done by setting a starting angle and angle span to the series.
47 47 Full pie is 360 degrees where 0 is at 12 a'clock.
48 48
49 49 See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
50 50 \image examples_piechart.png
51 51 */
52 52 /*!
53 53 \qmlclass PieSeries QPieSeries
54 54 \inherits AbstractSeries
55 55
56 56 The following QML shows how to create a simple pie chart.
57 57
58 58 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
59 59
60 60 \beginfloatleft
61 61 \image demos_qmlchart1.png
62 62 \endfloat
63 63 \clearfloat
64 64 */
65 65
66 66 /*!
67 67 \property QPieSeries::horizontalPosition
68 68 \brief Defines the horizontal position of the pie.
69 69
70 70 The value is a relative value to the chart rectangle where:
71 71
72 72 \list
73 73 \o 0.0 is the absolute left.
74 74 \o 1.0 is the absolute right.
75 75 \endlist
76 76 Default value is 0.5 (center).
77 77 \sa verticalPosition
78 78 */
79 79
80 80 /*!
81 81 \qmlproperty real PieSeries::horizontalPosition
82 82
83 83 Defines the horizontal position of the pie.
84 84
85 85 The value is a relative value to the chart rectangle where:
86 86
87 87 \list
88 88 \o 0.0 is the absolute left.
89 89 \o 1.0 is the absolute right.
90 90 \endlist
91 91 Default value is 0.5 (center).
92 92 \sa verticalPosition
93 93 */
94 94
95 95 /*!
96 96 \property QPieSeries::verticalPosition
97 97 \brief Defines the vertical position of the pie.
98 98
99 99 The value is a relative value to the chart rectangle where:
100 100
101 101 \list
102 102 \o 0.0 is the absolute top.
103 103 \o 1.0 is the absolute bottom.
104 104 \endlist
105 105 Default value is 0.5 (center).
106 106 \sa horizontalPosition
107 107 */
108 108
109 109 /*!
110 110 \qmlproperty real PieSeries::verticalPosition
111 111
112 112 Defines the vertical position of the pie.
113 113
114 114 The value is a relative value to the chart rectangle where:
115 115
116 116 \list
117 117 \o 0.0 is the absolute top.
118 118 \o 1.0 is the absolute bottom.
119 119 \endlist
120 120 Default value is 0.5 (center).
121 121 \sa horizontalPosition
122 122 */
123 123
124 124 /*!
125 125 \property QPieSeries::size
126 126 \brief Defines the pie size.
127 127
128 128 The value is a relative value to the chart rectangle where:
129 129
130 130 \list
131 131 \o 0.0 is the minimum size (pie not drawn).
132 132 \o 1.0 is the maximum size that can fit the chart.
133 133 \endlist
134 134
135 135 Default value is 0.7.
136 136 */
137 137
138 138 /*!
139 139 \qmlproperty real PieSeries::size
140 140
141 141 Defines the pie size.
142 142
143 143 The value is a relative value to the chart rectangle where:
144 144
145 145 \list
146 146 \o 0.0 is the minimum size (pie not drawn).
147 147 \o 1.0 is the maximum size that can fit the chart.
148 148 \endlist
149 149
150 150 Default value is 0.7.
151 151 */
152 152
153 153 /*!
154 \property QPieSeries::donutInnerSize
155 \brief Defines the donut inner size.
156
157 The value is a relative value to the chart rectangle where:
158
159 \list
160 \o 0.0 is the minimum size (pie not drawn).
161 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
162 \endlist
163
164 The value is never greater then size property.
165 Default value is 0.5.
166 */
167
168 /*!
169 \qmlproperty real PieSeries::donutInnerSize
170
171 Defines the donut inner size.
172
173 The value is a relative value to the chart rectangle where:
174
175 \list
176 \o 0.0 is the minimum size (donut is a pie).
177 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
178 \endlist
179
180 The value is never greater then size property.
181 Default value is 0.5.
182 */
183
184 /*!
154 185 \property QPieSeries::startAngle
155 186 \brief Defines the starting angle of the pie.
156 187
157 188 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
158 189
159 190 Default is value is 0.
160 191 */
161 192
162 193 /*!
163 194 \qmlproperty real PieSeries::startAngle
164 195
165 196 Defines the starting angle of the pie.
166 197
167 198 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
168 199
169 200 Default is value is 0.
170 201 */
171 202
172 203 /*!
173 204 \property QPieSeries::endAngle
174 205 \brief Defines the ending angle of the pie.
175 206
176 207 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
177 208
178 209 Default is value is 360.
179 210 */
180 211
181 212 /*!
182 213 \qmlproperty real PieSeries::endAngle
183 214
184 215 Defines the ending angle of the pie.
185 216
186 217 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
187 218
188 219 Default is value is 360.
189 220 */
190 221
191 222 /*!
192 223 \property QPieSeries::count
193 224
194 225 Number of slices in the series.
195 226 */
196 227
197 228 /*!
198 229 \qmlproperty int PieSeries::count
199 230
200 231 Number of slices in the series.
201 232 */
202 233
203 234 /*!
204 235 \fn void QPieSeries::countChanged()
205 236 Emitted when the slice count has changed.
206 237 \sa count
207 238 */
208 239 /*!
209 240 \qmlsignal PieSeries::onCountChanged()
210 241 Emitted when the slice count has changed.
211 242 */
212 243
213 244 /*!
214 245 \property QPieSeries::sum
215 246
216 247 Sum of all slices.
217 248
218 249 The series keeps track of the sum of all slices it holds.
219 250 */
220 251
221 252 /*!
222 253 \qmlproperty real PieSeries::sum
223 254
224 255 Sum of all slices.
225 256
226 257 The series keeps track of the sum of all slices it holds.
227 258 */
228 259
229 260 /*!
230 261 \fn void QPieSeries::sumChanged()
231 262 Emitted when the sum of all slices has changed.
232 263 \sa sum
233 264 */
234 265 /*!
235 266 \qmlsignal PieSeries::onSumChanged()
236 267 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
237 268 change value of a slice.
238 269 */
239 270
240 271 /*!
241 272 \fn void QPieSeries::added(QList<QPieSlice*> slices)
242 273
243 274 This signal is emitted when \a slices have been added to the series.
244 275
245 276 \sa append(), insert()
246 277 */
247 278 /*!
248 279 \qmlsignal PieSeries::onAdded(PieSlice slice)
249 280 Emitted when \a slice has been added to the series.
250 281 */
251 282
252 283 /*!
253 284 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
254 285 This signal is emitted when \a slices have been removed from the series.
255 286 \sa remove()
256 287 */
257 288 /*!
258 289 \qmlsignal PieSeries::onRemoved(PieSlice slice)
259 290 Emitted when \a slice has been removed from the series.
260 291 */
261 292
262 293 /*!
263 294 \fn void QPieSeries::clicked(QPieSlice* slice)
264 295 This signal is emitted when a \a slice has been clicked.
265 296 \sa QPieSlice::clicked()
266 297 */
267 298 /*!
268 299 \qmlsignal PieSeries::onClicked(PieSlice slice)
269 300 This signal is emitted when a \a slice has been clicked.
270 301 */
271 302
272 303 /*!
273 304 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
274 305 This signal is emitted when user has hovered over or away from the \a slice.
275 306 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
276 307 \sa QPieSlice::hovered()
277 308 */
278 309 /*!
279 310 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
280 311 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
281 312 over the slice and false when hover has moved away from the slice.
282 313 */
283 314
284 315 /*!
285 316 \qmlmethod PieSlice PieSeries::at(int index)
286 317 Returns slice at \a index. Returns null if the index is not valid.
287 318 */
288 319
289 320 /*!
290 321 \qmlmethod PieSlice PieSeries::find(string label)
291 322 Returns the first slice with \a label. Returns null if the index is not valid.
292 323 */
293 324
294 325 /*!
295 326 \qmlmethod PieSlice PieSeries::append(string label, real value)
296 327 Adds a new slice with \a label and \a value to the pie.
297 328 */
298 329
299 330 /*!
300 331 \qmlmethod bool PieSeries::remove(PieSlice slice)
301 332 Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise.
302 333 */
303 334
304 335 /*!
305 336 \qmlmethod PieSeries::clear()
306 337 Removes all slices from the pie.
307 338 */
308 339
309 340 /*!
310 341 Constructs a series object which is a child of \a parent.
311 342 */
312 343 QPieSeries::QPieSeries(QObject *parent) :
313 344 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
314 345 {
315 346
316 347 }
317 348
318 349 /*!
319 350 Destroys the series and its slices.
320 351 */
321 352 QPieSeries::~QPieSeries()
322 353 {
323 354 // NOTE: d_prt destroyed by QObject
324 355 }
325 356
326 357 /*!
327 358 Returns QChartSeries::SeriesTypePie.
328 359 */
329 360 QAbstractSeries::SeriesType QPieSeries::type() const
330 361 {
331 362 return QAbstractSeries::SeriesTypePie;
332 363 }
333 364
334 365 /*!
335 366 Appends a single \a slice to the series.
336 367 Slice ownership is passed to the series.
337 368
338 369 Returns true if append was succesfull.
339 370 */
340 371 bool QPieSeries::append(QPieSlice* slice)
341 372 {
342 373 return append(QList<QPieSlice*>() << slice);
343 374 }
344 375
345 376 /*!
346 377 Appends an array of \a slices to the series.
347 378 Slice ownership is passed to the series.
348 379
349 380 Returns true if append was successfull.
350 381 */
351 382 bool QPieSeries::append(QList<QPieSlice*> slices)
352 383 {
353 384 Q_D(QPieSeries);
354 385
355 386 if (slices.count() == 0)
356 387 return false;
357 388
358 389 foreach (QPieSlice* s, slices) {
359 390 if (!s || d->m_slices.contains(s))
360 391 return false;
361 392 if (s->series()) // already added to some series
362 393 return false;
363 394 }
364 395
365 396 foreach (QPieSlice* s, slices) {
366 397 s->setParent(this);
367 398 QPieSlicePrivate::fromSlice(s)->m_series = this;
368 399 d->m_slices << s;
369 400 }
370 401
371 402 d->updateDerivativeData();
372 403
373 404 foreach (QPieSlice* s, slices) {
374 405 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
375 406 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
376 407 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
377 408 }
378 409
379 410 emit added(slices);
380 411 emit countChanged();
381 412
382 413 return true;
383 414 }
384 415
385 416 /*!
386 417 Appends a single \a slice to the series and returns a reference to the series.
387 418 Slice ownership is passed to the series.
388 419 */
389 420 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
390 421 {
391 422 append(slice);
392 423 return *this;
393 424 }
394 425
395 426
396 427 /*!
397 428 Appends a single slice to the series with give \a value and \a label.
398 429 Slice ownership is passed to the series.
399 430 */
400 431 QPieSlice* QPieSeries::append(QString label, qreal value)
401 432 {
402 433 QPieSlice* slice = new QPieSlice(label, value);
403 434 append(slice);
404 435 return slice;
405 436 }
406 437
407 438 /*!
408 439 Inserts a single \a slice to the series before the slice at \a index position.
409 440 Slice ownership is passed to the series.
410 441
411 442 Returns true if insert was successfull.
412 443 */
413 444 bool QPieSeries::insert(int index, QPieSlice* slice)
414 445 {
415 446 Q_D(QPieSeries);
416 447
417 448 if (index < 0 || index > d->m_slices.count())
418 449 return false;
419 450
420 451 if (!slice || d->m_slices.contains(slice))
421 452 return false;
422 453
423 454 if (slice->series()) // already added to some series
424 455 return false;
425 456
426 457 slice->setParent(this);
427 458 QPieSlicePrivate::fromSlice(slice)->m_series = this;
428 459 d->m_slices.insert(index, slice);
429 460
430 461 d->updateDerivativeData();
431 462
432 463 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
433 464 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
434 465 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
435 466
436 467 emit added(QList<QPieSlice*>() << slice);
437 468 emit countChanged();
438 469
439 470 return true;
440 471 }
441 472
442 473 /*!
443 474 Removes a single \a slice from the series and deletes the slice.
444 475
445 476 Do not reference the pointer after this call.
446 477
447 478 Returns true if remove was successfull.
448 479 */
449 480 bool QPieSeries::remove(QPieSlice* slice)
450 481 {
451 482 Q_D(QPieSeries);
452 483
453 484 if (!d->m_slices.removeOne(slice))
454 485 return false;
455 486
456 487 d->updateDerivativeData();
457 488
458 489 emit removed(QList<QPieSlice*>() << slice);
459 490 emit countChanged();
460 491
461 492 delete slice;
462 493 slice = 0;
463 494
464 495 return true;
465 496 }
466 497
467 498 /*!
468 499 Clears all slices from the series.
469 500 */
470 501 void QPieSeries::clear()
471 502 {
472 503 Q_D(QPieSeries);
473 504 if (d->m_slices.count() == 0)
474 505 return;
475 506
476 507 QList<QPieSlice*> slices = d->m_slices;
477 508 foreach (QPieSlice* s, d->m_slices) {
478 509 d->m_slices.removeOne(s);
479 510 delete s;
480 511 }
481 512
482 513 d->updateDerivativeData();
483 514
484 515 emit removed(slices);
485 516 emit countChanged();
486 517 }
487 518
488 519 /*!
489 520 Returns a list of slices that belong to this series.
490 521 */
491 522 QList<QPieSlice*> QPieSeries::slices() const
492 523 {
493 524 Q_D(const QPieSeries);
494 525 return d->m_slices;
495 526 }
496 527
497 528 /*!
498 529 returns the number of the slices in this series.
499 530 */
500 531 int QPieSeries::count() const
501 532 {
502 533 Q_D(const QPieSeries);
503 534 return d->m_slices.count();
504 535 }
505 536
506 537 /*!
507 538 Returns true is the series is empty.
508 539 */
509 540 bool QPieSeries::isEmpty() const
510 541 {
511 542 Q_D(const QPieSeries);
512 543 return d->m_slices.isEmpty();
513 544 }
514 545
515 546 /*!
516 547 Returns the sum of all slice values in this series.
517 548
518 549 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
519 550 */
520 551 qreal QPieSeries::sum() const
521 552 {
522 553 Q_D(const QPieSeries);
523 554 return d->m_sum;
524 555 }
525 556
526 557 void QPieSeries::setDonut(bool donut)
527 558 {
528 559 Q_D(QPieSeries);
529 560 d->m_donutChart = donut;
530 561 d->updateDerivativeData();
531 562 }
532 563
533 564 bool QPieSeries::donut() const
534 565 {
535 566 Q_D(const QPieSeries);
536 567 return d->m_donutChart;
537 568 }
538 569
539 570 void QPieSeries::setDonutInnerSize(qreal innerSize)
540 571 {
541 572 Q_D(QPieSeries);
542 573
543 574 if (innerSize < 0.0)
544 575 innerSize = 0.0;
545 if (innerSize > 1.0)
546 innerSize = 1.0;
576 if (innerSize > d->m_pieRelativeSize)
577 innerSize = d->m_pieRelativeSize;
547 578
548 579 d->m_donutRelativeInnerSize = innerSize;
549 580 d->updateDerivativeData();
550 581 emit d->pieSizeChanged();
551 582 }
552 583
553 584 qreal QPieSeries::donutInnerSize() const
554 585 {
555 586 Q_D(const QPieSeries);
556 587 return d->m_donutRelativeInnerSize;
557 588 }
558 589
559 590 void QPieSeries::setHorizontalPosition(qreal relativePosition)
560 591 {
561 592 Q_D(QPieSeries);
562 593
563 594 if (relativePosition < 0.0)
564 595 relativePosition = 0.0;
565 596 if (relativePosition > 1.0)
566 597 relativePosition = 1.0;
567 598
568 599 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
569 600 d->m_pieRelativeHorPos = relativePosition;
570 601 emit d->horizontalPositionChanged();
571 602 }
572 603 }
573 604
574 605 qreal QPieSeries::horizontalPosition() const
575 606 {
576 607 Q_D(const QPieSeries);
577 608 return d->m_pieRelativeHorPos;
578 609 }
579 610
580 611 void QPieSeries::setVerticalPosition(qreal relativePosition)
581 612 {
582 613 Q_D(QPieSeries);
583 614
584 615 if (relativePosition < 0.0)
585 616 relativePosition = 0.0;
586 617 if (relativePosition > 1.0)
587 618 relativePosition = 1.0;
588 619
589 620 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
590 621 d->m_pieRelativeVerPos = relativePosition;
591 622 emit d->verticalPositionChanged();
592 623 }
593 624 }
594 625
595 626 qreal QPieSeries::verticalPosition() const
596 627 {
597 628 Q_D(const QPieSeries);
598 629 return d->m_pieRelativeVerPos;
599 630 }
600 631
601 632 void QPieSeries::setPieSize(qreal relativeSize)
602 633 {
603 634 Q_D(QPieSeries);
604 635
605 636 if (relativeSize < 0.0)
606 637 relativeSize = 0.0;
607 638 if (relativeSize > 1.0)
608 639 relativeSize = 1.0;
609 640
610 641 if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) {
611 642 d->m_pieRelativeSize = relativeSize;
612 643 emit d->pieSizeChanged();
613 644 }
614 645 }
615 646
616 647 qreal QPieSeries::pieSize() const
617 648 {
618 649 Q_D(const QPieSeries);
619 650 return d->m_pieRelativeSize;
620 651 }
621 652
622 653
623 654 void QPieSeries::setPieStartAngle(qreal angle)
624 655 {
625 656 Q_D(QPieSeries);
626 657 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
627 658 return;
628 659 d->m_pieStartAngle = angle;
629 660 d->updateDerivativeData();
630 661 emit d->pieStartAngleChanged();
631 662 }
632 663
633 664 qreal QPieSeries::pieStartAngle() const
634 665 {
635 666 Q_D(const QPieSeries);
636 667 return d->m_pieStartAngle;
637 668 }
638 669
639 670 /*!
640 671 Sets the end angle of the pie.
641 672
642 673 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
643 674
644 675 \a angle must be greater than start angle.
645 676
646 677 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
647 678 */
648 679 void QPieSeries::setPieEndAngle(qreal angle)
649 680 {
650 681 Q_D(QPieSeries);
651 682 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
652 683 return;
653 684 d->m_pieEndAngle = angle;
654 685 d->updateDerivativeData();
655 686 emit d->pieEndAngleChanged();
656 687 }
657 688
658 689 /*!
659 690 Returns the end angle of the pie.
660 691
661 692 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
662 693
663 694 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
664 695 */
665 696 qreal QPieSeries::pieEndAngle() const
666 697 {
667 698 Q_D(const QPieSeries);
668 699 return d->m_pieEndAngle;
669 700 }
670 701
671 702 /*!
672 703 Sets the all the slice labels \a visible or invisible.
673 704
674 705 Note that this affects only the current slices in the series.
675 706 If user adds a new slice the default label visibility is false.
676 707
677 708 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
678 709 */
679 710 void QPieSeries::setLabelsVisible(bool visible)
680 711 {
681 712 Q_D(QPieSeries);
682 713 foreach (QPieSlice* s, d->m_slices)
683 714 s->setLabelVisible(visible);
684 715 }
685 716
686 717 void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
687 718 {
688 719 Q_D(QPieSeries);
689 720 foreach (QPieSlice* s, d->m_slices)
690 721 s->setLabelPosition(position);
691 722 }
692 723
693 724 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
694 725
695 726
696 727 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
697 728 QAbstractSeriesPrivate(parent),
698 729 m_pieRelativeHorPos(0.5),
699 730 m_pieRelativeVerPos(0.5),
700 731 m_pieRelativeSize(0.7),
701 732 m_pieStartAngle(0),
702 733 m_pieEndAngle(360),
703 734 m_sum(0),
704 735 m_donutChart(false),
705 736 m_donutRelativeInnerSize(0.5)
706 737 {
707 738 }
708 739
709 740 QPieSeriesPrivate::~QPieSeriesPrivate()
710 741 {
711 742 }
712 743
713 744 void QPieSeriesPrivate::updateDerivativeData()
714 745 {
715 746 // calculate sum of all slices
716 747 qreal sum = 0;
717 748 foreach (QPieSlice* s, m_slices)
718 749 sum += s->value();
719 750
720 751 if (!qFuzzyIsNull(m_sum - sum)) {
721 752 m_sum = sum;
722 753 emit q_func()->sumChanged();
723 754 }
724 755
725 756 // nothing to show..
726 757 if (qFuzzyIsNull(m_sum))
727 758 return;
728 759
729 760 // update slice attributes
730 761 qreal sliceAngle = m_pieStartAngle;
731 762 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
732 763 QVector<QPieSlice*> changed;
733 764 foreach (QPieSlice* s, m_slices) {
734 765 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
735 766 d->setPercentage(s->value() / m_sum);
736 767 d->setStartAngle(sliceAngle);
737 768 d->setAngleSpan(pieSpan * s->percentage());
738 769 sliceAngle += s->angleSpan();
739 770 }
740 771
741 772
742 773 emit calculatedDataChanged();
743 774 }
744 775
745 776 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
746 777 {
747 778 return series->d_func();
748 779 }
749 780
750 781 void QPieSeriesPrivate::sliceValueChanged()
751 782 {
752 783 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
753 784 updateDerivativeData();
754 785 }
755 786
756 787 void QPieSeriesPrivate::sliceClicked()
757 788 {
758 789 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
759 790 Q_ASSERT(m_slices.contains(slice));
760 791 Q_Q(QPieSeries);
761 792 emit q->clicked(slice);
762 793 }
763 794
764 795 void QPieSeriesPrivate::sliceHovered(bool state)
765 796 {
766 797 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
767 798 Q_ASSERT(m_slices.contains(slice));
768 799 Q_Q(QPieSeries);
769 800 emit q->hovered(slice, state);
770 801 }
771 802
772 803 void QPieSeriesPrivate::scaleDomain(Domain& domain)
773 804 {
774 805 Q_UNUSED(domain);
775 806 // does not apply to pie
776 807 }
777 808
778 809 Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
779 810 {
780 811 Q_Q(QPieSeries);
781 812 PieChartItem* pie = new PieChartItem(q,presenter);
782 813 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
783 814 presenter->animator()->addAnimation(pie);
784 815 }
785 816 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
786 817 return pie;
787 818 }
788 819
789 820 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
790 821 {
791 822 Q_Q(QPieSeries);
792 823 QList<LegendMarker*> markers;
793 824 foreach(QPieSlice* slice, q->slices()) {
794 825 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
795 826 markers << marker;
796 827 }
797 828 return markers;
798 829 }
799 830
800 831 void QPieSeriesPrivate::initializeAxis(QAbstractAxis* axis)
801 832 {
802 833 Q_UNUSED(axis);
803 834 }
804 835
805 836 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
806 837 {
807 838 Q_UNUSED(orientation);
808 839 return QAbstractAxis::AxisTypeNoAxis;
809 840 }
810 841
811 842 #include "moc_qpieseries.cpp"
812 843 #include "moc_qpieseries_p.cpp"
813 844
814 845 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,104 +1,106
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef PIESERIES_H
22 22 #define PIESERIES_H
23 23
24 24 #include <qabstractseries.h>
25 25 #include <QPieSlice>
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28 class QPieSeriesPrivate;
29 29 //class QPieSlice;
30 30
31 31 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QAbstractSeries
32 32 {
33 33 Q_OBJECT
34 34 Q_PROPERTY(qreal horizontalPosition READ horizontalPosition WRITE setHorizontalPosition)
35 35 Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition)
36 36 Q_PROPERTY(qreal size READ pieSize WRITE setPieSize)
37 37 Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle)
38 38 Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle)
39 39 Q_PROPERTY(int count READ count NOTIFY countChanged)
40 40 Q_PROPERTY(qreal sum READ sum NOTIFY sumChanged)
41 Q_PROPERTY(qreal donutInnerSize READ donutInnerSize WRITE setDonutInnerSize)
42 Q_PROPERTY(bool donut READ donut WRITE setDonut)
41 43
42 44 public:
43 45 explicit QPieSeries(QObject *parent = 0);
44 46 virtual ~QPieSeries();
45 47
46 48 QAbstractSeries::SeriesType type() const;
47 49
48 50 bool append(QPieSlice* slice);
49 51 bool append(QList<QPieSlice*> slices);
50 52 QPieSeries& operator << (QPieSlice* slice);
51 53 QPieSlice* append(QString label, qreal value);
52 54
53 55 bool insert(int index, QPieSlice* slice);
54 56
55 57 bool remove(QPieSlice* slice);
56 58 void clear();
57 59
58 60 QList<QPieSlice*> slices() const;
59 61 int count() const;
60 62
61 63 bool isEmpty() const;
62 64
63 65 qreal sum() const;
64 66
65 67 void setDonut(bool donut = true);
66 68 bool donut() const;
67 69
68 70 void setDonutInnerSize(qreal innerSize);
69 71 qreal donutInnerSize() const;
70 72
71 73 void setHorizontalPosition(qreal relativePosition);
72 74 qreal horizontalPosition() const;
73 75
74 76 void setVerticalPosition(qreal relativePosition);
75 77 qreal verticalPosition() const;
76 78
77 79 void setPieSize(qreal relativeSize);
78 80 qreal pieSize() const;
79 81
80 82 void setPieStartAngle(qreal startAngle);
81 83 qreal pieStartAngle() const;
82 84
83 85 void setPieEndAngle(qreal endAngle);
84 86 qreal pieEndAngle() const;
85 87
86 88 void setLabelsVisible(bool visible = true);
87 89 void setLabelsPosition(QPieSlice::LabelPosition position);
88 90
89 91 Q_SIGNALS:
90 92 void added(QList<QPieSlice*> slices);
91 93 void removed(QList<QPieSlice*> slices);
92 94 void clicked(QPieSlice* slice);
93 95 void hovered(QPieSlice* slice, bool state);
94 96 void countChanged();
95 97 void sumChanged();
96 98
97 99 private:
98 100 Q_DECLARE_PRIVATE(QPieSeries)
99 101 Q_DISABLE_COPY(QPieSeries)
100 102 };
101 103
102 104 QTCOMMERCIALCHART_END_NAMESPACE
103 105
104 106 #endif // PIESERIES_H
@@ -1,779 +1,780
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qpieslice.h"
22 22 #include "qpieslice_p.h"
23 23
24 24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 25
26 26 /*!
27 27 \class QPieSlice
28 28 \brief Defines a slice in pie series.
29 29
30 30 This object defines the properties of a single slice in a QPieSeries.
31 31
32 32 In addition to the obvious value and label properties the user can also control
33 33 the visual appearance of a slice. By modifying the visual appearance also means that
34 34 the user is overriding the default appearance set by the theme.
35 35
36 36 Note that if the user has customized slices and theme is changed all customizations will be lost.
37 37
38 38 To enable user interaction with the pie some basic signals are provided about clicking and hovering.
39 39 */
40 40
41 41 /*!
42 42 \qmlclass PieSlice QPieSlice
43 43 PieSlice defines the properties of a single slice in a PieSeries. The element should be used
44 44 as a child for a PieSeries. For example:
45 45 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
46 46
47 47 An alternative (dynamic) method for adding slices to a PieSeries is using PieSeries.append
48 48 method.
49 49 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 4
50 50
51 51 In that case you may want to use PieSeries.at or PieSeries.find to access the properties of
52 52 an individual PieSlice instance.
53 53 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 5
54 54 \sa PieSeries
55 55 */
56 56
57 57 /*!
58 58 \enum QPieSlice::LabelPosition
59 59
60 60 This enum describes the position of the slice label.
61 61
62 62 \value LabelOutside Label is outside the slice with an arm.
63 63 \value LabelInside Label is centered inside the slice.
64
64 \value LabelInsideTangential Label is centered inside the slice and rotated to be parallel to the tangential of the slice's arc
65 \value LabelInsideNormal Label is centered inside the slice rotated to be parallel to the normal of the slice's arc.
65 66 */
66 67
67 68 /*!
68 69 \property QPieSlice::label
69 70 Label of the slice.
70 71 \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor
71 72 */
72 73 /*!
73 74 \qmlproperty string PieSlice::label
74 75 Label (text) of the slice.
75 76 */
76 77
77 78 /*!
78 79 \fn void QPieSlice::labelChanged()
79 80 This signal emitted when the slice label has been changed.
80 81 \sa label
81 82 */
82 83 /*!
83 84 \qmlsignal PieSlice::onLabelChanged()
84 85 This signal emitted when the slice label has been changed.
85 86 \sa label
86 87 */
87 88
88 89 /*!
89 90 \property QPieSlice::value
90 91 Value of the slice.
91 92 Note that if users sets a negative value it is converted to a positive value.
92 93 \sa percentage(), QPieSeries::sum()
93 94 */
94 95 /*!
95 96 \qmlproperty real PieSlice::value
96 97 Value of the slice. Note that if users sets a negative value it is converted to a positive value.
97 98 */
98 99
99 100 /*!
100 101 \fn void QPieSlice::valueChanged()
101 102 This signal is emitted when the slice value changes.
102 103 \sa value
103 104 */
104 105 /*!
105 106 \qmlsignal PieSlice::onValueChanged()
106 107 This signal is emitted when the slice value changes.
107 108 \sa value
108 109 */
109 110
110 111 /*!
111 112 \property QPieSlice::labelVisible
112 113 Defines the visibility of slice label. By default the label is not visible.
113 114 \sa label, labelBrush, labelFont, labelArmLengthFactor
114 115 */
115 116 /*!
116 117 \qmlproperty bool PieSlice::labelVisible
117 118 Defines the visibility of slice label. By default the label is not visible.
118 119 */
119 120
120 121 /*!
121 122 \fn void QPieSlice::labelVisibleChanged()
122 123 This signal emitted when visibility of the slice label has changed.
123 124 \sa labelVisible
124 125 */
125 126 /*!
126 127 \qmlsignal PieSlice::onLabelVisibleChanged()
127 128 This signal emitted when visibility of the slice label has changed.
128 129 \sa labelVisible
129 130 */
130 131
131 132 /*!
132 133 \property QPieSlice::exploded
133 134 If set to true the slice is "exploded" away from the pie.
134 135 \sa explodeDistanceFactor
135 136 */
136 137 /*!
137 138 \qmlproperty bool PieSlice::exploded
138 139 If set to true the slice is "exploded" away from the pie.
139 140 \sa explodeDistanceFactor
140 141 */
141 142
142 143 /*!
143 144 \property QPieSlice::pen
144 145 Pen used to draw the slice border.
145 146 */
146 147
147 148 /*!
148 149 \fn void QPieSlice::penChanged()
149 150 This signal is emitted when the pen of the slice has changed.
150 151 \sa pen
151 152 */
152 153
153 154 /*!
154 155 \property QPieSlice::borderColor
155 156 Color used to draw the slice border.
156 157 This is a convenience property for modifying the slice pen.
157 158 \sa pen, borderWidth
158 159 */
159 160 /*!
160 161 \qmlproperty color PieSlice::borderColor
161 162 Color used to draw the slice border (pen color).
162 163 \sa borderWidth
163 164 */
164 165
165 166 /*!
166 167 \fn void QPieSlice::borderColorChanged()
167 168 This signal is emitted when slice border color changes.
168 169 \sa pen, borderColor
169 170 */
170 171 /*!
171 172 \qmlsignal PieSlice::onBorderColorChanged()
172 173 This signal is emitted when slice border color changes.
173 174 \sa borderColor
174 175 */
175 176
176 177 /*!
177 178 \property QPieSlice::borderWidth
178 179 Width of the slice border.
179 180 This is a convenience property for modifying the slice pen.
180 181 \sa pen, borderColor
181 182 */
182 183 /*!
183 184 \qmlproperty int PieSlice::borderWidth
184 185 Width of the slice border.
185 186 This is a convenience property for modifying the slice pen.
186 187 \sa borderColor
187 188 */
188 189
189 190 /*!
190 191 \fn void QPieSlice::borderWidthChanged()
191 192 This signal is emitted when slice border width changes.
192 193 \sa pen, borderWidth
193 194 */
194 195 /*!
195 196 \qmlsignal PieSlice::onBorderWidthChanged()
196 197 This signal is emitted when slice border width changes.
197 198 \sa borderWidth
198 199 */
199 200
200 201 /*!
201 202 \property QPieSlice::brush
202 203 Brush used to draw the slice.
203 204 */
204 205
205 206 /*!
206 207 \fn void QPieSlice::brushChanged()
207 208 This signal is emitted when the brush of the slice has changed.
208 209 \sa brush
209 210 */
210 211
211 212 /*!
212 213 \property QPieSlice::color
213 214 Fill (brush) color of the slice.
214 215 This is a convenience property for modifying the slice brush.
215 216 \sa brush
216 217 */
217 218 /*!
218 219 \qmlproperty color PieSlice::color
219 220 Fill (brush) color of the slice.
220 221 */
221 222
222 223 /*!
223 224 \fn void QPieSlice::colorChanged()
224 225 This signal is emitted when slice color changes.
225 226 \sa brush
226 227 */
227 228 /*!
228 229 \qmlsignal PieSlice::onColorChanged()
229 230 This signal is emitted when slice color changes.
230 231 */
231 232
232 233 /*!
233 234 \property QPieSlice::labelBrush
234 235 Brush used to draw label and label arm of the slice.
235 236 \sa label, labelVisible, labelFont, labelArmLengthFactor
236 237 */
237 238
238 239 /*!
239 240 \fn void QPieSlice::labelBrushChanged()
240 241 This signal is emitted when the label brush of the slice has changed.
241 242 \sa labelBrush
242 243 */
243 244
244 245 /*!
245 246 \property QPieSlice::labelColor
246 247 Color used to draw the slice label.
247 248 This is a convenience property for modifying the slice label brush.
248 249 \sa labelBrush
249 250 */
250 251 /*!
251 252 \qmlproperty color PieSlice::labelColor
252 253 Color used to draw the slice label.
253 254 */
254 255
255 256 /*!
256 257 \fn void QPieSlice::labelColorChanged()
257 258 This signal is emitted when slice label color changes.
258 259 \sa labelColor
259 260 */
260 261 /*!
261 262 \qmlsignal PieSlice::onLabelColorChanged()
262 263 This signal is emitted when slice label color changes.
263 264 \sa labelColor
264 265 */
265 266
266 267 /*!
267 268 \property QPieSlice::labelFont
268 269 Font used for drawing label text.
269 270 \sa label, labelVisible, labelArmLengthFactor
270 271 */
271 272
272 273 /*!
273 274 \fn void QPieSlice::labelFontChanged()
274 275 This signal is emitted when the label font of the slice has changed.
275 276 \sa labelFont
276 277 */
277 278
278 279 /*!
279 280 \qmlproperty Font PieSlice::labelFont
280 281
281 282 Defines the font used for slice label.
282 283
283 284 See the \l {Font} {QML Font Element} for detailed documentation.
284 285
285 286 \sa labelVisible, labelPosition
286 287 */
287 288
288 289 /*!
289 290 \property QPieSlice::labelPosition
290 291 Position of the slice label.
291 292 \sa label, labelVisible
292 293 */
293 294 /*!
294 295 \qmlproperty LabelPosition PieSlice::labelPosition
295 296 Position of the slice label. One of PieSlice.LabelOutside or PieSlice.LabelInside.
296 297 \sa labelVisible
297 298 */
298 299
299 300 /*!
300 301 \property QPieSlice::labelArmLengthFactor
301 302 Defines the length of the label arm.
302 303 The factor is relative to pie radius. For example:
303 304 1.0 means the length is the same as the radius.
304 305 0.5 means the length is half of the radius.
305 306 By default the arm length is 0.15
306 307 \sa label, labelVisible, labelBrush, labelFont
307 308 */
308 309 /*!
309 310 \qmlproperty real PieSlice::labelArmLengthFactor
310 311 Defines the length of the label arm.
311 312 The factor is relative to pie radius. For example:
312 313 1.0 means the length is the same as the radius.
313 314 0.5 means the length is half of the radius.
314 315 By default the arm length is 0.15
315 316 \sa labelVisible
316 317 */
317 318
318 319 /*!
319 320 \property QPieSlice::explodeDistanceFactor
320 321 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
321 322 The factor is relative to pie radius. For example:
322 323 1.0 means the distance is the same as the radius.
323 324 0.5 means the distance is half of the radius.
324 325 By default the distance is is 0.15
325 326 \sa exploded
326 327 */
327 328 /*!
328 329 \qmlproperty real PieSlice::explodeDistanceFactor
329 330 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
330 331 The factor is relative to pie radius. For example:
331 332 1.0 means the distance is the same as the radius.
332 333 0.5 means the distance is half of the radius.
333 334 By default the distance is is 0.15
334 335 \sa exploded
335 336 */
336 337
337 338 /*!
338 339 \property QPieSlice::percentage
339 340 Percentage of the slice compared to the sum of all slices in the series.
340 341 The actual value ranges from 0.0 to 1.0.
341 342 Updated automatically once the slice is added to the series.
342 343 \sa value, QPieSeries::sum
343 344 */
344 345 /*!
345 346 \qmlproperty real PieSlice::percentage
346 347 Percentage of the slice compared to the sum of all slices in the series.
347 348 The actual value ranges from 0.0 to 1.0.
348 349 Updated automatically once the slice is added to the series.
349 350 */
350 351
351 352 /*!
352 353 \fn void QPieSlice::percentageChanged()
353 354 This signal is emitted when the percentage of the slice has changed.
354 355 \sa percentage
355 356 */
356 357 /*!
357 358 \qmlsignal void PieSlice::onPercentageChanged()
358 359 This signal is emitted when the percentage of the slice has changed.
359 360 \sa percentage
360 361 */
361 362
362 363 /*!
363 364 \property QPieSlice::startAngle
364 365 Defines the starting angle of this slice in the series it belongs to.
365 366 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
366 367 Updated automatically once the slice is added to the series.
367 368 */
368 369 /*!
369 370 \qmlproperty real PieSlice::startAngle
370 371 Defines the starting angle of this slice in the series it belongs to.
371 372 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
372 373 Updated automatically once the slice is added to the series.
373 374 */
374 375
375 376 /*!
376 377 \fn void QPieSlice::startAngleChanged()
377 378 This signal is emitted when the starting angle f the slice has changed.
378 379 \sa startAngle
379 380 */
380 381 /*!
381 382 \qmlsignal PieSlice::onStartAngleChanged()
382 383 This signal is emitted when the starting angle f the slice has changed.
383 384 \sa startAngle
384 385 */
385 386
386 387 /*!
387 388 \property QPieSlice::angleSpan
388 389 Span of the slice in degrees.
389 390 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
390 391 Updated automatically once the slice is added to the series.
391 392 */
392 393 /*!
393 394 \qmlproperty real PieSlice::angleSpan
394 395 Span of the slice in degrees.
395 396 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
396 397 Updated automatically once the slice is added to the series.
397 398 */
398 399
399 400 /*!
400 401 \fn void QPieSlice::angleSpanChanged()
401 402 This signal is emitted when the angle span of the slice has changed.
402 403 \sa angleSpan
403 404 */
404 405 /*!
405 406 \qmlsignal PieSlice::onAngleSpanChanged()
406 407 This signal is emitted when the angle span of the slice has changed.
407 408 \sa angleSpan
408 409 */
409 410
410 411 /*!
411 412 \fn void QPieSlice::clicked()
412 413 This signal is emitted when user has clicked the slice.
413 414 \sa QPieSeries::clicked()
414 415 */
415 416 /*!
416 417 \qmlsignal PieSlice::onClicked()
417 418 This signal is emitted when user has clicked the slice.
418 419 */
419 420
420 421 /*!
421 422 \fn void QPieSlice::hovered(bool state)
422 423 This signal is emitted when user has hovered over or away from the slice.
423 424 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
424 425 \sa QPieSeries::hovered()
425 426 */
426 427 /*!
427 428 \qmlsignal PieSlice::onHovered(bool state)
428 429 This signal is emitted when user has hovered over or away from the slice.
429 430 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
430 431 */
431 432
432 433 /*!
433 434 Constructs an empty slice with a \a parent.
434 435 \sa QPieSeries::append(), QPieSeries::insert()
435 436 */
436 437 QPieSlice::QPieSlice(QObject *parent)
437 438 :QObject(parent),
438 439 d_ptr(new QPieSlicePrivate(this))
439 440 {
440 441
441 442 }
442 443
443 444 /*!
444 445 Constructs an empty slice with given \a value, \a label and a \a parent.
445 446 \sa QPieSeries::append(), QPieSeries::insert()
446 447 */
447 448 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
448 449 :QObject(parent),
449 450 d_ptr(new QPieSlicePrivate(this))
450 451 {
451 452 setValue(value);
452 453 setLabel(label);
453 454 }
454 455
455 456 /*!
456 457 Destroys the slice.
457 458 User should not delete the slice if it has been added to the series.
458 459 */
459 460 QPieSlice::~QPieSlice()
460 461 {
461 462
462 463 }
463 464
464 465 void QPieSlice::setLabel(QString label)
465 466 {
466 467 if (d_ptr->m_data.m_labelText != label) {
467 468 d_ptr->m_data.m_labelText = label;
468 469 emit labelChanged();
469 470 }
470 471 }
471 472
472 473 QString QPieSlice::label() const
473 474 {
474 475 return d_ptr->m_data.m_labelText;
475 476 }
476 477
477 478 void QPieSlice::setValue(qreal value)
478 479 {
479 480 value = qAbs(value); // negative values not allowed
480 481 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
481 482 d_ptr->m_data.m_value = value;
482 483 emit valueChanged();
483 484 }
484 485 }
485 486
486 487 qreal QPieSlice::value() const
487 488 {
488 489 return d_ptr->m_data.m_value;
489 490 }
490 491
491 492 void QPieSlice::setLabelVisible(bool visible)
492 493 {
493 494 if (d_ptr->m_data.m_isLabelVisible != visible) {
494 495 d_ptr->m_data.m_isLabelVisible = visible;
495 496 emit labelVisibleChanged();
496 497 }
497 498 }
498 499
499 500 bool QPieSlice::isLabelVisible() const
500 501 {
501 502 return d_ptr->m_data.m_isLabelVisible;
502 503 }
503 504
504 505 void QPieSlice::setExploded(bool exploded)
505 506 {
506 507 if (d_ptr->m_data.m_isExploded != exploded) {
507 508 d_ptr->m_data.m_isExploded = exploded;
508 509 emit d_ptr->explodedChanged();
509 510 }
510 511 }
511 512
512 513 QPieSlice::LabelPosition QPieSlice::labelPosition()
513 514 {
514 515 return d_ptr->m_data.m_labelPosition;
515 516 }
516 517
517 518 void QPieSlice::setLabelPosition(LabelPosition position)
518 519 {
519 520 if (d_ptr->m_data.m_labelPosition != position) {
520 521 d_ptr->m_data.m_labelPosition = position;
521 522 emit d_ptr->labelPositionChanged();
522 523 }
523 524 }
524 525
525 526 bool QPieSlice::isExploded() const
526 527 {
527 528 return d_ptr->m_data.m_isExploded;
528 529 }
529 530
530 531 void QPieSlice::setPen(const QPen &pen)
531 532 {
532 533 d_ptr->setPen(pen, false);
533 534 }
534 535
535 536 QPen QPieSlice::pen() const
536 537 {
537 538 return d_ptr->m_data.m_slicePen;
538 539 }
539 540
540 541 QColor QPieSlice::borderColor()
541 542 {
542 543 return pen().color();
543 544 }
544 545
545 546 void QPieSlice::setBorderColor(QColor color)
546 547 {
547 548 QPen p = pen();
548 549 if (color != p.color()) {
549 550 p.setColor(color);
550 551 setPen(p);
551 552 }
552 553 }
553 554
554 555 int QPieSlice::borderWidth()
555 556 {
556 557 return pen().width();
557 558 }
558 559
559 560 void QPieSlice::setBorderWidth(int width)
560 561 {
561 562 QPen p = pen();
562 563 if (width != p.width()) {
563 564 p.setWidth(width);
564 565 setPen(p);
565 566 }
566 567 }
567 568
568 569 void QPieSlice::setBrush(const QBrush &brush)
569 570 {
570 571 d_ptr->setBrush(brush, false);
571 572 }
572 573
573 574 QBrush QPieSlice::brush() const
574 575 {
575 576 return d_ptr->m_data.m_sliceBrush;
576 577 }
577 578
578 579 QColor QPieSlice::color()
579 580 {
580 581 return brush().color();
581 582 }
582 583
583 584 void QPieSlice::setColor(QColor color)
584 585 {
585 586 QBrush b = brush();
586 587 if (color != b.color()) {
587 588 b.setColor(color);
588 589 setBrush(b);
589 590 }
590 591 }
591 592
592 593 void QPieSlice::setLabelBrush(const QBrush &brush)
593 594 {
594 595 d_ptr->setLabelBrush(brush, false);
595 596 }
596 597
597 598 QBrush QPieSlice::labelBrush() const
598 599 {
599 600 return d_ptr->m_data.m_labelBrush;
600 601 }
601 602
602 603 QColor QPieSlice::labelColor()
603 604 {
604 605 return labelBrush().color();
605 606 }
606 607
607 608 void QPieSlice::setLabelColor(QColor color)
608 609 {
609 610 QBrush b = labelBrush();
610 611 if (color != b.color()) {
611 612 b.setColor(color);
612 613 setLabelBrush(b);
613 614 }
614 615 }
615 616
616 617 void QPieSlice::setLabelFont(const QFont &font)
617 618 {
618 619 d_ptr->setLabelFont(font, false);
619 620 }
620 621
621 622 QFont QPieSlice::labelFont() const
622 623 {
623 624 return d_ptr->m_data.m_labelFont;
624 625 }
625 626
626 627 void QPieSlice::setLabelArmLengthFactor(qreal factor)
627 628 {
628 629 if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) {
629 630 d_ptr->m_data.m_labelArmLengthFactor = factor;
630 631 emit d_ptr->labelArmLengthFactorChanged();
631 632 }
632 633 }
633 634
634 635 qreal QPieSlice::labelArmLengthFactor() const
635 636 {
636 637 return d_ptr->m_data.m_labelArmLengthFactor;
637 638 }
638 639
639 640 void QPieSlice::setExplodeDistanceFactor(qreal factor)
640 641 {
641 642 if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) {
642 643 d_ptr->m_data.m_explodeDistanceFactor = factor;
643 644 emit d_ptr->explodeDistanceFactorChanged();
644 645 }
645 646 }
646 647
647 648 qreal QPieSlice::explodeDistanceFactor() const
648 649 {
649 650 return d_ptr->m_data.m_explodeDistanceFactor;
650 651 }
651 652
652 653 qreal QPieSlice::percentage() const
653 654 {
654 655 return d_ptr->m_data.m_percentage;
655 656 }
656 657
657 658 qreal QPieSlice::startAngle() const
658 659 {
659 660 return d_ptr->m_data.m_startAngle;
660 661 }
661 662
662 663 qreal QPieSlice::angleSpan() const
663 664 {
664 665 return d_ptr->m_data.m_angleSpan;
665 666 }
666 667
667 668 /*!
668 669 Returns the series that this slice belongs to.
669 670
670 671 \sa QPieSeries::append()
671 672 */
672 673 QPieSeries *QPieSlice::series() const
673 674 {
674 675 return d_ptr->m_series;
675 676 }
676 677
677 678 QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent)
678 679 :QObject(parent),
679 680 q_ptr(parent),
680 681 m_series(0)
681 682 {
682 683
683 684 }
684 685
685 686 QPieSlicePrivate::~QPieSlicePrivate()
686 687 {
687 688
688 689 }
689 690
690 691 QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice)
691 692 {
692 693 return slice->d_func();
693 694 }
694 695
695 696 void QPieSlicePrivate::setPen(const QPen &pen, bool themed)
696 697 {
697 698 if (m_data.m_slicePen != pen) {
698 699
699 700 QPen oldPen = m_data.m_slicePen;
700 701
701 702 m_data.m_slicePen = pen;
702 703 m_data.m_slicePen.setThemed(themed);
703 704
704 705 emit q_ptr->penChanged();
705 706 if (oldPen.color() != pen.color())
706 707 emit q_ptr->borderColorChanged();
707 708 if (oldPen.width() != pen.width())
708 709 emit q_ptr->borderWidthChanged();
709 710 }
710 711 }
711 712
712 713 void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed)
713 714 {
714 715 if (m_data.m_sliceBrush != brush) {
715 716
716 717 QBrush oldBrush = m_data.m_sliceBrush;
717 718
718 719 m_data.m_sliceBrush = brush;
719 720 m_data.m_sliceBrush.setThemed(themed);
720 721
721 722 emit q_ptr->brushChanged();
722 723 if (oldBrush.color() != brush.color())
723 724 emit q_ptr->colorChanged();
724 725 }
725 726 }
726 727
727 728 void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed)
728 729 {
729 730 if (m_data.m_labelBrush != brush) {
730 731
731 732 QBrush oldBrush = m_data.m_labelBrush;
732 733
733 734 m_data.m_labelBrush = brush;
734 735 m_data.m_labelBrush.setThemed(themed);
735 736
736 737 emit q_ptr->labelBrushChanged();
737 738 if (oldBrush.color() != brush.color())
738 739 emit q_ptr->labelColorChanged();
739 740 }
740 741 }
741 742
742 743 void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed)
743 744 {
744 745 if (m_data.m_labelFont != font) {
745 746 m_data.m_labelFont = font;
746 747 m_data.m_labelFont.setThemed(themed);
747 748 emit q_ptr->labelFontChanged();
748 749 }
749 750 }
750 751
751 752 void QPieSlicePrivate::setPercentage(qreal percentage)
752 753 {
753 754 if (!qFuzzyIsNull(m_data.m_percentage - percentage)) {
754 755 m_data.m_percentage = percentage;
755 756 emit q_ptr->percentageChanged();
756 757 }
757 758 }
758 759
759 760 void QPieSlicePrivate::setStartAngle(qreal angle)
760 761 {
761 762 if (!qFuzzyIsNull(m_data.m_startAngle - angle)) {
762 763 m_data.m_startAngle = angle;
763 764 emit q_ptr->startAngleChanged();
764 765 }
765 766 }
766 767
767 768 void QPieSlicePrivate::setAngleSpan(qreal span)
768 769 {
769 770 if (!qFuzzyIsNull(m_data.m_angleSpan - span)) {
770 771 m_data.m_angleSpan = span;
771 772 emit q_ptr->angleSpanChanged();
772 773 }
773 774 }
774 775
775 776 QTCOMMERCIALCHART_END_NAMESPACE
776 777
777 778 QTCOMMERCIALCHART_USE_NAMESPACE
778 779 #include "moc_qpieslice.cpp"
779 780 #include "moc_qpieslice_p.cpp"
General Comments 0
You need to be logged in to leave comments. Login now