##// END OF EJS Templates
Fix logdomain initialization
Marek Rosa -
r2355:66a2c62c4a9b
parent child
Show More
@@ -1,372 +1,374
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 LogValuesAxis QLogValueAxis
37 \qmlclass LogValuesAxis QLogValueAxis
38 \brief The LogValueAxis element is used for manipulating chart's axes
38 \brief The LogValueAxis 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 Value has to be greater then 0.
46 Value has to be greater then 0.
47 */
47 */
48 /*!
48 /*!
49 \qmlproperty real LogValuesAxis::min
49 \qmlproperty real LogValuesAxis::min
50 Defines the minimum value on the axis.
50 Defines the minimum value on the axis.
51 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
51 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
52 Value has to be greater then 0.
52 Value has to be greater then 0.
53 */
53 */
54
54
55 /*!
55 /*!
56 \property QLogValueAxis::max
56 \property QLogValueAxis::max
57 Defines the maximum value on the axis.
57 Defines the maximum value on the axis.
58 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
58 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
59 Value has to be greater then 0.
59 Value has to be greater then 0.
60 */
60 */
61 /*!
61 /*!
62 \qmlproperty real LogValuesAxis::max
62 \qmlproperty real LogValuesAxis::max
63 Defines the maximum value on the axis.
63 Defines the maximum value on the axis.
64 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
64 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
65 Value has to be greater then 0.
65 Value has to be greater then 0.
66 */
66 */
67
67
68 /*!
68 /*!
69 \property QLogValueAxis::base
69 \property QLogValueAxis::base
70 Defines the base of the logarithm.
70 Defines the base of the logarithm.
71 Value has to be greater then 0 and not equal 1
71 Value has to be greater then 0 and not equal 1
72 */
72 */
73 /*!
73 /*!
74 \qmlproperty real LogValuesAxis::base
74 \qmlproperty real LogValuesAxis::base
75 Defines the maximum value on the axis.
75 Defines the maximum value on the axis.
76 Defines the base of the logarithm.
76 Defines the base of the logarithm.
77 Value has to be greater then 0 and not equal 1
77 Value has to be greater then 0 and not equal 1
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QLogValueAxis::labelFormat
81 \property QLogValueAxis::labelFormat
82 Defines the label format of the axis.
82 Defines the label format of the axis.
83 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
83 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
84 See QString::sprintf() for additional details.
84 See QString::sprintf() for additional details.
85 */
85 */
86 /*!
86 /*!
87 \qmlproperty real LogValuesAxis::labelFormat
87 \qmlproperty real LogValuesAxis::labelFormat
88 Defines the label format of the axis.
88 Defines the label format of the axis.
89 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
89 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
90 See QString::sprintf() for additional details.
90 See QString::sprintf() for additional details.
91 */
91 */
92
92
93 /*!
93 /*!
94 \fn void QLogValueAxis::minChanged(qreal min)
94 \fn void QLogValueAxis::minChanged(qreal min)
95 Axis emits signal when \a min of axis has changed.
95 Axis emits signal when \a min of axis has changed.
96 */
96 */
97 /*!
97 /*!
98 \qmlsignal LogValuesAxis::onMinChanged(qreal min)
98 \qmlsignal LogValuesAxis::onMinChanged(qreal min)
99 Axis emits signal when \a min of axis has changed.
99 Axis emits signal when \a min of axis has changed.
100 */
100 */
101
101
102 /*!
102 /*!
103 \fn void QLogValueAxis::maxChanged(qreal max)
103 \fn void QLogValueAxis::maxChanged(qreal max)
104 Axis emits signal when \a max of axis has changed.
104 Axis emits signal when \a max of axis has changed.
105 */
105 */
106 /*!
106 /*!
107 \qmlsignal LogValuesAxis::onMaxChanged(qreal max)
107 \qmlsignal LogValuesAxis::onMaxChanged(qreal max)
108 Axis emits signal when \a max of axis has changed.
108 Axis emits signal when \a max of axis has changed.
109 */
109 */
110
110
111 /*!
111 /*!
112 \fn void QLogValueAxis::rangeChanged(qreal min, qreal max)
112 \fn void QLogValueAxis::rangeChanged(qreal min, qreal max)
113 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.
114 */
114 */
115
115
116 /*!
116 /*!
117 \fn void QLogValueAxis::labelFormatChanged(const QString &format)
117 \fn void QLogValueAxis::labelFormatChanged(const QString &format)
118 Axis emits signal when \a format of axis labels has changed.
118 Axis emits signal when \a format of axis labels has changed.
119 */
119 */
120 /*!
120 /*!
121 \qmlsignal LogValueAxis::labelFormatChanged(const QString &format)
121 \qmlsignal LogValueAxis::labelFormatChanged(const QString &format)
122 Axis emits signal when \a format of axis labels has changed.
122 Axis emits signal when \a format of axis labels has changed.
123 */
123 */
124
124
125 /*!
125 /*!
126 \fn void QLogValueAxis::baseChanged(qreal base)
126 \fn void QLogValueAxis::baseChanged(qreal base)
127 Axis emits signal when \a base of logarithm of the axis has changed.
127 Axis emits signal when \a base of logarithm of the axis has changed.
128 */
128 */
129 /*!
129 /*!
130 \qmlsignal LogValuesAxis::baseChanged(qreal base)
130 \qmlsignal LogValuesAxis::baseChanged(qreal base)
131 Axis emits signal when \a base of logarithm of the axis has changed.
131 Axis emits signal when \a base of logarithm of the axis has changed.
132 */
132 */
133
133
134 /*!
134 /*!
135 Constructs an axis object which is a child of \a parent.
135 Constructs an axis object which is a child of \a parent.
136 */
136 */
137 QLogValueAxis::QLogValueAxis(QObject *parent) :
137 QLogValueAxis::QLogValueAxis(QObject *parent) :
138 QAbstractAxis(*new QLogValueAxisPrivate(this), parent)
138 QAbstractAxis(*new QLogValueAxisPrivate(this), parent)
139 {
139 {
140
140
141 }
141 }
142
142
143 /*!
143 /*!
144 \internal
144 \internal
145 */
145 */
146 QLogValueAxis::QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent)
146 QLogValueAxis::QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent)
147 {
147 {
148
148
149 }
149 }
150
150
151 /*!
151 /*!
152 Destroys the object
152 Destroys the object
153 */
153 */
154 QLogValueAxis::~QLogValueAxis()
154 QLogValueAxis::~QLogValueAxis()
155 {
155 {
156 Q_D(QLogValueAxis);
156 Q_D(QLogValueAxis);
157 if (d->m_chart)
157 if (d->m_chart)
158 d->m_chart->removeAxis(this);
158 d->m_chart->removeAxis(this);
159 }
159 }
160
160
161 void QLogValueAxis::setMin(qreal min)
161 void QLogValueAxis::setMin(qreal min)
162 {
162 {
163 Q_D(QLogValueAxis);
163 Q_D(QLogValueAxis);
164 setRange(min, qMax(d->m_max, min));
164 setRange(min, qMax(d->m_max, min));
165 }
165 }
166
166
167 qreal QLogValueAxis::min() const
167 qreal QLogValueAxis::min() const
168 {
168 {
169 Q_D(const QLogValueAxis);
169 Q_D(const QLogValueAxis);
170 return d->m_min;
170 return d->m_min;
171 }
171 }
172
172
173 void QLogValueAxis::setMax(qreal max)
173 void QLogValueAxis::setMax(qreal max)
174 {
174 {
175 Q_D(QLogValueAxis);
175 Q_D(QLogValueAxis);
176 setRange(qMin(d->m_min, max), max);
176 setRange(qMin(d->m_min, max), max);
177 }
177 }
178
178
179 qreal QLogValueAxis::max() const
179 qreal QLogValueAxis::max() const
180 {
180 {
181 Q_D(const QLogValueAxis);
181 Q_D(const QLogValueAxis);
182 return d->m_max;
182 return d->m_max;
183 }
183 }
184
184
185 /*!
185 /*!
186 Sets range from \a min to \a max on the axis.
186 Sets range from \a min to \a max on the axis.
187 If min is greater than max then this function returns without making any changes.
187 If min is greater than max then this function returns without making any changes.
188 */
188 */
189 void QLogValueAxis::setRange(qreal min, qreal max)
189 void QLogValueAxis::setRange(qreal min, qreal max)
190 {
190 {
191 Q_D(QLogValueAxis);
191 Q_D(QLogValueAxis);
192 bool changed = false;
192 bool changed = false;
193
193
194 if (min > max)
194 if (min > max)
195 return;
195 return;
196
196
197 if (min > 0) {
197 if (min > 0) {
198 if (!qFuzzyCompare(d->m_min, min)) {
198 if (!qFuzzyCompare(d->m_min, min)) {
199 d->m_min = min;
199 d->m_min = min;
200 changed = true;
200 changed = true;
201 emit minChanged(min);
201 emit minChanged(min);
202 }
202 }
203
203
204 if (!qFuzzyCompare(d->m_max, max)) {
204 if (!qFuzzyCompare(d->m_max, max)) {
205 d->m_max = max;
205 d->m_max = max;
206 changed = true;
206 changed = true;
207 emit maxChanged(max);
207 emit maxChanged(max);
208 }
208 }
209
209
210 if (changed) {
210 if (changed) {
211 emit rangeChanged(min, max);
211 emit rangeChanged(min, max);
212 emit d->rangeChanged(min,max);
212 emit d->rangeChanged(min,max);
213 }
213 }
214 }
214 }
215 }
215 }
216
216
217 void QLogValueAxis::setLabelFormat(const QString &format)
217 void QLogValueAxis::setLabelFormat(const QString &format)
218 {
218 {
219 Q_D(QLogValueAxis);
219 Q_D(QLogValueAxis);
220 d->m_format = format;
220 d->m_format = format;
221 emit labelFormatChanged(format);
221 emit labelFormatChanged(format);
222 }
222 }
223
223
224 QString QLogValueAxis::labelFormat() const
224 QString QLogValueAxis::labelFormat() const
225 {
225 {
226 Q_D(const QLogValueAxis);
226 Q_D(const QLogValueAxis);
227 return d->m_format;
227 return d->m_format;
228 }
228 }
229
229
230 void QLogValueAxis::setBase(qreal base)
230 void QLogValueAxis::setBase(qreal base)
231 {
231 {
232 // check if base is correct
232 // check if base is correct
233 if (qFuzzyCompare(base, 1))
233 if (qFuzzyCompare(base, 1))
234 return;
234 return;
235
235
236 if (base > 0) {
236 if (base > 0) {
237 Q_D(QLogValueAxis);
237 Q_D(QLogValueAxis);
238 d->m_base = base;
238 d->m_base = base;
239 emit baseChanged(base);
239 emit baseChanged(base);
240 }
240 }
241 }
241 }
242
242
243 qreal QLogValueAxis::base() const
243 qreal QLogValueAxis::base() const
244 {
244 {
245 Q_D(const QLogValueAxis);
245 Q_D(const QLogValueAxis);
246 return d->m_base;
246 return d->m_base;
247 }
247 }
248
248
249 /*!
249 /*!
250 Returns the type of the axis
250 Returns the type of the axis
251 */
251 */
252 QAbstractAxis::AxisType QLogValueAxis::type() const
252 QAbstractAxis::AxisType QLogValueAxis::type() const
253 {
253 {
254 return AxisTypeLogValue;
254 return AxisTypeLogValue;
255 }
255 }
256
256
257 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
257 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
258
258
259 QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q)
259 QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q)
260 : QAbstractAxisPrivate(q),
260 : QAbstractAxisPrivate(q),
261 m_min(1),
261 m_min(1),
262 m_max(1),
262 m_max(1),
263 m_base(10),
263 m_base(10),
264 m_format(QString::null)
264 m_format(QString::null)
265 {
265 {
266 }
266 }
267
267
268 QLogValueAxisPrivate::~QLogValueAxisPrivate()
268 QLogValueAxisPrivate::~QLogValueAxisPrivate()
269 {
269 {
270
270
271 }
271 }
272
272
273 void QLogValueAxisPrivate::setMin(const QVariant &min)
273 void QLogValueAxisPrivate::setMin(const QVariant &min)
274 {
274 {
275 Q_Q(QLogValueAxis);
275 Q_Q(QLogValueAxis);
276 bool ok;
276 bool ok;
277 qreal value = min.toReal(&ok);
277 qreal value = min.toReal(&ok);
278 if (ok)
278 if (ok)
279 q->setMin(value);
279 q->setMin(value);
280 }
280 }
281
281
282 void QLogValueAxisPrivate::setMax(const QVariant &max)
282 void QLogValueAxisPrivate::setMax(const QVariant &max)
283 {
283 {
284
284
285 Q_Q(QLogValueAxis);
285 Q_Q(QLogValueAxis);
286 bool ok;
286 bool ok;
287 qreal value = max.toReal(&ok);
287 qreal value = max.toReal(&ok);
288 if (ok)
288 if (ok)
289 q->setMax(value);
289 q->setMax(value);
290 }
290 }
291
291
292 void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
292 void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
293 {
293 {
294 Q_Q(QLogValueAxis);
294 Q_Q(QLogValueAxis);
295 bool ok1;
295 bool ok1;
296 bool ok2;
296 bool ok2;
297 qreal value1 = min.toReal(&ok1);
297 qreal value1 = min.toReal(&ok1);
298 qreal value2 = max.toReal(&ok2);
298 qreal value2 = max.toReal(&ok2);
299 if (ok1 && ok2)
299 if (ok1 && ok2)
300 q->setRange(value1, value2);
300 q->setRange(value1, value2);
301 }
301 }
302
302
303 void QLogValueAxisPrivate::setRange(qreal min, qreal max)
303 void QLogValueAxisPrivate::setRange(qreal min, qreal max)
304 {
304 {
305 Q_Q(QLogValueAxis);
305 Q_Q(QLogValueAxis);
306 bool changed = false;
306 bool changed = false;
307
307
308 if (min > max)
308 if (min > max)
309 return;
309 return;
310
310
311 if (min > 0) {
311 if (min > 0) {
312 if (!qFuzzyCompare(m_min, min)) {
312 if (!qFuzzyCompare(m_min, min)) {
313 m_min = min;
313 m_min = min;
314 changed = true;
314 changed = true;
315 emit q->minChanged(min);
315 emit q->minChanged(min);
316 }
316 }
317
317
318 if (!qFuzzyCompare(m_max, max)) {
318 if (!qFuzzyCompare(m_max, max)) {
319 m_max = max;
319 m_max = max;
320 changed = true;
320 changed = true;
321 emit q->maxChanged(max);
321 emit q->maxChanged(max);
322 }
322 }
323
323
324 if (changed) {
324 if (changed) {
325 emit rangeChanged(min,max);
325 emit rangeChanged(min,max);
326 emit q->rangeChanged(min, max);
326 emit q->rangeChanged(min, max);
327 }
327 }
328 }
328 }
329 }
329 }
330
330
331 void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
331 void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
332 {
332 {
333 Q_Q(QLogValueAxis);
333 Q_Q(QLogValueAxis);
334 ChartAxis* axis(0);
334 ChartAxis* axis(0);
335 if (orientation() == Qt::Vertical)
335 if (orientation() == Qt::Vertical)
336 axis = new ChartLogValueAxisY(q,parent);
336 axis = new ChartLogValueAxisY(q,parent);
337 if (orientation() == Qt::Horizontal)
337 if (orientation() == Qt::Horizontal)
338 axis = new ChartLogValueAxisX(q,parent);
338 axis = new ChartLogValueAxisX(q,parent);
339
339
340 m_item.reset(axis);
340 m_item.reset(axis);
341 QAbstractAxisPrivate::initializeGraphics(parent);
341 QAbstractAxisPrivate::initializeGraphics(parent);
342 }
342 }
343
343
344
344
345 void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain)
345 void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain)
346 {
346 {
347 if (orientation() == Qt::Vertical) {
347 if (orientation() == Qt::Vertical) {
348 if(!qFuzzyCompare(m_max, m_min)) {
348 if(!qFuzzyCompare(m_max, m_min)) {
349 domain->setRangeY(m_min, m_max);
349 domain->setRangeY(m_min, m_max);
350 }
350 } else if ( domain->minY() > 0) {
351 else if ( domain->minY() > 0) {
352 setRange(domain->minY(), domain->maxY());
351 setRange(domain->minY(), domain->maxY());
353 } else {
352 } else if (domain->maxY() > 0) {
354 domain->setRangeY(m_min, domain->maxY());
353 domain->setRangeY(m_min, domain->maxY());
354 } else {
355 domain->setRangeY(1, 10);
355 }
356 }
356 }
357 }
357 if (orientation() == Qt::Horizontal) {
358 if (orientation() == Qt::Horizontal) {
358 if(!qFuzzyCompare(m_max, m_min)) {
359 if(!qFuzzyCompare(m_max, m_min)) {
359 domain->setRangeX(m_min, m_max);
360 domain->setRangeX(m_min, m_max);
360 }
361 } else if (domain->minX() > 0){
361 else if (domain->minX() > 0){
362 setRange(domain->minX(), domain->maxX());
362 setRange(domain->minX(), domain->maxX());
363 } else {
363 } else if (domain->maxX() > 0) {
364 domain->setRangeX(m_min, domain->maxX());
364 domain->setRangeX(m_min, domain->maxX());
365 } else {
366 domain->setRangeX(1, 10);
365 }
367 }
366 }
368 }
367 }
369 }
368
370
369 #include "moc_qlogvalueaxis.cpp"
371 #include "moc_qlogvalueaxis.cpp"
370 #include "moc_qlogvalueaxis_p.cpp"
372 #include "moc_qlogvalueaxis_p.cpp"
371
373
372 QTCOMMERCIALCHART_END_NAMESPACE
374 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now