##// END OF EJS Templates
QAbstractAxis: variants strike back.
sauimone -
r1578:18a3503b3b2c
parent child
Show More
@@ -1,587 +1,587
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, however there can be multiple y axes.
31 There is only one x Axis, 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 Axis QAbstractAxis
37 \qmlclass Axis 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, however there can be multiple y axes on a ChartView.
40 There is only one x Axis, 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 AxisTypeValues
62 \value AxisTypeValues
63 \value AxisTypeCategories
63 \value AxisTypeCategories
64 */
64 */
65
65
66 /*
66 /*
67 \property QAbstractAxis::type
67 \property QAbstractAxis::type
68 The type of the axis.
68 The type of the axis.
69 */
69 */
70
70
71 /*!
71 /*!
72 \property QAbstractAxis::labelsVisible
72 \property QAbstractAxis::labelsVisible
73 Defines if axis labels are visible.
73 Defines if axis labels are visible.
74 */
74 */
75 /*!
75 /*!
76 \qmlproperty bool Axis::labelsVisible
76 \qmlproperty bool Axis::labelsVisible
77 Defines if axis labels are visible.
77 Defines if axis labels are visible.
78 */
78 */
79
79
80 /*
80 /*
81 \property QAbstractAxis::min
81 \property QAbstractAxis::min
82 Defines the minimum value on the axis.
82 Defines the minimum value on the axis.
83 */
83 */
84 /*
84 /*
85 \qmlproperty real Axis::min
85 \qmlproperty real Axis::min
86 Defines the minimum value on the axis.
86 Defines the minimum value on the axis.
87 */
87 */
88
88
89 /*
89 /*
90 \property QAbstractAxis::max
90 \property QAbstractAxis::max
91 Defines the maximum value on the axis.
91 Defines the maximum value on the axis.
92 */
92 */
93 /*
93 /*
94 \qmlproperty real Axis::max
94 \qmlproperty real Axis::max
95 Defines the maximum value on the axis.
95 Defines the maximum value on the axis.
96 */
96 */
97
97
98 /*!
98 /*!
99 \property QAbstractAxis::visible
99 \property QAbstractAxis::visible
100 The visibility of the axis.
100 The visibility of the axis.
101 */
101 */
102 /*!
102 /*!
103 \qmlproperty bool Axis::visible
103 \qmlproperty bool Axis::visible
104 The visibility of the axis.
104 The visibility of the axis.
105 */
105 */
106
106
107 /*!
107 /*!
108 \property QAbstractAxis::gridVisible
108 \property QAbstractAxis::gridVisible
109 The visibility of the grid lines.
109 The visibility of the grid lines.
110 */
110 */
111 /*!
111 /*!
112 \qmlproperty bool Axis::gridVisible
112 \qmlproperty bool Axis::gridVisible
113 The visibility of the grid lines.
113 The visibility of the grid lines.
114 */
114 */
115
115
116 /*!
116 /*!
117 \property QAbstractAxis::color
117 \property QAbstractAxis::color
118 The color of the axis and ticks.
118 The color of the axis and ticks.
119 */
119 */
120 /*!
120 /*!
121 \qmlproperty color Axis::color
121 \qmlproperty color Axis::color
122 The color of the axis and ticks.
122 The color of the axis and ticks.
123 */
123 */
124
124
125 /*!
125 /*!
126 \property QAbstractAxis::labelsFont
126 \property QAbstractAxis::labelsFont
127 The font of the axis labels.
127 The font of the axis labels.
128 */
128 */
129
129
130 /*!
130 /*!
131 \qmlproperty Font Axis::labelsFont
131 \qmlproperty Font Axis::labelsFont
132 The font of the axis labels.
132 The font of the axis labels.
133
133
134 See the \l {Font} {QML Font Element} for detailed documentation.
134 See the \l {Font} {QML Font Element} for detailed documentation.
135 */
135 */
136
136
137 /*!
137 /*!
138 \property QAbstractAxis::labelsColor
138 \property QAbstractAxis::labelsColor
139 The color of the axis labels.
139 The color of the axis labels.
140 */
140 */
141 /*!
141 /*!
142 \qmlproperty color Axis::labelsColor
142 \qmlproperty color Axis::labelsColor
143 The color of the axis labels.
143 The color of the axis labels.
144 */
144 */
145
145
146 /*!
146 /*!
147 \property QAbstractAxis::labelsAngle
147 \property QAbstractAxis::labelsAngle
148 The angle of the axis labels in degrees.
148 The angle of the axis labels in degrees.
149 */
149 */
150 /*!
150 /*!
151 \qmlproperty int Axis::labelsAngle
151 \qmlproperty int Axis::labelsAngle
152 The angle of the axis labels in degrees.
152 The angle of the axis labels in degrees.
153 */
153 */
154
154
155 /*!
155 /*!
156 \property QAbstractAxis::shadesVisible
156 \property QAbstractAxis::shadesVisible
157 The visibility of the axis shades.
157 The visibility of the axis shades.
158 */
158 */
159 /*!
159 /*!
160 \qmlproperty bool Axis::shadesVisible
160 \qmlproperty bool Axis::shadesVisible
161 The visibility of the axis shades.
161 The visibility of the axis shades.
162 */
162 */
163
163
164 /*!
164 /*!
165 \property QAbstractAxis::shadesColor
165 \property QAbstractAxis::shadesColor
166 The fill (brush) color of the axis shades.
166 The fill (brush) color of the axis shades.
167 */
167 */
168 /*!
168 /*!
169 \qmlproperty color Axis::shadesColor
169 \qmlproperty color Axis::shadesColor
170 The fill (brush) color of the axis shades.
170 The fill (brush) color of the axis shades.
171 */
171 */
172
172
173 /*!
173 /*!
174 \property QAbstractAxis::shadesBorderColor
174 \property QAbstractAxis::shadesBorderColor
175 The border (pen) color of the axis shades.
175 The border (pen) color of the axis shades.
176 */
176 */
177 /*!
177 /*!
178 \qmlproperty color Axis::shadesBorderColor
178 \qmlproperty color Axis::shadesBorderColor
179 The border (pen) color of the axis shades.
179 The border (pen) color of the axis shades.
180 */
180 */
181
181
182 /*!
182 /*!
183 \fn void QAbstractAxis::visibleChanged(bool)
183 \fn void QAbstractAxis::visibleChanged(bool)
184 Visiblity of the axis has changed to \a visible.
184 Visiblity of the axis has changed to \a visible.
185 */
185 */
186
186
187 /*!
187 /*!
188 \fn void QAbstractAxis::labelsVisibleChanged(bool)
188 \fn void QAbstractAxis::labelsVisibleChanged(bool)
189 Visiblity of the labels of the axis has changed to \a visible.
189 Visiblity of the labels of the axis has changed to \a visible.
190 */
190 */
191
191
192 /*!
192 /*!
193 \fn void QAbstractAxis::gridVisibleChanged(bool)
193 \fn void QAbstractAxis::gridVisibleChanged(bool)
194 Visiblity of the grid lines of the axis has changed to \a visible.
194 Visiblity of the grid lines of the axis has changed to \a visible.
195 */
195 */
196
196
197 /*
197 /*
198 \fn void QAbstractAxis::minChanged(qreal min)
198 \fn void QAbstractAxis::minChanged(qreal min)
199 Axis emits signal when \a min of axis has changed.
199 Axis emits signal when \a min of axis has changed.
200 */
200 */
201
201
202 /*
202 /*
203 \fn void QAbstractAxis::maxChanged(qreal max)
203 \fn void QAbstractAxis::maxChanged(qreal max)
204 Axis emits signal when \a max of axis has changed.
204 Axis emits signal when \a max of axis has changed.
205 */
205 */
206
206
207 /*
207 /*
208 \fn void QAbstractAxis::rangeChanged(qreal min, qreal max)
208 \fn void QAbstractAxis::rangeChanged(qreal min, qreal max)
209 Axis emits signal when \a min or \a max of axis has changed.
209 Axis emits signal when \a min or \a max of axis has changed.
210 */
210 */
211
211
212 /*
212 /*
213 \fn QChartAxisCategories* QAbstractAxis::categories()
213 \fn QChartAxisCategories* QAbstractAxis::categories()
214 Returns pointer to the list of categories which correspond to the values on the axis.
214 Returns pointer to the list of categories which correspond to the values on the axis.
215 */
215 */
216
216
217 /*!
217 /*!
218 \fn void QAbstractAxis::colorChanged(QColor)
218 \fn void QAbstractAxis::colorChanged(QColor)
219 Emitted if the \a color of the axis is changed.
219 Emitted if the \a color of the axis is changed.
220 */
220 */
221
221
222 /*!
222 /*!
223 \fn void QAbstractAxis::labelsColorChanged(QColor)
223 \fn void QAbstractAxis::labelsColorChanged(QColor)
224 Emitted if the \a color of the axis labels is changed.
224 Emitted if the \a color of the axis labels is changed.
225 */
225 */
226
226
227 /*!
227 /*!
228 \fn void QAbstractAxis::shadesVisibleChanged(bool)
228 \fn void QAbstractAxis::shadesVisibleChanged(bool)
229 Emitted if the visibility of the axis shades is changed to \a visible.
229 Emitted if the visibility of the axis shades is changed to \a visible.
230 */
230 */
231
231
232 /*!
232 /*!
233 \fn void QAbstractAxis::shadesColorChanged(QColor)
233 \fn void QAbstractAxis::shadesColorChanged(QColor)
234 Emitted if the \a color of the axis shades is changed.
234 Emitted if the \a color of the axis shades is changed.
235 */
235 */
236
236
237 /*!
237 /*!
238 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
238 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
239 Emitted if the border \a color of the axis shades is changed.
239 Emitted if the border \a color of the axis shades is changed.
240 */
240 */
241
241
242 /*!
242 /*!
243 Constructs new axis object which is a child of \a parent. Ownership is taken by
243 Constructs new axis object which is a child of \a parent. Ownership is taken by
244 QChart when axis added.
244 QChart when axis added.
245 */
245 */
246
246
247 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) :
247 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) :
248 QObject(parent),
248 QObject(parent),
249 d_ptr(&d)
249 d_ptr(&d)
250 {
250 {
251 }
251 }
252
252
253 /*!
253 /*!
254 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
254 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
255 */
255 */
256
256
257 QAbstractAxis::~QAbstractAxis()
257 QAbstractAxis::~QAbstractAxis()
258 {
258 {
259 }
259 }
260
260
261 /*!
261 /*!
262 Sets \a pen used to draw axis line and ticks.
262 Sets \a pen used to draw axis line and ticks.
263 */
263 */
264 void QAbstractAxis::setAxisPen(const QPen &pen)
264 void QAbstractAxis::setAxisPen(const QPen &pen)
265 {
265 {
266 if (d_ptr->m_axisPen!=pen) {
266 if (d_ptr->m_axisPen!=pen) {
267 d_ptr->m_axisPen = pen;
267 d_ptr->m_axisPen = pen;
268 emit d_ptr->updated();
268 emit d_ptr->updated();
269 }
269 }
270 }
270 }
271
271
272 /*!
272 /*!
273 Returns pen used to draw axis and ticks.
273 Returns pen used to draw axis and ticks.
274 */
274 */
275 QPen QAbstractAxis::axisPen() const
275 QPen QAbstractAxis::axisPen() const
276 {
276 {
277 return d_ptr->m_axisPen;
277 return d_ptr->m_axisPen;
278 }
278 }
279
279
280 void QAbstractAxis::setAxisPenColor(QColor color)
280 void QAbstractAxis::setAxisPenColor(QColor color)
281 {
281 {
282 QPen p = d_ptr->m_axisPen;
282 QPen p = d_ptr->m_axisPen;
283 if (p.color() != color) {
283 if (p.color() != color) {
284 p.setColor(color);
284 p.setColor(color);
285 setAxisPen(p);
285 setAxisPen(p);
286 emit colorChanged(color);
286 emit colorChanged(color);
287 }
287 }
288 }
288 }
289
289
290 QColor QAbstractAxis::axisPenColor() const
290 QColor QAbstractAxis::axisPenColor() const
291 {
291 {
292 return d_ptr->m_axisPen.color();
292 return d_ptr->m_axisPen.color();
293 }
293 }
294
294
295 /*!
295 /*!
296 Sets if axis and ticks are \a visible.
296 Sets if axis and ticks are \a visible.
297 */
297 */
298 void QAbstractAxis::setAxisVisible(bool visible)
298 void QAbstractAxis::setAxisVisible(bool visible)
299 {
299 {
300 if (d_ptr->m_axisVisible != visible) {
300 if (d_ptr->m_axisVisible != visible) {
301 d_ptr->m_axisVisible = visible;
301 d_ptr->m_axisVisible = visible;
302 emit d_ptr->updated();
302 emit d_ptr->updated();
303 emit visibleChanged(visible);
303 emit visibleChanged(visible);
304 }
304 }
305 }
305 }
306
306
307 bool QAbstractAxis::isAxisVisible() const
307 bool QAbstractAxis::isAxisVisible() const
308 {
308 {
309 return d_ptr->m_axisVisible;
309 return d_ptr->m_axisVisible;
310 }
310 }
311
311
312 void QAbstractAxis::setGridLineVisible(bool visible)
312 void QAbstractAxis::setGridLineVisible(bool visible)
313 {
313 {
314 if (d_ptr->m_gridLineVisible != visible) {
314 if (d_ptr->m_gridLineVisible != visible) {
315 d_ptr->m_gridLineVisible = visible;
315 d_ptr->m_gridLineVisible = visible;
316 emit d_ptr->updated();
316 emit d_ptr->updated();
317 emit gridVisibleChanged(visible);
317 emit gridVisibleChanged(visible);
318 }
318 }
319 }
319 }
320
320
321 bool QAbstractAxis::isGridLineVisible() const
321 bool QAbstractAxis::isGridLineVisible() const
322 {
322 {
323 return d_ptr->m_gridLineVisible;
323 return d_ptr->m_gridLineVisible;
324 }
324 }
325
325
326 /*!
326 /*!
327 Sets \a pen used to draw grid line.
327 Sets \a pen used to draw grid line.
328 */
328 */
329 void QAbstractAxis::setGridLinePen(const QPen &pen)
329 void QAbstractAxis::setGridLinePen(const QPen &pen)
330 {
330 {
331 if (d_ptr->m_gridLinePen != pen) {
331 if (d_ptr->m_gridLinePen != pen) {
332 d_ptr->m_gridLinePen = pen;
332 d_ptr->m_gridLinePen = pen;
333 emit d_ptr->updated();
333 emit d_ptr->updated();
334 }
334 }
335 }
335 }
336
336
337 /*!
337 /*!
338 Returns pen used to draw grid.
338 Returns pen used to draw grid.
339 */
339 */
340 QPen QAbstractAxis::gridLinePen() const
340 QPen QAbstractAxis::gridLinePen() const
341 {
341 {
342 return d_ptr->m_gridLinePen;
342 return d_ptr->m_gridLinePen;
343 }
343 }
344
344
345 void QAbstractAxis::setLabelsVisible(bool visible)
345 void QAbstractAxis::setLabelsVisible(bool visible)
346 {
346 {
347 if (d_ptr->m_labelsVisible != visible) {
347 if (d_ptr->m_labelsVisible != visible) {
348 d_ptr->m_labelsVisible = visible;
348 d_ptr->m_labelsVisible = visible;
349 emit d_ptr->updated();
349 emit d_ptr->updated();
350 emit labelsVisibleChanged(visible);
350 emit labelsVisibleChanged(visible);
351 }
351 }
352 }
352 }
353
353
354 bool QAbstractAxis::labelsVisible() const
354 bool QAbstractAxis::labelsVisible() const
355 {
355 {
356 return d_ptr->m_labelsVisible;
356 return d_ptr->m_labelsVisible;
357 }
357 }
358
358
359 /*!
359 /*!
360 Sets \a pen used to draw labels.
360 Sets \a pen used to draw labels.
361 */
361 */
362 void QAbstractAxis::setLabelsPen(const QPen &pen)
362 void QAbstractAxis::setLabelsPen(const QPen &pen)
363 {
363 {
364 if (d_ptr->m_labelsPen != pen) {
364 if (d_ptr->m_labelsPen != pen) {
365 d_ptr->m_labelsPen = pen;
365 d_ptr->m_labelsPen = pen;
366 emit d_ptr->updated();
366 emit d_ptr->updated();
367 }
367 }
368 }
368 }
369
369
370 /*!
370 /*!
371 Returns the pen used to labels.
371 Returns the pen used to labels.
372 */
372 */
373 QPen QAbstractAxis::labelsPen() const
373 QPen QAbstractAxis::labelsPen() const
374 {
374 {
375 return d_ptr->m_labelsPen;
375 return d_ptr->m_labelsPen;
376 }
376 }
377
377
378 /*!
378 /*!
379 Sets \a brush used to draw labels.
379 Sets \a brush used to draw labels.
380 */
380 */
381 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
381 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
382 {
382 {
383 if (d_ptr->m_labelsBrush != brush) {
383 if (d_ptr->m_labelsBrush != brush) {
384 d_ptr->m_labelsBrush = brush;
384 d_ptr->m_labelsBrush = brush;
385 emit d_ptr->updated();
385 emit d_ptr->updated();
386 }
386 }
387 }
387 }
388
388
389 /*!
389 /*!
390 Returns brush used to draw labels.
390 Returns brush used to draw labels.
391 */
391 */
392 QBrush QAbstractAxis::labelsBrush() const
392 QBrush QAbstractAxis::labelsBrush() const
393 {
393 {
394 return d_ptr->m_labelsBrush;
394 return d_ptr->m_labelsBrush;
395 }
395 }
396
396
397 /*!
397 /*!
398 Sets \a font used to draw labels.
398 Sets \a font used to draw labels.
399 */
399 */
400 void QAbstractAxis::setLabelsFont(const QFont &font)
400 void QAbstractAxis::setLabelsFont(const QFont &font)
401 {
401 {
402 if (d_ptr->m_labelsFont != font) {
402 if (d_ptr->m_labelsFont != font) {
403 d_ptr->m_labelsFont = font;
403 d_ptr->m_labelsFont = font;
404 emit d_ptr->updated();
404 emit d_ptr->updated();
405 }
405 }
406 }
406 }
407
407
408 /*!
408 /*!
409 Returns font used to draw labels.
409 Returns font used to draw labels.
410 */
410 */
411 QFont QAbstractAxis::labelsFont() const
411 QFont QAbstractAxis::labelsFont() const
412 {
412 {
413 return d_ptr->m_labelsFont;
413 return d_ptr->m_labelsFont;
414 }
414 }
415
415
416 void QAbstractAxis::setLabelsAngle(int angle)
416 void QAbstractAxis::setLabelsAngle(int angle)
417 {
417 {
418 if (d_ptr->m_labelsAngle != angle) {
418 if (d_ptr->m_labelsAngle != angle) {
419 d_ptr->m_labelsAngle = angle;
419 d_ptr->m_labelsAngle = angle;
420 emit d_ptr->updated();
420 emit d_ptr->updated();
421 }
421 }
422 }
422 }
423
423
424 int QAbstractAxis::labelsAngle() const
424 int QAbstractAxis::labelsAngle() const
425 {
425 {
426 return d_ptr->m_labelsAngle;
426 return d_ptr->m_labelsAngle;
427 }
427 }
428
428
429 void QAbstractAxis::setLabelsColor(QColor color)
429 void QAbstractAxis::setLabelsColor(QColor color)
430 {
430 {
431 QBrush b = d_ptr->m_labelsBrush;
431 QBrush b = d_ptr->m_labelsBrush;
432 if (b.color() != color) {
432 if (b.color() != color) {
433 b.setColor(color);
433 b.setColor(color);
434 setLabelsBrush(b);
434 setLabelsBrush(b);
435 emit labelsColorChanged(color);
435 emit labelsColorChanged(color);
436 }
436 }
437 }
437 }
438
438
439 QColor QAbstractAxis::labelsColor() const
439 QColor QAbstractAxis::labelsColor() const
440 {
440 {
441 return d_ptr->m_labelsBrush.color();
441 return d_ptr->m_labelsBrush.color();
442 }
442 }
443
443
444 void QAbstractAxis::setShadesVisible(bool visible)
444 void QAbstractAxis::setShadesVisible(bool visible)
445 {
445 {
446 if (d_ptr->m_shadesVisible != visible) {
446 if (d_ptr->m_shadesVisible != visible) {
447 d_ptr->m_shadesVisible = visible;
447 d_ptr->m_shadesVisible = visible;
448 emit d_ptr->updated();
448 emit d_ptr->updated();
449 emit shadesVisibleChanged(visible);
449 emit shadesVisibleChanged(visible);
450 }
450 }
451 }
451 }
452
452
453 bool QAbstractAxis::shadesVisible() const
453 bool QAbstractAxis::shadesVisible() const
454 {
454 {
455 return d_ptr->m_shadesVisible;
455 return d_ptr->m_shadesVisible;
456 }
456 }
457
457
458 /*!
458 /*!
459 Sets \a pen used to draw shades.
459 Sets \a pen used to draw shades.
460 */
460 */
461 void QAbstractAxis::setShadesPen(const QPen &pen)
461 void QAbstractAxis::setShadesPen(const QPen &pen)
462 {
462 {
463 if (d_ptr->m_shadesPen != pen) {
463 if (d_ptr->m_shadesPen != pen) {
464 d_ptr->m_shadesPen = pen;
464 d_ptr->m_shadesPen = pen;
465 emit d_ptr->updated();
465 emit d_ptr->updated();
466 }
466 }
467 }
467 }
468
468
469 /*!
469 /*!
470 Returns pen used to draw shades.
470 Returns pen used to draw shades.
471 */
471 */
472 QPen QAbstractAxis::shadesPen() const
472 QPen QAbstractAxis::shadesPen() const
473 {
473 {
474 return d_ptr->m_shadesPen;
474 return d_ptr->m_shadesPen;
475 }
475 }
476
476
477 /*!
477 /*!
478 Sets \a brush used to draw shades.
478 Sets \a brush used to draw shades.
479 */
479 */
480 void QAbstractAxis::setShadesBrush(const QBrush &brush)
480 void QAbstractAxis::setShadesBrush(const QBrush &brush)
481 {
481 {
482 if (d_ptr->m_shadesBrush != brush) {
482 if (d_ptr->m_shadesBrush != brush) {
483 d_ptr->m_shadesBrush = brush;
483 d_ptr->m_shadesBrush = brush;
484 emit d_ptr->updated();
484 emit d_ptr->updated();
485 emit shadesColorChanged(brush.color());
485 emit shadesColorChanged(brush.color());
486 }
486 }
487 }
487 }
488
488
489 /*!
489 /*!
490 Returns brush used to draw shades.
490 Returns brush used to draw shades.
491 */
491 */
492 QBrush QAbstractAxis::shadesBrush() const
492 QBrush QAbstractAxis::shadesBrush() const
493 {
493 {
494 return d_ptr->m_shadesBrush;
494 return d_ptr->m_shadesBrush;
495 }
495 }
496
496
497 void QAbstractAxis::setShadesColor(QColor color)
497 void QAbstractAxis::setShadesColor(QColor color)
498 {
498 {
499 QBrush b = d_ptr->m_shadesBrush;
499 QBrush b = d_ptr->m_shadesBrush;
500 b.setColor(color);
500 b.setColor(color);
501 setShadesBrush(b);
501 setShadesBrush(b);
502 }
502 }
503
503
504 QColor QAbstractAxis::shadesColor() const
504 QColor QAbstractAxis::shadesColor() const
505 {
505 {
506 return d_ptr->m_shadesBrush.color();
506 return d_ptr->m_shadesBrush.color();
507 }
507 }
508
508
509 void QAbstractAxis::setShadesBorderColor(QColor color)
509 void QAbstractAxis::setShadesBorderColor(QColor color)
510 {
510 {
511 QPen p = d_ptr->m_shadesPen;
511 QPen p = d_ptr->m_shadesPen;
512 p.setColor(color);
512 p.setColor(color);
513 setShadesPen(p);
513 setShadesPen(p);
514 }
514 }
515
515
516 QColor QAbstractAxis::shadesBorderColor() const
516 QColor QAbstractAxis::shadesBorderColor() const
517 {
517 {
518 return d_ptr->m_shadesPen.color();
518 return d_ptr->m_shadesPen.color();
519 }
519 }
520
520
521
521
522 /*!
522 /*!
523 Sets axis, shades, labels and grid lines to be visible.
523 Sets axis, shades, labels and grid lines to be visible.
524 */
524 */
525 void QAbstractAxis::show()
525 void QAbstractAxis::show()
526 {
526 {
527 d_ptr->m_axisVisible=true;
527 d_ptr->m_axisVisible=true;
528 d_ptr->m_gridLineVisible=true;
528 d_ptr->m_gridLineVisible=true;
529 d_ptr->m_labelsVisible=true;
529 d_ptr->m_labelsVisible=true;
530 d_ptr->m_shadesVisible=true;
530 d_ptr->m_shadesVisible=true;
531 emit d_ptr->updated();
531 emit d_ptr->updated();
532 }
532 }
533
533
534 /*!
534 /*!
535 Sets axis, shades, labels and grid lines to not be visible.
535 Sets axis, shades, labels and grid lines to not be visible.
536 */
536 */
537 void QAbstractAxis::hide()
537 void QAbstractAxis::hide()
538 {
538 {
539 d_ptr->m_axisVisible = false;
539 d_ptr->m_axisVisible = false;
540 d_ptr->m_gridLineVisible = false;
540 d_ptr->m_gridLineVisible = false;
541 d_ptr->m_labelsVisible = false;
541 d_ptr->m_labelsVisible = false;
542 d_ptr->m_shadesVisible = false;
542 d_ptr->m_shadesVisible = false;
543 emit d_ptr->updated();
543 emit d_ptr->updated();
544 }
544 }
545
545
546
546
547 void QAbstractAxis::setMin(const qreal min)
547 void QAbstractAxis::setMin(const QVariant &min)
548 {
548 {
549 d_ptr->setMin(min);
549 d_ptr->setMin(min);
550 }
550 }
551 void QAbstractAxis::setMax(const qreal max)
551 void QAbstractAxis::setMax(const QVariant &max)
552 {
552 {
553 d_ptr->setMax(max);
553 d_ptr->setMax(max);
554 }
554 }
555 void QAbstractAxis::setRange(const qreal min, const qreal max)
555 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
556 {
556 {
557 d_ptr->setRange(min,max);
557 d_ptr->setRange(min,max);
558 }
558 }
559
559
560 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
560 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
561
561
562 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
562 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
563 q_ptr(q),
563 q_ptr(q),
564 m_axisVisible(true),
564 m_axisVisible(true),
565 m_gridLineVisible(true),
565 m_gridLineVisible(true),
566 m_labelsVisible(true),
566 m_labelsVisible(true),
567 m_labelsAngle(0),
567 m_labelsAngle(0),
568 m_shadesVisible(false),
568 m_shadesVisible(false),
569 m_shadesBrush(Qt::SolidPattern),
569 m_shadesBrush(Qt::SolidPattern),
570 m_shadesOpacity(1.0),
570 m_shadesOpacity(1.0),
571 m_orientation(Qt::Orientation(0)),
571 m_orientation(Qt::Orientation(0)),
572 m_min(0),
572 m_min(0),
573 m_max(0),
573 m_max(0),
574 m_ticksCount(5)
574 m_ticksCount(5)
575 {
575 {
576
576
577 }
577 }
578
578
579 QAbstractAxisPrivate::~QAbstractAxisPrivate()
579 QAbstractAxisPrivate::~QAbstractAxisPrivate()
580 {
580 {
581
581
582 }
582 }
583
583
584 #include "moc_qabstractaxis.cpp"
584 #include "moc_qabstractaxis.cpp"
585 #include "moc_qabstractaxis_p.cpp"
585 #include "moc_qabstractaxis_p.cpp"
586
586
587 QTCOMMERCIALCHART_END_NAMESPACE
587 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,130 +1,130
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QABSTRACTAXIS_H
21 #ifndef QABSTRACTAXIS_H
22 #define QABSTRACTAXIS_H
22 #define QABSTRACTAXIS_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QPen>
25 #include <QPen>
26 #include <QFont>
26 #include <QFont>
27 #include <QVariant>
27 #include <QVariant>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QAbstractAxisPrivate;
31 class QAbstractAxisPrivate;
32
32
33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36
36
37 Q_PROPERTY(bool visible READ isAxisVisible WRITE setAxisVisible NOTIFY visibleChanged)
37 Q_PROPERTY(bool visible READ isAxisVisible WRITE setAxisVisible NOTIFY visibleChanged)
38 Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged)
38 Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged)
39 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
39 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
40 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle)
40 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle)
41 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont)
41 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont)
42 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
42 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
43 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
43 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
44 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
44 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
45 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
45 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
46 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
46 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
47
47
48 public:
48 public:
49
49
50 enum AxisType {
50 enum AxisType {
51 AxisTypeValues,
51 AxisTypeValues,
52 AxisTypeCategories
52 AxisTypeCategories
53 };
53 };
54
54
55 protected:
55 protected:
56 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
56 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
57
57
58 public:
58 public:
59 ~QAbstractAxis();
59 ~QAbstractAxis();
60
60
61 virtual AxisType type() const = 0;
61 virtual AxisType type() const = 0;
62
62
63 //axis handling
63 //axis handling
64 bool isAxisVisible() const;
64 bool isAxisVisible() const;
65 void setAxisVisible(bool visible = true);
65 void setAxisVisible(bool visible = true);
66 void setAxisPen(const QPen &pen);
66 void setAxisPen(const QPen &pen);
67 QPen axisPen() const;
67 QPen axisPen() const;
68 void setAxisPenColor(QColor color);
68 void setAxisPenColor(QColor color);
69 QColor axisPenColor() const;
69 QColor axisPenColor() const;
70
70
71 //grid handling
71 //grid handling
72 bool isGridLineVisible() const;
72 bool isGridLineVisible() const;
73 void setGridLineVisible(bool visible = true);
73 void setGridLineVisible(bool visible = true);
74 void setGridLinePen(const QPen &pen);
74 void setGridLinePen(const QPen &pen);
75 QPen gridLinePen() const;
75 QPen gridLinePen() const;
76
76
77 //labels handling
77 //labels handling
78 bool labelsVisible() const;
78 bool labelsVisible() const;
79 void setLabelsVisible(bool visible = true);
79 void setLabelsVisible(bool visible = true);
80 void setLabelsPen(const QPen &pen);
80 void setLabelsPen(const QPen &pen);
81 QPen labelsPen() const;
81 QPen labelsPen() const;
82 void setLabelsBrush(const QBrush &brush);
82 void setLabelsBrush(const QBrush &brush);
83 QBrush labelsBrush() const;
83 QBrush labelsBrush() const;
84 void setLabelsFont(const QFont &font);
84 void setLabelsFont(const QFont &font);
85 QFont labelsFont() const;
85 QFont labelsFont() const;
86 void setLabelsAngle(int angle);
86 void setLabelsAngle(int angle);
87 int labelsAngle() const;
87 int labelsAngle() const;
88 void setLabelsColor(QColor color);
88 void setLabelsColor(QColor color);
89 QColor labelsColor() const;
89 QColor labelsColor() const;
90
90
91 //shades handling
91 //shades handling
92 bool shadesVisible() const;
92 bool shadesVisible() const;
93 void setShadesVisible(bool visible = true);
93 void setShadesVisible(bool visible = true);
94 void setShadesPen(const QPen &pen);
94 void setShadesPen(const QPen &pen);
95 QPen shadesPen() const;
95 QPen shadesPen() const;
96 void setShadesBrush(const QBrush &brush);
96 void setShadesBrush(const QBrush &brush);
97 QBrush shadesBrush() const;
97 QBrush shadesBrush() const;
98 void setShadesColor(QColor color);
98 void setShadesColor(QColor color);
99 QColor shadesColor() const;
99 QColor shadesColor() const;
100 void setShadesBorderColor(QColor color);
100 void setShadesBorderColor(QColor color);
101 QColor shadesBorderColor() const;
101 QColor shadesBorderColor() const;
102
102
103 //range handling
103 //range handling
104 void setMin(const qreal min);
104 void setMin(const QVariant &min);
105 void setMax(const qreal max);
105 void setMax(const QVariant &max);
106 void setRange(const qreal min, const qreal max);
106 void setRange(const QVariant &min, const QVariant &max);
107
107
108 void show();
108 void show();
109 void hide();
109 void hide();
110
110
111 Q_SIGNALS:
111 Q_SIGNALS:
112 void visibleChanged(bool visible);
112 void visibleChanged(bool visible);
113 void labelsVisibleChanged(bool visible);
113 void labelsVisibleChanged(bool visible);
114 void gridVisibleChanged(bool visible);
114 void gridVisibleChanged(bool visible);
115 void colorChanged(QColor color);
115 void colorChanged(QColor color);
116 void labelsColorChanged(QColor color);
116 void labelsColorChanged(QColor color);
117 void shadesVisibleChanged(bool visible);
117 void shadesVisibleChanged(bool visible);
118 void shadesColorChanged(QColor color);
118 void shadesColorChanged(QColor color);
119 void shadesBorderColorChanged(QColor color);
119 void shadesBorderColorChanged(QColor color);
120
120
121 protected:
121 protected:
122 QScopedPointer<QAbstractAxisPrivate> d_ptr;
122 QScopedPointer<QAbstractAxisPrivate> d_ptr;
123 Q_DISABLE_COPY(QAbstractAxis);
123 Q_DISABLE_COPY(QAbstractAxis);
124 friend class ChartDataSet;
124 friend class ChartDataSet;
125 friend class ChartAxis;
125 friend class ChartAxis;
126 friend class ChartPresenter;
126 friend class ChartPresenter;
127 };
127 };
128
128
129 QTCOMMERCIALCHART_END_NAMESPACE
129 QTCOMMERCIALCHART_END_NAMESPACE
130 #endif
130 #endif
@@ -1,93 +1,93
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QABSTRACTAXIS_P_H
30 #ifndef QABSTRACTAXIS_P_H
31 #define QABSTRACTAXIS_P_H
31 #define QABSTRACTAXIS_P_H
32
32
33 #include "qabstractaxis.h"
33 #include "qabstractaxis.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class ChartPresenter;
37 class ChartPresenter;
38 class ChartAxis;
38 class ChartAxis;
39
39
40 class QAbstractAxisPrivate : public QObject
40 class QAbstractAxisPrivate : public QObject
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43 public:
43 public:
44 QAbstractAxisPrivate(QAbstractAxis *q);
44 QAbstractAxisPrivate(QAbstractAxis *q);
45 ~QAbstractAxisPrivate();
45 ~QAbstractAxisPrivate();
46
46
47 Q_SIGNALS:
47 Q_SIGNALS:
48 void updated();
48 void updated();
49
49
50 public:
50 public:
51 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
51 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
52 virtual void updateRange() = 0;
52 virtual void updateRange() = 0;
53
53
54 protected:
54 protected:
55 virtual void setMin(const qreal min) = 0;
55 virtual void setMin(const QVariant &min) = 0;
56 virtual void setMax(const qreal max) = 0;
56 virtual void setMax(const QVariant &max) = 0;
57 virtual void setRange(const qreal min, const qreal max, bool force = false) = 0;
57 virtual void setRange(const QVariant &min, const QVariant &max, bool force = false) = 0;
58 virtual int ticksCount() const = 0;
58 virtual int ticksCount() const = 0;
59
59
60 public:
60 public:
61 QAbstractAxis *q_ptr;
61 QAbstractAxis *q_ptr;
62
62
63 bool m_axisVisible;
63 bool m_axisVisible;
64 QPen m_axisPen;
64 QPen m_axisPen;
65 QBrush m_axisBrush;
65 QBrush m_axisBrush;
66
66
67 bool m_gridLineVisible;
67 bool m_gridLineVisible;
68 QPen m_gridLinePen;
68 QPen m_gridLinePen;
69
69
70 bool m_labelsVisible;
70 bool m_labelsVisible;
71 QPen m_labelsPen;
71 QPen m_labelsPen;
72 QBrush m_labelsBrush;
72 QBrush m_labelsBrush;
73 QFont m_labelsFont;
73 QFont m_labelsFont;
74 int m_labelsAngle;
74 int m_labelsAngle;
75
75
76 bool m_shadesVisible;
76 bool m_shadesVisible;
77 QPen m_shadesPen;
77 QPen m_shadesPen;
78 QBrush m_shadesBrush;
78 QBrush m_shadesBrush;
79 qreal m_shadesOpacity;
79 qreal m_shadesOpacity;
80
80
81 Qt::Orientation m_orientation;
81 Qt::Orientation m_orientation;
82
82
83 // range
83 // range
84 qreal m_min;
84 qreal m_min;
85 qreal m_max;
85 qreal m_max;
86 int m_ticksCount;
86 int m_ticksCount;
87
87
88 friend class QAbstractAxis;
88 friend class QAbstractAxis;
89 };
89 };
90
90
91 QTCOMMERCIALCHART_END_NAMESPACE
91 QTCOMMERCIALCHART_END_NAMESPACE
92
92
93 #endif
93 #endif
@@ -1,301 +1,307
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 "qcategoriesaxis.h"
21 #include "qcategoriesaxis.h"
22 #include "qcategoriesaxis_p.h"
22 #include "qcategoriesaxis_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
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 QCategoriesAxis::QCategoriesAxis(QObject *parent):
29 QCategoriesAxis::QCategoriesAxis(QObject *parent):
30 QAbstractAxis(*new QCategoriesAxisPrivate(this),parent)
30 QAbstractAxis(*new QCategoriesAxisPrivate(this),parent)
31 {
31 {
32 }
32 }
33
33
34 QCategoriesAxis::~QCategoriesAxis()
34 QCategoriesAxis::~QCategoriesAxis()
35 {
35 {
36 }
36 }
37
37
38 QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
38 QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
39 {
39 {
40
40
41 }
41 }
42
42
43 /*!
43 /*!
44 Appends \a categories to axis
44 Appends \a categories to axis
45 */
45 */
46 void QCategoriesAxis::append(const QStringList &categories)
46 void QCategoriesAxis::append(const QStringList &categories)
47 {
47 {
48 Q_D(QCategoriesAxis);
48 Q_D(QCategoriesAxis);
49 d->m_categories.append(categories);
49 d->m_categories.append(categories);
50 emit categoriesChanged();
50 emit categoriesChanged();
51 }
51 }
52
52
53 /*!
53 /*!
54 Appends \a category to axis
54 Appends \a category to axis
55 */
55 */
56 void QCategoriesAxis::append(const QString &category)
56 void QCategoriesAxis::append(const QString &category)
57 {
57 {
58 Q_D(QCategoriesAxis);
58 Q_D(QCategoriesAxis);
59 d->m_categories.append(category);
59 d->m_categories.append(category);
60 emit categoriesChanged();
60 emit categoriesChanged();
61 }
61 }
62
62
63 /*!
63 /*!
64 Removes \a category from axis
64 Removes \a category from axis
65 */
65 */
66 void QCategoriesAxis::remove(const QString &category)
66 void QCategoriesAxis::remove(const QString &category)
67 {
67 {
68 Q_D(QCategoriesAxis);
68 Q_D(QCategoriesAxis);
69 if (d->m_categories.contains(category)) {
69 if (d->m_categories.contains(category)) {
70 d->m_categories.removeAt(d->m_categories.indexOf(category));
70 d->m_categories.removeAt(d->m_categories.indexOf(category));
71 emit categoriesChanged();
71 emit categoriesChanged();
72 }
72 }
73 }
73 }
74
74
75 /*!
75 /*!
76 Inserts \a category to axis at \a index
76 Inserts \a category to axis at \a index
77 */
77 */
78 void QCategoriesAxis::insert(int index, const QString &category)
78 void QCategoriesAxis::insert(int index, const QString &category)
79 {
79 {
80 Q_D(QCategoriesAxis);
80 Q_D(QCategoriesAxis);
81 d->m_categories.insert(index,category);
81 d->m_categories.insert(index,category);
82 emit categoriesChanged();
82 emit categoriesChanged();
83 }
83 }
84
84
85 /*!
85 /*!
86 Removes all categories.
86 Removes all categories.
87 */
87 */
88 void QCategoriesAxis::clear()
88 void QCategoriesAxis::clear()
89 {
89 {
90 Q_D(QCategoriesAxis);
90 Q_D(QCategoriesAxis);
91 d->m_categories.clear();
91 d->m_categories.clear();
92 emit categoriesChanged();
92 emit categoriesChanged();
93 }
93 }
94
94
95 void QCategoriesAxis::setCategories(const QStringList &categories)
95 void QCategoriesAxis::setCategories(const QStringList &categories)
96 {
96 {
97 Q_D(QCategoriesAxis);
97 Q_D(QCategoriesAxis);
98 d->m_categories = categories;
98 d->m_categories = categories;
99 emit categoriesChanged();
99 emit categoriesChanged();
100 }
100 }
101
101
102 QStringList QCategoriesAxis::categories()
102 QStringList QCategoriesAxis::categories()
103 {
103 {
104 Q_D(QCategoriesAxis);
104 Q_D(QCategoriesAxis);
105 return d->m_categories;
105 return d->m_categories;
106 }
106 }
107
107
108 /*!
108 /*!
109 Returns number of categories.
109 Returns number of categories.
110 */
110 */
111 int QCategoriesAxis::count() const
111 int QCategoriesAxis::count() const
112 {
112 {
113 Q_D(const QCategoriesAxis);
113 Q_D(const QCategoriesAxis);
114 return d->m_categories.count();
114 return d->m_categories.count();
115 }
115 }
116
116
117 /*!
117 /*!
118 Returns category at \a index. Index must be valid.
118 Returns category at \a index. Index must be valid.
119 */
119 */
120 QString QCategoriesAxis::at(int index) const
120 QString QCategoriesAxis::at(int index) const
121 {
121 {
122 Q_D(const QCategoriesAxis);
122 Q_D(const QCategoriesAxis);
123 return d->m_categories.at(index);
123 return d->m_categories.at(index);
124 }
124 }
125
125
126 /*!
126 /*!
127 Sets minimum category to \a minCategory.
127 Sets minimum category to \a minCategory.
128 */
128 */
129 void QCategoriesAxis::setMinCategory(const QString& minCategory)
129 void QCategoriesAxis::setMinCategory(const QString& minCategory)
130 {
130 {
131 Q_D(QCategoriesAxis);
131 Q_D(QCategoriesAxis);
132 d->setMinCategory(minCategory);
132 d->setMinCategory(minCategory);
133 }
133 }
134
134
135 /*!
135 /*!
136 Returns minimum category.
136 Returns minimum category.
137 */
137 */
138 QString QCategoriesAxis::minCategory() const
138 QString QCategoriesAxis::minCategory() const
139 {
139 {
140 Q_D(const QCategoriesAxis);
140 Q_D(const QCategoriesAxis);
141 return d->m_minCategory;
141 return d->m_minCategory;
142 }
142 }
143
143
144 /*!
144 /*!
145 Sets maximum category to \a maxCategory.
145 Sets maximum category to \a maxCategory.
146 */
146 */
147 void QCategoriesAxis::setMaxCategory(const QString& maxCategory)
147 void QCategoriesAxis::setMaxCategory(const QString& maxCategory)
148 {
148 {
149 Q_D(QCategoriesAxis);
149 Q_D(QCategoriesAxis);
150 d->setMaxCategory(maxCategory);
150 d->setMaxCategory(maxCategory);
151 }
151 }
152
152
153 /*!
153 /*!
154 Returns maximum category
154 Returns maximum category
155 */
155 */
156 QString QCategoriesAxis::maxCategory() const
156 QString QCategoriesAxis::maxCategory() const
157 {
157 {
158 Q_D(const QCategoriesAxis);
158 Q_D(const QCategoriesAxis);
159 return d->m_maxCategory;
159 return d->m_maxCategory;
160 }
160 }
161
161
162 /*!
162 /*!
163 Sets range from \a minCategory to \a maxCategory
163 Sets range from \a minCategory to \a maxCategory
164 */
164 */
165 void QCategoriesAxis::setCategoryRange(const QString& minCategory, const QString& maxCategory)
165 void QCategoriesAxis::setCategoryRange(const QString& minCategory, const QString& maxCategory)
166 {
166 {
167 Q_D(QCategoriesAxis);
167 Q_D(QCategoriesAxis);
168 d->setRangeCategory(minCategory,maxCategory);
168 d->setRangeCategory(minCategory,maxCategory);
169 }
169 }
170
170
171 /*!
171 /*!
172 Returns the type of axis.
172 Returns the type of axis.
173 */
173 */
174 QAbstractAxis::AxisType QCategoriesAxis::type() const
174 QAbstractAxis::AxisType QCategoriesAxis::type() const
175 {
175 {
176 return AxisTypeCategories;
176 return AxisTypeCategories;
177 }
177 }
178
178
179 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
179 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
180
180
181 QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q):
181 QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q):
182 QAbstractAxisPrivate(q)
182 QAbstractAxisPrivate(q)
183 {
183 {
184
184
185 }
185 }
186
186
187 QCategoriesAxisPrivate::~QCategoriesAxisPrivate()
187 QCategoriesAxisPrivate::~QCategoriesAxisPrivate()
188 {
188 {
189
189
190 }
190 }
191
191
192 void QCategoriesAxisPrivate::setMinCategory(const QString& minCategory)
192 void QCategoriesAxisPrivate::setMinCategory(const QString& minCategory)
193 {
193 {
194 // Convert the category to value
194 // Convert the category to value
195 int minIndex = m_categories.indexOf(minCategory);
195 int minIndex = m_categories.indexOf(minCategory);
196 if (minIndex == -1) {
196 if (minIndex == -1) {
197 return;
197 return;
198 }
198 }
199
199
200 int maxIndex = qFloor(m_max);
200 int maxIndex = qFloor(m_max);
201 if (minIndex > maxIndex) {
201 if (minIndex > maxIndex) {
202 maxIndex = m_categories.count()-1;
202 maxIndex = m_categories.count()-1;
203 }
203 }
204 setRange(minIndex - 0.5, maxIndex + 0.5);
204 setRange(minIndex - 0.5, maxIndex + 0.5);
205 }
205 }
206
206
207 void QCategoriesAxisPrivate::setMaxCategory(const QString& maxCategory)
207 void QCategoriesAxisPrivate::setMaxCategory(const QString& maxCategory)
208 {
208 {
209 // Convert the category to value
209 // Convert the category to value
210 int maxIndex = m_categories.indexOf(maxCategory);
210 int maxIndex = m_categories.indexOf(maxCategory);
211 if (maxIndex == -1) {
211 if (maxIndex == -1) {
212 return;
212 return;
213 }
213 }
214
214
215 int minIndex = qCeil(m_min);
215 int minIndex = qCeil(m_min);
216 if (maxIndex < minIndex) {
216 if (maxIndex < minIndex) {
217 minIndex = 0;
217 minIndex = 0;
218 }
218 }
219 setRange(minIndex - 0.5, maxIndex + 0.5);
219 setRange(minIndex - 0.5, maxIndex + 0.5);
220 }
220 }
221
221
222 void QCategoriesAxisPrivate::setRangeCategory(const QString& minCategory, const QString& maxCategory)
222 void QCategoriesAxisPrivate::setRangeCategory(const QString& minCategory, const QString& maxCategory)
223 {
223 {
224 // TODO:
224 // TODO:
225 int minIndex = m_categories.indexOf(minCategory);
225 int minIndex = m_categories.indexOf(minCategory);
226 if (minIndex == -1) {
226 if (minIndex == -1) {
227 return;
227 return;
228 }
228 }
229 int maxIndex = m_categories.indexOf(maxCategory);
229 int maxIndex = m_categories.indexOf(maxCategory);
230 if (maxIndex == -1) {
230 if (maxIndex == -1) {
231 return;
231 return;
232 }
232 }
233 setRange(minIndex -0.5, maxIndex + 0.5);
233 setRange(minIndex -0.5, maxIndex + 0.5);
234 }
234 }
235
235
236 void QCategoriesAxisPrivate::setMin(const qreal min)
236 void QCategoriesAxisPrivate::setMin(const QVariant &min)
237 {
237 {
238 setRange(min,m_max);
238 setRange(min,m_max);
239 }
239 }
240
240
241 void QCategoriesAxisPrivate::setMax(const qreal max)
241 void QCategoriesAxisPrivate::setMax(const QVariant &max)
242 {
242 {
243 setRange(m_min,max);
243 setRange(m_min,max);
244 }
244 }
245
245
246 void QCategoriesAxisPrivate::setRange(const qreal min, const qreal max, bool force)
246 void QCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max, bool force)
247 {
247 {
248 Q_UNUSED(min);
249 Q_UNUSED(max);
250 Q_UNUSED(force);
251 // TODO: refactor
252 /*
248 if (max <= min) {
253 if (max <= min) {
249 // max must be greater than min
254 // max must be greater than min
250 return;
255 return;
251 }
256 }
252 Q_Q(QCategoriesAxis);
257 Q_Q(QCategoriesAxis);
253 bool changed = false;
258 bool changed = false;
254 if (!qFuzzyIsNull(m_min - min)) {
259 if (!qFuzzyIsNull(m_min - min)) {
255 m_min = min;
260 m_min = min;
256 changed = true;
261 changed = true;
257 }
262 }
258
263
259 if (!qFuzzyIsNull(m_max - max)) {
264 if (!qFuzzyIsNull(m_max - max)) {
260 m_max = max;
265 m_max = max;
261 changed = true;
266 changed = true;
262 }
267 }
263
268
264 if ((changed) ||(force)) {
269 if ((changed) ||(force)) {
265 emit this->changed(m_min, m_max, qCeil(m_max) -qCeil(m_min) +1, false);
270 emit this->changed(m_min, m_max, qCeil(m_max) -qCeil(m_min) +1, false);
266 emit q->categoriesChanged();
271 emit q->categoriesChanged();
267 }
272 }
273 */
268 }
274 }
269
275
270 int QCategoriesAxisPrivate::ticksCount() const
276 int QCategoriesAxisPrivate::ticksCount() const
271 {
277 {
272 return m_categories.count()+1;
278 return m_categories.count()+1;
273 }
279 }
274
280
275 void QCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
281 void QCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
276 {
282 {
277 m_min = min;
283 m_min = min;
278 m_max = max;
284 m_max = max;
279 m_ticksCount = count;
285 m_ticksCount = count;
280 }
286 }
281
287
282 ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
288 ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
283 {
289 {
284 Q_Q( QCategoriesAxis);
290 Q_Q( QCategoriesAxis);
285 if(m_orientation == Qt::Vertical){
291 if(m_orientation == Qt::Vertical){
286 return new ChartCategoriesAxisY(q,presenter);
292 return new ChartCategoriesAxisY(q,presenter);
287 }else{
293 }else{
288 return new ChartCategoriesAxisX(q,presenter);
294 return new ChartCategoriesAxisX(q,presenter);
289 }
295 }
290 }
296 }
291
297
292 void QCategoriesAxisPrivate::updateRange()
298 void QCategoriesAxisPrivate::updateRange()
293 {
299 {
294 setRange(m_min,m_max,true);
300 setRange(m_min,m_max,true);
295 }
301 }
296
302
297
303
298 #include "moc_qcategoriesaxis.cpp"
304 #include "moc_qcategoriesaxis.cpp"
299 #include "moc_qcategoriesaxis_p.cpp"
305 #include "moc_qcategoriesaxis_p.cpp"
300
306
301 QTCOMMERCIALCHART_END_NAMESPACE
307 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,72 +1,76
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 QCATEGORIESAXIS_H
21 #ifndef QCATEGORIESAXIS_H
22 #define QCATEGORIESAXIS_H
22 #define QCATEGORIESAXIS_H
23
23
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 class QCategoriesAxisPrivate;
28 class QCategoriesAxisPrivate;
29
29
30 class QTCOMMERCIALCHART_EXPORT QCategoriesAxis : public QAbstractAxis
30 class QTCOMMERCIALCHART_EXPORT QCategoriesAxis : public QAbstractAxis
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33 Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged)
33 Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged)
34
34
35 public:
35 public:
36 explicit QCategoriesAxis(QObject *parent = 0);
36 explicit QCategoriesAxis(QObject *parent = 0);
37 ~QCategoriesAxis();
37 ~QCategoriesAxis();
38
38
39 protected:
39 protected:
40 QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent = 0);
40 QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent = 0);
41
41
42 public:
42 public:
43 AxisType type() const;
43 AxisType type() const;
44 void append(const QStringList &categories);
44 void append(const QStringList &categories);
45 void append(const QString &category);
45 void append(const QString &category);
46 void remove(const QString &category);
46 void remove(const QString &category);
47 void insert(int index, const QString &category);
47 void insert(int index, const QString &category);
48 void clear();
48 void clear();
49 void setCategories(const QStringList &categories);
49 void setCategories(const QStringList &categories);
50 QStringList categories();
50 QStringList categories();
51 int count() const;
51 int count() const;
52
52
53 QString at(int index) const;
53 QString at(int index) const;
54
54
55 //range handling convenience functions
55 //range handling convenience functions
56 void setMinCategory(const QString& minCategory);
56 void setMinCategory(const QString& minCategory);
57 QString minCategory() const;
57 QString minCategory() const;
58 void setMaxCategory(const QString& maxCategory);
58 void setMaxCategory(const QString& maxCategory);
59 QString maxCategory() const;
59 QString maxCategory() const;
60 void setCategoryRange(const QString& minCategory, const QString& maxCategory);
60 void setCategoryRange(const QString& minCategory, const QString& maxCategory);
61
61
62 void setMin(const QVariant &min);
63 void setMax(const QVariant &max);
64 void setRange(const QVariant &min, const QVariant &max);
65
62 Q_SIGNALS:
66 Q_SIGNALS:
63 void categoriesChanged();
67 void categoriesChanged();
64
68
65 private:
69 private:
66 Q_DECLARE_PRIVATE(QCategoriesAxis)
70 Q_DECLARE_PRIVATE(QCategoriesAxis)
67 Q_DISABLE_COPY(QCategoriesAxis)
71 Q_DISABLE_COPY(QCategoriesAxis)
68 };
72 };
69
73
70 QTCOMMERCIALCHART_END_NAMESPACE
74 QTCOMMERCIALCHART_END_NAMESPACE
71
75
72 #endif // QCATEGORIESAXIS_H
76 #endif // QCATEGORIESAXIS_H
@@ -1,78 +1,78
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QCATEGORIESAXIS_P_H
30 #ifndef QCATEGORIESAXIS_P_H
31 #define QCATEGORIESAXIS_P_H
31 #define QCATEGORIESAXIS_P_H
32
32
33 #include "qcategoriesaxis.h"
33 #include "qcategoriesaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qabstractaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QCategoriesAxisPrivate : public QAbstractAxisPrivate
38 class QCategoriesAxisPrivate : public QAbstractAxisPrivate
39 {
39 {
40 Q_OBJECT
40 Q_OBJECT
41
41
42 public:
42 public:
43 QCategoriesAxisPrivate(QCategoriesAxis *q);
43 QCategoriesAxisPrivate(QCategoriesAxis *q);
44 ~QCategoriesAxisPrivate();
44 ~QCategoriesAxisPrivate();
45
45
46 public:
46 public:
47 ChartAxis* createGraphics(ChartPresenter* presenter);
47 ChartAxis* createGraphics(ChartPresenter* presenter);
48 void updateRange();
48 void updateRange();
49
49
50 private:
50 private:
51 void setMinCategory(const QString& minCategory);
51 void setMinCategory(const QString& minCategory);
52 void setMaxCategory(const QString& maxCategory);
52 void setMaxCategory(const QString& maxCategory);
53 void setRangeCategory(const QString& minCategory, const QString& maxCategory);
53 void setRangeCategory(const QString& minCategory, const QString& maxCategory);
54
54
55 //range handling
55 //range handling
56 void setMin(const qreal min);
56 void setMin(const QVariant &min);
57 void setMax(const qreal max);
57 void setMax(const QVariant &max);
58 void setRange(const qreal min, const qreal max, bool force = false);
58 void setRange(const QVariant &min, const QVariant &max, bool force = false);
59 int ticksCount() const;
59 int ticksCount() const;
60
60
61 Q_SIGNALS:
61 Q_SIGNALS:
62 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
62 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
63
63
64 public Q_SLOTS:
64 public Q_SLOTS:
65 void handleAxisRangeChanged(qreal min, qreal max,int count);
65 void handleAxisRangeChanged(qreal min, qreal max,int count);
66
66
67 private:
67 private:
68 QStringList m_categories;
68 QStringList m_categories;
69 QString m_minCategory;
69 QString m_minCategory;
70 QString m_maxCategory;
70 QString m_maxCategory;
71
71
72 private:
72 private:
73 Q_DECLARE_PUBLIC(QCategoriesAxis)
73 Q_DECLARE_PUBLIC(QCategoriesAxis)
74 };
74 };
75
75
76 QTCOMMERCIALCHART_END_NAMESPACE
76 QTCOMMERCIALCHART_END_NAMESPACE
77
77
78 #endif // QCATEGORIESAXIS_P_H
78 #endif // QCATEGORIESAXIS_P_H
@@ -1,277 +1,289
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 "qvaluesaxis.h"
21 #include "qvaluesaxis.h"
22 #include "qvaluesaxis_p.h"
22 #include "qvaluesaxis_p.h"
23 #include "chartvaluesaxisx_p.h"
23 #include "chartvaluesaxisx_p.h"
24 #include "chartvaluesaxisy_p.h"
24 #include "chartvaluesaxisy_p.h"
25 #include <QDebug>
25 #include <QDebug>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 /*!
28 /*!
29 \class QValuesAxis
29 \class QValuesAxis
30 \brief The QValuesAxis class is used for manipulating chart's axis.
30 \brief The QValuesAxis class is used for manipulating chart's axis.
31 \mainclass
31 \mainclass
32
32
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 Axis QValuesAxis
37 \qmlclass Axis QValuesAxis
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 Axis can be setup to show axis line with tick marks, grid lines and shades.
40 Axis can be setup to show axis line with tick marks, grid lines and shades.
41
41
42 To access Axes you can use ChartView API. For example:
42 To access Axes you can use ChartView API. For example:
43 \code
43 \code
44 ChartView {
44 ChartView {
45 axisX.min: 0
45 axisX.min: 0
46 axisX.max: 3
46 axisX.max: 3
47 axisX.ticksCount: 4
47 axisX.ticksCount: 4
48 axisY.min: 0
48 axisY.min: 0
49 axisY.max: 4
49 axisY.max: 4
50 // Add a few series...
50 // Add a few series...
51 }
51 }
52 \endcode
52 \endcode
53 */
53 */
54
54
55 /*!
55 /*!
56 \property QValuesAxis::min
56 \property QValuesAxis::min
57 Defines the minimum value on the axis.
57 Defines the minimum value on the axis.
58 */
58 */
59 /*!
59 /*!
60 \qmlproperty real Axis::min
60 \qmlproperty real Axis::min
61 Defines the minimum value on the axis.
61 Defines the minimum value on the axis.
62 */
62 */
63
63
64 /*!
64 /*!
65 \property QValuesAxis::max
65 \property QValuesAxis::max
66 Defines the maximum value on the axis.
66 Defines the maximum value on the axis.
67 */
67 */
68 /*!
68 /*!
69 \qmlproperty real Axis::max
69 \qmlproperty real Axis::max
70 Defines the maximum value on the axis.
70 Defines the maximum value on the axis.
71 */
71 */
72
72
73 /*!
73 /*!
74 \fn void QValuesAxis::minChanged(qreal min)
74 \fn void QValuesAxis::minChanged(qreal min)
75 Axis emits signal when \a min of axis has changed.
75 Axis emits signal when \a min of axis has changed.
76 */
76 */
77
77
78 /*!
78 /*!
79 \fn void QValuesAxis::maxChanged(qreal max)
79 \fn void QValuesAxis::maxChanged(qreal max)
80 Axis emits signal when \a max of axis has changed.
80 Axis emits signal when \a max of axis has changed.
81 */
81 */
82
82
83 /*!
83 /*!
84 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
84 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
85 Axis emits signal when \a min or \a max of axis has changed.
85 Axis emits signal when \a min or \a max of axis has changed.
86 */
86 */
87
87
88 /*!
88 /*!
89 \property QValuesAxis::ticksCount
89 \property QValuesAxis::ticksCount
90 The number of tick marks for the axis.
90 The number of tick marks for the axis.
91 */
91 */
92
92
93 /*!
93 /*!
94 \qmlproperty int Axis::ticksCount
94 \qmlproperty int Axis::ticksCount
95 The number of tick marks for the axis.
95 The number of tick marks for the axis.
96 */
96 */
97
97
98 /*!
98 /*!
99 \property QValuesAxis::niceNumbersEnabled
99 \property QValuesAxis::niceNumbersEnabled
100 Whether the nice numbers algorithm is enabled or not for the axis.
100 Whether the nice numbers algorithm is enabled or not for the axis.
101 */
101 */
102
102
103 /*!
103 /*!
104 \qmlproperty bool Axis::niceNumbersEnabled
104 \qmlproperty bool Axis::niceNumbersEnabled
105 Whether the nice numbers algorithm is enabled or not for the axis.
105 Whether the nice numbers algorithm is enabled or not for the axis.
106 */
106 */
107
107
108 QValuesAxis::QValuesAxis(QObject *parent) :
108 QValuesAxis::QValuesAxis(QObject *parent) :
109 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
109 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
110 {
110 {
111
111
112 }
112 }
113
113
114 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
114 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
115 {
115 {
116
116
117 }
117 }
118
118
119 QValuesAxis::~QValuesAxis()
119 QValuesAxis::~QValuesAxis()
120 {
120 {
121
121
122 }
122 }
123
123
124 void QValuesAxis::setMin(qreal min)
124 void QValuesAxis::setMin(qreal min)
125 {
125 {
126 Q_D(QValuesAxis);
126 Q_D(QValuesAxis);
127 setRange(min,d->m_max);
127 setRange(min,d->m_max);
128 }
128 }
129
129
130 qreal QValuesAxis::min() const
130 qreal QValuesAxis::min() const
131 {
131 {
132 Q_D(const QValuesAxis);
132 Q_D(const QValuesAxis);
133 return d->m_min;
133 return d->m_min;
134 }
134 }
135
135
136 void QValuesAxis::setMax(qreal max)
136 void QValuesAxis::setMax(qreal max)
137 {
137 {
138 Q_D(QValuesAxis);
138 Q_D(QValuesAxis);
139 setRange(d->m_min,max);
139 setRange(d->m_min,max);
140 }
140 }
141
141
142 qreal QValuesAxis::max() const
142 qreal QValuesAxis::max() const
143 {
143 {
144 Q_D(const QValuesAxis);
144 Q_D(const QValuesAxis);
145 return d->m_max;
145 return d->m_max;
146 }
146 }
147
147
148 /*!
148 /*!
149 Sets range from \a min to \a max on the axis.
149 Sets range from \a min to \a max on the axis.
150 */
150 */
151 void QValuesAxis::setRange(qreal min, qreal max)
151 void QValuesAxis::setRange(qreal min, qreal max)
152 {
152 {
153 Q_D(QValuesAxis);
153 Q_D(QValuesAxis);
154 bool changed = false;
155 if (!qFuzzyIsNull(d->m_min - min)) {
156 d->m_min = min;
157 changed = true;
158 emit minChanged(min);
159 }
160
161 if (!qFuzzyIsNull(d->m_max - max)) {
162 d->m_max = max;
163 changed = true;
164 emit maxChanged(max);
165 }
166
167 if (changed) {
168 emit rangeChanged(d->m_min,d->m_max);
169 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
170 }
154 d->setRange(min,max);
171 d->setRange(min,max);
155 }
172 }
156
173
157 /*!
174 /*!
158 Sets \a count for ticks on the axis.
175 Sets \a count for ticks on the axis.
159 */
176 */
160 void QValuesAxis::setTicksCount(int count)
177 void QValuesAxis::setTicksCount(int count)
161 {
178 {
162 Q_D(QValuesAxis);
179 Q_D(QValuesAxis);
163 if (d->m_ticksCount != count) {
180 if (d->m_ticksCount != count) {
164 d->m_ticksCount = count;
181 d->m_ticksCount = count;
165 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
182 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
166 }
183 }
167 }
184 }
168
185
169 /*!
186 /*!
170 \fn int QValuesAxis::ticksCount() const
187 \fn int QValuesAxis::ticksCount() const
171 Return number of ticks on the axis
188 Return number of ticks on the axis
172 */
189 */
173 int QValuesAxis::ticksCount() const
190 int QValuesAxis::ticksCount() const
174 {
191 {
175 Q_D(const QValuesAxis);
192 Q_D(const QValuesAxis);
176 return d->m_ticksCount;
193 return d->m_ticksCount;
177 }
194 }
178
195
179 void QValuesAxis::setNiceNumbersEnabled(bool enable)
196 void QValuesAxis::setNiceNumbersEnabled(bool enable)
180 {
197 {
181 Q_D(QValuesAxis);
198 Q_D(QValuesAxis);
182 if (d->m_niceNumbers != enable){
199 if (d->m_niceNumbers != enable){
183 d->m_niceNumbers = enable;
200 d->m_niceNumbers = enable;
184 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
201 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
185 }
202 }
186 }
203 }
187
204
188 bool QValuesAxis::niceNumbersEnabled() const
205 bool QValuesAxis::niceNumbersEnabled() const
189 {
206 {
190 Q_D(const QValuesAxis);
207 Q_D(const QValuesAxis);
191 return d->m_niceNumbers;
208 return d->m_niceNumbers;
192 }
209 }
193
210
194 QAbstractAxis::AxisType QValuesAxis::type() const
211 QAbstractAxis::AxisType QValuesAxis::type() const
195 {
212 {
196 return AxisTypeValues;
213 return AxisTypeValues;
197 }
214 }
198
215
199 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
216 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
200
217
201 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
218 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
202 QAbstractAxisPrivate(q),
219 QAbstractAxisPrivate(q),
203 m_niceNumbers(false)
220 m_niceNumbers(false)
204 {
221 {
205
222
206 }
223 }
207
224
208 QValuesAxisPrivate::~QValuesAxisPrivate()
225 QValuesAxisPrivate::~QValuesAxisPrivate()
209 {
226 {
210
227
211 }
228 }
212
229
213 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
230 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
214 {
231 {
215 Q_Q(QValuesAxis);
232 Q_Q(QValuesAxis);
216 q->setRange(min,max);
233 q->setRange(min,max);
217 q->setTicksCount(count);
234 q->setTicksCount(count);
218 }
235 }
219
236
220
237
221 void QValuesAxisPrivate::setMin(const qreal min)
238 void QValuesAxisPrivate::setMin(const QVariant &min)
222 {
239 {
223 setRange(min,m_max);
240 Q_Q(QValuesAxis);
241 bool ok;
242 qreal value = min.toReal(&ok);
243 if(ok) q->setMin(value);
224 }
244 }
225
245
226 void QValuesAxisPrivate::setMax(const qreal max)
246 void QValuesAxisPrivate::setMax(const QVariant &max)
227 {
247 {
228 setRange(m_min,max);
248 Q_Q(QValuesAxis);
249 bool ok;
250 qreal value = max.toReal(&ok);
251 if(ok) q->setMax(value);
229 }
252 }
230
253
231 void QValuesAxisPrivate::setRange(const qreal min, const qreal max, bool force)
254 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max, bool force)
232 {
255 {
256 Q_UNUSED(force); // TODO: use this
233 Q_Q(QValuesAxis);
257 Q_Q(QValuesAxis);
234 bool changed = false;
258 bool ok1;
235 if (!qFuzzyIsNull(m_min - min)) {
259 bool ok2;
236 m_min = min;
260 qreal value1 = min.toReal(&ok1);
237 changed = true;
261 qreal value2 = max.toReal(&ok2);
238 emit q->minChanged(min);
262 if(ok1&&ok2) q->setRange(value1,value2);
239 }
240
241 if (!qFuzzyIsNull(m_max - max)) {
242 m_max = max;
243 changed = true;
244 emit q->maxChanged(max);
245 }
246
247 if ((changed) ||(force)) {
248 emit q->rangeChanged(m_min,m_max);
249 emit this->changed(m_min, m_max, m_ticksCount, m_niceNumbers);
250 }
251 }
263 }
252
264
253 int QValuesAxisPrivate::ticksCount() const
265 int QValuesAxisPrivate::ticksCount() const
254 {
266 {
255 return m_ticksCount;
267 return m_ticksCount;
256 }
268 }
257
269
258 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
270 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
259 {
271 {
260 Q_Q(QValuesAxis);
272 Q_Q(QValuesAxis);
261 if(m_orientation == Qt::Vertical){
273 if(m_orientation == Qt::Vertical){
262 return new ChartValuesAxisY(q,presenter);
274 return new ChartValuesAxisY(q,presenter);
263 }else{
275 }else{
264 return new ChartValuesAxisX(q,presenter);
276 return new ChartValuesAxisX(q,presenter);
265 }
277 }
266
278
267 }
279 }
268
280
269 void QValuesAxisPrivate::updateRange()
281 void QValuesAxisPrivate::updateRange()
270 {
282 {
271 setRange(m_min,m_max,true);
283 setRange(m_min,m_max,true);
272 }
284 }
273
285
274 #include "moc_qvaluesaxis.cpp"
286 #include "moc_qvaluesaxis.cpp"
275 #include "moc_qvaluesaxis_p.cpp"
287 #include "moc_qvaluesaxis_p.cpp"
276
288
277 QTCOMMERCIALCHART_END_NAMESPACE
289 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,68 +1,68
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QVALUESAXIS_P_H
30 #ifndef QVALUESAXIS_P_H
31 #define QVALUESAXIS_P_H
31 #define QVALUESAXIS_P_H
32
32
33 #include "qvaluesaxis.h"
33 #include "qvaluesaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qabstractaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QValuesAxisPrivate : public QAbstractAxisPrivate
38 class QValuesAxisPrivate : public QAbstractAxisPrivate
39 {
39 {
40 Q_OBJECT
40 Q_OBJECT
41 public:
41 public:
42 QValuesAxisPrivate(QValuesAxis *q);
42 QValuesAxisPrivate(QValuesAxis *q);
43 ~QValuesAxisPrivate();
43 ~QValuesAxisPrivate();
44
44
45 Q_SIGNALS:
45 Q_SIGNALS:
46 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
46 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
47
47
48 public Q_SLOTS:
48 public Q_SLOTS:
49 void handleAxisRangeChanged(qreal min, qreal max,int count);
49 void handleAxisRangeChanged(qreal min, qreal max,int count);
50
50
51 public:
51 public:
52 ChartAxis* createGraphics(ChartPresenter* presenter);
52 ChartAxis* createGraphics(ChartPresenter* presenter);
53 void updateRange();
53 void updateRange();
54
54
55 protected:
55 protected:
56 void setMin(const qreal min);
56 void setMin(const QVariant &min);
57 void setMax(const qreal max);
57 void setMax(const QVariant &max);
58 void setRange(const qreal min, const qreal max, bool force = false);
58 void setRange(const QVariant &min, const QVariant &max, bool force = false);
59 int ticksCount() const;
59 int ticksCount() const;
60
60
61 private:
61 private:
62 bool m_niceNumbers;
62 bool m_niceNumbers;
63 Q_DECLARE_PUBLIC(QValuesAxis)
63 Q_DECLARE_PUBLIC(QValuesAxis)
64 };
64 };
65
65
66 QTCOMMERCIALCHART_END_NAMESPACE
66 QTCOMMERCIALCHART_END_NAMESPACE
67
67
68 #endif // QVALUESAXIS_P_H
68 #endif // QVALUESAXIS_P_H
General Comments 0
You need to be logged in to leave comments. Login now