@@ -1,332 +1,334 | |||||
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 | Note that any date before 4800 BCE or after about 1.4 million CE may not be accurately stored. | |||
|
36 | ||||
35 | ValuesAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
37 | ValuesAxis can be setup to show axis line with tick marks, grid lines and shades. | |
36 | Values of axis are drawn to position of ticks |
|
38 | Values of axis are drawn to position of ticks | |
37 | */ |
|
39 | */ | |
38 |
|
40 | |||
39 | /*! |
|
41 | /*! | |
40 | \qmlclass ValuesAxis QDateTimeAxis |
|
42 | \qmlclass ValuesAxis QDateTimeAxis | |
41 | \brief The ValuesAxis element is used for manipulating chart's axes |
|
43 | \brief The ValuesAxis element is used for manipulating chart's axes | |
42 |
|
44 | |||
43 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
45 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
44 | Values of axis are drawn to position of ticks |
|
46 | Values of axis are drawn to position of ticks | |
45 |
|
47 | |||
46 | To access Axes you can use ChartView API. For example: |
|
48 | To access Axes you can use ChartView API. For example: | |
47 | \code |
|
49 | \code | |
48 | ChartView { |
|
50 | ChartView { | |
49 | ValuesAxis { |
|
51 | ValuesAxis { | |
50 | id: xAxis |
|
52 | id: xAxis | |
51 | min: 0 |
|
53 | min: 0 | |
52 | max: 10 |
|
54 | max: 10 | |
53 | } |
|
55 | } | |
54 | // Add a few series... |
|
56 | // Add a few series... | |
55 | } |
|
57 | } | |
56 | \endcode |
|
58 | \endcode | |
57 | */ |
|
59 | */ | |
58 |
|
60 | |||
59 | /*! |
|
61 | /*! | |
60 | \property QDateTimeAxis::min |
|
62 | \property QDateTimeAxis::min | |
61 | Defines the minimum value on the axis. |
|
63 | Defines the minimum value on the axis. | |
62 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
64 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
63 | */ |
|
65 | */ | |
64 | /*! |
|
66 | /*! | |
65 | \qmlproperty real ValuesAxis::min |
|
67 | \qmlproperty real ValuesAxis::min | |
66 | Defines the minimum value on the axis. |
|
68 | Defines the minimum value on the axis. | |
67 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
69 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
68 | */ |
|
70 | */ | |
69 |
|
71 | |||
70 | /*! |
|
72 | /*! | |
71 | \property QDateTimeAxis::max |
|
73 | \property QDateTimeAxis::max | |
72 | Defines the maximum value on the axis. |
|
74 | Defines the maximum value on the axis. | |
73 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
75 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
74 | */ |
|
76 | */ | |
75 | /*! |
|
77 | /*! | |
76 | \qmlproperty real ValuesAxis::max |
|
78 | \qmlproperty real ValuesAxis::max | |
77 | Defines the maximum value on the axis. |
|
79 | Defines the maximum value on the axis. | |
78 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
80 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
79 | */ |
|
81 | */ | |
80 |
|
82 | |||
81 | /*! |
|
83 | /*! | |
82 | \fn void QDateTimeAxis::minChanged(QDateTime min) |
|
84 | \fn void QDateTimeAxis::minChanged(QDateTime min) | |
83 | Axis emits signal when \a min of axis has changed. |
|
85 | Axis emits signal when \a min of axis has changed. | |
84 | */ |
|
86 | */ | |
85 | /*! |
|
87 | /*! | |
86 | \qmlsignal ValuesAxis::onMinChanged(QDateTime min) |
|
88 | \qmlsignal ValuesAxis::onMinChanged(QDateTime min) | |
87 | Axis emits signal when \a min of axis has changed. |
|
89 | Axis emits signal when \a min of axis has changed. | |
88 | */ |
|
90 | */ | |
89 |
|
91 | |||
90 | /*! |
|
92 | /*! | |
91 | \fn void QDateTimeAxis::maxChanged(QDateTime max) |
|
93 | \fn void QDateTimeAxis::maxChanged(QDateTime max) | |
92 | Axis emits signal when \a max of axis has changed. |
|
94 | Axis emits signal when \a max of axis has changed. | |
93 | */ |
|
95 | */ | |
94 | /*! |
|
96 | /*! | |
95 | \qmlsignal ValuesAxis::onMaxChanged(QDateTime max) |
|
97 | \qmlsignal ValuesAxis::onMaxChanged(QDateTime max) | |
96 | Axis emits signal when \a max of axis has changed. |
|
98 | Axis emits signal when \a max of axis has changed. | |
97 | */ |
|
99 | */ | |
98 |
|
100 | |||
99 | /*! |
|
101 | /*! | |
100 | \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max) |
|
102 | \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max) | |
101 | Axis emits signal when \a min or \a max of axis has changed. |
|
103 | Axis emits signal when \a min or \a max of axis has changed. | |
102 | */ |
|
104 | */ | |
103 |
|
105 | |||
104 | /*! |
|
106 | /*! | |
105 | \property QDateTimeAxis::ticksCount |
|
107 | \property QDateTimeAxis::ticksCount | |
106 | The number of tick marks for the axis. |
|
108 | The number of tick marks for the axis. | |
107 | */ |
|
109 | */ | |
108 |
|
110 | |||
109 | /*! |
|
111 | /*! | |
110 | \qmlproperty int ValuesAxis::ticksCount |
|
112 | \qmlproperty int ValuesAxis::ticksCount | |
111 | The number of tick marks for the axis. |
|
113 | The number of tick marks for the axis. | |
112 | */ |
|
114 | */ | |
113 |
|
115 | |||
114 | /*! |
|
116 | /*! | |
115 | Constructs an axis object which is a child of \a parent. |
|
117 | Constructs an axis object which is a child of \a parent. | |
116 | */ |
|
118 | */ | |
117 | QDateTimeAxis::QDateTimeAxis(QObject *parent) : |
|
119 | QDateTimeAxis::QDateTimeAxis(QObject *parent) : | |
118 | QAbstractAxis(*new QDateTimeAxisPrivate(this),parent) |
|
120 | QAbstractAxis(*new QDateTimeAxisPrivate(this),parent) | |
119 | { |
|
121 | { | |
120 |
|
122 | |||
121 | } |
|
123 | } | |
122 |
|
124 | |||
123 | /*! |
|
125 | /*! | |
124 | \internal |
|
126 | \internal | |
125 | */ |
|
127 | */ | |
126 | QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) |
|
128 | QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) | |
127 | { |
|
129 | { | |
128 |
|
130 | |||
129 | } |
|
131 | } | |
130 |
|
132 | |||
131 | /*! |
|
133 | /*! | |
132 | Destroys the object |
|
134 | Destroys the object | |
133 | */ |
|
135 | */ | |
134 | QDateTimeAxis::~QDateTimeAxis() |
|
136 | QDateTimeAxis::~QDateTimeAxis() | |
135 | { |
|
137 | { | |
136 |
|
138 | |||
137 | } |
|
139 | } | |
138 |
|
140 | |||
139 | void QDateTimeAxis::setMin(QDateTime min) |
|
141 | void QDateTimeAxis::setMin(QDateTime min) | |
140 | { |
|
142 | { | |
141 | Q_D(QDateTimeAxis); |
|
143 | Q_D(QDateTimeAxis); | |
142 | if (min.isValid()) |
|
144 | if (min.isValid()) | |
143 | setRange(min, qMax(d->m_max, min)); |
|
145 | setRange(min, qMax(d->m_max, min)); | |
144 | } |
|
146 | } | |
145 |
|
147 | |||
146 | QDateTime QDateTimeAxis::min() const |
|
148 | QDateTime QDateTimeAxis::min() const | |
147 | { |
|
149 | { | |
148 | Q_D(const QDateTimeAxis); |
|
150 | Q_D(const QDateTimeAxis); | |
149 | return d->m_min; |
|
151 | return d->m_min; | |
150 | } |
|
152 | } | |
151 |
|
153 | |||
152 | void QDateTimeAxis::setMax(QDateTime max) |
|
154 | void QDateTimeAxis::setMax(QDateTime max) | |
153 | { |
|
155 | { | |
154 | Q_D(QDateTimeAxis); |
|
156 | Q_D(QDateTimeAxis); | |
155 | if (max.isValid()) |
|
157 | if (max.isValid()) | |
156 | setRange(qMin(d->m_min, max), max); |
|
158 | setRange(qMin(d->m_min, max), max); | |
157 | } |
|
159 | } | |
158 |
|
160 | |||
159 | QDateTime QDateTimeAxis::max() const |
|
161 | QDateTime QDateTimeAxis::max() const | |
160 | { |
|
162 | { | |
161 | Q_D(const QDateTimeAxis); |
|
163 | Q_D(const QDateTimeAxis); | |
162 | return d->m_max; |
|
164 | return d->m_max; | |
163 | } |
|
165 | } | |
164 |
|
166 | |||
165 | /*! |
|
167 | /*! | |
166 | Sets range from \a min to \a max on the axis. |
|
168 | Sets range from \a min to \a max on the axis. | |
167 | If min is greater than max then this function returns without making any changes. |
|
169 | If min is greater than max then this function returns without making any changes. | |
168 | */ |
|
170 | */ | |
169 | void QDateTimeAxis::setRange(QDateTime min, QDateTime max) |
|
171 | void QDateTimeAxis::setRange(QDateTime min, QDateTime max) | |
170 | { |
|
172 | { | |
171 | Q_D(QDateTimeAxis); |
|
173 | Q_D(QDateTimeAxis); | |
172 | if (!min.isValid() || !max.isValid() || min > max) |
|
174 | if (!min.isValid() || !max.isValid() || min > max) | |
173 | return; |
|
175 | return; | |
174 |
|
176 | |||
175 | bool changed = false; |
|
177 | bool changed = false; | |
176 | if (d->m_min != min) { |
|
178 | if (d->m_min != min) { | |
177 | d->m_min = min; |
|
179 | d->m_min = min; | |
178 | changed = true; |
|
180 | changed = true; | |
179 | emit minChanged(min); |
|
181 | emit minChanged(min); | |
180 | } |
|
182 | } | |
181 |
|
183 | |||
182 | if (d->m_max != max) { |
|
184 | if (d->m_max != max) { | |
183 | d->m_max = max; |
|
185 | d->m_max = max; | |
184 | changed = true; |
|
186 | changed = true; | |
185 | emit maxChanged(max); |
|
187 | emit maxChanged(max); | |
186 | } |
|
188 | } | |
187 |
|
189 | |||
188 | // if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount); |
|
190 | // if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount); | |
189 |
|
191 | |||
190 | if (changed) { |
|
192 | if (changed) { | |
191 | emit rangeChanged(d->m_min,d->m_max); |
|
193 | emit rangeChanged(d->m_min,d->m_max); | |
192 | d->emitUpdated(); |
|
194 | d->emitUpdated(); | |
193 | } |
|
195 | } | |
194 | } |
|
196 | } | |
195 |
|
197 | |||
196 | /*! |
|
198 | /*! | |
197 | Sets \a format string that is used when creating label for the axis out of the QDateTime object. |
|
199 | Sets \a format string that is used when creating label for the axis out of the QDateTime object. | |
198 | Check QDateTime documentation for information on how the string should be defined. |
|
200 | Check QDateTime documentation for information on how the string should be defined. | |
199 | \sa formatString() |
|
201 | \sa formatString() | |
200 | */ |
|
202 | */ | |
201 | void QDateTimeAxis::setFormatString(QString format) |
|
203 | void QDateTimeAxis::setFormatString(QString format) | |
202 | { |
|
204 | { | |
203 | Q_D(QDateTimeAxis); |
|
205 | Q_D(QDateTimeAxis); | |
204 | d->m_format = format; |
|
206 | d->m_format = format; | |
205 | } |
|
207 | } | |
206 |
|
208 | |||
207 | /*! |
|
209 | /*! | |
208 | Returns the format string that is used when creating label for the axis out of the QDateTime object. |
|
210 | Returns the format string that is used when creating label for the axis out of the QDateTime object. | |
209 | Check QDateTime documentation for information on how the string should be defined. |
|
211 | Check QDateTime documentation for information on how the string should be defined. | |
210 | \sa setFormatString() |
|
212 | \sa setFormatString() | |
211 | */ |
|
213 | */ | |
212 | QString QDateTimeAxis::formatString() const |
|
214 | QString QDateTimeAxis::formatString() const | |
213 | { |
|
215 | { | |
214 | Q_D(const QDateTimeAxis); |
|
216 | Q_D(const QDateTimeAxis); | |
215 | return d->m_format; |
|
217 | return d->m_format; | |
216 | } |
|
218 | } | |
217 |
|
219 | |||
218 | /*! |
|
220 | /*! | |
219 | Sets \a count for ticks on the axis. |
|
221 | Sets \a count for ticks on the axis. | |
220 | */ |
|
222 | */ | |
221 | void QDateTimeAxis::setTicksCount(int count) |
|
223 | void QDateTimeAxis::setTicksCount(int count) | |
222 | { |
|
224 | { | |
223 | Q_D(QDateTimeAxis); |
|
225 | Q_D(QDateTimeAxis); | |
224 | if (d->m_tickCount != count && count >=2) { |
|
226 | if (d->m_tickCount != count && count >=2) { | |
225 | d->m_tickCount = count; |
|
227 | d->m_tickCount = count; | |
226 | d->emitUpdated(); |
|
228 | d->emitUpdated(); | |
227 | } |
|
229 | } | |
228 | } |
|
230 | } | |
229 |
|
231 | |||
230 | /*! |
|
232 | /*! | |
231 | \fn int QDateTimeAxis::ticksCount() const |
|
233 | \fn int QDateTimeAxis::ticksCount() const | |
232 | Return number of ticks on the axis |
|
234 | Return number of ticks on the axis | |
233 | */ |
|
235 | */ | |
234 | int QDateTimeAxis::ticksCount() const |
|
236 | int QDateTimeAxis::ticksCount() const | |
235 | { |
|
237 | { | |
236 | Q_D(const QDateTimeAxis); |
|
238 | Q_D(const QDateTimeAxis); | |
237 | return d->m_tickCount; |
|
239 | return d->m_tickCount; | |
238 | } |
|
240 | } | |
239 |
|
241 | |||
240 | /*! |
|
242 | /*! | |
241 | Returns the type of the axis |
|
243 | Returns the type of the axis | |
242 | */ |
|
244 | */ | |
243 | QAbstractAxis::AxisType QDateTimeAxis::type() const |
|
245 | QAbstractAxis::AxisType QDateTimeAxis::type() const | |
244 | { |
|
246 | { | |
245 | return AxisTypeDateTime; |
|
247 | return AxisTypeDateTime; | |
246 | } |
|
248 | } | |
247 |
|
249 | |||
248 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
250 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
249 |
|
251 | |||
250 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis* q): |
|
252 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis* q): | |
251 | QAbstractAxisPrivate(q), |
|
253 | QAbstractAxisPrivate(q), | |
252 | m_tickCount(5) |
|
254 | m_tickCount(5) | |
253 | { |
|
255 | { | |
254 | m_min = QDateTime::fromMSecsSinceEpoch(0); |
|
256 | m_min = QDateTime::fromMSecsSinceEpoch(0); | |
255 | m_max = QDateTime::fromMSecsSinceEpoch(0); |
|
257 | m_max = QDateTime::fromMSecsSinceEpoch(0); | |
256 | m_format = "hh:mm:ss\ndd-mm-yyyy"; |
|
258 | m_format = "hh:mm:ss\ndd-mm-yyyy"; | |
257 | } |
|
259 | } | |
258 |
|
260 | |||
259 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() |
|
261 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() | |
260 | { |
|
262 | { | |
261 |
|
263 | |||
262 | } |
|
264 | } | |
263 |
|
265 | |||
264 | void QDateTimeAxisPrivate::handleDomainUpdated() |
|
266 | void QDateTimeAxisPrivate::handleDomainUpdated() | |
265 | { |
|
267 | { | |
266 | Q_Q(QDateTimeAxis); |
|
268 | Q_Q(QDateTimeAxis); | |
267 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
269 | Domain* domain = qobject_cast<Domain*>(sender()); | |
268 | Q_ASSERT(domain); |
|
270 | Q_ASSERT(domain); | |
269 |
|
271 | |||
270 | if(orientation()==Qt::Horizontal){ |
|
272 | if(orientation()==Qt::Horizontal){ | |
271 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); |
|
273 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); | |
272 | }else if(orientation()==Qt::Vertical){ |
|
274 | }else if(orientation()==Qt::Vertical){ | |
273 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); |
|
275 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); | |
274 | } |
|
276 | } | |
275 | } |
|
277 | } | |
276 |
|
278 | |||
277 |
|
279 | |||
278 | void QDateTimeAxisPrivate::setMin(const QVariant &min) |
|
280 | void QDateTimeAxisPrivate::setMin(const QVariant &min) | |
279 | { |
|
281 | { | |
280 | Q_Q(QDateTimeAxis); |
|
282 | Q_Q(QDateTimeAxis); | |
281 | if (min.canConvert(QVariant::DateTime)) |
|
283 | if (min.canConvert(QVariant::DateTime)) | |
282 | q->setMin(min.toDateTime()); |
|
284 | q->setMin(min.toDateTime()); | |
283 | } |
|
285 | } | |
284 |
|
286 | |||
285 | void QDateTimeAxisPrivate::setMax(const QVariant &max) |
|
287 | void QDateTimeAxisPrivate::setMax(const QVariant &max) | |
286 | { |
|
288 | { | |
287 |
|
289 | |||
288 | Q_Q(QDateTimeAxis); |
|
290 | Q_Q(QDateTimeAxis); | |
289 | if (max.canConvert(QVariant::DateTime)) |
|
291 | if (max.canConvert(QVariant::DateTime)) | |
290 | q->setMax(max.toDateTime()); |
|
292 | q->setMax(max.toDateTime()); | |
291 | } |
|
293 | } | |
292 |
|
294 | |||
293 | void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
295 | void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
294 | { |
|
296 | { | |
295 | Q_Q(QDateTimeAxis); |
|
297 | Q_Q(QDateTimeAxis); | |
296 | if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime)) |
|
298 | if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime)) | |
297 | q->setRange(min.toDateTime(), max.toDateTime()); |
|
299 | q->setRange(min.toDateTime(), max.toDateTime()); | |
298 | } |
|
300 | } | |
299 |
|
301 | |||
300 | ChartAxis* QDateTimeAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
302 | ChartAxis* QDateTimeAxisPrivate::createGraphics(ChartPresenter* presenter) | |
301 | { |
|
303 | { | |
302 | Q_Q(QDateTimeAxis); |
|
304 | Q_Q(QDateTimeAxis); | |
303 | if(m_orientation == Qt::Vertical){ |
|
305 | if(m_orientation == Qt::Vertical){ | |
304 | return new ChartDateTimeAxisY(q,presenter); |
|
306 | return new ChartDateTimeAxisY(q,presenter); | |
305 | }else{ |
|
307 | }else{ | |
306 | return new ChartDateTimeAxisX(q,presenter); |
|
308 | return new ChartDateTimeAxisX(q,presenter); | |
307 | } |
|
309 | } | |
308 |
|
310 | |||
309 | } |
|
311 | } | |
310 |
|
312 | |||
311 | void QDateTimeAxisPrivate::intializeDomain(Domain* domain) |
|
313 | void QDateTimeAxisPrivate::intializeDomain(Domain* domain) | |
312 | { |
|
314 | { | |
313 | Q_Q(QDateTimeAxis); |
|
315 | Q_Q(QDateTimeAxis); | |
314 | if(m_max == m_min) { |
|
316 | if(m_max == m_min) { | |
315 | if(m_orientation==Qt::Vertical){ |
|
317 | if(m_orientation==Qt::Vertical){ | |
316 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); |
|
318 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); | |
317 | }else{ |
|
319 | }else{ | |
318 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); |
|
320 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); | |
319 | } |
|
321 | } | |
320 | } else { |
|
322 | } else { | |
321 | if(m_orientation==Qt::Vertical){ |
|
323 | if(m_orientation==Qt::Vertical){ | |
322 | domain->setRangeY(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); |
|
324 | domain->setRangeY(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); | |
323 | }else{ |
|
325 | }else{ | |
324 | domain->setRangeX(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); |
|
326 | domain->setRangeX(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); | |
325 | } |
|
327 | } | |
326 | } |
|
328 | } | |
327 | } |
|
329 | } | |
328 |
|
330 | |||
329 | #include "moc_qdatetimeaxis.cpp" |
|
331 | #include "moc_qdatetimeaxis.cpp" | |
330 | #include "moc_qdatetimeaxis_p.cpp" |
|
332 | #include "moc_qdatetimeaxis_p.cpp" | |
331 |
|
333 | |||
332 | QTCOMMERCIALCHART_END_NAMESPACE |
|
334 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,317 +1,313 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "../qabstractaxis/tst_qabstractaxis.h" |
|
21 | #include "../qabstractaxis/tst_qabstractaxis.h" | |
22 | #include <qdatetimeaxis.h> |
|
22 | #include <qdatetimeaxis.h> | |
23 | #include <qlineseries.h> |
|
23 | #include <qlineseries.h> | |
24 |
|
24 | |||
25 | class tst_QDateTimeAxis : public QObject//: public tst_QAbstractAxis |
|
25 | class tst_QDateTimeAxis : public QObject//: public tst_QAbstractAxis | |
26 | { |
|
26 | { | |
27 | Q_OBJECT |
|
27 | Q_OBJECT | |
28 |
|
28 | |||
29 | public slots: |
|
29 | public slots: | |
30 | void initTestCase(); |
|
30 | void initTestCase(); | |
31 | void cleanupTestCase(); |
|
31 | void cleanupTestCase(); | |
32 | void init(); |
|
32 | void init(); | |
33 | void cleanup(); |
|
33 | void cleanup(); | |
34 |
|
34 | |||
35 | private slots: |
|
35 | private slots: | |
36 | void qdatetimeaxis_data(); |
|
36 | void qdatetimeaxis_data(); | |
37 | void qdatetimeaxis(); |
|
37 | void qdatetimeaxis(); | |
38 |
|
38 | |||
39 | void max_raw_data(); |
|
39 | void max_raw_data(); | |
40 | void max_raw(); |
|
40 | void max_raw(); | |
41 | void max_data(); |
|
41 | void max_data(); | |
42 | void max(); |
|
42 | void max(); | |
43 |
|
|
43 | void max_animation_data(); | |
44 |
|
|
44 | void max_animation(); | |
45 | void min_raw_data(); |
|
45 | void min_raw_data(); | |
46 | void min_raw(); |
|
46 | void min_raw(); | |
47 | void min_data(); |
|
47 | void min_data(); | |
48 | void min(); |
|
48 | void min(); | |
49 |
|
|
49 | void min_animation_data(); | |
50 |
|
|
50 | void min_animation(); | |
51 | void range_raw_data(); |
|
51 | void range_raw_data(); | |
52 | void range_raw(); |
|
52 | void range_raw(); | |
53 | void range_data(); |
|
53 | void range_data(); | |
54 | void range(); |
|
54 | void range(); | |
55 |
|
|
55 | void range_animation_data(); | |
56 |
|
|
56 | void range_animation(); | |
57 |
|
57 | |||
58 | private: |
|
58 | private: | |
59 | QDateTimeAxis *m_dateTimeAxisX; |
|
59 | QDateTimeAxis *m_dateTimeAxisX; | |
60 | QDateTimeAxis *m_dateTimeAxisY; |
|
60 | QDateTimeAxis *m_dateTimeAxisY; | |
61 | QLineSeries* m_series; |
|
61 | QLineSeries* m_series; | |
62 | QChartView* m_view; |
|
62 | QChartView* m_view; | |
63 | QChart* m_chart; |
|
63 | QChart* m_chart; | |
64 | }; |
|
64 | }; | |
65 |
|
65 | |||
66 | void tst_QDateTimeAxis::initTestCase() |
|
66 | void tst_QDateTimeAxis::initTestCase() | |
67 | { |
|
67 | { | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void tst_QDateTimeAxis::cleanupTestCase() |
|
70 | void tst_QDateTimeAxis::cleanupTestCase() | |
71 | { |
|
71 | { | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void tst_QDateTimeAxis::init() |
|
74 | void tst_QDateTimeAxis::init() | |
75 | { |
|
75 | { | |
76 | m_dateTimeAxisX = new QDateTimeAxis(); |
|
76 | m_dateTimeAxisX = new QDateTimeAxis(); | |
77 | m_dateTimeAxisY = new QDateTimeAxis(); |
|
77 | m_dateTimeAxisY = new QDateTimeAxis(); | |
78 | m_series = new QLineSeries(); |
|
78 | m_series = new QLineSeries(); | |
79 | *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100); |
|
79 | *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100); | |
80 | // tst_QAbstractAxis::init(m_datetimeaxis, m_series); |
|
80 | // tst_QAbstractAxis::init(m_datetimeaxis, m_series); | |
81 |
|
81 | |||
82 | m_view = new QChartView(new QChart()); |
|
82 | m_view = new QChartView(new QChart()); | |
83 | m_chart = m_view->chart(); |
|
83 | m_chart = m_view->chart(); | |
84 | m_chart->addSeries(m_series); |
|
84 | m_chart->addSeries(m_series); | |
85 | m_chart->setAxisY(m_dateTimeAxisY, m_series); |
|
85 | m_chart->setAxisY(m_dateTimeAxisY, m_series); | |
86 | m_chart->setAxisX(m_dateTimeAxisX, m_series); |
|
86 | m_chart->setAxisX(m_dateTimeAxisX, m_series); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void tst_QDateTimeAxis::cleanup() |
|
89 | void tst_QDateTimeAxis::cleanup() | |
90 | { |
|
90 | { | |
91 | delete m_series; |
|
91 | delete m_series; | |
92 | delete m_dateTimeAxisX; |
|
92 | delete m_dateTimeAxisX; | |
93 | delete m_dateTimeAxisY; |
|
93 | delete m_dateTimeAxisY; | |
94 | m_series = 0; |
|
94 | m_series = 0; | |
95 | m_dateTimeAxisX = 0; |
|
95 | m_dateTimeAxisX = 0; | |
96 | m_dateTimeAxisY = 0; |
|
96 | m_dateTimeAxisY = 0; | |
97 | delete m_view; |
|
97 | delete m_view; | |
98 | m_view = 0; |
|
98 | m_view = 0; | |
99 | m_chart = 0; |
|
99 | m_chart = 0; | |
100 | // tst_QAbstractAxis::cleanup(); |
|
100 | // tst_QAbstractAxis::cleanup(); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | void tst_QDateTimeAxis::qdatetimeaxis_data() |
|
103 | void tst_QDateTimeAxis::qdatetimeaxis_data() | |
104 | { |
|
104 | { | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void tst_QDateTimeAxis::qdatetimeaxis() |
|
107 | void tst_QDateTimeAxis::qdatetimeaxis() | |
108 | { |
|
108 | { | |
109 | // qabstractaxis(); |
|
109 | // qabstractaxis(); | |
110 |
|
||||
111 | // QVERIFY(m_datetimeaxis->max().toMSecsSinceEpoch() == 0); |
|
|||
112 | // QVERIFY(m_datetimeaxis->min().toMSecsSinceEpoch() == 0); |
|
|||
113 | QCOMPARE(m_dateTimeAxisX->type(), QAbstractAxis::AxisTypeDateTime); |
|
110 | QCOMPARE(m_dateTimeAxisX->type(), QAbstractAxis::AxisTypeDateTime); | |
114 |
|
111 | |||
115 | m_view->show(); |
|
112 | m_view->show(); | |
116 | QTest::qWaitForWindowShown(m_view); |
|
113 | QTest::qWaitForWindowShown(m_view); | |
117 |
|
114 | |||
118 | QVERIFY(m_dateTimeAxisX->max().toMSecsSinceEpoch() != 0); |
|
115 | QVERIFY(m_dateTimeAxisX->max().toMSecsSinceEpoch() != 0); | |
119 | QVERIFY(m_dateTimeAxisX->min().toMSecsSinceEpoch() != 0); |
|
116 | QVERIFY(m_dateTimeAxisX->min().toMSecsSinceEpoch() != 0); | |
120 | } |
|
117 | } | |
121 |
|
118 | |||
122 | void tst_QDateTimeAxis::max_raw_data() |
|
119 | void tst_QDateTimeAxis::max_raw_data() | |
123 | { |
|
120 | { | |
124 | QTest::addColumn<QDateTime>("max"); |
|
121 | QTest::addColumn<QDateTime>("max"); | |
125 | QTest::addColumn<bool>("valid"); |
|
122 | QTest::addColumn<bool>("valid"); | |
126 | QDateTime dateTime; |
|
123 | QDateTime dateTime; | |
127 | dateTime.setDate(QDate(2012, 7, 19)); |
|
124 | dateTime.setDate(QDate(2012, 7, 19)); | |
128 | QTest::newRow("19.7.2012 - Valid") << dateTime << true; |
|
125 | QTest::newRow("19.7.2012 - Valid") << dateTime << true; | |
129 | dateTime.setDate(QDate(2012, 17, 32)); |
|
126 | dateTime.setDate(QDate(2012, 17, 32)); | |
130 | QTest::newRow("32.17.2012 - Invalid") << dateTime << false; |
|
127 | QTest::newRow("32.17.2012 - Invalid") << dateTime << false; | |
131 | } |
|
128 | } | |
132 |
|
129 | |||
133 | void tst_QDateTimeAxis::max_raw() |
|
130 | void tst_QDateTimeAxis::max_raw() | |
134 | { |
|
131 | { | |
135 | QFETCH(QDateTime, max); |
|
132 | QFETCH(QDateTime, max); | |
136 | QFETCH(bool, valid); |
|
133 | QFETCH(bool, valid); | |
137 |
|
134 | |||
138 | QSignalSpy spy0(m_dateTimeAxisX, SIGNAL(maxChanged(QDateTime))); |
|
135 | QSignalSpy spy0(m_dateTimeAxisX, SIGNAL(maxChanged(QDateTime))); | |
139 | QSignalSpy spy1(m_dateTimeAxisX, SIGNAL(minChanged(QDateTime))); |
|
136 | QSignalSpy spy1(m_dateTimeAxisX, SIGNAL(minChanged(QDateTime))); | |
140 | QSignalSpy spy2(m_dateTimeAxisX, SIGNAL(rangeChanged(QDateTime, QDateTime))); |
|
137 | QSignalSpy spy2(m_dateTimeAxisX, SIGNAL(rangeChanged(QDateTime, QDateTime))); | |
141 |
|
138 | |||
142 | m_dateTimeAxisX->setMax(max); |
|
139 | m_dateTimeAxisX->setMax(max); | |
143 |
|
140 | |||
144 |
|
||||
145 | if (valid) { |
|
141 | if (valid) { | |
146 | QVERIFY2(m_dateTimeAxisX->max() == max, "Not equal"); |
|
142 | QVERIFY2(m_dateTimeAxisX->max() == max, "Not equal"); | |
147 | QCOMPARE(spy0.count(), 1); |
|
143 | QCOMPARE(spy0.count(), 1); | |
148 | QCOMPARE(spy1.count(), 0); |
|
144 | QCOMPARE(spy1.count(), 0); | |
149 | QCOMPARE(spy2.count(), 1); |
|
145 | QCOMPARE(spy2.count(), 1); | |
150 | } else { |
|
146 | } else { | |
151 | QVERIFY2(m_dateTimeAxisX->max() != max, "Date is invalid and should not be set"); |
|
147 | QVERIFY2(m_dateTimeAxisX->max() != max, "Date is invalid and should not be set"); | |
152 | QCOMPARE(spy0.count(), 0); |
|
148 | QCOMPARE(spy0.count(), 0); | |
153 | QCOMPARE(spy1.count(), 0); |
|
149 | QCOMPARE(spy1.count(), 0); | |
154 | QCOMPARE(spy2.count(), 0); |
|
150 | QCOMPARE(spy2.count(), 0); | |
155 | } |
|
151 | } | |
156 | } |
|
152 | } | |
157 |
|
153 | |||
158 | void tst_QDateTimeAxis::max_data() |
|
154 | void tst_QDateTimeAxis::max_data() | |
159 | { |
|
155 | { | |
160 | max_raw_data(); |
|
156 | max_raw_data(); | |
161 | } |
|
157 | } | |
162 |
|
158 | |||
163 | void tst_QDateTimeAxis::max() |
|
159 | void tst_QDateTimeAxis::max() | |
164 | { |
|
160 | { | |
165 | m_chart->setAxisX(m_dateTimeAxisX, m_series); |
|
161 | m_chart->setAxisX(m_dateTimeAxisX, m_series); | |
166 | m_view->show(); |
|
162 | m_view->show(); | |
167 | QTest::qWaitForWindowShown(m_view); |
|
163 | QTest::qWaitForWindowShown(m_view); | |
168 | max_raw(); |
|
164 | max_raw(); | |
169 | } |
|
165 | } | |
170 |
|
166 | |||
171 |
|
|
167 | void tst_QDateTimeAxis::max_animation_data() | |
172 | //{ |
|
168 | { | |
173 |
|
|
169 | max_data(); | |
174 | //} |
|
170 | } | |
175 |
|
171 | |||
176 |
|
|
172 | void tst_QDateTimeAxis::max_animation() | |
177 | //{ |
|
173 | { | |
178 |
|
|
174 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |
179 |
|
|
175 | max(); | |
180 | //} |
|
176 | } | |
181 |
|
177 | |||
182 | void tst_QDateTimeAxis::min_raw_data() |
|
178 | void tst_QDateTimeAxis::min_raw_data() | |
183 | { |
|
179 | { | |
184 | QTest::addColumn<QDateTime>("min"); |
|
180 | QTest::addColumn<QDateTime>("min"); | |
185 | QTest::addColumn<bool>("valid"); |
|
181 | QTest::addColumn<bool>("valid"); | |
186 | QDateTime dateTime; |
|
182 | QDateTime dateTime; | |
187 | dateTime.setDate(QDate(1908, 1, 11)); |
|
183 | dateTime.setDate(QDate(1908, 1, 11)); | |
188 | QTest::newRow("11.1.1908 - Valid") << dateTime << true; // negative MSecs from Epoch |
|
184 | QTest::newRow("11.1.1908 - Valid") << dateTime << true; // negative MSecs from Epoch | |
189 | dateTime.setDate(QDate(2012, 17, 32)); |
|
185 | dateTime.setDate(QDate(2012, 17, 32)); | |
190 | QTest::newRow("32.17.2012 - Invalid") << dateTime << false; |
|
186 | QTest::newRow("32.17.2012 - Invalid") << dateTime << false; | |
191 | } |
|
187 | } | |
192 |
|
188 | |||
193 | void tst_QDateTimeAxis::min_raw() |
|
189 | void tst_QDateTimeAxis::min_raw() | |
194 | { |
|
190 | { | |
195 | QFETCH(QDateTime, min); |
|
191 | QFETCH(QDateTime, min); | |
196 | QFETCH(bool, valid); |
|
192 | QFETCH(bool, valid); | |
197 |
|
193 | |||
198 | QSignalSpy spy0(m_dateTimeAxisX, SIGNAL(maxChanged(QDateTime))); |
|
194 | QSignalSpy spy0(m_dateTimeAxisX, SIGNAL(maxChanged(QDateTime))); | |
199 | QSignalSpy spy1(m_dateTimeAxisX, SIGNAL(minChanged(QDateTime))); |
|
195 | QSignalSpy spy1(m_dateTimeAxisX, SIGNAL(minChanged(QDateTime))); | |
200 | QSignalSpy spy2(m_dateTimeAxisX, SIGNAL(rangeChanged(QDateTime, QDateTime))); |
|
196 | QSignalSpy spy2(m_dateTimeAxisX, SIGNAL(rangeChanged(QDateTime, QDateTime))); | |
201 |
|
197 | |||
202 | m_dateTimeAxisX->setMin(min); |
|
198 | m_dateTimeAxisX->setMin(min); | |
203 |
|
199 | |||
204 | if (valid) { |
|
200 | if (valid) { | |
205 | QVERIFY2(m_dateTimeAxisX->min() == min, "Not equal"); |
|
201 | QVERIFY2(m_dateTimeAxisX->min() == min, "Not equal"); | |
206 | QCOMPARE(spy0.count(), 0); |
|
202 | QCOMPARE(spy0.count(), 0); | |
207 | QCOMPARE(spy1.count(), 1); |
|
203 | QCOMPARE(spy1.count(), 1); | |
208 | QCOMPARE(spy2.count(), 1); |
|
204 | QCOMPARE(spy2.count(), 1); | |
209 | } else { |
|
205 | } else { | |
210 | QVERIFY2(m_dateTimeAxisX->min() != min, "Date is invalid and should not be set"); |
|
206 | QVERIFY2(m_dateTimeAxisX->min() != min, "Date is invalid and should not be set"); | |
211 | QCOMPARE(spy0.count(), 0); |
|
207 | QCOMPARE(spy0.count(), 0); | |
212 | QCOMPARE(spy1.count(), 0); |
|
208 | QCOMPARE(spy1.count(), 0); | |
213 | QCOMPARE(spy2.count(), 0); |
|
209 | QCOMPARE(spy2.count(), 0); | |
214 | } |
|
210 | } | |
215 | } |
|
211 | } | |
216 |
|
212 | |||
217 | void tst_QDateTimeAxis::min_data() |
|
213 | void tst_QDateTimeAxis::min_data() | |
218 | { |
|
214 | { | |
219 | min_raw_data(); |
|
215 | min_raw_data(); | |
220 | } |
|
216 | } | |
221 |
|
217 | |||
222 | void tst_QDateTimeAxis::min() |
|
218 | void tst_QDateTimeAxis::min() | |
223 | { |
|
219 | { | |
224 | m_chart->setAxisX(m_dateTimeAxisX, m_series); |
|
220 | m_chart->setAxisX(m_dateTimeAxisX, m_series); | |
225 | m_view->show(); |
|
221 | m_view->show(); | |
226 | QTest::qWaitForWindowShown(m_view); |
|
222 | QTest::qWaitForWindowShown(m_view); | |
227 | min_raw(); |
|
223 | min_raw(); | |
228 | } |
|
224 | } | |
229 |
|
225 | |||
230 |
|
|
226 | void tst_QDateTimeAxis::min_animation_data() | |
231 | //{ |
|
227 | { | |
232 |
|
|
228 | min_data(); | |
233 | //} |
|
229 | } | |
234 |
|
230 | |||
235 |
|
|
231 | void tst_QDateTimeAxis::min_animation() | |
236 | //{ |
|
232 | { | |
237 |
|
|
233 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |
238 |
|
|
234 | min(); | |
239 | //} |
|
235 | } | |
240 |
|
236 | |||
241 | void tst_QDateTimeAxis::range_raw_data() |
|
237 | void tst_QDateTimeAxis::range_raw_data() | |
242 | { |
|
238 | { | |
243 | QTest::addColumn<QDateTime>("min"); |
|
239 | QTest::addColumn<QDateTime>("min"); | |
244 | QTest::addColumn<bool>("minValid"); |
|
240 | QTest::addColumn<bool>("minValid"); | |
245 | QTest::addColumn<QDateTime>("max"); |
|
241 | QTest::addColumn<QDateTime>("max"); | |
246 | QTest::addColumn<bool>("maxValid"); |
|
242 | QTest::addColumn<bool>("maxValid"); | |
247 |
|
243 | |||
248 | QDateTime minDateTime; |
|
244 | QDateTime minDateTime; | |
249 | QDateTime maxDateTime; |
|
245 | QDateTime maxDateTime; | |
250 | minDateTime.setDate(QDate(1908, 1, 11)); |
|
246 | minDateTime.setDate(QDate(1908, 1, 11)); | |
251 | maxDateTime.setDate(QDate(1958, 11, 21)); |
|
247 | maxDateTime.setDate(QDate(1958, 11, 21)); | |
252 | QTest::newRow("11.1.1908 - min valid, 21.12.1958 - max valid") << minDateTime << true << maxDateTime << true; // negative MSecs from Epoch, min < max |
|
248 | QTest::newRow("11.1.1908 - min valid, 21.12.1958 - max valid") << minDateTime << true << maxDateTime << true; // negative MSecs from Epoch, min < max | |
253 |
|
249 | |||
254 | minDateTime.setDate(QDate(2012, 17, 32)); |
|
250 | minDateTime.setDate(QDate(2012, 17, 32)); | |
255 | QTest::newRow("32.17.2012 - min invalid, 21.12.1958 - max valid") << minDateTime << false << maxDateTime << true; |
|
251 | QTest::newRow("32.17.2012 - min invalid, 21.12.1958 - max valid") << minDateTime << false << maxDateTime << true; | |
256 |
|
252 | |||
257 | maxDateTime.setDate(QDate(2017, 0, 1)); |
|
253 | maxDateTime.setDate(QDate(2017, 0, 1)); | |
258 | QTest::newRow("32.17.2012 - min invalid, 1.0.2017 - max invalid") << minDateTime << false << maxDateTime << false; |
|
254 | QTest::newRow("32.17.2012 - min invalid, 1.0.2017 - max invalid") << minDateTime << false << maxDateTime << false; | |
259 |
|
255 | |||
260 | minDateTime.setDate(QDate(2012, 1, 1)); |
|
256 | minDateTime.setDate(QDate(2012, 1, 1)); | |
261 | QTest::newRow("1.1.2012 - min valid, 1.0.2017 - max invalid") << minDateTime << true << maxDateTime << false; |
|
257 | QTest::newRow("1.1.2012 - min valid, 1.0.2017 - max invalid") << minDateTime << true << maxDateTime << false; | |
262 |
|
258 | |||
263 | maxDateTime.setDate(QDate(2005, 2, 5)); |
|
259 | maxDateTime.setDate(QDate(2005, 2, 5)); | |
264 | QTest::newRow("1.1.2012 - min valid, 5.2.2005 - max valid") << minDateTime << true << maxDateTime << true; // min > max |
|
260 | QTest::newRow("1.1.2012 - min valid, 5.2.2005 - max valid") << minDateTime << true << maxDateTime << true; // min > max | |
265 | } |
|
261 | } | |
266 |
|
262 | |||
267 | void tst_QDateTimeAxis::range_raw() |
|
263 | void tst_QDateTimeAxis::range_raw() | |
268 | { |
|
264 | { | |
269 | QFETCH(QDateTime, min); |
|
265 | QFETCH(QDateTime, min); | |
270 | QFETCH(bool, minValid); |
|
266 | QFETCH(bool, minValid); | |
271 | QFETCH(QDateTime, max); |
|
267 | QFETCH(QDateTime, max); | |
272 | QFETCH(bool, maxValid); |
|
268 | QFETCH(bool, maxValid); | |
273 |
|
269 | |||
274 | QSignalSpy spy0(m_dateTimeAxisX, SIGNAL(maxChanged(QDateTime))); |
|
270 | QSignalSpy spy0(m_dateTimeAxisX, SIGNAL(maxChanged(QDateTime))); | |
275 | QSignalSpy spy1(m_dateTimeAxisX, SIGNAL(minChanged(QDateTime))); |
|
271 | QSignalSpy spy1(m_dateTimeAxisX, SIGNAL(minChanged(QDateTime))); | |
276 | QSignalSpy spy2(m_dateTimeAxisX, SIGNAL(rangeChanged(QDateTime, QDateTime))); |
|
272 | QSignalSpy spy2(m_dateTimeAxisX, SIGNAL(rangeChanged(QDateTime, QDateTime))); | |
277 |
|
273 | |||
278 | m_dateTimeAxisX->setRange(min, max); |
|
274 | m_dateTimeAxisX->setRange(min, max); | |
279 |
|
275 | |||
280 | if (minValid && maxValid && min < max) { |
|
276 | if (minValid && maxValid && min < max) { | |
281 | QCOMPARE(spy0.count(), 1); |
|
277 | QCOMPARE(spy0.count(), 1); | |
282 | QCOMPARE(spy1.count(), 1); |
|
278 | QCOMPARE(spy1.count(), 1); | |
283 | QCOMPARE(spy2.count(), 1); |
|
279 | QCOMPARE(spy2.count(), 1); | |
284 | } else { |
|
280 | } else { | |
285 | QCOMPARE(spy0.count(), 0); |
|
281 | QCOMPARE(spy0.count(), 0); | |
286 | QCOMPARE(spy1.count(), 0); |
|
282 | QCOMPARE(spy1.count(), 0); | |
287 | QCOMPARE(spy2.count(), 0); |
|
283 | QCOMPARE(spy2.count(), 0); | |
288 | } |
|
284 | } | |
289 | } |
|
285 | } | |
290 |
|
286 | |||
291 | void tst_QDateTimeAxis::range_data() |
|
287 | void tst_QDateTimeAxis::range_data() | |
292 | { |
|
288 | { | |
293 | range_raw_data(); |
|
289 | range_raw_data(); | |
294 | } |
|
290 | } | |
295 |
|
291 | |||
296 | void tst_QDateTimeAxis::range() |
|
292 | void tst_QDateTimeAxis::range() | |
297 | { |
|
293 | { | |
298 | m_chart->setAxisX(m_dateTimeAxisX, m_series); |
|
294 | m_chart->setAxisX(m_dateTimeAxisX, m_series); | |
299 | m_view->show(); |
|
295 | m_view->show(); | |
300 | QTest::qWaitForWindowShown(m_view); |
|
296 | QTest::qWaitForWindowShown(m_view); | |
301 | range_raw(); |
|
297 | range_raw(); | |
302 | } |
|
298 | } | |
303 |
|
299 | |||
304 |
|
|
300 | void tst_QDateTimeAxis::range_animation_data() | |
305 | //{ |
|
301 | { | |
306 |
|
|
302 | range_data(); | |
307 | //} |
|
303 | } | |
308 |
|
304 | |||
309 |
|
|
305 | void tst_QDateTimeAxis::range_animation() | |
310 | //{ |
|
306 | { | |
311 |
|
|
307 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |
312 |
|
|
308 | range(); | |
313 | //} |
|
309 | } | |
314 |
|
310 | |||
315 | QTEST_MAIN(tst_QDateTimeAxis) |
|
311 | QTEST_MAIN(tst_QDateTimeAxis) | |
316 | #include "tst_qdatetimeaxis.moc" |
|
312 | #include "tst_qdatetimeaxis.moc" | |
317 |
|
313 |
General Comments 0
You need to be logged in to leave comments.
Login now