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