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