@@ -1,318 +1,324 | |||||
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 "qlogvalueaxis.h" |
|
21 | #include "qlogvalueaxis.h" | |
22 | #include "qlogvalueaxis_p.h" |
|
22 | #include "qlogvalueaxis_p.h" | |
23 | #include "chartlogvalueaxisx_p.h" |
|
23 | #include "chartlogvalueaxisx_p.h" | |
24 | #include "chartlogvalueaxisy_p.h" |
|
24 | #include "chartlogvalueaxisy_p.h" | |
25 | #include "abstractdomain_p.h" |
|
25 | #include "abstractdomain_p.h" | |
26 | #include <float.h> |
|
26 | #include <float.h> | |
27 | #include <cmath> |
|
27 | #include <cmath> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | /*! |
|
30 | /*! | |
31 | \class QLogValueAxis |
|
31 | \class QLogValueAxis | |
32 | \brief The QLogValueAxis class is used for manipulating chart's axis. |
|
32 | \brief The QLogValueAxis class is used for manipulating chart's axis. | |
33 | \mainclass |
|
33 | \mainclass | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \qmlclass DateTimeAxis QLogValueAxis |
|
37 | \qmlclass DateTimeAxis QLogValueAxis | |
38 | \brief The DateTimeAxis element is used for manipulating chart's axes |
|
38 | \brief The DateTimeAxis element is used for manipulating chart's axes | |
39 | \inherits AbstractAxis |
|
39 | \inherits AbstractAxis | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \property QLogValueAxis::min |
|
43 | \property QLogValueAxis::min | |
44 | Defines the minimum value on the axis. |
|
44 | Defines the minimum value on the axis. | |
45 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
45 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
46 | */ |
|
46 | */ | |
47 | /*! |
|
47 | /*! | |
48 | \qmlproperty real ValuesAxis::min |
|
48 | \qmlproperty real ValuesAxis::min | |
49 | Defines the minimum value on the axis. |
|
49 | Defines the minimum value on the axis. | |
50 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
50 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
51 | */ |
|
51 | */ | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | \property QLogValueAxis::max |
|
54 | \property QLogValueAxis::max | |
55 | Defines the maximum value on the axis. |
|
55 | Defines the maximum value on the axis. | |
56 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
56 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
57 | */ |
|
57 | */ | |
58 | /*! |
|
58 | /*! | |
59 | \qmlproperty real ValuesAxis::max |
|
59 | \qmlproperty real ValuesAxis::max | |
60 | Defines the maximum value on the axis. |
|
60 | Defines the maximum value on the axis. | |
61 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
61 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | \fn void QLogValueAxis::minChanged(qreal min) |
|
65 | \fn void QLogValueAxis::minChanged(qreal min) | |
66 | Axis emits signal when \a min of axis has changed. |
|
66 | Axis emits signal when \a min of axis has changed. | |
67 | */ |
|
67 | */ | |
68 | /*! |
|
68 | /*! | |
69 | \qmlsignal ValuesAxis::onMinChanged(qreal min) |
|
69 | \qmlsignal ValuesAxis::onMinChanged(qreal min) | |
70 | Axis emits signal when \a min of axis has changed. |
|
70 | Axis emits signal when \a min of axis has changed. | |
71 | */ |
|
71 | */ | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | \fn void QLogValueAxis::maxChanged(qreal max) |
|
74 | \fn void QLogValueAxis::maxChanged(qreal max) | |
75 | Axis emits signal when \a max of axis has changed. |
|
75 | Axis emits signal when \a max of axis has changed. | |
76 | */ |
|
76 | */ | |
77 | /*! |
|
77 | /*! | |
78 | \qmlsignal ValuesAxis::onMaxChanged(qreal max) |
|
78 | \qmlsignal ValuesAxis::onMaxChanged(qreal max) | |
79 | Axis emits signal when \a max of axis has changed. |
|
79 | Axis emits signal when \a max of axis has changed. | |
80 | */ |
|
80 | */ | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
83 | \fn void QLogValueAxis::rangeChanged(qreal min, qreal max) |
|
83 | \fn void QLogValueAxis::rangeChanged(qreal min, qreal max) | |
84 | Axis emits signal when \a min or \a max of axis has changed. |
|
84 | Axis emits signal when \a min or \a max of axis has changed. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | Constructs an axis object which is a child of \a parent. |
|
88 | Constructs an axis object which is a child of \a parent. | |
89 | */ |
|
89 | */ | |
90 | QLogValueAxis::QLogValueAxis(QObject *parent) : |
|
90 | QLogValueAxis::QLogValueAxis(QObject *parent) : | |
91 | QAbstractAxis(*new QLogValueAxisPrivate(this), parent) |
|
91 | QAbstractAxis(*new QLogValueAxisPrivate(this), parent) | |
92 | { |
|
92 | { | |
93 |
|
93 | |||
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | /*! |
|
96 | /*! | |
97 | \internal |
|
97 | \internal | |
98 | */ |
|
98 | */ | |
99 | QLogValueAxis::QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) |
|
99 | QLogValueAxis::QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) | |
100 | { |
|
100 | { | |
101 |
|
101 | |||
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | Destroys the object |
|
105 | Destroys the object | |
106 | */ |
|
106 | */ | |
107 | QLogValueAxis::~QLogValueAxis() |
|
107 | QLogValueAxis::~QLogValueAxis() | |
108 | { |
|
108 | { | |
109 |
|
109 | Q_D(QLogValueAxis); | ||
|
110 | if (d->m_chart) | |||
|
111 | d->m_chart->removeAxis(this); | |||
110 | } |
|
112 | } | |
111 |
|
113 | |||
112 | void QLogValueAxis::setMin(qreal min) |
|
114 | void QLogValueAxis::setMin(qreal min) | |
113 | { |
|
115 | { | |
114 | Q_D(QLogValueAxis); |
|
116 | Q_D(QLogValueAxis); | |
115 | setRange(min, qMax(d->m_max, min)); |
|
117 | setRange(min, qMax(d->m_max, min)); | |
116 | } |
|
118 | } | |
117 |
|
119 | |||
118 | qreal QLogValueAxis::min() const |
|
120 | qreal QLogValueAxis::min() const | |
119 | { |
|
121 | { | |
120 | Q_D(const QLogValueAxis); |
|
122 | Q_D(const QLogValueAxis); | |
121 | return d->m_min; |
|
123 | return d->m_min; | |
122 | } |
|
124 | } | |
123 |
|
125 | |||
124 | void QLogValueAxis::setMax(qreal max) |
|
126 | void QLogValueAxis::setMax(qreal max) | |
125 | { |
|
127 | { | |
126 | Q_D(QLogValueAxis); |
|
128 | Q_D(QLogValueAxis); | |
127 | setRange(qMin(d->m_min, max), max); |
|
129 | setRange(qMin(d->m_min, max), max); | |
128 | } |
|
130 | } | |
129 |
|
131 | |||
130 | qreal QLogValueAxis::max() const |
|
132 | qreal QLogValueAxis::max() const | |
131 | { |
|
133 | { | |
132 | Q_D(const QLogValueAxis); |
|
134 | Q_D(const QLogValueAxis); | |
133 | return d->m_max; |
|
135 | return d->m_max; | |
134 | } |
|
136 | } | |
135 |
|
137 | |||
136 | /*! |
|
138 | /*! | |
137 | Sets range from \a min to \a max on the axis. |
|
139 | Sets range from \a min to \a max on the axis. | |
138 | If min is greater than max then this function returns without making any changes. |
|
140 | If min is greater than max then this function returns without making any changes. | |
139 | */ |
|
141 | */ | |
140 | void QLogValueAxis::setRange(qreal min, qreal max) |
|
142 | void QLogValueAxis::setRange(qreal min, qreal max) | |
141 | { |
|
143 | { | |
142 | Q_D(QLogValueAxis); |
|
144 | Q_D(QLogValueAxis); | |
143 | bool changed = false; |
|
145 | bool changed = false; | |
144 |
|
146 | |||
145 | if (min > max) |
|
147 | if (min > max) | |
146 | return; |
|
148 | return; | |
147 |
|
149 | |||
148 | if (min > 0) { |
|
150 | if (min > 0) { | |
149 | if (!qFuzzyCompare(d->m_min, min)) { |
|
151 | if (!qFuzzyCompare(d->m_min, min)) { | |
150 | d->m_min = min; |
|
152 | d->m_min = min; | |
151 | changed = true; |
|
153 | changed = true; | |
152 | emit minChanged(min); |
|
154 | emit minChanged(min); | |
153 | } |
|
155 | } | |
154 |
|
156 | |||
155 | if (!qFuzzyCompare(d->m_max, max)) { |
|
157 | if (!qFuzzyCompare(d->m_max, max)) { | |
156 | d->m_max = max; |
|
158 | d->m_max = max; | |
157 | changed = true; |
|
159 | changed = true; | |
158 | emit maxChanged(max); |
|
160 | emit maxChanged(max); | |
159 | } |
|
161 | } | |
160 |
|
162 | |||
161 | if (changed) { |
|
163 | if (changed) { | |
162 | emit rangeChanged(min, max); |
|
164 | emit rangeChanged(min, max); | |
163 | emit d->rangeChanged(min,max); |
|
165 | emit d->rangeChanged(min,max); | |
164 | } |
|
166 | } | |
165 | } |
|
167 | } | |
166 | } |
|
168 | } | |
167 |
|
169 | |||
168 | void QLogValueAxis::setLabelFormat(const QString &format) |
|
170 | void QLogValueAxis::setLabelFormat(const QString &format) | |
169 | { |
|
171 | { | |
170 | Q_D(QLogValueAxis); |
|
172 | Q_D(QLogValueAxis); | |
171 | d->m_format = format; |
|
173 | d->m_format = format; | |
172 | } |
|
174 | } | |
173 |
|
175 | |||
174 | QString QLogValueAxis::labelFormat() const |
|
176 | QString QLogValueAxis::labelFormat() const | |
175 | { |
|
177 | { | |
176 | Q_D(const QLogValueAxis); |
|
178 | Q_D(const QLogValueAxis); | |
177 | return d->m_format; |
|
179 | return d->m_format; | |
178 | } |
|
180 | } | |
179 |
|
181 | |||
180 | void QLogValueAxis::setBase(qreal base) |
|
182 | void QLogValueAxis::setBase(qreal base) | |
181 | { |
|
183 | { | |
182 | // check if base is correct |
|
184 | // check if base is correct | |
183 | if (qFuzzyCompare(base, 1)) |
|
185 | if (qFuzzyCompare(base, 1)) | |
184 | return; |
|
186 | return; | |
185 |
|
187 | |||
186 | if (base > 0) { |
|
188 | if (base > 0) { | |
187 | Q_D(QLogValueAxis); |
|
189 | Q_D(QLogValueAxis); | |
188 | d->m_base = base; |
|
190 | d->m_base = base; | |
189 | emit baseChanged(base); |
|
191 | emit baseChanged(base); | |
190 | } |
|
192 | } | |
191 | } |
|
193 | } | |
192 |
|
194 | |||
193 | qreal QLogValueAxis::base() const |
|
195 | qreal QLogValueAxis::base() const | |
194 | { |
|
196 | { | |
195 | Q_D(const QLogValueAxis); |
|
197 | Q_D(const QLogValueAxis); | |
196 | return d->m_base; |
|
198 | return d->m_base; | |
197 | } |
|
199 | } | |
198 |
|
200 | |||
199 | /*! |
|
201 | /*! | |
200 | Returns the type of the axis |
|
202 | Returns the type of the axis | |
201 | */ |
|
203 | */ | |
202 | QAbstractAxis::AxisType QLogValueAxis::type() const |
|
204 | QAbstractAxis::AxisType QLogValueAxis::type() const | |
203 | { |
|
205 | { | |
204 | return AxisTypeLogValue; |
|
206 | return AxisTypeLogValue; | |
205 | } |
|
207 | } | |
206 |
|
208 | |||
207 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
209 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
208 |
|
210 | |||
209 | QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q) |
|
211 | QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q) | |
210 | : QAbstractAxisPrivate(q), |
|
212 | : QAbstractAxisPrivate(q), | |
211 | m_min(1), |
|
213 | m_min(1), | |
212 |
m_max(1 |
|
214 | m_max(1), | |
213 | m_base(10), |
|
215 | m_base(10), | |
214 | m_format(QString::null) |
|
216 | m_format(QString::null) | |
215 | { |
|
217 | { | |
216 | } |
|
218 | } | |
217 |
|
219 | |||
218 | QLogValueAxisPrivate::~QLogValueAxisPrivate() |
|
220 | QLogValueAxisPrivate::~QLogValueAxisPrivate() | |
219 | { |
|
221 | { | |
220 |
|
222 | |||
221 | } |
|
223 | } | |
222 |
|
224 | |||
223 | void QLogValueAxisPrivate::setMin(const QVariant &min) |
|
225 | void QLogValueAxisPrivate::setMin(const QVariant &min) | |
224 | { |
|
226 | { | |
225 | Q_Q(QLogValueAxis); |
|
227 | Q_Q(QLogValueAxis); | |
226 | bool ok; |
|
228 | bool ok; | |
227 | qreal value = min.toReal(&ok); |
|
229 | qreal value = min.toReal(&ok); | |
228 | if (ok) |
|
230 | if (ok) | |
229 | q->setMin(value); |
|
231 | q->setMin(value); | |
230 | } |
|
232 | } | |
231 |
|
233 | |||
232 | void QLogValueAxisPrivate::setMax(const QVariant &max) |
|
234 | void QLogValueAxisPrivate::setMax(const QVariant &max) | |
233 | { |
|
235 | { | |
234 |
|
236 | |||
235 | Q_Q(QLogValueAxis); |
|
237 | Q_Q(QLogValueAxis); | |
236 | bool ok; |
|
238 | bool ok; | |
237 | qreal value = max.toReal(&ok); |
|
239 | qreal value = max.toReal(&ok); | |
238 | if (ok) |
|
240 | if (ok) | |
239 | q->setMax(value); |
|
241 | q->setMax(value); | |
240 | } |
|
242 | } | |
241 |
|
243 | |||
242 | void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
244 | void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
243 | { |
|
245 | { | |
244 | Q_Q(QLogValueAxis); |
|
246 | Q_Q(QLogValueAxis); | |
245 | bool ok1; |
|
247 | bool ok1; | |
246 | bool ok2; |
|
248 | bool ok2; | |
247 | qreal value1 = min.toReal(&ok1); |
|
249 | qreal value1 = min.toReal(&ok1); | |
248 | qreal value2 = max.toReal(&ok2); |
|
250 | qreal value2 = max.toReal(&ok2); | |
249 | if (ok1 && ok2) |
|
251 | if (ok1 && ok2) | |
250 | q->setRange(value1, value2); |
|
252 | q->setRange(value1, value2); | |
251 | } |
|
253 | } | |
252 |
|
254 | |||
253 | void QLogValueAxisPrivate::setRange(qreal min, qreal max) |
|
255 | void QLogValueAxisPrivate::setRange(qreal min, qreal max) | |
254 | { |
|
256 | { | |
255 | Q_Q(QLogValueAxis); |
|
257 | Q_Q(QLogValueAxis); | |
256 | bool changed = false; |
|
258 | bool changed = false; | |
257 |
|
259 | |||
258 | if (min > max) |
|
260 | if (min > max) | |
259 | return; |
|
261 | return; | |
260 |
|
262 | |||
261 | if (min > 0) { |
|
263 | if (min > 0) { | |
262 | if (!qFuzzyCompare(m_min, min)) { |
|
264 | if (!qFuzzyCompare(m_min, min)) { | |
263 | m_min = min; |
|
265 | m_min = min; | |
264 | changed = true; |
|
266 | changed = true; | |
265 | emit q->minChanged(min); |
|
267 | emit q->minChanged(min); | |
266 | } |
|
268 | } | |
267 |
|
269 | |||
268 | if (!qFuzzyCompare(m_max, max)) { |
|
270 | if (!qFuzzyCompare(m_max, max)) { | |
269 | m_max = max; |
|
271 | m_max = max; | |
270 | changed = true; |
|
272 | changed = true; | |
271 | emit q->maxChanged(max); |
|
273 | emit q->maxChanged(max); | |
272 | } |
|
274 | } | |
273 |
|
275 | |||
274 | if (changed) { |
|
276 | if (changed) { | |
275 | emit q->rangeChanged(min, max); |
|
277 | emit q->rangeChanged(min, max); | |
276 | emit rangeChanged(min,max); |
|
278 | emit rangeChanged(min,max); | |
277 | } |
|
279 | } | |
278 | } |
|
280 | } | |
279 | } |
|
281 | } | |
280 |
|
282 | |||
281 | void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
283 | void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
282 | { |
|
284 | { | |
283 | Q_Q(QLogValueAxis); |
|
285 | Q_Q(QLogValueAxis); | |
284 | ChartAxis* axis(0); |
|
286 | ChartAxis* axis(0); | |
285 | if (orientation() == Qt::Vertical) |
|
287 | if (orientation() == Qt::Vertical) | |
286 | axis = new ChartLogValueAxisY(q,parent); |
|
288 | axis = new ChartLogValueAxisY(q,parent); | |
287 | if (orientation() == Qt::Horizontal) |
|
289 | if (orientation() == Qt::Horizontal) | |
288 | axis = new ChartLogValueAxisX(q,parent); |
|
290 | axis = new ChartLogValueAxisX(q,parent); | |
289 |
|
291 | |||
290 | m_item.reset(axis); |
|
292 | m_item.reset(axis); | |
291 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
293 | QAbstractAxisPrivate::initializeGraphics(parent); | |
292 | } |
|
294 | } | |
293 |
|
295 | |||
294 |
|
296 | |||
295 | void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
297 | void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain) | |
296 | { |
|
298 | { | |
297 | if (orientation() == Qt::Vertical) { |
|
299 | if (orientation() == Qt::Vertical) { | |
298 | if(!qFuzzyCompare(m_max, m_min)) { |
|
300 | if(!qFuzzyCompare(m_max, m_min)) { | |
299 | domain->setRangeY(m_min, m_max); |
|
301 | domain->setRangeY(m_min, m_max); | |
300 | } |
|
302 | } | |
301 | else { |
|
303 | else if ( domain->minY() > 0) { | |
302 |
setRange(domain->minY() |
|
304 | setRange(domain->minY(), domain->maxY()); | |
|
305 | } else { | |||
|
306 | domain->setRangeY(m_min, domain->maxY()); | |||
303 | } |
|
307 | } | |
304 | } |
|
308 | } | |
305 | if (orientation() == Qt::Horizontal) { |
|
309 | if (orientation() == Qt::Horizontal) { | |
306 | if(!qFuzzyCompare(m_max, m_min)) { |
|
310 | if(!qFuzzyCompare(m_max, m_min)) { | |
307 | domain->setRangeX(m_min, m_max); |
|
311 | domain->setRangeX(m_min, m_max); | |
308 | } |
|
312 | } | |
309 | else { |
|
313 | else if (domain->minX() > 0){ | |
310 |
setRange(domain->minX() |
|
314 | setRange(domain->minX(), domain->maxX()); | |
|
315 | } else { | |||
|
316 | domain->setRangeX(m_min, domain->maxX()); | |||
311 | } |
|
317 | } | |
312 | } |
|
318 | } | |
313 | } |
|
319 | } | |
314 |
|
320 | |||
315 | #include "moc_qlogvalueaxis.cpp" |
|
321 | #include "moc_qlogvalueaxis.cpp" | |
316 | #include "moc_qlogvalueaxis_p.cpp" |
|
322 | #include "moc_qlogvalueaxis_p.cpp" | |
317 |
|
323 | |||
318 | QTCOMMERCIALCHART_END_NAMESPACE |
|
324 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now