##// END OF EJS Templates
Fix value axis documentation...
Titta Heikkala -
r2636:25b732239a6d
parent child
Show More
@@ -1,435 +1,436
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 11 ** accordance with the Qt Enterprise 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 "qvalueaxis.h"
22 22 #include "qvalueaxis_p.h"
23 23 #include "chartvalueaxisx_p.h"
24 24 #include "chartvalueaxisy_p.h"
25 25 #include "abstractdomain_p.h"
26 26 #include "polarchartvalueaxisangular_p.h"
27 27 #include "polarchartvalueaxisradial_p.h"
28 28 #include "chartdataset_p.h"
29 29 #include "chartpresenter_p.h"
30 30 #include "charttheme_p.h"
31 31
32 32
33 33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 34 /*!
35 35 \class QValueAxis
36 36 \brief The QValueAxis class is used for manipulating chart's axis.
37 37 \mainclass
38 38
39 39 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
40 40 Values of axis are drawn to position of ticks.
41 41
42 42 Example code on how to use QValueAxis.
43 43 \code
44 44 QChartView *chartView = new QChartView;
45 45 QLineSeries *series = new QLineSeries;
46 46 // ...
47 47 chartView->chart()->addSeries(series);
48 48
49 49 QValueAxis *axisX = new QValueAxis;
50 50 axisX->setRange(10, 20.5);
51 51 axisX->setTickCount(10);
52 52 axisX->setLabelFormat("%.2f");
53 53 chartView->chart()->setAxisX(axisX, series);
54 54 \endcode
55 55 */
56 56
57 57 /*!
58 58 \qmlclass ValueAxis QValueAxis
59 59 \inherits AbstractAxis
60 60 \brief The ValueAxis element is used for manipulating chart's axes
61 61
62 62 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
63 63 Values of axis are drawn to position of ticks
64 64
65 65 Example about using ValueAxis:
66 66 \code
67 67 ChartView {
68 68 ValueAxis {
69 69 id: xAxis
70 70 min: 0
71 71 max: 10
72 72 }
73 73 // Add a few series...
74 74 }
75 75 \endcode
76 76 */
77 77
78 78 /*!
79 79 \property QValueAxis::min
80 80 Defines the minimum value on the axis.
81 81 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
82 82 */
83 83 /*!
84 84 \qmlproperty real ValueAxis::min
85 85 Defines the minimum value on the axis.
86 86 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
87 87 */
88 88
89 89 /*!
90 90 \property QValueAxis::max
91 91 Defines the maximum value on the axis.
92 92 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
93 93 */
94 94 /*!
95 95 \qmlproperty real ValueAxis::max
96 96 Defines the maximum value on the axis.
97 97 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
98 98 */
99 99
100 100 /*!
101 101 \property QValueAxis::tickCount
102 102 Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart.
103 103 The default value is 5, and it can not be below 2.
104 104 */
105 105 /*!
106 106 \qmlproperty real ValueAxis::tickCount
107 107 Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart.
108 108 The default value is 5, and it can not be below 2.
109 109 */
110 110
111 111 /*!
112 112 \property QValueAxis::labelFormat
113 113 Defines the label format of the axis.
114 114 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
115 115 See QString::sprintf() for additional details.
116 116 */
117 117 /*!
118 118 \qmlproperty real ValueAxis::labelFormat
119 119 Defines the label format of the axis.
120 120 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
121 121 See QString::sprintf() for additional details.
122 122 */
123 123
124 124 /*!
125 125 \fn void QValueAxis::minChanged(qreal min)
126 126 Axis emits signal when \a min of axis has changed.
127 127 */
128 128 /*!
129 129 \qmlsignal ValueAxis::onMinChanged(real min)
130 130 Axis emits signal when \a min of axis has changed.
131 131 */
132 132
133 133 /*!
134 134 \fn void QValueAxis::maxChanged(qreal max)
135 135 Axis emits signal when \a max of axis has changed.
136 136 */
137 137 /*!
138 138 \qmlsignal ValueAxis::onMaxChanged(real max)
139 139 Axis emits signal when \a max of axis has changed.
140 140 */
141 141
142 142 /*!
143 143 \fn void QValueAxis::tickCountChanged(int tickCount)
144 144 Axis emits signal when \a tickCount of axis has changed.
145 145 */
146 146 /*!
147 147 \qmlsignal ValueAxis::tickCountChanged(int tickCount)
148 148 Axis emits signal when \a tickCount of axis has changed.
149 149 */
150 150
151 151 /*!
152 152 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
153 153 Axis emits signal when \a min or \a max of axis has changed.
154 154 */
155 155
156 156 /*!
157 157 \fn void QValueAxis::labelFormatChanged(const QString &format)
158 158 Axis emits signal when \a format of axis labels has changed.
159 159 */
160 160 /*!
161 161 \qmlsignal ValueAxis::labelFormatChanged(const QString &format)
162 162 Axis emits signal when \a format of axis labels has changed.
163 163 */
164 164
165 165 /*!
166 166 \property QValueAxis::niceNumbersEnabled
167 167 \obsolete
168 168 Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead.
169 169 */
170 170
171 171 /*!
172 172 \qmlproperty bool ValueAxis::niceNumbersEnabled
173 \obsolete
174 Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead.
173 Deprecated; Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead.
175 174 */
176 175
177 176 /*!
178 177 Constructs an axis object which is a child of \a parent.
179 178 */
180 179 QValueAxis::QValueAxis(QObject *parent) :
181 180 QAbstractAxis(*new QValueAxisPrivate(this), parent)
182 181 {
183 182
184 183 }
185 184
186 185 /*!
187 186 \internal
188 187 */
189 188 QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent)
190 189 : QAbstractAxis(d, parent)
191 190 {
192 191
193 192 }
194 193
195 194 /*!
196 195 Destroys the object
197 196 */
198 197 QValueAxis::~QValueAxis()
199 198 {
200 199 Q_D(QValueAxis);
201 200 if (d->m_chart)
202 201 d->m_chart->removeAxis(this);
203 202 }
204 203
205 204 void QValueAxis::setMin(qreal min)
206 205 {
207 206 Q_D(QValueAxis);
208 207 setRange(min, qMax(d->m_max, min));
209 208 }
210 209
211 210 qreal QValueAxis::min() const
212 211 {
213 212 Q_D(const QValueAxis);
214 213 return d->m_min;
215 214 }
216 215
217 216 void QValueAxis::setMax(qreal max)
218 217 {
219 218 Q_D(QValueAxis);
220 219 setRange(qMin(d->m_min, max), max);
221 220 }
222 221
223 222 qreal QValueAxis::max() const
224 223 {
225 224 Q_D(const QValueAxis);
226 225 return d->m_max;
227 226 }
228 227
229 228 /*!
230 229 Sets range from \a min to \a max on the axis.
231 230 If min is greater than max then this function returns without making any changes.
232 231 */
233 232 void QValueAxis::setRange(qreal min, qreal max)
234 233 {
235 234 Q_D(QValueAxis);
236 235 d->setRange(min,max);
237 236 }
238 237
239 238 void QValueAxis::setTickCount(int count)
240 239 {
241 240 Q_D(QValueAxis);
242 241 if (d->m_tickCount != count && count >= 2) {
243 242 d->m_tickCount = count;
244 243 emit tickCountChanged(count);
245 244 }
246 245 }
247 246
248 247 int QValueAxis::tickCount() const
249 248 {
250 249 Q_D(const QValueAxis);
251 250 return d->m_tickCount;
252 251 }
253 252
254 253 void QValueAxis::setNiceNumbersEnabled(bool enable)
255 254 {
256 255 Q_D(QValueAxis);
257 qWarning()<<"This function is depreciated, it can lead to unexpected behavior.Use applyNiceNumbers(). ";
256 qWarning() << "Deprecated; Using this function can lead to unexpected behavior. " \
257 "Use applyNiceNumbers() instead.";
258 258 if(enable) {
259 259 QObject::connect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers()));
260 260 QObject::connect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers()));
261 261 applyNiceNumbers();
262 262 }
263 263 else {
264 264 QObject::disconnect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers()));
265 265 QObject::disconnect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers()));
266 266 }
267 267 d->m_niceNumbersEnabled=enable;
268 268 }
269 269
270 270 bool QValueAxis::niceNumbersEnabled() const
271 271 {
272 272 Q_D(const QValueAxis);
273 qWarning()<<"This function is depreciated.Use applyNiceNumbers().";
273 qWarning() << "Deprecated; Using this function can lead to unexpected behavior. " \
274 "Use applyNiceNumbers() instead.";
274 275 return d->m_niceNumbersEnabled;
275 276 }
276 277
277 278 void QValueAxis::setLabelFormat(const QString &format)
278 279 {
279 280 Q_D(QValueAxis);
280 281 d->m_format = format;
281 282 emit labelFormatChanged(format);
282 283 }
283 284
284 285 QString QValueAxis::labelFormat() const
285 286 {
286 287 Q_D(const QValueAxis);
287 288 return d->m_format;
288 289 }
289 290
290 291 /*!
291 292 Returns the type of the axis
292 293 */
293 294 QAbstractAxis::AxisType QValueAxis::type() const
294 295 {
295 296 return AxisTypeValue;
296 297 }
297 298
298 299 /*!
299 300 This method modifies range and number of ticks on the axis to look "nice". Algorithm considers numbers that
300 301 can be expressed as form of 1*10^n, 2* 10^n or 5*10^n as a nice numbers. These numbers are used for spacing the ticks.
301 302 This method will modify the current range and number of ticks.
302 303 \sa setRange(), setTickCount()
303 304 */
304 305 void QValueAxis::applyNiceNumbers()
305 306 {
306 307 Q_D(QValueAxis);
307 308 if(d->m_applying) return;
308 309 qreal min = d->m_min;
309 310 qreal max = d->m_max;
310 311 int ticks = d->m_tickCount;
311 312 AbstractDomain::looseNiceNumbers(min,max,ticks);
312 313 d->m_applying=true;
313 314 d->setRange(min,max);
314 315 setTickCount(ticks);
315 316 d->m_applying=false;
316 317 }
317 318
318 319 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
319 320
320 321 QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q)
321 322 : QAbstractAxisPrivate(q),
322 323 m_min(0),
323 324 m_max(0),
324 325 m_tickCount(5),
325 326 m_format(QString::null),
326 327 m_applying(false),
327 328 m_niceNumbersEnabled(false)
328 329 {
329 330
330 331 }
331 332
332 333 QValueAxisPrivate::~QValueAxisPrivate()
333 334 {
334 335
335 336 }
336 337
337 338 void QValueAxisPrivate::setMin(const QVariant &min)
338 339 {
339 340 Q_Q(QValueAxis);
340 341 bool ok;
341 342 qreal value = min.toReal(&ok);
342 343 if (ok)
343 344 q->setMin(value);
344 345 }
345 346
346 347 void QValueAxisPrivate::setMax(const QVariant &max)
347 348 {
348 349 Q_Q(QValueAxis);
349 350 bool ok;
350 351 qreal value = max.toReal(&ok);
351 352 if (ok)
352 353 q->setMax(value);
353 354 }
354 355
355 356 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
356 357 {
357 358 Q_Q(QValueAxis);
358 359 bool ok1;
359 360 bool ok2;
360 361 qreal value1 = min.toReal(&ok1);
361 362 qreal value2 = max.toReal(&ok2);
362 363 if (ok1 && ok2)
363 364 q->setRange(value1, value2);
364 365 }
365 366
366 367 void QValueAxisPrivate::setRange(qreal min, qreal max)
367 368 {
368 369 Q_Q(QValueAxis);
369 370 bool changed = false;
370 371
371 372 if (min > max)
372 373 return;
373 374
374 375 if (!qFuzzyCompare(m_min,min)) {
375 376 m_min = min;
376 377 changed = true;
377 378 emit q->minChanged(min);
378 379 }
379 380
380 381 if (!qFuzzyCompare(m_max,max)) {
381 382 m_max = max;
382 383 changed = true;
383 384 emit q->maxChanged(max);
384 385 }
385 386
386 387 if (changed) {
387 388 emit rangeChanged(min,max);
388 389 emit q->rangeChanged(min, max);
389 390 }
390 391 }
391 392
392 393 void QValueAxisPrivate::initializeGraphics(QGraphicsItem *parent)
393 394 {
394 395 Q_Q(QValueAxis);
395 396 ChartAxisElement *axis(0);
396 397
397 398 if (m_chart->chartType() == QChart::ChartTypeCartesian) {
398 399 if (orientation() == Qt::Vertical)
399 400 axis = new ChartValueAxisY(q,parent);
400 401 if (orientation() == Qt::Horizontal)
401 402 axis = new ChartValueAxisX(q,parent);
402 403 }
403 404
404 405 if (m_chart->chartType() == QChart::ChartTypePolar) {
405 406 if (orientation() == Qt::Vertical)
406 407 axis = new PolarChartValueAxisRadial(q, parent);
407 408 if (orientation() == Qt::Horizontal)
408 409 axis = new PolarChartValueAxisAngular(q, parent);
409 410 }
410 411
411 412 m_item.reset(axis);
412 413 QAbstractAxisPrivate::initializeGraphics(parent);
413 414 }
414 415
415 416
416 417 void QValueAxisPrivate::initializeDomain(AbstractDomain *domain)
417 418 {
418 419 if (orientation() == Qt::Vertical) {
419 420 if (!qFuzzyIsNull(m_max - m_min))
420 421 domain->setRangeY(m_min, m_max);
421 422 else
422 423 setRange(domain->minY(), domain->maxY());
423 424 }
424 425 if (orientation() == Qt::Horizontal) {
425 426 if (!qFuzzyIsNull(m_max - m_min))
426 427 domain->setRangeX(m_min, m_max);
427 428 else
428 429 setRange(domain->minX(), domain->maxX());
429 430 }
430 431 }
431 432
432 433 #include "moc_qvalueaxis.cpp"
433 434 #include "moc_qvalueaxis_p.cpp"
434 435
435 436 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now