@@ -1,324 +1,325 | |||||
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 | Q_D(QLogValueAxis); |
|
109 | Q_D(QLogValueAxis); | |
110 | if (d->m_chart) |
|
110 | if (d->m_chart) | |
111 | d->m_chart->removeAxis(this); |
|
111 | d->m_chart->removeAxis(this); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | void QLogValueAxis::setMin(qreal min) |
|
114 | void QLogValueAxis::setMin(qreal min) | |
115 | { |
|
115 | { | |
116 | Q_D(QLogValueAxis); |
|
116 | Q_D(QLogValueAxis); | |
117 | setRange(min, qMax(d->m_max, min)); |
|
117 | setRange(min, qMax(d->m_max, min)); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | qreal QLogValueAxis::min() const |
|
120 | qreal QLogValueAxis::min() const | |
121 | { |
|
121 | { | |
122 | Q_D(const QLogValueAxis); |
|
122 | Q_D(const QLogValueAxis); | |
123 | return d->m_min; |
|
123 | return d->m_min; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void QLogValueAxis::setMax(qreal max) |
|
126 | void QLogValueAxis::setMax(qreal max) | |
127 | { |
|
127 | { | |
128 | Q_D(QLogValueAxis); |
|
128 | Q_D(QLogValueAxis); | |
129 | setRange(qMin(d->m_min, max), max); |
|
129 | setRange(qMin(d->m_min, max), max); | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | qreal QLogValueAxis::max() const |
|
132 | qreal QLogValueAxis::max() const | |
133 | { |
|
133 | { | |
134 | Q_D(const QLogValueAxis); |
|
134 | Q_D(const QLogValueAxis); | |
135 | return d->m_max; |
|
135 | return d->m_max; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | Sets range from \a min to \a max on the axis. |
|
139 | Sets range from \a min to \a max on the axis. | |
140 | 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. | |
141 | */ |
|
141 | */ | |
142 | void QLogValueAxis::setRange(qreal min, qreal max) |
|
142 | void QLogValueAxis::setRange(qreal min, qreal max) | |
143 | { |
|
143 | { | |
144 | Q_D(QLogValueAxis); |
|
144 | Q_D(QLogValueAxis); | |
145 | bool changed = false; |
|
145 | bool changed = false; | |
146 |
|
146 | |||
147 | if (min > max) |
|
147 | if (min > max) | |
148 | return; |
|
148 | return; | |
149 |
|
149 | |||
150 | if (min > 0) { |
|
150 | if (min > 0) { | |
151 | if (!qFuzzyCompare(d->m_min, min)) { |
|
151 | if (!qFuzzyCompare(d->m_min, min)) { | |
152 | d->m_min = min; |
|
152 | d->m_min = min; | |
153 | changed = true; |
|
153 | changed = true; | |
154 | emit minChanged(min); |
|
154 | emit minChanged(min); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | if (!qFuzzyCompare(d->m_max, max)) { |
|
157 | if (!qFuzzyCompare(d->m_max, max)) { | |
158 | d->m_max = max; |
|
158 | d->m_max = max; | |
159 | changed = true; |
|
159 | changed = true; | |
160 | emit maxChanged(max); |
|
160 | emit maxChanged(max); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | if (changed) { |
|
163 | if (changed) { | |
164 | emit rangeChanged(min, max); |
|
164 | emit rangeChanged(min, max); | |
165 | emit d->rangeChanged(min,max); |
|
165 | emit d->rangeChanged(min,max); | |
166 | } |
|
166 | } | |
167 | } |
|
167 | } | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void QLogValueAxis::setLabelFormat(const QString &format) |
|
170 | void QLogValueAxis::setLabelFormat(const QString &format) | |
171 | { |
|
171 | { | |
172 | Q_D(QLogValueAxis); |
|
172 | Q_D(QLogValueAxis); | |
173 | d->m_format = format; |
|
173 | d->m_format = format; | |
|
174 | emit labelFormatChanged(format); | |||
174 | } |
|
175 | } | |
175 |
|
176 | |||
176 | QString QLogValueAxis::labelFormat() const |
|
177 | QString QLogValueAxis::labelFormat() const | |
177 | { |
|
178 | { | |
178 | Q_D(const QLogValueAxis); |
|
179 | Q_D(const QLogValueAxis); | |
179 | return d->m_format; |
|
180 | return d->m_format; | |
180 | } |
|
181 | } | |
181 |
|
182 | |||
182 | void QLogValueAxis::setBase(qreal base) |
|
183 | void QLogValueAxis::setBase(qreal base) | |
183 | { |
|
184 | { | |
184 | // check if base is correct |
|
185 | // check if base is correct | |
185 | if (qFuzzyCompare(base, 1)) |
|
186 | if (qFuzzyCompare(base, 1)) | |
186 | return; |
|
187 | return; | |
187 |
|
188 | |||
188 | if (base > 0) { |
|
189 | if (base > 0) { | |
189 | Q_D(QLogValueAxis); |
|
190 | Q_D(QLogValueAxis); | |
190 | d->m_base = base; |
|
191 | d->m_base = base; | |
191 | emit baseChanged(base); |
|
192 | emit baseChanged(base); | |
192 | } |
|
193 | } | |
193 | } |
|
194 | } | |
194 |
|
195 | |||
195 | qreal QLogValueAxis::base() const |
|
196 | qreal QLogValueAxis::base() const | |
196 | { |
|
197 | { | |
197 | Q_D(const QLogValueAxis); |
|
198 | Q_D(const QLogValueAxis); | |
198 | return d->m_base; |
|
199 | return d->m_base; | |
199 | } |
|
200 | } | |
200 |
|
201 | |||
201 | /*! |
|
202 | /*! | |
202 | Returns the type of the axis |
|
203 | Returns the type of the axis | |
203 | */ |
|
204 | */ | |
204 | QAbstractAxis::AxisType QLogValueAxis::type() const |
|
205 | QAbstractAxis::AxisType QLogValueAxis::type() const | |
205 | { |
|
206 | { | |
206 | return AxisTypeLogValue; |
|
207 | return AxisTypeLogValue; | |
207 | } |
|
208 | } | |
208 |
|
209 | |||
209 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
210 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
210 |
|
211 | |||
211 | QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q) |
|
212 | QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q) | |
212 | : QAbstractAxisPrivate(q), |
|
213 | : QAbstractAxisPrivate(q), | |
213 | m_min(1), |
|
214 | m_min(1), | |
214 | m_max(1), |
|
215 | m_max(1), | |
215 | m_base(10), |
|
216 | m_base(10), | |
216 | m_format(QString::null) |
|
217 | m_format(QString::null) | |
217 | { |
|
218 | { | |
218 | } |
|
219 | } | |
219 |
|
220 | |||
220 | QLogValueAxisPrivate::~QLogValueAxisPrivate() |
|
221 | QLogValueAxisPrivate::~QLogValueAxisPrivate() | |
221 | { |
|
222 | { | |
222 |
|
223 | |||
223 | } |
|
224 | } | |
224 |
|
225 | |||
225 | void QLogValueAxisPrivate::setMin(const QVariant &min) |
|
226 | void QLogValueAxisPrivate::setMin(const QVariant &min) | |
226 | { |
|
227 | { | |
227 | Q_Q(QLogValueAxis); |
|
228 | Q_Q(QLogValueAxis); | |
228 | bool ok; |
|
229 | bool ok; | |
229 | qreal value = min.toReal(&ok); |
|
230 | qreal value = min.toReal(&ok); | |
230 | if (ok) |
|
231 | if (ok) | |
231 | q->setMin(value); |
|
232 | q->setMin(value); | |
232 | } |
|
233 | } | |
233 |
|
234 | |||
234 | void QLogValueAxisPrivate::setMax(const QVariant &max) |
|
235 | void QLogValueAxisPrivate::setMax(const QVariant &max) | |
235 | { |
|
236 | { | |
236 |
|
237 | |||
237 | Q_Q(QLogValueAxis); |
|
238 | Q_Q(QLogValueAxis); | |
238 | bool ok; |
|
239 | bool ok; | |
239 | qreal value = max.toReal(&ok); |
|
240 | qreal value = max.toReal(&ok); | |
240 | if (ok) |
|
241 | if (ok) | |
241 | q->setMax(value); |
|
242 | q->setMax(value); | |
242 | } |
|
243 | } | |
243 |
|
244 | |||
244 | void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
245 | void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
245 | { |
|
246 | { | |
246 | Q_Q(QLogValueAxis); |
|
247 | Q_Q(QLogValueAxis); | |
247 | bool ok1; |
|
248 | bool ok1; | |
248 | bool ok2; |
|
249 | bool ok2; | |
249 | qreal value1 = min.toReal(&ok1); |
|
250 | qreal value1 = min.toReal(&ok1); | |
250 | qreal value2 = max.toReal(&ok2); |
|
251 | qreal value2 = max.toReal(&ok2); | |
251 | if (ok1 && ok2) |
|
252 | if (ok1 && ok2) | |
252 | q->setRange(value1, value2); |
|
253 | q->setRange(value1, value2); | |
253 | } |
|
254 | } | |
254 |
|
255 | |||
255 | void QLogValueAxisPrivate::setRange(qreal min, qreal max) |
|
256 | void QLogValueAxisPrivate::setRange(qreal min, qreal max) | |
256 | { |
|
257 | { | |
257 | Q_Q(QLogValueAxis); |
|
258 | Q_Q(QLogValueAxis); | |
258 | bool changed = false; |
|
259 | bool changed = false; | |
259 |
|
260 | |||
260 | if (min > max) |
|
261 | if (min > max) | |
261 | return; |
|
262 | return; | |
262 |
|
263 | |||
263 | if (min > 0) { |
|
264 | if (min > 0) { | |
264 | if (!qFuzzyCompare(m_min, min)) { |
|
265 | if (!qFuzzyCompare(m_min, min)) { | |
265 | m_min = min; |
|
266 | m_min = min; | |
266 | changed = true; |
|
267 | changed = true; | |
267 | emit q->minChanged(min); |
|
268 | emit q->minChanged(min); | |
268 | } |
|
269 | } | |
269 |
|
270 | |||
270 | if (!qFuzzyCompare(m_max, max)) { |
|
271 | if (!qFuzzyCompare(m_max, max)) { | |
271 | m_max = max; |
|
272 | m_max = max; | |
272 | changed = true; |
|
273 | changed = true; | |
273 | emit q->maxChanged(max); |
|
274 | emit q->maxChanged(max); | |
274 | } |
|
275 | } | |
275 |
|
276 | |||
276 | if (changed) { |
|
277 | if (changed) { | |
277 | emit q->rangeChanged(min, max); |
|
278 | emit q->rangeChanged(min, max); | |
278 | emit rangeChanged(min,max); |
|
279 | emit rangeChanged(min,max); | |
279 | } |
|
280 | } | |
280 | } |
|
281 | } | |
281 | } |
|
282 | } | |
282 |
|
283 | |||
283 | void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
284 | void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
284 | { |
|
285 | { | |
285 | Q_Q(QLogValueAxis); |
|
286 | Q_Q(QLogValueAxis); | |
286 | ChartAxis* axis(0); |
|
287 | ChartAxis* axis(0); | |
287 | if (orientation() == Qt::Vertical) |
|
288 | if (orientation() == Qt::Vertical) | |
288 | axis = new ChartLogValueAxisY(q,parent); |
|
289 | axis = new ChartLogValueAxisY(q,parent); | |
289 | if (orientation() == Qt::Horizontal) |
|
290 | if (orientation() == Qt::Horizontal) | |
290 | axis = new ChartLogValueAxisX(q,parent); |
|
291 | axis = new ChartLogValueAxisX(q,parent); | |
291 |
|
292 | |||
292 | m_item.reset(axis); |
|
293 | m_item.reset(axis); | |
293 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
294 | QAbstractAxisPrivate::initializeGraphics(parent); | |
294 | } |
|
295 | } | |
295 |
|
296 | |||
296 |
|
297 | |||
297 | void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
298 | void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain) | |
298 | { |
|
299 | { | |
299 | if (orientation() == Qt::Vertical) { |
|
300 | if (orientation() == Qt::Vertical) { | |
300 | if(!qFuzzyCompare(m_max, m_min)) { |
|
301 | if(!qFuzzyCompare(m_max, m_min)) { | |
301 | domain->setRangeY(m_min, m_max); |
|
302 | domain->setRangeY(m_min, m_max); | |
302 | } |
|
303 | } | |
303 | else if ( domain->minY() > 0) { |
|
304 | else if ( domain->minY() > 0) { | |
304 | setRange(domain->minY(), domain->maxY()); |
|
305 | setRange(domain->minY(), domain->maxY()); | |
305 | } else { |
|
306 | } else { | |
306 | domain->setRangeY(m_min, domain->maxY()); |
|
307 | domain->setRangeY(m_min, domain->maxY()); | |
307 | } |
|
308 | } | |
308 | } |
|
309 | } | |
309 | if (orientation() == Qt::Horizontal) { |
|
310 | if (orientation() == Qt::Horizontal) { | |
310 | if(!qFuzzyCompare(m_max, m_min)) { |
|
311 | if(!qFuzzyCompare(m_max, m_min)) { | |
311 | domain->setRangeX(m_min, m_max); |
|
312 | domain->setRangeX(m_min, m_max); | |
312 | } |
|
313 | } | |
313 | else if (domain->minX() > 0){ |
|
314 | else if (domain->minX() > 0){ | |
314 | setRange(domain->minX(), domain->maxX()); |
|
315 | setRange(domain->minX(), domain->maxX()); | |
315 | } else { |
|
316 | } else { | |
316 | domain->setRangeX(m_min, domain->maxX()); |
|
317 | domain->setRangeX(m_min, domain->maxX()); | |
317 | } |
|
318 | } | |
318 | } |
|
319 | } | |
319 | } |
|
320 | } | |
320 |
|
321 | |||
321 | #include "moc_qlogvalueaxis.cpp" |
|
322 | #include "moc_qlogvalueaxis.cpp" | |
322 | #include "moc_qlogvalueaxis_p.cpp" |
|
323 | #include "moc_qlogvalueaxis_p.cpp" | |
323 |
|
324 | |||
324 | QTCOMMERCIALCHART_END_NAMESPACE |
|
325 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,75 +1,77 | |||||
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 QLOGVALUEAXIS_H |
|
21 | #ifndef QLOGVALUEAXIS_H | |
22 | #define QLOGVALUEAXIS_H |
|
22 | #define QLOGVALUEAXIS_H | |
23 |
|
23 | |||
24 | #include "qabstractaxis.h" |
|
24 | #include "qabstractaxis.h" | |
25 |
|
25 | |||
26 | class QDateTime; |
|
26 | class QDateTime; | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | class QLogValueAxisPrivate; |
|
30 | class QLogValueAxisPrivate; | |
31 |
|
31 | |||
32 | class QTCOMMERCIALCHART_EXPORT QLogValueAxis : public QAbstractAxis |
|
32 | class QTCOMMERCIALCHART_EXPORT QLogValueAxis : public QAbstractAxis | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
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 | Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat NOTIFY labelFormatChanged) | |
|
38 | Q_PROPERTY(qreal base READ base WRITE setBase NOTIFY baseChanged) | |||
38 |
|
39 | |||
39 | public: |
|
40 | public: | |
40 | explicit QLogValueAxis(QObject *parent = 0); |
|
41 | explicit QLogValueAxis(QObject *parent = 0); | |
41 | ~QLogValueAxis(); |
|
42 | ~QLogValueAxis(); | |
42 |
|
43 | |||
43 | protected: |
|
44 | protected: | |
44 | QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent = 0); |
|
45 | QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent = 0); | |
45 |
|
46 | |||
46 | public: |
|
47 | public: | |
47 | AxisType type() const; |
|
48 | AxisType type() const; | |
48 |
|
49 | |||
49 | //range handling |
|
50 | //range handling | |
50 | void setMin(qreal min); |
|
51 | void setMin(qreal min); | |
51 | qreal min() const; |
|
52 | qreal min() const; | |
52 | void setMax(qreal max); |
|
53 | void setMax(qreal max); | |
53 | qreal max() const; |
|
54 | qreal max() const; | |
54 | void setRange(qreal min, qreal max); |
|
55 | void setRange(qreal min, qreal max); | |
55 |
|
56 | |||
56 | void setLabelFormat(const QString &format); |
|
57 | void setLabelFormat(const QString &format); | |
57 | QString labelFormat() const; |
|
58 | QString labelFormat() const; | |
58 |
|
59 | |||
59 | void setBase(qreal base); |
|
60 | void setBase(qreal base); | |
60 | qreal base() const; |
|
61 | qreal base() const; | |
61 |
|
62 | |||
62 | Q_SIGNALS: |
|
63 | Q_SIGNALS: | |
63 | void minChanged(qreal min); |
|
64 | void minChanged(qreal min); | |
64 | void maxChanged(qreal max); |
|
65 | void maxChanged(qreal max); | |
65 | void rangeChanged(qreal min, qreal max); |
|
66 | void rangeChanged(qreal min, qreal max); | |
|
67 | void labelFormatChanged(const QString &format); | |||
66 | void baseChanged(qreal base); |
|
68 | void baseChanged(qreal base); | |
67 |
|
69 | |||
68 | private: |
|
70 | private: | |
69 | Q_DECLARE_PRIVATE(QLogValueAxis) |
|
71 | Q_DECLARE_PRIVATE(QLogValueAxis) | |
70 | Q_DISABLE_COPY(QLogValueAxis) |
|
72 | Q_DISABLE_COPY(QLogValueAxis) | |
71 | }; |
|
73 | }; | |
72 |
|
74 | |||
73 | QTCOMMERCIALCHART_END_NAMESPACE |
|
75 | QTCOMMERCIALCHART_END_NAMESPACE | |
74 |
|
76 | |||
75 | #endif // QLOGVALUEAXIS_H |
|
77 | #endif // QLOGVALUEAXIS_H |
@@ -1,409 +1,410 | |||||
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_D(QValueAxis); |
|
243 | Q_D(QValueAxis); | |
244 | qWarning()<<"This function is depreciated, it can lead to unexpected behaviour.Use applyNiceNumbers(). "; |
|
244 | qWarning()<<"This function is depreciated, it can lead to unexpected behaviour.Use applyNiceNumbers(). "; | |
245 | if(enable) { |
|
245 | if(enable) { | |
246 | QObject::connect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers())); |
|
246 | QObject::connect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers())); | |
247 | QObject::connect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers())); |
|
247 | QObject::connect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers())); | |
248 | applyNiceNumbers(); |
|
248 | applyNiceNumbers(); | |
249 | } |
|
249 | } | |
250 | else { |
|
250 | else { | |
251 | QObject::disconnect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers())); |
|
251 | QObject::disconnect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers())); | |
252 | QObject::disconnect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers())); |
|
252 | QObject::disconnect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers())); | |
253 | } |
|
253 | } | |
254 | d->m_niceNumbersEnabled=enable; |
|
254 | d->m_niceNumbersEnabled=enable; | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | bool QValueAxis::niceNumbersEnabled() const |
|
257 | bool QValueAxis::niceNumbersEnabled() const | |
258 | { |
|
258 | { | |
259 | Q_D(const QValueAxis); |
|
259 | Q_D(const QValueAxis); | |
260 | qWarning()<<"This function is depreciated.Use applyNiceNumbers()."; |
|
260 | qWarning()<<"This function is depreciated.Use applyNiceNumbers()."; | |
261 | return d->m_niceNumbersEnabled; |
|
261 | return d->m_niceNumbersEnabled; | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | void QValueAxis::setLabelFormat(const QString &format) |
|
264 | void QValueAxis::setLabelFormat(const QString &format) | |
265 | { |
|
265 | { | |
266 | Q_D(QValueAxis); |
|
266 | Q_D(QValueAxis); | |
267 | d->m_format = format; |
|
267 | d->m_format = format; | |
|
268 | emit labelFormatChanged(format); | |||
268 | } |
|
269 | } | |
269 |
|
270 | |||
270 | QString QValueAxis::labelFormat() const |
|
271 | QString QValueAxis::labelFormat() const | |
271 | { |
|
272 | { | |
272 | Q_D(const QValueAxis); |
|
273 | Q_D(const QValueAxis); | |
273 | return d->m_format; |
|
274 | return d->m_format; | |
274 | } |
|
275 | } | |
275 |
|
276 | |||
276 | /*! |
|
277 | /*! | |
277 | Returns the type of the axis |
|
278 | Returns the type of the axis | |
278 | */ |
|
279 | */ | |
279 | QAbstractAxis::AxisType QValueAxis::type() const |
|
280 | QAbstractAxis::AxisType QValueAxis::type() const | |
280 | { |
|
281 | { | |
281 | return AxisTypeValue; |
|
282 | return AxisTypeValue; | |
282 | } |
|
283 | } | |
283 |
|
284 | |||
284 | void QValueAxis::applyNiceNumbers() |
|
285 | void QValueAxis::applyNiceNumbers() | |
285 | { |
|
286 | { | |
286 | Q_D(QValueAxis); |
|
287 | Q_D(QValueAxis); | |
287 | if(d->m_applying) return; |
|
288 | if(d->m_applying) return; | |
288 | qreal min = d->m_min; |
|
289 | qreal min = d->m_min; | |
289 | qreal max = d->m_max; |
|
290 | qreal max = d->m_max; | |
290 | int ticks = d->m_tickCount; |
|
291 | int ticks = d->m_tickCount; | |
291 | AbstractDomain::looseNiceNumbers(min,max,ticks); |
|
292 | AbstractDomain::looseNiceNumbers(min,max,ticks); | |
292 | d->m_applying=true; |
|
293 | d->m_applying=true; | |
293 | d->setRange(min,max); |
|
294 | d->setRange(min,max); | |
294 | setTickCount(ticks); |
|
295 | setTickCount(ticks); | |
295 | d->m_applying=false; |
|
296 | d->m_applying=false; | |
296 | } |
|
297 | } | |
297 |
|
298 | |||
298 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
299 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
299 |
|
300 | |||
300 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q) |
|
301 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q) | |
301 | : QAbstractAxisPrivate(q), |
|
302 | : QAbstractAxisPrivate(q), | |
302 | m_min(0), |
|
303 | m_min(0), | |
303 | m_max(0), |
|
304 | m_max(0), | |
304 | m_tickCount(5), |
|
305 | m_tickCount(5), | |
305 | m_format(QString::null), |
|
306 | m_format(QString::null), | |
306 | m_applying(false), |
|
307 | m_applying(false), | |
307 | m_niceNumbersEnabled(false) |
|
308 | m_niceNumbersEnabled(false) | |
308 | { |
|
309 | { | |
309 |
|
310 | |||
310 | } |
|
311 | } | |
311 |
|
312 | |||
312 | QValueAxisPrivate::~QValueAxisPrivate() |
|
313 | QValueAxisPrivate::~QValueAxisPrivate() | |
313 | { |
|
314 | { | |
314 |
|
315 | |||
315 | } |
|
316 | } | |
316 |
|
317 | |||
317 | void QValueAxisPrivate::setMin(const QVariant &min) |
|
318 | void QValueAxisPrivate::setMin(const QVariant &min) | |
318 | { |
|
319 | { | |
319 | Q_Q(QValueAxis); |
|
320 | Q_Q(QValueAxis); | |
320 | bool ok; |
|
321 | bool ok; | |
321 | qreal value = min.toReal(&ok); |
|
322 | qreal value = min.toReal(&ok); | |
322 | if (ok) |
|
323 | if (ok) | |
323 | q->setMin(value); |
|
324 | q->setMin(value); | |
324 | } |
|
325 | } | |
325 |
|
326 | |||
326 | void QValueAxisPrivate::setMax(const QVariant &max) |
|
327 | void QValueAxisPrivate::setMax(const QVariant &max) | |
327 | { |
|
328 | { | |
328 | Q_Q(QValueAxis); |
|
329 | Q_Q(QValueAxis); | |
329 | bool ok; |
|
330 | bool ok; | |
330 | qreal value = max.toReal(&ok); |
|
331 | qreal value = max.toReal(&ok); | |
331 | if (ok) |
|
332 | if (ok) | |
332 | q->setMax(value); |
|
333 | q->setMax(value); | |
333 | } |
|
334 | } | |
334 |
|
335 | |||
335 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
336 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
336 | { |
|
337 | { | |
337 | Q_Q(QValueAxis); |
|
338 | Q_Q(QValueAxis); | |
338 | bool ok1; |
|
339 | bool ok1; | |
339 | bool ok2; |
|
340 | bool ok2; | |
340 | qreal value1 = min.toReal(&ok1); |
|
341 | qreal value1 = min.toReal(&ok1); | |
341 | qreal value2 = max.toReal(&ok2); |
|
342 | qreal value2 = max.toReal(&ok2); | |
342 | if (ok1 && ok2) |
|
343 | if (ok1 && ok2) | |
343 | q->setRange(value1, value2); |
|
344 | q->setRange(value1, value2); | |
344 | } |
|
345 | } | |
345 |
|
346 | |||
346 | void QValueAxisPrivate::setRange(qreal min, qreal max) |
|
347 | void QValueAxisPrivate::setRange(qreal min, qreal max) | |
347 | { |
|
348 | { | |
348 | Q_Q(QValueAxis); |
|
349 | Q_Q(QValueAxis); | |
349 | bool changed = false; |
|
350 | bool changed = false; | |
350 |
|
351 | |||
351 | if (min > max) |
|
352 | if (min > max) | |
352 | return; |
|
353 | return; | |
353 |
|
354 | |||
354 | if (!qFuzzyCompare(m_min,min)) { |
|
355 | if (!qFuzzyCompare(m_min,min)) { | |
355 | m_min = min; |
|
356 | m_min = min; | |
356 | changed = true; |
|
357 | changed = true; | |
357 | emit q->minChanged(min); |
|
358 | emit q->minChanged(min); | |
358 | } |
|
359 | } | |
359 |
|
360 | |||
360 | if (!qFuzzyCompare(m_max,max)) { |
|
361 | if (!qFuzzyCompare(m_max,max)) { | |
361 | m_max = max; |
|
362 | m_max = max; | |
362 | changed = true; |
|
363 | changed = true; | |
363 | emit q->maxChanged(max); |
|
364 | emit q->maxChanged(max); | |
364 | } |
|
365 | } | |
365 |
|
366 | |||
366 | if (changed) { |
|
367 | if (changed) { | |
367 | emit rangeChanged(min,max); |
|
368 | emit rangeChanged(min,max); | |
368 | emit q->rangeChanged(min, max); |
|
369 | emit q->rangeChanged(min, max); | |
369 | } |
|
370 | } | |
370 | } |
|
371 | } | |
371 |
|
372 | |||
372 | void QValueAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
373 | void QValueAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
373 | { |
|
374 | { | |
374 | Q_Q(QValueAxis); |
|
375 | Q_Q(QValueAxis); | |
375 | ChartAxis* axis(0); |
|
376 | ChartAxis* axis(0); | |
376 | if (orientation() == Qt::Vertical) |
|
377 | if (orientation() == Qt::Vertical) | |
377 | axis = new ChartValueAxisY(q,parent); |
|
378 | axis = new ChartValueAxisY(q,parent); | |
378 | if (orientation() == Qt::Horizontal) |
|
379 | if (orientation() == Qt::Horizontal) | |
379 | axis = new ChartValueAxisX(q,parent); |
|
380 | axis = new ChartValueAxisX(q,parent); | |
380 |
|
381 | |||
381 | m_item.reset(axis); |
|
382 | m_item.reset(axis); | |
382 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
383 | QAbstractAxisPrivate::initializeGraphics(parent); | |
383 | } |
|
384 | } | |
384 |
|
385 | |||
385 |
|
386 | |||
386 | void QValueAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
387 | void QValueAxisPrivate::initializeDomain(AbstractDomain *domain) | |
387 | { |
|
388 | { | |
388 | if (orientation() == Qt::Vertical) { |
|
389 | if (orientation() == Qt::Vertical) { | |
389 | if(!qFuzzyIsNull(m_max - m_min)) { |
|
390 | if(!qFuzzyIsNull(m_max - m_min)) { | |
390 | domain->setRangeY(m_min, m_max); |
|
391 | domain->setRangeY(m_min, m_max); | |
391 | } |
|
392 | } | |
392 | else { |
|
393 | else { | |
393 | setRange(domain->minY(), domain->maxY()); |
|
394 | setRange(domain->minY(), domain->maxY()); | |
394 | } |
|
395 | } | |
395 | } |
|
396 | } | |
396 | if (orientation() == Qt::Horizontal) { |
|
397 | if (orientation() == Qt::Horizontal) { | |
397 | if(!qFuzzyIsNull(m_max - m_min)) { |
|
398 | if(!qFuzzyIsNull(m_max - m_min)) { | |
398 | domain->setRangeX(m_min, m_max); |
|
399 | domain->setRangeX(m_min, m_max); | |
399 | } |
|
400 | } | |
400 | else { |
|
401 | else { | |
401 | setRange(domain->minX(), domain->maxX()); |
|
402 | setRange(domain->minX(), domain->maxX()); | |
402 | } |
|
403 | } | |
403 | } |
|
404 | } | |
404 | } |
|
405 | } | |
405 |
|
406 | |||
406 | #include "moc_qvalueaxis.cpp" |
|
407 | #include "moc_qvalueaxis.cpp" | |
407 | #include "moc_qvalueaxis_p.cpp" |
|
408 | #include "moc_qvalueaxis_p.cpp" | |
408 |
|
409 | |||
409 | QTCOMMERCIALCHART_END_NAMESPACE |
|
410 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,83 +1,84 | |||||
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 QVALUEAXIS_H |
|
21 | #ifndef QVALUEAXIS_H | |
22 | #define QVALUEAXIS_H |
|
22 | #define QVALUEAXIS_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 NOTIFY tickCountChanged) |
|
33 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged) | |
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 | Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat NOTIFY labelFormatChanged) | |
38 |
|
38 | |||
39 | public: |
|
39 | public: | |
40 | explicit QValueAxis(QObject *parent = 0); |
|
40 | explicit QValueAxis(QObject *parent = 0); | |
41 | ~QValueAxis(); |
|
41 | ~QValueAxis(); | |
42 |
|
42 | |||
43 | protected: |
|
43 | protected: | |
44 | QValueAxis(QValueAxisPrivate &d, QObject *parent = 0); |
|
44 | QValueAxis(QValueAxisPrivate &d, QObject *parent = 0); | |
45 |
|
45 | |||
46 | public: |
|
46 | public: | |
47 | AxisType type() const; |
|
47 | AxisType type() const; | |
48 |
|
48 | |||
49 | //range handling |
|
49 | //range handling | |
50 | void setMin(qreal min); |
|
50 | void setMin(qreal min); | |
51 | qreal min() const; |
|
51 | qreal min() const; | |
52 | void setMax(qreal max); |
|
52 | void setMax(qreal max); | |
53 | qreal max() const; |
|
53 | qreal max() const; | |
54 | void setRange(qreal min, qreal max); |
|
54 | void setRange(qreal min, qreal max); | |
55 |
|
55 | |||
56 | //ticks handling |
|
56 | //ticks handling | |
57 | void setTickCount(int count); |
|
57 | void setTickCount(int count); | |
58 | int tickCount() const; |
|
58 | int tickCount() const; | |
59 |
|
59 | |||
60 | void setLabelFormat(const QString &format); |
|
60 | void setLabelFormat(const QString &format); | |
61 | QString labelFormat() const; |
|
61 | QString labelFormat() const; | |
62 |
|
62 | |||
63 | //TODO: depreciated ! |
|
63 | //TODO: depreciated ! | |
64 | void setNiceNumbersEnabled(bool enable = true); |
|
64 | void setNiceNumbersEnabled(bool enable = true); | |
65 | bool niceNumbersEnabled() const; |
|
65 | bool niceNumbersEnabled() const; | |
66 |
|
66 | |||
67 | public Q_SLOTS: |
|
67 | public Q_SLOTS: | |
68 | void applyNiceNumbers(); |
|
68 | void applyNiceNumbers(); | |
69 |
|
69 | |||
70 | Q_SIGNALS: |
|
70 | Q_SIGNALS: | |
71 | void minChanged(qreal min); |
|
71 | void minChanged(qreal min); | |
72 | void maxChanged(qreal max); |
|
72 | void maxChanged(qreal max); | |
73 | void rangeChanged(qreal min, qreal max); |
|
73 | void rangeChanged(qreal min, qreal max); | |
74 | void tickCountChanged(int tickCount); |
|
74 | void tickCountChanged(int tickCount); | |
|
75 | void labelFormatChanged(const QString &format); | |||
75 |
|
76 | |||
76 | private: |
|
77 | private: | |
77 | Q_DECLARE_PRIVATE(QValueAxis) |
|
78 | Q_DECLARE_PRIVATE(QValueAxis) | |
78 | Q_DISABLE_COPY(QValueAxis) |
|
79 | Q_DISABLE_COPY(QValueAxis) | |
79 | }; |
|
80 | }; | |
80 |
|
81 | |||
81 | QTCOMMERCIALCHART_END_NAMESPACE |
|
82 | QTCOMMERCIALCHART_END_NAMESPACE | |
82 |
|
83 | |||
83 | #endif // QVALUEAXIS_H |
|
84 | #endif // QVALUEAXIS_H |
General Comments 0
You need to be logged in to leave comments.
Login now