##// END OF EJS Templates
Docs fixes
Marek Rosa -
r1657:35717e93d7e0
parent child
Show More
@@ -1,627 +1,628
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qabstractaxis.h"
21 #include "qabstractaxis.h"
22 #include "qabstractaxis_p.h"
22 #include "qabstractaxis_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QAbstractAxis
27 \class QAbstractAxis
28 \brief The QAbstractAxis class is used for manipulating chart's axis.
28 \brief The QAbstractAxis class is used for manipulating chart's axis.
29 \mainclass
29 \mainclass
30
30
31 There is only one x Axis visible at the time, however there can be multiple y axes.
31 There is only one x Axis visible at the time, however there can be multiple y axes.
32 Each chart series can be bound to exactly one Y axis and the shared common X axis.
32 Each chart series can be bound to exactly one Y axis and the shared common X axis.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 */
34 */
35
35
36 /*!
36 /*!
37 \qmlclass AbstractAxis QAbstractAxis
37 \qmlclass AbstractAxis QAbstractAxis
38 \brief The Axis element is used for manipulating chart's axes
38 \brief The Axis element is used for manipulating chart's axes
39
39
40 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
40 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
41 Each chart series can be bound to exactly one Y axis and the shared common X axis.
41 Each chart series can be bound to exactly one Y axis and the shared common X axis.
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
43
43
44 To access Axes you can use ChartView API. For example:
44 To access Axes you can use ChartView API. For example:
45 \code
45 \code
46 ChartView {
46 ChartView {
47 axisX.min: 0
47 axisX.min: 0
48 axisX.max: 3
48 axisX.max: 3
49 axisX.ticksCount: 4
49 axisX.ticksCount: 4
50 axisY.min: 0
50 axisY.min: 0
51 axisY.max: 4
51 axisY.max: 4
52 // Add a few series...
52 // Add a few series...
53 }
53 }
54 \endcode
54 \endcode
55 */
55 */
56
56
57 /*!
57 /*!
58 \enum QAbstractAxis::AxisType
58 \enum QAbstractAxis::AxisType
59
59
60 The type of the series object.
60 The type of the series object.
61
61
62 \value AxisTypeNoAxis
62 \value AxisTypeNoAxis
63 \value AxisTypeValues
63 \value AxisTypeValues
64 \value AxisTypeCategories
64 \value AxisTypeCategories
65 */
65 */
66
66
67 /*!
67 /*!
68 *\fn void QAbstractAxis::type() const
68 *\fn void QAbstractAxis::type() const
69 Returns the type of the axis
69 Returns the type of the axis
70 */
70 */
71
71
72 /*!
72 /*!
73 \property QAbstractAxis::arrowVisible
73 \property QAbstractAxis::arrowVisible
74 The visibility of the axis arrow
74 The visibility of the axis arrow
75 */
75 */
76 /*!
76 /*!
77 \qmlproperty bool AbstractAxis::arrrowVisible
77 \qmlproperty bool AbstractAxis::arrrowVisible
78 The visibility of the axis arrow
78 The visibility of the axis arrow
79 */
79 */
80
80
81 /*!
81 /*!
82 \property QAbstractAxis::labelsVisible
82 \property QAbstractAxis::labelsVisible
83 Defines if axis labels are visible.
83 Defines if axis labels are visible.
84 */
84 */
85 /*!
85 /*!
86 \qmlproperty bool AbstractAxis::labelsVisible
86 \qmlproperty bool AbstractAxis::labelsVisible
87 Defines if axis labels are visible.
87 Defines if axis labels are visible.
88 */
88 */
89
89
90 /*!
90 /*!
91 \property QAbstractAxis::visible
91 \property QAbstractAxis::visible
92 The visibility of the axis.
92 The visibility of the axis.
93 */
93 */
94 /*!
94 /*!
95 \qmlproperty bool AbstractAxis::visible
95 \qmlproperty bool AbstractAxis::visible
96 The visibility of the axis.
96 The visibility of the axis.
97 */
97 */
98
98
99 /*!
99 /*!
100 \property QAbstractAxis::gridVisible
100 \property QAbstractAxis::gridVisible
101 The visibility of the grid lines.
101 The visibility of the grid lines.
102 */
102 */
103 /*!
103 /*!
104 \qmlproperty bool AbstractAxis::gridVisible
104 \qmlproperty bool AbstractAxis::gridVisible
105 The visibility of the grid lines.
105 The visibility of the grid lines.
106 */
106 */
107
107
108 /*!
108 /*!
109 \property QAbstractAxis::color
109 \property QAbstractAxis::color
110 The color of the axis and ticks.
110 The color of the axis and ticks.
111 */
111 */
112 /*!
112 /*!
113 \qmlproperty color AbstractAxis::color
113 \qmlproperty color AbstractAxis::color
114 The color of the axis and ticks.
114 The color of the axis and ticks.
115 */
115 */
116
116
117 /*!
117 /*!
118 \property QAbstractAxis::labelsFont
118 \property QAbstractAxis::labelsFont
119 The font of the axis labels.
119 The font of the axis labels.
120 */
120 */
121
121
122 /*!
122 /*!
123 \qmlproperty Font AbstractAxis::labelsFont
123 \qmlproperty Font AbstractAxis::labelsFont
124 The font of the axis labels.
124 The font of the axis labels.
125
125
126 See the \l {Font} {QML Font Element} for detailed documentation.
126 See the \l {Font} {QML Font Element} for detailed documentation.
127 */
127 */
128
128
129 /*!
129 /*!
130 \property QAbstractAxis::labelsColor
130 \property QAbstractAxis::labelsColor
131 The color of the axis labels.
131 The color of the axis labels.
132 */
132 */
133 /*!
133 /*!
134 \qmlproperty color AbstractAxis::labelsColor
134 \qmlproperty color AbstractAxis::labelsColor
135 The color of the axis labels.
135 The color of the axis labels.
136 */
136 */
137
137
138 /*!
138 /*!
139 \property QAbstractAxis::labelsAngle
139 \property QAbstractAxis::labelsAngle
140 The angle of the axis labels in degrees.
140 The angle of the axis labels in degrees.
141 */
141 */
142 /*!
142 /*!
143 \qmlproperty int AbstractAxis::labelsAngle
143 \qmlproperty int AbstractAxis::labelsAngle
144 The angle of the axis labels in degrees.
144 The angle of the axis labels in degrees.
145 */
145 */
146
146
147 /*!
147 /*!
148 \property QAbstractAxis::shadesVisible
148 \property QAbstractAxis::shadesVisible
149 The visibility of the axis shades.
149 The visibility of the axis shades.
150 */
150 */
151 /*!
151 /*!
152 \qmlproperty bool AbstractAxis::shadesVisible
152 \qmlproperty bool AbstractAxis::shadesVisible
153 The visibility of the axis shades.
153 The visibility of the axis shades.
154 */
154 */
155
155
156 /*!
156 /*!
157 \property QAbstractAxis::shadesColor
157 \property QAbstractAxis::shadesColor
158 The fill (brush) color of the axis shades.
158 The fill (brush) color of the axis shades.
159 */
159 */
160 /*!
160 /*!
161 \qmlproperty color AbstractAxis::shadesColor
161 \qmlproperty color AbstractAxis::shadesColor
162 The fill (brush) color of the axis shades.
162 The fill (brush) color of the axis shades.
163 */
163 */
164
164
165 /*!
165 /*!
166 \property QAbstractAxis::shadesBorderColor
166 \property QAbstractAxis::shadesBorderColor
167 The border (pen) color of the axis shades.
167 The border (pen) color of the axis shades.
168 */
168 */
169 /*!
169 /*!
170 \qmlproperty color AbstractAxis::shadesBorderColor
170 \qmlproperty color AbstractAxis::shadesBorderColor
171 The border (pen) color of the axis shades.
171 The border (pen) color of the axis shades.
172 */
172 */
173
173
174 /*!
174 /*!
175 \fn void QAbstractAxis::visibleChanged(bool visible)
175 \fn void QAbstractAxis::visibleChanged(bool visible)
176 Visiblity of the axis has changed to \a visible.
176 Visiblity of the axis has changed to \a visible.
177 */
177 */
178 /*!
178 /*!
179 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
179 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
180 Visiblity of the axis has changed to \a visible.
180 Visiblity of the axis has changed to \a visible.
181 */
181 */
182
182
183 /*!
183 /*!
184 \fn void QAbstractAxis::arrowVisibleChanged(bool visible)
184 \fn void QAbstractAxis::arrowVisibleChanged(bool visible)
185 Visiblity of the axis arrow has changed to \a visible.
185 Visiblity of the axis arrow has changed to \a visible.
186 */
186 */
187 /*!
187 /*!
188 \qmlsignal AbstractAxis::onArrowVisibleChanged(bool visible)
188 \qmlsignal AbstractAxis::onArrowVisibleChanged(bool visible)
189 Visiblity of the axis arrow has changed to \a visible.
189 Visiblity of the axis arrow has changed to \a visible.
190 */
190 */
191
191
192 /*!
192 /*!
193 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
193 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
194 Visiblity of the labels of the axis has changed to \a visible.
194 Visiblity of the labels of the axis has changed to \a visible.
195 */
195 */
196 /*!
196 /*!
197 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
197 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
198 Visiblity of the labels of the axis has changed to \a visible.
198 Visiblity of the labels of the axis has changed to \a visible.
199 */
199 */
200
200
201 /*!
201 /*!
202 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
202 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
203 Visiblity of the grid lines of the axis has changed to \a visible.
203 Visiblity of the grid lines of the axis has changed to \a visible.
204 */
204 */
205 /*!
205 /*!
206 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
206 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
207 Visiblity of the grid lines of the axis has changed to \a visible.
207 Visiblity of the grid lines of the axis has changed to \a visible.
208 */
208 */
209
209
210 /*!
210 /*!
211 \fn void QAbstractAxis::colorChanged(QColor color)
211 \fn void QAbstractAxis::colorChanged(QColor color)
212 Emitted if the \a color of the axis is changed.
212 Emitted if the \a color of the axis is changed.
213 */
213 */
214 /*!
214 /*!
215 \qmlsignal AbstractAxis::onColorChanged(QColor color)
215 \qmlsignal AbstractAxis::onColorChanged(QColor color)
216 Emitted if the \a color of the axis is changed.
216 Emitted if the \a color of the axis is changed.
217 */
217 */
218
218
219 /*!
219 /*!
220 \fn void QAbstractAxis::labelsColorChanged(QColor color)
220 \fn void QAbstractAxis::labelsColorChanged(QColor color)
221 Emitted if the \a color of the axis labels is changed.
221 Emitted if the \a color of the axis labels is changed.
222 */
222 */
223 /*!
223 /*!
224 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
224 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
225 Emitted if the \a color of the axis labels is changed.
225 Emitted if the \a color of the axis labels is changed.
226 */
226 */
227
227
228 /*!
228 /*!
229 \fn void QAbstractAxis::shadesVisibleChanged(bool)
229 \fn void QAbstractAxis::shadesVisibleChanged(bool)
230 Emitted if the visibility of the axis shades is changed to \a visible.
230 Emitted if the visibility of the axis shades is changed to \a visible.
231 */
231 */
232 /*!
232 /*!
233 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
233 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
234 Emitted if the visibility of the axis shades is changed to \a visible.
234 Emitted if the visibility of the axis shades is changed to \a visible.
235 */
235 */
236
236
237 /*!
237 /*!
238 \fn void QAbstractAxis::shadesColorChanged(QColor color)
238 \fn void QAbstractAxis::shadesColorChanged(QColor color)
239 Emitted if the \a color of the axis shades is changed.
239 Emitted if the \a color of the axis shades is changed.
240 */
240 */
241 /*!
241 /*!
242 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
242 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
243 Emitted if the \a color of the axis shades is changed.
243 Emitted if the \a color of the axis shades is changed.
244 */
244 */
245
245
246 /*!
246 /*!
247 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
247 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
248 Emitted if the border \a color of the axis shades is changed.
248 Emitted if the border \a color of the axis shades is changed.
249 */
249 */
250 /*!
250 /*!
251 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
251 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
252 Emitted if the border \a color of the axis shades is changed.
252 Emitted if the border \a color of the axis shades is changed.
253 */
253 */
254
254
255 /*!
255 /*!
256 \internal
256 Constructs new axis object which is a child of \a parent. Ownership is taken by
257 Constructs new axis object which is a child of \a parent. Ownership is taken by
257 QChart when axis added.
258 QChart when axis added.
258 */
259 */
259
260
260 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) :
261 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) :
261 QObject(parent),
262 QObject(parent),
262 d_ptr(&d)
263 d_ptr(&d)
263 {
264 {
264 }
265 }
265
266
266 /*!
267 /*!
267 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
268 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
268 */
269 */
269
270
270 QAbstractAxis::~QAbstractAxis()
271 QAbstractAxis::~QAbstractAxis()
271 {
272 {
272 }
273 }
273
274
274 /*!
275 /*!
275 Sets \a pen used to draw axis line and ticks.
276 Sets \a pen used to draw axis line and ticks.
276 */
277 */
277 void QAbstractAxis::setAxisPen(const QPen &pen)
278 void QAbstractAxis::setAxisPen(const QPen &pen)
278 {
279 {
279 if (d_ptr->m_axisPen!=pen) {
280 if (d_ptr->m_axisPen!=pen) {
280 d_ptr->m_axisPen = pen;
281 d_ptr->m_axisPen = pen;
281 emit d_ptr->updated();
282 emit d_ptr->updated();
282 }
283 }
283 }
284 }
284
285
285 /*!
286 /*!
286 Returns pen used to draw axis and ticks.
287 Returns pen used to draw axis and ticks.
287 */
288 */
288 QPen QAbstractAxis::axisPen() const
289 QPen QAbstractAxis::axisPen() const
289 {
290 {
290 return d_ptr->m_axisPen;
291 return d_ptr->m_axisPen;
291 }
292 }
292
293
293 void QAbstractAxis::setAxisPenColor(QColor color)
294 void QAbstractAxis::setAxisPenColor(QColor color)
294 {
295 {
295 QPen p = d_ptr->m_axisPen;
296 QPen p = d_ptr->m_axisPen;
296 if (p.color() != color) {
297 if (p.color() != color) {
297 p.setColor(color);
298 p.setColor(color);
298 setAxisPen(p);
299 setAxisPen(p);
299 emit colorChanged(color);
300 emit colorChanged(color);
300 }
301 }
301 }
302 }
302
303
303 QColor QAbstractAxis::axisPenColor() const
304 QColor QAbstractAxis::axisPenColor() const
304 {
305 {
305 return d_ptr->m_axisPen.color();
306 return d_ptr->m_axisPen.color();
306 }
307 }
307
308
308 /*!
309 /*!
309 Sets if axis and ticks are \a visible.
310 Sets if axis and ticks are \a visible.
310 */
311 */
311 void QAbstractAxis::setArrowVisible(bool visible)
312 void QAbstractAxis::setArrowVisible(bool visible)
312 {
313 {
313 if (d_ptr->m_arrowVisible != visible) {
314 if (d_ptr->m_arrowVisible != visible) {
314 d_ptr->m_arrowVisible = visible;
315 d_ptr->m_arrowVisible = visible;
315 emit d_ptr->updated();
316 emit d_ptr->updated();
316 emit arrowVisibleChanged(visible);
317 emit arrowVisibleChanged(visible);
317 }
318 }
318 }
319 }
319
320
320 bool QAbstractAxis::isArrowVisible() const
321 bool QAbstractAxis::isArrowVisible() const
321 {
322 {
322 return d_ptr->m_arrowVisible;
323 return d_ptr->m_arrowVisible;
323 }
324 }
324
325
325 void QAbstractAxis::setGridLineVisible(bool visible)
326 void QAbstractAxis::setGridLineVisible(bool visible)
326 {
327 {
327 if (d_ptr->m_gridLineVisible != visible) {
328 if (d_ptr->m_gridLineVisible != visible) {
328 d_ptr->m_gridLineVisible = visible;
329 d_ptr->m_gridLineVisible = visible;
329 emit d_ptr->updated();
330 emit d_ptr->updated();
330 emit gridVisibleChanged(visible);
331 emit gridVisibleChanged(visible);
331 }
332 }
332 }
333 }
333
334
334 bool QAbstractAxis::isGridLineVisible() const
335 bool QAbstractAxis::isGridLineVisible() const
335 {
336 {
336 return d_ptr->m_gridLineVisible;
337 return d_ptr->m_gridLineVisible;
337 }
338 }
338
339
339 /*!
340 /*!
340 Sets \a pen used to draw grid line.
341 Sets \a pen used to draw grid line.
341 */
342 */
342 void QAbstractAxis::setGridLinePen(const QPen &pen)
343 void QAbstractAxis::setGridLinePen(const QPen &pen)
343 {
344 {
344 if (d_ptr->m_gridLinePen != pen) {
345 if (d_ptr->m_gridLinePen != pen) {
345 d_ptr->m_gridLinePen = pen;
346 d_ptr->m_gridLinePen = pen;
346 emit d_ptr->updated();
347 emit d_ptr->updated();
347 }
348 }
348 }
349 }
349
350
350 /*!
351 /*!
351 Returns pen used to draw grid.
352 Returns pen used to draw grid.
352 */
353 */
353 QPen QAbstractAxis::gridLinePen() const
354 QPen QAbstractAxis::gridLinePen() const
354 {
355 {
355 return d_ptr->m_gridLinePen;
356 return d_ptr->m_gridLinePen;
356 }
357 }
357
358
358 void QAbstractAxis::setLabelsVisible(bool visible)
359 void QAbstractAxis::setLabelsVisible(bool visible)
359 {
360 {
360 if (d_ptr->m_labelsVisible != visible) {
361 if (d_ptr->m_labelsVisible != visible) {
361 d_ptr->m_labelsVisible = visible;
362 d_ptr->m_labelsVisible = visible;
362 emit d_ptr->updated();
363 emit d_ptr->updated();
363 emit labelsVisibleChanged(visible);
364 emit labelsVisibleChanged(visible);
364 }
365 }
365 }
366 }
366
367
367 bool QAbstractAxis::labelsVisible() const
368 bool QAbstractAxis::labelsVisible() const
368 {
369 {
369 return d_ptr->m_labelsVisible;
370 return d_ptr->m_labelsVisible;
370 }
371 }
371
372
372 /*!
373 /*!
373 Sets \a pen used to draw labels.
374 Sets \a pen used to draw labels.
374 */
375 */
375 void QAbstractAxis::setLabelsPen(const QPen &pen)
376 void QAbstractAxis::setLabelsPen(const QPen &pen)
376 {
377 {
377 if (d_ptr->m_labelsPen != pen) {
378 if (d_ptr->m_labelsPen != pen) {
378 d_ptr->m_labelsPen = pen;
379 d_ptr->m_labelsPen = pen;
379 emit d_ptr->updated();
380 emit d_ptr->updated();
380 }
381 }
381 }
382 }
382
383
383 /*!
384 /*!
384 Returns the pen used to labels.
385 Returns the pen used to labels.
385 */
386 */
386 QPen QAbstractAxis::labelsPen() const
387 QPen QAbstractAxis::labelsPen() const
387 {
388 {
388 return d_ptr->m_labelsPen;
389 return d_ptr->m_labelsPen;
389 }
390 }
390
391
391 /*!
392 /*!
392 Sets \a brush used to draw labels.
393 Sets \a brush used to draw labels.
393 */
394 */
394 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
395 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
395 {
396 {
396 if (d_ptr->m_labelsBrush != brush) {
397 if (d_ptr->m_labelsBrush != brush) {
397 d_ptr->m_labelsBrush = brush;
398 d_ptr->m_labelsBrush = brush;
398 emit d_ptr->updated();
399 emit d_ptr->updated();
399 }
400 }
400 }
401 }
401
402
402 /*!
403 /*!
403 Returns brush used to draw labels.
404 Returns brush used to draw labels.
404 */
405 */
405 QBrush QAbstractAxis::labelsBrush() const
406 QBrush QAbstractAxis::labelsBrush() const
406 {
407 {
407 return d_ptr->m_labelsBrush;
408 return d_ptr->m_labelsBrush;
408 }
409 }
409
410
410 /*!
411 /*!
411 Sets \a font used to draw labels.
412 Sets \a font used to draw labels.
412 */
413 */
413 void QAbstractAxis::setLabelsFont(const QFont &font)
414 void QAbstractAxis::setLabelsFont(const QFont &font)
414 {
415 {
415 if (d_ptr->m_labelsFont != font) {
416 if (d_ptr->m_labelsFont != font) {
416 d_ptr->m_labelsFont = font;
417 d_ptr->m_labelsFont = font;
417 emit d_ptr->updated();
418 emit d_ptr->updated();
418 }
419 }
419 }
420 }
420
421
421 /*!
422 /*!
422 Returns font used to draw labels.
423 Returns font used to draw labels.
423 */
424 */
424 QFont QAbstractAxis::labelsFont() const
425 QFont QAbstractAxis::labelsFont() const
425 {
426 {
426 return d_ptr->m_labelsFont;
427 return d_ptr->m_labelsFont;
427 }
428 }
428
429
429 void QAbstractAxis::setLabelsAngle(int angle)
430 void QAbstractAxis::setLabelsAngle(int angle)
430 {
431 {
431 if (d_ptr->m_labelsAngle != angle) {
432 if (d_ptr->m_labelsAngle != angle) {
432 d_ptr->m_labelsAngle = angle;
433 d_ptr->m_labelsAngle = angle;
433 emit d_ptr->updated();
434 emit d_ptr->updated();
434 }
435 }
435 }
436 }
436
437
437 int QAbstractAxis::labelsAngle() const
438 int QAbstractAxis::labelsAngle() const
438 {
439 {
439 return d_ptr->m_labelsAngle;
440 return d_ptr->m_labelsAngle;
440 }
441 }
441
442
442 void QAbstractAxis::setLabelsColor(QColor color)
443 void QAbstractAxis::setLabelsColor(QColor color)
443 {
444 {
444 QBrush b = d_ptr->m_labelsBrush;
445 QBrush b = d_ptr->m_labelsBrush;
445 if (b.color() != color) {
446 if (b.color() != color) {
446 b.setColor(color);
447 b.setColor(color);
447 setLabelsBrush(b);
448 setLabelsBrush(b);
448 emit labelsColorChanged(color);
449 emit labelsColorChanged(color);
449 }
450 }
450 }
451 }
451
452
452 QColor QAbstractAxis::labelsColor() const
453 QColor QAbstractAxis::labelsColor() const
453 {
454 {
454 return d_ptr->m_labelsBrush.color();
455 return d_ptr->m_labelsBrush.color();
455 }
456 }
456
457
457 void QAbstractAxis::setShadesVisible(bool visible)
458 void QAbstractAxis::setShadesVisible(bool visible)
458 {
459 {
459 if (d_ptr->m_shadesVisible != visible) {
460 if (d_ptr->m_shadesVisible != visible) {
460 d_ptr->m_shadesVisible = visible;
461 d_ptr->m_shadesVisible = visible;
461 emit d_ptr->updated();
462 emit d_ptr->updated();
462 emit shadesVisibleChanged(visible);
463 emit shadesVisibleChanged(visible);
463 }
464 }
464 }
465 }
465
466
466 bool QAbstractAxis::shadesVisible() const
467 bool QAbstractAxis::shadesVisible() const
467 {
468 {
468 return d_ptr->m_shadesVisible;
469 return d_ptr->m_shadesVisible;
469 }
470 }
470
471
471 /*!
472 /*!
472 Sets \a pen used to draw shades.
473 Sets \a pen used to draw shades.
473 */
474 */
474 void QAbstractAxis::setShadesPen(const QPen &pen)
475 void QAbstractAxis::setShadesPen(const QPen &pen)
475 {
476 {
476 if (d_ptr->m_shadesPen != pen) {
477 if (d_ptr->m_shadesPen != pen) {
477 d_ptr->m_shadesPen = pen;
478 d_ptr->m_shadesPen = pen;
478 emit d_ptr->updated();
479 emit d_ptr->updated();
479 }
480 }
480 }
481 }
481
482
482 /*!
483 /*!
483 Returns pen used to draw shades.
484 Returns pen used to draw shades.
484 */
485 */
485 QPen QAbstractAxis::shadesPen() const
486 QPen QAbstractAxis::shadesPen() const
486 {
487 {
487 return d_ptr->m_shadesPen;
488 return d_ptr->m_shadesPen;
488 }
489 }
489
490
490 /*!
491 /*!
491 Sets \a brush used to draw shades.
492 Sets \a brush used to draw shades.
492 */
493 */
493 void QAbstractAxis::setShadesBrush(const QBrush &brush)
494 void QAbstractAxis::setShadesBrush(const QBrush &brush)
494 {
495 {
495 if (d_ptr->m_shadesBrush != brush) {
496 if (d_ptr->m_shadesBrush != brush) {
496 d_ptr->m_shadesBrush = brush;
497 d_ptr->m_shadesBrush = brush;
497 emit d_ptr->updated();
498 emit d_ptr->updated();
498 emit shadesColorChanged(brush.color());
499 emit shadesColorChanged(brush.color());
499 }
500 }
500 }
501 }
501
502
502 /*!
503 /*!
503 Returns brush used to draw shades.
504 Returns brush used to draw shades.
504 */
505 */
505 QBrush QAbstractAxis::shadesBrush() const
506 QBrush QAbstractAxis::shadesBrush() const
506 {
507 {
507 return d_ptr->m_shadesBrush;
508 return d_ptr->m_shadesBrush;
508 }
509 }
509
510
510 void QAbstractAxis::setShadesColor(QColor color)
511 void QAbstractAxis::setShadesColor(QColor color)
511 {
512 {
512 QBrush b = d_ptr->m_shadesBrush;
513 QBrush b = d_ptr->m_shadesBrush;
513 b.setColor(color);
514 b.setColor(color);
514 setShadesBrush(b);
515 setShadesBrush(b);
515 }
516 }
516
517
517 QColor QAbstractAxis::shadesColor() const
518 QColor QAbstractAxis::shadesColor() const
518 {
519 {
519 return d_ptr->m_shadesBrush.color();
520 return d_ptr->m_shadesBrush.color();
520 }
521 }
521
522
522 void QAbstractAxis::setShadesBorderColor(QColor color)
523 void QAbstractAxis::setShadesBorderColor(QColor color)
523 {
524 {
524 QPen p = d_ptr->m_shadesPen;
525 QPen p = d_ptr->m_shadesPen;
525 p.setColor(color);
526 p.setColor(color);
526 setShadesPen(p);
527 setShadesPen(p);
527 }
528 }
528
529
529 QColor QAbstractAxis::shadesBorderColor() const
530 QColor QAbstractAxis::shadesBorderColor() const
530 {
531 {
531 return d_ptr->m_shadesPen.color();
532 return d_ptr->m_shadesPen.color();
532 }
533 }
533
534
534
535
535 bool QAbstractAxis::isVisible() const
536 bool QAbstractAxis::isVisible() const
536 {
537 {
537 return d_ptr->m_visible;
538 return d_ptr->m_visible;
538 }
539 }
539
540
540 /*!
541 /*!
541 Sets axis, shades, labels and grid lines to be visible.
542 Sets axis, shades, labels and grid lines to be visible.
542 */
543 */
543 void QAbstractAxis::setVisible(bool visible)
544 void QAbstractAxis::setVisible(bool visible)
544 {
545 {
545 if(d_ptr->m_visible!=visible){
546 if(d_ptr->m_visible!=visible){
546 d_ptr->m_visible=visible;
547 d_ptr->m_visible=visible;
547 emit visibleChanged(visible);
548 emit visibleChanged(visible);
548 emit d_ptr->updated();
549 emit d_ptr->updated();
549 }
550 }
550 }
551 }
551
552
552
553
553 /*!
554 /*!
554 Sets axis, shades, labels and grid lines to be visible.
555 Sets axis, shades, labels and grid lines to be visible.
555 */
556 */
556 void QAbstractAxis::show()
557 void QAbstractAxis::show()
557 {
558 {
558 setVisible(true);
559 setVisible(true);
559 }
560 }
560
561
561 /*!
562 /*!
562 Sets axis, shades, labels and grid lines to not be visible.
563 Sets axis, shades, labels and grid lines to not be visible.
563 */
564 */
564 void QAbstractAxis::hide()
565 void QAbstractAxis::hide()
565 {
566 {
566 setVisible(false);
567 setVisible(false);
567 }
568 }
568
569
569 /*!
570 /*!
570 Sets the minimum value shown on the axis.
571 Sets the minimum value shown on the axis.
571 Depending on the actual axis type the \a min paramter is converted to appropriate type.
572 Depending on the actual axis type the \a min paramter is converted to appropriate type.
572 If the conversion is impossible then the function call does nothing
573 If the conversion is impossible then the function call does nothing
573 */
574 */
574 void QAbstractAxis::setMin(const QVariant &min)
575 void QAbstractAxis::setMin(const QVariant &min)
575 {
576 {
576 d_ptr->setMin(min);
577 d_ptr->setMin(min);
577 }
578 }
578
579
579 /*!
580 /*!
580 Sets the maximum value shown on the axis.
581 Sets the maximum value shown on the axis.
581 Depending on the actual axis type the \a max paramter is converted to appropriate type.
582 Depending on the actual axis type the \a max paramter is converted to appropriate type.
582 If the conversion is impossible then the function call does nothing
583 If the conversion is impossible then the function call does nothing
583 */
584 */
584 void QAbstractAxis::setMax(const QVariant &max)
585 void QAbstractAxis::setMax(const QVariant &max)
585 {
586 {
586 d_ptr->setMax(max);
587 d_ptr->setMax(max);
587 }
588 }
588
589
589 /*!
590 /*!
590 Sets the range shown on the axis.
591 Sets the range shown on the axis.
591 Depending on the actual axis type the \a min and \a max paramters are converted to appropriate types.
592 Depending on the actual axis type the \a min and \a max paramters are converted to appropriate types.
592 If the conversion is impossible then the function call does nothing.
593 If the conversion is impossible then the function call does nothing.
593 */
594 */
594 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
595 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
595 {
596 {
596 d_ptr->setRange(min,max);
597 d_ptr->setRange(min,max);
597 }
598 }
598
599
599 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
600 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
600
601
601 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
602 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
602 q_ptr(q),
603 q_ptr(q),
603 m_visible(false),
604 m_visible(false),
604 m_arrowVisible(true),
605 m_arrowVisible(true),
605 m_gridLineVisible(true),
606 m_gridLineVisible(true),
606 m_labelsVisible(true),
607 m_labelsVisible(true),
607 m_labelsAngle(0),
608 m_labelsAngle(0),
608 m_shadesVisible(false),
609 m_shadesVisible(false),
609 m_shadesBrush(Qt::SolidPattern),
610 m_shadesBrush(Qt::SolidPattern),
610 m_shadesOpacity(1.0),
611 m_shadesOpacity(1.0),
611 m_orientation(Qt::Orientation(0)),
612 m_orientation(Qt::Orientation(0)),
612 m_min(0),
613 m_min(0),
613 m_max(0),
614 m_max(0),
614 m_ticksCount(5)
615 m_ticksCount(5)
615 {
616 {
616
617
617 }
618 }
618
619
619 QAbstractAxisPrivate::~QAbstractAxisPrivate()
620 QAbstractAxisPrivate::~QAbstractAxisPrivate()
620 {
621 {
621
622
622 }
623 }
623
624
624 #include "moc_qabstractaxis.cpp"
625 #include "moc_qabstractaxis.cpp"
625 #include "moc_qabstractaxis_p.cpp"
626 #include "moc_qabstractaxis_p.cpp"
626
627
627 QTCOMMERCIALCHART_END_NAMESPACE
628 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,389 +1,394
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 "qbarcategoriesaxis.h"
21 #include "qbarcategoriesaxis.h"
22 #include "qbarcategoriesaxis_p.h"
22 #include "qbarcategoriesaxis_p.h"
23 #include "chartcategoriesaxisx_p.h"
23 #include "chartcategoriesaxisx_p.h"
24 #include "chartcategoriesaxisy_p.h"
24 #include "chartcategoriesaxisy_p.h"
25 #include <qmath.h>
25 #include <qmath.h>
26 #include <QDebug>
26 #include <QDebug>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 /*!
29 /*!
30 \class QBarCategoriesAxis
30 \class QBarCategoriesAxis
31 \brief The QBarCategoriesAxis class is used for manipulating chart's axis.
31 \brief The QBarCategoriesAxis class is used for manipulating chart's axis.
32 \mainclass
32 \mainclass
33
33
34 BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades.
34 BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades.
35 Categories are drawn between ticks. Note that you can use this also with lineseries too.
35 Categories are drawn between ticks. Note that you can use this also with lineseries too.
36 See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that.
36 See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that.
37 */
37 */
38
38
39 /*!
39 /*!
40 \qmlclass BarCategoriesAxis QBarCategoriesAxis
40 \qmlclass BarCategoriesAxis QBarCategoriesAxis
41 \brief The Axis element is used for manipulating chart's axes.
41 \brief The Axis element is used for manipulating chart's axes.
42
42
43 Axis can be setup to show axis line with tick marks, grid lines and shades.
43 Axis can be setup to show axis line with tick marks, grid lines and shades.
44 Categories are drawn between ticks. Note that you can use this also with lineseries too.
44 Categories are drawn between ticks. Note that you can use this also with lineseries too.
45
45
46 To access BarCategoriesAxis you can use ChartView API. For example:
46 To access BarCategoriesAxis you can use ChartView API. For example:
47 \code
47 \code
48 ChartView {
48 ChartView {
49 BarCategoriesAxis {
49 BarCategoriesAxis {
50 id: categoryAxis
50 id: categoryAxis
51 categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
51 categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
52 }
52 }
53 // Add a few series...
53 // Add a few series...
54 }
54 }
55 \endcode
55 \endcode
56 */
56 */
57
57
58 /*!
58 /*!
59 \property QBarCategoriesAxis::categories
59 \property QBarCategoriesAxis::categories
60 Defines the categories of axis
60 Defines the categories of axis
61 */
61 */
62 /*!
62 /*!
63 \qmlproperty QStringList BarCategoriesAxis::categories
63 \qmlproperty QStringList BarCategoriesAxis::categories
64 Defines the categories of axis
64 Defines the categories of axis
65 */
65 */
66
66
67 /*!
67 /*!
68 \property QBarCategoriesAxis::min
68 \property QBarCategoriesAxis::min
69 Defines the minimum value on the axis.
69 Defines the minimum value on the axis.
70 */
70 */
71 /*!
71 /*!
72 \qmlproperty QString BarCategoriesAxis::min
72 \qmlproperty QString BarCategoriesAxis::min
73 Defines the minimum value on the axis.
73 Defines the minimum value on the axis.
74 */
74 */
75
75
76 /*!
76 /*!
77 \property QBarCategoriesAxis::max
77 \property QBarCategoriesAxis::max
78 Defines the maximum value on the axis.
78 Defines the maximum value on the axis.
79 */
79 */
80 /*!
80 /*!
81 \qmlproperty QString BarCategoriesAxis::max
81 \qmlproperty QString BarCategoriesAxis::max
82 Defines the maximum value on the axis.
82 Defines the maximum value on the axis.
83 */
83 */
84
84
85
86 /*!
87 \fn void QBarCategoriesAxis::categoriesChanged()
88 Axis emits signal when the categories of the axis has changed.
89 */
85 /*!
90 /*!
86 \fn void QBarCategoriesAxis::minChanged(const QString &min)
91 \fn void QBarCategoriesAxis::minChanged(const QString &min)
87 Axis emits signal when \a min of axis has changed.
92 Axis emits signal when \a min of axis has changed.
88 */
93 */
89 /*!
94 /*!
90 \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min)
95 \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min)
91 Axis emits signal when \a min of axis has changed.
96 Axis emits signal when \a min of axis has changed.
92 */
97 */
93
98
94 /*!
99 /*!
95 \fn void QBarCategoriesAxis::maxChanged(const QString &max)
100 \fn void QBarCategoriesAxis::maxChanged(const QString &max)
96 Axis emits signal when \a max of axis has changed.
101 Axis emits signal when \a max of axis has changed.
97 */
102 */
98 /*!
103 /*!
99 \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max)
104 \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max)
100 Axis emits signal when \a max of axis has changed.
105 Axis emits signal when \a max of axis has changed.
101 */
106 */
102
107
103 /*!
108 /*!
104 \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max)
109 \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max)
105 Axis emits signal when \a min or \a max of axis has changed.
110 Axis emits signal when \a min or \a max of axis has changed.
106 */
111 */
107
112
108 /*!
113 /*!
109 Constructs an axis object which is a child of \a parent.
114 Constructs an axis object which is a child of \a parent.
110 */
115 */
111 QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent):
116 QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent):
112 QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent)
117 QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent)
113 {
118 {
114 }
119 }
115
120
116 /*!
121 /*!
117 Destroys the object
122 Destroys the object
118 */
123 */
119 QBarCategoriesAxis::~QBarCategoriesAxis()
124 QBarCategoriesAxis::~QBarCategoriesAxis()
120 {
125 {
121 }
126 }
122
127
123 /*!
128 /*!
124 \internal
129 \internal
125 */
130 */
126 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
131 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
127 {
132 {
128
133
129 }
134 }
130
135
131 /*!
136 /*!
132 Appends \a categories to axis
137 Appends \a categories to axis
133 */
138 */
134 void QBarCategoriesAxis::append(const QStringList &categories)
139 void QBarCategoriesAxis::append(const QStringList &categories)
135 {
140 {
136 if(categories.isEmpty()) return;
141 if(categories.isEmpty()) return;
137
142
138 Q_D(QBarCategoriesAxis);
143 Q_D(QBarCategoriesAxis);
139 if (d->m_categories.isEmpty()) {
144 if (d->m_categories.isEmpty()) {
140 d->m_categories.append(categories);
145 d->m_categories.append(categories);
141 setRange(categories.first(),categories.last());
146 setRange(categories.first(),categories.last());
142 }else{
147 }else{
143 d->m_categories.append(categories);
148 d->m_categories.append(categories);
144 }
149 }
145 emit d->updated();
150 emit d->updated();
146 emit categoriesChanged();
151 emit categoriesChanged();
147 }
152 }
148
153
149 /*!
154 /*!
150 Appends \a category to axis
155 Appends \a category to axis
151 */
156 */
152 void QBarCategoriesAxis::append(const QString &category)
157 void QBarCategoriesAxis::append(const QString &category)
153 {
158 {
154 Q_D(QBarCategoriesAxis);
159 Q_D(QBarCategoriesAxis);
155 if (d->m_categories.isEmpty()) {
160 if (d->m_categories.isEmpty()) {
156 d->m_categories.append(category);
161 d->m_categories.append(category);
157 setRange(category,category);
162 setRange(category,category);
158 }else{
163 }else{
159 d->m_categories.append(category);
164 d->m_categories.append(category);
160 }
165 }
161 emit d->updated();
166 emit d->updated();
162 emit categoriesChanged();
167 emit categoriesChanged();
163 }
168 }
164
169
165 /*!
170 /*!
166 Removes \a category from axis
171 Removes \a category from axis
167 */
172 */
168 void QBarCategoriesAxis::remove(const QString &category)
173 void QBarCategoriesAxis::remove(const QString &category)
169 {
174 {
170 Q_D(QBarCategoriesAxis);
175 Q_D(QBarCategoriesAxis);
171 if (d->m_categories.contains(category)) {
176 if (d->m_categories.contains(category)) {
172 d->m_categories.removeAt(d->m_categories.indexOf(category));
177 d->m_categories.removeAt(d->m_categories.indexOf(category));
173 setRange(d->m_categories.first(),d->m_categories.last());
178 setRange(d->m_categories.first(),d->m_categories.last());
174 emit d->updated();
179 emit d->updated();
175 emit categoriesChanged();
180 emit categoriesChanged();
176 }
181 }
177 }
182 }
178
183
179 /*!
184 /*!
180 Inserts \a category to axis at \a index
185 Inserts \a category to axis at \a index
181 */
186 */
182 void QBarCategoriesAxis::insert(int index, const QString &category)
187 void QBarCategoriesAxis::insert(int index, const QString &category)
183 {
188 {
184 Q_D(QBarCategoriesAxis);
189 Q_D(QBarCategoriesAxis);
185 if (d->m_categories.isEmpty()) {
190 if (d->m_categories.isEmpty()) {
186 d->m_categories.insert(index,category);
191 d->m_categories.insert(index,category);
187 setRange(category,category);
192 setRange(category,category);
188 }else{
193 }else{
189 d->m_categories.insert(index,category);
194 d->m_categories.insert(index,category);
190 }
195 }
191 emit d->updated();
196 emit d->updated();
192 emit categoriesChanged();
197 emit categoriesChanged();
193 }
198 }
194
199
195 /*!
200 /*!
196 Removes all categories.
201 Removes all categories.
197 */
202 */
198 void QBarCategoriesAxis::clear()
203 void QBarCategoriesAxis::clear()
199 {
204 {
200 Q_D(QBarCategoriesAxis);
205 Q_D(QBarCategoriesAxis);
201 d->m_categories.clear();
206 d->m_categories.clear();
202 setRange(QString::null,QString::null);
207 setRange(QString::null,QString::null);
203 emit d->updated();
208 emit d->updated();
204 emit categoriesChanged();
209 emit categoriesChanged();
205 }
210 }
206
211
207 void QBarCategoriesAxis::setCategories(const QStringList &categories)
212 void QBarCategoriesAxis::setCategories(const QStringList &categories)
208 {
213 {
209 Q_D(QBarCategoriesAxis);
214 Q_D(QBarCategoriesAxis);
210 if(d->m_categories!=categories){
215 if(d->m_categories!=categories){
211 d->m_categories = categories;
216 d->m_categories = categories;
212 setRange(categories.first(),categories.last());
217 setRange(categories.first(),categories.last());
213 emit d->updated();
218 emit d->updated();
214 emit categoriesChanged();
219 emit categoriesChanged();
215 }
220 }
216 }
221 }
217
222
218 QStringList QBarCategoriesAxis::categories()
223 QStringList QBarCategoriesAxis::categories()
219 {
224 {
220 Q_D(QBarCategoriesAxis);
225 Q_D(QBarCategoriesAxis);
221 return d->m_categories;
226 return d->m_categories;
222 }
227 }
223
228
224 /*!
229 /*!
225 Returns number of categories.
230 Returns number of categories.
226 */
231 */
227 int QBarCategoriesAxis::count() const
232 int QBarCategoriesAxis::count() const
228 {
233 {
229 Q_D(const QBarCategoriesAxis);
234 Q_D(const QBarCategoriesAxis);
230 return d->m_categories.count();
235 return d->m_categories.count();
231 }
236 }
232
237
233 /*!
238 /*!
234 Returns category at \a index. Index must be valid.
239 Returns category at \a index. Index must be valid.
235 */
240 */
236 QString QBarCategoriesAxis::at(int index) const
241 QString QBarCategoriesAxis::at(int index) const
237 {
242 {
238 Q_D(const QBarCategoriesAxis);
243 Q_D(const QBarCategoriesAxis);
239 return d->m_categories.at(index);
244 return d->m_categories.at(index);
240 }
245 }
241
246
242 /*!
247 /*!
243 Sets minimum category to \a min.
248 Sets minimum category to \a min.
244 */
249 */
245 void QBarCategoriesAxis::setMin(const QString& min)
250 void QBarCategoriesAxis::setMin(const QString& min)
246 {
251 {
247 Q_D(QBarCategoriesAxis);
252 Q_D(QBarCategoriesAxis);
248 setRange(min,d->m_maxCategory);
253 setRange(min,d->m_maxCategory);
249 }
254 }
250
255
251 /*!
256 /*!
252 Returns minimum category.
257 Returns minimum category.
253 */
258 */
254 QString QBarCategoriesAxis::min() const
259 QString QBarCategoriesAxis::min() const
255 {
260 {
256 Q_D(const QBarCategoriesAxis);
261 Q_D(const QBarCategoriesAxis);
257 return d->m_minCategory;
262 return d->m_minCategory;
258 }
263 }
259
264
260 /*!
265 /*!
261 Sets maximum category to \a max.
266 Sets maximum category to \a max.
262 */
267 */
263 void QBarCategoriesAxis::setMax(const QString& max)
268 void QBarCategoriesAxis::setMax(const QString& max)
264 {
269 {
265 Q_D(QBarCategoriesAxis);
270 Q_D(QBarCategoriesAxis);
266 setRange(d->m_minCategory,max);
271 setRange(d->m_minCategory,max);
267 }
272 }
268
273
269 /*!
274 /*!
270 Returns maximum category
275 Returns maximum category
271 */
276 */
272 QString QBarCategoriesAxis::max() const
277 QString QBarCategoriesAxis::max() const
273 {
278 {
274 Q_D(const QBarCategoriesAxis);
279 Q_D(const QBarCategoriesAxis);
275 return d->m_maxCategory;
280 return d->m_maxCategory;
276 }
281 }
277
282
278 /*!
283 /*!
279 Sets range from \a minCategory to \a maxCategory
284 Sets range from \a minCategory to \a maxCategory
280 */
285 */
281 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
286 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
282 {
287 {
283 Q_D(QBarCategoriesAxis);
288 Q_D(QBarCategoriesAxis);
284
289
285 int minIndex = d->m_categories.indexOf(minCategory);
290 int minIndex = d->m_categories.indexOf(minCategory);
286 if (minIndex == -1) {
291 if (minIndex == -1) {
287 return;
292 return;
288 }
293 }
289 int maxIndex = d->m_categories.indexOf(maxCategory);
294 int maxIndex = d->m_categories.indexOf(maxCategory);
290 if (maxIndex == -1) {
295 if (maxIndex == -1) {
291 return;
296 return;
292 }
297 }
293
298
294 if (maxIndex <= minIndex) {
299 if (maxIndex <= minIndex) {
295 // max must be greater than min
300 // max must be greater than min
296 return;
301 return;
297 }
302 }
298
303
299 bool changed = false;
304 bool changed = false;
300 if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) {
305 if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) {
301 d->m_minCategory = minCategory;
306 d->m_minCategory = minCategory;
302 d->m_min = minIndex;
307 d->m_min = minIndex;
303 emit minChanged(minCategory);
308 emit minChanged(minCategory);
304 changed = true;
309 changed = true;
305 }
310 }
306
311
307 if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) {
312 if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) {
308 d->m_max = maxIndex;
313 d->m_max = maxIndex;
309 d->m_maxCategory = maxCategory;
314 d->m_maxCategory = maxCategory;
310 emit maxChanged(maxCategory);
315 emit maxChanged(maxCategory);
311 changed = true;
316 changed = true;
312 }
317 }
313
318
314 if (changed) {
319 if (changed) {
315 d->emitRange();
320 d->emitRange();
316 }
321 }
317 }
322 }
318
323
319 /*!
324 /*!
320 Returns the type of the axis
325 Returns the type of the axis
321 */
326 */
322 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
327 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
323 {
328 {
324 return AxisTypeCategories;
329 return AxisTypeCategories;
325 }
330 }
326
331
327 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
332 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
328
333
329 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
334 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
330 QAbstractAxisPrivate(q)
335 QAbstractAxisPrivate(q)
331 {
336 {
332
337
333 }
338 }
334
339
335 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
340 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
336 {
341 {
337
342
338 }
343 }
339
344
340 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
345 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
341 {
346 {
342 setRange(min,m_maxCategory);
347 setRange(min,m_maxCategory);
343 }
348 }
344
349
345 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
350 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
346 {
351 {
347 setRange(m_minCategory,max);
352 setRange(m_minCategory,max);
348 }
353 }
349
354
350 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
355 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
351 {
356 {
352 Q_Q(QBarCategoriesAxis);
357 Q_Q(QBarCategoriesAxis);
353 QString value1 = min.toString();
358 QString value1 = min.toString();
354 QString value2 = max.toString();
359 QString value2 = max.toString();
355 q->setRange(value1,value2);
360 q->setRange(value1,value2);
356 }
361 }
357
362
358 int QBarCategoriesAxisPrivate::ticksCount() const
363 int QBarCategoriesAxisPrivate::ticksCount() const
359 {
364 {
360 return m_categories.count()+1;
365 return m_categories.count()+1;
361 }
366 }
362
367
363 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
368 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
364 {
369 {
365 m_min = min;
370 m_min = min;
366 m_max = max;
371 m_max = max;
367 m_ticksCount = count;
372 m_ticksCount = count;
368 }
373 }
369
374
370 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
375 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
371 {
376 {
372 Q_Q( QBarCategoriesAxis);
377 Q_Q( QBarCategoriesAxis);
373 if(m_orientation == Qt::Vertical){
378 if(m_orientation == Qt::Vertical){
374 return new ChartCategoriesAxisY(q,presenter);
379 return new ChartCategoriesAxisY(q,presenter);
375 }else{
380 }else{
376 return new ChartCategoriesAxisX(q,presenter);
381 return new ChartCategoriesAxisX(q,presenter);
377 }
382 }
378 }
383 }
379
384
380 void QBarCategoriesAxisPrivate::emitRange()
385 void QBarCategoriesAxisPrivate::emitRange()
381 {
386 {
382 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
387 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
383 }
388 }
384
389
385
390
386 #include "moc_qbarcategoriesaxis.cpp"
391 #include "moc_qbarcategoriesaxis.cpp"
387 #include "moc_qbarcategoriesaxis_p.cpp"
392 #include "moc_qbarcategoriesaxis_p.cpp"
388
393
389 QTCOMMERCIALCHART_END_NAMESPACE
394 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,199 +1,199
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 "qabstractseries.h"
21 #include "qabstractseries.h"
22 #include "qabstractseries_p.h"
22 #include "qabstractseries_p.h"
23 #include "chartdataset_p.h"
23 #include "chartdataset_p.h"
24
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
26
27 /*!
27 /*!
28 \class QAbstractSeries
28 \class QAbstractSeries
29 \brief Base class for all QtCommercial Chart series.
29 \brief Base class for all QtCommercial Chart series.
30 \mainclass
30 \mainclass
31
31
32 Usually you use the series type specific inherited classes instead of the base class.
32 Usually you use the series type specific inherited classes instead of the base class.
33 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries,
33 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries,
34 QPercentBarSeries, QPieSeries
34 QPercentBarSeries, QPieSeries
35 */
35 */
36 /*!
36 /*!
37 \qmlclass AbstractSeries
37 \qmlclass AbstractSeries
38 AbstractSeries is the base class for all series.
38 AbstractSeries is the base class for all series.
39 The class cannot be instantiated by the user.
39 The class cannot be instantiated by the user.
40 */
40 */
41
41
42 /*!
42 /*!
43 \enum QAbstractSeries::SeriesType
43 \enum QAbstractSeries::SeriesType
44
44
45 The type of the series object.
45 The type of the series object.
46
46
47 \value SeriesTypeLine
47 \value SeriesTypeLine
48 \value SeriesTypeArea
48 \value SeriesTypeArea
49 \value SeriesTypeBar
49 \value SeriesTypeBar
50 \value SeriesTypeStackedBar
50 \value SeriesTypeStackedBar
51 \value SeriesTypePercentBar
51 \value SeriesTypePercentBar
52 \value SeriesTypePie
52 \value SeriesTypePie
53 \value SeriesTypeScatter
53 \value SeriesTypeScatter
54 \value SeriesTypeSpline
54 \value SeriesTypeSpline
55 */
55 */
56
56
57 /*!
57 /*!
58 \property QAbstractSeries::type
58 \property QAbstractSeries::type
59 The type of the series.
59 The type of the series.
60 */
60 */
61 /*!
61 /*!
62 \qmlproperty ChartView.SeriesType AbstractSeries::type
62 \qmlproperty ChartView.SeriesType AbstractSeries::type
63 The type of the series.
63 The type of the series.
64 */
64 */
65
65
66 /*!
66 /*!
67 \property QAbstractSeries::name
67 \property QAbstractSeries::name
68 \brief name of the series property. The name is shown in legend for QXYSeries.
68 \brief name of the series property. The name is shown in legend for QXYSeries.
69 */
69 */
70 /*!
70 /*!
71 \qmlproperty string AbstractSeries::name
71 \qmlproperty string AbstractSeries::name
72 Name of the series. The name is shown in legend for QXYSeries.
72 Name of the series. The name is shown in legend for QXYSeries.
73 */
73 */
74
74
75 /*!
75 /*!
76 \fn void QAbstractSeries::nameChanged()
76 \fn void QAbstractSeries::nameChanged()
77 This signal is emitted when the series name changes.
77 This signal is emitted when the series name changes.
78 */
78 */
79 /*!
79 /*!
80 \qmlsignal AbstractSeries::nameChanged()
80 \qmlsignal AbstractSeries::nameChanged()
81 This signal is emitted when the series name changes.
81 This signal is emitted when the series name changes.
82 */
82 */
83
83
84 /*!
84 /*!
85 \property QAbstractSeries::visible
85 \property QAbstractSeries::visible
86 \brief whether the series is visible or not; true by default.
86 \brief whether the series is visible or not; true by default.
87 */
87 */
88
88
89 /*!
89 /*!
90 \fn void QAbstractSeries::visibleChanged()
90 \fn void QAbstractSeries::visibleChanged()
91 Emitted when the series visibility changes.
91 Emitted when the series visibility changes.
92 */
92 */
93
93
94 /*!
94 /*!
95 \internal
95 \internal
96 \brief Constructs ChartSeries object with \a parent.
96 \brief Constructs ChartSeries object with \a parent.
97 */
97 */
98 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
98 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
99 QObject(parent),
99 QObject(parent),
100 d_ptr(&d)
100 d_ptr(&d)
101 {
101 {
102 }
102 }
103
103
104 /*!
104 /*!
105 \brief Virtual destructor for the chart series.
105 \brief Virtual destructor for the chart series.
106 */
106 */
107 QAbstractSeries::~QAbstractSeries()
107 QAbstractSeries::~QAbstractSeries()
108 {
108 {
109 if(d_ptr->m_dataset) qFatal("Still binded series detected !");
109 if(d_ptr->m_dataset) qFatal("Still binded series detected !");
110 }
110 }
111
111
112 void QAbstractSeries::setName(const QString& name)
112 void QAbstractSeries::setName(const QString& name)
113 {
113 {
114 if (name != d_ptr->m_name) {
114 if (name != d_ptr->m_name) {
115 d_ptr->m_name = name;
115 d_ptr->m_name = name;
116 emit nameChanged();
116 emit nameChanged();
117 }
117 }
118 }
118 }
119
119
120 QString QAbstractSeries::name() const
120 QString QAbstractSeries::name() const
121 {
121 {
122 return d_ptr->m_name;
122 return d_ptr->m_name;
123 }
123 }
124
124
125 /*!
125 /*!
126 Sets the visibility of series to \a visible
126 Sets the visibility of series to \a visible
127 */
127 */
128 void QAbstractSeries::setVisible(bool visible)
128 void QAbstractSeries::setVisible(bool visible)
129 {
129 {
130 if (visible != d_ptr->m_visible) {
130 if (visible != d_ptr->m_visible) {
131 d_ptr->m_visible = visible;
131 d_ptr->m_visible = visible;
132 emit visibleChanged();
132 emit visibleChanged();
133 }
133 }
134 }
134 }
135
135
136 /*!
136 /*!
137 Returns the visibility of series
137 Returns the visibility of series
138 */
138 */
139 bool QAbstractSeries::isVisible() const
139 bool QAbstractSeries::isVisible() const
140 {
140 {
141 return d_ptr->m_visible;
141 return d_ptr->m_visible;
142 }
142 }
143
143
144 /*!
144 /*!
145 \brief Returns the chart where series belongs to.
145 \brief Returns the chart where series belongs to.
146
146
147 Set automatically when the series is added to the chart
147 Set automatically when the series is added to the chart
148 and unset when the series is removed from the chart.
148 and unset when the series is removed from the chart.
149 */
149 */
150 QChart* QAbstractSeries::chart() const
150 QChart* QAbstractSeries::chart() const
151 {
151 {
152 return d_ptr->m_chart;
152 return d_ptr->m_chart;
153 }
153 }
154
154
155 void QAbstractSeries::adjustView()
155 //void QAbstractSeries::adjustView()
156 {
156 //{
157 //TODO:
157 // //TODO:
158 }
158 //}
159
159
160 /*!
160 /*!
161 \brief Sets the visibility of the series to true
161 \brief Sets the visibility of the series to true
162
162
163 \sa setVisible(), isVisible()
163 \sa setVisible(), isVisible()
164 */
164 */
165 void QAbstractSeries::show()
165 void QAbstractSeries::show()
166 {
166 {
167 setVisible(true);
167 setVisible(true);
168 }
168 }
169
169
170 /*!
170 /*!
171 \brief Sets the visibility of the series to false
171 \brief Sets the visibility of the series to false
172
172
173 \sa setVisible(), isVisible()
173 \sa setVisible(), isVisible()
174 */
174 */
175 void QAbstractSeries::hide()
175 void QAbstractSeries::hide()
176 {
176 {
177 setVisible(false);
177 setVisible(false);
178 }
178 }
179
179
180 ///////////////////////////////////////////////////////////////////////////////////////////////////
180 ///////////////////////////////////////////////////////////////////////////////////////////////////
181
181
182 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
182 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
183 q_ptr(q),
183 q_ptr(q),
184 m_chart(0),
184 m_chart(0),
185 m_dataset(0),
185 m_dataset(0),
186 m_visible(true)
186 m_visible(true)
187 {
187 {
188 }
188 }
189
189
190 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
190 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
191 {
191 {
192 }
192 }
193
193
194 #include "moc_qabstractseries.cpp"
194 #include "moc_qabstractseries.cpp"
195 #include "moc_qabstractseries_p.cpp"
195 #include "moc_qabstractseries_p.cpp"
196
196
197 QTCOMMERCIALCHART_END_NAMESPACE
197 QTCOMMERCIALCHART_END_NAMESPACE
198
198
199
199
@@ -1,84 +1,83
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 QABSTRACTSERIES_H
21 #ifndef QABSTRACTSERIES_H
22 #define QABSTRACTSERIES_H
22 #define QABSTRACTSERIES_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <qabstractaxis.h>
25 #include <qabstractaxis.h>
26 #include <QObject>
26 #include <QObject>
27 #include <QPen>
27 #include <QPen>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QAbstractSeriesPrivate;
31 class QAbstractSeriesPrivate;
32 class QChart;
32 class QChart;
33
33
34 class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject
34 class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject
35 {
35 {
36 Q_OBJECT
36 Q_OBJECT
37 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
37 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
38 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
38 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
39 Q_PROPERTY(SeriesType type READ type)
39 Q_PROPERTY(SeriesType type READ type)
40 Q_ENUMS(SeriesType)
40 Q_ENUMS(SeriesType)
41
41
42 public:
42 public:
43 enum SeriesType {
43 enum SeriesType {
44 SeriesTypeLine,
44 SeriesTypeLine,
45 SeriesTypeArea,
45 SeriesTypeArea,
46 SeriesTypeBar,
46 SeriesTypeBar,
47 SeriesTypeStackedBar,
47 SeriesTypeStackedBar,
48 SeriesTypePercentBar,
48 SeriesTypePercentBar,
49 SeriesTypePie,
49 SeriesTypePie,
50 SeriesTypeScatter,
50 SeriesTypeScatter,
51 SeriesTypeSpline
51 SeriesTypeSpline
52 };
52 };
53
53
54 protected:
54 protected:
55 QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0);
55 QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0);
56
56
57 public:
57 public:
58 ~QAbstractSeries();
58 ~QAbstractSeries();
59 virtual SeriesType type() const = 0;
59 virtual SeriesType type() const = 0;
60
60
61 void setName(const QString& name);
61 void setName(const QString& name);
62 QString name() const;
62 QString name() const;
63 void setVisible(bool visible = true);
63 void setVisible(bool visible = true);
64 bool isVisible() const;
64 bool isVisible() const;
65 QChart* chart() const;
65 QChart* chart() const;
66
66
67 void adjustView();
68 void show();
67 void show();
69 void hide();
68 void hide();
70
69
71 Q_SIGNALS:
70 Q_SIGNALS:
72 void nameChanged();
71 void nameChanged();
73 void visibleChanged();
72 void visibleChanged();
74
73
75 protected:
74 protected:
76 QScopedPointer<QAbstractSeriesPrivate> d_ptr;
75 QScopedPointer<QAbstractSeriesPrivate> d_ptr;
77 friend class ChartDataSet;
76 friend class ChartDataSet;
78 friend class ChartPresenter;
77 friend class ChartPresenter;
79 friend class QLegendPrivate;
78 friend class QLegendPrivate;
80 };
79 };
81
80
82 QTCOMMERCIALCHART_END_NAMESPACE
81 QTCOMMERCIALCHART_END_NAMESPACE
83
82
84 #endif
83 #endif
@@ -1,490 +1,504
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 <QGraphicsScene>
27 #include <QGraphicsScene>
28 #include <QGraphicsSceneResizeEvent>
28 #include <QGraphicsSceneResizeEvent>
29 #include <QGraphicsLayout>
29 #include <QGraphicsLayout>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \enum QChart::ChartTheme
34 \enum QChart::ChartTheme
35
35
36 This enum describes the theme used by the chart.
36 This enum describes the theme used by the chart.
37
37
38 \value ChartThemeLight The default theme
38 \value ChartThemeLight The default theme
39 \value ChartThemeBlueCerulean
39 \value ChartThemeBlueCerulean
40 \value ChartThemeDark
40 \value ChartThemeDark
41 \value ChartThemeBrownSand
41 \value ChartThemeBrownSand
42 \value ChartThemeBlueNcs
42 \value ChartThemeBlueNcs
43 \value ChartThemeHighContrast
43 \value ChartThemeHighContrast
44 \value ChartThemeBlueIcy
44 \value ChartThemeBlueIcy
45 */
45 */
46
46
47 /*!
47 /*!
48 \enum QChart::AnimationOption
48 \enum QChart::AnimationOption
49
49
50 For enabling/disabling animations. Defaults to NoAnimation.
50 For enabling/disabling animations. Defaults to NoAnimation.
51
51
52 \value NoAnimation
52 \value NoAnimation
53 \value GridAxisAnimations
53 \value GridAxisAnimations
54 \value SeriesAnimations
54 \value SeriesAnimations
55 \value AllAnimations
55 \value AllAnimations
56 */
56 */
57
57
58 /*!
58 /*!
59 \class QChart
59 \class QChart
60 \brief QtCommercial chart API.
60 \brief QtCommercial chart API.
61
61
62 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
62 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
63 representation of different types of series and other chart related objects like
63 representation of different types of series and other chart related objects like
64 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
64 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
65 convenience class QChartView instead of QChart.
65 convenience class QChartView instead of QChart.
66 \sa QChartView
66 \sa QChartView
67 */
67 */
68
68
69 /*!
69 /*!
70 \property QChart::animationOptions
70 \property QChart::animationOptions
71 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
71 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
72 */
72 */
73
73
74 /*!
74 /*!
75 \property QChart::backgroundVisible
75 \property QChart::backgroundVisible
76 Whether the chart background is visible or not.
76 Whether the chart background is visible or not.
77 \sa setBackgroundBrush(), setBackgroundPen()
77 \sa setBackgroundBrush(), setBackgroundPen()
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QChart::dropShadowEnabled
81 \property QChart::dropShadowEnabled
82 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
82 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
83 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
83 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
84 */
84 */
85
85
86 /*!
86 /*!
87 \property QChart::margins
87 \property QChart::margins
88 Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes.
88 Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes.
89 */
89 */
90
90
91 /*!
91 /*!
92 \property QChart::theme
92 \property QChart::theme
93 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
93 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
94 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
94 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
95 different themes.
95 different themes.
96 Note: changing the theme will overwrite all customizations previously applied to the series.
96 Note: changing the theme will overwrite all customizations previously applied to the series.
97 */
97 */
98
98
99 /*!
99 /*!
100 \property QChart::title
100 \property QChart::title
101 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
101 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
102 */
102 */
103
103
104 /*!
104 /*!
105 \fn void QChart::marginsChanged(QRectF newMargins)
105 \fn void QChart::marginsChanged(QRectF newMargins)
106 The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size,
106 The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size,
107 modify axes or hide/show legend.
107 modify axes or hide/show legend.
108 */
108 */
109
109
110 /*!
110 /*!
111 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
111 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
112 */
112 */
113 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
113 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
114 d_ptr(new QChartPrivate())
114 d_ptr(new QChartPrivate())
115 {
115 {
116 d_ptr->m_dataset = new ChartDataSet(this);
116 d_ptr->m_dataset = new ChartDataSet(this);
117 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
117 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
118 d_ptr->createConnections();
118 d_ptr->createConnections();
119 d_ptr->m_legend = new LegendScroller(this);
119 d_ptr->m_legend = new LegendScroller(this);
120 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
120 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
121 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
121 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
122 setLayout(d_ptr->m_presenter->layout());
122 setLayout(d_ptr->m_presenter->layout());
123 }
123 }
124
124
125 /*!
125 /*!
126 Destroys the object and it's children, like series and axis objects added to it.
126 Destroys the object and it's children, like series and axis objects added to it.
127 */
127 */
128 QChart::~QChart()
128 QChart::~QChart()
129 {
129 {
130 //delete first presenter , since this is a root of all the graphical items
130 //delete first presenter , since this is a root of all the graphical items
131 setLayout(0);
131 setLayout(0);
132 delete d_ptr->m_presenter;
132 delete d_ptr->m_presenter;
133 d_ptr->m_presenter=0;
133 d_ptr->m_presenter=0;
134 }
134 }
135
135
136 /*!
136 /*!
137 Adds the \a series onto the chart and takes the ownership of the object.
137 Adds the \a series onto the chart and takes the ownership of the object.
138 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
138 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
139 the y axis).
139 the y axis).
140
140
141 \sa removeSeries(), removeAllSeries()
141 \sa removeSeries(), removeAllSeries()
142 */
142 */
143 void QChart::addSeries(QAbstractSeries *series)
143 void QChart::addSeries(QAbstractSeries *series)
144 {
144 {
145 Q_ASSERT(series);
145 Q_ASSERT(series);
146 d_ptr->m_dataset->addSeries(series);
146 d_ptr->m_dataset->addSeries(series);
147 }
147 }
148
148
149 /*!
149 /*!
150 Removes the \a series specified in a perameter from the QChartView.
150 Removes the \a series specified in a perameter from the QChartView.
151 It releses its ownership of the specified QChartSeries object.
151 It releses its ownership of the specified QChartSeries object.
152 It does not delete the pointed QChartSeries data object
152 It does not delete the pointed QChartSeries data object
153 \sa addSeries(), removeAllSeries()
153 \sa addSeries(), removeAllSeries()
154 */
154 */
155 void QChart::removeSeries(QAbstractSeries *series)
155 void QChart::removeSeries(QAbstractSeries *series)
156 {
156 {
157 Q_ASSERT(series);
157 Q_ASSERT(series);
158 d_ptr->m_dataset->removeSeries(series);
158 d_ptr->m_dataset->removeSeries(series);
159 }
159 }
160
160
161 /*!
161 /*!
162 Removes all the QChartSeries that have been added to the QChartView
162 Removes all the QChartSeries that have been added to the QChartView
163 It also deletes the pointed QChartSeries data objects
163 It also deletes the pointed QChartSeries data objects
164 \sa addSeries(), removeSeries()
164 \sa addSeries(), removeSeries()
165 */
165 */
166 void QChart::removeAllSeries()
166 void QChart::removeAllSeries()
167 {
167 {
168 d_ptr->m_dataset->removeAllSeries();
168 d_ptr->m_dataset->removeAllSeries();
169 }
169 }
170
170
171 /*!
171 /*!
172 Sets the \a brush that is used for painting the background of the chart area.
172 Sets the \a brush that is used for painting the background of the chart area.
173 */
173 */
174 void QChart::setBackgroundBrush(const QBrush& brush)
174 void QChart::setBackgroundBrush(const QBrush& brush)
175 {
175 {
176 d_ptr->m_presenter->setBackgroundBrush(brush);
176 d_ptr->m_presenter->setBackgroundBrush(brush);
177 }
177 }
178
178
179 /*!
179 /*!
180 Gets the brush that is used for painting the background of the chart area.
180 Gets the brush that is used for painting the background of the chart area.
181 */
181 */
182 QBrush QChart::backgroundBrush() const
182 QBrush QChart::backgroundBrush() const
183 {
183 {
184 return d_ptr->m_presenter->backgroundBrush();
184 return d_ptr->m_presenter->backgroundBrush();
185 }
185 }
186
186
187 /*!
187 /*!
188 Sets the \a pen that is used for painting the background of the chart area.
188 Sets the \a pen that is used for painting the background of the chart area.
189 */
189 */
190 void QChart::setBackgroundPen(const QPen& pen)
190 void QChart::setBackgroundPen(const QPen& pen)
191 {
191 {
192 d_ptr->m_presenter->setBackgroundPen(pen);
192 d_ptr->m_presenter->setBackgroundPen(pen);
193 }
193 }
194
194
195 /*!
195 /*!
196 Gets the pen that is used for painting the background of the chart area.
196 Gets the pen that is used for painting the background of the chart area.
197 */
197 */
198 QPen QChart::backgroundPen() const
198 QPen QChart::backgroundPen() const
199 {
199 {
200 return d_ptr->m_presenter->backgroundPen();
200 return d_ptr->m_presenter->backgroundPen();
201 }
201 }
202
202
203 /*!
203 /*!
204 Sets the chart \a title. The description text that is drawn above the chart.
204 Sets the chart \a title. The description text that is drawn above the chart.
205 */
205 */
206 void QChart::setTitle(const QString& title)
206 void QChart::setTitle(const QString& title)
207 {
207 {
208 d_ptr->m_presenter->setTitle(title);
208 d_ptr->m_presenter->setTitle(title);
209 }
209 }
210
210
211 /*!
211 /*!
212 Returns the chart title. The description text that is drawn above the chart.
212 Returns the chart title. The description text that is drawn above the chart.
213 */
213 */
214 QString QChart::title() const
214 QString QChart::title() const
215 {
215 {
216 return d_ptr->m_presenter->title();
216 return d_ptr->m_presenter->title();
217 }
217 }
218
218
219 /*!
219 /*!
220 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
220 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
221 */
221 */
222 void QChart::setTitleFont(const QFont& font)
222 void QChart::setTitleFont(const QFont& font)
223 {
223 {
224 d_ptr->m_presenter->setTitleFont(font);
224 d_ptr->m_presenter->setTitleFont(font);
225 }
225 }
226
226
227 /*!
227 /*!
228 Gets the font that is used for drawing the chart description text that is rendered above the chart.
228 Gets the font that is used for drawing the chart description text that is rendered above the chart.
229 */
229 */
230 QFont QChart::titleFont() const
230 QFont QChart::titleFont() const
231 {
231 {
232 return d_ptr->m_presenter->titleFont();
232 return d_ptr->m_presenter->titleFont();
233 }
233 }
234
234
235 /*!
235 /*!
236 Sets the \a brush used for rendering the title text.
236 Sets the \a brush used for rendering the title text.
237 */
237 */
238 void QChart::setTitleBrush(const QBrush &brush)
238 void QChart::setTitleBrush(const QBrush &brush)
239 {
239 {
240 d_ptr->m_presenter->setTitleBrush(brush);
240 d_ptr->m_presenter->setTitleBrush(brush);
241 }
241 }
242
242
243 /*!
243 /*!
244 Returns the brush used for rendering the title text.
244 Returns the brush used for rendering the title text.
245 */
245 */
246 QBrush QChart::titleBrush() const
246 QBrush QChart::titleBrush() const
247 {
247 {
248 return d_ptr->m_presenter->titleBrush();
248 return d_ptr->m_presenter->titleBrush();
249 }
249 }
250
250
251 void QChart::setTheme(QChart::ChartTheme theme)
251 void QChart::setTheme(QChart::ChartTheme theme)
252 {
252 {
253 d_ptr->m_presenter->setTheme(theme);
253 d_ptr->m_presenter->setTheme(theme);
254 }
254 }
255
255
256 QChart::ChartTheme QChart::theme() const
256 QChart::ChartTheme QChart::theme() const
257 {
257 {
258 return d_ptr->m_presenter->theme();
258 return d_ptr->m_presenter->theme();
259 }
259 }
260
260
261 /*!
261 /*!
262 Zooms in the view by a factor of 2
262 Zooms in the view by a factor of 2
263 */
263 */
264 void QChart::zoomIn()
264 void QChart::zoomIn()
265 {
265 {
266 d_ptr->m_presenter->zoomIn(2.0);
266 d_ptr->m_presenter->zoomIn(2.0);
267 }
267 }
268
268
269 /*!
269 /*!
270 Zooms in the view to a maximum level at which \a rect is still fully visible.
270 Zooms in the view to a maximum level at which \a rect is still fully visible.
271 */
271 */
272 void QChart::zoomIn(const QRectF& rect)
272 void QChart::zoomIn(const QRectF& rect)
273 {
273 {
274 if (!rect.isValid()) return;
274 if (!rect.isValid()) return;
275 d_ptr->m_presenter->zoomIn(rect);
275 d_ptr->m_presenter->zoomIn(rect);
276 }
276 }
277
277
278 /*!
278 /*!
279 Restores the view zoom level to the previous one.
279 Restores the view zoom level to the previous one.
280 */
280 */
281 void QChart::zoomOut()
281 void QChart::zoomOut()
282 {
282 {
283 d_ptr->m_presenter->zoomOut(2.0);
283 d_ptr->m_presenter->zoomOut(2.0);
284 }
284 }
285
285
286 /*!
286 /*!
287 Zooms in the view by a \a factor.
287 Zooms in the view by a \a factor.
288
288
289 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
289 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
290 */
290 */
291 void QChart::zoom(qreal factor)
291 void QChart::zoom(qreal factor)
292 {
292 {
293 if (qFuzzyIsNull(factor))
293 if (qFuzzyIsNull(factor))
294 return;
294 return;
295
295
296 if (qFuzzyCompare(factor, 1.0))
296 if (qFuzzyCompare(factor, 1.0))
297 return;
297 return;
298
298
299 if (factor < 0)
299 if (factor < 0)
300 return;
300 return;
301
301
302 if (factor > 1.0)
302 if (factor > 1.0)
303 d_ptr->m_presenter->zoomIn(factor);
303 d_ptr->m_presenter->zoomIn(factor);
304 else
304 else
305 d_ptr->m_presenter->zoomOut(1.0 / factor);
305 d_ptr->m_presenter->zoomOut(1.0 / factor);
306 }
306 }
307
307
308 /*!
308 /*!
309 Returns the pointer to the x axis object of the chart asociated with the specified \a series
309 Returns the pointer to the x axis object of the chart asociated with the specified \a series
310 If no series is provided then pointer to currently visible axis is provided
310 If no series is provided then pointer to currently visible axis is provided
311 */
311 */
312 QAbstractAxis* QChart::axisX(QAbstractSeries* series) const
312 QAbstractAxis* QChart::axisX(QAbstractSeries* series) const
313 {
313 {
314 return d_ptr->m_dataset->axisX(series);
314 return d_ptr->m_dataset->axisX(series);
315 }
315 }
316
316
317 /*!
317 /*!
318 Returns the pointer to the y axis object of the chart asociated with the specified \a series
318 Returns the pointer to the y axis object of the chart asociated with the specified \a series
319 If no series is provided then pointer to currently visible axis is provided
319 If no series is provided then pointer to currently visible axis is provided
320 */
320 */
321 QAbstractAxis* QChart::axisY(QAbstractSeries *series) const
321 QAbstractAxis* QChart::axisY(QAbstractSeries *series) const
322 {
322 {
323 return d_ptr->m_dataset->axisY(series);
323 return d_ptr->m_dataset->axisY(series);
324 }
324 }
325
325
326 /*!
326 /*!
327 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.
327 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.
328
328
329 Creates the axes for the chart based on the series that has already been added to the chart.
329 Creates the axes for the chart based on the series that has already been added to the chart.
330
330
331 \table
331 \table
332 \header
332 \header
333 \o Series type
333 \o Series type
334 \o X-axis
334 \o X-axis
335 \o Y-axis
335 \o Y-axis
336 \row
336 \row
337 \o QXYSeries
337 \o QXYSeries
338 \o QValuesAxis
338 \o QValuesAxis
339 \o QValuesAxis
339 \o QValuesAxis
340 \row
340 \row
341 \o QBarSeries
341 \o QBarSeries
342 \o QBarCategoriesAxis
342 \o QBarCategoriesAxis
343 \o QValuesAxis
343 \o QValuesAxis
344 \row
344 \row
345 \o QPieSeries
345 \o QPieSeries
346 \o None
346 \o None
347 \o None
347 \o None
348 \endtable
348 \endtable
349
349
350 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.
350 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.
351 If there are sevaral series added of different types then each series gets its own axes pair.
351 If there are sevaral series added of different types then each series gets its own axes pair.
352
352
353 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.
353 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.
354
354
355 Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls.
355 Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls.
356 QPieSeries does not create any axes.
356 QPieSeries does not create any axes.
357
357
358 \sa axisX(), axisY(), setAxisX(), setAxisY()
358 \sa axisX(), axisY(), setAxisX(), setAxisY()
359 */
359 */
360 void QChart::createDefaultAxes()
360 void QChart::createDefaultAxes()
361 {
361 {
362 d_ptr->m_dataset->createDefaultAxes();
362 d_ptr->m_dataset->createDefaultAxes();
363 }
363 }
364
364
365 /*!
365 /*!
366 Returns the legend object of the chart. Ownership stays in chart.
366 Returns the legend object of the chart. Ownership stays in chart.
367 */
367 */
368 QLegend* QChart::legend() const
368 QLegend* QChart::legend() const
369 {
369 {
370 return d_ptr->m_legend;
370 return d_ptr->m_legend;
371 }
371 }
372
372
373 /*!
373 /*!
374 Returns the rect that contains information about margins (distance between chart widget edge and axes).
374 Returns the rect that contains information about margins (distance between chart widget edge and axes).
375 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
375 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
376 */
376 */
377 QRectF QChart::margins() const
377 QRectF QChart::margins() const
378 {
378 {
379 return d_ptr->m_presenter->margins();
379 return d_ptr->m_presenter->margins();
380 }
380 }
381
381
382 /*!
383 Returns the the rect within which the drawing of the chart is done.
384 It does not include the area defines by margins.
385 */
382 QRectF QChart::plotArea() const
386 QRectF QChart::plotArea() const
383 {
387 {
384 return d_ptr->m_presenter->geometry();
388 return d_ptr->m_presenter->geometry();
385 }
389 }
386
390
391 ///*!
392 // TODO: Dummy.
393 // Adjest the ranges of the axes so that all the data of the specified \a series is visible
394 // */
395 //void QChart::adjustViewToSeries(QAbstractSeries* series)
396 //{
397 // //
398 //}
399
387 /*!
400 /*!
388 Sets animation \a options for the chart
401 Sets animation \a options for the chart
389 */
402 */
390
391 void QChart::setAnimationOptions(AnimationOptions options)
403 void QChart::setAnimationOptions(AnimationOptions options)
392 {
404 {
393 d_ptr->m_presenter->setAnimationOptions(options);
405 d_ptr->m_presenter->setAnimationOptions(options);
394 }
406 }
395
407
396 QChart::AnimationOptions QChart::animationOptions() const
408 QChart::AnimationOptions QChart::animationOptions() const
397 {
409 {
398 return d_ptr->m_presenter->animationOptions();
410 return d_ptr->m_presenter->animationOptions();
399 }
411 }
400
412
401 /*!
413 /*!
402 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
414 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
403 */
415 */
404 void QChart::scroll(qreal dx, qreal dy)
416 void QChart::scroll(qreal dx, qreal dy)
405 {
417 {
406 d_ptr->m_presenter->scroll(dx, dy);
418 d_ptr->m_presenter->scroll(dx, dy);
407 }
419 }
408
420
409 void QChart::setBackgroundVisible(bool visible)
421 void QChart::setBackgroundVisible(bool visible)
410 {
422 {
411 d_ptr->m_presenter->setBackgroundVisible(visible);
423 d_ptr->m_presenter->setBackgroundVisible(visible);
412 }
424 }
413
425
414 bool QChart::isBackgroundVisible() const
426 bool QChart::isBackgroundVisible() const
415 {
427 {
416 return d_ptr->m_presenter->isBackgroundVisible();
428 return d_ptr->m_presenter->isBackgroundVisible();
417 }
429 }
418
430
419 void QChart::setDropShadowEnabled(bool enabled)
431 void QChart::setDropShadowEnabled(bool enabled)
420 {
432 {
421 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
433 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
422 }
434 }
423
435
424 bool QChart::isDropShadowEnabled() const
436 bool QChart::isDropShadowEnabled() const
425 {
437 {
426 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
438 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
427 }
439 }
428
440
429 /*!
441 /*!
430 Returns all the series that are added to the chart.
442 Returns all the series that are added to the chart.
431
443
432 \sa addSeries(), removeSeries(), removeAllSeries()
444 \sa addSeries(), removeSeries(), removeAllSeries()
433 */
445 */
434 QList<QAbstractSeries*> QChart::series() const
446 QList<QAbstractSeries*> QChart::series() const
435 {
447 {
436 return d_ptr->m_dataset->series();
448 return d_ptr->m_dataset->series();
437 }
449 }
438
450 /*!
451 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
452 */
439 void QChart::setMarginsMinimum(const QRectF& margins)
453 void QChart::setMarginsMinimum(const QRectF& margins)
440 {
454 {
441 d_ptr->m_presenter->setMarginsMinimum(margins);
455 d_ptr->m_presenter->setMarginsMinimum(margins);
442 }
456 }
443
457
444 /*!
458 /*!
445 Sets \a axis to the chart, which will control the presentation of the \a series
459 Sets \a axis to the chart, which will control the presentation of the \a series
446
460
447 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
461 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
448 */
462 */
449 void QChart::setAxisX(QAbstractAxis* axis , QAbstractSeries *series)
463 void QChart::setAxisX(QAbstractAxis* axis , QAbstractSeries *series)
450 {
464 {
451 d_ptr->m_dataset->setAxisX(series,axis);
465 d_ptr->m_dataset->setAxisX(series,axis);
452 }
466 }
453
467
454 /*!
468 /*!
455 Sets \a axis to the chart, which will control the presentation of the \a series
469 Sets \a axis to the chart, which will control the presentation of the \a series
456
470
457 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
471 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
458 */
472 */
459 void QChart::setAxisY( QAbstractAxis* axis , QAbstractSeries *series)
473 void QChart::setAxisY( QAbstractAxis* axis , QAbstractSeries *series)
460 {
474 {
461 d_ptr->m_dataset->setAxisY(series,axis);
475 d_ptr->m_dataset->setAxisY(series,axis);
462 }
476 }
463
477
464 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
478 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
465
479
466 QChartPrivate::QChartPrivate():
480 QChartPrivate::QChartPrivate():
467 m_legend(0),
481 m_legend(0),
468 m_dataset(0),
482 m_dataset(0),
469 m_presenter(0)
483 m_presenter(0)
470 {
484 {
471
485
472 }
486 }
473
487
474 QChartPrivate::~QChartPrivate()
488 QChartPrivate::~QChartPrivate()
475 {
489 {
476
490
477 }
491 }
478
492
479 void QChartPrivate::createConnections()
493 void QChartPrivate::createConnections()
480 {
494 {
481 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
495 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
482 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
496 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
483 QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*)));
497 QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*)));
484 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*)));
498 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*)));
485 //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF)));
499 //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF)));
486 }
500 }
487
501
488 #include "moc_qchart.cpp"
502 #include "moc_qchart.cpp"
489
503
490 QTCOMMERCIALCHART_END_NAMESPACE
504 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,136 +1,134
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 QCHART_H
21 #ifndef QCHART_H
22 #define QCHART_H
22 #define QCHART_H
23
23
24 #include <QAbstractSeries>
24 #include <QAbstractSeries>
25 #include <QLegend>
25 #include <QLegend>
26 #include <QGraphicsWidget>
26 #include <QGraphicsWidget>
27
27
28 class QGraphicsSceneResizeEvent;
28 class QGraphicsSceneResizeEvent;
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 class QAbstractSeries;
32 class QAbstractSeries;
33 class QAbstractAxis;
33 class QAbstractAxis;
34 class QLegend;
34 class QLegend;
35 struct QChartPrivate;
35 struct QChartPrivate;
36
36
37 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
37 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
38 {
38 {
39 Q_OBJECT
39 Q_OBJECT
40 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
40 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
41 Q_PROPERTY(QString title READ title WRITE setTitle)
41 Q_PROPERTY(QString title READ title WRITE setTitle)
42 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
42 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
43 Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled)
43 Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled)
44 Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions)
44 Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions)
45 Q_PROPERTY(QRectF margins READ margins NOTIFY marginsChanged)
45 Q_PROPERTY(QRectF margins READ margins NOTIFY marginsChanged)
46 Q_ENUMS(ChartTheme)
46 Q_ENUMS(ChartTheme)
47 Q_ENUMS(AnimationOption)
47 Q_ENUMS(AnimationOption)
48
48
49 public:
49 public:
50 enum ChartTheme {
50 enum ChartTheme {
51 ChartThemeLight = 0,
51 ChartThemeLight = 0,
52 ChartThemeBlueCerulean,
52 ChartThemeBlueCerulean,
53 ChartThemeDark,
53 ChartThemeDark,
54 ChartThemeBrownSand,
54 ChartThemeBrownSand,
55 ChartThemeBlueNcs,
55 ChartThemeBlueNcs,
56 ChartThemeHighContrast,
56 ChartThemeHighContrast,
57 ChartThemeBlueIcy
57 ChartThemeBlueIcy
58 };
58 };
59
59
60 enum AnimationOption {
60 enum AnimationOption {
61 NoAnimation = 0x0,
61 NoAnimation = 0x0,
62 GridAxisAnimations = 0x1,
62 GridAxisAnimations = 0x1,
63 SeriesAnimations =0x2,
63 SeriesAnimations =0x2,
64 AllAnimations = 0x3
64 AllAnimations = 0x3
65 };
65 };
66
66
67 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
67 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
68
68
69 public:
69 public:
70 explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
70 explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
71 ~QChart();
71 ~QChart();
72
72
73 void addSeries(QAbstractSeries *series);
73 void addSeries(QAbstractSeries *series);
74 void removeSeries(QAbstractSeries *series);
74 void removeSeries(QAbstractSeries *series);
75 void removeAllSeries();
75 void removeAllSeries();
76 QList<QAbstractSeries*> series() const;
76 QList<QAbstractSeries*> series() const;
77
77
78 void setAxisX(QAbstractAxis* axis, QAbstractSeries *series = 0);
78 void setAxisX(QAbstractAxis* axis, QAbstractSeries *series = 0);
79 void setAxisY(QAbstractAxis* axis, QAbstractSeries *series = 0);
79 void setAxisY(QAbstractAxis* axis, QAbstractSeries *series = 0);
80
80
81 QAbstractAxis* axisX(QAbstractSeries* series = 0) const;
81 QAbstractAxis* axisX(QAbstractSeries* series = 0) const;
82 QAbstractAxis* axisY(QAbstractSeries* series = 0) const;
82 QAbstractAxis* axisY(QAbstractSeries* series = 0) const;
83
83
84 void createDefaultAxes();
84 void createDefaultAxes();
85
85
86 void setTheme(QChart::ChartTheme theme);
86 void setTheme(QChart::ChartTheme theme);
87 QChart::ChartTheme theme() const;
87 QChart::ChartTheme theme() const;
88
88
89 void setTitle(const QString& title);
89 void setTitle(const QString& title);
90 QString title() const;
90 QString title() const;
91 void setTitleFont(const QFont& font);
91 void setTitleFont(const QFont& font);
92 QFont titleFont() const;
92 QFont titleFont() const;
93 void setTitleBrush(const QBrush &brush);
93 void setTitleBrush(const QBrush &brush);
94 QBrush titleBrush() const;
94 QBrush titleBrush() const;
95
95
96 void setBackgroundBrush(const QBrush &brush);
96 void setBackgroundBrush(const QBrush &brush);
97 QBrush backgroundBrush() const;
97 QBrush backgroundBrush() const;
98 void setBackgroundPen(const QPen &pen);
98 void setBackgroundPen(const QPen &pen);
99 QPen backgroundPen() const;
99 QPen backgroundPen() const;
100 void setBackgroundVisible(bool visible = true);
100 void setBackgroundVisible(bool visible = true);
101 bool isBackgroundVisible() const;
101 bool isBackgroundVisible() const;
102
102
103 void setDropShadowEnabled(bool enabled = true);
103 void setDropShadowEnabled(bool enabled = true);
104 bool isDropShadowEnabled() const;
104 bool isDropShadowEnabled() const;
105 void setAnimationOptions(AnimationOptions options);
105 void setAnimationOptions(AnimationOptions options);
106 AnimationOptions animationOptions() const;
106 AnimationOptions animationOptions() const;
107
107
108 void zoomIn();
108 void zoomIn();
109 void zoomIn(const QRectF &rect);
109 void zoomIn(const QRectF &rect);
110 void zoomOut();
110 void zoomOut();
111 void zoom(qreal factor);
111 void zoom(qreal factor);
112 void scroll(qreal dx, qreal dy);
112 void scroll(qreal dx, qreal dy);
113
113
114 void adjustViewToSeries(QAbstractSeries* series = 0);
115
116 QLegend* legend() const;
114 QLegend* legend() const;
117
115
118 void setMarginsMinimum(const QRectF& margins);
116 void setMarginsMinimum(const QRectF& margins);
119 QRectF margins() const;
117 QRectF margins() const;
120 QRectF plotArea() const;
118 QRectF plotArea() const;
121
119
122 Q_SIGNALS:
120 Q_SIGNALS:
123 void marginsChanged(QRectF newMargins);
121 void marginsChanged(QRectF newMargins);
124
122
125 protected:
123 protected:
126 QScopedPointer<QChartPrivate> d_ptr;
124 QScopedPointer<QChartPrivate> d_ptr;
127 friend class QLegend;
125 friend class QLegend;
128 friend class ChartPresenter;
126 friend class ChartPresenter;
129 Q_DISABLE_COPY(QChart)
127 Q_DISABLE_COPY(QChart)
130 };
128 };
131
129
132 QTCOMMERCIALCHART_END_NAMESPACE
130 QTCOMMERCIALCHART_END_NAMESPACE
133
131
134 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
132 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
135
133
136 #endif
134 #endif
General Comments 0
You need to be logged in to leave comments. Login now