##// END OF EJS Templates
Few axes docs fixes
Marek Rosa -
r2339:cd067eebd24b
parent child
Show More
@@ -1,364 +1,373
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 "abstractdomain_p.h"
25 #include "abstractdomain_p.h"
26 #include "qchart.h"
26 #include "qchart.h"
27 #include <float.h>
27 #include <float.h>
28 #include <cmath>
28 #include <cmath>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 /*!
31 /*!
32 \class QDateTimeAxis
32 \class QDateTimeAxis
33 \brief The QDateTimeAxis class is used for manipulating chart's axis.
33 \brief The QDateTimeAxis class is used for manipulating chart's axis.
34 \mainclass
34 \mainclass
35
35
36 The labels can be configured by setting an appropriate DateTime format.
36 The labels can be configured by setting an appropriate DateTime format.
37 QDateTimeAxis works correctly with dates from 4714 BCE to 287396 CE
37 QDateTimeAxis works correctly with dates from 4714 BCE to 287396 CE
38 There are also other limitiation related to QDateTime . Please refer to QDateTime documentation.
38 There are also other limitiation related to QDateTime . Please refer to QDateTime documentation.
39 QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
39 QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
40
40
41 NOTE: QDateTimeAxis is disabled on ARM architecture.
41 NOTE: QDateTimeAxis is disabled on ARM architecture.
42
42
43 \image api_datatime_axis.png
43 \image api_datatime_axis.png
44
44
45 QDateTimeAxis can be used with QLineSeries, QSplineSeries or QScatterSeries.
45 QDateTimeAxis can be used with QLineSeries, QSplineSeries or QScatterSeries.
46 To add a data point to the series QDateTime::toMSecsSinceEpoch() is used.
46 To add a data point to the series QDateTime::toMSecsSinceEpoch() is used.
47 \code
47 \code
48 QLineSeries *series = new QLineSeries;
48 QLineSeries *series = new QLineSeries;
49
49
50 QDateTime xValue;
50 QDateTime xValue;
51 xValue.setDate(QDate(2012, 1 , 18));
51 xValue.setDate(QDate(2012, 1 , 18));
52 xValue.setTime(QTime(9, 34));
52 xValue.setTime(QTime(9, 34));
53 qreal yValue = 12;
53 qreal yValue = 12;
54 series->append(xValue.toMSecsSinceEpoch(), yValue);
54 series->append(xValue.toMSecsSinceEpoch(), yValue);
55
55
56 xValue.setDate(QDate(2013, 5 , 11));
56 xValue.setDate(QDate(2013, 5 , 11));
57 xValue.setTime(QTime(11, 14));
57 xValue.setTime(QTime(11, 14));
58 qreal yValue = 22;
58 qreal yValue = 22;
59 series->append(xValue.toMSecsSinceEpoch(), yValue);
59 series->append(xValue.toMSecsSinceEpoch(), yValue);
60 \endcode
60 \endcode
61
61
62 Adding the series to the chart and setting up the QDateTimeAxis.
62 Adding the series to the chart and setting up the QDateTimeAxis.
63 \code
63 \code
64 QChartView *chartView = new QChartView;
64 QChartView *chartView = new QChartView;
65 chartView->chart()->addSeries(series);
65 chartView->chart()->addSeries(series);
66
66
67 // ...
67 // ...
68 QDateTimeAxis *axisX = new QDateTimeAxis;
68 QDateTimeAxis *axisX = new QDateTimeAxis;
69 axisX->setFormat("dd-MM-yyyy h:mm");
69 axisX->setFormat("dd-MM-yyyy h:mm");
70 chartView->chart()->setAxisX(axisX, series);
70 chartView->chart()->setAxisX(axisX, series);
71 \endcode
71 \endcode
72 */
72 */
73
73
74 /*!
74 /*!
75 \qmlclass DateTimeAxis QDateTimeAxis
75 \qmlclass DateTimeAxis QDateTimeAxis
76 \brief The DateTimeAxis element is used for manipulating chart's axes
76 \brief The DateTimeAxis element is used for manipulating chart's axes
77 \inherits AbstractAxis
77 \inherits AbstractAxis
78
78
79 The labels can be configured by setting an appropriate DateTime format.
79 The labels can be configured by setting an appropriate DateTime format.
80 Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored.
80 Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored.
81 DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
81 DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
82 */
82 */
83
83
84 /*!
84 /*!
85 \property QDateTimeAxis::min
85 \property QDateTimeAxis::min
86 Defines the minimum value on the axis.
86 Defines the minimum value on the axis.
87 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
87 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
88 */
88 */
89 /*!
89 /*!
90 \qmlproperty real ValuesAxis::min
90 \qmlproperty real ValuesAxis::min
91 Defines the minimum value on the axis.
91 Defines the minimum value on the axis.
92 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
92 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
93 */
93 */
94
94
95 /*!
95 /*!
96 \property QDateTimeAxis::max
96 \property QDateTimeAxis::max
97 Defines the maximum value on the axis.
97 Defines the maximum value on the axis.
98 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
98 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
99 */
99 */
100 /*!
100 /*!
101 \qmlproperty real ValuesAxis::max
101 \qmlproperty real ValuesAxis::max
102 Defines the maximum value on the axis.
102 Defines the maximum value on the axis.
103 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
103 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
104 */
104 */
105
105
106 /*!
106 /*!
107 \fn void QDateTimeAxis::minChanged(QDateTime min)
107 \fn void QDateTimeAxis::minChanged(QDateTime min)
108 Axis emits signal when \a min of axis has changed.
108 Axis emits signal when \a min of axis has changed.
109 */
109 */
110 /*!
110 /*!
111 \qmlsignal ValuesAxis::onMinChanged(QDateTime min)
111 \qmlsignal ValuesAxis::onMinChanged(QDateTime min)
112 Axis emits signal when \a min of axis has changed.
112 Axis emits signal when \a min of axis has changed.
113 */
113 */
114
114
115 /*!
115 /*!
116 \fn void QDateTimeAxis::maxChanged(QDateTime max)
116 \fn void QDateTimeAxis::maxChanged(QDateTime max)
117 Axis emits signal when \a max of axis has changed.
117 Axis emits signal when \a max of axis has changed.
118 */
118 */
119 /*!
119 /*!
120 \qmlsignal ValuesAxis::onMaxChanged(QDateTime max)
120 \qmlsignal ValuesAxis::onMaxChanged(QDateTime max)
121 Axis emits signal when \a max of axis has changed.
121 Axis emits signal when \a max of axis has changed.
122 */
122 */
123
123
124 /*!
124 /*!
125 \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max)
125 \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max)
126 Axis emits signal when \a min or \a max of axis has changed.
126 Axis emits signal when \a min or \a max of axis has changed.
127 */
127 */
128
128
129 /*!
129 /*!
130 \property QDateTimeAxis::tickCount
130 \property QDateTimeAxis::tickCount
131 The number of tick marks for the axis.
131 The number of tick marks for the axis.
132 */
132 */
133
133
134 /*!
134 /*!
135 \qmlproperty int DateTimeAxis::tickCount
135 \qmlproperty int DateTimeAxis::tickCount
136 The number of tick marks for the axis.
136 The number of tick marks for the axis.
137 */
137 */
138
138
139 /*!
139 /*!
140 \property QDateTimeAxis::format
140 \property QDateTimeAxis::format
141 The format string that is used when creating label for the axis out of a QDateTime object.
141 The format string that is used when creating label for the axis out of a QDateTime object.
142 Check QDateTime documentation for information on how the string should be defined.
142 Check QDateTime documentation for information on how the string should be defined.
143 */
143 */
144 /*!
144 /*!
145 \qmlproperty string DateTimeAxis::format
145 \qmlproperty string DateTimeAxis::format
146 The format string that is used when creating label for the axis out of a QDateTime object.
146 The format string that is used when creating label for the axis out of a QDateTime object.
147 Check QDateTime documentation for information on how the string should be defined.
147 Check QDateTime documentation for information on how the string should be defined.
148 */
148 */
149
149
150 /*!
150 /*!
151 \fn void QDateTimeAxis::tickCountChanged(int tickCount)
152 Axis emits signal when \a tickCount number on axis have changed.
153 */
154 /*!
155 \qmlsignal DateTimeAxis::tickCountChanged(int tickCount)
156 Axis emits signal when \a tickCount number on axis have changed.
157 */
158
159 /*!
151 \fn void QDateTimeAxis::formatChanged(QString format)
160 \fn void QDateTimeAxis::formatChanged(QString format)
152 Axis emits signal when \a format of the axis has changed.
161 Axis emits signal when \a format of the axis has changed.
153 */
162 */
154 /*!
163 /*!
155 \qmlsignal DateTimeAxis::onFormatChanged(string format)
164 \qmlsignal DateTimeAxis::onFormatChanged(string format)
156 Axis emits signal when \a format of the axis has changed.
165 Axis emits signal when \a format of the axis has changed.
157 */
166 */
158
167
159 /*!
168 /*!
160 Constructs an axis object which is a child of \a parent.
169 Constructs an axis object which is a child of \a parent.
161 */
170 */
162 QDateTimeAxis::QDateTimeAxis(QObject *parent) :
171 QDateTimeAxis::QDateTimeAxis(QObject *parent) :
163 QAbstractAxis(*new QDateTimeAxisPrivate(this), parent)
172 QAbstractAxis(*new QDateTimeAxisPrivate(this), parent)
164 {
173 {
165
174
166 }
175 }
167
176
168 /*!
177 /*!
169 \internal
178 \internal
170 */
179 */
171 QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent)
180 QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent)
172 {
181 {
173
182
174 }
183 }
175
184
176 /*!
185 /*!
177 Destroys the object
186 Destroys the object
178 */
187 */
179 QDateTimeAxis::~QDateTimeAxis()
188 QDateTimeAxis::~QDateTimeAxis()
180 {
189 {
181 Q_D(QDateTimeAxis);
190 Q_D(QDateTimeAxis);
182 if (d->m_chart)
191 if (d->m_chart)
183 d->m_chart->removeAxis(this);
192 d->m_chart->removeAxis(this);
184 }
193 }
185
194
186 void QDateTimeAxis::setMin(QDateTime min)
195 void QDateTimeAxis::setMin(QDateTime min)
187 {
196 {
188 Q_D(QDateTimeAxis);
197 Q_D(QDateTimeAxis);
189 if (min.isValid())
198 if (min.isValid())
190 d->setRange(min.toMSecsSinceEpoch(), qMax(d->m_max, qreal(min.toMSecsSinceEpoch())));
199 d->setRange(min.toMSecsSinceEpoch(), qMax(d->m_max, qreal(min.toMSecsSinceEpoch())));
191 }
200 }
192
201
193 QDateTime QDateTimeAxis::min() const
202 QDateTime QDateTimeAxis::min() const
194 {
203 {
195 Q_D(const QDateTimeAxis);
204 Q_D(const QDateTimeAxis);
196 return QDateTime::fromMSecsSinceEpoch(d->m_min);
205 return QDateTime::fromMSecsSinceEpoch(d->m_min);
197 }
206 }
198
207
199 void QDateTimeAxis::setMax(QDateTime max)
208 void QDateTimeAxis::setMax(QDateTime max)
200 {
209 {
201 Q_D(QDateTimeAxis);
210 Q_D(QDateTimeAxis);
202 if (max.isValid())
211 if (max.isValid())
203 d->setRange(qMin(d->m_min, qreal(max.toMSecsSinceEpoch())), max.toMSecsSinceEpoch());
212 d->setRange(qMin(d->m_min, qreal(max.toMSecsSinceEpoch())), max.toMSecsSinceEpoch());
204 }
213 }
205
214
206 QDateTime QDateTimeAxis::max() const
215 QDateTime QDateTimeAxis::max() const
207 {
216 {
208 Q_D(const QDateTimeAxis);
217 Q_D(const QDateTimeAxis);
209 return QDateTime::fromMSecsSinceEpoch(d->m_max);
218 return QDateTime::fromMSecsSinceEpoch(d->m_max);
210 }
219 }
211
220
212 /*!
221 /*!
213 Sets range from \a min to \a max on the axis.
222 Sets range from \a min to \a max on the axis.
214 If min is greater than max then this function returns without making any changes.
223 If min is greater than max then this function returns without making any changes.
215 */
224 */
216 void QDateTimeAxis::setRange(QDateTime min, QDateTime max)
225 void QDateTimeAxis::setRange(QDateTime min, QDateTime max)
217 {
226 {
218 Q_D(QDateTimeAxis);
227 Q_D(QDateTimeAxis);
219 if (!min.isValid() || !max.isValid() || min > max)
228 if (!min.isValid() || !max.isValid() || min > max)
220 return;
229 return;
221
230
222 d->setRange(min.toMSecsSinceEpoch(),max.toMSecsSinceEpoch());
231 d->setRange(min.toMSecsSinceEpoch(),max.toMSecsSinceEpoch());
223 }
232 }
224
233
225 void QDateTimeAxis::setFormat(QString format)
234 void QDateTimeAxis::setFormat(QString format)
226 {
235 {
227 Q_D(QDateTimeAxis);
236 Q_D(QDateTimeAxis);
228 if (d->m_format != format) {
237 if (d->m_format != format) {
229 d->m_format = format;
238 d->m_format = format;
230 emit formatChanged(format);
239 emit formatChanged(format);
231 }
240 }
232 }
241 }
233
242
234 QString QDateTimeAxis::format() const
243 QString QDateTimeAxis::format() const
235 {
244 {
236 Q_D(const QDateTimeAxis);
245 Q_D(const QDateTimeAxis);
237 return d->m_format;
246 return d->m_format;
238 }
247 }
239
248
240 /*!
249 /*!
241 Sets \a count for ticks on the axis.
250 Sets \a count for ticks on the axis.
242 */
251 */
243 void QDateTimeAxis::setTickCount(int count)
252 void QDateTimeAxis::setTickCount(int count)
244 {
253 {
245 Q_D(QDateTimeAxis);
254 Q_D(QDateTimeAxis);
246 if (d->m_tickCount != count && count >= 2) {
255 if (d->m_tickCount != count && count >= 2) {
247 d->m_tickCount = count;
256 d->m_tickCount = count;
248 emit tickCountChanged(count);
257 emit tickCountChanged(count);
249 }
258 }
250 }
259 }
251
260
252 /*!
261 /*!
253 \fn int QDateTimeAxis::tickCount() const
262 \fn int QDateTimeAxis::tickCount() const
254 Return number of ticks on the axis
263 Return number of ticks on the axis
255 */
264 */
256 int QDateTimeAxis::tickCount() const
265 int QDateTimeAxis::tickCount() const
257 {
266 {
258 Q_D(const QDateTimeAxis);
267 Q_D(const QDateTimeAxis);
259 return d->m_tickCount;
268 return d->m_tickCount;
260 }
269 }
261
270
262 /*!
271 /*!
263 Returns the type of the axis
272 Returns the type of the axis
264 */
273 */
265 QAbstractAxis::AxisType QDateTimeAxis::type() const
274 QAbstractAxis::AxisType QDateTimeAxis::type() const
266 {
275 {
267 return AxisTypeDateTime;
276 return AxisTypeDateTime;
268 }
277 }
269
278
270 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
279 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
271
280
272 QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis *q)
281 QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis *q)
273 : QAbstractAxisPrivate(q),
282 : QAbstractAxisPrivate(q),
274 m_min(0),
283 m_min(0),
275 m_max(0),
284 m_max(0),
276 m_tickCount(5)
285 m_tickCount(5)
277 {
286 {
278 m_format = "dd-MM-yyyy\nh:mm";
287 m_format = "dd-MM-yyyy\nh:mm";
279 }
288 }
280
289
281 QDateTimeAxisPrivate::~QDateTimeAxisPrivate()
290 QDateTimeAxisPrivate::~QDateTimeAxisPrivate()
282 {
291 {
283
292
284 }
293 }
285
294
286 void QDateTimeAxisPrivate::setRange(qreal min,qreal max)
295 void QDateTimeAxisPrivate::setRange(qreal min,qreal max)
287 {
296 {
288 Q_Q(QDateTimeAxis);
297 Q_Q(QDateTimeAxis);
289
298
290 bool changed = false;
299 bool changed = false;
291
300
292 if (m_min != min) {
301 if (m_min != min) {
293 m_min = min;
302 m_min = min;
294 changed = true;
303 changed = true;
295 emit q->minChanged(QDateTime::fromMSecsSinceEpoch(min));
304 emit q->minChanged(QDateTime::fromMSecsSinceEpoch(min));
296 }
305 }
297
306
298 if (m_max != max) {
307 if (m_max != max) {
299 m_max = max;
308 m_max = max;
300 changed = true;
309 changed = true;
301 emit q->maxChanged(QDateTime::fromMSecsSinceEpoch(max));
310 emit q->maxChanged(QDateTime::fromMSecsSinceEpoch(max));
302 }
311 }
303
312
304 if (changed) {
313 if (changed) {
305 emit q->rangeChanged(QDateTime::fromMSecsSinceEpoch(min), QDateTime::fromMSecsSinceEpoch(max));
314 emit q->rangeChanged(QDateTime::fromMSecsSinceEpoch(min), QDateTime::fromMSecsSinceEpoch(max));
306 emit rangeChanged(m_min,m_max);
315 emit rangeChanged(m_min,m_max);
307 }
316 }
308 }
317 }
309
318
310
319
311 void QDateTimeAxisPrivate::setMin(const QVariant &min)
320 void QDateTimeAxisPrivate::setMin(const QVariant &min)
312 {
321 {
313 Q_Q(QDateTimeAxis);
322 Q_Q(QDateTimeAxis);
314 if (min.canConvert(QVariant::DateTime))
323 if (min.canConvert(QVariant::DateTime))
315 q->setMin(min.toDateTime());
324 q->setMin(min.toDateTime());
316 }
325 }
317
326
318 void QDateTimeAxisPrivate::setMax(const QVariant &max)
327 void QDateTimeAxisPrivate::setMax(const QVariant &max)
319 {
328 {
320
329
321 Q_Q(QDateTimeAxis);
330 Q_Q(QDateTimeAxis);
322 if (max.canConvert(QVariant::DateTime))
331 if (max.canConvert(QVariant::DateTime))
323 q->setMax(max.toDateTime());
332 q->setMax(max.toDateTime());
324 }
333 }
325
334
326 void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max)
335 void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max)
327 {
336 {
328 Q_Q(QDateTimeAxis);
337 Q_Q(QDateTimeAxis);
329 if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime))
338 if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime))
330 q->setRange(min.toDateTime(), max.toDateTime());
339 q->setRange(min.toDateTime(), max.toDateTime());
331 }
340 }
332
341
333 void QDateTimeAxisPrivate::initializeGraphics(QGraphicsItem* parent)
342 void QDateTimeAxisPrivate::initializeGraphics(QGraphicsItem* parent)
334 {
343 {
335 Q_Q(QDateTimeAxis);
344 Q_Q(QDateTimeAxis);
336 ChartAxis* axis(0);
345 ChartAxis* axis(0);
337 if (orientation() == Qt::Vertical)
346 if (orientation() == Qt::Vertical)
338 axis = new ChartDateTimeAxisY(q,parent);
347 axis = new ChartDateTimeAxisY(q,parent);
339 if (orientation() == Qt::Horizontal)
348 if (orientation() == Qt::Horizontal)
340 axis = new ChartDateTimeAxisX(q,parent);
349 axis = new ChartDateTimeAxisX(q,parent);
341
350
342 m_item.reset(axis);
351 m_item.reset(axis);
343 QAbstractAxisPrivate::initializeGraphics(parent);
352 QAbstractAxisPrivate::initializeGraphics(parent);
344 }
353 }
345
354
346 void QDateTimeAxisPrivate::initializeDomain(AbstractDomain *domain)
355 void QDateTimeAxisPrivate::initializeDomain(AbstractDomain *domain)
347 {
356 {
348 if (m_max == m_min) {
357 if (m_max == m_min) {
349 if (orientation() == Qt::Vertical)
358 if (orientation() == Qt::Vertical)
350 setRange(domain->minY(), domain->maxY());
359 setRange(domain->minY(), domain->maxY());
351 else
360 else
352 setRange(domain->minX(), domain->maxX());
361 setRange(domain->minX(), domain->maxX());
353 } else {
362 } else {
354 if (orientation() == Qt::Vertical)
363 if (orientation() == Qt::Vertical)
355 domain->setRangeY(m_min, m_max);
364 domain->setRangeY(m_min, m_max);
356 else
365 else
357 domain->setRangeX(m_min, m_max);
366 domain->setRangeX(m_min, m_max);
358 }
367 }
359 }
368 }
360
369
361 #include "moc_qdatetimeaxis.cpp"
370 #include "moc_qdatetimeaxis.cpp"
362 #include "moc_qdatetimeaxis_p.cpp"
371 #include "moc_qdatetimeaxis_p.cpp"
363
372
364 QTCOMMERCIALCHART_END_NAMESPACE
373 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,869 +1,870
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.h"
21 #include "qabstractaxis.h"
22 #include "qabstractaxis_p.h"
22 #include "qabstractaxis_p.h"
23 #include "chartdataset_p.h"
23 #include "chartdataset_p.h"
24 #include "charttheme_p.h"
24 #include "charttheme_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QAbstractAxis
29 \class QAbstractAxis
30 \brief The QAbstractAxis class is used for manipulating chart's axis.
30 \brief The QAbstractAxis class is used for manipulating chart's axis.
31 \mainclass
31 \mainclass
32
32
33 There is only one x Axis visible at the time, however there can be multiple y axes.
33 There is only one x Axis visible at the time, however there can be multiple y axes.
34 Each chart series can be bound to exactly one Y axis and the shared common X axis.
34 Each chart series can be bound to exactly one Y axis and the shared common X axis.
35 Axis can be setup to show axis line with tick marks, grid lines and shades.
35 Axis can be setup to show axis line with tick marks, grid lines and shades.
36 */
36 */
37
37
38 /*!
38 /*!
39 \qmlclass AbstractAxis QAbstractAxis
39 \qmlclass AbstractAxis QAbstractAxis
40 \brief The Axis element is used for manipulating chart's axes
40 \brief The Axis element is used for manipulating chart's axes
41
41
42 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
42 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
43 Each chart series can be bound to exactly one Y axis and the shared common X axis.
43 Each chart series can be bound to exactly one Y axis and the shared common X axis.
44 Axis can be setup to show axis line with tick marks, grid lines and shades.
44 Axis can be setup to show axis line with tick marks, grid lines and shades.
45
45
46 To access Axes you can use ChartView API. For example:
46 To access Axes you can use ChartView API. For example:
47 \code
47 \code
48 ChartView {
48 ChartView {
49 axisX.min: 0
49 axisX.min: 0
50 axisX.max: 3
50 axisX.max: 3
51 axisX.ticksCount: 4
51 axisX.ticksCount: 4
52 axisY.min: 0
52 axisY.min: 0
53 axisY.max: 4
53 axisY.max: 4
54 // Add a few series...
54 // Add a few series...
55 }
55 }
56 \endcode
56 \endcode
57 */
57 */
58
58
59 /*!
59 /*!
60 \enum QAbstractAxis::AxisType
60 \enum QAbstractAxis::AxisType
61
61
62 The type of the series object.
62 The type of the series object.
63
63
64 \value AxisTypeNoAxis
64 \value AxisTypeNoAxis
65 \value AxisTypeValue
65 \value AxisTypeValue
66 \value AxisTypeBarCategory
66 \value AxisTypeBarCategory
67 \value AxisTypeCategory
67 \value AxisTypeCategory
68 \value AxisTypeDateTime
68 \value AxisTypeDateTime
69 \value AxisTypeLogValue
69 */
70 */
70
71
71 /*!
72 /*!
72 *\fn void QAbstractAxis::type() const
73 *\fn void QAbstractAxis::type() const
73 Returns the type of the axis
74 Returns the type of the axis
74 */
75 */
75
76
76 /*!
77 /*!
77 \property QAbstractAxis::lineVisible
78 \property QAbstractAxis::lineVisible
78 The visibility of the axis line
79 The visibility of the axis line
79 */
80 */
80 /*!
81 /*!
81 \qmlproperty bool AbstractAxis::lineVisible
82 \qmlproperty bool AbstractAxis::lineVisible
82 The visibility of the axis line
83 The visibility of the axis line
83 */
84 */
84
85
85 /*!
86 /*!
86 \property QAbstractAxis::labelsVisible
87 \property QAbstractAxis::labelsVisible
87 Defines if axis labels are visible.
88 Defines if axis labels are visible.
88 */
89 */
89 /*!
90 /*!
90 \qmlproperty bool AbstractAxis::labelsVisible
91 \qmlproperty bool AbstractAxis::labelsVisible
91 Defines if axis labels are visible.
92 Defines if axis labels are visible.
92 */
93 */
93
94
94 /*!
95 /*!
95 \property QAbstractAxis::visible
96 \property QAbstractAxis::visible
96 The visibility of the axis.
97 The visibility of the axis.
97 */
98 */
98 /*!
99 /*!
99 \qmlproperty bool AbstractAxis::visible
100 \qmlproperty bool AbstractAxis::visible
100 The visibility of the axis.
101 The visibility of the axis.
101 */
102 */
102
103
103 /*!
104 /*!
104 \property QAbstractAxis::gridVisible
105 \property QAbstractAxis::gridVisible
105 The visibility of the grid lines.
106 The visibility of the grid lines.
106 */
107 */
107 /*!
108 /*!
108 \qmlproperty bool AbstractAxis::gridVisible
109 \qmlproperty bool AbstractAxis::gridVisible
109 The visibility of the grid lines.
110 The visibility of the grid lines.
110 */
111 */
111
112
112 /*!
113 /*!
113 \property QAbstractAxis::color
114 \property QAbstractAxis::color
114 The color of the axis and ticks.
115 The color of the axis and ticks.
115 */
116 */
116 /*!
117 /*!
117 \qmlproperty color AbstractAxis::color
118 \qmlproperty color AbstractAxis::color
118 The color of the axis and ticks.
119 The color of the axis and ticks.
119 */
120 */
120
121
121 /*!
122 /*!
122 \property QAbstractAxis::labelsFont
123 \property QAbstractAxis::labelsFont
123 The font of the axis labels.
124 The font of the axis labels.
124 */
125 */
125
126
126 /*!
127 /*!
127 \qmlproperty Font AbstractAxis::labelsFont
128 \qmlproperty Font AbstractAxis::labelsFont
128 The font of the axis labels.
129 The font of the axis labels.
129
130
130 See the \l {Font} {QML Font Element} for detailed documentation.
131 See the \l {Font} {QML Font Element} for detailed documentation.
131 */
132 */
132
133
133 /*!
134 /*!
134 \property QAbstractAxis::labelsColor
135 \property QAbstractAxis::labelsColor
135 The color of the axis labels.
136 The color of the axis labels.
136 */
137 */
137 /*!
138 /*!
138 \qmlproperty color AbstractAxis::labelsColor
139 \qmlproperty color AbstractAxis::labelsColor
139 The color of the axis labels.
140 The color of the axis labels.
140 */
141 */
141
142
142 /*!
143 /*!
143 \property QAbstractAxis::labelsAngle
144 \property QAbstractAxis::labelsAngle
144 The angle of the axis labels in degrees.
145 The angle of the axis labels in degrees.
145 */
146 */
146 /*!
147 /*!
147 \qmlproperty int AbstractAxis::labelsAngle
148 \qmlproperty int AbstractAxis::labelsAngle
148 The angle of the axis labels in degrees.
149 The angle of the axis labels in degrees.
149 */
150 */
150
151
151 /*!
152 /*!
152 \property QAbstractAxis::shadesVisible
153 \property QAbstractAxis::shadesVisible
153 The visibility of the axis shades.
154 The visibility of the axis shades.
154 */
155 */
155 /*!
156 /*!
156 \qmlproperty bool AbstractAxis::shadesVisible
157 \qmlproperty bool AbstractAxis::shadesVisible
157 The visibility of the axis shades.
158 The visibility of the axis shades.
158 */
159 */
159
160
160 /*!
161 /*!
161 \property QAbstractAxis::shadesColor
162 \property QAbstractAxis::shadesColor
162 The fill (brush) color of the axis shades.
163 The fill (brush) color of the axis shades.
163 */
164 */
164 /*!
165 /*!
165 \qmlproperty color AbstractAxis::shadesColor
166 \qmlproperty color AbstractAxis::shadesColor
166 The fill (brush) color of the axis shades.
167 The fill (brush) color of the axis shades.
167 */
168 */
168
169
169 /*!
170 /*!
170 \property QAbstractAxis::shadesBorderColor
171 \property QAbstractAxis::shadesBorderColor
171 The border (pen) color of the axis shades.
172 The border (pen) color of the axis shades.
172 */
173 */
173 /*!
174 /*!
174 \qmlproperty color AbstractAxis::shadesBorderColor
175 \qmlproperty color AbstractAxis::shadesBorderColor
175 The border (pen) color of the axis shades.
176 The border (pen) color of the axis shades.
176 */
177 */
177
178
178 /*!
179 /*!
179 \property QAbstractAxis::titleVisible
180 \property QAbstractAxis::titleVisible
180 The visibility of the axis title. By default the value is true.
181 The visibility of the axis title. By default the value is true.
181 */
182 */
182 /*!
183 /*!
183 \qmlproperty bool AbstractAxis::titleVisible
184 \qmlproperty bool AbstractAxis::titleVisible
184 The visibility of the axis title. By default the value is true.
185 The visibility of the axis title. By default the value is true.
185 */
186 */
186
187
187 /*!
188 /*!
188 \property QAbstractAxis::titleFont
189 \property QAbstractAxis::titleFont
189 The font of the title of the axis.
190 The font of the title of the axis.
190 */
191 */
191 /*!
192 /*!
192 \qmlproperty Font AbstractAxis::title
193 \qmlproperty Font AbstractAxis::title
193 The font of the title of the axis.
194 The font of the title of the axis.
194 */
195 */
195
196
196 /*!
197 /*!
197 \property QAbstractAxis::title
198 \property QAbstractAxis::title
198 The title of the axis. Empty by default.
199 The title of the axis. Empty by default.
199 */
200 */
200 /*!
201 /*!
201 \qmlproperty string AbstractAxis::title
202 \qmlproperty string AbstractAxis::title
202 The title of the axis. Empty string by default.
203 The title of the axis. Empty string by default.
203 */
204 */
204
205
205 /*!
206 /*!
206 \property QAbstractAxis::alignment
207 \property QAbstractAxis::alignment
207 The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom.
208 The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom.
208 */
209 */
209 /*!
210 /*!
210 \qmlproperty alignment AbstractAxis::alignment
211 \qmlproperty alignment AbstractAxis::alignment
211 The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom.
212 The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom.
212 */
213 */
213
214
214 /*!
215 /*!
215 \fn void QAbstractAxis::visibleChanged(bool visible)
216 \fn void QAbstractAxis::visibleChanged(bool visible)
216 Visibility of the axis has changed to \a visible.
217 Visibility of the axis has changed to \a visible.
217 */
218 */
218 /*!
219 /*!
219 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
220 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
220 Visibility of the axis has changed to \a visible.
221 Visibility of the axis has changed to \a visible.
221 */
222 */
222
223
223 /*!
224 /*!
224 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
225 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
225 Visibility of the axis line has changed to \a visible.
226 Visibility of the axis line has changed to \a visible.
226 */
227 */
227 /*!
228 /*!
228 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
229 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
229 Visibility of the axis line has changed to \a visible.
230 Visibility of the axis line has changed to \a visible.
230 */
231 */
231
232
232 /*!
233 /*!
233 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
234 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
234 Visibility of the labels of the axis has changed to \a visible.
235 Visibility of the labels of the axis has changed to \a visible.
235 */
236 */
236 /*!
237 /*!
237 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
238 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
238 Visibility of the labels of the axis has changed to \a visible.
239 Visibility of the labels of the axis has changed to \a visible.
239 */
240 */
240
241
241 /*!
242 /*!
242 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
243 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
243 Visibility of the grid lines of the axis has changed to \a visible.
244 Visibility of the grid lines of the axis has changed to \a visible.
244 */
245 */
245 /*!
246 /*!
246 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
247 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
247 Visibility of the grid lines of the axis has changed to \a visible.
248 Visibility of the grid lines of the axis has changed to \a visible.
248 */
249 */
249
250
250 /*!
251 /*!
251 \fn void QAbstractAxis::colorChanged(QColor color)
252 \fn void QAbstractAxis::colorChanged(QColor color)
252 Emitted if the \a color of the axis is changed.
253 Emitted if the \a color of the axis is changed.
253 */
254 */
254 /*!
255 /*!
255 \qmlsignal AbstractAxis::onColorChanged(QColor color)
256 \qmlsignal AbstractAxis::onColorChanged(QColor color)
256 Emitted if the \a color of the axis is changed.
257 Emitted if the \a color of the axis is changed.
257 */
258 */
258
259
259 /*!
260 /*!
260 \fn void QAbstractAxis::labelsColorChanged(QColor color)
261 \fn void QAbstractAxis::labelsColorChanged(QColor color)
261 Emitted if the \a color of the axis labels is changed.
262 Emitted if the \a color of the axis labels is changed.
262 */
263 */
263 /*!
264 /*!
264 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
265 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
265 Emitted if the \a color of the axis labels is changed.
266 Emitted if the \a color of the axis labels is changed.
266 */
267 */
267
268
268 /*!
269 /*!
269 \fn void QAbstractAxis::shadesVisibleChanged(bool)
270 \fn void QAbstractAxis::shadesVisibleChanged(bool)
270 Emitted if the visibility of the axis shades is changed to \a visible.
271 Emitted if the visibility of the axis shades is changed to \a visible.
271 */
272 */
272 /*!
273 /*!
273 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
274 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
274 Emitted if the visibility of the axis shades is changed to \a visible.
275 Emitted if the visibility of the axis shades is changed to \a visible.
275 */
276 */
276
277
277 /*!
278 /*!
278 \fn void QAbstractAxis::shadesColorChanged(QColor color)
279 \fn void QAbstractAxis::shadesColorChanged(QColor color)
279 Emitted if the \a color of the axis shades is changed.
280 Emitted if the \a color of the axis shades is changed.
280 */
281 */
281 /*!
282 /*!
282 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
283 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
283 Emitted if the \a color of the axis shades is changed.
284 Emitted if the \a color of the axis shades is changed.
284 */
285 */
285
286
286 /*!
287 /*!
287 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
288 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
288 Emitted if the border \a color of the axis shades is changed.
289 Emitted if the border \a color of the axis shades is changed.
289 */
290 */
290 /*!
291 /*!
291 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
292 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
292 Emitted if the border \a color of the axis shades is changed.
293 Emitted if the border \a color of the axis shades is changed.
293 */
294 */
294
295
295 /*!
296 /*!
296 \internal
297 \internal
297 Constructs new axis object which is a child of \a parent. Ownership is taken by
298 Constructs new axis object which is a child of \a parent. Ownership is taken by
298 QChart when axis added.
299 QChart when axis added.
299 */
300 */
300
301
301 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
302 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
302 : QObject(parent),
303 : QObject(parent),
303 d_ptr(&d)
304 d_ptr(&d)
304 {
305 {
305 }
306 }
306
307
307 /*!
308 /*!
308 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
309 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
309 */
310 */
310
311
311 QAbstractAxis::~QAbstractAxis()
312 QAbstractAxis::~QAbstractAxis()
312 {
313 {
313 if (d_ptr->m_chart)
314 if (d_ptr->m_chart)
314 qFatal("Still binded axis detected !");
315 qFatal("Still binded axis detected !");
315 }
316 }
316
317
317 /*!
318 /*!
318 Sets \a pen used to draw axis line and ticks.
319 Sets \a pen used to draw axis line and ticks.
319 */
320 */
320 void QAbstractAxis::setLinePen(const QPen &pen)
321 void QAbstractAxis::setLinePen(const QPen &pen)
321 {
322 {
322 if (d_ptr->m_axisPen != pen) {
323 if (d_ptr->m_axisPen != pen) {
323 d_ptr->m_axisPen = pen;
324 d_ptr->m_axisPen = pen;
324 emit linePenChanged(pen);
325 emit linePenChanged(pen);
325 }
326 }
326 }
327 }
327
328
328 /*!
329 /*!
329 Returns pen used to draw axis and ticks.
330 Returns pen used to draw axis and ticks.
330 */
331 */
331 QPen QAbstractAxis::linePen() const
332 QPen QAbstractAxis::linePen() const
332 {
333 {
333 return d_ptr->m_axisPen;
334 return d_ptr->m_axisPen;
334 }
335 }
335
336
336 //TODO: remove me
337 //TODO: remove me
337 void QAbstractAxis::setLinePenColor(QColor color)
338 void QAbstractAxis::setLinePenColor(QColor color)
338 {
339 {
339 QPen p = d_ptr->m_axisPen;
340 QPen p = d_ptr->m_axisPen;
340 if (p.color() != color) {
341 if (p.color() != color) {
341 p.setColor(color);
342 p.setColor(color);
342 setLinePen(p);
343 setLinePen(p);
343 emit colorChanged(color);
344 emit colorChanged(color);
344 }
345 }
345 }
346 }
346
347
347 QColor QAbstractAxis::linePenColor() const
348 QColor QAbstractAxis::linePenColor() const
348 {
349 {
349 return d_ptr->m_axisPen.color();
350 return d_ptr->m_axisPen.color();
350 }
351 }
351
352
352 /*!
353 /*!
353 Sets if axis and ticks are \a visible.
354 Sets if axis and ticks are \a visible.
354 */
355 */
355 void QAbstractAxis::setLineVisible(bool visible)
356 void QAbstractAxis::setLineVisible(bool visible)
356 {
357 {
357 if (d_ptr->m_arrowVisible != visible) {
358 if (d_ptr->m_arrowVisible != visible) {
358 d_ptr->m_arrowVisible = visible;
359 d_ptr->m_arrowVisible = visible;
359 emit lineVisibleChanged(visible);
360 emit lineVisibleChanged(visible);
360 }
361 }
361 }
362 }
362
363
363 bool QAbstractAxis::isLineVisible() const
364 bool QAbstractAxis::isLineVisible() const
364 {
365 {
365 return d_ptr->m_arrowVisible;
366 return d_ptr->m_arrowVisible;
366 }
367 }
367
368
368 void QAbstractAxis::setGridLineVisible(bool visible)
369 void QAbstractAxis::setGridLineVisible(bool visible)
369 {
370 {
370 if (d_ptr->m_gridLineVisible != visible) {
371 if (d_ptr->m_gridLineVisible != visible) {
371 d_ptr->m_gridLineVisible = visible;
372 d_ptr->m_gridLineVisible = visible;
372 emit gridVisibleChanged(visible);
373 emit gridVisibleChanged(visible);
373 }
374 }
374 }
375 }
375
376
376 bool QAbstractAxis::isGridLineVisible() const
377 bool QAbstractAxis::isGridLineVisible() const
377 {
378 {
378 return d_ptr->m_gridLineVisible;
379 return d_ptr->m_gridLineVisible;
379 }
380 }
380
381
381 /*!
382 /*!
382 Sets \a pen used to draw grid line.
383 Sets \a pen used to draw grid line.
383 */
384 */
384 void QAbstractAxis::setGridLinePen(const QPen &pen)
385 void QAbstractAxis::setGridLinePen(const QPen &pen)
385 {
386 {
386 if (d_ptr->m_gridLinePen != pen) {
387 if (d_ptr->m_gridLinePen != pen) {
387 d_ptr->m_gridLinePen = pen;
388 d_ptr->m_gridLinePen = pen;
388 emit gridLinePenChanged(pen);
389 emit gridLinePenChanged(pen);
389 }
390 }
390 }
391 }
391
392
392 /*!
393 /*!
393 Returns pen used to draw grid.
394 Returns pen used to draw grid.
394 */
395 */
395 QPen QAbstractAxis::gridLinePen() const
396 QPen QAbstractAxis::gridLinePen() const
396 {
397 {
397 return d_ptr->m_gridLinePen;
398 return d_ptr->m_gridLinePen;
398 }
399 }
399
400
400 void QAbstractAxis::setLabelsVisible(bool visible)
401 void QAbstractAxis::setLabelsVisible(bool visible)
401 {
402 {
402 if (d_ptr->m_labelsVisible != visible) {
403 if (d_ptr->m_labelsVisible != visible) {
403 d_ptr->m_labelsVisible = visible;
404 d_ptr->m_labelsVisible = visible;
404 emit labelsVisibleChanged(visible);
405 emit labelsVisibleChanged(visible);
405 }
406 }
406 }
407 }
407
408
408 bool QAbstractAxis::labelsVisible() const
409 bool QAbstractAxis::labelsVisible() const
409 {
410 {
410 return d_ptr->m_labelsVisible;
411 return d_ptr->m_labelsVisible;
411 }
412 }
412
413
413 /*!
414 /*!
414 Sets \a pen used to draw labels.
415 Sets \a pen used to draw labels.
415 */
416 */
416 void QAbstractAxis::setLabelsPen(const QPen &pen)
417 void QAbstractAxis::setLabelsPen(const QPen &pen)
417 {
418 {
418 if (d_ptr->m_labelsPen != pen) {
419 if (d_ptr->m_labelsPen != pen) {
419 d_ptr->m_labelsPen = pen;
420 d_ptr->m_labelsPen = pen;
420 emit labelsPenChanged(pen);
421 emit labelsPenChanged(pen);
421 }
422 }
422 }
423 }
423
424
424 /*!
425 /*!
425 Returns the pen used to labels.
426 Returns the pen used to labels.
426 */
427 */
427 QPen QAbstractAxis::labelsPen() const
428 QPen QAbstractAxis::labelsPen() const
428 {
429 {
429 return d_ptr->m_labelsPen;
430 return d_ptr->m_labelsPen;
430 }
431 }
431
432
432 /*!
433 /*!
433 Sets \a brush used to draw labels.
434 Sets \a brush used to draw labels.
434 */
435 */
435 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
436 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
436 {
437 {
437 if (d_ptr->m_labelsBrush != brush) {
438 if (d_ptr->m_labelsBrush != brush) {
438 d_ptr->m_labelsBrush = brush;
439 d_ptr->m_labelsBrush = brush;
439 emit labelsBrushChanged(brush);
440 emit labelsBrushChanged(brush);
440 }
441 }
441 }
442 }
442
443
443 /*!
444 /*!
444 Returns brush used to draw labels.
445 Returns brush used to draw labels.
445 */
446 */
446 QBrush QAbstractAxis::labelsBrush() const
447 QBrush QAbstractAxis::labelsBrush() const
447 {
448 {
448 return d_ptr->m_labelsBrush;
449 return d_ptr->m_labelsBrush;
449 }
450 }
450
451
451 /*!
452 /*!
452 Sets \a font used to draw labels.
453 Sets \a font used to draw labels.
453 */
454 */
454 void QAbstractAxis::setLabelsFont(const QFont &font)
455 void QAbstractAxis::setLabelsFont(const QFont &font)
455 {
456 {
456 if (d_ptr->m_labelsFont != font) {
457 if (d_ptr->m_labelsFont != font) {
457 d_ptr->m_labelsFont = font;
458 d_ptr->m_labelsFont = font;
458 emit labelsFontChanged(font);
459 emit labelsFontChanged(font);
459 }
460 }
460 }
461 }
461
462
462 /*!
463 /*!
463 Returns font used to draw labels.
464 Returns font used to draw labels.
464 */
465 */
465 QFont QAbstractAxis::labelsFont() const
466 QFont QAbstractAxis::labelsFont() const
466 {
467 {
467 return d_ptr->m_labelsFont;
468 return d_ptr->m_labelsFont;
468 }
469 }
469
470
470 void QAbstractAxis::setLabelsAngle(int angle)
471 void QAbstractAxis::setLabelsAngle(int angle)
471 {
472 {
472 if (d_ptr->m_labelsAngle != angle) {
473 if (d_ptr->m_labelsAngle != angle) {
473 d_ptr->m_labelsAngle = angle;
474 d_ptr->m_labelsAngle = angle;
474 emit labelsAngleChanged(angle);
475 emit labelsAngleChanged(angle);
475 }
476 }
476 }
477 }
477
478
478 int QAbstractAxis::labelsAngle() const
479 int QAbstractAxis::labelsAngle() const
479 {
480 {
480 return d_ptr->m_labelsAngle;
481 return d_ptr->m_labelsAngle;
481 }
482 }
482 //TODO: remove me
483 //TODO: remove me
483 void QAbstractAxis::setLabelsColor(QColor color)
484 void QAbstractAxis::setLabelsColor(QColor color)
484 {
485 {
485 QBrush b = d_ptr->m_labelsBrush;
486 QBrush b = d_ptr->m_labelsBrush;
486 if (b.color() != color) {
487 if (b.color() != color) {
487 b.setColor(color);
488 b.setColor(color);
488 setLabelsBrush(b);
489 setLabelsBrush(b);
489 emit labelsColorChanged(color);
490 emit labelsColorChanged(color);
490 }
491 }
491 }
492 }
492
493
493 QColor QAbstractAxis::labelsColor() const
494 QColor QAbstractAxis::labelsColor() const
494 {
495 {
495 return d_ptr->m_labelsBrush.color();
496 return d_ptr->m_labelsBrush.color();
496 }
497 }
497
498
498 void QAbstractAxis::setTitleVisible(bool visible)
499 void QAbstractAxis::setTitleVisible(bool visible)
499 {
500 {
500 if (d_ptr->m_titleVisible != visible) {
501 if (d_ptr->m_titleVisible != visible) {
501 d_ptr->m_titleVisible = visible;
502 d_ptr->m_titleVisible = visible;
502 emit titleVisibleChanged(visible);
503 emit titleVisibleChanged(visible);
503 }
504 }
504 }
505 }
505
506
506 bool QAbstractAxis::isTitleVisible() const
507 bool QAbstractAxis::isTitleVisible() const
507 {
508 {
508 return d_ptr->m_titleVisible;
509 return d_ptr->m_titleVisible;
509 }
510 }
510
511
511 /*!
512 /*!
512 Sets \a pen used to draw title.
513 Sets \a pen used to draw title.
513 */
514 */
514 void QAbstractAxis::setTitlePen(const QPen &pen)
515 void QAbstractAxis::setTitlePen(const QPen &pen)
515 {
516 {
516 if (d_ptr->m_titlePen != pen) {
517 if (d_ptr->m_titlePen != pen) {
517 d_ptr->m_titlePen = pen;
518 d_ptr->m_titlePen = pen;
518 emit titlePenChanged(pen);
519 emit titlePenChanged(pen);
519 }
520 }
520 }
521 }
521
522
522 /*!
523 /*!
523 Returns the pen used to title.
524 Returns the pen used to title.
524 */
525 */
525 QPen QAbstractAxis::titlePen() const
526 QPen QAbstractAxis::titlePen() const
526 {
527 {
527 return d_ptr->m_titlePen;
528 return d_ptr->m_titlePen;
528 }
529 }
529
530
530 /*!
531 /*!
531 Sets \a brush used to draw title.
532 Sets \a brush used to draw title.
532 */
533 */
533 void QAbstractAxis::setTitleBrush(const QBrush &brush)
534 void QAbstractAxis::setTitleBrush(const QBrush &brush)
534 {
535 {
535 if (d_ptr->m_titleBrush != brush) {
536 if (d_ptr->m_titleBrush != brush) {
536 d_ptr->m_titleBrush = brush;
537 d_ptr->m_titleBrush = brush;
537 emit titleBrushChanged(brush);
538 emit titleBrushChanged(brush);
538 }
539 }
539 }
540 }
540
541
541 /*!
542 /*!
542 Returns brush used to draw title.
543 Returns brush used to draw title.
543 */
544 */
544 QBrush QAbstractAxis::titleBrush() const
545 QBrush QAbstractAxis::titleBrush() const
545 {
546 {
546 return d_ptr->m_titleBrush;
547 return d_ptr->m_titleBrush;
547 }
548 }
548
549
549 /*!
550 /*!
550 Sets \a font used to draw title.
551 Sets \a font used to draw title.
551 */
552 */
552 void QAbstractAxis::setTitleFont(const QFont &font)
553 void QAbstractAxis::setTitleFont(const QFont &font)
553 {
554 {
554 if (d_ptr->m_titleFont != font) {
555 if (d_ptr->m_titleFont != font) {
555 d_ptr->m_titleFont = font;
556 d_ptr->m_titleFont = font;
556 emit titleFontChanged(font);
557 emit titleFontChanged(font);
557 }
558 }
558 }
559 }
559
560
560 /*!
561 /*!
561 Returns font used to draw title.
562 Returns font used to draw title.
562 */
563 */
563 QFont QAbstractAxis::titleFont() const
564 QFont QAbstractAxis::titleFont() const
564 {
565 {
565 return d_ptr->m_titleFont;
566 return d_ptr->m_titleFont;
566 }
567 }
567
568
568 void QAbstractAxis::setTitleText(const QString &title)
569 void QAbstractAxis::setTitleText(const QString &title)
569 {
570 {
570 if (d_ptr->m_title != title) {
571 if (d_ptr->m_title != title) {
571 d_ptr->m_title = title;
572 d_ptr->m_title = title;
572 emit titleTextChanged(title);
573 emit titleTextChanged(title);
573 }
574 }
574 }
575 }
575
576
576 QString QAbstractAxis::titleText() const
577 QString QAbstractAxis::titleText() const
577 {
578 {
578 return d_ptr->m_title;
579 return d_ptr->m_title;
579 }
580 }
580
581
581
582
582 void QAbstractAxis::setShadesVisible(bool visible)
583 void QAbstractAxis::setShadesVisible(bool visible)
583 {
584 {
584 if (d_ptr->m_shadesVisible != visible) {
585 if (d_ptr->m_shadesVisible != visible) {
585 d_ptr->m_shadesVisible = visible;
586 d_ptr->m_shadesVisible = visible;
586 emit shadesVisibleChanged(visible);
587 emit shadesVisibleChanged(visible);
587 }
588 }
588 }
589 }
589
590
590 bool QAbstractAxis::shadesVisible() const
591 bool QAbstractAxis::shadesVisible() const
591 {
592 {
592 return d_ptr->m_shadesVisible;
593 return d_ptr->m_shadesVisible;
593 }
594 }
594
595
595 /*!
596 /*!
596 Sets \a pen used to draw shades.
597 Sets \a pen used to draw shades.
597 */
598 */
598 void QAbstractAxis::setShadesPen(const QPen &pen)
599 void QAbstractAxis::setShadesPen(const QPen &pen)
599 {
600 {
600 if (d_ptr->m_shadesPen != pen) {
601 if (d_ptr->m_shadesPen != pen) {
601 d_ptr->m_shadesPen = pen;
602 d_ptr->m_shadesPen = pen;
602 emit shadesPenChanged(pen);
603 emit shadesPenChanged(pen);
603 }
604 }
604 }
605 }
605
606
606 /*!
607 /*!
607 Returns pen used to draw shades.
608 Returns pen used to draw shades.
608 */
609 */
609 QPen QAbstractAxis::shadesPen() const
610 QPen QAbstractAxis::shadesPen() const
610 {
611 {
611 return d_ptr->m_shadesPen;
612 return d_ptr->m_shadesPen;
612 }
613 }
613
614
614 /*!
615 /*!
615 Sets \a brush used to draw shades.
616 Sets \a brush used to draw shades.
616 */
617 */
617 void QAbstractAxis::setShadesBrush(const QBrush &brush)
618 void QAbstractAxis::setShadesBrush(const QBrush &brush)
618 {
619 {
619 if (d_ptr->m_shadesBrush != brush) {
620 if (d_ptr->m_shadesBrush != brush) {
620 d_ptr->m_shadesBrush = brush;
621 d_ptr->m_shadesBrush = brush;
621 emit shadesBrushChanged(brush);
622 emit shadesBrushChanged(brush);
622 }
623 }
623 }
624 }
624
625
625 /*!
626 /*!
626 Returns brush used to draw shades.
627 Returns brush used to draw shades.
627 */
628 */
628 QBrush QAbstractAxis::shadesBrush() const
629 QBrush QAbstractAxis::shadesBrush() const
629 {
630 {
630 return d_ptr->m_shadesBrush;
631 return d_ptr->m_shadesBrush;
631 }
632 }
632
633
633 void QAbstractAxis::setShadesColor(QColor color)
634 void QAbstractAxis::setShadesColor(QColor color)
634 {
635 {
635 QBrush b = d_ptr->m_shadesBrush;
636 QBrush b = d_ptr->m_shadesBrush;
636 if (b.color() != color) {
637 if (b.color() != color) {
637 b.setColor(color);
638 b.setColor(color);
638 setShadesBrush(b);
639 setShadesBrush(b);
639 emit shadesColorChanged(color);
640 emit shadesColorChanged(color);
640 }
641 }
641 }
642 }
642
643
643 QColor QAbstractAxis::shadesColor() const
644 QColor QAbstractAxis::shadesColor() const
644 {
645 {
645 return d_ptr->m_shadesBrush.color();
646 return d_ptr->m_shadesBrush.color();
646 }
647 }
647
648
648 void QAbstractAxis::setShadesBorderColor(QColor color)
649 void QAbstractAxis::setShadesBorderColor(QColor color)
649 {
650 {
650 QPen p = d_ptr->m_shadesPen;
651 QPen p = d_ptr->m_shadesPen;
651 if (p.color() != color) {
652 if (p.color() != color) {
652 p.setColor(color);
653 p.setColor(color);
653 setShadesPen(p);
654 setShadesPen(p);
654 emit shadesColorChanged(color);
655 emit shadesColorChanged(color);
655 }
656 }
656 }
657 }
657
658
658 QColor QAbstractAxis::shadesBorderColor() const
659 QColor QAbstractAxis::shadesBorderColor() const
659 {
660 {
660 return d_ptr->m_shadesPen.color();
661 return d_ptr->m_shadesPen.color();
661 }
662 }
662
663
663
664
664 bool QAbstractAxis::isVisible() const
665 bool QAbstractAxis::isVisible() const
665 {
666 {
666 return d_ptr->m_visible;
667 return d_ptr->m_visible;
667 }
668 }
668
669
669 /*!
670 /*!
670 Sets axis, shades, labels and grid lines to be visible.
671 Sets axis, shades, labels and grid lines to be visible.
671 */
672 */
672 void QAbstractAxis::setVisible(bool visible)
673 void QAbstractAxis::setVisible(bool visible)
673 {
674 {
674 if (d_ptr->m_visible != visible) {
675 if (d_ptr->m_visible != visible) {
675 d_ptr->m_visible = visible;
676 d_ptr->m_visible = visible;
676 emit visibleChanged(visible);
677 emit visibleChanged(visible);
677 }
678 }
678 }
679 }
679
680
680
681
681 /*!
682 /*!
682 Sets axis, shades, labels and grid lines to be visible.
683 Sets axis, shades, labels and grid lines to be visible.
683 */
684 */
684 void QAbstractAxis::show()
685 void QAbstractAxis::show()
685 {
686 {
686 setVisible(true);
687 setVisible(true);
687 }
688 }
688
689
689 /*!
690 /*!
690 Sets axis, shades, labels and grid lines to not be visible.
691 Sets axis, shades, labels and grid lines to not be visible.
691 */
692 */
692 void QAbstractAxis::hide()
693 void QAbstractAxis::hide()
693 {
694 {
694 setVisible(false);
695 setVisible(false);
695 }
696 }
696
697
697 /*!
698 /*!
698 Sets the minimum value shown on the axis.
699 Sets the minimum value shown on the axis.
699 Depending on the actual axis type the \a min parameter is converted to appropriate type.
700 Depending on the actual axis type the \a min parameter is converted to appropriate type.
700 If the conversion is impossible then the function call does nothing
701 If the conversion is impossible then the function call does nothing
701 */
702 */
702 void QAbstractAxis::setMin(const QVariant &min)
703 void QAbstractAxis::setMin(const QVariant &min)
703 {
704 {
704 d_ptr->setMin(min);
705 d_ptr->setMin(min);
705 }
706 }
706
707
707 /*!
708 /*!
708 Sets the maximum value shown on the axis.
709 Sets the maximum value shown on the axis.
709 Depending on the actual axis type the \a max parameter is converted to appropriate type.
710 Depending on the actual axis type the \a max parameter is converted to appropriate type.
710 If the conversion is impossible then the function call does nothing
711 If the conversion is impossible then the function call does nothing
711 */
712 */
712 void QAbstractAxis::setMax(const QVariant &max)
713 void QAbstractAxis::setMax(const QVariant &max)
713 {
714 {
714 d_ptr->setMax(max);
715 d_ptr->setMax(max);
715 }
716 }
716
717
717 /*!
718 /*!
718 Sets the range shown on the axis.
719 Sets the range shown on the axis.
719 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
720 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
720 If the conversion is impossible then the function call does nothing.
721 If the conversion is impossible then the function call does nothing.
721 */
722 */
722 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
723 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
723 {
724 {
724 d_ptr->setRange(min, max);
725 d_ptr->setRange(min, max);
725 }
726 }
726
727
727
728
728 /*!
729 /*!
729 Returns the orientation in which the axis is being used (Vertical or Horizontal)
730 Returns the orientation in which the axis is being used (Vertical or Horizontal)
730 */
731 */
731 // NOTE: should have const but it breaks BC:
732 // NOTE: should have const but it breaks BC:
732 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
733 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
733 Qt::Orientation QAbstractAxis::orientation()
734 Qt::Orientation QAbstractAxis::orientation()
734 {
735 {
735 return d_ptr->orientation();
736 return d_ptr->orientation();
736 }
737 }
737
738
738 Qt::Alignment QAbstractAxis::alignment() const
739 Qt::Alignment QAbstractAxis::alignment() const
739 {
740 {
740 return d_ptr->alignment();
741 return d_ptr->alignment();
741 }
742 }
742
743
743 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
744 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
744
745
745 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
746 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
746 : q_ptr(q),
747 : q_ptr(q),
747 m_chart(0),
748 m_chart(0),
748 m_alignment(0),
749 m_alignment(0),
749 m_orientation(Qt::Orientation(0)),
750 m_orientation(Qt::Orientation(0)),
750 m_visible(true),
751 m_visible(true),
751 m_arrowVisible(true),
752 m_arrowVisible(true),
752 m_gridLineVisible(true),
753 m_gridLineVisible(true),
753 m_labelsVisible(true),
754 m_labelsVisible(true),
754 m_labelsAngle(0),
755 m_labelsAngle(0),
755 m_shadesVisible(false),
756 m_shadesVisible(false),
756 m_shadesBrush(Qt::SolidPattern),
757 m_shadesBrush(Qt::SolidPattern),
757 m_shadesOpacity(1.0),
758 m_shadesOpacity(1.0),
758 m_dirty(false)
759 m_dirty(false)
759 {
760 {
760
761
761 }
762 }
762
763
763 QAbstractAxisPrivate::~QAbstractAxisPrivate()
764 QAbstractAxisPrivate::~QAbstractAxisPrivate()
764 {
765 {
765 }
766 }
766
767
767 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
768 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
768 {
769 {
769 switch(alignment) {
770 switch(alignment) {
770 case Qt::AlignTop:
771 case Qt::AlignTop:
771 case Qt::AlignBottom:
772 case Qt::AlignBottom:
772 m_orientation = Qt::Horizontal;
773 m_orientation = Qt::Horizontal;
773 break;
774 break;
774 case Qt::AlignLeft:
775 case Qt::AlignLeft:
775 case Qt::AlignRight:
776 case Qt::AlignRight:
776 m_orientation = Qt::Vertical;
777 m_orientation = Qt::Vertical;
777 break;
778 break;
778 default:
779 default:
779 qWarning()<<"No alignment specified !";
780 qWarning()<<"No alignment specified !";
780 break;
781 break;
781 };
782 };
782 m_alignment=alignment;
783 m_alignment=alignment;
783 }
784 }
784
785
785 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
786 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
786 {
787 {
787 QPen pen;
788 QPen pen;
788 QBrush brush;
789 QBrush brush;
789 QFont font;
790 QFont font;
790
791
791 bool axisX = m_orientation == Qt::Horizontal;
792 bool axisX = m_orientation == Qt::Horizontal;
792
793
793 if (m_arrowVisible) {
794 if (m_arrowVisible) {
794
795
795 if (forced || brush == m_labelsBrush){
796 if (forced || brush == m_labelsBrush){
796 q_ptr->setLabelsBrush(theme->labelBrush());
797 q_ptr->setLabelsBrush(theme->labelBrush());
797 }
798 }
798 //TODO: introduce axis brush
799 //TODO: introduce axis brush
799 if (forced || brush == m_titleBrush){
800 if (forced || brush == m_titleBrush){
800 q_ptr->setTitleBrush(theme->labelBrush());
801 q_ptr->setTitleBrush(theme->labelBrush());
801 }
802 }
802 if (forced || pen == m_labelsPen){
803 if (forced || pen == m_labelsPen){
803 q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons
804 q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons
804 }
805 }
805 if (forced || pen == m_titlePen){
806 if (forced || pen == m_titlePen){
806 q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons
807 q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons
807 }
808 }
808 if (forced || m_shadesVisible) {
809 if (forced || m_shadesVisible) {
809
810
810 if (forced || brush == m_shadesBrush){
811 if (forced || brush == m_shadesBrush){
811 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
812 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
812 }
813 }
813 if (forced || pen == m_shadesPen){
814 if (forced || pen == m_shadesPen){
814 q_ptr->setShadesPen(theme->backgroundShadesPen());
815 q_ptr->setShadesPen(theme->backgroundShadesPen());
815 }
816 }
816 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
817 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
817 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
818 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
818 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
819 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
819 q_ptr->setShadesVisible(true);
820 q_ptr->setShadesVisible(true);
820 }
821 }
821 }
822 }
822
823
823 if (forced || pen == m_axisPen) {
824 if (forced || pen == m_axisPen) {
824 q_ptr->setLinePen(theme->axisLinePen());
825 q_ptr->setLinePen(theme->axisLinePen());
825 }
826 }
826
827
827 if (forced || pen == m_gridLinePen) {
828 if (forced || pen == m_gridLinePen) {
828 q_ptr->setGridLinePen(theme->girdLinePen());
829 q_ptr->setGridLinePen(theme->girdLinePen());
829 }
830 }
830
831
831 if (forced || font == m_labelsFont){
832 if (forced || font == m_labelsFont){
832 q_ptr->setLabelsFont(theme->labelFont());
833 q_ptr->setLabelsFont(theme->labelFont());
833 }
834 }
834 //TODO: discuss with Tero
835 //TODO: discuss with Tero
835 if (forced || font == m_titleFont){
836 if (forced || font == m_titleFont){
836 QFont font(m_labelsFont);
837 QFont font(m_labelsFont);
837 font.setBold(true);
838 font.setBold(true);
838 q_ptr->setTitleFont(font);
839 q_ptr->setTitleFont(font);
839 }
840 }
840 }
841 }
841 }
842 }
842
843
843 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
844 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
844 {
845 {
845 setRange(min,max);
846 setRange(min,max);
846 }
847 }
847
848
848 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
849 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
849 {
850 {
850 Q_UNUSED(parent);
851 Q_UNUSED(parent);
851 }
852 }
852
853
853 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
854 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
854 {
855 {
855 ChartAxis* axis = m_item.data();
856 ChartAxis* axis = m_item.data();
856 Q_ASSERT(axis);
857 Q_ASSERT(axis);
857 if(options.testFlag(QChart::GridAxisAnimations)) {
858 if(options.testFlag(QChart::GridAxisAnimations)) {
858 axis->setAnimation(new AxisAnimation(axis));
859 axis->setAnimation(new AxisAnimation(axis));
859 }else{
860 }else{
860 axis->setAnimation(0);
861 axis->setAnimation(0);
861 }
862 }
862 }
863 }
863
864
864
865
865
866
866 #include "moc_qabstractaxis.cpp"
867 #include "moc_qabstractaxis.cpp"
867 #include "moc_qabstractaxis_p.cpp"
868 #include "moc_qabstractaxis_p.cpp"
868
869
869 QTCOMMERCIALCHART_END_NAMESPACE
870 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,418 +1,427
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 "qvalueaxis.h"
21 #include "qvalueaxis.h"
22 #include "qvalueaxis_p.h"
22 #include "qvalueaxis_p.h"
23 #include "chartvalueaxisx_p.h"
23 #include "chartvalueaxisx_p.h"
24 #include "chartvalueaxisy_p.h"
24 #include "chartvalueaxisy_p.h"
25 #include "abstractdomain_p.h"
25 #include "abstractdomain_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "chartpresenter_p.h"
27 #include "chartpresenter_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29
29
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 /*!
32 /*!
33 \class QValueAxis
33 \class QValueAxis
34 \brief The QValueAxis class is used for manipulating chart's axis.
34 \brief The QValueAxis class is used for manipulating chart's axis.
35 \mainclass
35 \mainclass
36
36
37 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
37 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
38 Values of axis are drawn to position of ticks.
38 Values of axis are drawn to position of ticks.
39
39
40 Example code on how to use QValueAxis.
40 Example code on how to use QValueAxis.
41 \code
41 \code
42 QChartView *chartView = new QChartView;
42 QChartView *chartView = new QChartView;
43 QLineSeries *series = new QLineSeries;
43 QLineSeries *series = new QLineSeries;
44 // ...
44 // ...
45 chartView->chart()->addSeries(series);
45 chartView->chart()->addSeries(series);
46
46
47 QValueAxis *axisX = new QValueAxis;
47 QValueAxis *axisX = new QValueAxis;
48 axisX->setRange(10, 20.5);
48 axisX->setRange(10, 20.5);
49 axisX->setTickCount(10);
49 axisX->setTickCount(10);
50 axisX->setLabelFormat("%.2f");
50 axisX->setLabelFormat("%.2f");
51 chartView->chart()->setAxisX(axisX, series);
51 chartView->chart()->setAxisX(axisX, series);
52 \endcode
52 \endcode
53 */
53 */
54
54
55 /*!
55 /*!
56 \qmlclass ValueAxis QValueAxis
56 \qmlclass ValueAxis QValueAxis
57 \inherits AbstractAxis
57 \inherits AbstractAxis
58 \brief The ValueAxis element is used for manipulating chart's axes
58 \brief The ValueAxis element is used for manipulating chart's axes
59
59
60 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
60 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
61 Values of axis are drawn to position of ticks
61 Values of axis are drawn to position of ticks
62
62
63 To access Axes you can use ChartView API. For example:
63 To access Axes you can use ChartView API. For example:
64 \code
64 \code
65 ChartView {
65 ChartView {
66 ValueAxis {
66 ValueAxis {
67 id: xAxis
67 id: xAxis
68 min: 0
68 min: 0
69 max: 10
69 max: 10
70 }
70 }
71 // Add a few series...
71 // Add a few series...
72 }
72 }
73 \endcode
73 \endcode
74 */
74 */
75
75
76 /*!
76 /*!
77 \property QValueAxis::min
77 \property QValueAxis::min
78 Defines the minimum value on the axis.
78 Defines the minimum value on the axis.
79 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
79 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
80 */
80 */
81 /*!
81 /*!
82 \qmlproperty real ValueAxis::min
82 \qmlproperty real ValueAxis::min
83 Defines the minimum value on the axis.
83 Defines the minimum value on the axis.
84 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
84 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
85 */
85 */
86
86
87 /*!
87 /*!
88 \property QValueAxis::max
88 \property QValueAxis::max
89 Defines the maximum value on the axis.
89 Defines the maximum value on the axis.
90 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
90 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
91 */
91 */
92 /*!
92 /*!
93 \qmlproperty real ValueAxis::max
93 \qmlproperty real ValueAxis::max
94 Defines the maximum value on the axis.
94 Defines the maximum value on the axis.
95 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
95 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
96 */
96 */
97
97
98 /*!
98 /*!
99 \property QValueAxis::tickCount
99 \property QValueAxis::tickCount
100 Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart.
100 Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart.
101 The default value is 5, and it can not be below 2.
101 The default value is 5, and it can not be below 2.
102 */
102 */
103 /*!
103 /*!
104 \qmlproperty real ValueAxis::tickCount
104 \qmlproperty real ValueAxis::tickCount
105 Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart.
105 Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart.
106 The default value is 5, and it can not be below 2.
106 The default value is 5, and it can not be below 2.
107 */
107 */
108
108
109 /*!
109 /*!
110 \property QValueAxis::labelFormat
110 \property QValueAxis::labelFormat
111 Defines the label format for the axis.
111 Defines the label format of the axis.
112 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
112 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
113 See QString::sprintf() for additional details.
113 See QString::sprintf() for additional details.
114 */
114 */
115 /*!
115 /*!
116 \qmlproperty real ValueAxis::labelFormat
116 \qmlproperty real ValueAxis::labelFormat
117 Defines the label format for the axis.
117 Defines the label format of the axis.
118 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
118 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
119 See QString::sprintf() for additional details.
119 See QString::sprintf() for additional details.
120 */
120 */
121
121
122 /*!
122 /*!
123 \fn void QValueAxis::minChanged(qreal min)
123 \fn void QValueAxis::minChanged(qreal min)
124 Axis emits signal when \a min of axis has changed.
124 Axis emits signal when \a min of axis has changed.
125 */
125 */
126 /*!
126 /*!
127 \qmlsignal ValueAxis::onMinChanged(real min)
127 \qmlsignal ValueAxis::onMinChanged(real min)
128 Axis emits signal when \a min of axis has changed.
128 Axis emits signal when \a min of axis has changed.
129 */
129 */
130
130
131 /*!
131 /*!
132 \fn void QValueAxis::maxChanged(qreal max)
132 \fn void QValueAxis::maxChanged(qreal max)
133 Axis emits signal when \a max of axis has changed.
133 Axis emits signal when \a max of axis has changed.
134 */
134 */
135 /*!
135 /*!
136 \qmlsignal ValueAxis::onMaxChanged(real max)
136 \qmlsignal ValueAxis::onMaxChanged(real max)
137 Axis emits signal when \a max of axis has changed.
137 Axis emits signal when \a max of axis has changed.
138 */
138 */
139
139
140 /*!
140 /*!
141 \fn void QValueAxis::tickCountChanged(int tickCount)
141 \fn void QValueAxis::tickCountChanged(int tickCount)
142 Axis emits signal when number of ticks on axis have changed.
142 Axis emits signal when \a tickCount number on axis have changed.
143 */
143 */
144 /*!
144 /*!
145 \qmlsignal ValueAxis::tickCountChanged(int tickCount)
145 \qmlsignal ValueAxis::tickCountChanged(int tickCount)
146 Axis emits signal when number of ticks on axis have changed.
146 Axis emits signal when \a tickCount number on axis have changed.
147 */
147 */
148
148
149 /*!
149 /*!
150 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
150 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
151 Axis emits signal when \a min or \a max of axis has changed.
151 Axis emits signal when \a min or \a max of axis has changed.
152 */
152 */
153
153
154 /*!
154 /*!
155 \fn void QValueAxis::labelFormatChanged(const QString &format)
156 Axis emits signal when \a format of axis labels has changed.
157 */
158 /*!
159 \qmlsignal ValueAxis::labelFormatChanged(const QString &format)
160 Axis emits signal when \a format of axis labels has changed.
161 */
162
163 /*!
155 \property QValueAxis::niceNumbersEnabled
164 \property QValueAxis::niceNumbersEnabled
156 \obsolete
165 \obsolete
157 Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead.
166 Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead.
158 */
167 */
159
168
160 /*!
169 /*!
161 \qmlproperty bool ValueAxis::niceNumbersEnabled
170 \qmlproperty bool ValueAxis::niceNumbersEnabled
162 \obsolete
171 \obsolete
163 Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead.
172 Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead.
164 */
173 */
165
174
166 /*!
175 /*!
167 Constructs an axis object which is a child of \a parent.
176 Constructs an axis object which is a child of \a parent.
168 */
177 */
169 QValueAxis::QValueAxis(QObject *parent) :
178 QValueAxis::QValueAxis(QObject *parent) :
170 QAbstractAxis(*new QValueAxisPrivate(this), parent)
179 QAbstractAxis(*new QValueAxisPrivate(this), parent)
171 {
180 {
172
181
173 }
182 }
174
183
175 /*!
184 /*!
176 \internal
185 \internal
177 */
186 */
178 QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent)
187 QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent)
179 : QAbstractAxis(d, parent)
188 : QAbstractAxis(d, parent)
180 {
189 {
181
190
182 }
191 }
183
192
184 /*!
193 /*!
185 Destroys the object
194 Destroys the object
186 */
195 */
187 QValueAxis::~QValueAxis()
196 QValueAxis::~QValueAxis()
188 {
197 {
189 Q_D(QValueAxis);
198 Q_D(QValueAxis);
190 if (d->m_chart)
199 if (d->m_chart)
191 d->m_chart->removeAxis(this);
200 d->m_chart->removeAxis(this);
192 }
201 }
193
202
194 void QValueAxis::setMin(qreal min)
203 void QValueAxis::setMin(qreal min)
195 {
204 {
196 Q_D(QValueAxis);
205 Q_D(QValueAxis);
197 setRange(min, qMax(d->m_max, min));
206 setRange(min, qMax(d->m_max, min));
198 }
207 }
199
208
200 qreal QValueAxis::min() const
209 qreal QValueAxis::min() const
201 {
210 {
202 Q_D(const QValueAxis);
211 Q_D(const QValueAxis);
203 return d->m_min;
212 return d->m_min;
204 }
213 }
205
214
206 void QValueAxis::setMax(qreal max)
215 void QValueAxis::setMax(qreal max)
207 {
216 {
208 Q_D(QValueAxis);
217 Q_D(QValueAxis);
209 setRange(qMin(d->m_min, max), max);
218 setRange(qMin(d->m_min, max), max);
210 }
219 }
211
220
212 qreal QValueAxis::max() const
221 qreal QValueAxis::max() const
213 {
222 {
214 Q_D(const QValueAxis);
223 Q_D(const QValueAxis);
215 return d->m_max;
224 return d->m_max;
216 }
225 }
217
226
218 /*!
227 /*!
219 Sets range from \a min to \a max on the axis.
228 Sets range from \a min to \a max on the axis.
220 If min is greater than max then this function returns without making any changes.
229 If min is greater than max then this function returns without making any changes.
221 */
230 */
222 void QValueAxis::setRange(qreal min, qreal max)
231 void QValueAxis::setRange(qreal min, qreal max)
223 {
232 {
224 Q_D(QValueAxis);
233 Q_D(QValueAxis);
225 d->setRange(min,max);
234 d->setRange(min,max);
226 }
235 }
227
236
228 void QValueAxis::setTickCount(int count)
237 void QValueAxis::setTickCount(int count)
229 {
238 {
230 Q_D(QValueAxis);
239 Q_D(QValueAxis);
231 if (d->m_tickCount != count && count >= 2) {
240 if (d->m_tickCount != count && count >= 2) {
232 d->m_tickCount = count;
241 d->m_tickCount = count;
233 emit tickCountChanged(count);
242 emit tickCountChanged(count);
234 }
243 }
235 }
244 }
236
245
237 int QValueAxis::tickCount() const
246 int QValueAxis::tickCount() const
238 {
247 {
239 Q_D(const QValueAxis);
248 Q_D(const QValueAxis);
240 return d->m_tickCount;
249 return d->m_tickCount;
241 }
250 }
242
251
243 void QValueAxis::setNiceNumbersEnabled(bool enable)
252 void QValueAxis::setNiceNumbersEnabled(bool enable)
244 {
253 {
245 Q_D(QValueAxis);
254 Q_D(QValueAxis);
246 qWarning()<<"This function is depreciated, it can lead to unexpected behavior.Use applyNiceNumbers(). ";
255 qWarning()<<"This function is depreciated, it can lead to unexpected behavior.Use applyNiceNumbers(). ";
247 if(enable) {
256 if(enable) {
248 QObject::connect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers()));
257 QObject::connect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers()));
249 QObject::connect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers()));
258 QObject::connect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers()));
250 applyNiceNumbers();
259 applyNiceNumbers();
251 }
260 }
252 else {
261 else {
253 QObject::disconnect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers()));
262 QObject::disconnect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers()));
254 QObject::disconnect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers()));
263 QObject::disconnect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers()));
255 }
264 }
256 d->m_niceNumbersEnabled=enable;
265 d->m_niceNumbersEnabled=enable;
257 }
266 }
258
267
259 bool QValueAxis::niceNumbersEnabled() const
268 bool QValueAxis::niceNumbersEnabled() const
260 {
269 {
261 Q_D(const QValueAxis);
270 Q_D(const QValueAxis);
262 qWarning()<<"This function is depreciated.Use applyNiceNumbers().";
271 qWarning()<<"This function is depreciated.Use applyNiceNumbers().";
263 return d->m_niceNumbersEnabled;
272 return d->m_niceNumbersEnabled;
264 }
273 }
265
274
266 void QValueAxis::setLabelFormat(const QString &format)
275 void QValueAxis::setLabelFormat(const QString &format)
267 {
276 {
268 Q_D(QValueAxis);
277 Q_D(QValueAxis);
269 d->m_format = format;
278 d->m_format = format;
270 emit labelFormatChanged(format);
279 emit labelFormatChanged(format);
271 }
280 }
272
281
273 QString QValueAxis::labelFormat() const
282 QString QValueAxis::labelFormat() const
274 {
283 {
275 Q_D(const QValueAxis);
284 Q_D(const QValueAxis);
276 return d->m_format;
285 return d->m_format;
277 }
286 }
278
287
279 /*!
288 /*!
280 Returns the type of the axis
289 Returns the type of the axis
281 */
290 */
282 QAbstractAxis::AxisType QValueAxis::type() const
291 QAbstractAxis::AxisType QValueAxis::type() const
283 {
292 {
284 return AxisTypeValue;
293 return AxisTypeValue;
285 }
294 }
286
295
287 /*!
296 /*!
288 This method modifies range and number of ticks on the axis to look "nice". Algorithm considers numbers that
297 This method modifies range and number of ticks on the axis to look "nice". Algorithm considers numbers that
289 can be expressed as form of 1*10^n, 2* 10^n or 5*10^n as a nice numbers. These numbers are used for spacing the ticks.
298 can be expressed as form of 1*10^n, 2* 10^n or 5*10^n as a nice numbers. These numbers are used for spacing the ticks.
290 This method will modify the current range and number of ticks.
299 This method will modify the current range and number of ticks.
291 \sa setRange(), setTicks()
300 \sa setRange(), setTickCount()
292 */
301 */
293 void QValueAxis::applyNiceNumbers()
302 void QValueAxis::applyNiceNumbers()
294 {
303 {
295 Q_D(QValueAxis);
304 Q_D(QValueAxis);
296 if(d->m_applying) return;
305 if(d->m_applying) return;
297 qreal min = d->m_min;
306 qreal min = d->m_min;
298 qreal max = d->m_max;
307 qreal max = d->m_max;
299 int ticks = d->m_tickCount;
308 int ticks = d->m_tickCount;
300 AbstractDomain::looseNiceNumbers(min,max,ticks);
309 AbstractDomain::looseNiceNumbers(min,max,ticks);
301 d->m_applying=true;
310 d->m_applying=true;
302 d->setRange(min,max);
311 d->setRange(min,max);
303 setTickCount(ticks);
312 setTickCount(ticks);
304 d->m_applying=false;
313 d->m_applying=false;
305 }
314 }
306
315
307 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
316 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
308
317
309 QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q)
318 QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q)
310 : QAbstractAxisPrivate(q),
319 : QAbstractAxisPrivate(q),
311 m_min(0),
320 m_min(0),
312 m_max(0),
321 m_max(0),
313 m_tickCount(5),
322 m_tickCount(5),
314 m_format(QString::null),
323 m_format(QString::null),
315 m_applying(false),
324 m_applying(false),
316 m_niceNumbersEnabled(false)
325 m_niceNumbersEnabled(false)
317 {
326 {
318
327
319 }
328 }
320
329
321 QValueAxisPrivate::~QValueAxisPrivate()
330 QValueAxisPrivate::~QValueAxisPrivate()
322 {
331 {
323
332
324 }
333 }
325
334
326 void QValueAxisPrivate::setMin(const QVariant &min)
335 void QValueAxisPrivate::setMin(const QVariant &min)
327 {
336 {
328 Q_Q(QValueAxis);
337 Q_Q(QValueAxis);
329 bool ok;
338 bool ok;
330 qreal value = min.toReal(&ok);
339 qreal value = min.toReal(&ok);
331 if (ok)
340 if (ok)
332 q->setMin(value);
341 q->setMin(value);
333 }
342 }
334
343
335 void QValueAxisPrivate::setMax(const QVariant &max)
344 void QValueAxisPrivate::setMax(const QVariant &max)
336 {
345 {
337 Q_Q(QValueAxis);
346 Q_Q(QValueAxis);
338 bool ok;
347 bool ok;
339 qreal value = max.toReal(&ok);
348 qreal value = max.toReal(&ok);
340 if (ok)
349 if (ok)
341 q->setMax(value);
350 q->setMax(value);
342 }
351 }
343
352
344 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
353 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
345 {
354 {
346 Q_Q(QValueAxis);
355 Q_Q(QValueAxis);
347 bool ok1;
356 bool ok1;
348 bool ok2;
357 bool ok2;
349 qreal value1 = min.toReal(&ok1);
358 qreal value1 = min.toReal(&ok1);
350 qreal value2 = max.toReal(&ok2);
359 qreal value2 = max.toReal(&ok2);
351 if (ok1 && ok2)
360 if (ok1 && ok2)
352 q->setRange(value1, value2);
361 q->setRange(value1, value2);
353 }
362 }
354
363
355 void QValueAxisPrivate::setRange(qreal min, qreal max)
364 void QValueAxisPrivate::setRange(qreal min, qreal max)
356 {
365 {
357 Q_Q(QValueAxis);
366 Q_Q(QValueAxis);
358 bool changed = false;
367 bool changed = false;
359
368
360 if (min > max)
369 if (min > max)
361 return;
370 return;
362
371
363 if (!qFuzzyCompare(m_min,min)) {
372 if (!qFuzzyCompare(m_min,min)) {
364 m_min = min;
373 m_min = min;
365 changed = true;
374 changed = true;
366 emit q->minChanged(min);
375 emit q->minChanged(min);
367 }
376 }
368
377
369 if (!qFuzzyCompare(m_max,max)) {
378 if (!qFuzzyCompare(m_max,max)) {
370 m_max = max;
379 m_max = max;
371 changed = true;
380 changed = true;
372 emit q->maxChanged(max);
381 emit q->maxChanged(max);
373 }
382 }
374
383
375 if (changed) {
384 if (changed) {
376 emit rangeChanged(min,max);
385 emit rangeChanged(min,max);
377 emit q->rangeChanged(min, max);
386 emit q->rangeChanged(min, max);
378 }
387 }
379 }
388 }
380
389
381 void QValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
390 void QValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
382 {
391 {
383 Q_Q(QValueAxis);
392 Q_Q(QValueAxis);
384 ChartAxis* axis(0);
393 ChartAxis* axis(0);
385 if (orientation() == Qt::Vertical)
394 if (orientation() == Qt::Vertical)
386 axis = new ChartValueAxisY(q,parent);
395 axis = new ChartValueAxisY(q,parent);
387 if (orientation() == Qt::Horizontal)
396 if (orientation() == Qt::Horizontal)
388 axis = new ChartValueAxisX(q,parent);
397 axis = new ChartValueAxisX(q,parent);
389
398
390 m_item.reset(axis);
399 m_item.reset(axis);
391 QAbstractAxisPrivate::initializeGraphics(parent);
400 QAbstractAxisPrivate::initializeGraphics(parent);
392 }
401 }
393
402
394
403
395 void QValueAxisPrivate::initializeDomain(AbstractDomain *domain)
404 void QValueAxisPrivate::initializeDomain(AbstractDomain *domain)
396 {
405 {
397 if (orientation() == Qt::Vertical) {
406 if (orientation() == Qt::Vertical) {
398 if(!qFuzzyIsNull(m_max - m_min)) {
407 if(!qFuzzyIsNull(m_max - m_min)) {
399 domain->setRangeY(m_min, m_max);
408 domain->setRangeY(m_min, m_max);
400 }
409 }
401 else {
410 else {
402 setRange(domain->minY(), domain->maxY());
411 setRange(domain->minY(), domain->maxY());
403 }
412 }
404 }
413 }
405 if (orientation() == Qt::Horizontal) {
414 if (orientation() == Qt::Horizontal) {
406 if(!qFuzzyIsNull(m_max - m_min)) {
415 if(!qFuzzyIsNull(m_max - m_min)) {
407 domain->setRangeX(m_min, m_max);
416 domain->setRangeX(m_min, m_max);
408 }
417 }
409 else {
418 else {
410 setRange(domain->minX(), domain->maxX());
419 setRange(domain->minX(), domain->maxX());
411 }
420 }
412 }
421 }
413 }
422 }
414
423
415 #include "moc_qvalueaxis.cpp"
424 #include "moc_qvalueaxis.cpp"
416 #include "moc_qvalueaxis_p.cpp"
425 #include "moc_qvalueaxis_p.cpp"
417
426
418 QTCOMMERCIALCHART_END_NAMESPACE
427 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now