##// END OF EJS Templates
Adds proper docs for tickCount on valueaxis
Michal Klocek -
r2308:b27f3a00c396
parent child
Show More
@@ -1,391 +1,394
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 "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 "chartdataset_p.h"
27 27 #include "chartpresenter_p.h"
28 28 #include "charttheme_p.h"
29 29
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32 /*!
33 33 \class QValueAxis
34 34 \brief The QValueAxis class is used for manipulating chart's axis.
35 35 \mainclass
36 36
37 37 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
38 38 Values of axis are drawn to position of ticks.
39 39
40 40 Example code on how to use QValueAxis.
41 41 \code
42 42 QChartView *chartView = new QChartView;
43 43 QLineSeries *series = new QLineSeries;
44 44 // ...
45 45 chartView->chart()->addSeries(series);
46 46
47 47 QValueAxis *axisX = new QValueAxis;
48 48 axisX->setRange(10, 20.5);
49 49 axisX->setTickCount(10);
50 50 axisX->setLabelFormat("%.2f");
51 51 chartView->chart()->setAxisX(axisX, series);
52 52 \endcode
53 53 */
54 54
55 55 /*!
56 56 \qmlclass ValueAxis QValueAxis
57 57 \inherits AbstractAxis
58 58 \brief The ValueAxis element is used for manipulating chart's axes
59 59
60 60 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
61 61 Values of axis are drawn to position of ticks
62 62
63 63 To access Axes you can use ChartView API. For example:
64 64 \code
65 65 ChartView {
66 66 ValueAxis {
67 67 id: xAxis
68 68 min: 0
69 69 max: 10
70 70 }
71 71 // Add a few series...
72 72 }
73 73 \endcode
74 74 */
75 75
76 76 /*!
77 77 \property QValueAxis::min
78 78 Defines the minimum value on the axis.
79 79 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
80 80 */
81 81 /*!
82 82 \qmlproperty real ValueAxis::min
83 83 Defines the minimum value on the axis.
84 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 88 \property QValueAxis::max
89 89 Defines the maximum value on the axis.
90 90 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
91 91 */
92 92 /*!
93 93 \qmlproperty real ValueAxis::max
94 94 Defines the maximum value on the axis.
95 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
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.
102 */
103 /*!
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.
106 The default value is 5, and it can not be below 2.
107 */
108
109 /*!
99 110 \property QValueAxis::labelFormat
100 111 Defines the label format for the axis.
101 112 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
102 113 See QString::sprintf() for additional details.
103 114 */
104 115 /*!
105 116 \qmlproperty real ValueAxis::labelFormat
106 117 Defines the label format for the axis.
107 118 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
108 119 See QString::sprintf() for additional details.
109 120 */
110 121
111 122 /*!
112 123 \fn void QValueAxis::minChanged(qreal min)
113 124 Axis emits signal when \a min of axis has changed.
114 125 */
115 126 /*!
116 127 \qmlsignal ValueAxis::onMinChanged(real min)
117 128 Axis emits signal when \a min of axis has changed.
118 129 */
119 130
120 131 /*!
121 132 \fn void QValueAxis::maxChanged(qreal max)
122 133 Axis emits signal when \a max of axis has changed.
123 134 */
124 135 /*!
125 136 \qmlsignal ValueAxis::onMaxChanged(real max)
126 137 Axis emits signal when \a max of axis has changed.
127 138 */
128 139
129 140 /*!
130 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
131 Axis emits signal when \a min or \a max of axis has changed.
141 \fn void QValueAxis::tickCountChanged(int tickCount)
142 Axis emits signal when number of ticks on axis have changed.
132 143 */
133
134 144 /*!
135 \property QValueAxis::tickCount
136 The number of tick marks for the axis.
145 \qmlsignal ValueAxis::tickCountChanged(int tickCount)
146 Axis emits signal when number of ticks on axis have changed.
137 147 */
138 148
139 149 /*!
140 \qmlproperty int ValueAxis::tickCount
141 The number of tick marks for the axis.
150 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
151 Axis emits signal when \a min or \a max of axis has changed.
142 152 */
143 153
144 154 /*!
145 155 \property QValueAxis::niceNumbersEnabled
146 156 Whether the nice numbers algorithm is enabled or not for the axis.
147 157 */
148 158
149 159 /*!
150 160 \qmlproperty bool ValueAxis::niceNumbersEnabled
151 161 Whether the nice numbers algorithm is enabled or not for the axis.
152 162 */
153 163
154 164 /*!
155 165 Constructs an axis object which is a child of \a parent.
156 166 */
157 167 QValueAxis::QValueAxis(QObject *parent) :
158 168 QAbstractAxis(*new QValueAxisPrivate(this), parent)
159 169 {
160 170
161 171 }
162 172
163 173 /*!
164 174 \internal
165 175 */
166 176 QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent)
167 177 : QAbstractAxis(d, parent)
168 178 {
169 179
170 180 }
171 181
172 182 /*!
173 183 Destroys the object
174 184 */
175 185 QValueAxis::~QValueAxis()
176 186 {
177 187 Q_D(QValueAxis);
178 188 if (d->m_chart)
179 189 d->m_chart->removeAxis(this);
180 190 }
181 191
182 192 void QValueAxis::setMin(qreal min)
183 193 {
184 194 Q_D(QValueAxis);
185 195 setRange(min, qMax(d->m_max, min));
186 196 }
187 197
188 198 qreal QValueAxis::min() const
189 199 {
190 200 Q_D(const QValueAxis);
191 201 return d->m_min;
192 202 }
193 203
194 204 void QValueAxis::setMax(qreal max)
195 205 {
196 206 Q_D(QValueAxis);
197 207 setRange(qMin(d->m_min, max), max);
198 208 }
199 209
200 210 qreal QValueAxis::max() const
201 211 {
202 212 Q_D(const QValueAxis);
203 213 return d->m_max;
204 214 }
205 215
206 216 /*!
207 217 Sets range from \a min to \a max on the axis.
208 218 If min is greater than max then this function returns without making any changes.
209 219 */
210 220 void QValueAxis::setRange(qreal min, qreal max)
211 221 {
212 222 Q_D(QValueAxis);
213 223 d->setRange(min,max);
214 224 }
215 225
216 /*!
217 Sets \a count for ticks on the axis.
218 */
219 226 void QValueAxis::setTickCount(int count)
220 227 {
221 228 Q_D(QValueAxis);
222 229 if (d->m_tickCount != count && count >= 2) {
223 230 d->m_tickCount = count;
224 231 emit tickCountChanged(count);
225 232 }
226 233 }
227 234
228 /*!
229 \fn int QValueAxis::tickCount() const
230 Return number of ticks on the axis
231 */
232 235 int QValueAxis::tickCount() const
233 236 {
234 237 Q_D(const QValueAxis);
235 238 return d->m_tickCount;
236 239 }
237 240
238 241 void QValueAxis::setNiceNumbersEnabled(bool enable)
239 242 {
240 243 Q_UNUSED(enable);
241 244 qWarning()<<"This function is depreciated.Use applyNiceNumbers().";
242 245 }
243 246
244 247 bool QValueAxis::niceNumbersEnabled() const
245 248 {
246 249 qWarning()<<"This function is depreciated.Use applyNiceNumbers().";
247 250 return false;
248 251 }
249 252
250 253 void QValueAxis::setLabelFormat(const QString &format)
251 254 {
252 255 Q_D(QValueAxis);
253 256 d->m_format = format;
254 257 }
255 258
256 259 QString QValueAxis::labelFormat() const
257 260 {
258 261 Q_D(const QValueAxis);
259 262 return d->m_format;
260 263 }
261 264
262 265 /*!
263 266 Returns the type of the axis
264 267 */
265 268 QAbstractAxis::AxisType QValueAxis::type() const
266 269 {
267 270 return AxisTypeValue;
268 271 }
269 272
270 273 void QValueAxis::applyNiceNumbers()
271 274 {
272 275 Q_D(QValueAxis);
273 276 qreal min = d->m_min;
274 277 qreal max = d->m_max;
275 278 int ticks = d->m_tickCount;
276 279 AbstractDomain::looseNiceNumbers(min,max,ticks);
277 280 d->setRange(min,max);
278 281 setTickCount(ticks);
279 282 }
280 283
281 284 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
282 285
283 286 QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q)
284 287 : QAbstractAxisPrivate(q),
285 288 m_min(0),
286 289 m_max(0),
287 290 m_tickCount(5),
288 291 m_format(QString::null)
289 292 {
290 293
291 294 }
292 295
293 296 QValueAxisPrivate::~QValueAxisPrivate()
294 297 {
295 298
296 299 }
297 300
298 301 void QValueAxisPrivate::setMin(const QVariant &min)
299 302 {
300 303 Q_Q(QValueAxis);
301 304 bool ok;
302 305 qreal value = min.toReal(&ok);
303 306 if (ok)
304 307 q->setMin(value);
305 308 }
306 309
307 310 void QValueAxisPrivate::setMax(const QVariant &max)
308 311 {
309 312
310 313 Q_Q(QValueAxis);
311 314 bool ok;
312 315 qreal value = max.toReal(&ok);
313 316 if (ok)
314 317 q->setMax(value);
315 318 }
316 319
317 320 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
318 321 {
319 322 Q_Q(QValueAxis);
320 323 bool ok1;
321 324 bool ok2;
322 325 qreal value1 = min.toReal(&ok1);
323 326 qreal value2 = max.toReal(&ok2);
324 327 if (ok1 && ok2)
325 328 q->setRange(value1, value2);
326 329 }
327 330
328 331 void QValueAxisPrivate::setRange(qreal min, qreal max)
329 332 {
330 333 Q_Q(QValueAxis);
331 334 bool changed = false;
332 335
333 336 if (min > max)
334 337 return;
335 338
336 339 if (!qFuzzyCompare(m_min,min)) {
337 340 m_min = min;
338 341 changed = true;
339 342 emit q->minChanged(min);
340 343 }
341 344
342 345 if (!qFuzzyCompare(m_max,max)) {
343 346 m_max = max;
344 347 changed = true;
345 348 emit q->maxChanged(max);
346 349 }
347 350
348 351 if (changed) {
349 352 emit q->rangeChanged(min, max);
350 353 emit rangeChanged(min,max);
351 354 }
352 355 }
353 356
354 357 void QValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
355 358 {
356 359 Q_Q(QValueAxis);
357 360 ChartAxis* axis(0);
358 361 if (orientation() == Qt::Vertical)
359 362 axis = new ChartValueAxisY(q,parent);
360 363 if (orientation() == Qt::Horizontal)
361 364 axis = new ChartValueAxisX(q,parent);
362 365
363 366 m_item.reset(axis);
364 367 QAbstractAxisPrivate::initializeGraphics(parent);
365 368 }
366 369
367 370
368 371 void QValueAxisPrivate::initializeDomain(AbstractDomain *domain)
369 372 {
370 373 if (orientation() == Qt::Vertical) {
371 374 if(!qFuzzyIsNull(m_max - m_min)) {
372 375 domain->setRangeY(m_min, m_max);
373 376 }
374 377 else {
375 378 setRange(domain->minY(), domain->maxY());
376 379 }
377 380 }
378 381 if (orientation() == Qt::Horizontal) {
379 382 if(!qFuzzyIsNull(m_max - m_min)) {
380 383 domain->setRangeX(m_min, m_max);
381 384 }
382 385 else {
383 386 setRange(domain->minX(), domain->maxX());
384 387 }
385 388 }
386 389 }
387 390
388 391 #include "moc_qvalueaxis.cpp"
389 392 #include "moc_qvalueaxis_p.cpp"
390 393
391 394 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,83 +1,83
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 #ifndef QVALUEAXIS_H
22 22 #define QVALUEAXIS_H
23 23
24 24 #include "qabstractaxis.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
28 28 class QValueAxisPrivate;
29 29
30 30 class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis
31 31 {
32 32 Q_OBJECT
33 33 Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged)
34 34 Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled)
35 35 Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged)
36 36 Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged)
37 37 Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat)
38 38
39 39 public:
40 40 explicit QValueAxis(QObject *parent = 0);
41 41 ~QValueAxis();
42 42
43 43 protected:
44 44 QValueAxis(QValueAxisPrivate &d, QObject *parent = 0);
45 45
46 46 public:
47 47 AxisType type() const;
48 48
49 49 //range handling
50 50 void setMin(qreal min);
51 51 qreal min() const;
52 52 void setMax(qreal max);
53 53 qreal max() const;
54 54 void setRange(qreal min, qreal max);
55 55
56 56 //ticks handling
57 57 void setTickCount(int count);
58 58 int tickCount() const;
59 59
60 60 void setLabelFormat(const QString &format);
61 61 QString labelFormat() const;
62 62
63 63 //TODO: depreciated !
64 64 void setNiceNumbersEnabled(bool enable = true);
65 65 bool niceNumbersEnabled() const;
66 66
67 67 public Q_SLOTS:
68 68 void applyNiceNumbers();
69 69
70 70 Q_SIGNALS:
71 71 void minChanged(qreal min);
72 72 void maxChanged(qreal max);
73 73 void rangeChanged(qreal min, qreal max);
74 void tickCountChanged(int ticks);
74 void tickCountChanged(int tickCount);
75 75
76 76 private:
77 77 Q_DECLARE_PRIVATE(QValueAxis)
78 78 Q_DISABLE_COPY(QValueAxis)
79 79 };
80 80
81 81 QTCOMMERCIALCHART_END_NAMESPACE
82 82
83 83 #endif // QVALUEAXIS_H
General Comments 0
You need to be logged in to leave comments. Login now