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