@@ -1,397 +1,408 | |||||
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 "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 | /*! |
|
31 | /*! | |
32 | \class QValueAxis |
|
32 | \class QValueAxis | |
33 | \brief The QValueAxis class is used for manipulating chart's axis. |
|
33 | \brief The QValueAxis class is used for manipulating chart's axis. | |
34 | \mainclass |
|
34 | \mainclass | |
35 |
|
35 | |||
36 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
36 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
37 | Values of axis are drawn to position of ticks |
|
37 | Values of axis are drawn to position of ticks | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 | \qmlclass ValueAxis QValueAxis |
|
41 | \qmlclass ValueAxis QValueAxis | |
42 | \brief The ValueAxis element is used for manipulating chart's axes |
|
42 | \brief The ValueAxis element is used for manipulating chart's axes | |
43 |
|
43 | |||
44 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
44 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
45 | Values of axis are drawn to position of ticks |
|
45 | Values of axis are drawn to position of ticks | |
46 |
|
46 | |||
47 | To access Axes you can use ChartView API. For example: |
|
47 | To access Axes you can use ChartView API. For example: | |
48 | \code |
|
48 | \code | |
49 | ChartView { |
|
49 | ChartView { | |
50 | ValueAxis { |
|
50 | ValueAxis { | |
51 | id: xAxis |
|
51 | id: xAxis | |
52 | min: 0 |
|
52 | min: 0 | |
53 | max: 10 |
|
53 | max: 10 | |
54 | } |
|
54 | } | |
55 | // Add a few series... |
|
55 | // Add a few series... | |
56 | } |
|
56 | } | |
57 | \endcode |
|
57 | \endcode | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \property QValueAxis::min |
|
61 | \property QValueAxis::min | |
62 | Defines the minimum value on the axis. |
|
62 | Defines the minimum value on the axis. | |
63 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
63 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
64 | */ |
|
64 | */ | |
65 | /*! |
|
65 | /*! | |
66 | \qmlproperty real ValueAxis::min |
|
66 | \qmlproperty real ValueAxis::min | |
67 | Defines the minimum value on the axis. |
|
67 | Defines the minimum value on the axis. | |
68 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
68 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \property QValueAxis::max |
|
72 | \property QValueAxis::max | |
73 | Defines the maximum value on the axis. |
|
73 | Defines the maximum value on the axis. | |
74 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
74 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
75 | */ |
|
75 | */ | |
76 | /*! |
|
76 | /*! | |
77 | \qmlproperty real ValueAxis::max |
|
77 | \qmlproperty real ValueAxis::max | |
78 | Defines the maximum value on the axis. |
|
78 | Defines the maximum value on the axis. | |
79 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
79 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
80 | */ |
|
80 | */ | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
|
83 | \property QValueAxis::labelFormat | |||
|
84 | Defines the label format for the axis. | |||
|
85 | See QString::sprintf() for the details. | |||
|
86 | */ | |||
|
87 | /*! | |||
|
88 | \qmlproperty real ValueAxis::labelFormat | |||
|
89 | Defines the label format for the axis. | |||
|
90 | See QString::sprintf() for the details. | |||
|
91 | */ | |||
|
92 | ||||
|
93 | /*! | |||
83 | \fn void QValueAxis::minChanged(qreal min) |
|
94 | \fn void QValueAxis::minChanged(qreal min) | |
84 | Axis emits signal when \a min of axis has changed. |
|
95 | Axis emits signal when \a min of axis has changed. | |
85 | */ |
|
96 | */ | |
86 | /*! |
|
97 | /*! | |
87 | \qmlsignal ValueAxis::onMinChanged(real min) |
|
98 | \qmlsignal ValueAxis::onMinChanged(real min) | |
88 | Axis emits signal when \a min of axis has changed. |
|
99 | Axis emits signal when \a min of axis has changed. | |
89 | */ |
|
100 | */ | |
90 |
|
101 | |||
91 | /*! |
|
102 | /*! | |
92 | \fn void QValueAxis::maxChanged(qreal max) |
|
103 | \fn void QValueAxis::maxChanged(qreal max) | |
93 | Axis emits signal when \a max of axis has changed. |
|
104 | Axis emits signal when \a max of axis has changed. | |
94 | */ |
|
105 | */ | |
95 | /*! |
|
106 | /*! | |
96 | \qmlsignal ValueAxis::onMaxChanged(real max) |
|
107 | \qmlsignal ValueAxis::onMaxChanged(real max) | |
97 | Axis emits signal when \a max of axis has changed. |
|
108 | Axis emits signal when \a max of axis has changed. | |
98 | */ |
|
109 | */ | |
99 |
|
110 | |||
100 | /*! |
|
111 | /*! | |
101 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) |
|
112 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) | |
102 | Axis emits signal when \a min or \a max of axis has changed. |
|
113 | Axis emits signal when \a min or \a max of axis has changed. | |
103 | */ |
|
114 | */ | |
104 |
|
115 | |||
105 | /*! |
|
116 | /*! | |
106 | \property QValueAxis::tickCount |
|
117 | \property QValueAxis::tickCount | |
107 | The number of tick marks for the axis. |
|
118 | The number of tick marks for the axis. | |
108 | */ |
|
119 | */ | |
109 |
|
120 | |||
110 | /*! |
|
121 | /*! | |
111 | \qmlproperty int ValueAxis::tickCount |
|
122 | \qmlproperty int ValueAxis::tickCount | |
112 | The number of tick marks for the axis. |
|
123 | The number of tick marks for the axis. | |
113 | */ |
|
124 | */ | |
114 |
|
125 | |||
115 | /*! |
|
126 | /*! | |
116 | \property QValueAxis::niceNumbersEnabled |
|
127 | \property QValueAxis::niceNumbersEnabled | |
117 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
128 | Whether the nice numbers algorithm is enabled or not for the axis. | |
118 | */ |
|
129 | */ | |
119 |
|
130 | |||
120 | /*! |
|
131 | /*! | |
121 | \qmlproperty bool ValueAxis::niceNumbersEnabled |
|
132 | \qmlproperty bool ValueAxis::niceNumbersEnabled | |
122 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
133 | Whether the nice numbers algorithm is enabled or not for the axis. | |
123 | */ |
|
134 | */ | |
124 |
|
135 | |||
125 | /*! |
|
136 | /*! | |
126 | Constructs an axis object which is a child of \a parent. |
|
137 | Constructs an axis object which is a child of \a parent. | |
127 | */ |
|
138 | */ | |
128 | QValueAxis::QValueAxis(QObject *parent) : |
|
139 | QValueAxis::QValueAxis(QObject *parent) : | |
129 | QAbstractAxis(*new QValueAxisPrivate(this),parent) |
|
140 | QAbstractAxis(*new QValueAxisPrivate(this),parent) | |
130 | { |
|
141 | { | |
131 |
|
142 | |||
132 | } |
|
143 | } | |
133 |
|
144 | |||
134 | /*! |
|
145 | /*! | |
135 | \internal |
|
146 | \internal | |
136 | */ |
|
147 | */ | |
137 | QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) |
|
148 | QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) | |
138 | { |
|
149 | { | |
139 |
|
150 | |||
140 | } |
|
151 | } | |
141 |
|
152 | |||
142 | /*! |
|
153 | /*! | |
143 | Destroys the object |
|
154 | Destroys the object | |
144 | */ |
|
155 | */ | |
145 | QValueAxis::~QValueAxis() |
|
156 | QValueAxis::~QValueAxis() | |
146 | { |
|
157 | { | |
147 | Q_D(QValueAxis); |
|
158 | Q_D(QValueAxis); | |
148 | if(d->m_dataset) { |
|
159 | if(d->m_dataset) { | |
149 | d->m_dataset->removeAxis(this); |
|
160 | d->m_dataset->removeAxis(this); | |
150 | } |
|
161 | } | |
151 | } |
|
162 | } | |
152 |
|
163 | |||
153 | void QValueAxis::setMin(qreal min) |
|
164 | void QValueAxis::setMin(qreal min) | |
154 | { |
|
165 | { | |
155 | Q_D(QValueAxis); |
|
166 | Q_D(QValueAxis); | |
156 | setRange(min, qMax(d->m_max, min)); |
|
167 | setRange(min, qMax(d->m_max, min)); | |
157 | } |
|
168 | } | |
158 |
|
169 | |||
159 | qreal QValueAxis::min() const |
|
170 | qreal QValueAxis::min() const | |
160 | { |
|
171 | { | |
161 | Q_D(const QValueAxis); |
|
172 | Q_D(const QValueAxis); | |
162 | return d->m_min; |
|
173 | return d->m_min; | |
163 | } |
|
174 | } | |
164 |
|
175 | |||
165 | void QValueAxis::setMax(qreal max) |
|
176 | void QValueAxis::setMax(qreal max) | |
166 | { |
|
177 | { | |
167 | Q_D(QValueAxis); |
|
178 | Q_D(QValueAxis); | |
168 | setRange(qMin(d->m_min, max), max); |
|
179 | setRange(qMin(d->m_min, max), max); | |
169 | } |
|
180 | } | |
170 |
|
181 | |||
171 | qreal QValueAxis::max() const |
|
182 | qreal QValueAxis::max() const | |
172 | { |
|
183 | { | |
173 | Q_D(const QValueAxis); |
|
184 | Q_D(const QValueAxis); | |
174 | return d->m_max; |
|
185 | return d->m_max; | |
175 | } |
|
186 | } | |
176 |
|
187 | |||
177 | /*! |
|
188 | /*! | |
178 | Sets range from \a min to \a max on the axis. |
|
189 | Sets range from \a min to \a max on the axis. | |
179 | If min is greater than max then this function returns without making any changes. |
|
190 | If min is greater than max then this function returns without making any changes. | |
180 | */ |
|
191 | */ | |
181 | void QValueAxis::setRange(qreal min, qreal max) |
|
192 | void QValueAxis::setRange(qreal min, qreal max) | |
182 | { |
|
193 | { | |
183 | Q_D(QValueAxis); |
|
194 | Q_D(QValueAxis); | |
184 | bool changed = false; |
|
195 | bool changed = false; | |
185 |
|
196 | |||
186 | if (min > max) return; |
|
197 | if (min > max) return; | |
187 |
|
198 | |||
188 | if(d->m_niceNumbers) { |
|
199 | if(d->m_niceNumbers) { | |
189 | int ticks = d->m_tickCount; |
|
200 | int ticks = d->m_tickCount; | |
190 | d->looseNiceNumbers(min, max, ticks); |
|
201 | d->looseNiceNumbers(min, max, ticks); | |
191 | if(ticks!=d->m_tickCount) setTickCount(ticks); |
|
202 | if(ticks!=d->m_tickCount) setTickCount(ticks); | |
192 | } |
|
203 | } | |
193 |
|
204 | |||
194 | if (!qFuzzyIsNull(d->m_min - min)) { |
|
205 | if (!qFuzzyIsNull(d->m_min - min)) { | |
195 | d->m_min = min; |
|
206 | d->m_min = min; | |
196 | changed = true; |
|
207 | changed = true; | |
197 | emit minChanged(min); |
|
208 | emit minChanged(min); | |
198 | } |
|
209 | } | |
199 |
|
210 | |||
200 | if (!qFuzzyIsNull(d->m_max - max)) { |
|
211 | if (!qFuzzyIsNull(d->m_max - max)) { | |
201 | d->m_max = max; |
|
212 | d->m_max = max; | |
202 | changed = true; |
|
213 | changed = true; | |
203 | emit maxChanged(max); |
|
214 | emit maxChanged(max); | |
204 | } |
|
215 | } | |
205 |
|
216 | |||
206 | if (changed) { |
|
217 | if (changed) { | |
207 | emit rangeChanged(min,max); |
|
218 | emit rangeChanged(min,max); | |
208 | d->emitUpdated(); |
|
219 | d->emitUpdated(); | |
209 | } |
|
220 | } | |
210 | } |
|
221 | } | |
211 |
|
222 | |||
212 | /*! |
|
223 | /*! | |
213 | Sets \a count for ticks on the axis. |
|
224 | Sets \a count for ticks on the axis. | |
214 | */ |
|
225 | */ | |
215 | void QValueAxis::setTickCount(int count) |
|
226 | void QValueAxis::setTickCount(int count) | |
216 | { |
|
227 | { | |
217 | Q_D(QValueAxis); |
|
228 | Q_D(QValueAxis); | |
218 | if (d->m_tickCount != count && count >=2) { |
|
229 | if (d->m_tickCount != count && count >=2) { | |
219 | d->m_tickCount = count; |
|
230 | d->m_tickCount = count; | |
220 | d->emitUpdated(); |
|
231 | d->emitUpdated(); | |
221 | } |
|
232 | } | |
222 | } |
|
233 | } | |
223 |
|
234 | |||
224 | /*! |
|
235 | /*! | |
225 | \fn int QValueAxis::tickCount() const |
|
236 | \fn int QValueAxis::tickCount() const | |
226 | Return number of ticks on the axis |
|
237 | Return number of ticks on the axis | |
227 | */ |
|
238 | */ | |
228 | int QValueAxis::tickCount() const |
|
239 | int QValueAxis::tickCount() const | |
229 | { |
|
240 | { | |
230 | Q_D(const QValueAxis); |
|
241 | Q_D(const QValueAxis); | |
231 | return d->m_tickCount; |
|
242 | return d->m_tickCount; | |
232 | } |
|
243 | } | |
233 |
|
244 | |||
234 | void QValueAxis::setNiceNumbersEnabled(bool enable) |
|
245 | void QValueAxis::setNiceNumbersEnabled(bool enable) | |
235 | { |
|
246 | { | |
236 | Q_D(QValueAxis); |
|
247 | Q_D(QValueAxis); | |
237 | if (d->m_niceNumbers != enable){ |
|
248 | if (d->m_niceNumbers != enable){ | |
238 | d->m_niceNumbers = enable; |
|
249 | d->m_niceNumbers = enable; | |
239 | if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) { |
|
250 | if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) { | |
240 | setRange(d->m_min,d->m_max); |
|
251 | setRange(d->m_min,d->m_max); | |
241 | } |
|
252 | } | |
242 | } |
|
253 | } | |
243 | } |
|
254 | } | |
244 |
|
255 | |||
245 | bool QValueAxis::niceNumbersEnabled() const |
|
256 | bool QValueAxis::niceNumbersEnabled() const | |
246 | { |
|
257 | { | |
247 | Q_D(const QValueAxis); |
|
258 | Q_D(const QValueAxis); | |
248 | return d->m_niceNumbers; |
|
259 | return d->m_niceNumbers; | |
249 | } |
|
260 | } | |
250 |
|
261 | |||
251 | void QValueAxis::setLabelFormat(const QString &format) |
|
262 | void QValueAxis::setLabelFormat(const QString &format) | |
252 | { |
|
263 | { | |
253 | Q_D(QValueAxis); |
|
264 | Q_D(QValueAxis); | |
254 | d->m_format = format; |
|
265 | d->m_format = format; | |
255 | } |
|
266 | } | |
256 |
|
267 | |||
257 | QString QValueAxis::labelFormat() const |
|
268 | QString QValueAxis::labelFormat() const | |
258 | { |
|
269 | { | |
259 | Q_D(const QValueAxis); |
|
270 | Q_D(const QValueAxis); | |
260 | return d->m_format; |
|
271 | return d->m_format; | |
261 | } |
|
272 | } | |
262 |
|
273 | |||
263 | /*! |
|
274 | /*! | |
264 | Returns the type of the axis |
|
275 | Returns the type of the axis | |
265 | */ |
|
276 | */ | |
266 | QAbstractAxis::AxisType QValueAxis::type() const |
|
277 | QAbstractAxis::AxisType QValueAxis::type() const | |
267 | { |
|
278 | { | |
268 | return AxisTypeValue; |
|
279 | return AxisTypeValue; | |
269 | } |
|
280 | } | |
270 |
|
281 | |||
271 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
282 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
272 |
|
283 | |||
273 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q): |
|
284 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q): | |
274 | QAbstractAxisPrivate(q), |
|
285 | QAbstractAxisPrivate(q), | |
275 | m_min(0), |
|
286 | m_min(0), | |
276 | m_max(0), |
|
287 | m_max(0), | |
277 | m_tickCount(5), |
|
288 | m_tickCount(5), | |
278 | m_niceNumbers(false), |
|
289 | m_niceNumbers(false), | |
279 | m_format("%g") |
|
290 | m_format("%g") | |
280 | { |
|
291 | { | |
281 |
|
292 | |||
282 | } |
|
293 | } | |
283 |
|
294 | |||
284 | QValueAxisPrivate::~QValueAxisPrivate() |
|
295 | QValueAxisPrivate::~QValueAxisPrivate() | |
285 | { |
|
296 | { | |
286 |
|
297 | |||
287 | } |
|
298 | } | |
288 |
|
299 | |||
289 | void QValueAxisPrivate::handleDomainUpdated() |
|
300 | void QValueAxisPrivate::handleDomainUpdated() | |
290 | { |
|
301 | { | |
291 | Q_Q(QValueAxis); |
|
302 | Q_Q(QValueAxis); | |
292 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
303 | Domain* domain = qobject_cast<Domain*>(sender()); | |
293 | Q_ASSERT(domain); |
|
304 | Q_ASSERT(domain); | |
294 |
|
305 | |||
295 | if(orientation()==Qt::Horizontal){ |
|
306 | if(orientation()==Qt::Horizontal){ | |
296 | q->setRange(domain->minX(),domain->maxX()); |
|
307 | q->setRange(domain->minX(),domain->maxX()); | |
297 | }else if(orientation()==Qt::Vertical){ |
|
308 | }else if(orientation()==Qt::Vertical){ | |
298 | q->setRange(domain->minY(),domain->maxY()); |
|
309 | q->setRange(domain->minY(),domain->maxY()); | |
299 | } |
|
310 | } | |
300 | } |
|
311 | } | |
301 |
|
312 | |||
302 |
|
313 | |||
303 | void QValueAxisPrivate::setMin(const QVariant &min) |
|
314 | void QValueAxisPrivate::setMin(const QVariant &min) | |
304 | { |
|
315 | { | |
305 | Q_Q(QValueAxis); |
|
316 | Q_Q(QValueAxis); | |
306 | bool ok; |
|
317 | bool ok; | |
307 | qreal value = min.toReal(&ok); |
|
318 | qreal value = min.toReal(&ok); | |
308 | if(ok) q->setMin(value); |
|
319 | if(ok) q->setMin(value); | |
309 | } |
|
320 | } | |
310 |
|
321 | |||
311 | void QValueAxisPrivate::setMax(const QVariant &max) |
|
322 | void QValueAxisPrivate::setMax(const QVariant &max) | |
312 | { |
|
323 | { | |
313 |
|
324 | |||
314 | Q_Q(QValueAxis); |
|
325 | Q_Q(QValueAxis); | |
315 | bool ok; |
|
326 | bool ok; | |
316 | qreal value = max.toReal(&ok); |
|
327 | qreal value = max.toReal(&ok); | |
317 | if(ok) q->setMax(value); |
|
328 | if(ok) q->setMax(value); | |
318 | } |
|
329 | } | |
319 |
|
330 | |||
320 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
331 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
321 | { |
|
332 | { | |
322 | Q_Q(QValueAxis); |
|
333 | Q_Q(QValueAxis); | |
323 | bool ok1; |
|
334 | bool ok1; | |
324 | bool ok2; |
|
335 | bool ok2; | |
325 | qreal value1 = min.toReal(&ok1); |
|
336 | qreal value1 = min.toReal(&ok1); | |
326 | qreal value2 = max.toReal(&ok2); |
|
337 | qreal value2 = max.toReal(&ok2); | |
327 | if(ok1&&ok2) q->setRange(value1,value2); |
|
338 | if(ok1&&ok2) q->setRange(value1,value2); | |
328 | } |
|
339 | } | |
329 |
|
340 | |||
330 | ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
341 | ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter) | |
331 | { |
|
342 | { | |
332 | Q_Q(QValueAxis); |
|
343 | Q_Q(QValueAxis); | |
333 | if(m_orientation == Qt::Vertical){ |
|
344 | if(m_orientation == Qt::Vertical){ | |
334 | return new ChartValueAxisY(q,presenter); |
|
345 | return new ChartValueAxisY(q,presenter); | |
335 | }else{ |
|
346 | }else{ | |
336 | return new ChartValueAxisX(q,presenter); |
|
347 | return new ChartValueAxisX(q,presenter); | |
337 | } |
|
348 | } | |
338 |
|
349 | |||
339 | } |
|
350 | } | |
340 |
|
351 | |||
341 | void QValueAxisPrivate::intializeDomain(Domain* domain) |
|
352 | void QValueAxisPrivate::intializeDomain(Domain* domain) | |
342 | { |
|
353 | { | |
343 | Q_Q(QValueAxis); |
|
354 | Q_Q(QValueAxis); | |
344 | if(qFuzzyCompare(m_max,m_min)) { |
|
355 | if(qFuzzyCompare(m_max,m_min)) { | |
345 | if(m_orientation==Qt::Vertical){ |
|
356 | if(m_orientation==Qt::Vertical){ | |
346 | q->setRange(domain->minY(),domain->maxY()); |
|
357 | q->setRange(domain->minY(),domain->maxY()); | |
347 | }else{ |
|
358 | }else{ | |
348 | q->setRange(domain->minX(), domain->maxX()); |
|
359 | q->setRange(domain->minX(), domain->maxX()); | |
349 | } |
|
360 | } | |
350 | } else { |
|
361 | } else { | |
351 | if(m_orientation==Qt::Vertical){ |
|
362 | if(m_orientation==Qt::Vertical){ | |
352 | domain->setRangeY(m_min, m_max); |
|
363 | domain->setRangeY(m_min, m_max); | |
353 | }else{ |
|
364 | }else{ | |
354 | domain->setRangeX(m_min, m_max); |
|
365 | domain->setRangeX(m_min, m_max); | |
355 | } |
|
366 | } | |
356 | } |
|
367 | } | |
357 | } |
|
368 | } | |
358 |
|
369 | |||
359 | //algorithm defined by Paul S.Heckbert GraphicalGems I |
|
370 | //algorithm defined by Paul S.Heckbert GraphicalGems I | |
360 |
|
371 | |||
361 | void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const |
|
372 | void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const | |
362 | { |
|
373 | { | |
363 | qreal range = niceNumber(max-min,true); //range with ceiling |
|
374 | qreal range = niceNumber(max-min,true); //range with ceiling | |
364 | qreal step = niceNumber(range/(ticksCount-1),false); |
|
375 | qreal step = niceNumber(range/(ticksCount-1),false); | |
365 | min = qFloor(min/step); |
|
376 | min = qFloor(min/step); | |
366 | max = qCeil(max/step); |
|
377 | max = qCeil(max/step); | |
367 | ticksCount = int(max-min) +1; |
|
378 | ticksCount = int(max-min) +1; | |
368 | min*=step; |
|
379 | min*=step; | |
369 | max*=step; |
|
380 | max*=step; | |
370 | } |
|
381 | } | |
371 |
|
382 | |||
372 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n |
|
383 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n | |
373 |
|
384 | |||
374 | qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const |
|
385 | qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const | |
375 | { |
|
386 | { | |
376 | qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x |
|
387 | qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x | |
377 | qreal q = x/z;//q<10 && q>=1; |
|
388 | qreal q = x/z;//q<10 && q>=1; | |
378 |
|
389 | |||
379 | if(ceiling) { |
|
390 | if(ceiling) { | |
380 | if(q <= 1.0) q=1; |
|
391 | if(q <= 1.0) q=1; | |
381 | else if(q <= 2.0) q=2; |
|
392 | else if(q <= 2.0) q=2; | |
382 | else if(q <= 5.0) q=5; |
|
393 | else if(q <= 5.0) q=5; | |
383 | else q=10; |
|
394 | else q=10; | |
384 | } |
|
395 | } | |
385 | else { |
|
396 | else { | |
386 | if(q < 1.5) q=1; |
|
397 | if(q < 1.5) q=1; | |
387 | else if(q < 3.0) q=2; |
|
398 | else if(q < 3.0) q=2; | |
388 | else if(q < 7.0) q=5; |
|
399 | else if(q < 7.0) q=5; | |
389 | else q=10; |
|
400 | else q=10; | |
390 | } |
|
401 | } | |
391 | return q*z; |
|
402 | return q*z; | |
392 | } |
|
403 | } | |
393 |
|
404 | |||
394 | #include "moc_qvalueaxis.cpp" |
|
405 | #include "moc_qvalueaxis.cpp" | |
395 | #include "moc_qvalueaxis_p.cpp" |
|
406 | #include "moc_qvalueaxis_p.cpp" | |
396 |
|
407 | |||
397 | QTCOMMERCIALCHART_END_NAMESPACE |
|
408 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,77 +1,78 | |||||
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 | #ifndef QVALUESAXIS_H |
|
21 | #ifndef QVALUESAXIS_H | |
22 | #define QVALUESAXIS_H |
|
22 | #define QVALUESAXIS_H | |
23 |
|
23 | |||
24 | #include "qabstractaxis.h" |
|
24 | #include "qabstractaxis.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QValueAxisPrivate; |
|
28 | class QValueAxisPrivate; | |
29 |
|
29 | |||
30 | class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis |
|
30 | class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount) |
|
33 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount) | |
34 | Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled) |
|
34 | Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled) | |
35 | Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) |
|
35 | Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) | |
36 | Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) |
|
36 | Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) | |
|
37 | Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat) | |||
37 |
|
38 | |||
38 | public: |
|
39 | public: | |
39 | explicit QValueAxis(QObject *parent = 0); |
|
40 | explicit QValueAxis(QObject *parent = 0); | |
40 | ~QValueAxis(); |
|
41 | ~QValueAxis(); | |
41 |
|
42 | |||
42 | protected: |
|
43 | protected: | |
43 | QValueAxis(QValueAxisPrivate &d,QObject *parent = 0); |
|
44 | QValueAxis(QValueAxisPrivate &d,QObject *parent = 0); | |
44 |
|
45 | |||
45 | public: |
|
46 | public: | |
46 | AxisType type() const; |
|
47 | AxisType type() const; | |
47 |
|
48 | |||
48 | //range handling |
|
49 | //range handling | |
49 | void setMin(qreal min); |
|
50 | void setMin(qreal min); | |
50 | qreal min() const; |
|
51 | qreal min() const; | |
51 | void setMax(qreal max); |
|
52 | void setMax(qreal max); | |
52 | qreal max() const; |
|
53 | qreal max() const; | |
53 | void setRange(qreal min, qreal max); |
|
54 | void setRange(qreal min, qreal max); | |
54 |
|
55 | |||
55 | //ticks handling |
|
56 | //ticks handling | |
56 | void setTickCount(int count); |
|
57 | void setTickCount(int count); | |
57 | int tickCount() const; |
|
58 | int tickCount() const; | |
58 |
|
59 | |||
59 | void setLabelFormat(const QString &format); |
|
60 | void setLabelFormat(const QString &format); | |
60 | QString labelFormat() const; |
|
61 | QString labelFormat() const; | |
61 |
|
62 | |||
62 | void setNiceNumbersEnabled(bool enable = true); |
|
63 | void setNiceNumbersEnabled(bool enable = true); | |
63 | bool niceNumbersEnabled() const; |
|
64 | bool niceNumbersEnabled() const; | |
64 |
|
65 | |||
65 | Q_SIGNALS: |
|
66 | Q_SIGNALS: | |
66 | void minChanged(qreal min); |
|
67 | void minChanged(qreal min); | |
67 | void maxChanged(qreal max); |
|
68 | void maxChanged(qreal max); | |
68 | void rangeChanged(qreal min, qreal max); |
|
69 | void rangeChanged(qreal min, qreal max); | |
69 |
|
70 | |||
70 | private: |
|
71 | private: | |
71 | Q_DECLARE_PRIVATE(QValueAxis) |
|
72 | Q_DECLARE_PRIVATE(QValueAxis) | |
72 | Q_DISABLE_COPY(QValueAxis) |
|
73 | Q_DISABLE_COPY(QValueAxis) | |
73 | }; |
|
74 | }; | |
74 |
|
75 | |||
75 | QTCOMMERCIALCHART_END_NAMESPACE |
|
76 | QTCOMMERCIALCHART_END_NAMESPACE | |
76 |
|
77 | |||
77 | #endif // QVALUESAXIS_H |
|
78 | #endif // QVALUESAXIS_H |
General Comments 0
You need to be logged in to leave comments.
Login now