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