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