##// END OF EJS Templates
Few docs updated
Marek Rosa -
r1743:d1cb593b6c09
parent child
Show More
@@ -1,655 +1,658
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 "qabstractaxis.h"
21 #include "qabstractaxis.h"
22 #include "qabstractaxis_p.h"
22 #include "qabstractaxis_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QAbstractAxis
27 \class QAbstractAxis
28 \brief The QAbstractAxis class is used for manipulating chart's axis.
28 \brief The QAbstractAxis class is used for manipulating chart's axis.
29 \mainclass
29 \mainclass
30
30
31 There is only one x Axis visible at the time, however there can be multiple y axes.
31 There is only one x Axis visible at the time, however there can be multiple y axes.
32 Each chart series can be bound to exactly one Y axis and the shared common X axis.
32 Each chart series can be bound to exactly one Y axis and the shared common X axis.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 */
34 */
35
35
36 /*!
36 /*!
37 \qmlclass AbstractAxis QAbstractAxis
37 \qmlclass AbstractAxis QAbstractAxis
38 \brief The Axis element is used for manipulating chart's axes
38 \brief The Axis element is used for manipulating chart's axes
39
39
40 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
40 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
41 Each chart series can be bound to exactly one Y axis and the shared common X axis.
41 Each chart series can be bound to exactly one Y axis and the shared common X axis.
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 ChartView {
46 ChartView {
47 axisX.min: 0
47 axisX.min: 0
48 axisX.max: 3
48 axisX.max: 3
49 axisX.ticksCount: 4
49 axisX.ticksCount: 4
50 axisY.min: 0
50 axisY.min: 0
51 axisY.max: 4
51 axisY.max: 4
52 // Add a few series...
52 // Add a few series...
53 }
53 }
54 \endcode
54 \endcode
55 */
55 */
56
56
57 /*!
57 /*!
58 \enum QAbstractAxis::AxisType
58 \enum QAbstractAxis::AxisType
59
59
60 The type of the series object.
60 The type of the series object.
61
61
62 \value AxisTypeNoAxis
62 \value AxisTypeNoAxis
63 \value AxisTypeValues
63 \value AxisTypeValues
64 \value AxisTypeCategories
64 \value AxisTypeCategories
65 \value AxisTypeIntervals
65 \value AxisTypeIntervals
66 \value AxisTypeDateTime
66 \value AxisTypeDateTime
67 */
67 */
68
68
69 /*!
69 /*!
70 *\fn void QAbstractAxis::type() const
70 *\fn void QAbstractAxis::type() const
71 Returns the type of the axis
71 Returns the type of the axis
72 */
72 */
73
73
74 /*!
74 /*!
75 \property QAbstractAxis::arrowVisible
75 \property QAbstractAxis::arrowVisible
76 The visibility of the axis arrow
76 The visibility of the axis arrow
77 */
77 */
78 /*!
78 /*!
79 \qmlproperty bool AbstractAxis::arrrowVisible
79 \qmlproperty bool AbstractAxis::arrrowVisible
80 The visibility of the axis arrow
80 The visibility of the axis arrow
81 */
81 */
82
82
83 /*!
83 /*!
84 \property QAbstractAxis::labelsVisible
84 \property QAbstractAxis::labelsVisible
85 Defines if axis labels are visible.
85 Defines if axis labels are visible.
86 */
86 */
87 /*!
87 /*!
88 \qmlproperty bool AbstractAxis::labelsVisible
88 \qmlproperty bool AbstractAxis::labelsVisible
89 Defines if axis labels are visible.
89 Defines if axis labels are visible.
90 */
90 */
91
91
92 /*!
92 /*!
93 \property QAbstractAxis::visible
93 \property QAbstractAxis::visible
94 The visibility of the axis.
94 The visibility of the axis.
95 */
95 */
96 /*!
96 /*!
97 \qmlproperty bool AbstractAxis::visible
97 \qmlproperty bool AbstractAxis::visible
98 The visibility of the axis.
98 The visibility of the axis.
99 */
99 */
100
100
101 /*!
101 /*!
102 \property QAbstractAxis::gridVisible
102 \property QAbstractAxis::gridVisible
103 The visibility of the grid lines.
103 The visibility of the grid lines.
104 */
104 */
105 /*!
105 /*!
106 \qmlproperty bool AbstractAxis::gridVisible
106 \qmlproperty bool AbstractAxis::gridVisible
107 The visibility of the grid lines.
107 The visibility of the grid lines.
108 */
108 */
109
109
110 /*!
110 /*!
111 \property QAbstractAxis::color
111 \property QAbstractAxis::color
112 The color of the axis and ticks.
112 The color of the axis and ticks.
113 */
113 */
114 /*!
114 /*!
115 \qmlproperty color AbstractAxis::color
115 \qmlproperty color AbstractAxis::color
116 The color of the axis and ticks.
116 The color of the axis and ticks.
117 */
117 */
118
118
119 /*!
119 /*!
120 \property QAbstractAxis::labelsFont
120 \property QAbstractAxis::labelsFont
121 The font of the axis labels.
121 The font of the axis labels.
122 */
122 */
123
123
124 /*!
124 /*!
125 \qmlproperty Font AbstractAxis::labelsFont
125 \qmlproperty Font AbstractAxis::labelsFont
126 The font of the axis labels.
126 The font of the axis labels.
127
127
128 See the \l {Font} {QML Font Element} for detailed documentation.
128 See the \l {Font} {QML Font Element} for detailed documentation.
129 */
129 */
130
130
131 /*!
131 /*!
132 \property QAbstractAxis::labelsColor
132 \property QAbstractAxis::labelsColor
133 The color of the axis labels.
133 The color of the axis labels.
134 */
134 */
135 /*!
135 /*!
136 \qmlproperty color AbstractAxis::labelsColor
136 \qmlproperty color AbstractAxis::labelsColor
137 The color of the axis labels.
137 The color of the axis labels.
138 */
138 */
139
139
140 /*!
140 /*!
141 \property QAbstractAxis::labelsAngle
141 \property QAbstractAxis::labelsAngle
142 The angle of the axis labels in degrees.
142 The angle of the axis labels in degrees.
143 */
143 */
144 /*!
144 /*!
145 \qmlproperty int AbstractAxis::labelsAngle
145 \qmlproperty int AbstractAxis::labelsAngle
146 The angle of the axis labels in degrees.
146 The angle of the axis labels in degrees.
147 */
147 */
148
148
149 /*!
149 /*!
150 \property QAbstractAxis::shadesVisible
150 \property QAbstractAxis::shadesVisible
151 The visibility of the axis shades.
151 The visibility of the axis shades.
152 */
152 */
153 /*!
153 /*!
154 \qmlproperty bool AbstractAxis::shadesVisible
154 \qmlproperty bool AbstractAxis::shadesVisible
155 The visibility of the axis shades.
155 The visibility of the axis shades.
156 */
156 */
157
157
158 /*!
158 /*!
159 \property QAbstractAxis::shadesColor
159 \property QAbstractAxis::shadesColor
160 The fill (brush) color of the axis shades.
160 The fill (brush) color of the axis shades.
161 */
161 */
162 /*!
162 /*!
163 \qmlproperty color AbstractAxis::shadesColor
163 \qmlproperty color AbstractAxis::shadesColor
164 The fill (brush) color of the axis shades.
164 The fill (brush) color of the axis shades.
165 */
165 */
166
166
167 /*!
167 /*!
168 \property QAbstractAxis::shadesBorderColor
168 \property QAbstractAxis::shadesBorderColor
169 The border (pen) color of the axis shades.
169 The border (pen) color of the axis shades.
170 */
170 */
171 /*!
171 /*!
172 \qmlproperty color AbstractAxis::shadesBorderColor
172 \qmlproperty color AbstractAxis::shadesBorderColor
173 The border (pen) color of the axis shades.
173 The border (pen) color of the axis shades.
174 */
174 */
175
175
176 /*!
176 /*!
177 \fn void QAbstractAxis::visibleChanged(bool visible)
177 \fn void QAbstractAxis::visibleChanged(bool visible)
178 Visiblity of the axis has changed to \a visible.
178 Visiblity of the axis has changed to \a visible.
179 */
179 */
180 /*!
180 /*!
181 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
181 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
182 Visiblity of the axis has changed to \a visible.
182 Visiblity of the axis has changed to \a visible.
183 */
183 */
184
184
185 /*!
185 /*!
186 \fn void QAbstractAxis::arrowVisibleChanged(bool visible)
186 \fn void QAbstractAxis::arrowVisibleChanged(bool visible)
187 Visiblity of the axis arrow has changed to \a visible.
187 Visiblity of the axis arrow has changed to \a visible.
188 */
188 */
189 /*!
189 /*!
190 \qmlsignal AbstractAxis::onArrowVisibleChanged(bool visible)
190 \qmlsignal AbstractAxis::onArrowVisibleChanged(bool visible)
191 Visiblity of the axis arrow has changed to \a visible.
191 Visiblity of the axis arrow has changed to \a visible.
192 */
192 */
193
193
194 /*!
194 /*!
195 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
195 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
196 Visiblity of the labels of the axis has changed to \a visible.
196 Visiblity of the labels of the axis has changed to \a visible.
197 */
197 */
198 /*!
198 /*!
199 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
199 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
200 Visiblity of the labels of the axis has changed to \a visible.
200 Visiblity of the labels of the axis has changed to \a visible.
201 */
201 */
202
202
203 /*!
203 /*!
204 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
204 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
205 Visiblity of the grid lines of the axis has changed to \a visible.
205 Visiblity of the grid lines of the axis has changed to \a visible.
206 */
206 */
207 /*!
207 /*!
208 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
208 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
209 Visiblity of the grid lines of the axis has changed to \a visible.
209 Visiblity of the grid lines of the axis has changed to \a visible.
210 */
210 */
211
211
212 /*!
212 /*!
213 \fn void QAbstractAxis::colorChanged(QColor color)
213 \fn void QAbstractAxis::colorChanged(QColor color)
214 Emitted if the \a color of the axis is changed.
214 Emitted if the \a color of the axis is changed.
215 */
215 */
216 /*!
216 /*!
217 \qmlsignal AbstractAxis::onColorChanged(QColor color)
217 \qmlsignal AbstractAxis::onColorChanged(QColor color)
218 Emitted if the \a color of the axis is changed.
218 Emitted if the \a color of the axis is changed.
219 */
219 */
220
220
221 /*!
221 /*!
222 \fn void QAbstractAxis::labelsColorChanged(QColor color)
222 \fn void QAbstractAxis::labelsColorChanged(QColor color)
223 Emitted if the \a color of the axis labels is changed.
223 Emitted if the \a color of the axis labels is changed.
224 */
224 */
225 /*!
225 /*!
226 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
226 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
227 Emitted if the \a color of the axis labels is changed.
227 Emitted if the \a color of the axis labels is changed.
228 */
228 */
229
229
230 /*!
230 /*!
231 \fn void QAbstractAxis::shadesVisibleChanged(bool)
231 \fn void QAbstractAxis::shadesVisibleChanged(bool)
232 Emitted if the visibility of the axis shades is changed to \a visible.
232 Emitted if the visibility of the axis shades is changed to \a visible.
233 */
233 */
234 /*!
234 /*!
235 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
235 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
236 Emitted if the visibility of the axis shades is changed to \a visible.
236 Emitted if the visibility of the axis shades is changed to \a visible.
237 */
237 */
238
238
239 /*!
239 /*!
240 \fn void QAbstractAxis::shadesColorChanged(QColor color)
240 \fn void QAbstractAxis::shadesColorChanged(QColor color)
241 Emitted if the \a color of the axis shades is changed.
241 Emitted if the \a color of the axis shades is changed.
242 */
242 */
243 /*!
243 /*!
244 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
244 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
245 Emitted if the \a color of the axis shades is changed.
245 Emitted if the \a color of the axis shades is changed.
246 */
246 */
247
247
248 /*!
248 /*!
249 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
249 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
250 Emitted if the border \a color of the axis shades is changed.
250 Emitted if the border \a color of the axis shades is changed.
251 */
251 */
252 /*!
252 /*!
253 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
253 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
254 Emitted if the border \a color of the axis shades is changed.
254 Emitted if the border \a color of the axis shades is changed.
255 */
255 */
256
256
257 /*!
257 /*!
258 \internal
258 \internal
259 Constructs new axis object which is a child of \a parent. Ownership is taken by
259 Constructs new axis object which is a child of \a parent. Ownership is taken by
260 QChart when axis added.
260 QChart when axis added.
261 */
261 */
262
262
263 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) :
263 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) :
264 QObject(parent),
264 QObject(parent),
265 d_ptr(&d)
265 d_ptr(&d)
266 {
266 {
267 }
267 }
268
268
269 /*!
269 /*!
270 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
270 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
271 */
271 */
272
272
273 QAbstractAxis::~QAbstractAxis()
273 QAbstractAxis::~QAbstractAxis()
274 {
274 {
275 if(d_ptr->m_dataset) qFatal("Still binded axis detected !");
275 if(d_ptr->m_dataset) qFatal("Still binded axis detected !");
276 }
276 }
277
277
278 /*!
278 /*!
279 Sets \a pen used to draw axis line and ticks.
279 Sets \a pen used to draw axis line and ticks.
280 */
280 */
281 void QAbstractAxis::setAxisPen(const QPen &pen)
281 void QAbstractAxis::setAxisPen(const QPen &pen)
282 {
282 {
283 if (d_ptr->m_axisPen!=pen) {
283 if (d_ptr->m_axisPen!=pen) {
284 d_ptr->m_axisPen = pen;
284 d_ptr->m_axisPen = pen;
285 d_ptr->emitUpdated();
285 d_ptr->emitUpdated();
286 }
286 }
287 }
287 }
288
288
289 /*!
289 /*!
290 Returns pen used to draw axis and ticks.
290 Returns pen used to draw axis and ticks.
291 */
291 */
292 QPen QAbstractAxis::axisPen() const
292 QPen QAbstractAxis::axisPen() const
293 {
293 {
294 return d_ptr->m_axisPen;
294 return d_ptr->m_axisPen;
295 }
295 }
296
296
297 void QAbstractAxis::setAxisPenColor(QColor color)
297 void QAbstractAxis::setAxisPenColor(QColor color)
298 {
298 {
299 QPen p = d_ptr->m_axisPen;
299 QPen p = d_ptr->m_axisPen;
300 if (p.color() != color) {
300 if (p.color() != color) {
301 p.setColor(color);
301 p.setColor(color);
302 setAxisPen(p);
302 setAxisPen(p);
303 emit colorChanged(color);
303 emit colorChanged(color);
304 }
304 }
305 }
305 }
306
306
307 QColor QAbstractAxis::axisPenColor() const
307 QColor QAbstractAxis::axisPenColor() const
308 {
308 {
309 return d_ptr->m_axisPen.color();
309 return d_ptr->m_axisPen.color();
310 }
310 }
311
311
312 /*!
312 /*!
313 Sets if axis and ticks are \a visible.
313 Sets if axis and ticks are \a visible.
314 */
314 */
315 void QAbstractAxis::setArrowVisible(bool visible)
315 void QAbstractAxis::setArrowVisible(bool visible)
316 {
316 {
317 if (d_ptr->m_arrowVisible != visible) {
317 if (d_ptr->m_arrowVisible != visible) {
318 d_ptr->m_arrowVisible = visible;
318 d_ptr->m_arrowVisible = visible;
319 d_ptr->emitUpdated();
319 d_ptr->emitUpdated();
320 emit arrowVisibleChanged(visible);
320 emit arrowVisibleChanged(visible);
321 }
321 }
322 }
322 }
323
323
324 bool QAbstractAxis::isArrowVisible() const
324 bool QAbstractAxis::isArrowVisible() const
325 {
325 {
326 return d_ptr->m_arrowVisible;
326 return d_ptr->m_arrowVisible;
327 }
327 }
328
328
329 void QAbstractAxis::setGridLineVisible(bool visible)
329 void QAbstractAxis::setGridLineVisible(bool visible)
330 {
330 {
331 if (d_ptr->m_gridLineVisible != visible) {
331 if (d_ptr->m_gridLineVisible != visible) {
332 d_ptr->m_gridLineVisible = visible;
332 d_ptr->m_gridLineVisible = visible;
333 d_ptr->emitUpdated();
333 d_ptr->emitUpdated();
334 emit gridVisibleChanged(visible);
334 emit gridVisibleChanged(visible);
335 }
335 }
336 }
336 }
337
337
338 bool QAbstractAxis::isGridLineVisible() const
338 bool QAbstractAxis::isGridLineVisible() const
339 {
339 {
340 return d_ptr->m_gridLineVisible;
340 return d_ptr->m_gridLineVisible;
341 }
341 }
342
342
343 /*!
343 /*!
344 Sets \a pen used to draw grid line.
344 Sets \a pen used to draw grid line.
345 */
345 */
346 void QAbstractAxis::setGridLinePen(const QPen &pen)
346 void QAbstractAxis::setGridLinePen(const QPen &pen)
347 {
347 {
348 if (d_ptr->m_gridLinePen != pen) {
348 if (d_ptr->m_gridLinePen != pen) {
349 d_ptr->m_gridLinePen = pen;
349 d_ptr->m_gridLinePen = pen;
350 d_ptr->emitUpdated();
350 d_ptr->emitUpdated();
351 }
351 }
352 }
352 }
353
353
354 /*!
354 /*!
355 Returns pen used to draw grid.
355 Returns pen used to draw grid.
356 */
356 */
357 QPen QAbstractAxis::gridLinePen() const
357 QPen QAbstractAxis::gridLinePen() const
358 {
358 {
359 return d_ptr->m_gridLinePen;
359 return d_ptr->m_gridLinePen;
360 }
360 }
361
361
362 void QAbstractAxis::setLabelsVisible(bool visible)
362 void QAbstractAxis::setLabelsVisible(bool visible)
363 {
363 {
364 if (d_ptr->m_labelsVisible != visible) {
364 if (d_ptr->m_labelsVisible != visible) {
365 d_ptr->m_labelsVisible = visible;
365 d_ptr->m_labelsVisible = visible;
366 d_ptr->emitUpdated();
366 d_ptr->emitUpdated();
367 emit labelsVisibleChanged(visible);
367 emit labelsVisibleChanged(visible);
368 }
368 }
369 }
369 }
370
370
371 bool QAbstractAxis::labelsVisible() const
371 bool QAbstractAxis::labelsVisible() const
372 {
372 {
373 return d_ptr->m_labelsVisible;
373 return d_ptr->m_labelsVisible;
374 }
374 }
375
375
376 /*!
376 /*!
377 Sets \a pen used to draw labels.
377 Sets \a pen used to draw labels.
378 */
378 */
379 void QAbstractAxis::setLabelsPen(const QPen &pen)
379 void QAbstractAxis::setLabelsPen(const QPen &pen)
380 {
380 {
381 if (d_ptr->m_labelsPen != pen) {
381 if (d_ptr->m_labelsPen != pen) {
382 d_ptr->m_labelsPen = pen;
382 d_ptr->m_labelsPen = pen;
383 d_ptr->emitUpdated();
383 d_ptr->emitUpdated();
384 }
384 }
385 }
385 }
386
386
387 /*!
387 /*!
388 Returns the pen used to labels.
388 Returns the pen used to labels.
389 */
389 */
390 QPen QAbstractAxis::labelsPen() const
390 QPen QAbstractAxis::labelsPen() const
391 {
391 {
392 return d_ptr->m_labelsPen;
392 return d_ptr->m_labelsPen;
393 }
393 }
394
394
395 /*!
395 /*!
396 Sets \a brush used to draw labels.
396 Sets \a brush used to draw labels.
397 */
397 */
398 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
398 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
399 {
399 {
400 if (d_ptr->m_labelsBrush != brush) {
400 if (d_ptr->m_labelsBrush != brush) {
401 d_ptr->m_labelsBrush = brush;
401 d_ptr->m_labelsBrush = brush;
402 d_ptr->emitUpdated();
402 d_ptr->emitUpdated();
403 }
403 }
404 }
404 }
405
405
406 /*!
406 /*!
407 Returns brush used to draw labels.
407 Returns brush used to draw labels.
408 */
408 */
409 QBrush QAbstractAxis::labelsBrush() const
409 QBrush QAbstractAxis::labelsBrush() const
410 {
410 {
411 return d_ptr->m_labelsBrush;
411 return d_ptr->m_labelsBrush;
412 }
412 }
413
413
414 /*!
414 /*!
415 Sets \a font used to draw labels.
415 Sets \a font used to draw labels.
416 */
416 */
417 void QAbstractAxis::setLabelsFont(const QFont &font)
417 void QAbstractAxis::setLabelsFont(const QFont &font)
418 {
418 {
419 if (d_ptr->m_labelsFont != font) {
419 if (d_ptr->m_labelsFont != font) {
420 d_ptr->m_labelsFont = font;
420 d_ptr->m_labelsFont = font;
421 d_ptr->emitUpdated();
421 d_ptr->emitUpdated();
422 }
422 }
423 }
423 }
424
424
425 /*!
425 /*!
426 Returns font used to draw labels.
426 Returns font used to draw labels.
427 */
427 */
428 QFont QAbstractAxis::labelsFont() const
428 QFont QAbstractAxis::labelsFont() const
429 {
429 {
430 return d_ptr->m_labelsFont;
430 return d_ptr->m_labelsFont;
431 }
431 }
432
432
433 void QAbstractAxis::setLabelsAngle(int angle)
433 void QAbstractAxis::setLabelsAngle(int angle)
434 {
434 {
435 if (d_ptr->m_labelsAngle != angle) {
435 if (d_ptr->m_labelsAngle != angle) {
436 d_ptr->m_labelsAngle = angle;
436 d_ptr->m_labelsAngle = angle;
437 d_ptr->emitUpdated();
437 d_ptr->emitUpdated();
438 }
438 }
439 }
439 }
440
440
441 int QAbstractAxis::labelsAngle() const
441 int QAbstractAxis::labelsAngle() const
442 {
442 {
443 return d_ptr->m_labelsAngle;
443 return d_ptr->m_labelsAngle;
444 }
444 }
445
445
446 void QAbstractAxis::setLabelsColor(QColor color)
446 void QAbstractAxis::setLabelsColor(QColor color)
447 {
447 {
448 QBrush b = d_ptr->m_labelsBrush;
448 QBrush b = d_ptr->m_labelsBrush;
449 if (b.color() != color) {
449 if (b.color() != color) {
450 b.setColor(color);
450 b.setColor(color);
451 setLabelsBrush(b);
451 setLabelsBrush(b);
452 emit labelsColorChanged(color);
452 emit labelsColorChanged(color);
453 }
453 }
454 }
454 }
455
455
456 QColor QAbstractAxis::labelsColor() const
456 QColor QAbstractAxis::labelsColor() const
457 {
457 {
458 return d_ptr->m_labelsBrush.color();
458 return d_ptr->m_labelsBrush.color();
459 }
459 }
460
460
461 void QAbstractAxis::setShadesVisible(bool visible)
461 void QAbstractAxis::setShadesVisible(bool visible)
462 {
462 {
463 if (d_ptr->m_shadesVisible != visible) {
463 if (d_ptr->m_shadesVisible != visible) {
464 d_ptr->m_shadesVisible = visible;
464 d_ptr->m_shadesVisible = visible;
465 d_ptr->emitUpdated();
465 d_ptr->emitUpdated();
466 emit shadesVisibleChanged(visible);
466 emit shadesVisibleChanged(visible);
467 }
467 }
468 }
468 }
469
469
470 bool QAbstractAxis::shadesVisible() const
470 bool QAbstractAxis::shadesVisible() const
471 {
471 {
472 return d_ptr->m_shadesVisible;
472 return d_ptr->m_shadesVisible;
473 }
473 }
474
474
475 /*!
475 /*!
476 Sets \a pen used to draw shades.
476 Sets \a pen used to draw shades.
477 */
477 */
478 void QAbstractAxis::setShadesPen(const QPen &pen)
478 void QAbstractAxis::setShadesPen(const QPen &pen)
479 {
479 {
480 if (d_ptr->m_shadesPen != pen) {
480 if (d_ptr->m_shadesPen != pen) {
481 d_ptr->m_shadesPen = pen;
481 d_ptr->m_shadesPen = pen;
482 d_ptr->emitUpdated();
482 d_ptr->emitUpdated();
483 }
483 }
484 }
484 }
485
485
486 /*!
486 /*!
487 Returns pen used to draw shades.
487 Returns pen used to draw shades.
488 */
488 */
489 QPen QAbstractAxis::shadesPen() const
489 QPen QAbstractAxis::shadesPen() const
490 {
490 {
491 return d_ptr->m_shadesPen;
491 return d_ptr->m_shadesPen;
492 }
492 }
493
493
494 /*!
494 /*!
495 Sets \a brush used to draw shades.
495 Sets \a brush used to draw shades.
496 */
496 */
497 void QAbstractAxis::setShadesBrush(const QBrush &brush)
497 void QAbstractAxis::setShadesBrush(const QBrush &brush)
498 {
498 {
499 if (d_ptr->m_shadesBrush != brush) {
499 if (d_ptr->m_shadesBrush != brush) {
500 d_ptr->m_shadesBrush = brush;
500 d_ptr->m_shadesBrush = brush;
501 d_ptr->emitUpdated();
501 d_ptr->emitUpdated();
502 emit shadesColorChanged(brush.color());
502 emit shadesColorChanged(brush.color());
503 }
503 }
504 }
504 }
505
505
506 /*!
506 /*!
507 Returns brush used to draw shades.
507 Returns brush used to draw shades.
508 */
508 */
509 QBrush QAbstractAxis::shadesBrush() const
509 QBrush QAbstractAxis::shadesBrush() const
510 {
510 {
511 return d_ptr->m_shadesBrush;
511 return d_ptr->m_shadesBrush;
512 }
512 }
513
513
514 void QAbstractAxis::setShadesColor(QColor color)
514 void QAbstractAxis::setShadesColor(QColor color)
515 {
515 {
516 QBrush b = d_ptr->m_shadesBrush;
516 QBrush b = d_ptr->m_shadesBrush;
517 b.setColor(color);
517 b.setColor(color);
518 setShadesBrush(b);
518 setShadesBrush(b);
519 }
519 }
520
520
521 QColor QAbstractAxis::shadesColor() const
521 QColor QAbstractAxis::shadesColor() const
522 {
522 {
523 return d_ptr->m_shadesBrush.color();
523 return d_ptr->m_shadesBrush.color();
524 }
524 }
525
525
526 void QAbstractAxis::setShadesBorderColor(QColor color)
526 void QAbstractAxis::setShadesBorderColor(QColor color)
527 {
527 {
528 QPen p = d_ptr->m_shadesPen;
528 QPen p = d_ptr->m_shadesPen;
529 p.setColor(color);
529 p.setColor(color);
530 setShadesPen(p);
530 setShadesPen(p);
531 }
531 }
532
532
533 QColor QAbstractAxis::shadesBorderColor() const
533 QColor QAbstractAxis::shadesBorderColor() const
534 {
534 {
535 return d_ptr->m_shadesPen.color();
535 return d_ptr->m_shadesPen.color();
536 }
536 }
537
537
538
538
539 bool QAbstractAxis::isVisible() const
539 bool QAbstractAxis::isVisible() const
540 {
540 {
541 return d_ptr->m_visible;
541 return d_ptr->m_visible;
542 }
542 }
543
543
544 /*!
544 /*!
545 Sets axis, shades, labels and grid lines to be visible.
545 Sets axis, shades, labels and grid lines to be visible.
546 */
546 */
547 void QAbstractAxis::setVisible(bool visible)
547 void QAbstractAxis::setVisible(bool visible)
548 {
548 {
549 if(d_ptr->m_visible!=visible){
549 if(d_ptr->m_visible!=visible){
550 d_ptr->m_visible=visible;
550 d_ptr->m_visible=visible;
551 d_ptr->emitUpdated();
551 d_ptr->emitUpdated();
552 emit visibleChanged(visible);
552 emit visibleChanged(visible);
553 }
553 }
554 }
554 }
555
555
556
556
557 /*!
557 /*!
558 Sets axis, shades, labels and grid lines to be visible.
558 Sets axis, shades, labels and grid lines to be visible.
559 */
559 */
560 void QAbstractAxis::show()
560 void QAbstractAxis::show()
561 {
561 {
562 setVisible(true);
562 setVisible(true);
563 }
563 }
564
564
565 /*!
565 /*!
566 Sets axis, shades, labels and grid lines to not be visible.
566 Sets axis, shades, labels and grid lines to not be visible.
567 */
567 */
568 void QAbstractAxis::hide()
568 void QAbstractAxis::hide()
569 {
569 {
570 setVisible(false);
570 setVisible(false);
571 }
571 }
572
572
573 /*!
573 /*!
574 Sets the minimum value shown on the axis.
574 Sets the minimum value shown on the axis.
575 Depending on the actual axis type the \a min paramter is converted to appropriate type.
575 Depending on the actual axis type the \a min paramter is converted to appropriate type.
576 If the conversion is impossible then the function call does nothing
576 If the conversion is impossible then the function call does nothing
577 */
577 */
578 void QAbstractAxis::setMin(const QVariant &min)
578 void QAbstractAxis::setMin(const QVariant &min)
579 {
579 {
580 d_ptr->setMin(min);
580 d_ptr->setMin(min);
581 }
581 }
582
582
583 /*!
583 /*!
584 Sets the maximum value shown on the axis.
584 Sets the maximum value shown on the axis.
585 Depending on the actual axis type the \a max paramter is converted to appropriate type.
585 Depending on the actual axis type the \a max paramter is converted to appropriate type.
586 If the conversion is impossible then the function call does nothing
586 If the conversion is impossible then the function call does nothing
587 */
587 */
588 void QAbstractAxis::setMax(const QVariant &max)
588 void QAbstractAxis::setMax(const QVariant &max)
589 {
589 {
590 d_ptr->setMax(max);
590 d_ptr->setMax(max);
591 }
591 }
592
592
593 /*!
593 /*!
594 Sets the range shown on the axis.
594 Sets the range shown on the axis.
595 Depending on the actual axis type the \a min and \a max paramters are converted to appropriate types.
595 Depending on the actual axis type the \a min and \a max paramters are converted to appropriate types.
596 If the conversion is impossible then the function call does nothing.
596 If the conversion is impossible then the function call does nothing.
597 */
597 */
598 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
598 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
599 {
599 {
600 d_ptr->setRange(min,max);
600 d_ptr->setRange(min,max);
601 }
601 }
602
602
603
603
604 /*!
605 Returns the orientation in which the axis is being used (Vertical or Horizontal)
606 */
604 Qt::Orientation QAbstractAxis::orientation()
607 Qt::Orientation QAbstractAxis::orientation()
605 {
608 {
606 return d_ptr->m_orientation;
609 return d_ptr->m_orientation;
607 }
610 }
608
611
609 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
612 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
610
613
611 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
614 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
612 q_ptr(q),
615 q_ptr(q),
613 m_orientation(Qt::Orientation(0)),
616 m_orientation(Qt::Orientation(0)),
614 m_dataset(0),
617 m_dataset(0),
615 m_visible(false),
618 m_visible(false),
616 m_arrowVisible(true),
619 m_arrowVisible(true),
617 m_gridLineVisible(true),
620 m_gridLineVisible(true),
618 m_labelsVisible(true),
621 m_labelsVisible(true),
619 m_labelsAngle(0),
622 m_labelsAngle(0),
620 m_shadesVisible(false),
623 m_shadesVisible(false),
621 m_shadesBrush(Qt::SolidPattern),
624 m_shadesBrush(Qt::SolidPattern),
622 m_shadesOpacity(1.0),
625 m_shadesOpacity(1.0),
623 m_dirty(false)
626 m_dirty(false)
624 {
627 {
625
628
626 }
629 }
627
630
628 QAbstractAxisPrivate::~QAbstractAxisPrivate()
631 QAbstractAxisPrivate::~QAbstractAxisPrivate()
629 {
632 {
630
633
631 }
634 }
632
635
633 void QAbstractAxisPrivate::emitUpdated()
636 void QAbstractAxisPrivate::emitUpdated()
634 {
637 {
635 if(!m_dirty){
638 if(!m_dirty){
636 m_dirty=true;
639 m_dirty=true;
637 emit updated();
640 emit updated();
638 }
641 }
639 }
642 }
640
643
641 void QAbstractAxisPrivate::setDirty(bool dirty)
644 void QAbstractAxisPrivate::setDirty(bool dirty)
642 {
645 {
643 m_dirty=dirty;
646 m_dirty=dirty;
644 }
647 }
645
648
646 void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation)
649 void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation)
647 {
650 {
648 m_orientation=orientation;
651 m_orientation=orientation;
649 }
652 }
650
653
651
654
652 #include "moc_qabstractaxis.cpp"
655 #include "moc_qabstractaxis.cpp"
653 #include "moc_qabstractaxis_p.cpp"
656 #include "moc_qabstractaxis_p.cpp"
654
657
655 QTCOMMERCIALCHART_END_NAMESPACE
658 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,110 +1,110
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QABSTRACTAXIS_P_H
30 #ifndef QABSTRACTAXIS_P_H
31 #define QABSTRACTAXIS_P_H
31 #define QABSTRACTAXIS_P_H
32
32
33 #include "qabstractaxis.h"
33 #include "qabstractaxis.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class ChartPresenter;
37 class ChartPresenter;
38 class ChartAxis;
38 class ChartAxis;
39 class Domain;
39 class Domain;
40 class ChartDataSet;
40 class ChartDataSet;
41
41
42 class QTCOMMERCIALCHART_AUTOTEST_EXPORT QAbstractAxisPrivate : public QObject
42 class QTCOMMERCIALCHART_AUTOTEST_EXPORT QAbstractAxisPrivate : public QObject
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45 public:
45 public:
46 QAbstractAxisPrivate(QAbstractAxis *q);
46 QAbstractAxisPrivate(QAbstractAxis *q);
47 ~QAbstractAxisPrivate();
47 ~QAbstractAxisPrivate();
48
48
49 public:
49 public:
50
50
51 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
51 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
52 virtual void intializeDomain(Domain* domain) = 0;
52 virtual void intializeDomain(Domain* domain) = 0;
53
53
54 void emitUpdated();
54 void emitUpdated();
55 void setDirty(bool dirty);
55 void setDirty(bool dirty);
56 bool isDirty(){ return m_dirty; };
56 bool isDirty(){ return m_dirty; }
57 void setOrientation(Qt::Orientation orientation);
57 void setOrientation(Qt::Orientation orientation);
58 Qt::Orientation orientation() const { return m_orientation; }
58 Qt::Orientation orientation() const { return m_orientation; }
59
59
60 virtual void setMin(const QVariant &min) = 0;
60 virtual void setMin(const QVariant &min) = 0;
61 virtual qreal min() = 0;
61 virtual qreal min() = 0;
62
62
63 virtual void setMax(const QVariant &max) = 0;
63 virtual void setMax(const QVariant &max) = 0;
64 virtual qreal max() = 0;
64 virtual qreal max() = 0;
65
65
66 virtual int count() const = 0;
66 virtual int count() const = 0;
67
67
68 virtual void setRange(const QVariant &min, const QVariant &max) = 0;
68 virtual void setRange(const QVariant &min, const QVariant &max) = 0;
69
69
70 public Q_SLOTS:
70 public Q_SLOTS:
71 virtual void handleDomainUpdated() = 0;
71 virtual void handleDomainUpdated() = 0;
72
72
73 Q_SIGNALS:
73 Q_SIGNALS:
74 void updated();
74 void updated();
75
75
76 protected:
76 protected:
77 QAbstractAxis *q_ptr;
77 QAbstractAxis *q_ptr;
78 Qt::Orientation m_orientation;
78 Qt::Orientation m_orientation;
79 ChartDataSet *m_dataset;
79 ChartDataSet *m_dataset;
80
80
81 private:
81 private:
82 bool m_visible;
82 bool m_visible;
83
83
84 bool m_arrowVisible;
84 bool m_arrowVisible;
85 QPen m_axisPen;
85 QPen m_axisPen;
86 QBrush m_axisBrush;
86 QBrush m_axisBrush;
87
87
88 bool m_gridLineVisible;
88 bool m_gridLineVisible;
89 QPen m_gridLinePen;
89 QPen m_gridLinePen;
90
90
91 bool m_labelsVisible;
91 bool m_labelsVisible;
92 QPen m_labelsPen;
92 QPen m_labelsPen;
93 QBrush m_labelsBrush;
93 QBrush m_labelsBrush;
94 QFont m_labelsFont;
94 QFont m_labelsFont;
95 int m_labelsAngle;
95 int m_labelsAngle;
96
96
97 bool m_shadesVisible;
97 bool m_shadesVisible;
98 QPen m_shadesPen;
98 QPen m_shadesPen;
99 QBrush m_shadesBrush;
99 QBrush m_shadesBrush;
100 qreal m_shadesOpacity;
100 qreal m_shadesOpacity;
101
101
102 bool m_dirty;
102 bool m_dirty;
103
103
104 friend class QAbstractAxis;
104 friend class QAbstractAxis;
105 friend class ChartDataSet;
105 friend class ChartDataSet;
106 };
106 };
107
107
108 QTCOMMERCIALCHART_END_NAMESPACE
108 QTCOMMERCIALCHART_END_NAMESPACE
109
109
110 #endif
110 #endif
@@ -1,864 +1,872
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qpieseries.h"
21 #include "qpieseries.h"
22 #include "qpieseries_p.h"
22 #include "qpieseries_p.h"
23 #include "qpieslice.h"
23 #include "qpieslice.h"
24 #include "qpieslice_p.h"
24 #include "qpieslice_p.h"
25 #include "pieslicedata_p.h"
25 #include "pieslicedata_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "legendmarker_p.h"
28 #include "legendmarker_p.h"
29 #include "qabstractaxis.h"
29 #include "qabstractaxis.h"
30 #include "pieanimation_p.h"
30 #include "pieanimation_p.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 /*!
34 /*!
35 \class QPieSeries
35 \class QPieSeries
36 \brief Pie series API for QtCommercial Charts
36 \brief Pie series API for QtCommercial Charts
37
37
38 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
38 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
39 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
39 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
40 The actual slice size is determined by that relative value.
40 The actual slice size is determined by that relative value.
41
41
42 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
42 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
43 These relate to the actual chart rectangle.
43 These relate to the actual chart rectangle.
44
44
45 By default the pie is defined as a full pie but it can also be a partial pie.
45 By default the pie is defined as a full pie but it can also be a partial pie.
46 This can be done by setting a starting angle and angle span to the series.
46 This can be done by setting a starting angle and angle span to the series.
47 Full pie is 360 degrees where 0 is at 12 a'clock.
47 Full pie is 360 degrees where 0 is at 12 a'clock.
48
48
49 See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
49 See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
50 \image examples_piechart.png
50 \image examples_piechart.png
51 */
51 */
52 /*!
52 /*!
53 \qmlclass PieSeries QPieSeries
53 \qmlclass PieSeries QPieSeries
54 \inherits AbstractSeries
54 \inherits AbstractSeries
55
55
56 The following QML shows how to create a simple pie chart.
56 The following QML shows how to create a simple pie chart.
57
57
58 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
58 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
59
59
60 \beginfloatleft
60 \beginfloatleft
61 \image demos_qmlchart1.png
61 \image demos_qmlchart1.png
62 \endfloat
62 \endfloat
63 \clearfloat
63 \clearfloat
64 */
64 */
65
65
66 /*!
66 /*!
67 \property QPieSeries::horizontalPosition
67 \property QPieSeries::horizontalPosition
68 \brief Defines the horizontal position of the pie.
68 \brief Defines the horizontal position of the pie.
69
69
70 The value is a relative value to the chart rectangle where:
70 The value is a relative value to the chart rectangle where:
71
71
72 \list
72 \list
73 \o 0.0 is the absolute left.
73 \o 0.0 is the absolute left.
74 \o 1.0 is the absolute right.
74 \o 1.0 is the absolute right.
75 \endlist
75 \endlist
76 Default value is 0.5 (center).
76 Default value is 0.5 (center).
77 \sa verticalPosition
77 \sa verticalPosition
78 */
78 */
79
79
80 /*!
80 /*!
81 \qmlproperty real PieSeries::horizontalPosition
81 \qmlproperty real PieSeries::horizontalPosition
82
82
83 Defines the horizontal position of the pie.
83 Defines the horizontal position of the pie.
84
84
85 The value is a relative value to the chart rectangle where:
85 The value is a relative value to the chart rectangle where:
86
86
87 \list
87 \list
88 \o 0.0 is the absolute left.
88 \o 0.0 is the absolute left.
89 \o 1.0 is the absolute right.
89 \o 1.0 is the absolute right.
90 \endlist
90 \endlist
91 Default value is 0.5 (center).
91 Default value is 0.5 (center).
92 \sa verticalPosition
92 \sa verticalPosition
93 */
93 */
94
94
95 /*!
95 /*!
96 \property QPieSeries::verticalPosition
96 \property QPieSeries::verticalPosition
97 \brief Defines the vertical position of the pie.
97 \brief Defines the vertical position of the pie.
98
98
99 The value is a relative value to the chart rectangle where:
99 The value is a relative value to the chart rectangle where:
100
100
101 \list
101 \list
102 \o 0.0 is the absolute top.
102 \o 0.0 is the absolute top.
103 \o 1.0 is the absolute bottom.
103 \o 1.0 is the absolute bottom.
104 \endlist
104 \endlist
105 Default value is 0.5 (center).
105 Default value is 0.5 (center).
106 \sa horizontalPosition
106 \sa horizontalPosition
107 */
107 */
108
108
109 /*!
109 /*!
110 \qmlproperty real PieSeries::verticalPosition
110 \qmlproperty real PieSeries::verticalPosition
111
111
112 Defines the vertical position of the pie.
112 Defines the vertical position of the pie.
113
113
114 The value is a relative value to the chart rectangle where:
114 The value is a relative value to the chart rectangle where:
115
115
116 \list
116 \list
117 \o 0.0 is the absolute top.
117 \o 0.0 is the absolute top.
118 \o 1.0 is the absolute bottom.
118 \o 1.0 is the absolute bottom.
119 \endlist
119 \endlist
120 Default value is 0.5 (center).
120 Default value is 0.5 (center).
121 \sa horizontalPosition
121 \sa horizontalPosition
122 */
122 */
123
123
124 /*!
124 /*!
125 \property QPieSeries::size
125 \property QPieSeries::size
126 \brief Defines the pie size.
126 \brief Defines the pie size.
127
127
128 The value is a relative value to the chart rectangle where:
128 The value is a relative value to the chart rectangle where:
129
129
130 \list
130 \list
131 \o 0.0 is the minimum size (pie not drawn).
131 \o 0.0 is the minimum size (pie not drawn).
132 \o 1.0 is the maximum size that can fit the chart.
132 \o 1.0 is the maximum size that can fit the chart.
133 \endlist
133 \endlist
134
134
135 When setting this property the donutInnerSize property is adjusted if necessary, to ensure that the inner size is not greater than the outer size.
135 When setting this property the donutInnerSize property is adjusted if necessary, to ensure that the inner size is not greater than the outer size.
136
136
137 Default value is 0.7.
137 Default value is 0.7.
138 */
138 */
139
139
140 /*!
140 /*!
141 \qmlproperty real PieSeries::size
141 \qmlproperty real PieSeries::size
142
142
143 Defines the pie size.
143 Defines the pie size.
144
144
145 The value is a relative value to the chart rectangle where:
145 The value is a relative value to the chart rectangle where:
146
146
147 \list
147 \list
148 \o 0.0 is the minimum size (pie not drawn).
148 \o 0.0 is the minimum size (pie not drawn).
149 \o 1.0 is the maximum size that can fit the chart.
149 \o 1.0 is the maximum size that can fit the chart.
150 \endlist
150 \endlist
151
151
152 Default value is 0.7.
152 Default value is 0.7.
153 */
153 */
154
154
155 /*!
155 /*!
156 \property QPieSeries::donutInnerSize
156 \property QPieSeries::donutInnerSize
157 \brief Defines the donut inner size.
157 \brief Defines the donut inner size.
158
158
159 The value is a relative value to the chart rectangle where:
159 The value is a relative value to the chart rectangle where:
160
160
161 \list
161 \list
162 \o 0.0 is the minimum size (pie not drawn).
162 \o 0.0 is the minimum size (pie not drawn).
163 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
163 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
164 \endlist
164 \endlist
165
165
166 The value is never greater then size property.
166 The value is never greater then size property.
167 Default value is 0.5.
167 Default value is 0.5.
168 */
168 */
169
169
170 /*!
170 /*!
171 \qmlproperty real PieSeries::donutInnerSize
171 \qmlproperty real PieSeries::donutInnerSize
172
172
173 Defines the donut inner size.
173 Defines the donut inner size.
174
174
175 The value is a relative value to the chart rectangle where:
175 The value is a relative value to the chart rectangle where:
176
176
177 \list
177 \list
178 \o 0.0 is the minimum size (donut is a pie).
178 \o 0.0 is the minimum size (donut is a pie).
179 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
179 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
180 \endlist
180 \endlist
181
181
182 When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size.
182 When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size.
183
183
184 Default value is 0.5.
184 Default value is 0.5.
185 */
185 */
186
186
187 /*!
187 /*!
188 \property QPieSeries::startAngle
188 \property QPieSeries::startAngle
189 \brief Defines the starting angle of the pie.
189 \brief Defines the starting angle of the pie.
190
190
191 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
191 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
192
192
193 Default is value is 0.
193 Default is value is 0.
194 */
194 */
195
195
196 /*!
196 /*!
197 \qmlproperty real PieSeries::startAngle
197 \qmlproperty real PieSeries::startAngle
198
198
199 Defines the starting angle of the pie.
199 Defines the starting angle of the pie.
200
200
201 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
201 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
202
202
203 Default is value is 0.
203 Default is value is 0.
204 */
204 */
205
205
206 /*!
206 /*!
207 \property QPieSeries::endAngle
207 \property QPieSeries::endAngle
208 \brief Defines the ending angle of the pie.
208 \brief Defines the ending angle of the pie.
209
209
210 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
210 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
211
211
212 Default is value is 360.
212 Default is value is 360.
213 */
213 */
214
214
215 /*!
215 /*!
216 \qmlproperty real PieSeries::endAngle
216 \qmlproperty real PieSeries::endAngle
217
217
218 Defines the ending angle of the pie.
218 Defines the ending angle of the pie.
219
219
220 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
220 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
221
221
222 Default is value is 360.
222 Default is value is 360.
223 */
223 */
224
224
225 /*!
225 /*!
226 \property QPieSeries::count
226 \property QPieSeries::count
227
227
228 Number of slices in the series.
228 Number of slices in the series.
229 */
229 */
230
230
231 /*!
231 /*!
232 \qmlproperty int PieSeries::count
232 \qmlproperty int PieSeries::count
233
233
234 Number of slices in the series.
234 Number of slices in the series.
235 */
235 */
236
236
237 /*!
237 /*!
238 \property QPieSeries::donut
238 \property QPieSeries::donut
239
239
240 Defines whether the series should be drawn as a donut
240 Defines whether the series should be drawn as a donut
241 */
241 */
242
242
243 /*!
243 /*!
244 \qmlproperty int PieSeries::donut
244 \qmlproperty int PieSeries::donut
245
245
246 Defines whether the series should be drawn as a donut
246 Defines whether the series should be drawn as a donut
247 */
247 */
248
248
249 /*!
249 /*!
250 \fn void QPieSeries::countChanged()
250 \fn void QPieSeries::countChanged()
251 Emitted when the slice count has changed.
251 Emitted when the slice count has changed.
252 \sa count
252 \sa count
253 */
253 */
254 /*!
254 /*!
255 \qmlsignal PieSeries::onCountChanged()
255 \qmlsignal PieSeries::onCountChanged()
256 Emitted when the slice count has changed.
256 Emitted when the slice count has changed.
257 */
257 */
258
258
259 /*!
259 /*!
260 \property QPieSeries::sum
260 \property QPieSeries::sum
261
261
262 Sum of all slices.
262 Sum of all slices.
263
263
264 The series keeps track of the sum of all slices it holds.
264 The series keeps track of the sum of all slices it holds.
265 */
265 */
266
266
267 /*!
267 /*!
268 \qmlproperty real PieSeries::sum
268 \qmlproperty real PieSeries::sum
269
269
270 Sum of all slices.
270 Sum of all slices.
271
271
272 The series keeps track of the sum of all slices it holds.
272 The series keeps track of the sum of all slices it holds.
273 */
273 */
274
274
275 /*!
275 /*!
276 \fn void QPieSeries::sumChanged()
276 \fn void QPieSeries::sumChanged()
277 Emitted when the sum of all slices has changed.
277 Emitted when the sum of all slices has changed.
278 \sa sum
278 \sa sum
279 */
279 */
280 /*!
280 /*!
281 \qmlsignal PieSeries::onSumChanged()
281 \qmlsignal PieSeries::onSumChanged()
282 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
282 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
283 change value of a slice.
283 change value of a slice.
284 */
284 */
285
285
286 /*!
286 /*!
287 \fn void QPieSeries::added(QList<QPieSlice*> slices)
287 \fn void QPieSeries::added(QList<QPieSlice*> slices)
288
288
289 This signal is emitted when \a slices have been added to the series.
289 This signal is emitted when \a slices have been added to the series.
290
290
291 \sa append(), insert()
291 \sa append(), insert()
292 */
292 */
293 /*!
293 /*!
294 \qmlsignal PieSeries::onAdded(PieSlice slice)
294 \qmlsignal PieSeries::onAdded(PieSlice slice)
295 Emitted when \a slice has been added to the series.
295 Emitted when \a slice has been added to the series.
296 */
296 */
297
297
298 /*!
298 /*!
299 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
299 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
300 This signal is emitted when \a slices have been removed from the series.
300 This signal is emitted when \a slices have been removed from the series.
301 \sa remove()
301 \sa remove()
302 */
302 */
303 /*!
303 /*!
304 \qmlsignal PieSeries::onRemoved(PieSlice slice)
304 \qmlsignal PieSeries::onRemoved(PieSlice slice)
305 Emitted when \a slice has been removed from the series.
305 Emitted when \a slice has been removed from the series.
306 */
306 */
307
307
308 /*!
308 /*!
309 \fn void QPieSeries::clicked(QPieSlice* slice)
309 \fn void QPieSeries::clicked(QPieSlice* slice)
310 This signal is emitted when a \a slice has been clicked.
310 This signal is emitted when a \a slice has been clicked.
311 \sa QPieSlice::clicked()
311 \sa QPieSlice::clicked()
312 */
312 */
313 /*!
313 /*!
314 \qmlsignal PieSeries::onClicked(PieSlice slice)
314 \qmlsignal PieSeries::onClicked(PieSlice slice)
315 This signal is emitted when a \a slice has been clicked.
315 This signal is emitted when a \a slice has been clicked.
316 */
316 */
317
317
318 /*!
318 /*!
319 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
319 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
320 This signal is emitted when user has hovered over or away from the \a slice.
320 This signal is emitted when user has hovered over or away from the \a slice.
321 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
321 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
322 \sa QPieSlice::hovered()
322 \sa QPieSlice::hovered()
323 */
323 */
324 /*!
324 /*!
325 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
325 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
326 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
326 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
327 over the slice and false when hover has moved away from the slice.
327 over the slice and false when hover has moved away from the slice.
328 */
328 */
329
329
330 /*!
330 /*!
331 \qmlmethod PieSlice PieSeries::at(int index)
331 \qmlmethod PieSlice PieSeries::at(int index)
332 Returns slice at \a index. Returns null if the index is not valid.
332 Returns slice at \a index. Returns null if the index is not valid.
333 */
333 */
334
334
335 /*!
335 /*!
336 \qmlmethod PieSlice PieSeries::find(string label)
336 \qmlmethod PieSlice PieSeries::find(string label)
337 Returns the first slice with \a label. Returns null if the index is not valid.
337 Returns the first slice with \a label. Returns null if the index is not valid.
338 */
338 */
339
339
340 /*!
340 /*!
341 \qmlmethod PieSlice PieSeries::append(string label, real value)
341 \qmlmethod PieSlice PieSeries::append(string label, real value)
342 Adds a new slice with \a label and \a value to the pie.
342 Adds a new slice with \a label and \a value to the pie.
343 */
343 */
344
344
345 /*!
345 /*!
346 \qmlmethod bool PieSeries::remove(PieSlice slice)
346 \qmlmethod bool PieSeries::remove(PieSlice slice)
347 Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise.
347 Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise.
348 */
348 */
349
349
350 /*!
350 /*!
351 \qmlmethod PieSeries::clear()
351 \qmlmethod PieSeries::clear()
352 Removes all slices from the pie.
352 Removes all slices from the pie.
353 */
353 */
354
354
355 /*!
355 /*!
356 Constructs a series object which is a child of \a parent.
356 Constructs a series object which is a child of \a parent.
357 */
357 */
358 QPieSeries::QPieSeries(QObject *parent) :
358 QPieSeries::QPieSeries(QObject *parent) :
359 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
359 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
360 {
360 {
361
361
362 }
362 }
363
363
364 /*!
364 /*!
365 Destroys the series and its slices.
365 Destroys the series and its slices.
366 */
366 */
367 QPieSeries::~QPieSeries()
367 QPieSeries::~QPieSeries()
368 {
368 {
369 // NOTE: d_prt destroyed by QObject
369 // NOTE: d_prt destroyed by QObject
370 }
370 }
371
371
372 /*!
372 /*!
373 Returns QChartSeries::SeriesTypePie.
373 Returns QChartSeries::SeriesTypePie.
374 */
374 */
375 QAbstractSeries::SeriesType QPieSeries::type() const
375 QAbstractSeries::SeriesType QPieSeries::type() const
376 {
376 {
377 return QAbstractSeries::SeriesTypePie;
377 return QAbstractSeries::SeriesTypePie;
378 }
378 }
379
379
380 /*!
380 /*!
381 Appends a single \a slice to the series.
381 Appends a single \a slice to the series.
382 Slice ownership is passed to the series.
382 Slice ownership is passed to the series.
383
383
384 Returns true if append was succesfull.
384 Returns true if append was succesfull.
385 */
385 */
386 bool QPieSeries::append(QPieSlice* slice)
386 bool QPieSeries::append(QPieSlice* slice)
387 {
387 {
388 return append(QList<QPieSlice*>() << slice);
388 return append(QList<QPieSlice*>() << slice);
389 }
389 }
390
390
391 /*!
391 /*!
392 Appends an array of \a slices to the series.
392 Appends an array of \a slices to the series.
393 Slice ownership is passed to the series.
393 Slice ownership is passed to the series.
394
394
395 Returns true if append was successfull.
395 Returns true if append was successfull.
396 */
396 */
397 bool QPieSeries::append(QList<QPieSlice*> slices)
397 bool QPieSeries::append(QList<QPieSlice*> slices)
398 {
398 {
399 Q_D(QPieSeries);
399 Q_D(QPieSeries);
400
400
401 if (slices.count() == 0)
401 if (slices.count() == 0)
402 return false;
402 return false;
403
403
404 foreach (QPieSlice* s, slices) {
404 foreach (QPieSlice* s, slices) {
405 if (!s || d->m_slices.contains(s))
405 if (!s || d->m_slices.contains(s))
406 return false;
406 return false;
407 if (s->series()) // already added to some series
407 if (s->series()) // already added to some series
408 return false;
408 return false;
409 }
409 }
410
410
411 foreach (QPieSlice* s, slices) {
411 foreach (QPieSlice* s, slices) {
412 s->setParent(this);
412 s->setParent(this);
413 QPieSlicePrivate::fromSlice(s)->m_series = this;
413 QPieSlicePrivate::fromSlice(s)->m_series = this;
414 d->m_slices << s;
414 d->m_slices << s;
415 }
415 }
416
416
417 d->updateDerivativeData();
417 d->updateDerivativeData();
418
418
419 foreach (QPieSlice* s, slices) {
419 foreach (QPieSlice* s, slices) {
420 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
420 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
421 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
421 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
422 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
422 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
423 }
423 }
424
424
425 emit added(slices);
425 emit added(slices);
426 emit countChanged();
426 emit countChanged();
427
427
428 return true;
428 return true;
429 }
429 }
430
430
431 /*!
431 /*!
432 Appends a single \a slice to the series and returns a reference to the series.
432 Appends a single \a slice to the series and returns a reference to the series.
433 Slice ownership is passed to the series.
433 Slice ownership is passed to the series.
434 */
434 */
435 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
435 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
436 {
436 {
437 append(slice);
437 append(slice);
438 return *this;
438 return *this;
439 }
439 }
440
440
441
441
442 /*!
442 /*!
443 Appends a single slice to the series with give \a value and \a label.
443 Appends a single slice to the series with give \a value and \a label.
444 Slice ownership is passed to the series.
444 Slice ownership is passed to the series.
445 */
445 */
446 QPieSlice* QPieSeries::append(QString label, qreal value)
446 QPieSlice* QPieSeries::append(QString label, qreal value)
447 {
447 {
448 QPieSlice* slice = new QPieSlice(label, value);
448 QPieSlice* slice = new QPieSlice(label, value);
449 append(slice);
449 append(slice);
450 return slice;
450 return slice;
451 }
451 }
452
452
453 /*!
453 /*!
454 Inserts a single \a slice to the series before the slice at \a index position.
454 Inserts a single \a slice to the series before the slice at \a index position.
455 Slice ownership is passed to the series.
455 Slice ownership is passed to the series.
456
456
457 Returns true if insert was successfull.
457 Returns true if insert was successfull.
458 */
458 */
459 bool QPieSeries::insert(int index, QPieSlice* slice)
459 bool QPieSeries::insert(int index, QPieSlice* slice)
460 {
460 {
461 Q_D(QPieSeries);
461 Q_D(QPieSeries);
462
462
463 if (index < 0 || index > d->m_slices.count())
463 if (index < 0 || index > d->m_slices.count())
464 return false;
464 return false;
465
465
466 if (!slice || d->m_slices.contains(slice))
466 if (!slice || d->m_slices.contains(slice))
467 return false;
467 return false;
468
468
469 if (slice->series()) // already added to some series
469 if (slice->series()) // already added to some series
470 return false;
470 return false;
471
471
472 slice->setParent(this);
472 slice->setParent(this);
473 QPieSlicePrivate::fromSlice(slice)->m_series = this;
473 QPieSlicePrivate::fromSlice(slice)->m_series = this;
474 d->m_slices.insert(index, slice);
474 d->m_slices.insert(index, slice);
475
475
476 d->updateDerivativeData();
476 d->updateDerivativeData();
477
477
478 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
478 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
479 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
479 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
480 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
480 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
481
481
482 emit added(QList<QPieSlice*>() << slice);
482 emit added(QList<QPieSlice*>() << slice);
483 emit countChanged();
483 emit countChanged();
484
484
485 return true;
485 return true;
486 }
486 }
487
487
488 /*!
488 /*!
489 Removes a single \a slice from the series and deletes the slice.
489 Removes a single \a slice from the series and deletes the slice.
490
490
491 Do not reference the pointer after this call.
491 Do not reference the pointer after this call.
492
492
493 Returns true if remove was successfull.
493 Returns true if remove was successfull.
494 */
494 */
495 bool QPieSeries::remove(QPieSlice* slice)
495 bool QPieSeries::remove(QPieSlice* slice)
496 {
496 {
497 Q_D(QPieSeries);
497 Q_D(QPieSeries);
498
498
499 if (!d->m_slices.removeOne(slice))
499 if (!d->m_slices.removeOne(slice))
500 return false;
500 return false;
501
501
502 d->updateDerivativeData();
502 d->updateDerivativeData();
503
503
504 emit removed(QList<QPieSlice*>() << slice);
504 emit removed(QList<QPieSlice*>() << slice);
505 emit countChanged();
505 emit countChanged();
506
506
507 delete slice;
507 delete slice;
508 slice = 0;
508 slice = 0;
509
509
510 return true;
510 return true;
511 }
511 }
512
512
513 /*!
513 /*!
514 Clears all slices from the series.
514 Clears all slices from the series.
515 */
515 */
516 void QPieSeries::clear()
516 void QPieSeries::clear()
517 {
517 {
518 Q_D(QPieSeries);
518 Q_D(QPieSeries);
519 if (d->m_slices.count() == 0)
519 if (d->m_slices.count() == 0)
520 return;
520 return;
521
521
522 QList<QPieSlice*> slices = d->m_slices;
522 QList<QPieSlice*> slices = d->m_slices;
523 foreach (QPieSlice* s, d->m_slices) {
523 foreach (QPieSlice* s, d->m_slices) {
524 d->m_slices.removeOne(s);
524 d->m_slices.removeOne(s);
525 delete s;
525 delete s;
526 }
526 }
527
527
528 d->updateDerivativeData();
528 d->updateDerivativeData();
529
529
530 emit removed(slices);
530 emit removed(slices);
531 emit countChanged();
531 emit countChanged();
532 }
532 }
533
533
534 /*!
534 /*!
535 Returns a list of slices that belong to this series.
535 Returns a list of slices that belong to this series.
536 */
536 */
537 QList<QPieSlice*> QPieSeries::slices() const
537 QList<QPieSlice*> QPieSeries::slices() const
538 {
538 {
539 Q_D(const QPieSeries);
539 Q_D(const QPieSeries);
540 return d->m_slices;
540 return d->m_slices;
541 }
541 }
542
542
543 /*!
543 /*!
544 returns the number of the slices in this series.
544 returns the number of the slices in this series.
545 */
545 */
546 int QPieSeries::count() const
546 int QPieSeries::count() const
547 {
547 {
548 Q_D(const QPieSeries);
548 Q_D(const QPieSeries);
549 return d->m_slices.count();
549 return d->m_slices.count();
550 }
550 }
551
551
552 /*!
552 /*!
553 Returns true is the series is empty.
553 Returns true is the series is empty.
554 */
554 */
555 bool QPieSeries::isEmpty() const
555 bool QPieSeries::isEmpty() const
556 {
556 {
557 Q_D(const QPieSeries);
557 Q_D(const QPieSeries);
558 return d->m_slices.isEmpty();
558 return d->m_slices.isEmpty();
559 }
559 }
560
560
561 /*!
561 /*!
562 Returns the sum of all slice values in this series.
562 Returns the sum of all slice values in this series.
563
563
564 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
564 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
565 */
565 */
566 qreal QPieSeries::sum() const
566 qreal QPieSeries::sum() const
567 {
567 {
568 Q_D(const QPieSeries);
568 Q_D(const QPieSeries);
569 return d->m_sum;
569 return d->m_sum;
570 }
570 }
571
571
572 void QPieSeries::setDonut(bool donut)
572 void QPieSeries::setDonut(bool donut)
573 {
573 {
574 Q_D(QPieSeries);
574 Q_D(QPieSeries);
575 d->m_donutChart = donut;
575 d->m_donutChart = donut;
576 d->updateDerivativeData();
576 d->updateDerivativeData();
577 }
577 }
578
578
579 bool QPieSeries::donut() const
579 bool QPieSeries::donut() const
580 {
580 {
581 Q_D(const QPieSeries);
581 Q_D(const QPieSeries);
582 return d->m_donutChart;
582 return d->m_donutChart;
583 }
583 }
584
584
585 void QPieSeries::setDonutInnerSize(qreal innerSize)
585 void QPieSeries::setDonutInnerSize(qreal innerSize)
586 {
586 {
587 Q_D(QPieSeries);
587 Q_D(QPieSeries);
588 innerSize = qBound(0.0, innerSize, 1.0);
588 innerSize = qBound(0.0, innerSize, 1.0);
589 d->setSizes(innerSize, qMax(d->m_pieRelativeSize, innerSize));
589 d->setSizes(innerSize, qMax(d->m_pieRelativeSize, innerSize));
590 }
590 }
591
591
592 qreal QPieSeries::donutInnerSize() const
592 qreal QPieSeries::donutInnerSize() const
593 {
593 {
594 Q_D(const QPieSeries);
594 Q_D(const QPieSeries);
595 return d->m_donutRelativeInnerSize;
595 return d->m_donutRelativeInnerSize;
596 }
596 }
597
597
598 void QPieSeries::setHorizontalPosition(qreal relativePosition)
598 void QPieSeries::setHorizontalPosition(qreal relativePosition)
599 {
599 {
600 Q_D(QPieSeries);
600 Q_D(QPieSeries);
601
601
602 if (relativePosition < 0.0)
602 if (relativePosition < 0.0)
603 relativePosition = 0.0;
603 relativePosition = 0.0;
604 if (relativePosition > 1.0)
604 if (relativePosition > 1.0)
605 relativePosition = 1.0;
605 relativePosition = 1.0;
606
606
607 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
607 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
608 d->m_pieRelativeHorPos = relativePosition;
608 d->m_pieRelativeHorPos = relativePosition;
609 emit d->horizontalPositionChanged();
609 emit d->horizontalPositionChanged();
610 }
610 }
611 }
611 }
612
612
613 qreal QPieSeries::horizontalPosition() const
613 qreal QPieSeries::horizontalPosition() const
614 {
614 {
615 Q_D(const QPieSeries);
615 Q_D(const QPieSeries);
616 return d->m_pieRelativeHorPos;
616 return d->m_pieRelativeHorPos;
617 }
617 }
618
618
619 void QPieSeries::setVerticalPosition(qreal relativePosition)
619 void QPieSeries::setVerticalPosition(qreal relativePosition)
620 {
620 {
621 Q_D(QPieSeries);
621 Q_D(QPieSeries);
622
622
623 if (relativePosition < 0.0)
623 if (relativePosition < 0.0)
624 relativePosition = 0.0;
624 relativePosition = 0.0;
625 if (relativePosition > 1.0)
625 if (relativePosition > 1.0)
626 relativePosition = 1.0;
626 relativePosition = 1.0;
627
627
628 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
628 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
629 d->m_pieRelativeVerPos = relativePosition;
629 d->m_pieRelativeVerPos = relativePosition;
630 emit d->verticalPositionChanged();
630 emit d->verticalPositionChanged();
631 }
631 }
632 }
632 }
633
633
634 qreal QPieSeries::verticalPosition() const
634 qreal QPieSeries::verticalPosition() const
635 {
635 {
636 Q_D(const QPieSeries);
636 Q_D(const QPieSeries);
637 return d->m_pieRelativeVerPos;
637 return d->m_pieRelativeVerPos;
638 }
638 }
639
639
640 void QPieSeries::setPieSize(qreal relativeSize)
640 void QPieSeries::setPieSize(qreal relativeSize)
641 {
641 {
642 Q_D(QPieSeries);
642 Q_D(QPieSeries);
643 relativeSize = qBound(0.0, relativeSize, 1.0);
643 relativeSize = qBound(0.0, relativeSize, 1.0);
644 d->setSizes(qMin(d->m_donutRelativeInnerSize, relativeSize), relativeSize);
644 d->setSizes(qMin(d->m_donutRelativeInnerSize, relativeSize), relativeSize);
645
645
646 }
646 }
647
647
648 qreal QPieSeries::pieSize() const
648 qreal QPieSeries::pieSize() const
649 {
649 {
650 Q_D(const QPieSeries);
650 Q_D(const QPieSeries);
651 return d->m_pieRelativeSize;
651 return d->m_pieRelativeSize;
652 }
652 }
653
653
654
654
655 void QPieSeries::setPieStartAngle(qreal angle)
655 void QPieSeries::setPieStartAngle(qreal angle)
656 {
656 {
657 Q_D(QPieSeries);
657 Q_D(QPieSeries);
658 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
658 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
659 return;
659 return;
660 d->m_pieStartAngle = angle;
660 d->m_pieStartAngle = angle;
661 d->updateDerivativeData();
661 d->updateDerivativeData();
662 emit d->pieStartAngleChanged();
662 emit d->pieStartAngleChanged();
663 }
663 }
664
664
665 qreal QPieSeries::pieStartAngle() const
665 qreal QPieSeries::pieStartAngle() const
666 {
666 {
667 Q_D(const QPieSeries);
667 Q_D(const QPieSeries);
668 return d->m_pieStartAngle;
668 return d->m_pieStartAngle;
669 }
669 }
670
670
671 /*!
671 /*!
672 Sets the end angle of the pie.
672 Sets the end angle of the pie.
673
673
674 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
674 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
675
675
676 \a angle must be greater than start angle.
676 \a angle must be greater than start angle.
677
677
678 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
678 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
679 */
679 */
680 void QPieSeries::setPieEndAngle(qreal angle)
680 void QPieSeries::setPieEndAngle(qreal angle)
681 {
681 {
682 Q_D(QPieSeries);
682 Q_D(QPieSeries);
683 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
683 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
684 return;
684 return;
685 d->m_pieEndAngle = angle;
685 d->m_pieEndAngle = angle;
686 d->updateDerivativeData();
686 d->updateDerivativeData();
687 emit d->pieEndAngleChanged();
687 emit d->pieEndAngleChanged();
688 }
688 }
689
689
690 /*!
690 /*!
691 Returns the end angle of the pie.
691 Returns the end angle of the pie.
692
692
693 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
693 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
694
694
695 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
695 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
696 */
696 */
697 qreal QPieSeries::pieEndAngle() const
697 qreal QPieSeries::pieEndAngle() const
698 {
698 {
699 Q_D(const QPieSeries);
699 Q_D(const QPieSeries);
700 return d->m_pieEndAngle;
700 return d->m_pieEndAngle;
701 }
701 }
702
702
703 /*!
703 /*!
704 Sets the all the slice labels \a visible or invisible.
704 Sets the all the slice labels \a visible or invisible.
705
705
706 Note that this affects only the current slices in the series.
706 Note that this affects only the current slices in the series.
707 If user adds a new slice the default label visibility is false.
707 If user adds a new slice the default label visibility is false.
708
708
709 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
709 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
710 */
710 */
711 void QPieSeries::setLabelsVisible(bool visible)
711 void QPieSeries::setLabelsVisible(bool visible)
712 {
712 {
713 Q_D(QPieSeries);
713 Q_D(QPieSeries);
714 foreach (QPieSlice* s, d->m_slices)
714 foreach (QPieSlice* s, d->m_slices)
715 s->setLabelVisible(visible);
715 s->setLabelVisible(visible);
716 }
716 }
717
717
718 /*!
719 Sets the all the slice labels \a position
720
721 Note that this affects only the current slices in the series.
722 If user adds a new slice the default label position is LabelOutside
723
724 \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition()
725 */
718 void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
726 void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
719 {
727 {
720 Q_D(QPieSeries);
728 Q_D(QPieSeries);
721 foreach (QPieSlice* s, d->m_slices)
729 foreach (QPieSlice* s, d->m_slices)
722 s->setLabelPosition(position);
730 s->setLabelPosition(position);
723 }
731 }
724
732
725 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
733 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
726
734
727
735
728 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
736 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
729 QAbstractSeriesPrivate(parent),
737 QAbstractSeriesPrivate(parent),
730 m_pieRelativeHorPos(0.5),
738 m_pieRelativeHorPos(0.5),
731 m_pieRelativeVerPos(0.5),
739 m_pieRelativeVerPos(0.5),
732 m_pieRelativeSize(0.7),
740 m_pieRelativeSize(0.7),
733 m_pieStartAngle(0),
741 m_pieStartAngle(0),
734 m_pieEndAngle(360),
742 m_pieEndAngle(360),
735 m_sum(0),
743 m_sum(0),
736 m_donutChart(false),
744 m_donutChart(false),
737 m_donutRelativeInnerSize(0.5)
745 m_donutRelativeInnerSize(0.5)
738 {
746 {
739 }
747 }
740
748
741 QPieSeriesPrivate::~QPieSeriesPrivate()
749 QPieSeriesPrivate::~QPieSeriesPrivate()
742 {
750 {
743 }
751 }
744
752
745 void QPieSeriesPrivate::updateDerivativeData()
753 void QPieSeriesPrivate::updateDerivativeData()
746 {
754 {
747 // calculate sum of all slices
755 // calculate sum of all slices
748 qreal sum = 0;
756 qreal sum = 0;
749 foreach (QPieSlice* s, m_slices)
757 foreach (QPieSlice* s, m_slices)
750 sum += s->value();
758 sum += s->value();
751
759
752 if (!qFuzzyIsNull(m_sum - sum)) {
760 if (!qFuzzyIsNull(m_sum - sum)) {
753 m_sum = sum;
761 m_sum = sum;
754 emit q_func()->sumChanged();
762 emit q_func()->sumChanged();
755 }
763 }
756
764
757 // nothing to show..
765 // nothing to show..
758 if (qFuzzyIsNull(m_sum))
766 if (qFuzzyIsNull(m_sum))
759 return;
767 return;
760
768
761 // update slice attributes
769 // update slice attributes
762 qreal sliceAngle = m_pieStartAngle;
770 qreal sliceAngle = m_pieStartAngle;
763 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
771 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
764 QVector<QPieSlice*> changed;
772 QVector<QPieSlice*> changed;
765 foreach (QPieSlice* s, m_slices) {
773 foreach (QPieSlice* s, m_slices) {
766 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
774 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
767 d->setPercentage(s->value() / m_sum);
775 d->setPercentage(s->value() / m_sum);
768 d->setStartAngle(sliceAngle);
776 d->setStartAngle(sliceAngle);
769 d->setAngleSpan(pieSpan * s->percentage());
777 d->setAngleSpan(pieSpan * s->percentage());
770 sliceAngle += s->angleSpan();
778 sliceAngle += s->angleSpan();
771 }
779 }
772
780
773
781
774 emit calculatedDataChanged();
782 emit calculatedDataChanged();
775 }
783 }
776
784
777 void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize)
785 void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize)
778 {
786 {
779 bool changed = false;
787 bool changed = false;
780
788
781 if (!qFuzzyIsNull(m_donutRelativeInnerSize - innerSize)) {
789 if (!qFuzzyIsNull(m_donutRelativeInnerSize - innerSize)) {
782 m_donutRelativeInnerSize = innerSize;
790 m_donutRelativeInnerSize = innerSize;
783 changed = true;
791 changed = true;
784 }
792 }
785
793
786 if (!qFuzzyIsNull(m_pieRelativeSize - outerSize)) {
794 if (!qFuzzyIsNull(m_pieRelativeSize - outerSize)) {
787 m_pieRelativeSize = outerSize;
795 m_pieRelativeSize = outerSize;
788 changed = true;
796 changed = true;
789 }
797 }
790
798
791 if (changed)
799 if (changed)
792 emit pieSizeChanged();
800 emit pieSizeChanged();
793 }
801 }
794
802
795 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
803 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
796 {
804 {
797 return series->d_func();
805 return series->d_func();
798 }
806 }
799
807
800 void QPieSeriesPrivate::sliceValueChanged()
808 void QPieSeriesPrivate::sliceValueChanged()
801 {
809 {
802 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
810 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
803 updateDerivativeData();
811 updateDerivativeData();
804 }
812 }
805
813
806 void QPieSeriesPrivate::sliceClicked()
814 void QPieSeriesPrivate::sliceClicked()
807 {
815 {
808 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
816 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
809 Q_ASSERT(m_slices.contains(slice));
817 Q_ASSERT(m_slices.contains(slice));
810 Q_Q(QPieSeries);
818 Q_Q(QPieSeries);
811 emit q->clicked(slice);
819 emit q->clicked(slice);
812 }
820 }
813
821
814 void QPieSeriesPrivate::sliceHovered(bool state)
822 void QPieSeriesPrivate::sliceHovered(bool state)
815 {
823 {
816 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
824 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
817 Q_ASSERT(m_slices.contains(slice));
825 Q_ASSERT(m_slices.contains(slice));
818 Q_Q(QPieSeries);
826 Q_Q(QPieSeries);
819 emit q->hovered(slice, state);
827 emit q->hovered(slice, state);
820 }
828 }
821
829
822 void QPieSeriesPrivate::scaleDomain(Domain& domain)
830 void QPieSeriesPrivate::scaleDomain(Domain& domain)
823 {
831 {
824 Q_UNUSED(domain);
832 Q_UNUSED(domain);
825 // does not apply to pie
833 // does not apply to pie
826 }
834 }
827
835
828 ChartElement* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
836 ChartElement* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
829 {
837 {
830 Q_Q(QPieSeries);
838 Q_Q(QPieSeries);
831 PieChartItem* pie = new PieChartItem(q,presenter);
839 PieChartItem* pie = new PieChartItem(q,presenter);
832 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
840 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
833 pie->setAnimation(new PieAnimation(pie));
841 pie->setAnimation(new PieAnimation(pie));
834 }
842 }
835 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
843 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
836 return pie;
844 return pie;
837 }
845 }
838
846
839 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
847 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
840 {
848 {
841 Q_Q(QPieSeries);
849 Q_Q(QPieSeries);
842 QList<LegendMarker*> markers;
850 QList<LegendMarker*> markers;
843 foreach(QPieSlice* slice, q->slices()) {
851 foreach(QPieSlice* slice, q->slices()) {
844 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
852 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
845 markers << marker;
853 markers << marker;
846 }
854 }
847 return markers;
855 return markers;
848 }
856 }
849
857
850 void QPieSeriesPrivate::initializeAxis(QAbstractAxis* axis)
858 void QPieSeriesPrivate::initializeAxis(QAbstractAxis* axis)
851 {
859 {
852 Q_UNUSED(axis);
860 Q_UNUSED(axis);
853 }
861 }
854
862
855 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
863 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
856 {
864 {
857 Q_UNUSED(orientation);
865 Q_UNUSED(orientation);
858 return QAbstractAxis::AxisTypeNoAxis;
866 return QAbstractAxis::AxisTypeNoAxis;
859 }
867 }
860
868
861 #include "moc_qpieseries.cpp"
869 #include "moc_qpieseries.cpp"
862 #include "moc_qpieseries_p.cpp"
870 #include "moc_qpieseries_p.cpp"
863
871
864 QTCOMMERCIALCHART_END_NAMESPACE
872 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now