##// END OF EJS Templates
Fix niceNumbers legacy support
Michal Klocek -
r2314:9f65e31516fe
parent child
Show More
@@ -1,61 +1,65
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 "chart.h"
21 #include "chart.h"
22 #include "chartview.h"
22 #include "chartview.h"
23 #include <QApplication>
23 #include <QApplication>
24 #include <QMainWindow>
24 #include <QMainWindow>
25 #include <qmath.h>
25 #include <qmath.h>
26 #include <QLineSeries>
26 #include <QLineSeries>
27 #include <QValueAxis>
27
28
28 QTCOMMERCIALCHART_USE_NAMESPACE
29 QTCOMMERCIALCHART_USE_NAMESPACE
29
30
30 int main(int argc, char *argv[])
31 int main(int argc, char *argv[])
31 {
32 {
32 QApplication a(argc, argv);
33 QApplication a(argc, argv);
33
34
34 //![1]
35 //![1]
35 QLineSeries *series = new QLineSeries();
36 QLineSeries *series = new QLineSeries();
36 for (int i = 0; i < 500; i++) {
37 for (int i = 0; i < 500; i++) {
37 QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
38 QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
38 p.ry() += qrand() % 20;
39 p.ry() += qrand() % 20;
39 *series << p;
40 *series << p;
40 }
41 }
41 //![1]
42 //![1]
42
43
43 Chart *chart = new Chart();
44 Chart *chart = new Chart();
44 chart->addSeries(series);
45 chart->addSeries(series);
45 chart->setTitle("Zoom in/out example");
46 chart->setTitle("Zoom in/out example");
46 chart->setAnimationOptions(QChart::SeriesAnimations);
47 chart->setAnimationOptions(QChart::SeriesAnimations);
47 chart->legend()->hide();
48 chart->legend()->hide();
48 chart->createDefaultAxes();
49 chart->createDefaultAxes();
50 qobject_cast<QValueAxis*>(chart->axisX())->setNiceNumbersEnabled(true);
49
51
50 ChartView *chartView = new ChartView(chart);
52 ChartView *chartView = new ChartView(chart);
51 chartView->setRenderHint(QPainter::Antialiasing);
53 chartView->setRenderHint(QPainter::Antialiasing);
52
54
53 QMainWindow window;
55 QMainWindow window;
54 window.setCentralWidget(chartView);
56 window.setCentralWidget(chartView);
55 window.resize(400, 300);
57 window.resize(400, 300);
56 window.grabGesture(Qt::PanGesture);
58 window.grabGesture(Qt::PanGesture);
57 window.grabGesture(Qt::PinchGesture);
59 window.grabGesture(Qt::PinchGesture);
58 window.show();
60 window.show();
59
61
62 qobject_cast<QValueAxis*>(chart->axisX())->setMax(600);
63
60 return a.exec();
64 return a.exec();
61 }
65 }
@@ -1,394 +1,409
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 for 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 for 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 number of ticks 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 number of ticks 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 \property QValueAxis::niceNumbersEnabled
155 \property QValueAxis::niceNumbersEnabled
156 Whether the nice numbers algorithm is enabled or not for the axis.
156 Whether the nice numbers algorithm is enabled or not for the axis.
157 */
157 */
158
158
159 /*!
159 /*!
160 \qmlproperty bool ValueAxis::niceNumbersEnabled
160 \qmlproperty bool ValueAxis::niceNumbersEnabled
161 Whether the nice numbers algorithm is enabled or not for the axis.
161 Whether the nice numbers algorithm is enabled or not for the axis.
162 */
162 */
163
163
164 /*!
164 /*!
165 Constructs an axis object which is a child of \a parent.
165 Constructs an axis object which is a child of \a parent.
166 */
166 */
167 QValueAxis::QValueAxis(QObject *parent) :
167 QValueAxis::QValueAxis(QObject *parent) :
168 QAbstractAxis(*new QValueAxisPrivate(this), parent)
168 QAbstractAxis(*new QValueAxisPrivate(this), parent)
169 {
169 {
170
170
171 }
171 }
172
172
173 /*!
173 /*!
174 \internal
174 \internal
175 */
175 */
176 QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent)
176 QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent)
177 : QAbstractAxis(d, parent)
177 : QAbstractAxis(d, parent)
178 {
178 {
179
179
180 }
180 }
181
181
182 /*!
182 /*!
183 Destroys the object
183 Destroys the object
184 */
184 */
185 QValueAxis::~QValueAxis()
185 QValueAxis::~QValueAxis()
186 {
186 {
187 Q_D(QValueAxis);
187 Q_D(QValueAxis);
188 if (d->m_chart)
188 if (d->m_chart)
189 d->m_chart->removeAxis(this);
189 d->m_chart->removeAxis(this);
190 }
190 }
191
191
192 void QValueAxis::setMin(qreal min)
192 void QValueAxis::setMin(qreal min)
193 {
193 {
194 Q_D(QValueAxis);
194 Q_D(QValueAxis);
195 setRange(min, qMax(d->m_max, min));
195 setRange(min, qMax(d->m_max, min));
196 }
196 }
197
197
198 qreal QValueAxis::min() const
198 qreal QValueAxis::min() const
199 {
199 {
200 Q_D(const QValueAxis);
200 Q_D(const QValueAxis);
201 return d->m_min;
201 return d->m_min;
202 }
202 }
203
203
204 void QValueAxis::setMax(qreal max)
204 void QValueAxis::setMax(qreal max)
205 {
205 {
206 Q_D(QValueAxis);
206 Q_D(QValueAxis);
207 setRange(qMin(d->m_min, max), max);
207 setRange(qMin(d->m_min, max), max);
208 }
208 }
209
209
210 qreal QValueAxis::max() const
210 qreal QValueAxis::max() const
211 {
211 {
212 Q_D(const QValueAxis);
212 Q_D(const QValueAxis);
213 return d->m_max;
213 return d->m_max;
214 }
214 }
215
215
216 /*!
216 /*!
217 Sets range from \a min to \a max on the axis.
217 Sets range from \a min to \a max on the axis.
218 If min is greater than max then this function returns without making any changes.
218 If min is greater than max then this function returns without making any changes.
219 */
219 */
220 void QValueAxis::setRange(qreal min, qreal max)
220 void QValueAxis::setRange(qreal min, qreal max)
221 {
221 {
222 Q_D(QValueAxis);
222 Q_D(QValueAxis);
223 d->setRange(min,max);
223 d->setRange(min,max);
224 }
224 }
225
225
226 void QValueAxis::setTickCount(int count)
226 void QValueAxis::setTickCount(int count)
227 {
227 {
228 Q_D(QValueAxis);
228 Q_D(QValueAxis);
229 if (d->m_tickCount != count && count >= 2) {
229 if (d->m_tickCount != count && count >= 2) {
230 d->m_tickCount = count;
230 d->m_tickCount = count;
231 emit tickCountChanged(count);
231 emit tickCountChanged(count);
232 }
232 }
233 }
233 }
234
234
235 int QValueAxis::tickCount() const
235 int QValueAxis::tickCount() const
236 {
236 {
237 Q_D(const QValueAxis);
237 Q_D(const QValueAxis);
238 return d->m_tickCount;
238 return d->m_tickCount;
239 }
239 }
240
240
241 void QValueAxis::setNiceNumbersEnabled(bool enable)
241 void QValueAxis::setNiceNumbersEnabled(bool enable)
242 {
242 {
243 Q_UNUSED(enable);
243 Q_D(QValueAxis);
244 qWarning()<<"This function is depreciated.Use applyNiceNumbers().";
244 qWarning()<<"This function is depreciated, it can lead to unexpected behaviour.Use applyNiceNumbers(). ";
245 if(enable) {
246 QObject::connect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers()));
247 QObject::connect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers()));
248 applyNiceNumbers();
249 }
250 else {
251 QObject::disconnect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers()));
252 QObject::disconnect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers()));
253 }
254 d->m_niceNumbersEnabled=true;
245 }
255 }
246
256
247 bool QValueAxis::niceNumbersEnabled() const
257 bool QValueAxis::niceNumbersEnabled() const
248 {
258 {
259 Q_D(const QValueAxis);
249 qWarning()<<"This function is depreciated.Use applyNiceNumbers().";
260 qWarning()<<"This function is depreciated.Use applyNiceNumbers().";
250 return false;
261 return d->m_niceNumbersEnabled;
251 }
262 }
252
263
253 void QValueAxis::setLabelFormat(const QString &format)
264 void QValueAxis::setLabelFormat(const QString &format)
254 {
265 {
255 Q_D(QValueAxis);
266 Q_D(QValueAxis);
256 d->m_format = format;
267 d->m_format = format;
257 }
268 }
258
269
259 QString QValueAxis::labelFormat() const
270 QString QValueAxis::labelFormat() const
260 {
271 {
261 Q_D(const QValueAxis);
272 Q_D(const QValueAxis);
262 return d->m_format;
273 return d->m_format;
263 }
274 }
264
275
265 /*!
276 /*!
266 Returns the type of the axis
277 Returns the type of the axis
267 */
278 */
268 QAbstractAxis::AxisType QValueAxis::type() const
279 QAbstractAxis::AxisType QValueAxis::type() const
269 {
280 {
270 return AxisTypeValue;
281 return AxisTypeValue;
271 }
282 }
272
283
273 void QValueAxis::applyNiceNumbers()
284 void QValueAxis::applyNiceNumbers()
274 {
285 {
275 Q_D(QValueAxis);
286 Q_D(QValueAxis);
287 if(d->m_applying) return;
276 qreal min = d->m_min;
288 qreal min = d->m_min;
277 qreal max = d->m_max;
289 qreal max = d->m_max;
278 int ticks = d->m_tickCount;
290 int ticks = d->m_tickCount;
279 AbstractDomain::looseNiceNumbers(min,max,ticks);
291 AbstractDomain::looseNiceNumbers(min,max,ticks);
292 d->m_applying=true;
280 d->setRange(min,max);
293 d->setRange(min,max);
281 setTickCount(ticks);
294 setTickCount(ticks);
295 d->m_applying=false;
282 }
296 }
283
297
284 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
298 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
285
299
286 QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q)
300 QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q)
287 : QAbstractAxisPrivate(q),
301 : QAbstractAxisPrivate(q),
288 m_min(0),
302 m_min(0),
289 m_max(0),
303 m_max(0),
290 m_tickCount(5),
304 m_tickCount(5),
291 m_format(QString::null)
305 m_format(QString::null),
306 m_applying(false),
307 m_niceNumbersEnabled(false)
292 {
308 {
293
309
294 }
310 }
295
311
296 QValueAxisPrivate::~QValueAxisPrivate()
312 QValueAxisPrivate::~QValueAxisPrivate()
297 {
313 {
298
314
299 }
315 }
300
316
301 void QValueAxisPrivate::setMin(const QVariant &min)
317 void QValueAxisPrivate::setMin(const QVariant &min)
302 {
318 {
303 Q_Q(QValueAxis);
319 Q_Q(QValueAxis);
304 bool ok;
320 bool ok;
305 qreal value = min.toReal(&ok);
321 qreal value = min.toReal(&ok);
306 if (ok)
322 if (ok)
307 q->setMin(value);
323 q->setMin(value);
308 }
324 }
309
325
310 void QValueAxisPrivate::setMax(const QVariant &max)
326 void QValueAxisPrivate::setMax(const QVariant &max)
311 {
327 {
312
313 Q_Q(QValueAxis);
328 Q_Q(QValueAxis);
314 bool ok;
329 bool ok;
315 qreal value = max.toReal(&ok);
330 qreal value = max.toReal(&ok);
316 if (ok)
331 if (ok)
317 q->setMax(value);
332 q->setMax(value);
318 }
333 }
319
334
320 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
335 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
321 {
336 {
322 Q_Q(QValueAxis);
337 Q_Q(QValueAxis);
323 bool ok1;
338 bool ok1;
324 bool ok2;
339 bool ok2;
325 qreal value1 = min.toReal(&ok1);
340 qreal value1 = min.toReal(&ok1);
326 qreal value2 = max.toReal(&ok2);
341 qreal value2 = max.toReal(&ok2);
327 if (ok1 && ok2)
342 if (ok1 && ok2)
328 q->setRange(value1, value2);
343 q->setRange(value1, value2);
329 }
344 }
330
345
331 void QValueAxisPrivate::setRange(qreal min, qreal max)
346 void QValueAxisPrivate::setRange(qreal min, qreal max)
332 {
347 {
333 Q_Q(QValueAxis);
348 Q_Q(QValueAxis);
334 bool changed = false;
349 bool changed = false;
335
350
336 if (min > max)
351 if (min > max)
337 return;
352 return;
338
353
339 if (!qFuzzyCompare(m_min,min)) {
354 if (!qFuzzyCompare(m_min,min)) {
340 m_min = min;
355 m_min = min;
341 changed = true;
356 changed = true;
342 emit q->minChanged(min);
357 emit q->minChanged(min);
343 }
358 }
344
359
345 if (!qFuzzyCompare(m_max,max)) {
360 if (!qFuzzyCompare(m_max,max)) {
346 m_max = max;
361 m_max = max;
347 changed = true;
362 changed = true;
348 emit q->maxChanged(max);
363 emit q->maxChanged(max);
349 }
364 }
350
365
351 if (changed) {
366 if (changed) {
352 emit q->rangeChanged(min, max);
353 emit rangeChanged(min,max);
367 emit rangeChanged(min,max);
368 emit q->rangeChanged(min, max);
354 }
369 }
355 }
370 }
356
371
357 void QValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
372 void QValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
358 {
373 {
359 Q_Q(QValueAxis);
374 Q_Q(QValueAxis);
360 ChartAxis* axis(0);
375 ChartAxis* axis(0);
361 if (orientation() == Qt::Vertical)
376 if (orientation() == Qt::Vertical)
362 axis = new ChartValueAxisY(q,parent);
377 axis = new ChartValueAxisY(q,parent);
363 if (orientation() == Qt::Horizontal)
378 if (orientation() == Qt::Horizontal)
364 axis = new ChartValueAxisX(q,parent);
379 axis = new ChartValueAxisX(q,parent);
365
380
366 m_item.reset(axis);
381 m_item.reset(axis);
367 QAbstractAxisPrivate::initializeGraphics(parent);
382 QAbstractAxisPrivate::initializeGraphics(parent);
368 }
383 }
369
384
370
385
371 void QValueAxisPrivate::initializeDomain(AbstractDomain *domain)
386 void QValueAxisPrivate::initializeDomain(AbstractDomain *domain)
372 {
387 {
373 if (orientation() == Qt::Vertical) {
388 if (orientation() == Qt::Vertical) {
374 if(!qFuzzyIsNull(m_max - m_min)) {
389 if(!qFuzzyIsNull(m_max - m_min)) {
375 domain->setRangeY(m_min, m_max);
390 domain->setRangeY(m_min, m_max);
376 }
391 }
377 else {
392 else {
378 setRange(domain->minY(), domain->maxY());
393 setRange(domain->minY(), domain->maxY());
379 }
394 }
380 }
395 }
381 if (orientation() == Qt::Horizontal) {
396 if (orientation() == Qt::Horizontal) {
382 if(!qFuzzyIsNull(m_max - m_min)) {
397 if(!qFuzzyIsNull(m_max - m_min)) {
383 domain->setRangeX(m_min, m_max);
398 domain->setRangeX(m_min, m_max);
384 }
399 }
385 else {
400 else {
386 setRange(domain->minX(), domain->maxX());
401 setRange(domain->minX(), domain->maxX());
387 }
402 }
388 }
403 }
389 }
404 }
390
405
391 #include "moc_qvalueaxis.cpp"
406 #include "moc_qvalueaxis.cpp"
392 #include "moc_qvalueaxis_p.cpp"
407 #include "moc_qvalueaxis_p.cpp"
393
408
394 QTCOMMERCIALCHART_END_NAMESPACE
409 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,68 +1,70
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QVALUEAXIS_P_H
30 #ifndef QVALUEAXIS_P_H
31 #define QVALUEAXIS_P_H
31 #define QVALUEAXIS_P_H
32
32
33 #include "qvalueaxis.h"
33 #include "qvalueaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qabstractaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QValueAxisPrivate : public QAbstractAxisPrivate
38 class QValueAxisPrivate : public QAbstractAxisPrivate
39 {
39 {
40 Q_OBJECT
40 Q_OBJECT
41 public:
41 public:
42 QValueAxisPrivate(QValueAxis *q);
42 QValueAxisPrivate(QValueAxis *q);
43 ~QValueAxisPrivate();
43 ~QValueAxisPrivate();
44
44
45 public:
45 public:
46 void initializeGraphics(QGraphicsItem* parent);
46 void initializeGraphics(QGraphicsItem* parent);
47 void initializeDomain(AbstractDomain *domain);
47 void initializeDomain(AbstractDomain *domain);
48
48
49 qreal min() { return m_min; };
49 qreal min() { return m_min; };
50 qreal max() { return m_max; };
50 qreal max() { return m_max; };
51 void setRange(qreal min,qreal max);
51 void setRange(qreal min,qreal max);
52
52
53 protected:
53 protected:
54 void setMin(const QVariant &min);
54 void setMin(const QVariant &min);
55 void setMax(const QVariant &max);
55 void setMax(const QVariant &max);
56 void setRange(const QVariant &min, const QVariant &max);
56 void setRange(const QVariant &min, const QVariant &max);
57
57
58 private:
58 private:
59 qreal m_min;
59 qreal m_min;
60 qreal m_max;
60 qreal m_max;
61 int m_tickCount;
61 int m_tickCount;
62 QString m_format;
62 QString m_format;
63 bool m_applying;
64 bool m_niceNumbersEnabled; //TODO: this depreciated
63 Q_DECLARE_PUBLIC(QValueAxis)
65 Q_DECLARE_PUBLIC(QValueAxis)
64 };
66 };
65
67
66 QTCOMMERCIALCHART_END_NAMESPACE
68 QTCOMMERCIALCHART_END_NAMESPACE
67
69
68 #endif // QVALUEAXIS_P_H
70 #endif // QVALUEAXIS_P_H
General Comments 0
You need to be logged in to leave comments. Login now