@@ -1,90 +1,90 | |||||
1 | /*! |
|
1 | /*! | |
2 | \page classes.html |
|
2 | \page classes.html | |
3 | \title QtCommercial Charts API |
|
3 | \title QtCommercial Charts API | |
4 | \keyword All Classes |
|
4 | \keyword All Classes | |
5 |
|
5 | |||
6 | Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However |
|
6 | Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However | |
7 | there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget. |
|
7 | there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget. | |
8 |
|
8 | |||
9 | Each chart type is represented by QAbstractSeries derived class. To create given chart type users have to use instance of related series class and add it to QChart instance. |
|
9 | Each chart type is represented by QAbstractSeries derived class. To create given chart type users have to use instance of related series class and add it to QChart instance. | |
10 | \code |
|
10 | \code | |
11 | QLineSeries* series = new QLineSeries(); |
|
11 | QLineSeries* series = new QLineSeries(); | |
12 | series->add(0, 6); |
|
12 | series->add(0, 6); | |
13 | series->add(2, 4); |
|
13 | series->add(2, 4); | |
14 | ... |
|
14 | ... | |
15 | chartView->chart()->addSeries(series); |
|
15 | chartView->chart()->addSeries(series); | |
16 | chartView->chart()->createDefaultAxes(); |
|
16 | chartView->chart()->createDefaultAxes(); | |
17 | \endcode |
|
17 | \endcode | |
18 |
|
18 | |||
19 | \raw HTML |
|
19 | \raw HTML | |
20 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> |
|
20 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> | |
21 | <tr> |
|
21 | <tr> | |
22 | <th class="titleheader" width="25%"> |
|
22 | <th class="titleheader" width="25%"> | |
23 | Common and global |
|
23 | Common and global | |
24 | </th> |
|
24 | </th> | |
25 | <th class="titleheader" width="25%"> |
|
25 | <th class="titleheader" width="25%"> | |
26 | XY chart |
|
26 | XY chart | |
27 | </th> |
|
27 | </th> | |
28 | </tr> |
|
28 | </tr> | |
29 | <tr> |
|
29 | <tr> | |
30 | <td valign="top"> |
|
30 | <td valign="top"> | |
31 | <ul> |
|
31 | <ul> | |
32 | <li><a href="qchart.html">QChart</a></li> |
|
32 | <li><a href="qchart.html">QChart</a></li> | |
33 | <li><a href="qchartview.html">QChartView</a></li> |
|
33 | <li><a href="qchartview.html">QChartView</a></li> | |
34 | <li><a href="qabstractaxis.html">QAbstractAxis</a></li> |
|
34 | <li><a href="qabstractaxis.html">QAbstractAxis</a></li> | |
35 |
<li><a href="qvalue |
|
35 | <li><a href="qvalueaxis.html">QValueAxis</a></li> | |
36 |
<li><a href="qbarcategor |
|
36 | <li><a href="qbarcategoryaxis.html">QBarCategoryAxis</a></li> | |
37 | <li><a href="qintervalsaxis.html">QIntervalsAxis</a></li> |
|
37 | <li><a href="qintervalsaxis.html">QIntervalsAxis</a></li> | |
38 | <li><a href="qlegend.html">QLegend</a></li> |
|
38 | <li><a href="qlegend.html">QLegend</a></li> | |
39 | <li><a href="qabstractseries.html">QAbstractSeries</a></li> |
|
39 | <li><a href="qabstractseries.html">QAbstractSeries</a></li> | |
40 | <li><a href="qchartglobal.html">QChartGlobal</a></li> |
|
40 | <li><a href="qchartglobal.html">QChartGlobal</a></li> | |
41 | </ul> |
|
41 | </ul> | |
42 | </td> |
|
42 | </td> | |
43 | <td valign="top"> |
|
43 | <td valign="top"> | |
44 | <ul> |
|
44 | <ul> | |
45 | <li><a href="qxyseries.html">QXYSeries</a></li> |
|
45 | <li><a href="qxyseries.html">QXYSeries</a></li> | |
46 | <li><a href="qlineseries.html">QLineSeries</a></li> |
|
46 | <li><a href="qlineseries.html">QLineSeries</a></li> | |
47 | <li><a href="qareaseries.html">QAreaSeries</a></li> |
|
47 | <li><a href="qareaseries.html">QAreaSeries</a></li> | |
48 | <li><a href="qscatterseries.html">QScatterSeries</a></li> |
|
48 | <li><a href="qscatterseries.html">QScatterSeries</a></li> | |
49 | <li><a href="qsplineseries.html">QSplineSeries</a></li> |
|
49 | <li><a href="qsplineseries.html">QSplineSeries</a></li> | |
50 | <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li> |
|
50 | <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li> | |
51 | <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li> |
|
51 | <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li> | |
52 | </ul> |
|
52 | </ul> | |
53 | </td> |
|
53 | </td> | |
54 | </tr> |
|
54 | </tr> | |
55 | </table> |
|
55 | </table> | |
56 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> |
|
56 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> | |
57 | <tr> |
|
57 | <tr> | |
58 | <th class="titleheader" width="25%"> |
|
58 | <th class="titleheader" width="25%"> | |
59 | Pie chart |
|
59 | Pie chart | |
60 | </th> |
|
60 | </th> | |
61 | <th class="titleheader" width="25%"> |
|
61 | <th class="titleheader" width="25%"> | |
62 | Bar chart |
|
62 | Bar chart | |
63 | </th> |
|
63 | </th> | |
64 | <tr> |
|
64 | <tr> | |
65 | <td valign="top"> |
|
65 | <td valign="top"> | |
66 | <ul> |
|
66 | <ul> | |
67 | <li><a href="qpieseries.html">QPieSeries</a></li> |
|
67 | <li><a href="qpieseries.html">QPieSeries</a></li> | |
68 | <li><a href="qpieslice.html">QPieSlice</a></li> |
|
68 | <li><a href="qpieslice.html">QPieSlice</a></li> | |
69 | <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li> |
|
69 | <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li> | |
70 | <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li> |
|
70 | <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li> | |
71 | </ul> |
|
71 | </ul> | |
72 | </td> |
|
72 | </td> | |
73 | <td valign="top"> |
|
73 | <td valign="top"> | |
74 | <ul> |
|
74 | <ul> | |
75 | <li><a href="qbarseries.html">QBarSeries</a></li> |
|
75 | <li><a href="qbarseries.html">QBarSeries</a></li> | |
76 | <li><a href="qbarset.html">QBarSet</a></li> |
|
76 | <li><a href="qbarset.html">QBarSet</a></li> | |
77 | <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li> |
|
77 | <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li> | |
78 | <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li> |
|
78 | <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li> | |
79 | <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li> |
|
79 | <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li> | |
80 | <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li> |
|
80 | <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li> | |
81 | <li><a href="qhorizontalbarseries.html">QHorizontalBarSeries</a></li> |
|
81 | <li><a href="qhorizontalbarseries.html">QHorizontalBarSeries</a></li> | |
82 | <li><a href="qhorizontalstackedbarseries.html">QHorizontalStackedBarSeries</a></li> |
|
82 | <li><a href="qhorizontalstackedbarseries.html">QHorizontalStackedBarSeries</a></li> | |
83 | <li><a href="qhorizontalpercentbarseries.html">QHorizontalPercentBarSeries</a></li> |
|
83 | <li><a href="qhorizontalpercentbarseries.html">QHorizontalPercentBarSeries</a></li> | |
84 | </ul> |
|
84 | </ul> | |
85 | </td> |
|
85 | </td> | |
86 | </tr> |
|
86 | </tr> | |
87 | </table> |
|
87 | </table> | |
88 | \endraw |
|
88 | \endraw | |
89 |
|
89 | |||
90 | */ |
|
90 | */ |
@@ -1,322 +1,322 | |||||
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 "qdatetimeaxis.h" |
|
21 | #include "qdatetimeaxis.h" | |
22 | #include "qdatetimeaxis_p.h" |
|
22 | #include "qdatetimeaxis_p.h" | |
23 | #include "chartdatetimeaxisx_p.h" |
|
23 | #include "chartdatetimeaxisx_p.h" | |
24 | #include "chartdatetimeaxisy_p.h" |
|
24 | #include "chartdatetimeaxisy_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include <cmath> |
|
26 | #include <cmath> | |
27 | #include <QDebug> |
|
27 | #include <QDebug> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | /*! |
|
30 | /*! | |
31 | \class QDateTimeAxis |
|
31 | \class QDateTimeAxis | |
32 | \brief The QDateTimeAxis class is used for manipulating chart's axis. |
|
32 | \brief The QDateTimeAxis class is used for manipulating chart's axis. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | The labels can be configured by setting an appropriate DateTime format. |
|
35 | The labels can be configured by setting an appropriate DateTime format. | |
36 | Note that any date before 4800 BCE or after about 1.4 million CE may not be accurately stored. |
|
36 | Note that any date before 4800 BCE or after about 1.4 million CE may not be accurately stored. | |
37 | QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
37 | QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 | \qmlclass DateTimeAxis QDateTimeAxis |
|
41 | \qmlclass DateTimeAxis QDateTimeAxis | |
42 | \brief The DateTimeAxis element is used for manipulating chart's axes |
|
42 | \brief The DateTimeAxis element is used for manipulating chart's axes | |
43 |
|
43 | |||
44 | The labels can be configured by setting an appropriate DateTime format. |
|
44 | The labels can be configured by setting an appropriate DateTime format. | |
45 | Note that any date before 4800 BCE or after about 1.4 million CE may not be accurately stored. |
|
45 | Note that any date before 4800 BCE or after about 1.4 million CE may not be accurately stored. | |
46 | DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
46 | DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \property QDateTimeAxis::min |
|
50 | \property QDateTimeAxis::min | |
51 | Defines the minimum value on the axis. |
|
51 | Defines the minimum value on the axis. | |
52 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
52 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
53 | */ |
|
53 | */ | |
54 | /*! |
|
54 | /*! | |
55 | \qmlproperty real ValuesAxis::min |
|
55 | \qmlproperty real ValuesAxis::min | |
56 | Defines the minimum value on the axis. |
|
56 | Defines the minimum value on the axis. | |
57 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
57 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \property QDateTimeAxis::max |
|
61 | \property QDateTimeAxis::max | |
62 | Defines the maximum value on the axis. |
|
62 | Defines the maximum value on the axis. | |
63 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
63 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
64 | */ |
|
64 | */ | |
65 | /*! |
|
65 | /*! | |
66 | \qmlproperty real ValuesAxis::max |
|
66 | \qmlproperty real ValuesAxis::max | |
67 | Defines the maximum value on the axis. |
|
67 | Defines the maximum value on the axis. | |
68 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
68 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \fn void QDateTimeAxis::minChanged(QDateTime min) |
|
72 | \fn void QDateTimeAxis::minChanged(QDateTime min) | |
73 | Axis emits signal when \a min of axis has changed. |
|
73 | Axis emits signal when \a min of axis has changed. | |
74 | */ |
|
74 | */ | |
75 | /*! |
|
75 | /*! | |
76 | \qmlsignal ValuesAxis::onMinChanged(QDateTime min) |
|
76 | \qmlsignal ValuesAxis::onMinChanged(QDateTime min) | |
77 | Axis emits signal when \a min of axis has changed. |
|
77 | Axis emits signal when \a min of axis has changed. | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \fn void QDateTimeAxis::maxChanged(QDateTime max) |
|
81 | \fn void QDateTimeAxis::maxChanged(QDateTime max) | |
82 | Axis emits signal when \a max of axis has changed. |
|
82 | Axis emits signal when \a max of axis has changed. | |
83 | */ |
|
83 | */ | |
84 | /*! |
|
84 | /*! | |
85 | \qmlsignal ValuesAxis::onMaxChanged(QDateTime max) |
|
85 | \qmlsignal ValuesAxis::onMaxChanged(QDateTime max) | |
86 | Axis emits signal when \a max of axis has changed. |
|
86 | Axis emits signal when \a max of axis has changed. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max) |
|
90 | \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max) | |
91 | Axis emits signal when \a min or \a max of axis has changed. |
|
91 | Axis emits signal when \a min or \a max of axis has changed. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 |
\property QDateTimeAxis::tick |
|
95 | \property QDateTimeAxis::tickCount | |
96 | The number of tick marks for the axis. |
|
96 | The number of tick marks for the axis. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 |
\qmlproperty int ValuesAxis::tick |
|
100 | \qmlproperty int ValuesAxis::tickCount | |
101 | The number of tick marks for the axis. |
|
101 | The number of tick marks for the axis. | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | Constructs an axis object which is a child of \a parent. |
|
105 | Constructs an axis object which is a child of \a parent. | |
106 | */ |
|
106 | */ | |
107 | QDateTimeAxis::QDateTimeAxis(QObject *parent) : |
|
107 | QDateTimeAxis::QDateTimeAxis(QObject *parent) : | |
108 | QAbstractAxis(*new QDateTimeAxisPrivate(this),parent) |
|
108 | QAbstractAxis(*new QDateTimeAxisPrivate(this),parent) | |
109 | { |
|
109 | { | |
110 |
|
110 | |||
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | /*! |
|
113 | /*! | |
114 | \internal |
|
114 | \internal | |
115 | */ |
|
115 | */ | |
116 | QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) |
|
116 | QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) | |
117 | { |
|
117 | { | |
118 |
|
118 | |||
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | /*! |
|
121 | /*! | |
122 | Destroys the object |
|
122 | Destroys the object | |
123 | */ |
|
123 | */ | |
124 | QDateTimeAxis::~QDateTimeAxis() |
|
124 | QDateTimeAxis::~QDateTimeAxis() | |
125 | { |
|
125 | { | |
126 |
|
126 | |||
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | void QDateTimeAxis::setMin(QDateTime min) |
|
129 | void QDateTimeAxis::setMin(QDateTime min) | |
130 | { |
|
130 | { | |
131 | Q_D(QDateTimeAxis); |
|
131 | Q_D(QDateTimeAxis); | |
132 | if (min.isValid()) |
|
132 | if (min.isValid()) | |
133 | setRange(min, qMax(d->m_max, min)); |
|
133 | setRange(min, qMax(d->m_max, min)); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | QDateTime QDateTimeAxis::min() const |
|
136 | QDateTime QDateTimeAxis::min() const | |
137 | { |
|
137 | { | |
138 | Q_D(const QDateTimeAxis); |
|
138 | Q_D(const QDateTimeAxis); | |
139 | return d->m_min; |
|
139 | return d->m_min; | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | void QDateTimeAxis::setMax(QDateTime max) |
|
142 | void QDateTimeAxis::setMax(QDateTime max) | |
143 | { |
|
143 | { | |
144 | Q_D(QDateTimeAxis); |
|
144 | Q_D(QDateTimeAxis); | |
145 | if (max.isValid()) |
|
145 | if (max.isValid()) | |
146 | setRange(qMin(d->m_min, max), max); |
|
146 | setRange(qMin(d->m_min, max), max); | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | QDateTime QDateTimeAxis::max() const |
|
149 | QDateTime QDateTimeAxis::max() const | |
150 | { |
|
150 | { | |
151 | Q_D(const QDateTimeAxis); |
|
151 | Q_D(const QDateTimeAxis); | |
152 | return d->m_max; |
|
152 | return d->m_max; | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | Sets range from \a min to \a max on the axis. |
|
156 | Sets range from \a min to \a max on the axis. | |
157 | If min is greater than max then this function returns without making any changes. |
|
157 | If min is greater than max then this function returns without making any changes. | |
158 | */ |
|
158 | */ | |
159 | void QDateTimeAxis::setRange(QDateTime min, QDateTime max) |
|
159 | void QDateTimeAxis::setRange(QDateTime min, QDateTime max) | |
160 | { |
|
160 | { | |
161 | Q_D(QDateTimeAxis); |
|
161 | Q_D(QDateTimeAxis); | |
162 | if (!min.isValid() || !max.isValid() || min > max) |
|
162 | if (!min.isValid() || !max.isValid() || min > max) | |
163 | return; |
|
163 | return; | |
164 |
|
164 | |||
165 | bool changed = false; |
|
165 | bool changed = false; | |
166 | if (d->m_min != min) { |
|
166 | if (d->m_min != min) { | |
167 | d->m_min = min; |
|
167 | d->m_min = min; | |
168 | changed = true; |
|
168 | changed = true; | |
169 | emit minChanged(min); |
|
169 | emit minChanged(min); | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | if (d->m_max != max) { |
|
172 | if (d->m_max != max) { | |
173 | d->m_max = max; |
|
173 | d->m_max = max; | |
174 | changed = true; |
|
174 | changed = true; | |
175 | emit maxChanged(max); |
|
175 | emit maxChanged(max); | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | // if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount); |
|
178 | // if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount); | |
179 |
|
179 | |||
180 | if (changed) { |
|
180 | if (changed) { | |
181 | emit rangeChanged(d->m_min,d->m_max); |
|
181 | emit rangeChanged(d->m_min,d->m_max); | |
182 | d->emitUpdated(); |
|
182 | d->emitUpdated(); | |
183 | } |
|
183 | } | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | /*! |
|
186 | /*! | |
187 | Sets \a format string that is used when creating label for the axis out of the QDateTime object. |
|
187 | Sets \a format string that is used when creating label for the axis out of the QDateTime object. | |
188 | Check QDateTime documentation for information on how the string should be defined. |
|
188 | Check QDateTime documentation for information on how the string should be defined. | |
189 |
\sa format |
|
189 | \sa format() | |
190 | */ |
|
190 | */ | |
191 | void QDateTimeAxis::setFormat(QString format) |
|
191 | void QDateTimeAxis::setFormat(QString format) | |
192 | { |
|
192 | { | |
193 | Q_D(QDateTimeAxis); |
|
193 | Q_D(QDateTimeAxis); | |
194 | d->m_format = format; |
|
194 | d->m_format = format; | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | /*! |
|
197 | /*! | |
198 | Returns the format string that is used when creating label for the axis out of the QDateTime object. |
|
198 | Returns the format string that is used when creating label for the axis out of the QDateTime object. | |
199 | Check QDateTime documentation for information on how the string should be defined. |
|
199 | Check QDateTime documentation for information on how the string should be defined. | |
200 |
\sa setFormat |
|
200 | \sa setFormat() | |
201 | */ |
|
201 | */ | |
202 | QString QDateTimeAxis::format() const |
|
202 | QString QDateTimeAxis::format() const | |
203 | { |
|
203 | { | |
204 | Q_D(const QDateTimeAxis); |
|
204 | Q_D(const QDateTimeAxis); | |
205 | return d->m_format; |
|
205 | return d->m_format; | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | /*! |
|
208 | /*! | |
209 | Sets \a count for ticks on the axis. |
|
209 | Sets \a count for ticks on the axis. | |
210 | */ |
|
210 | */ | |
211 | void QDateTimeAxis::setTickCount(int count) |
|
211 | void QDateTimeAxis::setTickCount(int count) | |
212 | { |
|
212 | { | |
213 | Q_D(QDateTimeAxis); |
|
213 | Q_D(QDateTimeAxis); | |
214 | if (d->m_tickCount != count && count >=2) { |
|
214 | if (d->m_tickCount != count && count >=2) { | |
215 | d->m_tickCount = count; |
|
215 | d->m_tickCount = count; | |
216 | d->emitUpdated(); |
|
216 | d->emitUpdated(); | |
217 | } |
|
217 | } | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | /*! |
|
220 | /*! | |
221 |
\fn int QDateTimeAxis::tick |
|
221 | \fn int QDateTimeAxis::tickCount() const | |
222 | Return number of ticks on the axis |
|
222 | Return number of ticks on the axis | |
223 | */ |
|
223 | */ | |
224 | int QDateTimeAxis::tickCount() const |
|
224 | int QDateTimeAxis::tickCount() const | |
225 | { |
|
225 | { | |
226 | Q_D(const QDateTimeAxis); |
|
226 | Q_D(const QDateTimeAxis); | |
227 | return d->m_tickCount; |
|
227 | return d->m_tickCount; | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | /*! |
|
230 | /*! | |
231 | Returns the type of the axis |
|
231 | Returns the type of the axis | |
232 | */ |
|
232 | */ | |
233 | QAbstractAxis::AxisType QDateTimeAxis::type() const |
|
233 | QAbstractAxis::AxisType QDateTimeAxis::type() const | |
234 | { |
|
234 | { | |
235 | return AxisTypeDateTime; |
|
235 | return AxisTypeDateTime; | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
238 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
239 |
|
239 | |||
240 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis* q): |
|
240 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis* q): | |
241 | QAbstractAxisPrivate(q), |
|
241 | QAbstractAxisPrivate(q), | |
242 | m_tickCount(5) |
|
242 | m_tickCount(5) | |
243 | { |
|
243 | { | |
244 | m_min = QDateTime::fromMSecsSinceEpoch(0); |
|
244 | m_min = QDateTime::fromMSecsSinceEpoch(0); | |
245 | m_max = QDateTime::fromMSecsSinceEpoch(0); |
|
245 | m_max = QDateTime::fromMSecsSinceEpoch(0); | |
246 | m_format = "dd-MMM-yy\nh:mm"; |
|
246 | m_format = "dd-MMM-yy\nh:mm"; | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() |
|
249 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() | |
250 | { |
|
250 | { | |
251 |
|
251 | |||
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | void QDateTimeAxisPrivate::handleDomainUpdated() |
|
254 | void QDateTimeAxisPrivate::handleDomainUpdated() | |
255 | { |
|
255 | { | |
256 | Q_Q(QDateTimeAxis); |
|
256 | Q_Q(QDateTimeAxis); | |
257 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
257 | Domain* domain = qobject_cast<Domain*>(sender()); | |
258 | Q_ASSERT(domain); |
|
258 | Q_ASSERT(domain); | |
259 |
|
259 | |||
260 | if(orientation()==Qt::Horizontal){ |
|
260 | if(orientation()==Qt::Horizontal){ | |
261 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); |
|
261 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); | |
262 | }else if(orientation()==Qt::Vertical){ |
|
262 | }else if(orientation()==Qt::Vertical){ | |
263 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); |
|
263 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); | |
264 | } |
|
264 | } | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 |
|
267 | |||
268 | void QDateTimeAxisPrivate::setMin(const QVariant &min) |
|
268 | void QDateTimeAxisPrivate::setMin(const QVariant &min) | |
269 | { |
|
269 | { | |
270 | Q_Q(QDateTimeAxis); |
|
270 | Q_Q(QDateTimeAxis); | |
271 | if (min.canConvert(QVariant::DateTime)) |
|
271 | if (min.canConvert(QVariant::DateTime)) | |
272 | q->setMin(min.toDateTime()); |
|
272 | q->setMin(min.toDateTime()); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | void QDateTimeAxisPrivate::setMax(const QVariant &max) |
|
275 | void QDateTimeAxisPrivate::setMax(const QVariant &max) | |
276 | { |
|
276 | { | |
277 |
|
277 | |||
278 | Q_Q(QDateTimeAxis); |
|
278 | Q_Q(QDateTimeAxis); | |
279 | if (max.canConvert(QVariant::DateTime)) |
|
279 | if (max.canConvert(QVariant::DateTime)) | |
280 | q->setMax(max.toDateTime()); |
|
280 | q->setMax(max.toDateTime()); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
283 | void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
284 | { |
|
284 | { | |
285 | Q_Q(QDateTimeAxis); |
|
285 | Q_Q(QDateTimeAxis); | |
286 | if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime)) |
|
286 | if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime)) | |
287 | q->setRange(min.toDateTime(), max.toDateTime()); |
|
287 | q->setRange(min.toDateTime(), max.toDateTime()); | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | ChartAxis* QDateTimeAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
290 | ChartAxis* QDateTimeAxisPrivate::createGraphics(ChartPresenter* presenter) | |
291 | { |
|
291 | { | |
292 | Q_Q(QDateTimeAxis); |
|
292 | Q_Q(QDateTimeAxis); | |
293 | if(m_orientation == Qt::Vertical){ |
|
293 | if(m_orientation == Qt::Vertical){ | |
294 | return new ChartDateTimeAxisY(q,presenter); |
|
294 | return new ChartDateTimeAxisY(q,presenter); | |
295 | }else{ |
|
295 | }else{ | |
296 | return new ChartDateTimeAxisX(q,presenter); |
|
296 | return new ChartDateTimeAxisX(q,presenter); | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | void QDateTimeAxisPrivate::intializeDomain(Domain* domain) |
|
301 | void QDateTimeAxisPrivate::intializeDomain(Domain* domain) | |
302 | { |
|
302 | { | |
303 | Q_Q(QDateTimeAxis); |
|
303 | Q_Q(QDateTimeAxis); | |
304 | if(m_max == m_min) { |
|
304 | if(m_max == m_min) { | |
305 | if(m_orientation==Qt::Vertical){ |
|
305 | if(m_orientation==Qt::Vertical){ | |
306 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); |
|
306 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); | |
307 | }else{ |
|
307 | }else{ | |
308 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); |
|
308 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); | |
309 | } |
|
309 | } | |
310 | } else { |
|
310 | } else { | |
311 | if(m_orientation==Qt::Vertical){ |
|
311 | if(m_orientation==Qt::Vertical){ | |
312 | domain->setRangeY(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); |
|
312 | domain->setRangeY(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); | |
313 | }else{ |
|
313 | }else{ | |
314 | domain->setRangeX(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); |
|
314 | domain->setRangeX(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); | |
315 | } |
|
315 | } | |
316 | } |
|
316 | } | |
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | #include "moc_qdatetimeaxis.cpp" |
|
319 | #include "moc_qdatetimeaxis.cpp" | |
320 | #include "moc_qdatetimeaxis_p.cpp" |
|
320 | #include "moc_qdatetimeaxis_p.cpp" | |
321 |
|
321 | |||
322 | QTCOMMERCIALCHART_END_NAMESPACE |
|
322 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,384 +1,384 | |||||
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 "qvalueaxis.h" |
|
21 | #include "qvalueaxis.h" | |
22 | #include "qvalueaxis_p.h" |
|
22 | #include "qvalueaxis_p.h" | |
23 | #include "chartvalueaxisx_p.h" |
|
23 | #include "chartvalueaxisx_p.h" | |
24 | #include "chartvalueaxisy_p.h" |
|
24 | #include "chartvalueaxisy_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 | /*! |
|
31 | /*! | |
32 | \class QValueAxis |
|
32 | \class QValueAxis | |
33 | \brief The QValueAxis class is used for manipulating chart's axis. |
|
33 | \brief The QValueAxis class is used for manipulating chart's axis. | |
34 | \mainclass |
|
34 | \mainclass | |
35 |
|
35 | |||
36 |
Value |
|
36 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
37 | Values of axis are drawn to position of ticks |
|
37 | Values of axis are drawn to position of ticks | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 |
\qmlclass Value |
|
41 | \qmlclass ValueAxis QValueAxis | |
42 |
\brief The Value |
|
42 | \brief The ValueAxis element is used for manipulating chart's axes | |
43 |
|
43 | |||
44 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
44 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
45 | Values of axis are drawn to position of ticks |
|
45 | Values of axis are drawn to position of ticks | |
46 |
|
46 | |||
47 | To access Axes you can use ChartView API. For example: |
|
47 | To access Axes you can use ChartView API. For example: | |
48 | \code |
|
48 | \code | |
49 | ChartView { |
|
49 | ChartView { | |
50 |
Value |
|
50 | ValueAxis { | |
51 | id: xAxis |
|
51 | id: xAxis | |
52 | min: 0 |
|
52 | min: 0 | |
53 | max: 10 |
|
53 | max: 10 | |
54 | } |
|
54 | } | |
55 | // Add a few series... |
|
55 | // Add a few series... | |
56 | } |
|
56 | } | |
57 | \endcode |
|
57 | \endcode | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \property QValueAxis::min |
|
61 | \property QValueAxis::min | |
62 | Defines the minimum value on the axis. |
|
62 | Defines the minimum value on the axis. | |
63 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
63 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
64 | */ |
|
64 | */ | |
65 | /*! |
|
65 | /*! | |
66 |
\qmlproperty real Value |
|
66 | \qmlproperty real ValueAxis::min | |
67 | Defines the minimum value on the axis. |
|
67 | Defines the minimum value on the axis. | |
68 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
68 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \property QValueAxis::max |
|
72 | \property QValueAxis::max | |
73 | Defines the maximum value on the axis. |
|
73 | Defines the maximum value on the axis. | |
74 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
74 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
75 | */ |
|
75 | */ | |
76 | /*! |
|
76 | /*! | |
77 |
\qmlproperty real Value |
|
77 | \qmlproperty real ValueAxis::max | |
78 | Defines the maximum value on the axis. |
|
78 | Defines the maximum value on the axis. | |
79 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
79 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
80 | */ |
|
80 | */ | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
83 | \fn void QValueAxis::minChanged(qreal min) |
|
83 | \fn void QValueAxis::minChanged(qreal min) | |
84 | Axis emits signal when \a min of axis has changed. |
|
84 | Axis emits signal when \a min of axis has changed. | |
85 | */ |
|
85 | */ | |
86 | /*! |
|
86 | /*! | |
87 |
\qmlsignal Value |
|
87 | \qmlsignal ValueAxis::onMinChanged(real min) | |
88 | Axis emits signal when \a min of axis has changed. |
|
88 | Axis emits signal when \a min of axis has changed. | |
89 | */ |
|
89 | */ | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | \fn void QValueAxis::maxChanged(qreal max) |
|
92 | \fn void QValueAxis::maxChanged(qreal max) | |
93 | Axis emits signal when \a max of axis has changed. |
|
93 | Axis emits signal when \a max of axis has changed. | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 |
\qmlsignal Value |
|
96 | \qmlsignal ValueAxis::onMaxChanged(real max) | |
97 | Axis emits signal when \a max of axis has changed. |
|
97 | Axis emits signal when \a max of axis has changed. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) |
|
101 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) | |
102 | Axis emits signal when \a min or \a max of axis has changed. |
|
102 | Axis emits signal when \a min or \a max of axis has changed. | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 |
\property QValueAxis::tick |
|
106 | \property QValueAxis::tickCount | |
107 | The number of tick marks for the axis. |
|
107 | The number of tick marks for the axis. | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 |
\qmlproperty int Value |
|
111 | \qmlproperty int ValueAxis::tickCount | |
112 | The number of tick marks for the axis. |
|
112 | The number of tick marks for the axis. | |
113 | */ |
|
113 | */ | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | \property QValueAxis::niceNumbersEnabled |
|
116 | \property QValueAxis::niceNumbersEnabled | |
117 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
117 | Whether the nice numbers algorithm is enabled or not for the axis. | |
118 | */ |
|
118 | */ | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 |
\qmlproperty bool Value |
|
121 | \qmlproperty bool ValueAxis::niceNumbersEnabled | |
122 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
122 | Whether the nice numbers algorithm is enabled or not for the axis. | |
123 | */ |
|
123 | */ | |
124 |
|
124 | |||
125 | /*! |
|
125 | /*! | |
126 | Constructs an axis object which is a child of \a parent. |
|
126 | Constructs an axis object which is a child of \a parent. | |
127 | */ |
|
127 | */ | |
128 | QValueAxis::QValueAxis(QObject *parent) : |
|
128 | QValueAxis::QValueAxis(QObject *parent) : | |
129 | QAbstractAxis(*new QValueAxisPrivate(this),parent) |
|
129 | QAbstractAxis(*new QValueAxisPrivate(this),parent) | |
130 | { |
|
130 | { | |
131 |
|
131 | |||
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | \internal |
|
135 | \internal | |
136 | */ |
|
136 | */ | |
137 | QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) |
|
137 | QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) | |
138 | { |
|
138 | { | |
139 |
|
139 | |||
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | Destroys the object |
|
143 | Destroys the object | |
144 | */ |
|
144 | */ | |
145 | QValueAxis::~QValueAxis() |
|
145 | QValueAxis::~QValueAxis() | |
146 | { |
|
146 | { | |
147 | Q_D(QValueAxis); |
|
147 | Q_D(QValueAxis); | |
148 | if(d->m_dataset) { |
|
148 | if(d->m_dataset) { | |
149 | d->m_dataset->removeAxis(this); |
|
149 | d->m_dataset->removeAxis(this); | |
150 | } |
|
150 | } | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | void QValueAxis::setMin(qreal min) |
|
153 | void QValueAxis::setMin(qreal min) | |
154 | { |
|
154 | { | |
155 | Q_D(QValueAxis); |
|
155 | Q_D(QValueAxis); | |
156 | setRange(min, qMax(d->m_max, min)); |
|
156 | setRange(min, qMax(d->m_max, min)); | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | qreal QValueAxis::min() const |
|
159 | qreal QValueAxis::min() const | |
160 | { |
|
160 | { | |
161 | Q_D(const QValueAxis); |
|
161 | Q_D(const QValueAxis); | |
162 | return d->m_min; |
|
162 | return d->m_min; | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | void QValueAxis::setMax(qreal max) |
|
165 | void QValueAxis::setMax(qreal max) | |
166 | { |
|
166 | { | |
167 | Q_D(QValueAxis); |
|
167 | Q_D(QValueAxis); | |
168 | setRange(qMin(d->m_min, max), max); |
|
168 | setRange(qMin(d->m_min, max), max); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | qreal QValueAxis::max() const |
|
171 | qreal QValueAxis::max() const | |
172 | { |
|
172 | { | |
173 | Q_D(const QValueAxis); |
|
173 | Q_D(const QValueAxis); | |
174 | return d->m_max; |
|
174 | return d->m_max; | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | /*! |
|
177 | /*! | |
178 | Sets range from \a min to \a max on the axis. |
|
178 | Sets range from \a min to \a max on the axis. | |
179 | If min is greater than max then this function returns without making any changes. |
|
179 | If min is greater than max then this function returns without making any changes. | |
180 | */ |
|
180 | */ | |
181 | void QValueAxis::setRange(qreal min, qreal max) |
|
181 | void QValueAxis::setRange(qreal min, qreal max) | |
182 | { |
|
182 | { | |
183 | Q_D(QValueAxis); |
|
183 | Q_D(QValueAxis); | |
184 | bool changed = false; |
|
184 | bool changed = false; | |
185 |
|
185 | |||
186 | if (min > max) return; |
|
186 | if (min > max) return; | |
187 |
|
187 | |||
188 | if(d->m_niceNumbers) { |
|
188 | if(d->m_niceNumbers) { | |
189 | int ticks = d->m_tickCount; |
|
189 | int ticks = d->m_tickCount; | |
190 | d->looseNiceNumbers(min, max, ticks); |
|
190 | d->looseNiceNumbers(min, max, ticks); | |
191 | if(ticks!=d->m_tickCount) setTickCount(ticks); |
|
191 | if(ticks!=d->m_tickCount) setTickCount(ticks); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | if (!qFuzzyIsNull(d->m_min - min)) { |
|
194 | if (!qFuzzyIsNull(d->m_min - min)) { | |
195 | d->m_min = min; |
|
195 | d->m_min = min; | |
196 | changed = true; |
|
196 | changed = true; | |
197 | emit minChanged(min); |
|
197 | emit minChanged(min); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | if (!qFuzzyIsNull(d->m_max - max)) { |
|
200 | if (!qFuzzyIsNull(d->m_max - max)) { | |
201 | d->m_max = max; |
|
201 | d->m_max = max; | |
202 | changed = true; |
|
202 | changed = true; | |
203 | emit maxChanged(max); |
|
203 | emit maxChanged(max); | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | if (changed) { |
|
206 | if (changed) { | |
207 | emit rangeChanged(min,max); |
|
207 | emit rangeChanged(min,max); | |
208 | d->emitUpdated(); |
|
208 | d->emitUpdated(); | |
209 | } |
|
209 | } | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | Sets \a count for ticks on the axis. |
|
213 | Sets \a count for ticks on the axis. | |
214 | */ |
|
214 | */ | |
215 | void QValueAxis::setTickCount(int count) |
|
215 | void QValueAxis::setTickCount(int count) | |
216 | { |
|
216 | { | |
217 | Q_D(QValueAxis); |
|
217 | Q_D(QValueAxis); | |
218 | if (d->m_tickCount != count && count >=2) { |
|
218 | if (d->m_tickCount != count && count >=2) { | |
219 | d->m_tickCount = count; |
|
219 | d->m_tickCount = count; | |
220 | d->emitUpdated(); |
|
220 | d->emitUpdated(); | |
221 | } |
|
221 | } | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | /*! |
|
224 | /*! | |
225 |
\fn int QValueAxis::tick |
|
225 | \fn int QValueAxis::tickCount() const | |
226 | Return number of ticks on the axis |
|
226 | Return number of ticks on the axis | |
227 | */ |
|
227 | */ | |
228 | int QValueAxis::tickCount() const |
|
228 | int QValueAxis::tickCount() const | |
229 | { |
|
229 | { | |
230 | Q_D(const QValueAxis); |
|
230 | Q_D(const QValueAxis); | |
231 | return d->m_tickCount; |
|
231 | return d->m_tickCount; | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | void QValueAxis::setNiceNumbersEnabled(bool enable) |
|
234 | void QValueAxis::setNiceNumbersEnabled(bool enable) | |
235 | { |
|
235 | { | |
236 | Q_D(QValueAxis); |
|
236 | Q_D(QValueAxis); | |
237 | if (d->m_niceNumbers != enable){ |
|
237 | if (d->m_niceNumbers != enable){ | |
238 | d->m_niceNumbers = enable; |
|
238 | d->m_niceNumbers = enable; | |
239 | if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) { |
|
239 | if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) { | |
240 | setRange(d->m_min,d->m_max); |
|
240 | setRange(d->m_min,d->m_max); | |
241 | } |
|
241 | } | |
242 | } |
|
242 | } | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | bool QValueAxis::niceNumbersEnabled() const |
|
245 | bool QValueAxis::niceNumbersEnabled() const | |
246 | { |
|
246 | { | |
247 | Q_D(const QValueAxis); |
|
247 | Q_D(const QValueAxis); | |
248 | return d->m_niceNumbers; |
|
248 | return d->m_niceNumbers; | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | /*! |
|
251 | /*! | |
252 | Returns the type of the axis |
|
252 | Returns the type of the axis | |
253 | */ |
|
253 | */ | |
254 | QAbstractAxis::AxisType QValueAxis::type() const |
|
254 | QAbstractAxis::AxisType QValueAxis::type() const | |
255 | { |
|
255 | { | |
256 | return AxisTypeValues; |
|
256 | return AxisTypeValues; | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
259 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
260 |
|
260 | |||
261 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q): |
|
261 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q): | |
262 | QAbstractAxisPrivate(q), |
|
262 | QAbstractAxisPrivate(q), | |
263 | m_min(0), |
|
263 | m_min(0), | |
264 | m_max(0), |
|
264 | m_max(0), | |
265 | m_tickCount(5), |
|
265 | m_tickCount(5), | |
266 | m_niceNumbers(false) |
|
266 | m_niceNumbers(false) | |
267 | { |
|
267 | { | |
268 |
|
268 | |||
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 | QValueAxisPrivate::~QValueAxisPrivate() |
|
271 | QValueAxisPrivate::~QValueAxisPrivate() | |
272 | { |
|
272 | { | |
273 |
|
273 | |||
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | void QValueAxisPrivate::handleDomainUpdated() |
|
276 | void QValueAxisPrivate::handleDomainUpdated() | |
277 | { |
|
277 | { | |
278 | Q_Q(QValueAxis); |
|
278 | Q_Q(QValueAxis); | |
279 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
279 | Domain* domain = qobject_cast<Domain*>(sender()); | |
280 | Q_ASSERT(domain); |
|
280 | Q_ASSERT(domain); | |
281 |
|
281 | |||
282 | if(orientation()==Qt::Horizontal){ |
|
282 | if(orientation()==Qt::Horizontal){ | |
283 | q->setRange(domain->minX(),domain->maxX()); |
|
283 | q->setRange(domain->minX(),domain->maxX()); | |
284 | }else if(orientation()==Qt::Vertical){ |
|
284 | }else if(orientation()==Qt::Vertical){ | |
285 | q->setRange(domain->minY(),domain->maxY()); |
|
285 | q->setRange(domain->minY(),domain->maxY()); | |
286 | } |
|
286 | } | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 |
|
289 | |||
290 | void QValueAxisPrivate::setMin(const QVariant &min) |
|
290 | void QValueAxisPrivate::setMin(const QVariant &min) | |
291 | { |
|
291 | { | |
292 | Q_Q(QValueAxis); |
|
292 | Q_Q(QValueAxis); | |
293 | bool ok; |
|
293 | bool ok; | |
294 | qreal value = min.toReal(&ok); |
|
294 | qreal value = min.toReal(&ok); | |
295 | if(ok) q->setMin(value); |
|
295 | if(ok) q->setMin(value); | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
298 | void QValueAxisPrivate::setMax(const QVariant &max) |
|
298 | void QValueAxisPrivate::setMax(const QVariant &max) | |
299 | { |
|
299 | { | |
300 |
|
300 | |||
301 | Q_Q(QValueAxis); |
|
301 | Q_Q(QValueAxis); | |
302 | bool ok; |
|
302 | bool ok; | |
303 | qreal value = max.toReal(&ok); |
|
303 | qreal value = max.toReal(&ok); | |
304 | if(ok) q->setMax(value); |
|
304 | if(ok) q->setMax(value); | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
307 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
308 | { |
|
308 | { | |
309 | Q_Q(QValueAxis); |
|
309 | Q_Q(QValueAxis); | |
310 | bool ok1; |
|
310 | bool ok1; | |
311 | bool ok2; |
|
311 | bool ok2; | |
312 | qreal value1 = min.toReal(&ok1); |
|
312 | qreal value1 = min.toReal(&ok1); | |
313 | qreal value2 = max.toReal(&ok2); |
|
313 | qreal value2 = max.toReal(&ok2); | |
314 | if(ok1&&ok2) q->setRange(value1,value2); |
|
314 | if(ok1&&ok2) q->setRange(value1,value2); | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
317 | ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter) | |
318 | { |
|
318 | { | |
319 | Q_Q(QValueAxis); |
|
319 | Q_Q(QValueAxis); | |
320 | if(m_orientation == Qt::Vertical){ |
|
320 | if(m_orientation == Qt::Vertical){ | |
321 | return new ChartValueAxisY(q,presenter); |
|
321 | return new ChartValueAxisY(q,presenter); | |
322 | }else{ |
|
322 | }else{ | |
323 | return new ChartValueAxisX(q,presenter); |
|
323 | return new ChartValueAxisX(q,presenter); | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | void QValueAxisPrivate::intializeDomain(Domain* domain) |
|
328 | void QValueAxisPrivate::intializeDomain(Domain* domain) | |
329 | { |
|
329 | { | |
330 | Q_Q(QValueAxis); |
|
330 | Q_Q(QValueAxis); | |
331 | if(qFuzzyCompare(m_max,m_min)) { |
|
331 | if(qFuzzyCompare(m_max,m_min)) { | |
332 | if(m_orientation==Qt::Vertical){ |
|
332 | if(m_orientation==Qt::Vertical){ | |
333 | q->setRange(domain->minY(),domain->maxY()); |
|
333 | q->setRange(domain->minY(),domain->maxY()); | |
334 | }else{ |
|
334 | }else{ | |
335 | q->setRange(domain->minX(), domain->maxX()); |
|
335 | q->setRange(domain->minX(), domain->maxX()); | |
336 | } |
|
336 | } | |
337 | } else { |
|
337 | } else { | |
338 | if(m_orientation==Qt::Vertical){ |
|
338 | if(m_orientation==Qt::Vertical){ | |
339 | domain->setRangeY(m_min, m_max); |
|
339 | domain->setRangeY(m_min, m_max); | |
340 | }else{ |
|
340 | }else{ | |
341 | domain->setRangeX(m_min, m_max); |
|
341 | domain->setRangeX(m_min, m_max); | |
342 | } |
|
342 | } | |
343 | } |
|
343 | } | |
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | //algorithm defined by Paul S.Heckbert GraphicalGems I |
|
346 | //algorithm defined by Paul S.Heckbert GraphicalGems I | |
347 |
|
347 | |||
348 | void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const |
|
348 | void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const | |
349 | { |
|
349 | { | |
350 | qreal range = niceNumber(max-min,true); //range with ceiling |
|
350 | qreal range = niceNumber(max-min,true); //range with ceiling | |
351 | qreal step = niceNumber(range/(ticksCount-1),false); |
|
351 | qreal step = niceNumber(range/(ticksCount-1),false); | |
352 | min = qFloor(min/step); |
|
352 | min = qFloor(min/step); | |
353 | max = qCeil(max/step); |
|
353 | max = qCeil(max/step); | |
354 | ticksCount = int(max-min) +1; |
|
354 | ticksCount = int(max-min) +1; | |
355 | min*=step; |
|
355 | min*=step; | |
356 | max*=step; |
|
356 | max*=step; | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n |
|
359 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n | |
360 |
|
360 | |||
361 | qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const |
|
361 | qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const | |
362 | { |
|
362 | { | |
363 | qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x |
|
363 | qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x | |
364 | qreal q = x/z;//q<10 && q>=1; |
|
364 | qreal q = x/z;//q<10 && q>=1; | |
365 |
|
365 | |||
366 | if(ceiling) { |
|
366 | if(ceiling) { | |
367 | if(q <= 1.0) q=1; |
|
367 | if(q <= 1.0) q=1; | |
368 | else if(q <= 2.0) q=2; |
|
368 | else if(q <= 2.0) q=2; | |
369 | else if(q <= 5.0) q=5; |
|
369 | else if(q <= 5.0) q=5; | |
370 | else q=10; |
|
370 | else q=10; | |
371 | } |
|
371 | } | |
372 | else { |
|
372 | else { | |
373 | if(q < 1.5) q=1; |
|
373 | if(q < 1.5) q=1; | |
374 | else if(q < 3.0) q=2; |
|
374 | else if(q < 3.0) q=2; | |
375 | else if(q < 7.0) q=5; |
|
375 | else if(q < 7.0) q=5; | |
376 | else q=10; |
|
376 | else q=10; | |
377 | } |
|
377 | } | |
378 | return q*z; |
|
378 | return q*z; | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 | #include "moc_qvalueaxis.cpp" |
|
381 | #include "moc_qvalueaxis.cpp" | |
382 | #include "moc_qvalueaxis_p.cpp" |
|
382 | #include "moc_qvalueaxis_p.cpp" | |
383 |
|
383 | |||
384 | QTCOMMERCIALCHART_END_NAMESPACE |
|
384 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now