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