##// END OF EJS Templates
Fix crash when axis range is infinite....
Miikka Heikkinen -
r2875:6961daf29fe7
parent child
Show More
@@ -1,458 +1,464
1 /******************************************************************************
1 /******************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
4 ** Contact: http://www.qt.io/licensing/
5 **
5 **
6 ** This file is part of the Qt Charts module.
6 ** This file is part of the Qt Charts module.
7 **
7 **
8 ** $QT_BEGIN_LICENSE:COMM$
8 ** $QT_BEGIN_LICENSE:COMM$
9 **
9 **
10 ** Commercial License Usage
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** and conditions see http://www.qt.io/terms-conditions. For further
16 ** information use the contact form at http://www.qt.io/contact-us.
16 ** information use the contact form at http://www.qt.io/contact-us.
17 **
17 **
18 ** $QT_END_LICENSE$
18 ** $QT_END_LICENSE$
19 **
19 **
20 ******************************************************************************/
20 ******************************************************************************/
21
21
22 #include <QtCharts/QValueAxis>
22 #include <QtCharts/QValueAxis>
23 #include <private/qvalueaxis_p.h>
23 #include <private/qvalueaxis_p.h>
24 #include <private/chartvalueaxisx_p.h>
24 #include <private/chartvalueaxisx_p.h>
25 #include <private/chartvalueaxisy_p.h>
25 #include <private/chartvalueaxisy_p.h>
26 #include <private/abstractdomain_p.h>
26 #include <private/abstractdomain_p.h>
27 #include <private/polarchartvalueaxisangular_p.h>
27 #include <private/polarchartvalueaxisangular_p.h>
28 #include <private/polarchartvalueaxisradial_p.h>
28 #include <private/polarchartvalueaxisradial_p.h>
29 #include <private/chartdataset_p.h>
29 #include <private/chartdataset_p.h>
30 #include <private/chartpresenter_p.h>
30 #include <private/chartpresenter_p.h>
31 #include <private/charttheme_p.h>
31 #include <private/charttheme_p.h>
32
32 #include <private/charthelpers_p.h>
33
33
34 QT_CHARTS_BEGIN_NAMESPACE
34 QT_CHARTS_BEGIN_NAMESPACE
35 /*!
35 /*!
36 \class QValueAxis
36 \class QValueAxis
37 \inmodule Qt Charts
37 \inmodule Qt Charts
38 \brief The QValueAxis class is used for manipulating chart's axis.
38 \brief The QValueAxis class is used for manipulating chart's axis.
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 /*!
57 /*!
58 \qmltype ValueAxis
58 \qmltype ValueAxis
59 \instantiates QValueAxis
59 \instantiates QValueAxis
60 \inqmlmodule QtCharts
60 \inqmlmodule QtCharts
61
61
62 \inherits AbstractAxis
62 \inherits AbstractAxis
63 \brief The ValueAxis element is used for manipulating chart's axes
63 \brief The ValueAxis element is used for manipulating chart's axes
64
64
65 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
65 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
66 Values of axis are drawn to position of ticks
66 Values of axis are drawn to position of ticks
67
67
68 Example about using ValueAxis:
68 Example about using ValueAxis:
69 \code
69 \code
70 ChartView {
70 ChartView {
71 ValueAxis {
71 ValueAxis {
72 id: xAxis
72 id: xAxis
73 min: 0
73 min: 0
74 max: 10
74 max: 10
75 }
75 }
76 // Add a few series...
76 // Add a few series...
77 }
77 }
78 \endcode
78 \endcode
79 */
79 */
80
80
81 /*!
81 /*!
82 \property QValueAxis::min
82 \property QValueAxis::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 \qmlproperty real ValueAxis::min
87 \qmlproperty real ValueAxis::min
88 Defines the minimum value on the axis.
88 Defines the minimum value on the axis.
89 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
89 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
90 */
90 */
91
91
92 /*!
92 /*!
93 \property QValueAxis::max
93 \property QValueAxis::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 \qmlproperty real ValueAxis::max
98 \qmlproperty real ValueAxis::max
99 Defines the maximum value on the axis.
99 Defines the maximum value on the axis.
100 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
100 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
101 */
101 */
102
102
103 /*!
103 /*!
104 \property QValueAxis::tickCount
104 \property QValueAxis::tickCount
105 Defines the number of ticks on the axis. This indicates how many grid lines are drawn on the
105 Defines the number of ticks on the axis. This indicates how many grid lines are drawn on the
106 chart. The default value is 5, and it can not be below 2.
106 chart. The default value is 5, and it can not be below 2.
107 */
107 */
108 /*!
108 /*!
109 \qmlproperty int ValueAxis::tickCount
109 \qmlproperty int ValueAxis::tickCount
110 Defines the number of ticks on the axis. This indicates how many grid lines are drawn on the
110 Defines the number of ticks on the axis. This indicates how many grid lines are drawn on the
111 chart. The default value is 5, and it can not be below 2.
111 chart. The default value is 5, and it can not be below 2.
112 */
112 */
113
113
114 /*!
114 /*!
115 \property QValueAxis::minorTickCount
115 \property QValueAxis::minorTickCount
116 Defines the number of minor ticks on the axis. This indicates how many grid lines are drawn
116 Defines the number of minor ticks on the axis. This indicates how many grid lines are drawn
117 between major ticks on the chart. Labels are not drawn for minor ticks. The default value is 0.
117 between major ticks on the chart. Labels are not drawn for minor ticks. The default value is 0.
118 */
118 */
119 /*!
119 /*!
120 \qmlproperty int ValueAxis::minorTickCount
120 \qmlproperty int ValueAxis::minorTickCount
121 Defines the number of minor ticks on the axis. This indicates how many grid lines are drawn
121 Defines the number of minor ticks on the axis. This indicates how many grid lines are drawn
122 between major ticks on the chart. Labels are not drawn for minor ticks. The default value is 0.
122 between major ticks on the chart. Labels are not drawn for minor ticks. The default value is 0.
123 */
123 */
124
124
125 /*!
125 /*!
126 \property QValueAxis::labelFormat
126 \property QValueAxis::labelFormat
127 Defines the label format of the axis.
127 Defines the label format of the axis.
128 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, and c.
128 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, and c.
129 See QString::sprintf() for additional details.
129 See QString::sprintf() for additional details.
130
130
131 If the QChart::localizeNumbers is \c{true}, the supported specifiers are limited to: d, e, E, f,
131 If the QChart::localizeNumbers is \c{true}, the supported specifiers are limited to: d, e, E, f,
132 g, G, and i. Also, only the precision modifier is supported. The rest of the formatting comes from
132 g, G, and i. Also, only the precision modifier is supported. The rest of the formatting comes from
133 the default QLocale of the application.
133 the default QLocale of the application.
134 */
134 */
135 /*!
135 /*!
136 \qmlproperty real ValueAxis::labelFormat
136 \qmlproperty real ValueAxis::labelFormat
137 Defines the label format of the axis.
137 Defines the label format of the axis.
138 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, and c.
138 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, and c.
139 See QString::sprintf() for additional details.
139 See QString::sprintf() for additional details.
140
140
141 If the ChartView::localizeNumbers is \c{true}, the supported specifiers are limited to: d, e, E, f,
141 If the ChartView::localizeNumbers is \c{true}, the supported specifiers are limited to: d, e, E, f,
142 g, G, and i. Also, only the precision modifier is supported. The rest of the formatting comes from
142 g, G, and i. Also, only the precision modifier is supported. The rest of the formatting comes from
143 the default QLocale of the application.
143 the default QLocale of the application.
144 */
144 */
145
145
146 /*!
146 /*!
147 \fn void QValueAxis::minChanged(qreal min)
147 \fn void QValueAxis::minChanged(qreal min)
148 Axis emits signal when \a min of axis has changed.
148 Axis emits signal when \a min of axis has changed.
149 */
149 */
150 /*!
150 /*!
151 \qmlsignal ValueAxis::onMinChanged(real min)
151 \qmlsignal ValueAxis::onMinChanged(real min)
152 Axis emits signal when \a min of axis has changed.
152 Axis emits signal when \a min of axis has changed.
153 */
153 */
154
154
155 /*!
155 /*!
156 \fn void QValueAxis::maxChanged(qreal max)
156 \fn void QValueAxis::maxChanged(qreal max)
157 Axis emits signal when \a max of axis has changed.
157 Axis emits signal when \a max of axis has changed.
158 */
158 */
159 /*!
159 /*!
160 \qmlsignal ValueAxis::onMaxChanged(real max)
160 \qmlsignal ValueAxis::onMaxChanged(real max)
161 Axis emits signal when \a max of axis has changed.
161 Axis emits signal when \a max of axis has changed.
162 */
162 */
163
163
164 /*!
164 /*!
165 \fn void QValueAxis::tickCountChanged(int tickCount)
165 \fn void QValueAxis::tickCountChanged(int tickCount)
166 Axis emits signal when \a tickCount of axis has changed.
166 Axis emits signal when \a tickCount of axis has changed.
167 */
167 */
168 /*!
168 /*!
169 \qmlsignal ValueAxis::tickCountChanged(int tickCount)
169 \qmlsignal ValueAxis::tickCountChanged(int tickCount)
170 Axis emits signal when \a tickCount of axis has changed.
170 Axis emits signal when \a tickCount of axis has changed.
171 */
171 */
172
172
173 /*!
173 /*!
174 \fn void QValueAxis::minorTickCountChanged(int minorTickCount)
174 \fn void QValueAxis::minorTickCountChanged(int minorTickCount)
175 Axis emits signal when \a minorTickCount of axis has changed.
175 Axis emits signal when \a minorTickCount of axis has changed.
176 */
176 */
177 /*!
177 /*!
178 \qmlsignal ValueAxis::minorTickCountChanged(int minorTickCount)
178 \qmlsignal ValueAxis::minorTickCountChanged(int minorTickCount)
179 Axis emits signal when \a minorTickCount of axis has changed.
179 Axis emits signal when \a minorTickCount of axis has changed.
180 */
180 */
181
181
182 /*!
182 /*!
183 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
183 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
184 Axis emits signal when \a min or \a max of axis has changed.
184 Axis emits signal when \a min or \a max of axis has changed.
185 */
185 */
186
186
187 /*!
187 /*!
188 \fn void QValueAxis::labelFormatChanged(const QString &format)
188 \fn void QValueAxis::labelFormatChanged(const QString &format)
189 Axis emits signal when \a format of axis labels has changed.
189 Axis emits signal when \a format of axis labels has changed.
190 */
190 */
191 /*!
191 /*!
192 \qmlsignal ValueAxis::labelFormatChanged(const QString &format)
192 \qmlsignal ValueAxis::labelFormatChanged(const QString &format)
193 Axis emits signal when \a format of axis labels has changed.
193 Axis emits signal when \a format of axis labels has changed.
194 */
194 */
195
195
196 /*!
196 /*!
197 Constructs an axis object which is a child of \a parent.
197 Constructs an axis object which is a child of \a parent.
198 */
198 */
199 QValueAxis::QValueAxis(QObject *parent) :
199 QValueAxis::QValueAxis(QObject *parent) :
200 QAbstractAxis(*new QValueAxisPrivate(this), parent)
200 QAbstractAxis(*new QValueAxisPrivate(this), parent)
201 {
201 {
202
202
203 }
203 }
204
204
205 /*!
205 /*!
206 \internal
206 \internal
207 */
207 */
208 QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent)
208 QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent)
209 : QAbstractAxis(d, parent)
209 : QAbstractAxis(d, parent)
210 {
210 {
211
211
212 }
212 }
213
213
214 /*!
214 /*!
215 Destroys the object
215 Destroys the object
216 */
216 */
217 QValueAxis::~QValueAxis()
217 QValueAxis::~QValueAxis()
218 {
218 {
219 Q_D(QValueAxis);
219 Q_D(QValueAxis);
220 if (d->m_chart)
220 if (d->m_chart)
221 d->m_chart->removeAxis(this);
221 d->m_chart->removeAxis(this);
222 }
222 }
223
223
224 void QValueAxis::setMin(qreal min)
224 void QValueAxis::setMin(qreal min)
225 {
225 {
226 Q_D(QValueAxis);
226 Q_D(QValueAxis);
227 setRange(min, qMax(d->m_max, min));
227 setRange(min, qMax(d->m_max, min));
228 }
228 }
229
229
230 qreal QValueAxis::min() const
230 qreal QValueAxis::min() const
231 {
231 {
232 Q_D(const QValueAxis);
232 Q_D(const QValueAxis);
233 return d->m_min;
233 return d->m_min;
234 }
234 }
235
235
236 void QValueAxis::setMax(qreal max)
236 void QValueAxis::setMax(qreal max)
237 {
237 {
238 Q_D(QValueAxis);
238 Q_D(QValueAxis);
239 setRange(qMin(d->m_min, max), max);
239 setRange(qMin(d->m_min, max), max);
240 }
240 }
241
241
242 qreal QValueAxis::max() const
242 qreal QValueAxis::max() const
243 {
243 {
244 Q_D(const QValueAxis);
244 Q_D(const QValueAxis);
245 return d->m_max;
245 return d->m_max;
246 }
246 }
247
247
248 /*!
248 /*!
249 Sets range from \a min to \a max on the axis.
249 Sets range from \a min to \a max on the axis.
250 If min is greater than max then this function returns without making any changes.
250 If min is greater than max then this function returns without making any changes.
251 */
251 */
252 void QValueAxis::setRange(qreal min, qreal max)
252 void QValueAxis::setRange(qreal min, qreal max)
253 {
253 {
254 Q_D(QValueAxis);
254 Q_D(QValueAxis);
255 d->setRange(min,max);
255 d->setRange(min,max);
256 }
256 }
257
257
258 void QValueAxis::setTickCount(int count)
258 void QValueAxis::setTickCount(int count)
259 {
259 {
260 Q_D(QValueAxis);
260 Q_D(QValueAxis);
261 if (d->m_tickCount != count && count >= 2) {
261 if (d->m_tickCount != count && count >= 2) {
262 d->m_tickCount = count;
262 d->m_tickCount = count;
263 emit tickCountChanged(count);
263 emit tickCountChanged(count);
264 }
264 }
265 }
265 }
266
266
267 int QValueAxis::tickCount() const
267 int QValueAxis::tickCount() const
268 {
268 {
269 Q_D(const QValueAxis);
269 Q_D(const QValueAxis);
270 return d->m_tickCount;
270 return d->m_tickCount;
271 }
271 }
272
272
273 void QValueAxis::setMinorTickCount(int count)
273 void QValueAxis::setMinorTickCount(int count)
274 {
274 {
275 Q_D(QValueAxis);
275 Q_D(QValueAxis);
276 if (d->m_minorTickCount != count && count >= 0) {
276 if (d->m_minorTickCount != count && count >= 0) {
277 d->m_minorTickCount = count;
277 d->m_minorTickCount = count;
278 emit minorTickCountChanged(count);
278 emit minorTickCountChanged(count);
279 }
279 }
280 }
280 }
281
281
282 int QValueAxis::minorTickCount() const
282 int QValueAxis::minorTickCount() const
283 {
283 {
284 Q_D(const QValueAxis);
284 Q_D(const QValueAxis);
285 return d->m_minorTickCount;
285 return d->m_minorTickCount;
286 }
286 }
287
287
288 void QValueAxis::setLabelFormat(const QString &format)
288 void QValueAxis::setLabelFormat(const QString &format)
289 {
289 {
290 Q_D(QValueAxis);
290 Q_D(QValueAxis);
291 d->m_format = format;
291 d->m_format = format;
292 emit labelFormatChanged(format);
292 emit labelFormatChanged(format);
293 }
293 }
294
294
295 QString QValueAxis::labelFormat() const
295 QString QValueAxis::labelFormat() const
296 {
296 {
297 Q_D(const QValueAxis);
297 Q_D(const QValueAxis);
298 return d->m_format;
298 return d->m_format;
299 }
299 }
300
300
301 /*!
301 /*!
302 Returns the type of the axis
302 Returns the type of the axis
303 */
303 */
304 QAbstractAxis::AxisType QValueAxis::type() const
304 QAbstractAxis::AxisType QValueAxis::type() const
305 {
305 {
306 return AxisTypeValue;
306 return AxisTypeValue;
307 }
307 }
308
308
309 /*!
309 /*!
310 This method modifies range and number of ticks on the axis to look "nice". Algorithm considers numbers that
310 This method modifies range and number of ticks on the axis to look "nice". Algorithm considers numbers that
311 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.
311 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.
312 This method will modify the current range and number of ticks.
312 This method will modify the current range and number of ticks.
313 \sa setRange(), setTickCount()
313 \sa setRange(), setTickCount()
314 */
314 */
315 void QValueAxis::applyNiceNumbers()
315 void QValueAxis::applyNiceNumbers()
316 {
316 {
317 Q_D(QValueAxis);
317 Q_D(QValueAxis);
318 if(d->m_applying) return;
318 if(d->m_applying) return;
319 qreal min = d->m_min;
319 qreal min = d->m_min;
320 qreal max = d->m_max;
320 qreal max = d->m_max;
321 int ticks = d->m_tickCount;
321 int ticks = d->m_tickCount;
322 AbstractDomain::looseNiceNumbers(min,max,ticks);
322 AbstractDomain::looseNiceNumbers(min,max,ticks);
323 d->m_applying=true;
323 d->m_applying=true;
324 d->setRange(min,max);
324 d->setRange(min,max);
325 setTickCount(ticks);
325 setTickCount(ticks);
326 d->m_applying=false;
326 d->m_applying=false;
327 }
327 }
328
328
329 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
329 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
330
330
331 QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q)
331 QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q)
332 : QAbstractAxisPrivate(q),
332 : QAbstractAxisPrivate(q),
333 m_min(0),
333 m_min(0),
334 m_max(0),
334 m_max(0),
335 m_tickCount(5),
335 m_tickCount(5),
336 m_minorTickCount(0),
336 m_minorTickCount(0),
337 m_format(QString::null),
337 m_format(QString::null),
338 m_applying(false)
338 m_applying(false)
339 {
339 {
340
340
341 }
341 }
342
342
343 QValueAxisPrivate::~QValueAxisPrivate()
343 QValueAxisPrivate::~QValueAxisPrivate()
344 {
344 {
345
345
346 }
346 }
347
347
348 void QValueAxisPrivate::setMin(const QVariant &min)
348 void QValueAxisPrivate::setMin(const QVariant &min)
349 {
349 {
350 Q_Q(QValueAxis);
350 Q_Q(QValueAxis);
351 bool ok;
351 bool ok;
352 qreal value = min.toReal(&ok);
352 qreal value = min.toReal(&ok);
353 if (ok)
353 if (ok)
354 q->setMin(value);
354 q->setMin(value);
355 }
355 }
356
356
357 void QValueAxisPrivate::setMax(const QVariant &max)
357 void QValueAxisPrivate::setMax(const QVariant &max)
358 {
358 {
359 Q_Q(QValueAxis);
359 Q_Q(QValueAxis);
360 bool ok;
360 bool ok;
361 qreal value = max.toReal(&ok);
361 qreal value = max.toReal(&ok);
362 if (ok)
362 if (ok)
363 q->setMax(value);
363 q->setMax(value);
364 }
364 }
365
365
366 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
366 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
367 {
367 {
368 Q_Q(QValueAxis);
368 Q_Q(QValueAxis);
369 bool ok1;
369 bool ok1;
370 bool ok2;
370 bool ok2;
371 qreal value1 = min.toReal(&ok1);
371 qreal value1 = min.toReal(&ok1);
372 qreal value2 = max.toReal(&ok2);
372 qreal value2 = max.toReal(&ok2);
373 if (ok1 && ok2)
373 if (ok1 && ok2)
374 q->setRange(value1, value2);
374 q->setRange(value1, value2);
375 }
375 }
376
376
377 void QValueAxisPrivate::setRange(qreal min, qreal max)
377 void QValueAxisPrivate::setRange(qreal min, qreal max)
378 {
378 {
379 Q_Q(QValueAxis);
379 Q_Q(QValueAxis);
380 bool changed = false;
380 bool changed = false;
381
381
382 if (min > max)
382 if (min > max)
383 return;
383 return;
384
384
385 if (!isValidValue(min, max)) {
386 qWarning() << "Attempting to set invalid range for value axis: ["
387 << min << " - " << max << "]";
388 return;
389 }
390
385 bool changeMin = false;
391 bool changeMin = false;
386 if (m_min == 0 || min == 0)
392 if (m_min == 0 || min == 0)
387 changeMin = !qFuzzyCompare(1 + m_min, 1 + min);
393 changeMin = !qFuzzyCompare(1 + m_min, 1 + min);
388 else
394 else
389 changeMin = !qFuzzyCompare(m_min, min);
395 changeMin = !qFuzzyCompare(m_min, min);
390
396
391 bool changeMax = false;
397 bool changeMax = false;
392 if (m_max == 0 || max == 0)
398 if (m_max == 0 || max == 0)
393 changeMax = !qFuzzyCompare(1 + m_max, 1 + max);
399 changeMax = !qFuzzyCompare(1 + m_max, 1 + max);
394 else
400 else
395 changeMax = !qFuzzyCompare(m_max, max);
401 changeMax = !qFuzzyCompare(m_max, max);
396
402
397 if (changeMin) {
403 if (changeMin) {
398 m_min = min;
404 m_min = min;
399 changed = true;
405 changed = true;
400 emit q->minChanged(min);
406 emit q->minChanged(min);
401 }
407 }
402
408
403 if (changeMax) {
409 if (changeMax) {
404 m_max = max;
410 m_max = max;
405 changed = true;
411 changed = true;
406 emit q->maxChanged(max);
412 emit q->maxChanged(max);
407 }
413 }
408
414
409 if (changed) {
415 if (changed) {
410 emit rangeChanged(min,max);
416 emit rangeChanged(min,max);
411 emit q->rangeChanged(min, max);
417 emit q->rangeChanged(min, max);
412 }
418 }
413 }
419 }
414
420
415 void QValueAxisPrivate::initializeGraphics(QGraphicsItem *parent)
421 void QValueAxisPrivate::initializeGraphics(QGraphicsItem *parent)
416 {
422 {
417 Q_Q(QValueAxis);
423 Q_Q(QValueAxis);
418 ChartAxisElement *axis(0);
424 ChartAxisElement *axis(0);
419
425
420 if (m_chart->chartType() == QChart::ChartTypeCartesian) {
426 if (m_chart->chartType() == QChart::ChartTypeCartesian) {
421 if (orientation() == Qt::Vertical)
427 if (orientation() == Qt::Vertical)
422 axis = new ChartValueAxisY(q,parent);
428 axis = new ChartValueAxisY(q,parent);
423 if (orientation() == Qt::Horizontal)
429 if (orientation() == Qt::Horizontal)
424 axis = new ChartValueAxisX(q,parent);
430 axis = new ChartValueAxisX(q,parent);
425 }
431 }
426
432
427 if (m_chart->chartType() == QChart::ChartTypePolar) {
433 if (m_chart->chartType() == QChart::ChartTypePolar) {
428 if (orientation() == Qt::Vertical)
434 if (orientation() == Qt::Vertical)
429 axis = new PolarChartValueAxisRadial(q, parent);
435 axis = new PolarChartValueAxisRadial(q, parent);
430 if (orientation() == Qt::Horizontal)
436 if (orientation() == Qt::Horizontal)
431 axis = new PolarChartValueAxisAngular(q, parent);
437 axis = new PolarChartValueAxisAngular(q, parent);
432 }
438 }
433
439
434 m_item.reset(axis);
440 m_item.reset(axis);
435 QAbstractAxisPrivate::initializeGraphics(parent);
441 QAbstractAxisPrivate::initializeGraphics(parent);
436 }
442 }
437
443
438
444
439 void QValueAxisPrivate::initializeDomain(AbstractDomain *domain)
445 void QValueAxisPrivate::initializeDomain(AbstractDomain *domain)
440 {
446 {
441 if (orientation() == Qt::Vertical) {
447 if (orientation() == Qt::Vertical) {
442 if (!qFuzzyIsNull(m_max - m_min))
448 if (!qFuzzyIsNull(m_max - m_min))
443 domain->setRangeY(m_min, m_max);
449 domain->setRangeY(m_min, m_max);
444 else
450 else
445 setRange(domain->minY(), domain->maxY());
451 setRange(domain->minY(), domain->maxY());
446 }
452 }
447 if (orientation() == Qt::Horizontal) {
453 if (orientation() == Qt::Horizontal) {
448 if (!qFuzzyIsNull(m_max - m_min))
454 if (!qFuzzyIsNull(m_max - m_min))
449 domain->setRangeX(m_min, m_max);
455 domain->setRangeX(m_min, m_max);
450 else
456 else
451 setRange(domain->minX(), domain->maxX());
457 setRange(domain->minX(), domain->maxX());
452 }
458 }
453 }
459 }
454
460
455 #include "moc_qvalueaxis.cpp"
461 #include "moc_qvalueaxis.cpp"
456 #include "moc_qvalueaxis_p.cpp"
462 #include "moc_qvalueaxis_p.cpp"
457
463
458 QT_CHARTS_END_NAMESPACE
464 QT_CHARTS_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now