##// END OF EJS Templates
Fix QValueAxis range setting...
Titta Heikkala -
r2699:9a409f001e2a
parent child
Show More
@@ -1,431 +1,443
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 "polarchartvalueaxisangular_p.h"
26 #include "polarchartvalueaxisangular_p.h"
27 #include "polarchartvalueaxisradial_p.h"
27 #include "polarchartvalueaxisradial_p.h"
28 #include "chartdataset_p.h"
28 #include "chartdataset_p.h"
29 #include "chartpresenter_p.h"
29 #include "chartpresenter_p.h"
30 #include "charttheme_p.h"
30 #include "charttheme_p.h"
31
31
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 /*!
34 /*!
35 \class QValueAxis
35 \class QValueAxis
36 \inmodule Qt Charts
36 \inmodule Qt Charts
37 \brief The QValueAxis class is used for manipulating chart's axis.
37 \brief The QValueAxis class is used for manipulating chart's axis.
38 \mainclass
38 \mainclass
39
39
40 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
40 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
41 Values of axis are drawn to position of ticks.
41 Values of axis are drawn to position of ticks.
42
42
43 Example code on how to use QValueAxis.
43 Example code on how to use QValueAxis.
44 \code
44 \code
45 QChartView *chartView = new QChartView;
45 QChartView *chartView = new QChartView;
46 QLineSeries *series = new QLineSeries;
46 QLineSeries *series = new QLineSeries;
47 // ...
47 // ...
48 chartView->chart()->addSeries(series);
48 chartView->chart()->addSeries(series);
49
49
50 QValueAxis *axisX = new QValueAxis;
50 QValueAxis *axisX = new QValueAxis;
51 axisX->setRange(10, 20.5);
51 axisX->setRange(10, 20.5);
52 axisX->setTickCount(10);
52 axisX->setTickCount(10);
53 axisX->setLabelFormat("%.2f");
53 axisX->setLabelFormat("%.2f");
54 chartView->chart()->setAxisX(axisX, series);
54 chartView->chart()->setAxisX(axisX, series);
55 \endcode
55 \endcode
56 */
56 */
57 #ifdef QDOC_QT5
57 #ifdef QDOC_QT5
58 /*!
58 /*!
59 \qmltype ValueAxis
59 \qmltype ValueAxis
60 \instantiates QValueAxis
60 \instantiates QValueAxis
61 \inqmlmodule QtCommercial.Chart
61 \inqmlmodule QtCommercial.Chart
62
62
63 \include doc/src/valueaxis.qdocinc
63 \include doc/src/valueaxis.qdocinc
64 */
64 */
65 #else
65 #else
66 /*!
66 /*!
67 \qmlclass ValueAxis QValueAxis
67 \qmlclass ValueAxis QValueAxis
68
68
69 \include ../doc/src/valueaxis.qdocinc
69 \include ../doc/src/valueaxis.qdocinc
70 */
70 */
71 #endif
71 #endif
72
72
73 /*!
73 /*!
74 \property QValueAxis::min
74 \property QValueAxis::min
75 Defines the minimum value on the axis.
75 Defines the minimum value on the axis.
76 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
76 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
77 */
77 */
78 /*!
78 /*!
79 \qmlproperty real ValueAxis::min
79 \qmlproperty real ValueAxis::min
80 Defines the minimum value on the axis.
80 Defines the minimum value on the axis.
81 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
81 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
82 */
82 */
83
83
84 /*!
84 /*!
85 \property QValueAxis::max
85 \property QValueAxis::max
86 Defines the maximum value on the axis.
86 Defines the maximum value on the axis.
87 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
87 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
88 */
88 */
89 /*!
89 /*!
90 \qmlproperty real ValueAxis::max
90 \qmlproperty real ValueAxis::max
91 Defines the maximum value on the axis.
91 Defines the maximum value on the axis.
92 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
92 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
93 */
93 */
94
94
95 /*!
95 /*!
96 \property QValueAxis::tickCount
96 \property QValueAxis::tickCount
97 Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart.
97 Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart.
98 The default value is 5, and it can not be below 2.
98 The default value is 5, and it can not be below 2.
99 */
99 */
100 /*!
100 /*!
101 \qmlproperty real ValueAxis::tickCount
101 \qmlproperty real ValueAxis::tickCount
102 Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart.
102 Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart.
103 The default value is 5, and it can not be below 2.
103 The default value is 5, and it can not be below 2.
104 */
104 */
105
105
106 /*!
106 /*!
107 \property QValueAxis::labelFormat
107 \property QValueAxis::labelFormat
108 Defines the label format of the axis.
108 Defines the label format of the axis.
109 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
109 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
110 See QString::sprintf() for additional details.
110 See QString::sprintf() for additional details.
111 */
111 */
112 /*!
112 /*!
113 \qmlproperty real ValueAxis::labelFormat
113 \qmlproperty real ValueAxis::labelFormat
114 Defines the label format of the axis.
114 Defines the label format of the axis.
115 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
115 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
116 See QString::sprintf() for additional details.
116 See QString::sprintf() for additional details.
117 */
117 */
118
118
119 /*!
119 /*!
120 \fn void QValueAxis::minChanged(qreal min)
120 \fn void QValueAxis::minChanged(qreal min)
121 Axis emits signal when \a min of axis has changed.
121 Axis emits signal when \a min of axis has changed.
122 */
122 */
123 /*!
123 /*!
124 \qmlsignal ValueAxis::onMinChanged(real min)
124 \qmlsignal ValueAxis::onMinChanged(real min)
125 Axis emits signal when \a min of axis has changed.
125 Axis emits signal when \a min of axis has changed.
126 */
126 */
127
127
128 /*!
128 /*!
129 \fn void QValueAxis::maxChanged(qreal max)
129 \fn void QValueAxis::maxChanged(qreal max)
130 Axis emits signal when \a max of axis has changed.
130 Axis emits signal when \a max of axis has changed.
131 */
131 */
132 /*!
132 /*!
133 \qmlsignal ValueAxis::onMaxChanged(real max)
133 \qmlsignal ValueAxis::onMaxChanged(real max)
134 Axis emits signal when \a max of axis has changed.
134 Axis emits signal when \a max of axis has changed.
135 */
135 */
136
136
137 /*!
137 /*!
138 \fn void QValueAxis::tickCountChanged(int tickCount)
138 \fn void QValueAxis::tickCountChanged(int tickCount)
139 Axis emits signal when \a tickCount of axis has changed.
139 Axis emits signal when \a tickCount of axis has changed.
140 */
140 */
141 /*!
141 /*!
142 \qmlsignal ValueAxis::tickCountChanged(int tickCount)
142 \qmlsignal ValueAxis::tickCountChanged(int tickCount)
143 Axis emits signal when \a tickCount of axis has changed.
143 Axis emits signal when \a tickCount of axis has changed.
144 */
144 */
145
145
146 /*!
146 /*!
147 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
147 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
148 Axis emits signal when \a min or \a max of axis has changed.
148 Axis emits signal when \a min or \a max of axis has changed.
149 */
149 */
150
150
151 /*!
151 /*!
152 \fn void QValueAxis::labelFormatChanged(const QString &format)
152 \fn void QValueAxis::labelFormatChanged(const QString &format)
153 Axis emits signal when \a format of axis labels has changed.
153 Axis emits signal when \a format of axis labels has changed.
154 */
154 */
155 /*!
155 /*!
156 \qmlsignal ValueAxis::labelFormatChanged(const QString &format)
156 \qmlsignal ValueAxis::labelFormatChanged(const QString &format)
157 Axis emits signal when \a format of axis labels has changed.
157 Axis emits signal when \a format of axis labels has changed.
158 */
158 */
159
159
160 /*!
160 /*!
161 \property QValueAxis::niceNumbersEnabled
161 \property QValueAxis::niceNumbersEnabled
162 \obsolete
162 \obsolete
163 Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead.
163 Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead.
164 */
164 */
165
165
166 /*!
166 /*!
167 \qmlproperty bool ValueAxis::niceNumbersEnabled
167 \qmlproperty bool ValueAxis::niceNumbersEnabled
168 Deprecated; Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead.
168 Deprecated; Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead.
169 */
169 */
170
170
171 /*!
171 /*!
172 Constructs an axis object which is a child of \a parent.
172 Constructs an axis object which is a child of \a parent.
173 */
173 */
174 QValueAxis::QValueAxis(QObject *parent) :
174 QValueAxis::QValueAxis(QObject *parent) :
175 QAbstractAxis(*new QValueAxisPrivate(this), parent)
175 QAbstractAxis(*new QValueAxisPrivate(this), parent)
176 {
176 {
177
177
178 }
178 }
179
179
180 /*!
180 /*!
181 \internal
181 \internal
182 */
182 */
183 QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent)
183 QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent)
184 : QAbstractAxis(d, parent)
184 : QAbstractAxis(d, parent)
185 {
185 {
186
186
187 }
187 }
188
188
189 /*!
189 /*!
190 Destroys the object
190 Destroys the object
191 */
191 */
192 QValueAxis::~QValueAxis()
192 QValueAxis::~QValueAxis()
193 {
193 {
194 Q_D(QValueAxis);
194 Q_D(QValueAxis);
195 if (d->m_chart)
195 if (d->m_chart)
196 d->m_chart->removeAxis(this);
196 d->m_chart->removeAxis(this);
197 }
197 }
198
198
199 void QValueAxis::setMin(qreal min)
199 void QValueAxis::setMin(qreal min)
200 {
200 {
201 Q_D(QValueAxis);
201 Q_D(QValueAxis);
202 setRange(min, qMax(d->m_max, min));
202 setRange(min, qMax(d->m_max, min));
203 }
203 }
204
204
205 qreal QValueAxis::min() const
205 qreal QValueAxis::min() const
206 {
206 {
207 Q_D(const QValueAxis);
207 Q_D(const QValueAxis);
208 return d->m_min;
208 return d->m_min;
209 }
209 }
210
210
211 void QValueAxis::setMax(qreal max)
211 void QValueAxis::setMax(qreal max)
212 {
212 {
213 Q_D(QValueAxis);
213 Q_D(QValueAxis);
214 setRange(qMin(d->m_min, max), max);
214 setRange(qMin(d->m_min, max), max);
215 }
215 }
216
216
217 qreal QValueAxis::max() const
217 qreal QValueAxis::max() const
218 {
218 {
219 Q_D(const QValueAxis);
219 Q_D(const QValueAxis);
220 return d->m_max;
220 return d->m_max;
221 }
221 }
222
222
223 /*!
223 /*!
224 Sets range from \a min to \a max on the axis.
224 Sets range from \a min to \a max on the axis.
225 If min is greater than max then this function returns without making any changes.
225 If min is greater than max then this function returns without making any changes.
226 */
226 */
227 void QValueAxis::setRange(qreal min, qreal max)
227 void QValueAxis::setRange(qreal min, qreal max)
228 {
228 {
229 Q_D(QValueAxis);
229 Q_D(QValueAxis);
230 d->setRange(min,max);
230 d->setRange(min,max);
231 }
231 }
232
232
233 void QValueAxis::setTickCount(int count)
233 void QValueAxis::setTickCount(int count)
234 {
234 {
235 Q_D(QValueAxis);
235 Q_D(QValueAxis);
236 if (d->m_tickCount != count && count >= 2) {
236 if (d->m_tickCount != count && count >= 2) {
237 d->m_tickCount = count;
237 d->m_tickCount = count;
238 emit tickCountChanged(count);
238 emit tickCountChanged(count);
239 }
239 }
240 }
240 }
241
241
242 int QValueAxis::tickCount() const
242 int QValueAxis::tickCount() const
243 {
243 {
244 Q_D(const QValueAxis);
244 Q_D(const QValueAxis);
245 return d->m_tickCount;
245 return d->m_tickCount;
246 }
246 }
247
247
248 void QValueAxis::setNiceNumbersEnabled(bool enable)
248 void QValueAxis::setNiceNumbersEnabled(bool enable)
249 {
249 {
250 Q_D(QValueAxis);
250 Q_D(QValueAxis);
251 qWarning() << "Deprecated; Using this function can lead to unexpected behavior. " \
251 qWarning() << "Deprecated; Using this function can lead to unexpected behavior. " \
252 "Use applyNiceNumbers() instead.";
252 "Use applyNiceNumbers() instead.";
253 if(enable) {
253 if(enable) {
254 QObject::connect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers()));
254 QObject::connect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers()));
255 QObject::connect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers()));
255 QObject::connect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers()));
256 applyNiceNumbers();
256 applyNiceNumbers();
257 }
257 }
258 else {
258 else {
259 QObject::disconnect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers()));
259 QObject::disconnect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers()));
260 QObject::disconnect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers()));
260 QObject::disconnect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers()));
261 }
261 }
262 d->m_niceNumbersEnabled=enable;
262 d->m_niceNumbersEnabled=enable;
263 }
263 }
264
264
265 bool QValueAxis::niceNumbersEnabled() const
265 bool QValueAxis::niceNumbersEnabled() const
266 {
266 {
267 Q_D(const QValueAxis);
267 Q_D(const QValueAxis);
268 qWarning() << "Deprecated; Using this function can lead to unexpected behavior. " \
268 qWarning() << "Deprecated; Using this function can lead to unexpected behavior. " \
269 "Use applyNiceNumbers() instead.";
269 "Use applyNiceNumbers() instead.";
270 return d->m_niceNumbersEnabled;
270 return d->m_niceNumbersEnabled;
271 }
271 }
272
272
273 void QValueAxis::setLabelFormat(const QString &format)
273 void QValueAxis::setLabelFormat(const QString &format)
274 {
274 {
275 Q_D(QValueAxis);
275 Q_D(QValueAxis);
276 d->m_format = format;
276 d->m_format = format;
277 emit labelFormatChanged(format);
277 emit labelFormatChanged(format);
278 }
278 }
279
279
280 QString QValueAxis::labelFormat() const
280 QString QValueAxis::labelFormat() const
281 {
281 {
282 Q_D(const QValueAxis);
282 Q_D(const QValueAxis);
283 return d->m_format;
283 return d->m_format;
284 }
284 }
285
285
286 /*!
286 /*!
287 Returns the type of the axis
287 Returns the type of the axis
288 */
288 */
289 QAbstractAxis::AxisType QValueAxis::type() const
289 QAbstractAxis::AxisType QValueAxis::type() const
290 {
290 {
291 return AxisTypeValue;
291 return AxisTypeValue;
292 }
292 }
293
293
294 /*!
294 /*!
295 This method modifies range and number of ticks on the axis to look "nice". Algorithm considers numbers that
295 This method modifies range and number of ticks on the axis to look "nice". Algorithm considers numbers that
296 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.
296 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.
297 This method will modify the current range and number of ticks.
297 This method will modify the current range and number of ticks.
298 \sa setRange(), setTickCount()
298 \sa setRange(), setTickCount()
299 */
299 */
300 void QValueAxis::applyNiceNumbers()
300 void QValueAxis::applyNiceNumbers()
301 {
301 {
302 Q_D(QValueAxis);
302 Q_D(QValueAxis);
303 if(d->m_applying) return;
303 if(d->m_applying) return;
304 qreal min = d->m_min;
304 qreal min = d->m_min;
305 qreal max = d->m_max;
305 qreal max = d->m_max;
306 int ticks = d->m_tickCount;
306 int ticks = d->m_tickCount;
307 AbstractDomain::looseNiceNumbers(min,max,ticks);
307 AbstractDomain::looseNiceNumbers(min,max,ticks);
308 d->m_applying=true;
308 d->m_applying=true;
309 d->setRange(min,max);
309 d->setRange(min,max);
310 setTickCount(ticks);
310 setTickCount(ticks);
311 d->m_applying=false;
311 d->m_applying=false;
312 }
312 }
313
313
314 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
314 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
315
315
316 QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q)
316 QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q)
317 : QAbstractAxisPrivate(q),
317 : QAbstractAxisPrivate(q),
318 m_min(0),
318 m_min(0),
319 m_max(0),
319 m_max(0),
320 m_tickCount(5),
320 m_tickCount(5),
321 m_format(QString::null),
321 m_format(QString::null),
322 m_applying(false),
322 m_applying(false),
323 m_niceNumbersEnabled(false)
323 m_niceNumbersEnabled(false)
324 {
324 {
325
325
326 }
326 }
327
327
328 QValueAxisPrivate::~QValueAxisPrivate()
328 QValueAxisPrivate::~QValueAxisPrivate()
329 {
329 {
330
330
331 }
331 }
332
332
333 void QValueAxisPrivate::setMin(const QVariant &min)
333 void QValueAxisPrivate::setMin(const QVariant &min)
334 {
334 {
335 Q_Q(QValueAxis);
335 Q_Q(QValueAxis);
336 bool ok;
336 bool ok;
337 qreal value = min.toReal(&ok);
337 qreal value = min.toReal(&ok);
338 if (ok)
338 if (ok)
339 q->setMin(value);
339 q->setMin(value);
340 }
340 }
341
341
342 void QValueAxisPrivate::setMax(const QVariant &max)
342 void QValueAxisPrivate::setMax(const QVariant &max)
343 {
343 {
344 Q_Q(QValueAxis);
344 Q_Q(QValueAxis);
345 bool ok;
345 bool ok;
346 qreal value = max.toReal(&ok);
346 qreal value = max.toReal(&ok);
347 if (ok)
347 if (ok)
348 q->setMax(value);
348 q->setMax(value);
349 }
349 }
350
350
351 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
351 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
352 {
352 {
353 Q_Q(QValueAxis);
353 Q_Q(QValueAxis);
354 bool ok1;
354 bool ok1;
355 bool ok2;
355 bool ok2;
356 qreal value1 = min.toReal(&ok1);
356 qreal value1 = min.toReal(&ok1);
357 qreal value2 = max.toReal(&ok2);
357 qreal value2 = max.toReal(&ok2);
358 if (ok1 && ok2)
358 if (ok1 && ok2)
359 q->setRange(value1, value2);
359 q->setRange(value1, value2);
360 }
360 }
361
361
362 void QValueAxisPrivate::setRange(qreal min, qreal max)
362 void QValueAxisPrivate::setRange(qreal min, qreal max)
363 {
363 {
364 Q_Q(QValueAxis);
364 Q_Q(QValueAxis);
365 bool changed = false;
365 bool changed = false;
366
366
367 if (min > max)
367 if (min > max)
368 return;
368 return;
369
369
370 if (!qFuzzyCompare(m_min,min)) {
370 bool changeMin = false;
371 if (m_min == 0 || min == 0)
372 changeMin = !qFuzzyCompare(1 + m_min, 1 + min);
373 else
374 changeMin = !qFuzzyCompare(m_min, min);
375
376 bool changeMax = false;
377 if (m_max == 0 || max == 0)
378 changeMax = !qFuzzyCompare(1 + m_max, 1 + max);
379 else
380 changeMax = !qFuzzyCompare(m_max, max);
381
382 if (changeMin) {
371 m_min = min;
383 m_min = min;
372 changed = true;
384 changed = true;
373 emit q->minChanged(min);
385 emit q->minChanged(min);
374 }
386 }
375
387
376 if (!qFuzzyCompare(m_max,max)) {
388 if (changeMax) {
377 m_max = max;
389 m_max = max;
378 changed = true;
390 changed = true;
379 emit q->maxChanged(max);
391 emit q->maxChanged(max);
380 }
392 }
381
393
382 if (changed) {
394 if (changed) {
383 emit rangeChanged(min,max);
395 emit rangeChanged(min,max);
384 emit q->rangeChanged(min, max);
396 emit q->rangeChanged(min, max);
385 }
397 }
386 }
398 }
387
399
388 void QValueAxisPrivate::initializeGraphics(QGraphicsItem *parent)
400 void QValueAxisPrivate::initializeGraphics(QGraphicsItem *parent)
389 {
401 {
390 Q_Q(QValueAxis);
402 Q_Q(QValueAxis);
391 ChartAxisElement *axis(0);
403 ChartAxisElement *axis(0);
392
404
393 if (m_chart->chartType() == QChart::ChartTypeCartesian) {
405 if (m_chart->chartType() == QChart::ChartTypeCartesian) {
394 if (orientation() == Qt::Vertical)
406 if (orientation() == Qt::Vertical)
395 axis = new ChartValueAxisY(q,parent);
407 axis = new ChartValueAxisY(q,parent);
396 if (orientation() == Qt::Horizontal)
408 if (orientation() == Qt::Horizontal)
397 axis = new ChartValueAxisX(q,parent);
409 axis = new ChartValueAxisX(q,parent);
398 }
410 }
399
411
400 if (m_chart->chartType() == QChart::ChartTypePolar) {
412 if (m_chart->chartType() == QChart::ChartTypePolar) {
401 if (orientation() == Qt::Vertical)
413 if (orientation() == Qt::Vertical)
402 axis = new PolarChartValueAxisRadial(q, parent);
414 axis = new PolarChartValueAxisRadial(q, parent);
403 if (orientation() == Qt::Horizontal)
415 if (orientation() == Qt::Horizontal)
404 axis = new PolarChartValueAxisAngular(q, parent);
416 axis = new PolarChartValueAxisAngular(q, parent);
405 }
417 }
406
418
407 m_item.reset(axis);
419 m_item.reset(axis);
408 QAbstractAxisPrivate::initializeGraphics(parent);
420 QAbstractAxisPrivate::initializeGraphics(parent);
409 }
421 }
410
422
411
423
412 void QValueAxisPrivate::initializeDomain(AbstractDomain *domain)
424 void QValueAxisPrivate::initializeDomain(AbstractDomain *domain)
413 {
425 {
414 if (orientation() == Qt::Vertical) {
426 if (orientation() == Qt::Vertical) {
415 if (!qFuzzyIsNull(m_max - m_min))
427 if (!qFuzzyIsNull(m_max - m_min))
416 domain->setRangeY(m_min, m_max);
428 domain->setRangeY(m_min, m_max);
417 else
429 else
418 setRange(domain->minY(), domain->maxY());
430 setRange(domain->minY(), domain->maxY());
419 }
431 }
420 if (orientation() == Qt::Horizontal) {
432 if (orientation() == Qt::Horizontal) {
421 if (!qFuzzyIsNull(m_max - m_min))
433 if (!qFuzzyIsNull(m_max - m_min))
422 domain->setRangeX(m_min, m_max);
434 domain->setRangeX(m_min, m_max);
423 else
435 else
424 setRange(domain->minX(), domain->maxX());
436 setRange(domain->minX(), domain->maxX());
425 }
437 }
426 }
438 }
427
439
428 #include "moc_qvalueaxis.cpp"
440 #include "moc_qvalueaxis.cpp"
429 #include "moc_qvalueaxis_p.cpp"
441 #include "moc_qvalueaxis_p.cpp"
430
442
431 QTCOMMERCIALCHART_END_NAMESPACE
443 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now