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