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