@@ -1,60 +1,62 | |||||
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 "charts.h" |
|
21 | #include "charts.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qlineseries.h" |
|
23 | #include "qlineseries.h" | |
24 | #include "qvalueaxis.h" |
|
24 | #include "qvalueaxis.h" | |
25 | #include "qdatetimeaxis.h" |
|
25 | #include "qdatetimeaxis.h" | |
26 |
|
26 | |||
27 | class DateTimeAxisX: public Chart |
|
27 | class DateTimeAxisX: public Chart | |
28 | { |
|
28 | { | |
29 | public: |
|
29 | public: | |
30 | QString name() { return "AxisX"; } |
|
30 | QString name() { return "AxisX"; } | |
31 | QString category() { return QObject::tr("Axis"); } |
|
31 | QString category() { return QObject::tr("Axis"); } | |
32 | QString subCategory() { return "DateTimeAxis"; } |
|
32 | QString subCategory() { return "DateTimeAxis"; } | |
33 |
|
33 | |||
34 | QChart *createChart(const DataTable &table) |
|
34 | QChart *createChart(const DataTable &table) | |
35 | { |
|
35 | { | |
36 | QChart *chart = new QChart(); |
|
36 | QChart *chart = new QChart(); | |
37 | chart->setTitle("DateTime X , Value Y"); |
|
37 | chart->setTitle("DateTime X , Value Y"); | |
38 | QValueAxis *valueaxis = new QValueAxis(); |
|
38 | QValueAxis *valueaxis = new QValueAxis(); | |
39 | QDateTimeAxis *datetimeaxis = new QDateTimeAxis(); |
|
39 | QDateTimeAxis *datetimeaxis = new QDateTimeAxis(); | |
40 | datetimeaxis->setTickCount(10); |
|
40 | datetimeaxis->setTickCount(10); | |
41 |
datetimeaxis->setFormat(" |
|
41 | datetimeaxis->setFormat("yyyy"); | |
42 |
|
42 | |||
43 | QString name("Series "); |
|
43 | QString name("Series "); | |
44 | int nameIndex = 0; |
|
44 | int nameIndex = 0; | |
45 | foreach (DataList list, table) { |
|
45 | foreach (DataList list, table) { | |
46 | QLineSeries *series = new QLineSeries(chart); |
|
46 | QLineSeries *series = new QLineSeries(chart); | |
47 | foreach (Data data, list) |
|
47 | foreach (Data data, list){ | |
48 |
|
|
48 | QPointF point = data.first; | |
|
49 | series->append(1000l*60l*60l*24l*365l*30l+point.x()*1000l*60l*60l*24l*365l,point.y()); | |||
|
50 | } | |||
49 | series->setName(name + QString::number(nameIndex)); |
|
51 | series->setName(name + QString::number(nameIndex)); | |
50 | nameIndex++; |
|
52 | nameIndex++; | |
51 | chart->addSeries(series); |
|
53 | chart->addSeries(series); | |
52 | chart->setAxisX(datetimeaxis, series); |
|
54 | chart->setAxisX(datetimeaxis, series); | |
53 | chart->setAxisY(valueaxis, series); |
|
55 | chart->setAxisY(valueaxis, series); | |
54 | } |
|
56 | } | |
55 |
|
57 | |||
56 | return chart; |
|
58 | return chart; | |
57 | } |
|
59 | } | |
58 | }; |
|
60 | }; | |
59 |
|
61 | |||
60 | DECLARE_CHART(DateTimeAxisX); |
|
62 | DECLARE_CHART(DateTimeAxisX); |
@@ -1,360 +1,361 | |||||
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 <float.h> | |||
26 | #include <cmath> |
|
27 | #include <cmath> | |
27 |
|
28 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 | /*! |
|
30 | /*! | |
30 | \class QDateTimeAxis |
|
31 | \class QDateTimeAxis | |
31 | \brief The QDateTimeAxis class is used for manipulating chart's axis. |
|
32 | \brief The QDateTimeAxis class is used for manipulating chart's axis. | |
32 | \mainclass |
|
33 | \mainclass | |
33 |
|
34 | |||
34 | The labels can be configured by setting an appropriate DateTime format. |
|
35 | The labels can be configured by setting an appropriate DateTime format. | |
35 | QDateTimeAxis works correctly with dates from 4714 BCE to 287396 CE |
|
36 | QDateTimeAxis works correctly with dates from 4714 BCE to 287396 CE | |
36 | There are also other limitiation related to QDateTime . Please refer to QDateTime documentation. |
|
37 | There are also other limitiation related to QDateTime . Please refer to QDateTime documentation. | |
37 | QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
38 | QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. | |
38 |
|
39 | |||
39 | NOTE: QDateTimeAxis is disabled on ARM architecture. |
|
40 | NOTE: QDateTimeAxis is disabled on ARM architecture. | |
40 |
|
41 | |||
41 | \image api_datatime_axis.png |
|
42 | \image api_datatime_axis.png | |
42 |
|
43 | |||
43 | QDateTimeAxis can be used with QLineSeries, QSplineSeries or QScatterSeries. |
|
44 | QDateTimeAxis can be used with QLineSeries, QSplineSeries or QScatterSeries. | |
44 | To add a data point to the series QDateTime::toMSecsSinceEpoch() is used. |
|
45 | To add a data point to the series QDateTime::toMSecsSinceEpoch() is used. | |
45 | \code |
|
46 | \code | |
46 | QLineSeries *series = new QLineSeries; |
|
47 | QLineSeries *series = new QLineSeries; | |
47 |
|
48 | |||
48 | QDateTime xValue; |
|
49 | QDateTime xValue; | |
49 | xValue.setDate(QDate(2012, 1 , 18)); |
|
50 | xValue.setDate(QDate(2012, 1 , 18)); | |
50 | xValue.setTime(QTime(9, 34)); |
|
51 | xValue.setTime(QTime(9, 34)); | |
51 | qreal yValue = 12; |
|
52 | qreal yValue = 12; | |
52 | series->append(xValue.toMSecsSinceEpoch(), yValue); |
|
53 | series->append(xValue.toMSecsSinceEpoch(), yValue); | |
53 |
|
54 | |||
54 | xValue.setDate(QDate(2013, 5 , 11)); |
|
55 | xValue.setDate(QDate(2013, 5 , 11)); | |
55 | xValue.setTime(QTime(11, 14)); |
|
56 | xValue.setTime(QTime(11, 14)); | |
56 | qreal yValue = 22; |
|
57 | qreal yValue = 22; | |
57 | series->append(xValue.toMSecsSinceEpoch(), yValue); |
|
58 | series->append(xValue.toMSecsSinceEpoch(), yValue); | |
58 | \endcode |
|
59 | \endcode | |
59 |
|
60 | |||
60 | Adding the series to the chart and setting up the QDateTimeAxis. |
|
61 | Adding the series to the chart and setting up the QDateTimeAxis. | |
61 | \code |
|
62 | \code | |
62 | QChartView *chartView = new QChartView; |
|
63 | QChartView *chartView = new QChartView; | |
63 | chartView->chart()->addSeries(series); |
|
64 | chartView->chart()->addSeries(series); | |
64 |
|
65 | |||
65 | // ... |
|
66 | // ... | |
66 | QDateTimeAxis *axisX = new QDateTimeAxis; |
|
67 | QDateTimeAxis *axisX = new QDateTimeAxis; | |
67 | axisX->setFormat("dd-MM-yyyy h:mm"); |
|
68 | axisX->setFormat("dd-MM-yyyy h:mm"); | |
68 | chartView->chart()->setAxisX(axisX, series); |
|
69 | chartView->chart()->setAxisX(axisX, series); | |
69 | \endcode |
|
70 | \endcode | |
70 | */ |
|
71 | */ | |
71 |
|
72 | |||
72 | /*! |
|
73 | /*! | |
73 | \qmlclass DateTimeAxis QDateTimeAxis |
|
74 | \qmlclass DateTimeAxis QDateTimeAxis | |
74 | \brief The DateTimeAxis element is used for manipulating chart's axes |
|
75 | \brief The DateTimeAxis element is used for manipulating chart's axes | |
75 | \inherits AbstractAxis |
|
76 | \inherits AbstractAxis | |
76 |
|
77 | |||
77 | The labels can be configured by setting an appropriate DateTime format. |
|
78 | The labels can be configured by setting an appropriate DateTime format. | |
78 | Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored. |
|
79 | Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored. | |
79 | DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
80 | DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. | |
80 | */ |
|
81 | */ | |
81 |
|
82 | |||
82 | /*! |
|
83 | /*! | |
83 | \property QDateTimeAxis::min |
|
84 | \property QDateTimeAxis::min | |
84 | Defines the minimum value on the axis. |
|
85 | Defines the minimum value on the axis. | |
85 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
86 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
86 | */ |
|
87 | */ | |
87 | /*! |
|
88 | /*! | |
88 | \qmlproperty real ValuesAxis::min |
|
89 | \qmlproperty real ValuesAxis::min | |
89 | Defines the minimum value on the axis. |
|
90 | Defines the minimum value on the axis. | |
90 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
91 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
91 | */ |
|
92 | */ | |
92 |
|
93 | |||
93 | /*! |
|
94 | /*! | |
94 | \property QDateTimeAxis::max |
|
95 | \property QDateTimeAxis::max | |
95 | Defines the maximum value on the axis. |
|
96 | Defines the maximum value on the axis. | |
96 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
97 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
97 | */ |
|
98 | */ | |
98 | /*! |
|
99 | /*! | |
99 | \qmlproperty real ValuesAxis::max |
|
100 | \qmlproperty real ValuesAxis::max | |
100 | Defines the maximum value on the axis. |
|
101 | Defines the maximum value on the axis. | |
101 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
102 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
102 | */ |
|
103 | */ | |
103 |
|
104 | |||
104 | /*! |
|
105 | /*! | |
105 | \fn void QDateTimeAxis::minChanged(QDateTime min) |
|
106 | \fn void QDateTimeAxis::minChanged(QDateTime min) | |
106 | Axis emits signal when \a min of axis has changed. |
|
107 | Axis emits signal when \a min of axis has changed. | |
107 | */ |
|
108 | */ | |
108 | /*! |
|
109 | /*! | |
109 | \qmlsignal ValuesAxis::onMinChanged(QDateTime min) |
|
110 | \qmlsignal ValuesAxis::onMinChanged(QDateTime min) | |
110 | Axis emits signal when \a min of axis has changed. |
|
111 | Axis emits signal when \a min of axis has changed. | |
111 | */ |
|
112 | */ | |
112 |
|
113 | |||
113 | /*! |
|
114 | /*! | |
114 | \fn void QDateTimeAxis::maxChanged(QDateTime max) |
|
115 | \fn void QDateTimeAxis::maxChanged(QDateTime max) | |
115 | Axis emits signal when \a max of axis has changed. |
|
116 | Axis emits signal when \a max of axis has changed. | |
116 | */ |
|
117 | */ | |
117 | /*! |
|
118 | /*! | |
118 | \qmlsignal ValuesAxis::onMaxChanged(QDateTime max) |
|
119 | \qmlsignal ValuesAxis::onMaxChanged(QDateTime max) | |
119 | Axis emits signal when \a max of axis has changed. |
|
120 | Axis emits signal when \a max of axis has changed. | |
120 | */ |
|
121 | */ | |
121 |
|
122 | |||
122 | /*! |
|
123 | /*! | |
123 | \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max) |
|
124 | \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max) | |
124 | Axis emits signal when \a min or \a max of axis has changed. |
|
125 | Axis emits signal when \a min or \a max of axis has changed. | |
125 | */ |
|
126 | */ | |
126 |
|
127 | |||
127 | /*! |
|
128 | /*! | |
128 | \property QDateTimeAxis::tickCount |
|
129 | \property QDateTimeAxis::tickCount | |
129 | The number of tick marks for the axis. |
|
130 | The number of tick marks for the axis. | |
130 | */ |
|
131 | */ | |
131 |
|
132 | |||
132 | /*! |
|
133 | /*! | |
133 | \qmlproperty int DateTimeAxis::tickCount |
|
134 | \qmlproperty int DateTimeAxis::tickCount | |
134 | The number of tick marks for the axis. |
|
135 | The number of tick marks for the axis. | |
135 | */ |
|
136 | */ | |
136 |
|
137 | |||
137 | /*! |
|
138 | /*! | |
138 | \property QDateTimeAxis::format |
|
139 | \property QDateTimeAxis::format | |
139 | The format string that is used when creating label for the axis out of a QDateTime object. |
|
140 | The format string that is used when creating label for the axis out of a QDateTime object. | |
140 | Check QDateTime documentation for information on how the string should be defined. |
|
141 | Check QDateTime documentation for information on how the string should be defined. | |
141 | */ |
|
142 | */ | |
142 | /*! |
|
143 | /*! | |
143 | \qmlproperty string DateTimeAxis::format |
|
144 | \qmlproperty string DateTimeAxis::format | |
144 | The format string that is used when creating label for the axis out of a QDateTime object. |
|
145 | The format string that is used when creating label for the axis out of a QDateTime object. | |
145 | Check QDateTime documentation for information on how the string should be defined. |
|
146 | Check QDateTime documentation for information on how the string should be defined. | |
146 | */ |
|
147 | */ | |
147 |
|
148 | |||
148 | /*! |
|
149 | /*! | |
149 | \fn void QDateTimeAxis::formatChanged(QString format) |
|
150 | \fn void QDateTimeAxis::formatChanged(QString format) | |
150 | Axis emits signal when \a format of the axis has changed. |
|
151 | Axis emits signal when \a format of the axis has changed. | |
151 | */ |
|
152 | */ | |
152 | /*! |
|
153 | /*! | |
153 | \qmlsignal DateTimeAxis::onFormatChanged(string format) |
|
154 | \qmlsignal DateTimeAxis::onFormatChanged(string format) | |
154 | Axis emits signal when \a format of the axis has changed. |
|
155 | Axis emits signal when \a format of the axis has changed. | |
155 | */ |
|
156 | */ | |
156 |
|
157 | |||
157 | /*! |
|
158 | /*! | |
158 | Constructs an axis object which is a child of \a parent. |
|
159 | Constructs an axis object which is a child of \a parent. | |
159 | */ |
|
160 | */ | |
160 | QDateTimeAxis::QDateTimeAxis(QObject *parent) : |
|
161 | QDateTimeAxis::QDateTimeAxis(QObject *parent) : | |
161 | QAbstractAxis(*new QDateTimeAxisPrivate(this), parent) |
|
162 | QAbstractAxis(*new QDateTimeAxisPrivate(this), parent) | |
162 | { |
|
163 | { | |
163 |
|
164 | |||
164 | } |
|
165 | } | |
165 |
|
166 | |||
166 | /*! |
|
167 | /*! | |
167 | \internal |
|
168 | \internal | |
168 | */ |
|
169 | */ | |
169 | QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) |
|
170 | QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) | |
170 | { |
|
171 | { | |
171 |
|
172 | |||
172 | } |
|
173 | } | |
173 |
|
174 | |||
174 | /*! |
|
175 | /*! | |
175 | Destroys the object |
|
176 | Destroys the object | |
176 | */ |
|
177 | */ | |
177 | QDateTimeAxis::~QDateTimeAxis() |
|
178 | QDateTimeAxis::~QDateTimeAxis() | |
178 | { |
|
179 | { | |
179 |
|
180 | |||
180 | } |
|
181 | } | |
181 |
|
182 | |||
182 | void QDateTimeAxis::setMin(QDateTime min) |
|
183 | void QDateTimeAxis::setMin(QDateTime min) | |
183 | { |
|
184 | { | |
184 | Q_D(QDateTimeAxis); |
|
185 | Q_D(QDateTimeAxis); | |
185 | if (min.isValid()) |
|
186 | if (min.isValid()) | |
186 | setRange(min, qMax(d->m_max, min)); |
|
187 | setRange(min, qMax(d->m_max, min)); | |
187 | } |
|
188 | } | |
188 |
|
189 | |||
189 | QDateTime QDateTimeAxis::min() const |
|
190 | QDateTime QDateTimeAxis::min() const | |
190 | { |
|
191 | { | |
191 | Q_D(const QDateTimeAxis); |
|
192 | Q_D(const QDateTimeAxis); | |
192 | return d->m_min; |
|
193 | return d->m_min; | |
193 | } |
|
194 | } | |
194 |
|
195 | |||
195 | void QDateTimeAxis::setMax(QDateTime max) |
|
196 | void QDateTimeAxis::setMax(QDateTime max) | |
196 | { |
|
197 | { | |
197 | Q_D(QDateTimeAxis); |
|
198 | Q_D(QDateTimeAxis); | |
198 | if (max.isValid()) |
|
199 | if (max.isValid()) | |
199 | setRange(qMin(d->m_min, max), max); |
|
200 | setRange(qMin(d->m_min, max), max); | |
200 | } |
|
201 | } | |
201 |
|
202 | |||
202 | QDateTime QDateTimeAxis::max() const |
|
203 | QDateTime QDateTimeAxis::max() const | |
203 | { |
|
204 | { | |
204 | Q_D(const QDateTimeAxis); |
|
205 | Q_D(const QDateTimeAxis); | |
205 | return d->m_max; |
|
206 | return d->m_max; | |
206 | } |
|
207 | } | |
207 |
|
208 | |||
208 | /*! |
|
209 | /*! | |
209 | Sets range from \a min to \a max on the axis. |
|
210 | Sets range from \a min to \a max on the axis. | |
210 | If min is greater than max then this function returns without making any changes. |
|
211 | If min is greater than max then this function returns without making any changes. | |
211 | */ |
|
212 | */ | |
212 | void QDateTimeAxis::setRange(QDateTime min, QDateTime max) |
|
213 | void QDateTimeAxis::setRange(QDateTime min, QDateTime max) | |
213 | { |
|
214 | { | |
214 | Q_D(QDateTimeAxis); |
|
215 | Q_D(QDateTimeAxis); | |
215 | if (!min.isValid() || !max.isValid() || min > max) |
|
216 | if (!min.isValid() || !max.isValid() || min > max) | |
216 | return; |
|
217 | return; | |
217 |
|
218 | |||
218 | bool changed = false; |
|
219 | bool changed = false; | |
219 | if (d->m_min != min) { |
|
220 | if (d->m_min != min) { | |
220 | d->m_min = min; |
|
221 | d->m_min = min; | |
221 | changed = true; |
|
222 | changed = true; | |
222 | emit minChanged(min); |
|
223 | emit minChanged(min); | |
223 | } |
|
224 | } | |
224 |
|
225 | |||
225 | if (d->m_max != max) { |
|
226 | if (d->m_max != max) { | |
226 | d->m_max = max; |
|
227 | d->m_max = max; | |
227 | changed = true; |
|
228 | changed = true; | |
228 | emit maxChanged(max); |
|
229 | emit maxChanged(max); | |
229 | } |
|
230 | } | |
230 |
|
231 | |||
231 | if (changed) { |
|
232 | if (changed) { | |
232 | emit rangeChanged(d->m_min, d->m_max); |
|
233 | emit rangeChanged(d->m_min, d->m_max); | |
233 | d->emitUpdated(); |
|
234 | d->emitUpdated(); | |
234 | } |
|
235 | } | |
235 | } |
|
236 | } | |
236 |
|
237 | |||
237 | void QDateTimeAxis::setFormat(QString format) |
|
238 | void QDateTimeAxis::setFormat(QString format) | |
238 | { |
|
239 | { | |
239 | Q_D(QDateTimeAxis); |
|
240 | Q_D(QDateTimeAxis); | |
240 | if (d->m_format != format) { |
|
241 | if (d->m_format != format) { | |
241 | d->m_format = format; |
|
242 | d->m_format = format; | |
242 | emit formatChanged(format); |
|
243 | emit formatChanged(format); | |
243 | } |
|
244 | } | |
244 | } |
|
245 | } | |
245 |
|
246 | |||
246 | QString QDateTimeAxis::format() const |
|
247 | QString QDateTimeAxis::format() const | |
247 | { |
|
248 | { | |
248 | Q_D(const QDateTimeAxis); |
|
249 | Q_D(const QDateTimeAxis); | |
249 | return d->m_format; |
|
250 | return d->m_format; | |
250 | } |
|
251 | } | |
251 |
|
252 | |||
252 | /*! |
|
253 | /*! | |
253 | Sets \a count for ticks on the axis. |
|
254 | Sets \a count for ticks on the axis. | |
254 | */ |
|
255 | */ | |
255 | void QDateTimeAxis::setTickCount(int count) |
|
256 | void QDateTimeAxis::setTickCount(int count) | |
256 | { |
|
257 | { | |
257 | Q_D(QDateTimeAxis); |
|
258 | Q_D(QDateTimeAxis); | |
258 | if (d->m_tickCount != count && count >= 2) { |
|
259 | if (d->m_tickCount != count && count >= 2) { | |
259 | d->m_tickCount = count; |
|
260 | d->m_tickCount = count; | |
260 | d->emitUpdated(); |
|
261 | d->emitUpdated(); | |
261 | } |
|
262 | } | |
262 | } |
|
263 | } | |
263 |
|
264 | |||
264 | /*! |
|
265 | /*! | |
265 | \fn int QDateTimeAxis::tickCount() const |
|
266 | \fn int QDateTimeAxis::tickCount() const | |
266 | Return number of ticks on the axis |
|
267 | Return number of ticks on the axis | |
267 | */ |
|
268 | */ | |
268 | int QDateTimeAxis::tickCount() const |
|
269 | int QDateTimeAxis::tickCount() const | |
269 | { |
|
270 | { | |
270 | Q_D(const QDateTimeAxis); |
|
271 | Q_D(const QDateTimeAxis); | |
271 | return d->m_tickCount; |
|
272 | return d->m_tickCount; | |
272 | } |
|
273 | } | |
273 |
|
274 | |||
274 | /*! |
|
275 | /*! | |
275 | Returns the type of the axis |
|
276 | Returns the type of the axis | |
276 | */ |
|
277 | */ | |
277 | QAbstractAxis::AxisType QDateTimeAxis::type() const |
|
278 | QAbstractAxis::AxisType QDateTimeAxis::type() const | |
278 | { |
|
279 | { | |
279 | return AxisTypeDateTime; |
|
280 | return AxisTypeDateTime; | |
280 | } |
|
281 | } | |
281 |
|
282 | |||
282 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
283 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
283 |
|
284 | |||
284 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis *q) |
|
285 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis *q) | |
285 | : QAbstractAxisPrivate(q), |
|
286 | : QAbstractAxisPrivate(q), | |
286 | m_min(QDateTime::fromMSecsSinceEpoch(0)), |
|
287 | m_min(QDateTime::fromMSecsSinceEpoch(0)), | |
287 | m_max(QDateTime::fromMSecsSinceEpoch(0)), |
|
288 | m_max(QDateTime::fromMSecsSinceEpoch(0)), | |
288 | m_tickCount(5) |
|
289 | m_tickCount(5) | |
289 | { |
|
290 | { | |
290 | m_format = "dd-MM-yyyy\nh:mm"; |
|
291 | m_format = "dd-MM-yyyy\nh:mm"; | |
291 | } |
|
292 | } | |
292 |
|
293 | |||
293 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() |
|
294 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() | |
294 | { |
|
295 | { | |
295 |
|
296 | |||
296 | } |
|
297 | } | |
297 |
|
298 | |||
298 | void QDateTimeAxisPrivate::handleDomainUpdated() |
|
299 | void QDateTimeAxisPrivate::handleDomainUpdated() | |
299 | { |
|
300 | { | |
300 | Q_Q(QDateTimeAxis); |
|
301 | Q_Q(QDateTimeAxis); | |
301 | Domain *domain = qobject_cast<Domain *>(sender()); |
|
302 | Domain *domain = qobject_cast<Domain *>(sender()); | |
302 | Q_ASSERT(domain); |
|
303 | Q_ASSERT(domain); | |
303 |
|
304 | |||
304 | if (orientation() == Qt::Horizontal) |
|
305 | if (orientation() == Qt::Horizontal) | |
305 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); |
|
306 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); | |
306 | else if (orientation() == Qt::Vertical) |
|
307 | else if (orientation() == Qt::Vertical) | |
307 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); |
|
308 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); | |
308 | } |
|
309 | } | |
309 |
|
310 | |||
310 |
|
311 | |||
311 | void QDateTimeAxisPrivate::setMin(const QVariant &min) |
|
312 | void QDateTimeAxisPrivate::setMin(const QVariant &min) | |
312 | { |
|
313 | { | |
313 | Q_Q(QDateTimeAxis); |
|
314 | Q_Q(QDateTimeAxis); | |
314 | if (min.canConvert(QVariant::DateTime)) |
|
315 | if (min.canConvert(QVariant::DateTime)) | |
315 | q->setMin(min.toDateTime()); |
|
316 | q->setMin(min.toDateTime()); | |
316 | } |
|
317 | } | |
317 |
|
318 | |||
318 | void QDateTimeAxisPrivate::setMax(const QVariant &max) |
|
319 | void QDateTimeAxisPrivate::setMax(const QVariant &max) | |
319 | { |
|
320 | { | |
320 |
|
321 | |||
321 | Q_Q(QDateTimeAxis); |
|
322 | Q_Q(QDateTimeAxis); | |
322 | if (max.canConvert(QVariant::DateTime)) |
|
323 | if (max.canConvert(QVariant::DateTime)) | |
323 | q->setMax(max.toDateTime()); |
|
324 | q->setMax(max.toDateTime()); | |
324 | } |
|
325 | } | |
325 |
|
326 | |||
326 | void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
327 | void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
327 | { |
|
328 | { | |
328 | Q_Q(QDateTimeAxis); |
|
329 | Q_Q(QDateTimeAxis); | |
329 | if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime)) |
|
330 | if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime)) | |
330 | q->setRange(min.toDateTime(), max.toDateTime()); |
|
331 | q->setRange(min.toDateTime(), max.toDateTime()); | |
331 | } |
|
332 | } | |
332 |
|
333 | |||
333 | ChartAxis *QDateTimeAxisPrivate::createGraphics(ChartPresenter *presenter) |
|
334 | ChartAxis *QDateTimeAxisPrivate::createGraphics(ChartPresenter *presenter) | |
334 | { |
|
335 | { | |
335 | Q_Q(QDateTimeAxis); |
|
336 | Q_Q(QDateTimeAxis); | |
336 | if (m_orientation == Qt::Vertical) |
|
337 | if (m_orientation == Qt::Vertical) | |
337 | return new ChartDateTimeAxisY(q, presenter); |
|
338 | return new ChartDateTimeAxisY(q, presenter); | |
338 | return new ChartDateTimeAxisX(q, presenter); |
|
339 | return new ChartDateTimeAxisX(q, presenter); | |
339 | } |
|
340 | } | |
340 |
|
341 | |||
341 | void QDateTimeAxisPrivate::intializeDomain(Domain *domain) |
|
342 | void QDateTimeAxisPrivate::intializeDomain(Domain *domain) | |
342 | { |
|
343 | { | |
343 | Q_Q(QDateTimeAxis); |
|
344 | Q_Q(QDateTimeAxis); | |
344 | if (m_max == m_min) { |
|
345 | if (m_max == m_min) { | |
345 | if (m_orientation == Qt::Vertical) |
|
346 | if (m_orientation == Qt::Vertical) | |
346 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); |
|
347 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); | |
347 | else |
|
348 | else | |
348 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); |
|
349 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); | |
349 | } else { |
|
350 | } else { | |
350 | if (m_orientation == Qt::Vertical) |
|
351 | if (m_orientation == Qt::Vertical) | |
351 | domain->setRangeY(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); |
|
352 | domain->setRangeY(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); | |
352 | else |
|
353 | else | |
353 | domain->setRangeX(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); |
|
354 | domain->setRangeX(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); | |
354 | } |
|
355 | } | |
355 | } |
|
356 | } | |
356 |
|
357 | |||
357 | #include "moc_qdatetimeaxis.cpp" |
|
358 | #include "moc_qdatetimeaxis.cpp" | |
358 | #include "moc_qdatetimeaxis_p.cpp" |
|
359 | #include "moc_qdatetimeaxis_p.cpp" | |
359 |
|
360 | |||
360 | QTCOMMERCIALCHART_END_NAMESPACE |
|
361 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now