##// END OF EJS Templates
Adds domains swap logic
Michal Klocek -
r2284:5ea9e4fa75c8
parent child
Show More
@@ -1,868 +1,869
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 #include "chartdataset_p.h"
23 #include "chartdataset_p.h"
24 #include "charttheme_p.h"
24 #include "charttheme_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QAbstractAxis
29 \class QAbstractAxis
30 \brief The QAbstractAxis class is used for manipulating chart's axis.
30 \brief The QAbstractAxis class is used for manipulating chart's axis.
31 \mainclass
31 \mainclass
32
32
33 There is only one x Axis visible at the time, however there can be multiple y axes.
33 There is only one x Axis visible at the time, however there can be multiple y axes.
34 Each chart series can be bound to exactly one Y axis and the shared common X axis.
34 Each chart series can be bound to exactly one Y axis and the shared common X axis.
35 Axis can be setup to show axis line with tick marks, grid lines and shades.
35 Axis can be setup to show axis line with tick marks, grid lines and shades.
36 */
36 */
37
37
38 /*!
38 /*!
39 \qmlclass AbstractAxis QAbstractAxis
39 \qmlclass AbstractAxis QAbstractAxis
40 \brief The Axis element is used for manipulating chart's axes
40 \brief The Axis element is used for manipulating chart's axes
41
41
42 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
42 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
43 Each chart series can be bound to exactly one Y axis and the shared common X axis.
43 Each chart series can be bound to exactly one Y axis and the shared common X axis.
44 Axis can be setup to show axis line with tick marks, grid lines and shades.
44 Axis can be setup to show axis line with tick marks, grid lines and shades.
45
45
46 To access Axes you can use ChartView API. For example:
46 To access Axes you can use ChartView API. For example:
47 \code
47 \code
48 ChartView {
48 ChartView {
49 axisX.min: 0
49 axisX.min: 0
50 axisX.max: 3
50 axisX.max: 3
51 axisX.ticksCount: 4
51 axisX.ticksCount: 4
52 axisY.min: 0
52 axisY.min: 0
53 axisY.max: 4
53 axisY.max: 4
54 // Add a few series...
54 // Add a few series...
55 }
55 }
56 \endcode
56 \endcode
57 */
57 */
58
58
59 /*!
59 /*!
60 \enum QAbstractAxis::AxisType
60 \enum QAbstractAxis::AxisType
61
61
62 The type of the series object.
62 The type of the series object.
63
63
64 \value AxisTypeNoAxis
64 \value AxisTypeNoAxis
65 \value AxisTypeValue
65 \value AxisTypeValue
66 \value AxisTypeBarCategory
66 \value AxisTypeBarCategory
67 \value AxisTypeCategory
67 \value AxisTypeCategory
68 \value AxisTypeDateTime
68 \value AxisTypeDateTime
69 */
69 */
70
70
71 /*!
71 /*!
72 *\fn void QAbstractAxis::type() const
72 *\fn void QAbstractAxis::type() const
73 Returns the type of the axis
73 Returns the type of the axis
74 */
74 */
75
75
76 /*!
76 /*!
77 \property QAbstractAxis::lineVisible
77 \property QAbstractAxis::lineVisible
78 The visibility of the axis line
78 The visibility of the axis line
79 */
79 */
80 /*!
80 /*!
81 \qmlproperty bool AbstractAxis::lineVisible
81 \qmlproperty bool AbstractAxis::lineVisible
82 The visibility of the axis line
82 The visibility of the axis line
83 */
83 */
84
84
85 /*!
85 /*!
86 \property QAbstractAxis::labelsVisible
86 \property QAbstractAxis::labelsVisible
87 Defines if axis labels are visible.
87 Defines if axis labels are visible.
88 */
88 */
89 /*!
89 /*!
90 \qmlproperty bool AbstractAxis::labelsVisible
90 \qmlproperty bool AbstractAxis::labelsVisible
91 Defines if axis labels are visible.
91 Defines if axis labels are visible.
92 */
92 */
93
93
94 /*!
94 /*!
95 \property QAbstractAxis::visible
95 \property QAbstractAxis::visible
96 The visibility of the axis.
96 The visibility of the axis.
97 */
97 */
98 /*!
98 /*!
99 \qmlproperty bool AbstractAxis::visible
99 \qmlproperty bool AbstractAxis::visible
100 The visibility of the axis.
100 The visibility of the axis.
101 */
101 */
102
102
103 /*!
103 /*!
104 \property QAbstractAxis::gridVisible
104 \property QAbstractAxis::gridVisible
105 The visibility of the grid lines.
105 The visibility of the grid lines.
106 */
106 */
107 /*!
107 /*!
108 \qmlproperty bool AbstractAxis::gridVisible
108 \qmlproperty bool AbstractAxis::gridVisible
109 The visibility of the grid lines.
109 The visibility of the grid lines.
110 */
110 */
111
111
112 /*!
112 /*!
113 \property QAbstractAxis::color
113 \property QAbstractAxis::color
114 The color of the axis and ticks.
114 The color of the axis and ticks.
115 */
115 */
116 /*!
116 /*!
117 \qmlproperty color AbstractAxis::color
117 \qmlproperty color AbstractAxis::color
118 The color of the axis and ticks.
118 The color of the axis and ticks.
119 */
119 */
120
120
121 /*!
121 /*!
122 \property QAbstractAxis::labelsFont
122 \property QAbstractAxis::labelsFont
123 The font of the axis labels.
123 The font of the axis labels.
124 */
124 */
125
125
126 /*!
126 /*!
127 \qmlproperty Font AbstractAxis::labelsFont
127 \qmlproperty Font AbstractAxis::labelsFont
128 The font of the axis labels.
128 The font of the axis labels.
129
129
130 See the \l {Font} {QML Font Element} for detailed documentation.
130 See the \l {Font} {QML Font Element} for detailed documentation.
131 */
131 */
132
132
133 /*!
133 /*!
134 \property QAbstractAxis::labelsColor
134 \property QAbstractAxis::labelsColor
135 The color of the axis labels.
135 The color of the axis labels.
136 */
136 */
137 /*!
137 /*!
138 \qmlproperty color AbstractAxis::labelsColor
138 \qmlproperty color AbstractAxis::labelsColor
139 The color of the axis labels.
139 The color of the axis labels.
140 */
140 */
141
141
142 /*!
142 /*!
143 \property QAbstractAxis::labelsAngle
143 \property QAbstractAxis::labelsAngle
144 The angle of the axis labels in degrees.
144 The angle of the axis labels in degrees.
145 */
145 */
146 /*!
146 /*!
147 \qmlproperty int AbstractAxis::labelsAngle
147 \qmlproperty int AbstractAxis::labelsAngle
148 The angle of the axis labels in degrees.
148 The angle of the axis labels in degrees.
149 */
149 */
150
150
151 /*!
151 /*!
152 \property QAbstractAxis::shadesVisible
152 \property QAbstractAxis::shadesVisible
153 The visibility of the axis shades.
153 The visibility of the axis shades.
154 */
154 */
155 /*!
155 /*!
156 \qmlproperty bool AbstractAxis::shadesVisible
156 \qmlproperty bool AbstractAxis::shadesVisible
157 The visibility of the axis shades.
157 The visibility of the axis shades.
158 */
158 */
159
159
160 /*!
160 /*!
161 \property QAbstractAxis::shadesColor
161 \property QAbstractAxis::shadesColor
162 The fill (brush) color of the axis shades.
162 The fill (brush) color of the axis shades.
163 */
163 */
164 /*!
164 /*!
165 \qmlproperty color AbstractAxis::shadesColor
165 \qmlproperty color AbstractAxis::shadesColor
166 The fill (brush) color of the axis shades.
166 The fill (brush) color of the axis shades.
167 */
167 */
168
168
169 /*!
169 /*!
170 \property QAbstractAxis::shadesBorderColor
170 \property QAbstractAxis::shadesBorderColor
171 The border (pen) color of the axis shades.
171 The border (pen) color of the axis shades.
172 */
172 */
173 /*!
173 /*!
174 \qmlproperty color AbstractAxis::shadesBorderColor
174 \qmlproperty color AbstractAxis::shadesBorderColor
175 The border (pen) color of the axis shades.
175 The border (pen) color of the axis shades.
176 */
176 */
177
177
178 /*!
178 /*!
179 \property QAbstractAxis::titleVisible
179 \property QAbstractAxis::titleVisible
180 The visibility of the axis title. By default the value is true.
180 The visibility of the axis title. By default the value is true.
181 */
181 */
182 /*!
182 /*!
183 \qmlproperty bool AbstractAxis::titleVisible
183 \qmlproperty bool AbstractAxis::titleVisible
184 The visibility of the axis title. By default the value is true.
184 The visibility of the axis title. By default the value is true.
185 */
185 */
186
186
187 /*!
187 /*!
188 \property QAbstractAxis::titleFont
188 \property QAbstractAxis::titleFont
189 The font of the title of the axis.
189 The font of the title of the axis.
190 */
190 */
191 /*!
191 /*!
192 \qmlproperty Font AbstractAxis::title
192 \qmlproperty Font AbstractAxis::title
193 The font of the title of the axis.
193 The font of the title of the axis.
194 */
194 */
195
195
196 /*!
196 /*!
197 \property QAbstractAxis::title
197 \property QAbstractAxis::title
198 The title of the axis. Empty by default.
198 The title of the axis. Empty by default.
199 */
199 */
200 /*!
200 /*!
201 \qmlproperty string AbstractAxis::title
201 \qmlproperty string AbstractAxis::title
202 The title of the axis. Empty string by default.
202 The title of the axis. Empty string by default.
203 */
203 */
204
204
205 /*!
205 /*!
206 \property QAbstractAxis::alignment
206 \property QAbstractAxis::alignment
207 The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom.
207 The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom.
208 */
208 */
209 /*!
209 /*!
210 \qmlproperty alignment AbstractAxis::alignment
210 \qmlproperty alignment AbstractAxis::alignment
211 The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom.
211 The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom.
212 */
212 */
213
213
214 /*!
214 /*!
215 \fn void QAbstractAxis::visibleChanged(bool visible)
215 \fn void QAbstractAxis::visibleChanged(bool visible)
216 Visibility of the axis has changed to \a visible.
216 Visibility of the axis has changed to \a visible.
217 */
217 */
218 /*!
218 /*!
219 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
219 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
220 Visibility of the axis has changed to \a visible.
220 Visibility of the axis has changed to \a visible.
221 */
221 */
222
222
223 /*!
223 /*!
224 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
224 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
225 Visibility of the axis line has changed to \a visible.
225 Visibility of the axis line has changed to \a visible.
226 */
226 */
227 /*!
227 /*!
228 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
228 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
229 Visibility of the axis line has changed to \a visible.
229 Visibility of the axis line has changed to \a visible.
230 */
230 */
231
231
232 /*!
232 /*!
233 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
233 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
234 Visibility of the labels of the axis has changed to \a visible.
234 Visibility of the labels of the axis has changed to \a visible.
235 */
235 */
236 /*!
236 /*!
237 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
237 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
238 Visibility of the labels of the axis has changed to \a visible.
238 Visibility of the labels of the axis has changed to \a visible.
239 */
239 */
240
240
241 /*!
241 /*!
242 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
242 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
243 Visibility of the grid lines of the axis has changed to \a visible.
243 Visibility of the grid lines of the axis has changed to \a visible.
244 */
244 */
245 /*!
245 /*!
246 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
246 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
247 Visibility of the grid lines of the axis has changed to \a visible.
247 Visibility of the grid lines of the axis has changed to \a visible.
248 */
248 */
249
249
250 /*!
250 /*!
251 \fn void QAbstractAxis::colorChanged(QColor color)
251 \fn void QAbstractAxis::colorChanged(QColor color)
252 Emitted if the \a color of the axis is changed.
252 Emitted if the \a color of the axis is changed.
253 */
253 */
254 /*!
254 /*!
255 \qmlsignal AbstractAxis::onColorChanged(QColor color)
255 \qmlsignal AbstractAxis::onColorChanged(QColor color)
256 Emitted if the \a color of the axis is changed.
256 Emitted if the \a color of the axis is changed.
257 */
257 */
258
258
259 /*!
259 /*!
260 \fn void QAbstractAxis::labelsColorChanged(QColor color)
260 \fn void QAbstractAxis::labelsColorChanged(QColor color)
261 Emitted if the \a color of the axis labels is changed.
261 Emitted if the \a color of the axis labels is changed.
262 */
262 */
263 /*!
263 /*!
264 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
264 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
265 Emitted if the \a color of the axis labels is changed.
265 Emitted if the \a color of the axis labels is changed.
266 */
266 */
267
267
268 /*!
268 /*!
269 \fn void QAbstractAxis::shadesVisibleChanged(bool)
269 \fn void QAbstractAxis::shadesVisibleChanged(bool)
270 Emitted if the visibility of the axis shades is changed to \a visible.
270 Emitted if the visibility of the axis shades is changed to \a visible.
271 */
271 */
272 /*!
272 /*!
273 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
273 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
274 Emitted if the visibility of the axis shades is changed to \a visible.
274 Emitted if the visibility of the axis shades is changed to \a visible.
275 */
275 */
276
276
277 /*!
277 /*!
278 \fn void QAbstractAxis::shadesColorChanged(QColor color)
278 \fn void QAbstractAxis::shadesColorChanged(QColor color)
279 Emitted if the \a color of the axis shades is changed.
279 Emitted if the \a color of the axis shades is changed.
280 */
280 */
281 /*!
281 /*!
282 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
282 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
283 Emitted if the \a color of the axis shades is changed.
283 Emitted if the \a color of the axis shades is changed.
284 */
284 */
285
285
286 /*!
286 /*!
287 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
287 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
288 Emitted if the border \a color of the axis shades is changed.
288 Emitted if the border \a color of the axis shades is changed.
289 */
289 */
290 /*!
290 /*!
291 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
291 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
292 Emitted if the border \a color of the axis shades is changed.
292 Emitted if the border \a color of the axis shades is changed.
293 */
293 */
294
294
295 /*!
295 /*!
296 \internal
296 \internal
297 Constructs new axis object which is a child of \a parent. Ownership is taken by
297 Constructs new axis object which is a child of \a parent. Ownership is taken by
298 QChart when axis added.
298 QChart when axis added.
299 */
299 */
300
300
301 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
301 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
302 : QObject(parent),
302 : QObject(parent),
303 d_ptr(&d)
303 d_ptr(&d)
304 {
304 {
305 }
305 }
306
306
307 /*!
307 /*!
308 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
308 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
309 */
309 */
310
310
311 QAbstractAxis::~QAbstractAxis()
311 QAbstractAxis::~QAbstractAxis()
312 {
312 {
313 if (d_ptr->m_chart)
313 if (d_ptr->m_chart)
314 qFatal("Still binded axis detected !");
314 qFatal("Still binded axis detected !");
315 }
315 }
316
316
317 /*!
317 /*!
318 Sets \a pen used to draw axis line and ticks.
318 Sets \a pen used to draw axis line and ticks.
319 */
319 */
320 void QAbstractAxis::setLinePen(const QPen &pen)
320 void QAbstractAxis::setLinePen(const QPen &pen)
321 {
321 {
322 if (d_ptr->m_axisPen != pen) {
322 if (d_ptr->m_axisPen != pen) {
323 d_ptr->m_axisPen = pen;
323 d_ptr->m_axisPen = pen;
324 emit linePenChanged(pen);
324 emit linePenChanged(pen);
325 }
325 }
326 }
326 }
327
327
328 /*!
328 /*!
329 Returns pen used to draw axis and ticks.
329 Returns pen used to draw axis and ticks.
330 */
330 */
331 QPen QAbstractAxis::linePen() const
331 QPen QAbstractAxis::linePen() const
332 {
332 {
333 return d_ptr->m_axisPen;
333 return d_ptr->m_axisPen;
334 }
334 }
335
335
336 //TODO: remove me
336 //TODO: remove me
337 void QAbstractAxis::setLinePenColor(QColor color)
337 void QAbstractAxis::setLinePenColor(QColor color)
338 {
338 {
339 QPen p = d_ptr->m_axisPen;
339 QPen p = d_ptr->m_axisPen;
340 if (p.color() != color) {
340 if (p.color() != color) {
341 p.setColor(color);
341 p.setColor(color);
342 setLinePen(p);
342 setLinePen(p);
343 emit colorChanged(color);
343 emit colorChanged(color);
344 }
344 }
345 }
345 }
346
346
347 QColor QAbstractAxis::linePenColor() const
347 QColor QAbstractAxis::linePenColor() const
348 {
348 {
349 return d_ptr->m_axisPen.color();
349 return d_ptr->m_axisPen.color();
350 }
350 }
351
351
352 /*!
352 /*!
353 Sets if axis and ticks are \a visible.
353 Sets if axis and ticks are \a visible.
354 */
354 */
355 void QAbstractAxis::setLineVisible(bool visible)
355 void QAbstractAxis::setLineVisible(bool visible)
356 {
356 {
357 if (d_ptr->m_arrowVisible != visible) {
357 if (d_ptr->m_arrowVisible != visible) {
358 d_ptr->m_arrowVisible = visible;
358 d_ptr->m_arrowVisible = visible;
359 emit lineVisibleChanged(visible);
359 emit lineVisibleChanged(visible);
360 }
360 }
361 }
361 }
362
362
363 bool QAbstractAxis::isLineVisible() const
363 bool QAbstractAxis::isLineVisible() const
364 {
364 {
365 return d_ptr->m_arrowVisible;
365 return d_ptr->m_arrowVisible;
366 }
366 }
367
367
368 void QAbstractAxis::setGridLineVisible(bool visible)
368 void QAbstractAxis::setGridLineVisible(bool visible)
369 {
369 {
370 if (d_ptr->m_gridLineVisible != visible) {
370 if (d_ptr->m_gridLineVisible != visible) {
371 d_ptr->m_gridLineVisible = visible;
371 d_ptr->m_gridLineVisible = visible;
372 emit gridVisibleChanged(visible);
372 emit gridVisibleChanged(visible);
373 }
373 }
374 }
374 }
375
375
376 bool QAbstractAxis::isGridLineVisible() const
376 bool QAbstractAxis::isGridLineVisible() const
377 {
377 {
378 return d_ptr->m_gridLineVisible;
378 return d_ptr->m_gridLineVisible;
379 }
379 }
380
380
381 /*!
381 /*!
382 Sets \a pen used to draw grid line.
382 Sets \a pen used to draw grid line.
383 */
383 */
384 void QAbstractAxis::setGridLinePen(const QPen &pen)
384 void QAbstractAxis::setGridLinePen(const QPen &pen)
385 {
385 {
386 if (d_ptr->m_gridLinePen != pen) {
386 if (d_ptr->m_gridLinePen != pen) {
387 d_ptr->m_gridLinePen = pen;
387 d_ptr->m_gridLinePen = pen;
388 emit gridLinePenChanged(pen);
388 emit gridLinePenChanged(pen);
389 }
389 }
390 }
390 }
391
391
392 /*!
392 /*!
393 Returns pen used to draw grid.
393 Returns pen used to draw grid.
394 */
394 */
395 QPen QAbstractAxis::gridLinePen() const
395 QPen QAbstractAxis::gridLinePen() const
396 {
396 {
397 return d_ptr->m_gridLinePen;
397 return d_ptr->m_gridLinePen;
398 }
398 }
399
399
400 void QAbstractAxis::setLabelsVisible(bool visible)
400 void QAbstractAxis::setLabelsVisible(bool visible)
401 {
401 {
402 if (d_ptr->m_labelsVisible != visible) {
402 if (d_ptr->m_labelsVisible != visible) {
403 d_ptr->m_labelsVisible = visible;
403 d_ptr->m_labelsVisible = visible;
404 emit labelsVisibleChanged(visible);
404 emit labelsVisibleChanged(visible);
405 }
405 }
406 }
406 }
407
407
408 bool QAbstractAxis::labelsVisible() const
408 bool QAbstractAxis::labelsVisible() const
409 {
409 {
410 return d_ptr->m_labelsVisible;
410 return d_ptr->m_labelsVisible;
411 }
411 }
412
412
413 /*!
413 /*!
414 Sets \a pen used to draw labels.
414 Sets \a pen used to draw labels.
415 */
415 */
416 void QAbstractAxis::setLabelsPen(const QPen &pen)
416 void QAbstractAxis::setLabelsPen(const QPen &pen)
417 {
417 {
418 if (d_ptr->m_labelsPen != pen) {
418 if (d_ptr->m_labelsPen != pen) {
419 d_ptr->m_labelsPen = pen;
419 d_ptr->m_labelsPen = pen;
420 emit labelsPenChanged(pen);
420 emit labelsPenChanged(pen);
421 }
421 }
422 }
422 }
423
423
424 /*!
424 /*!
425 Returns the pen used to labels.
425 Returns the pen used to labels.
426 */
426 */
427 QPen QAbstractAxis::labelsPen() const
427 QPen QAbstractAxis::labelsPen() const
428 {
428 {
429 return d_ptr->m_labelsPen;
429 return d_ptr->m_labelsPen;
430 }
430 }
431
431
432 /*!
432 /*!
433 Sets \a brush used to draw labels.
433 Sets \a brush used to draw labels.
434 */
434 */
435 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
435 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
436 {
436 {
437 if (d_ptr->m_labelsBrush != brush) {
437 if (d_ptr->m_labelsBrush != brush) {
438 d_ptr->m_labelsBrush = brush;
438 d_ptr->m_labelsBrush = brush;
439 emit labelsBrushChanged(brush);
439 emit labelsBrushChanged(brush);
440 }
440 }
441 }
441 }
442
442
443 /*!
443 /*!
444 Returns brush used to draw labels.
444 Returns brush used to draw labels.
445 */
445 */
446 QBrush QAbstractAxis::labelsBrush() const
446 QBrush QAbstractAxis::labelsBrush() const
447 {
447 {
448 return d_ptr->m_labelsBrush;
448 return d_ptr->m_labelsBrush;
449 }
449 }
450
450
451 /*!
451 /*!
452 Sets \a font used to draw labels.
452 Sets \a font used to draw labels.
453 */
453 */
454 void QAbstractAxis::setLabelsFont(const QFont &font)
454 void QAbstractAxis::setLabelsFont(const QFont &font)
455 {
455 {
456 if (d_ptr->m_labelsFont != font) {
456 if (d_ptr->m_labelsFont != font) {
457 d_ptr->m_labelsFont = font;
457 d_ptr->m_labelsFont = font;
458 emit labelsFontChanged(font);
458 emit labelsFontChanged(font);
459 }
459 }
460 }
460 }
461
461
462 /*!
462 /*!
463 Returns font used to draw labels.
463 Returns font used to draw labels.
464 */
464 */
465 QFont QAbstractAxis::labelsFont() const
465 QFont QAbstractAxis::labelsFont() const
466 {
466 {
467 return d_ptr->m_labelsFont;
467 return d_ptr->m_labelsFont;
468 }
468 }
469
469
470 void QAbstractAxis::setLabelsAngle(int angle)
470 void QAbstractAxis::setLabelsAngle(int angle)
471 {
471 {
472 if (d_ptr->m_labelsAngle != angle) {
472 if (d_ptr->m_labelsAngle != angle) {
473 d_ptr->m_labelsAngle = angle;
473 d_ptr->m_labelsAngle = angle;
474 emit labelsAngleChanged(angle);
474 emit labelsAngleChanged(angle);
475 }
475 }
476 }
476 }
477
477
478 int QAbstractAxis::labelsAngle() const
478 int QAbstractAxis::labelsAngle() const
479 {
479 {
480 return d_ptr->m_labelsAngle;
480 return d_ptr->m_labelsAngle;
481 }
481 }
482 //TODO: remove me
482 //TODO: remove me
483 void QAbstractAxis::setLabelsColor(QColor color)
483 void QAbstractAxis::setLabelsColor(QColor color)
484 {
484 {
485 QBrush b = d_ptr->m_labelsBrush;
485 QBrush b = d_ptr->m_labelsBrush;
486 if (b.color() != color) {
486 if (b.color() != color) {
487 b.setColor(color);
487 b.setColor(color);
488 setLabelsBrush(b);
488 setLabelsBrush(b);
489 emit labelsColorChanged(color);
489 emit labelsColorChanged(color);
490 }
490 }
491 }
491 }
492
492
493 QColor QAbstractAxis::labelsColor() const
493 QColor QAbstractAxis::labelsColor() const
494 {
494 {
495 return d_ptr->m_labelsBrush.color();
495 return d_ptr->m_labelsBrush.color();
496 }
496 }
497
497
498 void QAbstractAxis::setTitleVisible(bool visible)
498 void QAbstractAxis::setTitleVisible(bool visible)
499 {
499 {
500 if (d_ptr->m_titleVisible != visible) {
500 if (d_ptr->m_titleVisible != visible) {
501 d_ptr->m_titleVisible = visible;
501 d_ptr->m_titleVisible = visible;
502 emit labelsVisibleChanged(visible);
502 emit labelsVisibleChanged(visible);
503 }
503 }
504 }
504 }
505
505
506 bool QAbstractAxis::titleVisible() const
506 bool QAbstractAxis::titleVisible() const
507 {
507 {
508 return d_ptr->m_titleVisible;
508 return d_ptr->m_titleVisible;
509 }
509 }
510
510
511 /*!
511 /*!
512 Sets \a pen used to draw title.
512 Sets \a pen used to draw title.
513 */
513 */
514 void QAbstractAxis::setTitlePen(const QPen &pen)
514 void QAbstractAxis::setTitlePen(const QPen &pen)
515 {
515 {
516 if (d_ptr->m_titlePen != pen) {
516 if (d_ptr->m_titlePen != pen) {
517 d_ptr->m_titlePen = pen;
517 d_ptr->m_titlePen = pen;
518 emit titlePenChanged(pen);
518 emit titlePenChanged(pen);
519 }
519 }
520 }
520 }
521
521
522 /*!
522 /*!
523 Returns the pen used to title.
523 Returns the pen used to title.
524 */
524 */
525 QPen QAbstractAxis::titlePen() const
525 QPen QAbstractAxis::titlePen() const
526 {
526 {
527 return d_ptr->m_titlePen;
527 return d_ptr->m_titlePen;
528 }
528 }
529
529
530 /*!
530 /*!
531 Sets \a brush used to draw title.
531 Sets \a brush used to draw title.
532 */
532 */
533 void QAbstractAxis::setTitleBrush(const QBrush &brush)
533 void QAbstractAxis::setTitleBrush(const QBrush &brush)
534 {
534 {
535 if (d_ptr->m_titleBrush != brush) {
535 if (d_ptr->m_titleBrush != brush) {
536 d_ptr->m_titleBrush = brush;
536 d_ptr->m_titleBrush = brush;
537 emit titleBrushChanged(brush);
537 emit titleBrushChanged(brush);
538 }
538 }
539 }
539 }
540
540
541 /*!
541 /*!
542 Returns brush used to draw title.
542 Returns brush used to draw title.
543 */
543 */
544 QBrush QAbstractAxis::titleBrush() const
544 QBrush QAbstractAxis::titleBrush() const
545 {
545 {
546 return d_ptr->m_titleBrush;
546 return d_ptr->m_titleBrush;
547 }
547 }
548
548
549 /*!
549 /*!
550 Sets \a font used to draw title.
550 Sets \a font used to draw title.
551 */
551 */
552 void QAbstractAxis::setTitleFont(const QFont &font)
552 void QAbstractAxis::setTitleFont(const QFont &font)
553 {
553 {
554 if (d_ptr->m_titleFont != font) {
554 if (d_ptr->m_titleFont != font) {
555 d_ptr->m_titleFont = font;
555 d_ptr->m_titleFont = font;
556 emit titleFontChanged(font);
556 emit titleFontChanged(font);
557 }
557 }
558 }
558 }
559
559
560 /*!
560 /*!
561 Returns font used to draw title.
561 Returns font used to draw title.
562 */
562 */
563 QFont QAbstractAxis::titleFont() const
563 QFont QAbstractAxis::titleFont() const
564 {
564 {
565 return d_ptr->m_titleFont;
565 return d_ptr->m_titleFont;
566 }
566 }
567
567
568 void QAbstractAxis::setTitleText(const QString &title)
568 void QAbstractAxis::setTitleText(const QString &title)
569 {
569 {
570 if (d_ptr->m_title != title) {
570 if (d_ptr->m_title != title) {
571 d_ptr->m_title = title;
571 d_ptr->m_title = title;
572 emit titleTextChanged(title);
572 emit titleTextChanged(title);
573 }
573 }
574 }
574 }
575
575
576 QString QAbstractAxis::titleText() const
576 QString QAbstractAxis::titleText() const
577 {
577 {
578 return d_ptr->m_title;
578 return d_ptr->m_title;
579 }
579 }
580
580
581
581
582 void QAbstractAxis::setShadesVisible(bool visible)
582 void QAbstractAxis::setShadesVisible(bool visible)
583 {
583 {
584 if (d_ptr->m_shadesVisible != visible) {
584 if (d_ptr->m_shadesVisible != visible) {
585 d_ptr->m_shadesVisible = visible;
585 d_ptr->m_shadesVisible = visible;
586 emit shadesVisibleChanged(visible);
586 emit shadesVisibleChanged(visible);
587 }
587 }
588 }
588 }
589
589
590 bool QAbstractAxis::shadesVisible() const
590 bool QAbstractAxis::shadesVisible() const
591 {
591 {
592 return d_ptr->m_shadesVisible;
592 return d_ptr->m_shadesVisible;
593 }
593 }
594
594
595 /*!
595 /*!
596 Sets \a pen used to draw shades.
596 Sets \a pen used to draw shades.
597 */
597 */
598 void QAbstractAxis::setShadesPen(const QPen &pen)
598 void QAbstractAxis::setShadesPen(const QPen &pen)
599 {
599 {
600 if (d_ptr->m_shadesPen != pen) {
600 if (d_ptr->m_shadesPen != pen) {
601 d_ptr->m_shadesPen = pen;
601 d_ptr->m_shadesPen = pen;
602 emit shadesPenChanged(pen);
602 emit shadesPenChanged(pen);
603 }
603 }
604 }
604 }
605
605
606 /*!
606 /*!
607 Returns pen used to draw shades.
607 Returns pen used to draw shades.
608 */
608 */
609 QPen QAbstractAxis::shadesPen() const
609 QPen QAbstractAxis::shadesPen() const
610 {
610 {
611 return d_ptr->m_shadesPen;
611 return d_ptr->m_shadesPen;
612 }
612 }
613
613
614 /*!
614 /*!
615 Sets \a brush used to draw shades.
615 Sets \a brush used to draw shades.
616 */
616 */
617 void QAbstractAxis::setShadesBrush(const QBrush &brush)
617 void QAbstractAxis::setShadesBrush(const QBrush &brush)
618 {
618 {
619 if (d_ptr->m_shadesBrush != brush) {
619 if (d_ptr->m_shadesBrush != brush) {
620 d_ptr->m_shadesBrush = brush;
620 d_ptr->m_shadesBrush = brush;
621 emit shadesBrushChanged(brush);
621 emit shadesBrushChanged(brush);
622 }
622 }
623 }
623 }
624
624
625 /*!
625 /*!
626 Returns brush used to draw shades.
626 Returns brush used to draw shades.
627 */
627 */
628 QBrush QAbstractAxis::shadesBrush() const
628 QBrush QAbstractAxis::shadesBrush() const
629 {
629 {
630 return d_ptr->m_shadesBrush;
630 return d_ptr->m_shadesBrush;
631 }
631 }
632
632
633 void QAbstractAxis::setShadesColor(QColor color)
633 void QAbstractAxis::setShadesColor(QColor color)
634 {
634 {
635 QBrush b = d_ptr->m_shadesBrush;
635 QBrush b = d_ptr->m_shadesBrush;
636 if (b.color() != color) {
636 if (b.color() != color) {
637 b.setColor(color);
637 b.setColor(color);
638 setShadesBrush(b);
638 setShadesBrush(b);
639 emit shadesColorChanged(color);
639 emit shadesColorChanged(color);
640 }
640 }
641 }
641 }
642
642
643 QColor QAbstractAxis::shadesColor() const
643 QColor QAbstractAxis::shadesColor() const
644 {
644 {
645 return d_ptr->m_shadesBrush.color();
645 return d_ptr->m_shadesBrush.color();
646 }
646 }
647
647
648 void QAbstractAxis::setShadesBorderColor(QColor color)
648 void QAbstractAxis::setShadesBorderColor(QColor color)
649 {
649 {
650 QPen p = d_ptr->m_shadesPen;
650 QPen p = d_ptr->m_shadesPen;
651 if (p.color() != color) {
651 if (p.color() != color) {
652 p.setColor(color);
652 p.setColor(color);
653 setShadesPen(p);
653 setShadesPen(p);
654 emit shadesColorChanged(color);
654 emit shadesColorChanged(color);
655 }
655 }
656 }
656 }
657
657
658 QColor QAbstractAxis::shadesBorderColor() const
658 QColor QAbstractAxis::shadesBorderColor() const
659 {
659 {
660 return d_ptr->m_shadesPen.color();
660 return d_ptr->m_shadesPen.color();
661 }
661 }
662
662
663
663
664 bool QAbstractAxis::isVisible() const
664 bool QAbstractAxis::isVisible() const
665 {
665 {
666 return d_ptr->m_visible;
666 return d_ptr->m_visible;
667 }
667 }
668
668
669 /*!
669 /*!
670 Sets axis, shades, labels and grid lines to be visible.
670 Sets axis, shades, labels and grid lines to be visible.
671 */
671 */
672 void QAbstractAxis::setVisible(bool visible)
672 void QAbstractAxis::setVisible(bool visible)
673 {
673 {
674 if (d_ptr->m_visible != visible) {
674 if (d_ptr->m_visible != visible) {
675 d_ptr->m_visible = visible;
675 d_ptr->m_visible = visible;
676 emit visibleChanged(visible);
676 emit visibleChanged(visible);
677 }
677 }
678 }
678 }
679
679
680
680
681 /*!
681 /*!
682 Sets axis, shades, labels and grid lines to be visible.
682 Sets axis, shades, labels and grid lines to be visible.
683 */
683 */
684 void QAbstractAxis::show()
684 void QAbstractAxis::show()
685 {
685 {
686 setVisible(true);
686 setVisible(true);
687 }
687 }
688
688
689 /*!
689 /*!
690 Sets axis, shades, labels and grid lines to not be visible.
690 Sets axis, shades, labels and grid lines to not be visible.
691 */
691 */
692 void QAbstractAxis::hide()
692 void QAbstractAxis::hide()
693 {
693 {
694 setVisible(false);
694 setVisible(false);
695 }
695 }
696
696
697 /*!
697 /*!
698 Sets the minimum value shown on the axis.
698 Sets the minimum value shown on the axis.
699 Depending on the actual axis type the \a min parameter is converted to appropriate type.
699 Depending on the actual axis type the \a min parameter is converted to appropriate type.
700 If the conversion is impossible then the function call does nothing
700 If the conversion is impossible then the function call does nothing
701 */
701 */
702 void QAbstractAxis::setMin(const QVariant &min)
702 void QAbstractAxis::setMin(const QVariant &min)
703 {
703 {
704 d_ptr->setMin(min);
704 d_ptr->setMin(min);
705 }
705 }
706
706
707 /*!
707 /*!
708 Sets the maximum value shown on the axis.
708 Sets the maximum value shown on the axis.
709 Depending on the actual axis type the \a max parameter is converted to appropriate type.
709 Depending on the actual axis type the \a max parameter is converted to appropriate type.
710 If the conversion is impossible then the function call does nothing
710 If the conversion is impossible then the function call does nothing
711 */
711 */
712 void QAbstractAxis::setMax(const QVariant &max)
712 void QAbstractAxis::setMax(const QVariant &max)
713 {
713 {
714 d_ptr->setMax(max);
714 d_ptr->setMax(max);
715 }
715 }
716
716
717 /*!
717 /*!
718 Sets the range shown on the axis.
718 Sets the range shown on the axis.
719 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
719 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
720 If the conversion is impossible then the function call does nothing.
720 If the conversion is impossible then the function call does nothing.
721 */
721 */
722 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
722 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
723 {
723 {
724 d_ptr->setRange(min, max);
724 d_ptr->setRange(min, max);
725 }
725 }
726
726
727
727
728 /*!
728 /*!
729 Returns the orientation in which the axis is being used (Vertical or Horizontal)
729 Returns the orientation in which the axis is being used (Vertical or Horizontal)
730 */
730 */
731 // NOTE: should have const but it breaks BC:
731 // NOTE: should have const but it breaks BC:
732 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
732 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
733 Qt::Orientation QAbstractAxis::orientation()
733 Qt::Orientation QAbstractAxis::orientation()
734 {
734 {
735 return d_ptr->orientation();
735 return d_ptr->orientation();
736 }
736 }
737
737
738 Qt::Alignment QAbstractAxis::alignment() const
738 Qt::Alignment QAbstractAxis::alignment() const
739 {
739 {
740 return d_ptr->alignment();
740 return d_ptr->alignment();
741 }
741 }
742
742
743 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
743 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
744
744
745 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
745 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
746 : q_ptr(q),
746 : q_ptr(q),
747 m_chart(0),
747 m_chart(0),
748 m_orientation(Qt::Orientation(0)),
748 m_orientation(Qt::Orientation(0)),
749 m_alignment(0),
749 m_alignment(0),
750 m_visible(true),
750 m_visible(true),
751 m_arrowVisible(true),
751 m_arrowVisible(true),
752 m_gridLineVisible(true),
752 m_gridLineVisible(true),
753 m_labelsVisible(true),
753 m_labelsVisible(true),
754 m_labelsAngle(0),
754 m_labelsAngle(0),
755 m_shadesVisible(false),
755 m_shadesVisible(false),
756 m_shadesBrush(Qt::SolidPattern),
756 m_shadesBrush(Qt::SolidPattern),
757 m_shadesOpacity(1.0),
757 m_shadesOpacity(1.0),
758 m_dirty(false)
758 m_dirty(false)
759 {
759 {
760
760
761 }
761 }
762
762
763 QAbstractAxisPrivate::~QAbstractAxisPrivate()
763 QAbstractAxisPrivate::~QAbstractAxisPrivate()
764 {
764 {
765 }
765 }
766
766
767 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
767 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
768 {
768 {
769 switch(alignment) {
769 switch(alignment) {
770 case Qt::AlignTop:
770 case Qt::AlignTop:
771 case Qt::AlignBottom:
771 case Qt::AlignBottom:
772 m_orientation = Qt::Horizontal;
772 m_orientation = Qt::Horizontal;
773 break;
773 break;
774 case Qt::AlignLeft:
774 case Qt::AlignLeft:
775 case Qt::AlignRight:
775 case Qt::AlignRight:
776 m_orientation = Qt::Vertical;
776 m_orientation = Qt::Vertical;
777 break;
777 break;
778 default:
778 default:
779 qWarning()<<"No alignment specified !";
779 qWarning()<<"No alignment specified !";
780 break;
780 break;
781 };
781 };
782 m_alignment=alignment;
782 m_alignment=alignment;
783 }
783 }
784
784
785 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
785 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
786 {
786 {
787 QPen pen;
787 QPen pen;
788 QBrush brush;
788 QBrush brush;
789 QFont font;
789 QFont font;
790
790
791 bool axisX = m_orientation == Qt::Horizontal;
791 bool axisX = m_orientation == Qt::Horizontal;
792
792
793 if (m_arrowVisible) {
793 if (m_arrowVisible) {
794
794
795 if (forced || brush == m_labelsBrush){
795 if (forced || brush == m_labelsBrush){
796 q_ptr->setLabelsBrush(theme->labelBrush());
796 q_ptr->setLabelsBrush(theme->labelBrush());
797 }
797 }
798 //TODO: introduce axis brush
798 //TODO: introduce axis brush
799 if (forced || brush == m_titleBrush){
799 if (forced || brush == m_titleBrush){
800 q_ptr->setTitleBrush(theme->labelBrush());
800 q_ptr->setTitleBrush(theme->labelBrush());
801 }
801 }
802 if (forced || pen == m_labelsPen){
802 if (forced || pen == m_labelsPen){
803 q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons
803 q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons
804 }
804 }
805 if (forced || pen == m_titlePen){
805 if (forced || pen == m_titlePen){
806 q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons
806 q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons
807 }
807 }
808 if (forced || m_shadesVisible) {
808 if (forced || m_shadesVisible) {
809
809
810 if (forced || brush == m_shadesBrush){
810 if (forced || brush == m_shadesBrush){
811 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
811 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
812 }
812 }
813 if (forced || pen == m_shadesPen){
813 if (forced || pen == m_shadesPen){
814 q_ptr->setShadesPen(theme->backgroundShadesPen());
814 q_ptr->setShadesPen(theme->backgroundShadesPen());
815 }
815 }
816 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
816 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
817 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
817 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
818 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
818 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
819 q_ptr->setShadesVisible(true);
819 q_ptr->setShadesVisible(true);
820 }
820 }
821 }
821 }
822
822
823 if (forced || pen == m_axisPen) {
823 if (forced || pen == m_axisPen) {
824 q_ptr->setLinePen(theme->axisLinePen());
824 q_ptr->setLinePen(theme->axisLinePen());
825 }
825 }
826
826
827 if (forced || pen == m_gridLinePen) {
827 if (forced || pen == m_gridLinePen) {
828 q_ptr->setGridLinePen(theme->girdLinePen());
828 q_ptr->setGridLinePen(theme->girdLinePen());
829 }
829 }
830
830
831 if (forced || font == m_labelsFont){
831 if (forced || font == m_labelsFont){
832 q_ptr->setLabelsFont(theme->labelFont());
832 q_ptr->setLabelsFont(theme->labelFont());
833 }
833 }
834 //TODO: discuss with Tero
834 //TODO: discuss with Tero
835 if (forced || font == m_titleFont){
835 if (forced || font == m_titleFont){
836 QFont font(m_labelsFont);
836 QFont font(m_labelsFont);
837 font.setBold(true);
837 font.setBold(true);
838 q_ptr->setTitleFont(font);
838 q_ptr->setTitleFont(font);
839 }
839 }
840 }
840 }
841 }
841 }
842
842
843 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
843 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
844 {
844 {
845 setRange(min,max);
845 setRange(min,max);
846 }
846 }
847
847
848 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
848 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
849 {
849 {
850 Q_UNUSED(parent);
850 Q_UNUSED(parent);
851 }
851 }
852
852
853 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
853 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
854 {
854 {
855 ChartAxis* axis = m_item.data();
855 ChartAxis* axis = m_item.data();
856 Q_ASSERT(axis);
856 Q_ASSERT(axis);
857 if(options.testFlag(QChart::GridAxisAnimations)) {
857 if(options.testFlag(QChart::GridAxisAnimations)) {
858 axis->setAnimation(new AxisAnimation(axis));
858 axis->setAnimation(new AxisAnimation(axis));
859 }else{
859 }else{
860 axis->setAnimation(0);
860 axis->setAnimation(0);
861 }
861 }
862 }
862 }
863
863
864
864
865
865 #include "moc_qabstractaxis.cpp"
866 #include "moc_qabstractaxis.cpp"
866 #include "moc_qabstractaxis_p.cpp"
867 #include "moc_qabstractaxis_p.cpp"
867
868
868 QTCOMMERCIALCHART_END_NAMESPACE
869 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,196 +1,197
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QABSTRACTAXIS_H
21 #ifndef QABSTRACTAXIS_H
22 #define QABSTRACTAXIS_H
22 #define QABSTRACTAXIS_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QPen>
25 #include <QPen>
26 #include <QFont>
26 #include <QFont>
27 #include <QVariant>
27 #include <QVariant>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QAbstractAxisPrivate;
31 class QAbstractAxisPrivate;
32
32
33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 //visibility
36 //visibility
37 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
37 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
38 //arrow
38 //arrow
39 Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged)
39 Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged)
40 Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged)
40 Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged)
41 //TODO: make wrapping of color for qml
41 //TODO: make wrapping of color for qml
42 Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged)
42 Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged)
43 //labels
43 //labels
44 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
44 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
45 Q_PROPERTY(QPen lablesPen READ labelsPen WRITE setLabelsPen NOTIFY labelsPenChanged)
45 Q_PROPERTY(QPen lablesPen READ labelsPen WRITE setLabelsPen NOTIFY labelsPenChanged)
46 Q_PROPERTY(QBrush lablesBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged)
46 Q_PROPERTY(QBrush lablesBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged)
47 //TODO: fix labels angles to work with layout
47 //TODO: fix labels angles to work with layout
48 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged)
48 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged)
49 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged)
49 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged)
50 //TODO: make wrapping of color for qml
50 //TODO: make wrapping of color for qml
51 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
51 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
52 //grid
52 //grid
53 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
53 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
54 Q_PROPERTY(QPen girdLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged)
54 Q_PROPERTY(QPen girdLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged)
55 //shades
55 //shades
56 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
56 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
57 //TODO: make wrapping of color for qml
57 //TODO: make wrapping of color for qml
58 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
58 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
59 //TODO: make wrapping of border for qml
59 //TODO: make wrapping of border for qml
60 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
60 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
61 Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged)
61 Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged)
62 Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged)
62 Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged)
63 //title
63 //title
64 Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged)
64 Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged)
65 Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged)
65 Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged)
66 Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged)
66 Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged)
67 Q_PROPERTY(bool titleVisible READ titleVisible WRITE setTitleVisible)
67 Q_PROPERTY(bool titleVisible READ titleVisible WRITE setTitleVisible)
68 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
68 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
69 //orientation
69 //orientation
70 Q_PROPERTY(Qt::Orientation orinetation READ orientation)
70 Q_PROPERTY(Qt::Orientation orinetation READ orientation)
71 //aligment
71 //aligment
72 Q_PROPERTY(Qt::Alignment alignment READ alignment)
72 Q_PROPERTY(Qt::Alignment alignment READ alignment)
73
73
74 public:
74 public:
75
75
76 enum AxisType {
76 enum AxisType {
77 AxisTypeNoAxis = 0x0,
77 AxisTypeNoAxis = 0x0,
78 AxisTypeValue = 0x1,
78 AxisTypeValue = 0x1,
79 AxisTypeBarCategory = 0x2,
79 AxisTypeBarCategory = 0x2,
80 AxisTypeCategory = 0x3,
80 AxisTypeCategory = 0x3,
81 AxisTypeDateTime = 0x4,
81 AxisTypeDateTime = 0x4,
82 AxisTypeLogValue = 0x5
82 AxisTypeLogValue = 0x5
83 };
83 };
84
84
85 Q_DECLARE_FLAGS(AxisTypes, AxisType)
85 Q_DECLARE_FLAGS(AxisTypes, AxisType)
86
86
87 protected:
87 protected:
88 explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = 0);
88 explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = 0);
89
89
90 public:
90 public:
91 ~QAbstractAxis();
91 ~QAbstractAxis();
92
92
93 virtual AxisType type() const = 0;
93 virtual AxisType type() const = 0;
94
94
95 //visibility handling
95 //visibility handling
96 bool isVisible() const;
96 bool isVisible() const;
97 void setVisible(bool visible = true);
97 void setVisible(bool visible = true);
98 void show();
98 void show();
99 void hide();
99 void hide();
100
100
101 //arrow handling
101 //arrow handling
102 bool isLineVisible() const;
102 bool isLineVisible() const;
103 void setLineVisible(bool visible = true);
103 void setLineVisible(bool visible = true);
104 void setLinePen(const QPen &pen);
104 void setLinePen(const QPen &pen);
105 QPen linePen() const;
105 QPen linePen() const;
106 void setLinePenColor(QColor color);
106 void setLinePenColor(QColor color);
107 QColor linePenColor() const;
107 QColor linePenColor() const;
108
108
109 //grid handling
109 //grid handling
110 bool isGridLineVisible() const;
110 bool isGridLineVisible() const;
111 void setGridLineVisible(bool visible = true);
111 void setGridLineVisible(bool visible = true);
112 void setGridLinePen(const QPen &pen);
112 void setGridLinePen(const QPen &pen);
113 QPen gridLinePen() const;
113 QPen gridLinePen() const;
114
114
115 //labels handling
115 //labels handling
116 bool labelsVisible() const;
116 bool labelsVisible() const;
117 void setLabelsVisible(bool visible = true);
117 void setLabelsVisible(bool visible = true);
118 void setLabelsPen(const QPen &pen);
118 void setLabelsPen(const QPen &pen);
119 QPen labelsPen() const;
119 QPen labelsPen() const;
120 void setLabelsBrush(const QBrush &brush);
120 void setLabelsBrush(const QBrush &brush);
121 QBrush labelsBrush() const;
121 QBrush labelsBrush() const;
122 void setLabelsFont(const QFont &font);
122 void setLabelsFont(const QFont &font);
123 QFont labelsFont() const;
123 QFont labelsFont() const;
124 void setLabelsAngle(int angle);
124 void setLabelsAngle(int angle);
125 int labelsAngle() const;
125 int labelsAngle() const;
126 void setLabelsColor(QColor color);
126 void setLabelsColor(QColor color);
127 QColor labelsColor() const;
127 QColor labelsColor() const;
128
128
129 //title handling
129 //title handling
130 bool titleVisible() const;
130 bool titleVisible() const;
131 void setTitleVisible(bool visible = true);
131 void setTitleVisible(bool visible = true);
132 void setTitlePen(const QPen &pen);
132 void setTitlePen(const QPen &pen);
133 QPen titlePen() const;
133 QPen titlePen() const;
134 void setTitleBrush(const QBrush &brush);
134 void setTitleBrush(const QBrush &brush);
135 QBrush titleBrush() const;
135 QBrush titleBrush() const;
136 void setTitleFont(const QFont &font);
136 void setTitleFont(const QFont &font);
137 QFont titleFont() const;
137 QFont titleFont() const;
138 void setTitleText(const QString &title);
138 void setTitleText(const QString &title);
139 QString titleText() const;
139 QString titleText() const;
140
140
141 //shades handling
141 //shades handling
142 bool shadesVisible() const;
142 bool shadesVisible() const;
143 void setShadesVisible(bool visible = true);
143 void setShadesVisible(bool visible = true);
144 void setShadesPen(const QPen &pen);
144 void setShadesPen(const QPen &pen);
145 QPen shadesPen() const;
145 QPen shadesPen() const;
146 void setShadesBrush(const QBrush &brush);
146 void setShadesBrush(const QBrush &brush);
147 QBrush shadesBrush() const;
147 QBrush shadesBrush() const;
148 void setShadesColor(QColor color);
148 void setShadesColor(QColor color);
149 QColor shadesColor() const;
149 QColor shadesColor() const;
150 void setShadesBorderColor(QColor color);
150 void setShadesBorderColor(QColor color);
151 QColor shadesBorderColor() const;
151 QColor shadesBorderColor() const;
152
152
153 Qt::Orientation orientation(); //TODO: missing const <- BC
153 Qt::Orientation orientation(); //TODO: missing const <- BC
154 Qt::Alignment alignment() const;
154 Qt::Alignment alignment() const;
155
155
156 //range handling
156 //range handling
157 void setMin(const QVariant &min);
157 void setMin(const QVariant &min);
158 void setMax(const QVariant &max);
158 void setMax(const QVariant &max);
159 void setRange(const QVariant &min, const QVariant &max);
159 void setRange(const QVariant &min, const QVariant &max);
160
160
161 Q_SIGNALS:
161 Q_SIGNALS:
162 void visibleChanged(bool visible);
162 void visibleChanged(bool visible);
163 void linePenChanged(const QPen& pen);
163 void linePenChanged(const QPen& pen);
164 void lineVisibleChanged(bool visible);
164 void lineVisibleChanged(bool visible);
165 void labelsVisibleChanged(bool visible);
165 void labelsVisibleChanged(bool visible);
166 void labelsPenChanged(const QPen& pen);
166 void labelsPenChanged(const QPen& pen);
167 void labelsBrushChanged(const QBrush& brush);
167 void labelsBrushChanged(const QBrush& brush);
168 void labelsFontChanged(const QFont& pen);
168 void labelsFontChanged(const QFont& pen);
169 void labelsAngleChanged(int angle);
169 void labelsAngleChanged(int angle);
170 void gridLinePenChanged(const QPen& pen);
170 void gridLinePenChanged(const QPen& pen);
171 void gridVisibleChanged(bool visible);
171 void gridVisibleChanged(bool visible);
172 void colorChanged(QColor color);
172 void colorChanged(QColor color);
173 void labelsColorChanged(QColor color);
173 void labelsColorChanged(QColor color);
174 void titleTextChanged(const QString& title);
174 void titleTextChanged(const QString& title);
175 void titlePenChanged(const QPen& pen);
175 void titlePenChanged(const QPen& pen);
176 void titleBrushChanged(const QBrush brush);
176 void titleBrushChanged(const QBrush brush);
177 void titleVisibleChanged(bool visible);
177 void titleVisibleChanged(bool visible);
178 void titleFontChanged(const QFont& font);
178 void titleFontChanged(const QFont& font);
179 void shadesVisibleChanged(bool visible);
179 void shadesVisibleChanged(bool visible);
180 void shadesColorChanged(QColor color);
180 void shadesColorChanged(QColor color);
181 void shadesBorderColorChanged(QColor color);
181 void shadesBorderColorChanged(QColor color);
182 void shadesPenChanged(const QPen& pen);
182 void shadesPenChanged(const QPen& pen);
183 void shadesBrushChanged(const QBrush brush);
183 void shadesBrushChanged(const QBrush brush);
184
184
185 protected:
185 protected:
186 QScopedPointer<QAbstractAxisPrivate> d_ptr;
186 QScopedPointer<QAbstractAxisPrivate> d_ptr;
187 Q_DISABLE_COPY(QAbstractAxis)
187 Q_DISABLE_COPY(QAbstractAxis)
188 friend class ChartDataSet;
188 friend class ChartDataSet;
189 friend class ChartAxis;
189 friend class ChartAxis;
190 friend class ChartPresenter;
190 friend class ChartPresenter;
191 friend class ChartThemeManager;
191 friend class ChartThemeManager;
192 friend class AbstractDomain;
192 };
193 };
193
194
194 QTCOMMERCIALCHART_END_NAMESPACE
195 QTCOMMERCIALCHART_END_NAMESPACE
195
196
196 #endif // QABSTRACTAXIS_H
197 #endif // QABSTRACTAXIS_H
@@ -1,410 +1,471
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 "chartdataset_p.h"
21 #include "chartdataset_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qchart_p.h"
24 #include "qchart_p.h"
25 #include "qvalueaxis.h"
25 #include "qvalueaxis.h"
26 #include "qbarcategoryaxis.h"
26 #include "qbarcategoryaxis.h"
27 #include "qvalueaxis_p.h"
27 #include "qvalueaxis_p.h"
28 #include "qcategoryaxis.h"
28 #include "qcategoryaxis.h"
29 #include "qabstractseries_p.h"
29 #include "qabstractseries_p.h"
30 #include "qabstractbarseries.h"
30 #include "qabstractbarseries.h"
31 #include "qstackedbarseries.h"
31 #include "qstackedbarseries.h"
32 #include "qpercentbarseries.h"
32 #include "qpercentbarseries.h"
33 #include "qpieseries.h"
33 #include "qpieseries.h"
34 #include "chartitem_p.h"
34 #include "chartitem_p.h"
35 #include "xydomain_p.h"
35 #include "xydomain_p.h"
36 #include "xlogydomain_p.h"
36 #include "xlogydomain_p.h"
37 #include "logxydomain_p.h"
37 #include "logxydomain_p.h"
38 #include "logxlogydomain_p.h"
38 #include "logxlogydomain_p.h"
39
39
40 #ifndef QT_ON_ARM
40 #ifndef QT_ON_ARM
41 #include "qdatetimeaxis.h"
41 #include "qdatetimeaxis.h"
42 #endif
42 #endif
43
43
44 QTCOMMERCIALCHART_BEGIN_NAMESPACE
44 QTCOMMERCIALCHART_BEGIN_NAMESPACE
45
45
46 ChartDataSet::ChartDataSet(QChart *chart)
46 ChartDataSet::ChartDataSet(QChart *chart)
47 : QObject(chart),
47 : QObject(chart),
48 m_chart(chart)
48 m_chart(chart)
49 {
49 {
50
50
51 }
51 }
52
52
53 ChartDataSet::~ChartDataSet()
53 ChartDataSet::~ChartDataSet()
54 {
54 {
55 removeAllSeries();
55 deleteAllSeries();
56 removeAllAxes();
56 deleteAllAxes();
57 }
57 }
58
58
59 /*
59 /*
60 * This method adds series to chartdataset, series ownership is taken from caller.
60 * This method adds series to chartdataset, series ownership is taken from caller.
61 */
61 */
62 void ChartDataSet::addSeries(QAbstractSeries *series)
62 void ChartDataSet::addSeries(QAbstractSeries *series)
63 {
63 {
64 if (m_seriesList.contains(series)) {
64 if (m_seriesList.contains(series)) {
65 qWarning() << QObject::tr("Can not add series. Series already on the chart.");
65 qWarning() << QObject::tr("Can not add series. Series already on the chart.");
66 return;
66 return;
67 }
67 }
68
68
69 series->d_ptr->initializeDomain();
69 series->d_ptr->initializeDomain();
70 m_seriesList.append(series);
70 m_seriesList.append(series);
71
71
72 series->setParent(this); // take ownership
72 series->setParent(this); // take ownership
73 series->d_ptr->m_chart = m_chart;
73 series->d_ptr->m_chart = m_chart;
74
74
75 emit seriesAdded(series);
75 emit seriesAdded(series);
76 }
76 }
77
77
78 /*
78 /*
79 * This method adds axis to chartdataset, axis ownership is taken from caller.
79 * This method adds axis to chartdataset, axis ownership is taken from caller.
80 */
80 */
81 void ChartDataSet::addAxis(QAbstractAxis *axis,Qt::Alignment aligment)
81 void ChartDataSet::addAxis(QAbstractAxis *axis,Qt::Alignment aligment)
82 {
82 {
83 if (m_axisList.contains(axis)) {
83 if (m_axisList.contains(axis)) {
84 qWarning() << QObject::tr("Can not add axis. Axis already on the chart.");
84 qWarning() << QObject::tr("Can not add axis. Axis already on the chart.");
85 return;
85 return;
86 }
86 }
87
87
88 axis->d_ptr->setAlignment(aligment);
88 axis->d_ptr->setAlignment(aligment);
89
89
90 if(!axis->alignment()) {
90 if(!axis->alignment()) {
91 qWarning()<< QObject::tr("No alignment specified !");
91 qWarning()<< QObject::tr("No alignment specified !");
92 return;
92 return;
93 };
93 };
94
94
95 QSharedPointer<AbstractDomain> domain(new XYDomain());
95 QSharedPointer<AbstractDomain> domain(new XYDomain());
96 axis->d_ptr->initializeDomain(domain.data());
96 axis->d_ptr->initializeDomain(domain.data());
97
97
98 axis->setParent(this);
98 axis->setParent(this);
99 axis->d_ptr->m_chart = m_chart;
99 axis->d_ptr->m_chart = m_chart;
100 m_axisList.append(axis);
100 m_axisList.append(axis);
101
101
102 emit axisAdded(axis);
102 emit axisAdded(axis);
103 }
103 }
104
104
105 /*
105 /*
106 * This method removes series form chartdataset, series ownership is passed back to caller.
106 * This method removes series form chartdataset, series ownership is passed back to caller.
107 */
107 */
108 void ChartDataSet::removeSeries(QAbstractSeries *series)
108 void ChartDataSet::removeSeries(QAbstractSeries *series)
109 {
109 {
110
110
111 if (! m_seriesList.contains(series)) {
111 if (! m_seriesList.contains(series)) {
112 qWarning() << QObject::tr("Can not remove series. Series not found on the chart.");
112 qWarning() << QObject::tr("Can not remove series. Series not found on the chart.");
113 return;
113 return;
114 }
114 }
115
115
116 emit seriesRemoved(series);
116 emit seriesRemoved(series);
117 m_seriesList.removeAll(series);
117 m_seriesList.removeAll(series);
118
118
119 series->setParent(0);
119 series->setParent(0);
120 series->d_ptr->m_chart = 0;
120 series->d_ptr->m_chart = 0;
121 series->d_ptr->m_domain.clear();
121 series->d_ptr->m_domain.clear();
122
122
123 QList<QAbstractAxis*> axes = series->d_ptr->m_axes;
123 QList<QAbstractAxis*> axes = series->d_ptr->m_axes;
124
124
125 foreach(QAbstractAxis* axis, axes) {
125 foreach(QAbstractAxis* axis, axes) {
126 axis->d_ptr->m_series.removeAll(series);
126 axis->d_ptr->m_series.removeAll(series);
127 series->d_ptr->m_axes.removeAll(axis);
127 series->d_ptr->m_axes.removeAll(axis);
128 }
128 }
129
129 }
130 }
130
131
131 /*
132 /*
132 * This method removes axis form chartdataset, series ownership is passed back to caller.
133 * This method removes axis form chartdataset, series ownership is passed back to caller.
133 */
134 */
134 void ChartDataSet::removeAxis(QAbstractAxis *axis)
135 void ChartDataSet::removeAxis(QAbstractAxis *axis)
135 {
136 {
136 if (! m_axisList.contains(axis)) {
137 if (! m_axisList.contains(axis)) {
137 qWarning() << QObject::tr("Can not remove axis. Axis not found on the chart.");
138 qWarning() << QObject::tr("Can not remove axis. Axis not found on the chart.");
138 return;
139 return;
139 }
140 }
140
141
141 emit axisRemoved(axis);
142 emit axisRemoved(axis);
142 m_axisList.removeAll(axis);
143 m_axisList.removeAll(axis);
143
144
144 axis->setParent(0);
145 axis->setParent(0);
145 axis->d_ptr->m_chart = 0;
146 axis->d_ptr->m_chart = 0;
146
147
147 QList<QAbstractSeries*> series = axis->d_ptr->m_series;
148 QList<QAbstractSeries*> series = axis->d_ptr->m_series;
148
149
149 foreach(QAbstractSeries* s, series) {
150 foreach(QAbstractSeries* s, series) {
150 s->d_ptr->m_axes.removeAll(axis);
151 s->d_ptr->m_axes.removeAll(axis);
151 axis->d_ptr->m_series.removeAll(s);
152 axis->d_ptr->m_series.removeAll(s);
152 }
153 }
153 }
154 }
154
155
155 /*
156 /*
156 * This method attach axis to series, return true if success.
157 * This method attaches axis to series, return true if success.
157 */
158 */
158 bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis)
159 bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis)
159 {
160 {
160 Q_ASSERT(series);
161 Q_ASSERT(series);
161 Q_ASSERT(axis);
162 Q_ASSERT(axis);
162
163
163 QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series;
164 QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series;
164 QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes;
165 QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes;
165 QSharedPointer<AbstractDomain> domain = series->d_ptr->m_domain;
166
166
167 if (!m_seriesList.contains(series)) {
167 if (!m_seriesList.contains(series)) {
168 qWarning() << QObject::tr("Can not find series on the chart.");
168 qWarning() << QObject::tr("Can not find series on the chart.");
169 return false;
169 return false;
170 }
170 }
171
171
172 if (axis && !m_axisList.contains(axis)) {
172 if (axis && !m_axisList.contains(axis)) {
173 qWarning() << QObject::tr("Can not find axis on the chart.");
173 qWarning() << QObject::tr("Can not find axis on the chart.");
174 return false;
174 return false;
175 }
175 }
176
176
177 if (attachedAxisList.contains(axis)) {
177 if (attachedAxisList.contains(axis)) {
178 qWarning() << QObject::tr("Axis already attached to series.");
178 qWarning() << QObject::tr("Axis already attached to series.");
179 return false;
179 return false;
180 }
180 }
181
181
182 Q_ASSERT(!attachedSeriesList.contains(series));
182 if (attachedSeriesList.contains(series)) {
183 Q_ASSERT(!domain.isNull());
183 qWarning() << QObject::tr("Axis already attached to series.");
184 return false;
185 }
186
187 QSharedPointer<AbstractDomain> domain = series->d_ptr->domain();
188 AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis);
189
190 if(type == AbstractDomain::UndefinedDomain) return false;
184
191
185 if(attachedSeriesList.isEmpty()){
186
192
187 }else{
193 if(domain->type()!=type){
188 domain = attachedSeriesList.first()->d_ptr->domain();
194 domain = QSharedPointer<AbstractDomain>(createDomain(type));
189 Q_ASSERT(!domain.isNull());
190 series->d_ptr->setDomain(domain);
191 }
195 }
192
196
197 if(domain.isNull()) return false;
198
199 if(!domain->attachAxis(axis)) return false;
200
193 series->d_ptr->m_axes<<axis;
201 series->d_ptr->m_axes<<axis;
194 axis->d_ptr->m_series<<series;
202 axis->d_ptr->m_series<<series;
195
203
204 series->d_ptr->setDomain(domain);
205 series->d_ptr->initializeDomain();
196 series->d_ptr->initializeAxes();
206 series->d_ptr->initializeAxes();
197 axis->d_ptr->initializeDomain(domain.data());
207 axis->d_ptr->initializeDomain(domain.data());
198
208
199 if(axis->orientation()==Qt::Vertical){
209 if(attachedSeriesList.count()>0 && attachedAxisList.count()>0){
200 QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleVerticalAxisRangeChanged(qreal,qreal)));
210 //TODO optimatization: joinDomain(attachedAxisList, attachedSeriesList);
201 QObject::connect(domain.data(), SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
202 }
203
204 if(axis->orientation()==Qt::Horizontal){
205 QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleHorizontalAxisRangeChanged(qreal,qreal)));
206 QObject::connect(domain.data(), SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
207 }
211 }
208
212
209 return true;
213 return true;
210 }
214 }
211
215
212 /*
216 /*
213 * This method detach axis to series, return true if success.
217 * This method detaches axis to series, return true if success.
214 */
218 */
215 bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis)
219 bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis)
216 {
220 {
217 Q_ASSERT(series);
221 Q_ASSERT(series);
218 Q_ASSERT(axis);
222 Q_ASSERT(axis);
219
223
220 QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series;
224 QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series;
221 QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes;
225 QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes;
222 QSharedPointer<AbstractDomain> domain = series->d_ptr->m_domain;
226 QSharedPointer<AbstractDomain> domain = series->d_ptr->m_domain;
223
227
224 if (!m_seriesList.contains(series)) {
228 if (!m_seriesList.contains(series)) {
225 qWarning() << QObject::tr("Can not find series on the chart.");
229 qWarning() << QObject::tr("Can not find series on the chart.");
226 return false;
230 return false;
227 }
231 }
228
232
229 if (axis && !m_axisList.contains(axis)) {
233 if (axis && !m_axisList.contains(axis)) {
230 qWarning() << QObject::tr("Can not find axis on the chart.");
234 qWarning() << QObject::tr("Can not find axis on the chart.");
231 return false;
235 return false;
232 }
236 }
233
237
234 if (!attachedAxisList.contains(axis)) {
238 if (!attachedAxisList.contains(axis)) {
235 qWarning() << QObject::tr("Axis not attached to series.");
239 qWarning() << QObject::tr("Axis not attached to series.");
236 return false;
240 return false;
237 }
241 }
238
242
239 Q_ASSERT(axis->d_ptr->m_series.contains(series));
243 Q_ASSERT(axis->d_ptr->m_series.contains(series));
240
244
245 domain->detachAxis(axis);
241 series->d_ptr->m_axes.removeAll(axis);
246 series->d_ptr->m_axes.removeAll(axis);
242 axis->d_ptr->m_series.removeAll(series);
247 axis->d_ptr->m_series.removeAll(series);
243
248
244 if(axis->orientation()==Qt::Vertical){
245 QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleVerticalAxisRangeChanged(qreal,qreal)));
246 QObject::disconnect(domain.data(), SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
247 }
248
249 if(axis->orientation()==Qt::Horizontal){
250 QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleHorizontalAxisRangeChanged(qreal,qreal)));
251 QObject::disconnect(domain.data(), SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
252 }
253
254 return true;
249 return true;
255 }
250 }
256
251
257 void ChartDataSet::createDefaultAxes()
252 void ChartDataSet::createDefaultAxes()
258 {
253 {
259 if (m_seriesList.isEmpty())
254 if (m_seriesList.isEmpty())
260 return;
255 return;
261
256
262 QAbstractAxis::AxisTypes typeX(0);
257 QAbstractAxis::AxisTypes typeX(0);
263 QAbstractAxis::AxisTypes typeY(0);
258 QAbstractAxis::AxisTypes typeY(0);
264
259
265 // Remove possibly existing axes
260 // Remove possibly existing axes
266 removeAllAxes();
261 deleteAllAxes();
267
262
268 Q_ASSERT(m_axisList.isEmpty());
263 Q_ASSERT(m_axisList.isEmpty());
269
264
270 // Select the required axis x and axis y types based on the types of the current series
265 // Select the required axis x and axis y types based on the types of the current series
271 foreach(QAbstractSeries* s, m_seriesList) {
266 foreach(QAbstractSeries* s, m_seriesList) {
272 typeX |= s->d_ptr->defaultAxisType(Qt::Horizontal);
267 typeX |= s->d_ptr->defaultAxisType(Qt::Horizontal);
273 typeY |= s->d_ptr->defaultAxisType(Qt::Vertical);
268 typeY |= s->d_ptr->defaultAxisType(Qt::Vertical);
274 }
269 }
275
270
276 // Create the axes of the types selected
271 // Create the axes of the types selected
277 createAxes(typeX, Qt::Horizontal);
272 createAxes(typeX, Qt::Horizontal);
278 createAxes(typeY, Qt::Vertical);
273 createAxes(typeY, Qt::Vertical);
279
274
280 }
275 }
281
276
282 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation)
277 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation)
283 {
278 {
284 QAbstractAxis *axis = 0;
279 QAbstractAxis *axis = 0;
285 //decide what axis should be created
280 //decide what axis should be created
286
281
287 switch (type) {
282 switch (type) {
288 case QAbstractAxis::AxisTypeValue:
283 case QAbstractAxis::AxisTypeValue:
289 axis = new QValueAxis(this);
284 axis = new QValueAxis(this);
290 break;
285 break;
291 case QAbstractAxis::AxisTypeBarCategory:
286 case QAbstractAxis::AxisTypeBarCategory:
292 axis = new QBarCategoryAxis(this);
287 axis = new QBarCategoryAxis(this);
293 break;
288 break;
294 case QAbstractAxis::AxisTypeCategory:
289 case QAbstractAxis::AxisTypeCategory:
295 axis = new QCategoryAxis(this);
290 axis = new QCategoryAxis(this);
296 break;
291 break;
297 #ifndef Q_WS_QWS
292 #ifndef Q_WS_QWS
298 case QAbstractAxis::AxisTypeDateTime:
293 case QAbstractAxis::AxisTypeDateTime:
299 axis = new QDateTimeAxis(this);
294 axis = new QDateTimeAxis(this);
300 break;
295 break;
301 #endif
296 #endif
302 default:
297 default:
303 axis = 0;
298 axis = 0;
304 break;
299 break;
305 }
300 }
306
301
307 if (axis) {
302 if (axis) {
308 //create one axis for all
303 //create one axis for all
309
304
310 addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft);
305 addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft);
311
306
312 foreach(QAbstractSeries *s, m_seriesList) {
307 foreach(QAbstractSeries *s, m_seriesList) {
313 attachAxis(s,axis);
308 attachAxis(s,axis);
314 }
309 }
315
310
316 }
311 }
317 else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) {
312 else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) {
318 //create separate axis
313 //create separate axis
319 foreach(QAbstractSeries *s, m_seriesList) {
314 foreach(QAbstractSeries *s, m_seriesList) {
320 QAbstractAxis *axis = s->d_ptr->createDefaultAxis(orientation);
315 QAbstractAxis *axis = s->d_ptr->createDefaultAxis(orientation);
321 if(axis) {
316 if(axis) {
322 addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft);
317 addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft);
323 attachAxis(s,axis);
318 attachAxis(s,axis);
324 }
319 }
325 }
320 }
326 }
321 }
327 }
322 }
328
323
329 void ChartDataSet::removeAllSeries()
324 void ChartDataSet::deleteAllSeries()
330 {
325 {
331 foreach (QAbstractSeries *s , m_seriesList)
326 foreach (QAbstractSeries *s , m_seriesList){
332 removeSeries(s);
327 removeSeries(s);
333
328 delete s;
329 }
334 Q_ASSERT(m_seriesList.count() == 0);
330 Q_ASSERT(m_seriesList.count() == 0);
335 qDeleteAll(m_seriesList);
336 }
331 }
337
332
338 void ChartDataSet::removeAllAxes()
333 void ChartDataSet::deleteAllAxes()
339 {
334 {
340 foreach (QAbstractAxis *a , m_axisList)
335 foreach (QAbstractAxis *a , m_axisList){
341 removeAxis(a);
336 removeAxis(a);
342
337 delete a;
338 }
343 Q_ASSERT(m_axisList.count() == 0);
339 Q_ASSERT(m_axisList.count() == 0);
344 qDeleteAll(m_axisList);
345 }
340 }
346
341
347 void ChartDataSet::zoomInDomain(const QRectF &rect)
342 void ChartDataSet::zoomInDomain(const QRectF &rect)
348 {
343 {
349 QList<AbstractDomain*> domains;
344 QList<AbstractDomain*> domains;
350 foreach(QAbstractSeries *s, m_seriesList) {
345 foreach(QAbstractSeries *s, m_seriesList) {
351 AbstractDomain* domain = s->d_ptr->m_domain.data();
346 AbstractDomain* domain = s->d_ptr->m_domain.data();
352 if(domains.contains(domain)) continue;
347 if(domains.contains(domain)) continue;
353 s->d_ptr->m_domain->blockAxisSignals(true);
348 s->d_ptr->m_domain->blockAxisSignals(true);
354 domains<<domain;
349 domains<<domain;
355 }
350 }
356
351
357 foreach(AbstractDomain *domain, domains)
352 foreach(AbstractDomain *domain, domains)
358 domain->zoomIn(rect);
353 domain->zoomIn(rect);
359
354
360 foreach(AbstractDomain *domain, domains)
355 foreach(AbstractDomain *domain, domains)
361 domain->blockAxisSignals(false);
356 domain->blockAxisSignals(false);
362 }
357 }
363
358
364 void ChartDataSet::zoomOutDomain(const QRectF &rect)
359 void ChartDataSet::zoomOutDomain(const QRectF &rect)
365 {
360 {
366 QList<AbstractDomain*> domains;
361 QList<AbstractDomain*> domains;
367 foreach(QAbstractSeries *s, m_seriesList) {
362 foreach(QAbstractSeries *s, m_seriesList) {
368 AbstractDomain* domain = s->d_ptr->m_domain.data();
363 AbstractDomain* domain = s->d_ptr->m_domain.data();
369 if(domains.contains(domain)) continue;
364 if(domains.contains(domain)) continue;
370 s->d_ptr->m_domain->blockAxisSignals(true);
365 s->d_ptr->m_domain->blockAxisSignals(true);
371 domains<<domain;
366 domains<<domain;
372 }
367 }
373
368
374 foreach(AbstractDomain *domain, domains)
369 foreach(AbstractDomain *domain, domains)
375 domain->zoomOut(rect);
370 domain->zoomOut(rect);
376
371
377 foreach(AbstractDomain *domain, domains)
372 foreach(AbstractDomain *domain, domains)
378 domain->blockAxisSignals(false);
373 domain->blockAxisSignals(false);
379 }
374 }
380
375
381 void ChartDataSet::scrollDomain(qreal dx, qreal dy)
376 void ChartDataSet::scrollDomain(qreal dx, qreal dy)
382 {
377 {
383 QList<AbstractDomain*> domains;
378 QList<AbstractDomain*> domains;
384 foreach(QAbstractSeries *s, m_seriesList) {
379 foreach(QAbstractSeries *s, m_seriesList) {
385 AbstractDomain* domain = s->d_ptr->m_domain.data();
380 AbstractDomain* domain = s->d_ptr->m_domain.data();
386 if(domains.contains(domain)) continue;
381 if(domains.contains(domain)) continue;
387 s->d_ptr->m_domain->blockAxisSignals(true);
382 s->d_ptr->m_domain->blockAxisSignals(true);
388 domains<<domain;
383 domains<<domain;
389 }
384 }
390
385
391 foreach(AbstractDomain *domain, domains)
386 foreach(AbstractDomain *domain, domains)
392 domain->move(dx, dy);
387 domain->move(dx, dy);
393
388
394 foreach(AbstractDomain *domain, domains)
389 foreach(AbstractDomain *domain, domains)
395 domain->blockAxisSignals(false);
390 domain->blockAxisSignals(false);
396 }
391 }
397
392
398 QList<QAbstractAxis*> ChartDataSet::axes() const
393 QList<QAbstractAxis*> ChartDataSet::axes() const
399 {
394 {
400 return m_axisList;
395 return m_axisList;
401 }
396 }
402
397
403 QList<QAbstractSeries *> ChartDataSet::series() const
398 QList<QAbstractSeries *> ChartDataSet::series() const
404 {
399 {
405 return m_seriesList;
400 return m_seriesList;
406 }
401 }
407
402
403 AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis*> axes)
404 {
405 enum Type {
406 LogType = 0x1,
407 ValueType = 0x2
408 };
409
410 int horizontal(ValueType);
411 int vertical(ValueType);
412
413 foreach(QAbstractAxis* axis, axes)
414 {
415 switch(axis->type()) {
416 case QAbstractAxis::AxisTypeLogValue:
417 axis->orientation()==Qt::Horizontal?horizontal:vertical|=LogType;
418 break;
419 case QAbstractAxis::AxisTypeValue:
420 case QAbstractAxis::AxisTypeBarCategory:
421 case QAbstractAxis::AxisTypeCategory:
422 case QAbstractAxis::AxisTypeDateTime:
423 axis->orientation()==Qt::Horizontal?horizontal:vertical|=ValueType;
424 break;
425 default:
426 qWarning()<<"Undefined type";
427 break;
428 }
429 }
430
431 if(vertical==ValueType && horizontal== ValueType) {
432 return AbstractDomain::XYDomain;
433 }
434
435 if(vertical==LogType && horizontal== ValueType) {
436 return AbstractDomain::XLogYDomain;
437 }
438
439 if(vertical==ValueType && horizontal== LogType) {
440 return AbstractDomain::LogXYDomain;
441 }
442
443 if(vertical==LogType && horizontal== LogType) {
444 return AbstractDomain::XLogYLogDomain;
445 }
446
447 return AbstractDomain::UndefinedDomain;
448 }
449
450
451 //refactor create factory
452 AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type)
453 {
454 switch(type)
455 {
456 case AbstractDomain::XLogYLogDomain:
457 return 0;
458 case AbstractDomain::XYDomain:
459 return new XYDomain();
460 case AbstractDomain::XLogYDomain:
461 return 0;
462 case AbstractDomain::LogXYDomain:
463 return 0;
464 default:
465 return 0;
466 }
467 }
468
408 #include "moc_chartdataset_p.cpp"
469 #include "moc_chartdataset_p.cpp"
409
470
410 QTCOMMERCIALCHART_END_NAMESPACE
471 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,87 +1,88
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 CHARTDATASET_P_H
30 #ifndef CHARTDATASET_P_H
31 #define CHARTDATASET_P_H
31 #define CHARTDATASET_P_H
32
32
33 #include "qabstractseries.h"
33 #include "qabstractseries.h"
34 #include "abstractdomain_p.h"
34 #include "abstractdomain_p.h"
35 #include "qabstractaxis_p.h"
35 #include "qabstractaxis_p.h"
36 #include <QVector>
36 #include <QVector>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class QAbstractAxis;
40 class QAbstractAxis;
41 class ChartPresenter;
41 class ChartPresenter;
42
42
43 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
43 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
44 {
44 {
45 Q_OBJECT
45 Q_OBJECT
46 public:
46 public:
47 ChartDataSet(QChart *chart);
47 ChartDataSet(QChart *chart);
48 virtual ~ChartDataSet();
48 virtual ~ChartDataSet();
49
49
50 void addSeries(QAbstractSeries *series);
50 void addSeries(QAbstractSeries *series);
51 void removeSeries(QAbstractSeries *series);
51 void removeSeries(QAbstractSeries *series);
52 QList<QAbstractSeries *> series() const;
52 QList<QAbstractSeries *> series() const;
53 void removeAllSeries();
54
53
55 void addAxis(QAbstractAxis *axis,Qt::Alignment aligment);
54 void addAxis(QAbstractAxis *axis,Qt::Alignment aligment);
56 void removeAxis(QAbstractAxis *axis);
55 void removeAxis(QAbstractAxis *axis);
57 QList<QAbstractAxis*> axes() const;
56 QList<QAbstractAxis*> axes() const;
58 void removeAllAxes();
59
57
60 bool attachAxis(QAbstractSeries* series,QAbstractAxis *axis);
58 bool attachAxis(QAbstractSeries* series,QAbstractAxis *axis);
61 bool detachAxis(QAbstractSeries* series,QAbstractAxis *axis);
59 bool detachAxis(QAbstractSeries* series,QAbstractAxis *axis);
62
60
63 void createDefaultAxes();
61 void createDefaultAxes();
64
62
65 void zoomInDomain(const QRectF &rect);
63 void zoomInDomain(const QRectF &rect);
66 void zoomOutDomain(const QRectF &rect);
64 void zoomOutDomain(const QRectF &rect);
67 void scrollDomain(qreal dx, qreal dy);
65 void scrollDomain(qreal dx, qreal dy);
68
66
69 Q_SIGNALS:
67 Q_SIGNALS:
70 void axisAdded(QAbstractAxis* axis);
68 void axisAdded(QAbstractAxis* axis);
71 void axisRemoved(QAbstractAxis* axis);
69 void axisRemoved(QAbstractAxis* axis);
72 void seriesAdded(QAbstractSeries* series);
70 void seriesAdded(QAbstractSeries* series);
73 void seriesRemoved(QAbstractSeries* series);
71 void seriesRemoved(QAbstractSeries* series);
74
72
75 private:
73 private:
76 void createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation);
74 void createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation);
77 QAbstractAxis *createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation);
75 QAbstractAxis *createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation);
78
76 AbstractDomain::DomainType selectDomain(QList<QAbstractAxis* > axes);
77 AbstractDomain* createDomain(AbstractDomain::DomainType type);
78 void deleteAllAxes();
79 void deleteAllSeries();
79 private:
80 private:
80 QList<QAbstractSeries *> m_seriesList;
81 QList<QAbstractSeries *> m_seriesList;
81 QList<QAbstractAxis *> m_axisList;
82 QList<QAbstractAxis *> m_axisList;
82 QChart* m_chart;
83 QChart* m_chart;
83 };
84 };
84
85
85 QTCOMMERCIALCHART_END_NAMESPACE
86 QTCOMMERCIALCHART_END_NAMESPACE
86
87
87 #endif /* CHARTENGINE_P_H */
88 #endif /* CHARTENGINE_P_H */
@@ -1,190 +1,219
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 "abstractdomain_p.h"
21 #include "abstractdomain_p.h"
22 #include "qabstractaxis_p.h"
22 #include "qabstractaxis_p.h"
23 #include <qmath.h>
23 #include <qmath.h>
24
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
26
27 AbstractDomain::AbstractDomain(QObject *parent)
27 AbstractDomain::AbstractDomain(QObject *parent)
28 : QObject(parent),
28 : QObject(parent),
29 m_minX(0),
29 m_minX(0),
30 m_maxX(0),
30 m_maxX(0),
31 m_minY(0),
31 m_minY(0),
32 m_maxY(0),
32 m_maxY(0),
33 m_axisSignalsBlocked(false)
33 m_axisSignalsBlocked(false)
34 {
34 {
35 }
35 }
36
36
37 AbstractDomain::~AbstractDomain()
37 AbstractDomain::~AbstractDomain()
38 {
38 {
39 }
39 }
40
40
41 void AbstractDomain::setSize(const QSizeF& size)
41 void AbstractDomain::setSize(const QSizeF& size)
42 {
42 {
43 if(m_size!=size)
43 if(m_size!=size)
44 {
44 {
45 m_size=size;
45 m_size=size;
46 emit updated();
46 emit updated();
47 }
47 }
48 }
48 }
49
49
50 QSizeF AbstractDomain::size() const
50 QSizeF AbstractDomain::size() const
51 {
51 {
52 return m_size;
52 return m_size;
53 }
53 }
54
54
55 void AbstractDomain::setRangeX(qreal min, qreal max)
55 void AbstractDomain::setRangeX(qreal min, qreal max)
56 {
56 {
57 setRange(min, max, m_minY, m_maxY);
57 setRange(min, max, m_minY, m_maxY);
58 }
58 }
59
59
60 void AbstractDomain::setRangeY(qreal min, qreal max)
60 void AbstractDomain::setRangeY(qreal min, qreal max)
61 {
61 {
62 setRange(m_minX, m_maxX, min, max);
62 setRange(m_minX, m_maxX, min, max);
63 }
63 }
64
64
65 void AbstractDomain::setMinX(qreal min)
65 void AbstractDomain::setMinX(qreal min)
66 {
66 {
67 setRange(min, m_maxX, m_minY, m_maxY);
67 setRange(min, m_maxX, m_minY, m_maxY);
68 }
68 }
69
69
70 void AbstractDomain::setMaxX(qreal max)
70 void AbstractDomain::setMaxX(qreal max)
71 {
71 {
72 setRange(m_minX, max, m_minY, m_maxY);
72 setRange(m_minX, max, m_minY, m_maxY);
73 }
73 }
74
74
75 void AbstractDomain::setMinY(qreal min)
75 void AbstractDomain::setMinY(qreal min)
76 {
76 {
77 setRange(m_minX, m_maxX, min, m_maxY);
77 setRange(m_minX, m_maxX, min, m_maxY);
78 }
78 }
79
79
80 void AbstractDomain::setMaxY(qreal max)
80 void AbstractDomain::setMaxY(qreal max)
81 {
81 {
82 setRange(m_minX, m_maxX, m_minY, max);
82 setRange(m_minX, m_maxX, m_minY, max);
83 }
83 }
84
84
85 qreal AbstractDomain::spanX() const
85 qreal AbstractDomain::spanX() const
86 {
86 {
87 Q_ASSERT(m_maxX >= m_minX);
87 Q_ASSERT(m_maxX >= m_minX);
88 return m_maxX - m_minX;
88 return m_maxX - m_minX;
89 }
89 }
90
90
91 qreal AbstractDomain::spanY() const
91 qreal AbstractDomain::spanY() const
92 {
92 {
93 Q_ASSERT(m_maxY >= m_minY);
93 Q_ASSERT(m_maxY >= m_minY);
94 return m_maxY - m_minY;
94 return m_maxY - m_minY;
95 }
95 }
96
96
97 bool AbstractDomain::isEmpty() const
97 bool AbstractDomain::isEmpty() const
98 {
98 {
99 return qFuzzyIsNull(spanX()) || qFuzzyIsNull(spanY()) || m_size.isEmpty() ;
99 return qFuzzyIsNull(spanX()) || qFuzzyIsNull(spanY()) || m_size.isEmpty() ;
100 }
100 }
101
101
102 QPointF AbstractDomain::calculateDomainPoint(const QPointF &point) const
102 QPointF AbstractDomain::calculateDomainPoint(const QPointF &point) const
103 {
103 {
104 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
104 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
105 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
105 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
106 qreal x = point.x() / deltaX + m_minX;
106 qreal x = point.x() / deltaX + m_minX;
107 qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY;
107 qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY;
108 return QPointF(x, y);
108 return QPointF(x, y);
109 }
109 }
110
110
111 // handlers
111 // handlers
112
112
113 void AbstractDomain::handleVerticalAxisRangeChanged(qreal min, qreal max)
113 void AbstractDomain::handleVerticalAxisRangeChanged(qreal min, qreal max)
114 {
114 {
115 if(!m_axisSignalsBlocked)
115 if(!m_axisSignalsBlocked)
116 setRangeY(min, max);
116 setRangeY(min, max);
117 }
117 }
118
118
119 void AbstractDomain::handleHorizontalAxisRangeChanged(qreal min, qreal max)
119 void AbstractDomain::handleHorizontalAxisRangeChanged(qreal min, qreal max)
120 {
120 {
121 if(!m_axisSignalsBlocked)
121 if(!m_axisSignalsBlocked)
122 setRangeX(min, max);
122 setRangeX(min, max);
123 }
123 }
124
124
125 void AbstractDomain::blockAxisSignals(bool block)
125 void AbstractDomain::blockAxisSignals(bool block)
126 {
126 {
127 m_axisSignalsBlocked=block;
127 m_axisSignalsBlocked=block;
128 }
128 }
129
129
130 //algorithm defined by Paul S.Heckbert GraphicalGems I
130 //algorithm defined by Paul S.Heckbert GraphicalGems I
131
131
132 void AbstractDomain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount)
132 void AbstractDomain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount)
133 {
133 {
134 qreal range = niceNumber(max - min, true); //range with ceiling
134 qreal range = niceNumber(max - min, true); //range with ceiling
135 qreal step = niceNumber(range / (ticksCount - 1), false);
135 qreal step = niceNumber(range / (ticksCount - 1), false);
136 min = qFloor(min / step);
136 min = qFloor(min / step);
137 max = qCeil(max / step);
137 max = qCeil(max / step);
138 ticksCount = int(max - min) + 1;
138 ticksCount = int(max - min) + 1;
139 min *= step;
139 min *= step;
140 max *= step;
140 max *= step;
141 }
141 }
142
142
143 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
143 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
144
144
145 qreal AbstractDomain::niceNumber(qreal x, bool ceiling)
145 qreal AbstractDomain::niceNumber(qreal x, bool ceiling)
146 {
146 {
147 qreal z = qPow(10, qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
147 qreal z = qPow(10, qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
148 qreal q = x / z; //q<10 && q>=1;
148 qreal q = x / z; //q<10 && q>=1;
149
149
150 if (ceiling) {
150 if (ceiling) {
151 if (q <= 1.0) q = 1;
151 if (q <= 1.0) q = 1;
152 else if (q <= 2.0) q = 2;
152 else if (q <= 2.0) q = 2;
153 else if (q <= 5.0) q = 5;
153 else if (q <= 5.0) q = 5;
154 else q = 10;
154 else q = 10;
155 } else {
155 } else {
156 if (q < 1.5) q = 1;
156 if (q < 1.5) q = 1;
157 else if (q < 3.0) q = 2;
157 else if (q < 3.0) q = 2;
158 else if (q < 7.0) q = 5;
158 else if (q < 7.0) q = 5;
159 else q = 10;
159 else q = 10;
160 }
160 }
161 return q * z;
161 return q * z;
162 }
162 }
163
163
164 bool AbstractDomain::attachAxis(QAbstractAxis* axis)
165 {
166 if(axis->orientation()==Qt::Vertical) {
167 QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleVerticalAxisRangeChanged(qreal,qreal)));
168 QObject::connect(this, SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
169 }
170
171 if(axis->orientation()==Qt::Horizontal) {
172 QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleHorizontalAxisRangeChanged(qreal,qreal)));
173 QObject::connect(this, SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
174 }
175
176 return true;
177 }
178
179 bool AbstractDomain::detachAxis(QAbstractAxis* axis)
180 {
181 if(axis->orientation()==Qt::Vertical) {
182 QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleVerticalAxisRangeChanged(qreal,qreal)));
183 QObject::disconnect(this, SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
184 }
185
186 if(axis->orientation()==Qt::Horizontal) {
187 QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleHorizontalAxisRangeChanged(qreal,qreal)));
188 QObject::disconnect(this, SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
189 }
190
191 return true;
192 }
164
193
165 // operators
194 // operators
166
195
167 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const AbstractDomain &domain1, const AbstractDomain &domain2)
196 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const AbstractDomain &domain1, const AbstractDomain &domain2)
168 {
197 {
169 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
198 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
170 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
199 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
171 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
200 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
172 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
201 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
173 }
202 }
174
203
175
204
176 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const AbstractDomain &domain1, const AbstractDomain &domain2)
205 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const AbstractDomain &domain1, const AbstractDomain &domain2)
177 {
206 {
178 return !(domain1 == domain2);
207 return !(domain1 == domain2);
179 }
208 }
180
209
181
210
182 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const AbstractDomain &domain)
211 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const AbstractDomain &domain)
183 {
212 {
184 dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size;
213 dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size;
185 return dbg.maybeSpace();
214 return dbg.maybeSpace();
186 }
215 }
187
216
188 #include "moc_abstractdomain_p.cpp"
217 #include "moc_abstractdomain_p.cpp"
189
218
190 QTCOMMERCIALCHART_END_NAMESPACE
219 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,106 +1,113
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 ABSTRACTDOMAIN_H
30 #ifndef ABSTRACTDOMAIN_H
31 #define ABSTRACTDOMAIN_H
31 #define ABSTRACTDOMAIN_H
32 #include "qchartglobal.h"
32 #include "qchartglobal.h"
33 #include <QRectF>
33 #include <QRectF>
34 #include <QSizeF>
34 #include <QSizeF>
35 #include <QDebug>
35 #include <QDebug>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 class QAbstractAxis;
40
39 class QTCOMMERCIALCHART_AUTOTEST_EXPORT AbstractDomain: public QObject
41 class QTCOMMERCIALCHART_AUTOTEST_EXPORT AbstractDomain: public QObject
40 {
42 {
41 Q_OBJECT
43 Q_OBJECT
42 public:
44 public:
45 enum DomainType { UndefinedDomain, XYDomain, XLogYDomain, LogXYDomain, XLogYLogDomain };
46 public:
43 explicit AbstractDomain(QObject *object = 0);
47 explicit AbstractDomain(QObject *object = 0);
44 virtual ~AbstractDomain();
48 virtual ~AbstractDomain();
45
49
46 void setSize(const QSizeF& size);
50 void setSize(const QSizeF& size);
47 QSizeF size() const;
51 QSizeF size() const;
48
52
53 virtual DomainType type() = 0;
54
49 virtual void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) = 0;
55 virtual void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) = 0;
50 void setRangeX(qreal min, qreal max);
56 void setRangeX(qreal min, qreal max);
51 void setRangeY(qreal min, qreal max);
57 void setRangeY(qreal min, qreal max);
52 void setMinX(qreal min);
58 void setMinX(qreal min);
53 void setMaxX(qreal max);
59 void setMaxX(qreal max);
54 void setMinY(qreal min);
60 void setMinY(qreal min);
55 void setMaxY(qreal max);
61 void setMaxY(qreal max);
56
62
57 qreal minX() const { return m_minX; }
63 qreal minX() const { return m_minX; }
58 qreal maxX() const { return m_maxX; }
64 qreal maxX() const { return m_maxX; }
59 qreal minY() const { return m_minY; }
65 qreal minY() const { return m_minY; }
60 qreal maxY() const { return m_maxY; }
66 qreal maxY() const { return m_maxY; }
61
67
62 qreal spanX() const;
68 qreal spanX() const;
63 qreal spanY() const;
69 qreal spanY() const;
64 bool isEmpty() const;
70 bool isEmpty() const;
65
71
66
67 void blockAxisSignals(bool block);
72 void blockAxisSignals(bool block);
68 bool axisSignalsBlocked() const { return m_axisSignalsBlocked; }
73 bool axisSignalsBlocked() const { return m_axisSignalsBlocked; }
69
74
70
71 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const AbstractDomain &domain1, const AbstractDomain &domain2);
75 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const AbstractDomain &domain1, const AbstractDomain &domain2);
72 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const AbstractDomain &domain1, const AbstractDomain &domain2);
76 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const AbstractDomain &domain1, const AbstractDomain &domain2);
73 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const AbstractDomain &domain);
77 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const AbstractDomain &domain);
74
78
75 virtual void zoomIn(const QRectF &rect) = 0;
79 virtual void zoomIn(const QRectF &rect) = 0;
76 virtual void zoomOut(const QRectF &rect) = 0;
80 virtual void zoomOut(const QRectF &rect) = 0;
77 virtual void move(qreal dx, qreal dy) = 0;
81 virtual void move(qreal dx, qreal dy) = 0;
78
82
79 virtual QPointF calculateGeometryPoint(const QPointF &point) const = 0;
83 virtual QPointF calculateGeometryPoint(const QPointF &point) const = 0;
80 virtual QPointF calculateDomainPoint(const QPointF &point) const = 0;
84 virtual QPointF calculateDomainPoint(const QPointF &point) const = 0;
81 virtual QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const = 0;
85 virtual QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const = 0;
82
86
87 virtual bool attachAxis(QAbstractAxis* axis);
88 virtual bool detachAxis(QAbstractAxis* axis);
89
83 static void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount);
90 static void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount);
84 static qreal niceNumber(qreal x, bool ceiling);
91 static qreal niceNumber(qreal x, bool ceiling);
85
92
86 Q_SIGNALS:
93 Q_SIGNALS:
87 void updated();
94 void updated();
88 void rangeHorizontalChanged(qreal min, qreal max);
95 void rangeHorizontalChanged(qreal min, qreal max);
89 void rangeVerticalChanged(qreal min, qreal max);
96 void rangeVerticalChanged(qreal min, qreal max);
90
97
91 public Q_SLOTS:
98 public Q_SLOTS:
92 void handleVerticalAxisRangeChanged(qreal min,qreal max);
99 void handleVerticalAxisRangeChanged(qreal min,qreal max);
93 void handleHorizontalAxisRangeChanged(qreal min,qreal max);
100 void handleHorizontalAxisRangeChanged(qreal min,qreal max);
94
101
95 protected:
102 protected:
96 qreal m_minX;
103 qreal m_minX;
97 qreal m_maxX;
104 qreal m_maxX;
98 qreal m_minY;
105 qreal m_minY;
99 qreal m_maxY;
106 qreal m_maxY;
100 QSizeF m_size;
107 QSizeF m_size;
101 bool m_axisSignalsBlocked;
108 bool m_axisSignalsBlocked;
102 };
109 };
103
110
104 QTCOMMERCIALCHART_END_NAMESPACE
111 QTCOMMERCIALCHART_END_NAMESPACE
105
112
106 #endif // ABSTRACTDOMAIN_H
113 #endif // ABSTRACTDOMAIN_H
@@ -1,62 +1,64
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 XYDOMAIN_H
30 #ifndef XYDOMAIN_H
31 #define XYDOMAIN_H
31 #define XYDOMAIN_H
32 #include "abstractdomain_p.h"
32 #include "abstractdomain_p.h"
33 #include <QRectF>
33 #include <QRectF>
34 #include <QSizeF>
34 #include <QSizeF>
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QTCOMMERCIALCHART_AUTOTEST_EXPORT XYDomain: public AbstractDomain
38 class QTCOMMERCIALCHART_AUTOTEST_EXPORT XYDomain: public AbstractDomain
39 {
39 {
40 Q_OBJECT
40 Q_OBJECT
41 public:
41 public:
42 explicit XYDomain(QObject *object = 0);
42 explicit XYDomain(QObject *object = 0);
43 virtual ~XYDomain();
43 virtual ~XYDomain();
44
44
45 DomainType type(){ return AbstractDomain::XYDomain;}
46
45 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
47 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
46
48
47 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XYDomain &Domain1, const XYDomain &Domain2);
49 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XYDomain &Domain1, const XYDomain &Domain2);
48 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const XYDomain &Domain1, const XYDomain &Domain2);
50 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const XYDomain &Domain1, const XYDomain &Domain2);
49 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const XYDomain &AbstractDomain);
51 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const XYDomain &AbstractDomain);
50
52
51 void zoomIn(const QRectF &rect);
53 void zoomIn(const QRectF &rect);
52 void zoomOut(const QRectF &rect);
54 void zoomOut(const QRectF &rect);
53 void move(qreal dx, qreal dy);
55 void move(qreal dx, qreal dy);
54
56
55 QPointF calculateGeometryPoint(const QPointF &point) const;
57 QPointF calculateGeometryPoint(const QPointF &point) const;
56 QPointF calculateDomainPoint(const QPointF &point) const;
58 QPointF calculateDomainPoint(const QPointF &point) const;
57 QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const;
59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const;
58 };
60 };
59
61
60 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
61
63
62 #endif // XYDOMAIN_H
64 #endif // XYDOMAIN_H
@@ -1,101 +1,100
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 QLEGEND_P_H
30 #ifndef QLEGEND_P_H
31 #define QLEGEND_P_H
31 #define QLEGEND_P_H
32
32
33 #include "qlegend.h"
33 #include "qlegend.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QChart;
37 class QChart;
38 class ChartPresenter;
38 class ChartPresenter;
39 class QAbstractSeries;
39 class QAbstractSeries;
40 class LegendLayout;
40 class LegendLayout;
41 class Domain;
42 class QLegendMarker;
41 class QLegendMarker;
43
42
44 class QLegendPrivate : public QObject
43 class QLegendPrivate : public QObject
45 {
44 {
46 Q_OBJECT
45 Q_OBJECT
47 public:
46 public:
48 QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q);
47 QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q);
49 ~QLegendPrivate();
48 ~QLegendPrivate();
50
49
51 void setOffset(const QPointF &offset);
50 void setOffset(const QPointF &offset);
52 QPointF offset() const;
51 QPointF offset() const;
53 int roundness(qreal size);
52 int roundness(qreal size);
54
53
55 QGraphicsItemGroup* items() { return m_items; }
54 QGraphicsItemGroup* items() { return m_items; }
56
55
57 QList<QLegendMarker*> markers(QAbstractSeries *series = 0);
56 QList<QLegendMarker*> markers(QAbstractSeries *series = 0);
58
57
59 public Q_SLOTS:
58 public Q_SLOTS:
60 void handleSeriesAdded(QAbstractSeries *series);
59 void handleSeriesAdded(QAbstractSeries *series);
61 void handleSeriesRemoved(QAbstractSeries *series);
60 void handleSeriesRemoved(QAbstractSeries *series);
62 void handleSeriesVisibleChanged();
61 void handleSeriesVisibleChanged();
63 void handleCountChanged();
62 void handleCountChanged();
64
63
65 private:
64 private:
66 // Internal helpers
65 // Internal helpers
67 void addMarkers(QList<QLegendMarker *> markers);
66 void addMarkers(QList<QLegendMarker *> markers);
68 void removeMarkers(QList<QLegendMarker *> markers);
67 void removeMarkers(QList<QLegendMarker *> markers);
69 void decorateMarkers(QList<QLegendMarker *> markers);
68 void decorateMarkers(QList<QLegendMarker *> markers);
70
69
71 private:
70 private:
72 QLegend *q_ptr;
71 QLegend *q_ptr;
73 ChartPresenter *m_presenter;
72 ChartPresenter *m_presenter;
74 LegendLayout *m_layout;
73 LegendLayout *m_layout;
75 QChart *m_chart;
74 QChart *m_chart;
76 QGraphicsItemGroup *m_items;
75 QGraphicsItemGroup *m_items;
77 Qt::Alignment m_alignment;
76 Qt::Alignment m_alignment;
78 QBrush m_brush;
77 QBrush m_brush;
79 QPen m_pen;
78 QPen m_pen;
80 QFont m_font;
79 QFont m_font;
81 QBrush m_labelBrush;
80 QBrush m_labelBrush;
82
81
83 qreal m_diameter;
82 qreal m_diameter;
84 bool m_attachedToChart;
83 bool m_attachedToChart;
85 bool m_backgroundVisible;
84 bool m_backgroundVisible;
86
85
87 QList<QLegendMarker *> m_markers;
86 QList<QLegendMarker *> m_markers;
88 QList<QAbstractSeries *> m_series;
87 QList<QAbstractSeries *> m_series;
89
88
90 QHash<QGraphicsItem *, QLegendMarker *> m_markerHash;
89 QHash<QGraphicsItem *, QLegendMarker *> m_markerHash;
91
90
92 friend class QLegend;
91 friend class QLegend;
93 friend class LegendMarkerItem;
92 friend class LegendMarkerItem;
94 friend class LegendLayout;
93 friend class LegendLayout;
95 friend class QLegendMarkerPrivate;
94 friend class QLegendMarkerPrivate;
96 friend class LegendScroller;
95 friend class LegendScroller;
97 };
96 };
98
97
99 QTCOMMERCIALCHART_END_NAMESPACE
98 QTCOMMERCIALCHART_END_NAMESPACE
100
99
101 #endif
100 #endif
@@ -1,654 +1,657
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 "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "legendscroller_p.h"
23 #include "legendscroller_p.h"
24 #include "qlegend_p.h"
24 #include "qlegend_p.h"
25 #include "chartbackground_p.h"
25 #include "chartbackground_p.h"
26 #include "qabstractaxis.h"
26 #include "qabstractaxis.h"
27 #include "chartlayout_p.h"
27 #include "chartlayout_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartpresenter_p.h"
29 #include "chartpresenter_p.h"
30 #include "chartdataset_p.h"
30 #include "chartdataset_p.h"
31 #include <QGraphicsScene>
31 #include <QGraphicsScene>
32 #include <QGraphicsSceneResizeEvent>
32 #include <QGraphicsSceneResizeEvent>
33
33
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35
35
36 /*!
36 /*!
37 \enum QChart::ChartTheme
37 \enum QChart::ChartTheme
38
38
39 This enum describes the theme used by the chart.
39 This enum describes the theme used by the chart.
40
40
41 \value ChartThemeLight The default theme
41 \value ChartThemeLight The default theme
42 \value ChartThemeBlueCerulean
42 \value ChartThemeBlueCerulean
43 \value ChartThemeDark
43 \value ChartThemeDark
44 \value ChartThemeBrownSand
44 \value ChartThemeBrownSand
45 \value ChartThemeBlueNcs
45 \value ChartThemeBlueNcs
46 \value ChartThemeHighContrast
46 \value ChartThemeHighContrast
47 \value ChartThemeBlueIcy
47 \value ChartThemeBlueIcy
48 */
48 */
49
49
50 /*!
50 /*!
51 \enum QChart::AnimationOption
51 \enum QChart::AnimationOption
52
52
53 For enabling/disabling animations. Defaults to NoAnimation.
53 For enabling/disabling animations. Defaults to NoAnimation.
54
54
55 \value NoAnimation
55 \value NoAnimation
56 \value GridAxisAnimations
56 \value GridAxisAnimations
57 \value SeriesAnimations
57 \value SeriesAnimations
58 \value AllAnimations
58 \value AllAnimations
59 */
59 */
60
60
61 /*!
61 /*!
62 \class QChart
62 \class QChart
63 \brief QtCommercial chart API.
63 \brief QtCommercial chart API.
64
64
65 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
65 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
66 representation of different types of series and other chart related objects like
66 representation of different types of series and other chart related objects like
67 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
67 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
68 convenience class QChartView instead of QChart.
68 convenience class QChartView instead of QChart.
69 \sa QChartView
69 \sa QChartView
70 */
70 */
71
71
72 /*!
72 /*!
73 \property QChart::animationOptions
73 \property QChart::animationOptions
74 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
74 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
75 */
75 */
76
76
77 /*!
77 /*!
78 \property QChart::backgroundVisible
78 \property QChart::backgroundVisible
79 Whether the chart background is visible or not.
79 Whether the chart background is visible or not.
80 \sa setBackgroundBrush(), setBackgroundPen()
80 \sa setBackgroundBrush(), setBackgroundPen()
81 */
81 */
82
82
83 /*!
83 /*!
84 \property QChart::dropShadowEnabled
84 \property QChart::dropShadowEnabled
85 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
85 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
86 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
86 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
87 */
87 */
88
88
89 /*!
89 /*!
90 \property QChart::minimumMargins
90 \property QChart::minimumMargins
91 Minimum margins between the plot area (axes) and the edge of the chart widget.
91 Minimum margins between the plot area (axes) and the edge of the chart widget.
92 */
92 */
93
93
94 /*!
94 /*!
95 \property QChart::theme
95 \property QChart::theme
96 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
96 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
97 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
97 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
98 different themes.
98 different themes.
99 Note: changing the theme will overwrite all customizations previously applied to the series.
99 Note: changing the theme will overwrite all customizations previously applied to the series.
100 */
100 */
101
101
102 /*!
102 /*!
103 \property QChart::title
103 \property QChart::title
104 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
104 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
105 */
105 */
106
106
107 /*!
107 /*!
108 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
108 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
109 */
109 */
110 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
110 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
111 : QGraphicsWidget(parent, wFlags),
111 : QGraphicsWidget(parent, wFlags),
112 d_ptr(new QChartPrivate(this))
112 d_ptr(new QChartPrivate(this))
113 {
113 {
114 d_ptr->m_legend = new LegendScroller(this);
114 d_ptr->m_legend = new LegendScroller(this);
115 setTheme(QChart::ChartThemeLight);
115 setTheme(QChart::ChartThemeLight);
116 //TODO: what is that ?
116 //TODO: what is that ?
117 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
117 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
118 setLayout(d_ptr->m_presenter->layout());
118 setLayout(d_ptr->m_presenter->layout());
119 }
119 }
120
120
121 /*!
121 /*!
122 Destroys the object and it's children, like series and axis objects added to it.
122 Destroys the object and it's children, like series and axis objects added to it.
123 */
123 */
124 QChart::~QChart()
124 QChart::~QChart()
125 {
125 {
126 //start by deleting dataset, it will remove all series and axes
126 //start by deleting dataset, it will remove all series and axes
127 delete d_ptr->m_dataset;
127 delete d_ptr->m_dataset;
128 d_ptr->m_dataset = 0;
128 d_ptr->m_dataset = 0;
129 }
129 }
130
130
131 /*!
131 /*!
132 Adds the \a series onto the chart and takes the ownership of the object.
132 Adds the \a series onto the chart and takes the ownership of the object.
133 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
133 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
134 the y axis).
134 the y axis).
135
135
136 \sa removeSeries(), removeAllSeries()
136 \sa removeSeries(), removeAllSeries()
137 */
137 */
138 void QChart::addSeries(QAbstractSeries *series)
138 void QChart::addSeries(QAbstractSeries *series)
139 {
139 {
140 Q_ASSERT(series);
140 Q_ASSERT(series);
141 d_ptr->m_dataset->addSeries(series);
141 d_ptr->m_dataset->addSeries(series);
142 }
142 }
143
143
144 /*!
144 /*!
145 Removes the \a series specified in a perameter from the QChartView.
145 Removes the \a series specified in a perameter from the QChartView.
146 It releses its ownership of the specified QChartSeries object.
146 It releses its ownership of the specified QChartSeries object.
147 It does not delete the pointed QChartSeries data object
147 It does not delete the pointed QChartSeries data object
148 \sa addSeries(), removeAllSeries()
148 \sa addSeries(), removeAllSeries()
149 */
149 */
150 void QChart::removeSeries(QAbstractSeries *series)
150 void QChart::removeSeries(QAbstractSeries *series)
151 {
151 {
152 Q_ASSERT(series);
152 Q_ASSERT(series);
153 d_ptr->m_dataset->removeSeries(series);
153 d_ptr->m_dataset->removeSeries(series);
154 }
154 }
155
155
156 /*!
156 /*!
157 Removes all the QChartSeries that have been added to the QChartView
157 Removes all the QChartSeries that have been added to the QChartView
158 It also deletes the pointed QChartSeries data objects
158 It also deletes the pointed QChartSeries data objects
159 \sa addSeries(), removeSeries()
159 \sa addSeries(), removeSeries()
160 */
160 */
161 void QChart::removeAllSeries()
161 void QChart::removeAllSeries()
162 {
162 {
163 d_ptr->m_dataset->removeAllSeries();
163 foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){
164 removeSeries(s);
165 delete s;
166 }
164 }
167 }
165
168
166 /*!
169 /*!
167 Sets the \a brush that is used for painting the background of the chart area.
170 Sets the \a brush that is used for painting the background of the chart area.
168 */
171 */
169 void QChart::setBackgroundBrush(const QBrush &brush)
172 void QChart::setBackgroundBrush(const QBrush &brush)
170 {
173 {
171 d_ptr->m_presenter->setBackgroundBrush(brush);
174 d_ptr->m_presenter->setBackgroundBrush(brush);
172 }
175 }
173
176
174 /*!
177 /*!
175 Gets the brush that is used for painting the background of the chart area.
178 Gets the brush that is used for painting the background of the chart area.
176 */
179 */
177 QBrush QChart::backgroundBrush() const
180 QBrush QChart::backgroundBrush() const
178 {
181 {
179 return d_ptr->m_presenter->backgroundBrush();
182 return d_ptr->m_presenter->backgroundBrush();
180 }
183 }
181
184
182 /*!
185 /*!
183 Sets the \a pen that is used for painting the background of the chart area.
186 Sets the \a pen that is used for painting the background of the chart area.
184 */
187 */
185 void QChart::setBackgroundPen(const QPen &pen)
188 void QChart::setBackgroundPen(const QPen &pen)
186 {
189 {
187 d_ptr->m_presenter->setBackgroundPen(pen);
190 d_ptr->m_presenter->setBackgroundPen(pen);
188 }
191 }
189
192
190 /*!
193 /*!
191 Gets the pen that is used for painting the background of the chart area.
194 Gets the pen that is used for painting the background of the chart area.
192 */
195 */
193 QPen QChart::backgroundPen() const
196 QPen QChart::backgroundPen() const
194 {
197 {
195 return d_ptr->m_presenter->backgroundPen();
198 return d_ptr->m_presenter->backgroundPen();
196 }
199 }
197
200
198 /*!
201 /*!
199 Sets the chart \a title. The description text that is drawn above the chart.
202 Sets the chart \a title. The description text that is drawn above the chart.
200 */
203 */
201 void QChart::setTitle(const QString &title)
204 void QChart::setTitle(const QString &title)
202 {
205 {
203 d_ptr->m_presenter->setTitle(title);
206 d_ptr->m_presenter->setTitle(title);
204 }
207 }
205
208
206 /*!
209 /*!
207 Returns the chart title. The description text that is drawn above the chart.
210 Returns the chart title. The description text that is drawn above the chart.
208 */
211 */
209 QString QChart::title() const
212 QString QChart::title() const
210 {
213 {
211 return d_ptr->m_presenter->title();
214 return d_ptr->m_presenter->title();
212 }
215 }
213
216
214 /*!
217 /*!
215 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
218 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
216 */
219 */
217 void QChart::setTitleFont(const QFont &font)
220 void QChart::setTitleFont(const QFont &font)
218 {
221 {
219 d_ptr->m_presenter->setTitleFont(font);
222 d_ptr->m_presenter->setTitleFont(font);
220 }
223 }
221
224
222 /*!
225 /*!
223 Gets the font that is used for drawing the chart description text that is rendered above the chart.
226 Gets the font that is used for drawing the chart description text that is rendered above the chart.
224 */
227 */
225 QFont QChart::titleFont() const
228 QFont QChart::titleFont() const
226 {
229 {
227 return d_ptr->m_presenter->titleFont();
230 return d_ptr->m_presenter->titleFont();
228 }
231 }
229
232
230 /*!
233 /*!
231 Sets the \a brush used for rendering the title text.
234 Sets the \a brush used for rendering the title text.
232 */
235 */
233 void QChart::setTitleBrush(const QBrush &brush)
236 void QChart::setTitleBrush(const QBrush &brush)
234 {
237 {
235 d_ptr->m_presenter->setTitleBrush(brush);
238 d_ptr->m_presenter->setTitleBrush(brush);
236 }
239 }
237
240
238 /*!
241 /*!
239 Returns the brush used for rendering the title text.
242 Returns the brush used for rendering the title text.
240 */
243 */
241 QBrush QChart::titleBrush() const
244 QBrush QChart::titleBrush() const
242 {
245 {
243 return d_ptr->m_presenter->titleBrush();
246 return d_ptr->m_presenter->titleBrush();
244 }
247 }
245
248
246 void QChart::setTheme(QChart::ChartTheme theme)
249 void QChart::setTheme(QChart::ChartTheme theme)
247 {
250 {
248 d_ptr->m_themeManager->setTheme(theme);
251 d_ptr->m_themeManager->setTheme(theme);
249 }
252 }
250
253
251 QChart::ChartTheme QChart::theme() const
254 QChart::ChartTheme QChart::theme() const
252 {
255 {
253 return d_ptr->m_themeManager->theme()->id();
256 return d_ptr->m_themeManager->theme()->id();
254 }
257 }
255
258
256 /*!
259 /*!
257 Zooms in the view by a factor of 2
260 Zooms in the view by a factor of 2
258 */
261 */
259 void QChart::zoomIn()
262 void QChart::zoomIn()
260 {
263 {
261 d_ptr->zoomIn(2.0);
264 d_ptr->zoomIn(2.0);
262 }
265 }
263
266
264 /*!
267 /*!
265 Zooms in the view to a maximum level at which \a rect is still fully visible.
268 Zooms in the view to a maximum level at which \a rect is still fully visible.
266 */
269 */
267 void QChart::zoomIn(const QRectF &rect)
270 void QChart::zoomIn(const QRectF &rect)
268 {
271 {
269 d_ptr->zoomIn(rect);
272 d_ptr->zoomIn(rect);
270 }
273 }
271
274
272 /*!
275 /*!
273 Restores the view zoom level to the previous one.
276 Restores the view zoom level to the previous one.
274 */
277 */
275 void QChart::zoomOut()
278 void QChart::zoomOut()
276 {
279 {
277 d_ptr->zoomOut(2.0);
280 d_ptr->zoomOut(2.0);
278 }
281 }
279
282
280 /*!
283 /*!
281 Zooms in the view by a \a factor.
284 Zooms in the view by a \a factor.
282
285
283 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
286 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
284 */
287 */
285 void QChart::zoom(qreal factor)
288 void QChart::zoom(qreal factor)
286 {
289 {
287 if (qFuzzyCompare(factor, 0))
290 if (qFuzzyCompare(factor, 0))
288 return;
291 return;
289
292
290 if (qFuzzyCompare(factor, (qreal)1.0))
293 if (qFuzzyCompare(factor, (qreal)1.0))
291 return;
294 return;
292
295
293 if (factor < 0)
296 if (factor < 0)
294 return;
297 return;
295
298
296 if (factor > 1.0)
299 if (factor > 1.0)
297 d_ptr->zoomIn(factor);
300 d_ptr->zoomIn(factor);
298 else
301 else
299 d_ptr->zoomOut(1.0 / factor);
302 d_ptr->zoomOut(1.0 / factor);
300 }
303 }
301
304
302 /*!
305 /*!
303 Returns the pointer to the x axis object of the chart asociated with the specified \a series
306 Returns the pointer to the x axis object of the chart asociated with the specified \a series
304 If no series is provided then pointer to currently visible axis is provided
307 If no series is provided then pointer to currently visible axis is provided
305 */
308 */
306 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
309 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
307 {
310 {
308 if(!series && d_ptr->m_dataset->series().size()>0){
311 if(!series && d_ptr->m_dataset->series().size()>0){
309 series = d_ptr->m_dataset->series().first();
312 series = d_ptr->m_dataset->series().first();
310 }
313 }
311
314
312 QList<QAbstractAxis*> axes = series->attachedAxes();
315 QList<QAbstractAxis*> axes = series->attachedAxes();
313 QAbstractAxis* bottom=0;
316 QAbstractAxis* bottom=0;
314 QAbstractAxis* top=0;
317 QAbstractAxis* top=0;
315
318
316 foreach(QAbstractAxis* axis, axes){
319 foreach(QAbstractAxis* axis, axes){
317
320
318 if(axis->alignment()==Qt::AlignTop){
321 if(axis->alignment()==Qt::AlignTop){
319 top=axis;
322 top=axis;
320 }
323 }
321
324
322 if(axis->alignment()==Qt::AlignBottom){
325 if(axis->alignment()==Qt::AlignBottom){
323 bottom=axis;
326 bottom=axis;
324 }
327 }
325 }
328 }
326 return bottom?bottom:top;
329 return bottom?bottom:top;
327 }
330 }
328
331
329 /*!
332 /*!
330 Returns the pointer to the y axis object of the chart asociated with the specified \a series
333 Returns the pointer to the y axis object of the chart asociated with the specified \a series
331 If no series is provided then pointer to currently visible axis is provided
334 If no series is provided then pointer to currently visible axis is provided
332 */
335 */
333 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
336 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
334 {
337 {
335 if(!series && d_ptr->m_dataset->series().size()>0) {
338 if(!series && d_ptr->m_dataset->series().size()>0) {
336 series = d_ptr->m_dataset->series().first();
339 series = d_ptr->m_dataset->series().first();
337 }
340 }
338
341
339 QList<QAbstractAxis*> axes = series->attachedAxes();
342 QList<QAbstractAxis*> axes = series->attachedAxes();
340
343
341 QAbstractAxis* left=0;
344 QAbstractAxis* left=0;
342 QAbstractAxis* right=0;
345 QAbstractAxis* right=0;
343
346
344 foreach(QAbstractAxis* axis, axes){
347 foreach(QAbstractAxis* axis, axes){
345
348
346 if(axis->alignment()==Qt::AlignLeft){
349 if(axis->alignment()==Qt::AlignLeft){
347 left=axis;
350 left=axis;
348 }
351 }
349
352
350 if(axis->alignment()==Qt::AlignRight){
353 if(axis->alignment()==Qt::AlignRight){
351 right=axis;
354 right=axis;
352 }
355 }
353 }
356 }
354
357
355 return left?left:right;
358 return left?left:right;
356 }
359 }
357
360
358
361
359 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
362 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
360 {
363 {
361 QList<QAbstractAxis *> result ;
364 QList<QAbstractAxis *> result ;
362
365
363 foreach(QAbstractAxis* axis,series->attachedAxes()){
366 foreach(QAbstractAxis* axis,series->attachedAxes()){
364 if(orientation.testFlag(axis->orientation()))
367 if(orientation.testFlag(axis->orientation()))
365 result << axis;
368 result << axis;
366 }
369 }
367
370
368 return result;
371 return result;
369 }
372 }
370
373
371 /*!
374 /*!
372 NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL.
375 NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL.
373
376
374 Creates the axes for the chart based on the series that has already been added to the chart.
377 Creates the axes for the chart based on the series that has already been added to the chart.
375
378
376 \table
379 \table
377 \header
380 \header
378 \o Series type
381 \o Series type
379 \o X-axis
382 \o X-axis
380 \o Y-axis
383 \o Y-axis
381 \row
384 \row
382 \o QXYSeries
385 \o QXYSeries
383 \o QValueAxis
386 \o QValueAxis
384 \o QValueAxis
387 \o QValueAxis
385 \row
388 \row
386 \o QBarSeries
389 \o QBarSeries
387 \o QBarCategoryAxis
390 \o QBarCategoryAxis
388 \o QValueAxis
391 \o QValueAxis
389 \row
392 \row
390 \o QPieSeries
393 \o QPieSeries
391 \o None
394 \o None
392 \o None
395 \o None
393 \endtable
396 \endtable
394
397
395 If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created.
398 If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created.
396 If there are sevaral series added of different types then each series gets its own axes pair.
399 If there are sevaral series added of different types then each series gets its own axes pair.
397
400
398 NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown.
401 NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown.
399
402
400 Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls.
403 Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls.
401 QPieSeries does not create any axes.
404 QPieSeries does not create any axes.
402
405
403 \sa axisX(), axisY(), setAxisX(), setAxisY()
406 \sa axisX(), axisY(), setAxisX(), setAxisY()
404 */
407 */
405 void QChart::createDefaultAxes()
408 void QChart::createDefaultAxes()
406 {
409 {
407 d_ptr->m_dataset->createDefaultAxes();
410 d_ptr->m_dataset->createDefaultAxes();
408 }
411 }
409
412
410 /*!
413 /*!
411 Returns the legend object of the chart. Ownership stays in chart.
414 Returns the legend object of the chart. Ownership stays in chart.
412 */
415 */
413 QLegend *QChart::legend() const
416 QLegend *QChart::legend() const
414 {
417 {
415 return d_ptr->m_legend;
418 return d_ptr->m_legend;
416 }
419 }
417
420
418 /*!
421 /*!
419 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
422 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
420 Deprecated. Use setMargins().
423 Deprecated. Use setMargins().
421 */
424 */
422 void QChart::setMinimumMargins(const QMargins &margins)
425 void QChart::setMinimumMargins(const QMargins &margins)
423 {
426 {
424 qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead.";
427 qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead.";
425 d_ptr->m_presenter->layout()->setMargins(margins);
428 d_ptr->m_presenter->layout()->setMargins(margins);
426 }
429 }
427
430
428 /*!
431 /*!
429 Returns the rect that contains information about margins (distance between chart widget edge and axes).
432 Returns the rect that contains information about margins (distance between chart widget edge and axes).
430 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
433 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
431 Deprecated. Use margins().
434 Deprecated. Use margins().
432 */
435 */
433 QMargins QChart::minimumMargins() const
436 QMargins QChart::minimumMargins() const
434 {
437 {
435 qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead.";
438 qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead.";
436 return d_ptr->m_presenter->layout()->margins();
439 return d_ptr->m_presenter->layout()->margins();
437 }
440 }
438
441
439 /*!
442 /*!
440 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
443 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
441 */
444 */
442 void QChart::setMargins(const QMargins &margins)
445 void QChart::setMargins(const QMargins &margins)
443 {
446 {
444 d_ptr->m_presenter->layout()->setMargins(margins);
447 d_ptr->m_presenter->layout()->setMargins(margins);
445 }
448 }
446
449
447 /*!
450 /*!
448 Returns the rect that contains information about margins (distance between chart widget edge and axes).
451 Returns the rect that contains information about margins (distance between chart widget edge and axes).
449 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
452 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
450 */
453 */
451 QMargins QChart::margins() const
454 QMargins QChart::margins() const
452 {
455 {
453 return d_ptr->m_presenter->layout()->margins();
456 return d_ptr->m_presenter->layout()->margins();
454 }
457 }
455
458
456 /*!
459 /*!
457 Returns the the rect within which the drawing of the chart is done.
460 Returns the the rect within which the drawing of the chart is done.
458 It does not include the area defines by margins.
461 It does not include the area defines by margins.
459 */
462 */
460 QRectF QChart::plotArea() const
463 QRectF QChart::plotArea() const
461 {
464 {
462 return d_ptr->m_presenter->geometry();
465 return d_ptr->m_presenter->geometry();
463 }
466 }
464
467
465 ///*!
468 ///*!
466 // TODO: Dummy.
469 // TODO: Dummy.
467 // Adjest the ranges of the axes so that all the data of the specified \a series is visible
470 // Adjest the ranges of the axes so that all the data of the specified \a series is visible
468 // */
471 // */
469 //void QChart::adjustViewToSeries(QAbstractSeries* series)
472 //void QChart::adjustViewToSeries(QAbstractSeries* series)
470 //{
473 //{
471 // //
474 // //
472 //}
475 //}
473
476
474 /*!
477 /*!
475 Sets animation \a options for the chart
478 Sets animation \a options for the chart
476 */
479 */
477 void QChart::setAnimationOptions(AnimationOptions options)
480 void QChart::setAnimationOptions(AnimationOptions options)
478 {
481 {
479 d_ptr->m_presenter->setAnimationOptions(options);
482 d_ptr->m_presenter->setAnimationOptions(options);
480 }
483 }
481
484
482 QChart::AnimationOptions QChart::animationOptions() const
485 QChart::AnimationOptions QChart::animationOptions() const
483 {
486 {
484 return d_ptr->m_presenter->animationOptions();
487 return d_ptr->m_presenter->animationOptions();
485 }
488 }
486
489
487 /*!
490 /*!
488 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
491 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
489 */
492 */
490 void QChart::scroll(qreal dx, qreal dy)
493 void QChart::scroll(qreal dx, qreal dy)
491 {
494 {
492 d_ptr->scroll(dx,dy);
495 d_ptr->scroll(dx,dy);
493 }
496 }
494
497
495 void QChart::setBackgroundVisible(bool visible)
498 void QChart::setBackgroundVisible(bool visible)
496 {
499 {
497 d_ptr->m_presenter->setBackgroundVisible(visible);
500 d_ptr->m_presenter->setBackgroundVisible(visible);
498 }
501 }
499
502
500 bool QChart::isBackgroundVisible() const
503 bool QChart::isBackgroundVisible() const
501 {
504 {
502 return d_ptr->m_presenter->isBackgroundVisible();
505 return d_ptr->m_presenter->isBackgroundVisible();
503 }
506 }
504
507
505 void QChart::setDropShadowEnabled(bool enabled)
508 void QChart::setDropShadowEnabled(bool enabled)
506 {
509 {
507 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
510 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
508 }
511 }
509
512
510 bool QChart::isDropShadowEnabled() const
513 bool QChart::isDropShadowEnabled() const
511 {
514 {
512 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
515 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
513 }
516 }
514
517
515 /*!
518 /*!
516 Returns all the series that are added to the chart.
519 Returns all the series that are added to the chart.
517
520
518 \sa addSeries(), removeSeries(), removeAllSeries()
521 \sa addSeries(), removeSeries(), removeAllSeries()
519 */
522 */
520 QList<QAbstractSeries *> QChart::series() const
523 QList<QAbstractSeries *> QChart::series() const
521 {
524 {
522 return d_ptr->m_dataset->series();
525 return d_ptr->m_dataset->series();
523 }
526 }
524
527
525 /*!
528 /*!
526 Sets \a axis to the chart, which will control the presentation of the \a series
529 Sets \a axis to the chart, which will control the presentation of the \a series
527
530
528 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
531 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
529 */
532 */
530 void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series)
533 void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series)
531 {
534 {
532 QList<QAbstractAxis*> list = axes(Qt::Horizontal,series);
535 QList<QAbstractAxis*> list = axes(Qt::Horizontal,series);
533
536
534 foreach(QAbstractAxis* a, list){
537 foreach(QAbstractAxis* a, list){
535 d_ptr->m_dataset->removeAxis(a);
538 d_ptr->m_dataset->removeAxis(a);
536 delete a;
539 delete a;
537 }
540 }
538
541
539 if(!d_ptr->m_dataset->axes().contains(axis))
542 if(!d_ptr->m_dataset->axes().contains(axis))
540 d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom);
543 d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom);
541 d_ptr->m_dataset->attachAxis(series,axis);
544 d_ptr->m_dataset->attachAxis(series,axis);
542 }
545 }
543
546
544 /*!
547 /*!
545 Sets \a axis to the chart, which will control the presentation of the \a series
548 Sets \a axis to the chart, which will control the presentation of the \a series
546
549
547 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
550 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
548 */
551 */
549 void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series)
552 void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series)
550 {
553 {
551 QList<QAbstractAxis*> list = axes(Qt::Vertical,series);
554 QList<QAbstractAxis*> list = axes(Qt::Vertical,series);
552
555
553 foreach(QAbstractAxis* a, list) {
556 foreach(QAbstractAxis* a, list) {
554 d_ptr->m_dataset->removeAxis(a);
557 d_ptr->m_dataset->removeAxis(a);
555 delete a;
558 delete a;
556 }
559 }
557
560
558 if(!d_ptr->m_dataset->axes().contains(axis))
561 if(!d_ptr->m_dataset->axes().contains(axis))
559 d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft);
562 d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft);
560 d_ptr->m_dataset->attachAxis(series,axis);
563 d_ptr->m_dataset->attachAxis(series,axis);
561 }
564 }
562
565
563 void QChart::addAxis(QAbstractAxis *axis,Qt::Alignment aligment)
566 void QChart::addAxis(QAbstractAxis *axis,Qt::Alignment aligment)
564 {
567 {
565 d_ptr->m_dataset->addAxis(axis,aligment);
568 d_ptr->m_dataset->addAxis(axis,aligment);
566 }
569 }
567
570
568 void QChart::removeAxis(QAbstractAxis *axis)
571 void QChart::removeAxis(QAbstractAxis *axis)
569 {
572 {
570 d_ptr->m_dataset->removeAxis(axis);
573 d_ptr->m_dataset->removeAxis(axis);
571 }
574 }
572
575
573 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
576 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
574
577
575 QChartPrivate::QChartPrivate(QChart *q):
578 QChartPrivate::QChartPrivate(QChart *q):
576 q_ptr(q),
579 q_ptr(q),
577 m_legend(0),
580 m_legend(0),
578 m_dataset(new ChartDataSet(q)),
581 m_dataset(new ChartDataSet(q)),
579 m_presenter(new ChartPresenter(q)),
582 m_presenter(new ChartPresenter(q)),
580 m_themeManager(new ChartThemeManager(q))
583 m_themeManager(new ChartThemeManager(q))
581 {
584 {
582 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
585 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
583 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
586 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
584 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*)));
587 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*)));
585 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
588 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
586 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*)));
589 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*)));
587 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*)));
590 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*)));
588 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*)));
591 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*)));
589 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*)));
592 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*)));
590 }
593 }
591
594
592 QChartPrivate::~QChartPrivate()
595 QChartPrivate::~QChartPrivate()
593 {
596 {
594
597
595 }
598 }
596
599
597 void QChartPrivate::zoomIn(qreal factor)
600 void QChartPrivate::zoomIn(qreal factor)
598 {
601 {
599 QRectF rect = m_presenter->geometry();
602 QRectF rect = m_presenter->geometry();
600 rect.setWidth(rect.width() / factor);
603 rect.setWidth(rect.width() / factor);
601 rect.setHeight(rect.height() / factor);
604 rect.setHeight(rect.height() / factor);
602 rect.moveCenter(m_presenter->geometry().center());
605 rect.moveCenter(m_presenter->geometry().center());
603 zoomIn(rect);
606 zoomIn(rect);
604 }
607 }
605
608
606 void QChartPrivate::zoomIn(const QRectF &rect)
609 void QChartPrivate::zoomIn(const QRectF &rect)
607 {
610 {
608 if (!rect.isValid())
611 if (!rect.isValid())
609 return;
612 return;
610
613
611 QRectF r = rect.normalized();
614 QRectF r = rect.normalized();
612 const QRectF geometry = m_presenter->geometry();
615 const QRectF geometry = m_presenter->geometry();
613 r.translate(-geometry.topLeft());
616 r.translate(-geometry.topLeft());
614
617
615 if (!r.isValid())
618 if (!r.isValid())
616 return;
619 return;
617
620
618 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
621 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
619 m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint);
622 m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint);
620 m_dataset->zoomInDomain(r);
623 m_dataset->zoomInDomain(r);
621 m_presenter->setState(ChartPresenter::ShowState,QPointF());
624 m_presenter->setState(ChartPresenter::ShowState,QPointF());
622
625
623 }
626 }
624
627
625 void QChartPrivate::zoomOut(qreal factor)
628 void QChartPrivate::zoomOut(qreal factor)
626 {
629 {
627 const QRectF geometry = m_presenter->geometry();
630 const QRectF geometry = m_presenter->geometry();
628
631
629 QRectF r;
632 QRectF r;
630 r.setSize(geometry.size() / factor);
633 r.setSize(geometry.size() / factor);
631 r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2));
634 r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2));
632 if (!r.isValid())
635 if (!r.isValid())
633 return;
636 return;
634
637
635 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
638 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
636 m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint);
639 m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint);
637 m_dataset->zoomOutDomain(r);
640 m_dataset->zoomOutDomain(r);
638 m_presenter->setState(ChartPresenter::ShowState,QPointF());
641 m_presenter->setState(ChartPresenter::ShowState,QPointF());
639 }
642 }
640
643
641 void QChartPrivate::scroll(qreal dx, qreal dy)
644 void QChartPrivate::scroll(qreal dx, qreal dy)
642 {
645 {
643 if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF());
646 if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF());
644 if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF());
647 if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF());
645 if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF());
648 if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF());
646 if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF());
649 if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF());
647
650
648 m_dataset->scrollDomain(dx, dy);
651 m_dataset->scrollDomain(dx, dy);
649 m_presenter->setState(ChartPresenter::ShowState,QPointF());
652 m_presenter->setState(ChartPresenter::ShowState,QPointF());
650 }
653 }
651
654
652 #include "moc_qchart.cpp"
655 #include "moc_qchart.cpp"
653
656
654 QTCOMMERCIALCHART_END_NAMESPACE
657 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,483 +1,398
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 #ifndef BUILD_PRIVATE_UNIT_TESTS
20 #ifndef BUILD_PRIVATE_UNIT_TESTS
21 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
22
22
23 class tst_ChartDataSet: public QObject {
23 class tst_ChartDataSet: public QObject {
24
24
25 Q_OBJECT
25 Q_OBJECT
26
26
27 private Q_SLOTS:
27 private Q_SLOTS:
28 void skip();
28 void skip();
29
29
30 };
30 };
31
31
32 void tst_ChartDataSet::skip()
32 void tst_ChartDataSet::skip()
33 {
33 {
34 QSKIP("This test requires the debug version of library", SkipAll);
34 QSKIP("This test requires the debug version of library", SkipAll);
35 }
35 }
36
36
37 QTEST_MAIN(tst_ChartDataSet)
37 QTEST_MAIN(tst_ChartDataSet)
38 #include "tst_chartdataset.moc"
38 #include "tst_chartdataset.moc"
39
39
40 #else
40 #else
41
41
42 #include <QtTest/QtTest>
42 #include <QtTest/QtTest>
43 #include <qabstractaxis.h>
43 #include <qabstractaxis.h>
44 #include <qvalueaxis.h>
44 #include <qvalueaxis.h>
45 #include <qbarcategoryaxis.h>
45 #include <qbarcategoryaxis.h>
46 #include <qcategoryaxis.h>
46 #include <qcategoryaxis.h>
47 #include <qdatetimeaxis.h>
47 #include <qdatetimeaxis.h>
48 #include <qlineseries.h>
48 #include <qlineseries.h>
49 #include <qareaseries.h>
49 #include <qareaseries.h>
50 #include <qscatterseries.h>
50 #include <qscatterseries.h>
51 #include <qsplineseries.h>
51 #include <qsplineseries.h>
52 #include <qpieseries.h>
52 #include <qpieseries.h>
53 #include <qbarseries.h>
53 #include <qbarseries.h>
54 #include <qpercentbarseries.h>
54 #include <qpercentbarseries.h>
55 #include <qstackedbarseries.h>
55 #include <qstackedbarseries.h>
56 #include <private/chartdataset_p.h>
56 #include <private/chartdataset_p.h>
57 #include <private/abstractdomain_p.h>
57 #include <private/abstractdomain_p.h>
58 #include <tst_definitions.h>
58 #include <tst_definitions.h>
59
59
60 QTCOMMERCIALCHART_USE_NAMESPACE
60 QTCOMMERCIALCHART_USE_NAMESPACE
61
61
62 Q_DECLARE_METATYPE(AbstractDomain *)
62 Q_DECLARE_METATYPE(AbstractDomain *)
63 Q_DECLARE_METATYPE(QAbstractAxis *)
63 Q_DECLARE_METATYPE(QAbstractAxis *)
64 Q_DECLARE_METATYPE(QAbstractSeries *)
64 Q_DECLARE_METATYPE(QAbstractSeries *)
65 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
65 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
66 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
66 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
67 Q_DECLARE_METATYPE(Qt::Alignment)
67 Q_DECLARE_METATYPE(Qt::Alignment)
68 Q_DECLARE_METATYPE(QList<Qt::Alignment>)
68 Q_DECLARE_METATYPE(QList<Qt::Alignment>)
69 Q_DECLARE_METATYPE(QLineSeries *)
69 Q_DECLARE_METATYPE(QLineSeries *)
70
70
71 class tst_ChartDataSet: public QObject {
71 class tst_ChartDataSet: public QObject {
72
72
73 Q_OBJECT
73 Q_OBJECT
74 public:
75 tst_ChartDataSet():m_dataset(0){};
74
76
75 public Q_SLOTS:
77 public Q_SLOTS:
76 void initTestCase();
78 void initTestCase();
77 void cleanupTestCase();
79 void cleanupTestCase();
78 void init();
80 void init();
79 void cleanup();
81 void cleanup();
80
82
81 private Q_SLOTS:
83 private Q_SLOTS:
82 void chartdataset_data();
84 void chartdataset_data();
83 void chartdataset();
85 void chartdataset();
84 void addSeries_data();
86 void addSeries_data();
85 void addSeries();
87 void addSeries();
86 void removeSeries_data();
88 void removeSeries_data();
87 void removeSeries();
89 void removeSeries();
88 void removeAllSeries_data();
89 void removeAllSeries();
90 void addAxis_data();
90 void addAxis_data();
91 void addAxis();
91 void addAxis();
92 void removeAxis_data();
92 void removeAxis_data();
93 void removeAxis();
93 void removeAxis();
94 void removeAllAxes_data();
95 void removeAllAxes();
96 void attachAxis_data();
94 void attachAxis_data();
97 void attachAxis();
95 void attachAxis();
98 void detachAxis_data();
96 void detachAxis_data();
99 void detachAxis();
97 void detachAxis();
100
98
101 private:
99 private:
102 ChartDataSet* m_dataset;
100 ChartDataSet* m_dataset;
103 };
101 };
104
102
105 void tst_ChartDataSet::initTestCase()
103 void tst_ChartDataSet::initTestCase()
106 {
104 {
107 qRegisterMetaType<AbstractDomain*>();
105 qRegisterMetaType<AbstractDomain*>();
108 qRegisterMetaType<QAbstractAxis*>();
106 qRegisterMetaType<QAbstractAxis*>();
109 qRegisterMetaType<QAbstractSeries*>();
107 qRegisterMetaType<QAbstractSeries*>();
110 }
108 }
111
109
112 void tst_ChartDataSet::cleanupTestCase()
110 void tst_ChartDataSet::cleanupTestCase()
113 {
111 {
114 }
112 }
115
113
116 void tst_ChartDataSet::init()
114 void tst_ChartDataSet::init()
117 {
115 {
116 Q_ASSERT(!m_dataset);
118 m_dataset = new ChartDataSet(0);
117 m_dataset = new ChartDataSet(0);
119 }
118 }
120
119
121
120
122 void tst_ChartDataSet::cleanup()
121 void tst_ChartDataSet::cleanup()
123 {
122 {
124 QList<QAbstractSeries*> series = m_dataset->series();
123 delete m_dataset;
125 foreach (QAbstractSeries* serie, series)
124 m_dataset=0;
126 {
127 m_dataset->removeSeries(serie);
128 }
129 }
125 }
130
126
131 void tst_ChartDataSet::chartdataset_data()
127 void tst_ChartDataSet::chartdataset_data()
132 {
128 {
133 }
129 }
134
130
135 void tst_ChartDataSet::chartdataset()
131 void tst_ChartDataSet::chartdataset()
136 {
132 {
137 QVERIFY(m_dataset->axes().isEmpty());
133 QVERIFY(m_dataset->axes().isEmpty());
138 QVERIFY(m_dataset->series().isEmpty());
134 QVERIFY(m_dataset->series().isEmpty());
139 m_dataset->createDefaultAxes();
135 m_dataset->createDefaultAxes();
140 }
136 }
141
137
142
138
143 void tst_ChartDataSet::addSeries_data()
139 void tst_ChartDataSet::addSeries_data()
144 {
140 {
145 QTest::addColumn<QAbstractSeries*>("series");
141 QTest::addColumn<QAbstractSeries*>("series");
146
142
147 QAbstractSeries* line = new QLineSeries(this);
143 QAbstractSeries* line = new QLineSeries(this);
148 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
149 QAbstractSeries* scatter = new QScatterSeries(this);
150 QAbstractSeries* spline = new QSplineSeries(this);
151 QAbstractSeries* pie = new QPieSeries(this);
152 QAbstractSeries* bar = new QBarSeries(this);
153 QAbstractSeries* percent = new QPercentBarSeries(this);
154 QAbstractSeries* stacked = new QStackedBarSeries(this);
155
156 QTest::newRow("line") << line;
144 QTest::newRow("line") << line;
145
146 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this)));
157 QTest::newRow("area") << area;
147 QTest::newRow("area") << area;
148
149 QAbstractSeries* scatter = new QScatterSeries(this);
158 QTest::newRow("scatter") << scatter;
150 QTest::newRow("scatter") << scatter;
151
152 QAbstractSeries* spline = new QSplineSeries(this);
159 QTest::newRow("spline") << spline;
153 QTest::newRow("spline") << spline;
154
155 QAbstractSeries* pie = new QPieSeries(this);
160 QTest::newRow("pie") << pie;
156 QTest::newRow("pie") << pie;
157
158 QAbstractSeries* bar = new QBarSeries(this);
161 QTest::newRow("bar") << bar;
159 QTest::newRow("bar") << bar;
160
161 QAbstractSeries* percent = new QPercentBarSeries(this);
162 QTest::newRow("percent") << percent;
162 QTest::newRow("percent") << percent;
163
164 QAbstractSeries* stacked = new QStackedBarSeries(this);
163 QTest::newRow("stacked") << stacked;
165 QTest::newRow("stacked") << stacked;
164 }
166 }
165
167
166 void tst_ChartDataSet::addSeries()
168 void tst_ChartDataSet::addSeries()
167 {
169 {
168 QFETCH(QAbstractSeries*, series);
170 QFETCH(QAbstractSeries*, series);
169 QVERIFY(m_dataset->series().isEmpty());
171 QVERIFY(m_dataset->series().isEmpty());
170
172
171 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
173 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
172 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
174 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
173 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
175 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
174 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
176 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
175
177
176 m_dataset->addSeries(series);
178 m_dataset->addSeries(series);
177
179
178
179 QCOMPARE(m_dataset->series().count(),1);
180 QCOMPARE(m_dataset->series().count(),1);
180 TRY_COMPARE(spy0.count(), 0);
181 TRY_COMPARE(spy0.count(), 0);
181 TRY_COMPARE(spy1.count(), 0);
182 TRY_COMPARE(spy1.count(), 0);
182 TRY_COMPARE(spy2.count(), 1);
183 TRY_COMPARE(spy2.count(), 1);
183 TRY_COMPARE(spy3.count(), 0);
184 TRY_COMPARE(spy3.count(), 0);
184 }
185 }
185
186
186 void tst_ChartDataSet::removeSeries_data()
187 void tst_ChartDataSet::removeSeries_data()
187 {
188 {
188 addSeries_data();
189 addSeries_data();
189 }
190 }
190
191
191 void tst_ChartDataSet::removeSeries()
192 void tst_ChartDataSet::removeSeries()
192 {
193 {
193 QFETCH(QAbstractSeries*, series);
194 QFETCH(QAbstractSeries*, series);
194 QVERIFY(m_dataset->series().isEmpty());
195 QVERIFY(m_dataset->series().isEmpty());
195 m_dataset->addSeries(series);
196 m_dataset->addSeries(series);
196
197
197 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
198 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
198 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
199 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
199 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
200 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
200 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
201 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
201
202
202 m_dataset->removeSeries(series);
203 m_dataset->removeSeries(series);
203
204
204 QCOMPARE(m_dataset->series().count(),0);
205 QCOMPARE(m_dataset->series().count(),0);
205 TRY_COMPARE(spy0.count(), 0);
206 TRY_COMPARE(spy0.count(), 0);
206 TRY_COMPARE(spy1.count(), 0);
207 TRY_COMPARE(spy1.count(), 0);
207 TRY_COMPARE(spy2.count(), 0);
208 TRY_COMPARE(spy2.count(), 0);
208 TRY_COMPARE(spy3.count(), 1);
209 TRY_COMPARE(spy3.count(), 1);
209 }
210 }
210
211
211 void tst_ChartDataSet::removeAllSeries_data()
212 {
213 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
214 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
215
216 QList<QAbstractSeries*> series;
217 QList<QAbstractAxis*> axis;
218
219 series << new QLineSeries(this) << new QSplineSeries(this) << new QScatterSeries(this);
220 axis << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this);
221
222 QTest::newRow("3 series , 3 axis") << series << axis;
223 }
224
225 void tst_ChartDataSet::removeAllSeries()
226 {
227 QFETCH(QList<QAbstractSeries*>, seriesList);
228 QFETCH(QList<QAbstractAxis*>, axisList);
229
230 QCOMPARE(m_dataset->series().count(),0);
231 QCOMPARE(m_dataset->axes().count(),0);
232
233 foreach (QAbstractSeries* series, seriesList) {
234 m_dataset->addSeries(series);
235 }
236
237 foreach (QAbstractAxis* axis, axisList) {
238 m_dataset->addAxis(axis,Qt::AlignBottom);
239 }
240
241 for (int i = 0; i < seriesList.count(); i++) {
242 m_dataset->attachAxis(seriesList.at(i),axisList.at(i));
243 }
244
245 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
246 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
247 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
248 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
249
250 m_dataset->removeAllSeries();
251
252 TRY_COMPARE(spy0.count(), 0);
253 TRY_COMPARE(spy1.count(), 0);
254 TRY_COMPARE(spy2.count(), 0);
255 TRY_COMPARE(spy3.count(), seriesList.count());
256
257 QCOMPARE(m_dataset->series().count(),0);
258 QCOMPARE(m_dataset->axes().count(),axisList.count());
259 }
260
261 void tst_ChartDataSet::addAxis_data()
212 void tst_ChartDataSet::addAxis_data()
262 {
213 {
263 QTest::addColumn<QAbstractAxis*>("axis");
214 QTest::addColumn<QAbstractAxis*>("axis");
264 QAbstractAxis* value = new QValueAxis(this);
215 QAbstractAxis* value = new QValueAxis(this);
265 QAbstractAxis* category = new QCategoryAxis(this);
216 QAbstractAxis* category = new QCategoryAxis(this);
266 QAbstractAxis* barcategory = new QBarCategoryAxis(this);
217 QAbstractAxis* barcategory = new QBarCategoryAxis(this);
267 QAbstractAxis* datetime = new QDateTimeAxis(this);
218 QAbstractAxis* datetime = new QDateTimeAxis(this);
268
219
269 QTest::newRow("value") << value;
220 QTest::newRow("value") << value;
270 QTest::newRow("category") << category;
221 QTest::newRow("category") << category;
271 QTest::newRow("barcategory") << barcategory;
222 QTest::newRow("barcategory") << barcategory;
272 QTest::newRow("datetime") << datetime;
223 QTest::newRow("datetime") << datetime;
273 }
224 }
274
225
275 void tst_ChartDataSet::addAxis()
226 void tst_ChartDataSet::addAxis()
276 {
227 {
277 QFETCH(QAbstractAxis*, axis);
228 QFETCH(QAbstractAxis*, axis);
278 QVERIFY(m_dataset->axes().isEmpty());
229 QVERIFY(m_dataset->axes().isEmpty());
279
230
280 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
231 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
281 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
232 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
282 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
233 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
283 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
234 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
284
235
285 m_dataset->addAxis(axis,Qt::AlignBottom);
236 m_dataset->addAxis(axis,Qt::AlignBottom);
286
237
287 QCOMPARE(m_dataset->axes().count(),1);
238 QCOMPARE(m_dataset->axes().count(),1);
288 TRY_COMPARE(spy0.count(), 1);
239 TRY_COMPARE(spy0.count(), 1);
289 TRY_COMPARE(spy1.count(), 0);
240 TRY_COMPARE(spy1.count(), 0);
290 TRY_COMPARE(spy2.count(), 0);
241 TRY_COMPARE(spy2.count(), 0);
291 TRY_COMPARE(spy3.count(), 0);
242 TRY_COMPARE(spy3.count(), 0);
292 }
243 }
293
244
294 void tst_ChartDataSet::removeAxis_data()
245 void tst_ChartDataSet::removeAxis_data()
295 {
246 {
296 addAxis_data();
247 addAxis_data();
297 }
248 }
298
249
299 void tst_ChartDataSet::removeAxis()
250 void tst_ChartDataSet::removeAxis()
300 {
251 {
301 QFETCH(QAbstractAxis*, axis);
252 QFETCH(QAbstractAxis*, axis);
302 QVERIFY(m_dataset->series().isEmpty());
253 QVERIFY(m_dataset->series().isEmpty());
303 m_dataset->addAxis(axis,Qt::AlignBottom);
254 m_dataset->addAxis(axis,Qt::AlignBottom);
304
255
305 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
256 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
306 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
257 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
307 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
258 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
308 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
259 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
309
260
310 m_dataset->removeAxis(axis);
261 m_dataset->removeAxis(axis);
311
262
312 QCOMPARE(m_dataset->series().count(),0);
263 QCOMPARE(m_dataset->series().count(),0);
313 TRY_COMPARE(spy0.count(), 0);
264 TRY_COMPARE(spy0.count(), 0);
314 TRY_COMPARE(spy1.count(), 1);
265 TRY_COMPARE(spy1.count(), 1);
315 TRY_COMPARE(spy2.count(), 0);
266 TRY_COMPARE(spy2.count(), 0);
316 TRY_COMPARE(spy3.count(), 0);
267 TRY_COMPARE(spy3.count(), 0);
317 }
268 }
318
269
319 void tst_ChartDataSet::removeAllAxes_data()
320 {
321 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
322 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
323
324 QList<QAbstractSeries*> series;
325 QList<QAbstractAxis*> axis;
326
327 series << new QLineSeries(this) << new QSplineSeries(this) << new QScatterSeries(this);
328 axis << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this);
329
330 QTest::newRow("3 series , 3 axis") << series << axis;
331 }
332
333 void tst_ChartDataSet::removeAllAxes()
334 {
335 QFETCH(QList<QAbstractSeries*>, seriesList);
336 QFETCH(QList<QAbstractAxis*>, axisList);
337
338 QCOMPARE(m_dataset->series().count(),0);
339 QCOMPARE(m_dataset->axes().count(),0);
340
341 foreach (QAbstractSeries* series, seriesList) {
342 m_dataset->addSeries(series);
343 }
344
345 foreach (QAbstractAxis* axis, axisList) {
346 m_dataset->addAxis(axis,Qt::AlignBottom);
347 }
348
349 for (int i = 0; i < seriesList.count(); i++) {
350 m_dataset->attachAxis(seriesList.at(i),axisList.at(i));
351 }
352
353 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
354 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
355 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
356 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
357
358 m_dataset->removeAllAxes();
359
360 TRY_COMPARE(spy0.count(), 0);
361 TRY_COMPARE(spy1.count(), axisList.count());
362 TRY_COMPARE(spy2.count(), 0);
363 TRY_COMPARE(spy3.count(), 0);
364
365 QCOMPARE(m_dataset->series().count(),seriesList.count());
366 QCOMPARE(m_dataset->axes().count(),0);
367 }
368
369 void tst_ChartDataSet::attachAxis_data()
270 void tst_ChartDataSet::attachAxis_data()
370 {
271 {
272
371 QTest::addColumn<QList<QAbstractSeries*> >("series");
273 QTest::addColumn<QList<QAbstractSeries*> >("series");
372 QTest::addColumn<QList<QAbstractAxis*> >("axis");
274 QTest::addColumn<QList<QAbstractAxis*> >("axis");
373 QTest::addColumn<QList<Qt::Alignment> >("alignment");
275 QTest::addColumn<QList<Qt::Alignment> >("alignment");
374 QTest::addColumn<QAbstractSeries*>("attachSeries");
276 QTest::addColumn<QAbstractSeries*>("attachSeries");
375 QTest::addColumn<QAbstractAxis*>("attachAxis");
277 QTest::addColumn<QAbstractAxis*>("attachAxis");
376 QTest::addColumn<bool>("success");
278 QTest::addColumn<bool>("success");
377
279
378 QList<QAbstractSeries*> series;
280 //QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
379 QList<QAbstractAxis*> axes;
380 QList<Qt::Alignment> alignment;
381
382 QAbstractSeries* line = new QLineSeries(this);
383 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
384 QAbstractSeries* scatter = new QScatterSeries(this);
281 QAbstractSeries* scatter = new QScatterSeries(this);
385 QAbstractSeries* spline = new QSplineSeries(this);
282 QAbstractSeries* spline = new QSplineSeries(this);
386 QAbstractSeries* pie = new QPieSeries(this);
283 QAbstractSeries* pie = new QPieSeries(this);
387 QAbstractSeries* bar = new QBarSeries(this);
284 QAbstractSeries* bar = new QBarSeries(this);
388 QAbstractSeries* percent = new QPercentBarSeries(this);
285 QAbstractSeries* percent = new QPercentBarSeries(this);
389 QAbstractSeries* stacked = new QStackedBarSeries(this);
286 QAbstractSeries* stacked = new QStackedBarSeries(this);
390
287
391 QAbstractAxis* value1 = new QValueAxis(this);
392 QAbstractAxis* value2 = new QValueAxis(this);
393 QAbstractAxis* category = new QCategoryAxis(this);
288 QAbstractAxis* category = new QCategoryAxis(this);
394 QAbstractAxis* barcategory = new QBarCategoryAxis(this);
289 QAbstractAxis* barcategory = new QBarCategoryAxis(this);
395 QAbstractAxis* datetime = new QDateTimeAxis(this);
290 QAbstractAxis* datetime = new QDateTimeAxis(this);
396
291
292 {
293 QList<QAbstractSeries*> series;
294 QList<QAbstractAxis*> axes;
295 QList<Qt::Alignment> alignment;
296 QAbstractSeries* line = new QLineSeries(this);
297 QAbstractAxis* value1 = new QValueAxis(this);
298 QAbstractAxis* value2 = new QValueAxis(this);
299 series << line << 0;
300 axes << value1 << value2;
301 alignment << Qt::AlignBottom << Qt::AlignLeft;
302 QTest::newRow("first") << series << axes << alignment << line << value2 << true ;
303 }
397
304
398 series << line << 0;
305 {
399 axes << value1 << value2;
306 QList<QAbstractSeries*> series;
400 alignment << Qt::AlignBottom << Qt::AlignLeft;
307 QList<QAbstractAxis*> axes;
401 QTest::newRow("line + two axes") << series << axes << alignment << line << value2 << true;
308 QList<Qt::Alignment> alignment;
309 QAbstractSeries* line = new QLineSeries(this);
310 QAbstractAxis* value1 = new QValueAxis(this);
311 QAbstractAxis* value2 = new QValueAxis(this);
312 series << 0 << line;
313 axes << value1 << value2;
314 alignment << Qt::AlignBottom << Qt::AlignLeft;
315 QTest::newRow("second") << series << axes << alignment << line << value1 << true;
316 }
402
317
403 }
318 }
404
319
405 void tst_ChartDataSet::attachAxis()
320 void tst_ChartDataSet::attachAxis()
406 {
321 {
407 QFETCH(QList<QAbstractSeries*>, series);
322 QFETCH(QList<QAbstractSeries*>, series);
408 QFETCH(QList<QAbstractAxis*>, axis);
323 QFETCH(QList<QAbstractAxis*>, axis);
409 QFETCH(QList<Qt::Alignment>, alignment);
324 QFETCH(QList<Qt::Alignment>, alignment);
410 QFETCH(QAbstractSeries*, attachSeries);
325 QFETCH(QAbstractSeries*, attachSeries);
411 QFETCH(QAbstractAxis*, attachAxis);
326 QFETCH(QAbstractAxis*, attachAxis);
412 QFETCH(bool, success);
327 QFETCH(bool, success);
413
328
414 Q_ASSERT(series.count() == axis.count());
329 Q_ASSERT(series.count() == axis.count());
415 Q_ASSERT(series.count() == alignment.count());
330 Q_ASSERT(series.count() == alignment.count());
416
331
417 QVERIFY(m_dataset->series().isEmpty());
332 QVERIFY(m_dataset->series().isEmpty());
418 QVERIFY(m_dataset->axes().isEmpty());
333 QVERIFY(m_dataset->axes().isEmpty());
419
334
420 for(int i = 0 ; i < series.count() ; i++){
335 for(int i = 0 ; i < series.count() ; i++){
421 if(series[i]) m_dataset->addSeries(series[i]);
336 if(series[i]) m_dataset->addSeries(series[i]);
422 if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]);
337 if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]);
423 if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]);
338 if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]);
424 }
339 }
425
340
426 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
341 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
427 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
342 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
428 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
343 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
429 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
344 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
430
345
431 QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success);
346 QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success);
432
347
433 }
348 }
434
349
435 void tst_ChartDataSet::detachAxis_data()
350 void tst_ChartDataSet::detachAxis_data()
436 {
351 {
437 QTest::addColumn<QList<QAbstractSeries*> >("series");
352 QTest::addColumn<QList<QAbstractSeries*> >("series");
438 QTest::addColumn<QList<QAbstractAxis*> >("axis");
353 QTest::addColumn<QList<QAbstractAxis*> >("axis");
439 QTest::addColumn<QAbstractSeries*>("detachSeries");
354 QTest::addColumn<QAbstractSeries*>("detachSeries");
440 QTest::addColumn<QAbstractAxis*>("detachAxis");
355 QTest::addColumn<QAbstractAxis*>("detachAxis");
441 QTest::addColumn<bool>("success");
356 QTest::addColumn<bool>("success");
442
357
358 {
443 QList<QAbstractSeries*> series;
359 QList<QAbstractSeries*> series;
444 QList<QAbstractAxis*> axes;
360 QList<QAbstractAxis*> axes;
445
446 QAbstractSeries* line = new QLineSeries(this);
361 QAbstractSeries* line = new QLineSeries(this);
447 QAbstractAxis* value = new QValueAxis(this);
362 QAbstractAxis* value = new QValueAxis(this);
448
449 series << line;
363 series << line;
450 axes << value;
364 axes << value;
451 QTest::newRow("line + axis") << series << axes << line << value << true;
365 QTest::newRow("first") << series << axes << line << value << true;
366 }
452 }
367 }
453
368
454 void tst_ChartDataSet::detachAxis()
369 void tst_ChartDataSet::detachAxis()
455 {
370 {
456 QFETCH(QList<QAbstractSeries*>, series);
371 QFETCH(QList<QAbstractSeries*>, series);
457 QFETCH(QList<QAbstractAxis*>, axis);
372 QFETCH(QList<QAbstractAxis*>, axis);
458 QFETCH(QAbstractSeries*, detachSeries);
373 QFETCH(QAbstractSeries*, detachSeries);
459 QFETCH(QAbstractAxis*, detachAxis);
374 QFETCH(QAbstractAxis*, detachAxis);
460 QFETCH(bool, success);
375 QFETCH(bool, success);
461
376
462 Q_ASSERT(series.count() == axis.count());
377 Q_ASSERT(series.count() == axis.count());
463
378
464 QVERIFY(m_dataset->series().isEmpty());
379 QVERIFY(m_dataset->series().isEmpty());
465 QVERIFY(m_dataset->axes().isEmpty());
380 QVERIFY(m_dataset->axes().isEmpty());
466
381
467 for(int i = 0; i < series.count(); i++) {
382 for(int i = 0; i < series.count(); i++) {
468 if(series[i]) m_dataset->addSeries(series[i]);
383 if(series[i]) m_dataset->addSeries(series[i]);
469 if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom);
384 if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom);
470 if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]);
385 if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]);
471 }
386 }
472
387
473 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
388 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
474 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
389 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
475 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
390 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
476 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
391 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
477
392
478 QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success);
393 QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success);
479 }
394 }
480
395
481 QTEST_MAIN(tst_ChartDataSet)
396 QTEST_MAIN(tst_ChartDataSet)
482 #include "tst_chartdataset.moc"
397 #include "tst_chartdataset.moc"
483 #endif
398 #endif
General Comments 0
You need to be logged in to leave comments. Login now