@@ -1,401 +1,432 | |||
|
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 "qbarcategoriesaxis.h" |
|
22 | 22 | #include "qbarcategoriesaxis_p.h" |
|
23 | 23 | #include "chartcategoriesaxisx_p.h" |
|
24 | 24 | #include "chartcategoriesaxisy_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include <qmath.h> |
|
27 | 27 | #include <QDebug> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | /*! |
|
31 | 31 | \class QBarCategoriesAxis |
|
32 | 32 | \brief The QBarCategoriesAxis class is used for manipulating chart's axis. |
|
33 | 33 | \mainclass |
|
34 | 34 | |
|
35 | 35 | BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
36 | 36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
37 | 37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. |
|
38 | 38 | */ |
|
39 | 39 | |
|
40 | 40 | /*! |
|
41 | 41 | \qmlclass BarCategoriesAxis QBarCategoriesAxis |
|
42 | 42 | \brief The Axis element is used for manipulating chart's axes. |
|
43 | 43 | |
|
44 | 44 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
45 | 45 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
46 | 46 | |
|
47 | 47 | To access BarCategoriesAxis you can use ChartView API. For example: |
|
48 | 48 | \code |
|
49 | 49 | ChartView { |
|
50 | 50 | BarCategoriesAxis { |
|
51 | 51 | id: categoryAxis |
|
52 | 52 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] |
|
53 | 53 | } |
|
54 | 54 | // Add a few series... |
|
55 | 55 | } |
|
56 | 56 | \endcode |
|
57 | 57 | */ |
|
58 | 58 | |
|
59 | 59 | /*! |
|
60 | 60 | \property QBarCategoriesAxis::categories |
|
61 | 61 | Defines the categories of axis |
|
62 | 62 | */ |
|
63 | 63 | /*! |
|
64 | 64 | \qmlproperty QStringList BarCategoriesAxis::categories |
|
65 | 65 | Defines the categories of axis |
|
66 | 66 | */ |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | \property QBarCategoriesAxis::min |
|
70 | 70 | Defines the minimum value on the axis. |
|
71 | 71 | */ |
|
72 | 72 | /*! |
|
73 | 73 | \qmlproperty QString BarCategoriesAxis::min |
|
74 | 74 | Defines the minimum value on the axis. |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \property QBarCategoriesAxis::max |
|
79 | 79 | Defines the maximum value on the axis. |
|
80 | 80 | */ |
|
81 | 81 | /*! |
|
82 | 82 | \qmlproperty QString BarCategoriesAxis::max |
|
83 | 83 | Defines the maximum value on the axis. |
|
84 | 84 | */ |
|
85 | 85 | |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \fn void QBarCategoriesAxis::categoriesChanged() |
|
89 | 89 | Axis emits signal when the categories of the axis has changed. |
|
90 | 90 | */ |
|
91 | 91 | /*! |
|
92 | 92 | \fn void QBarCategoriesAxis::minChanged(const QString &min) |
|
93 | 93 | Axis emits signal when \a min of axis has changed. |
|
94 | 94 | */ |
|
95 | 95 | /*! |
|
96 | 96 | \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min) |
|
97 | 97 | Axis emits signal when \a min of axis has changed. |
|
98 | 98 | */ |
|
99 | 99 | |
|
100 | 100 | /*! |
|
101 | 101 | \fn void QBarCategoriesAxis::maxChanged(const QString &max) |
|
102 | 102 | Axis emits signal when \a max of axis has changed. |
|
103 | 103 | */ |
|
104 | 104 | /*! |
|
105 | 105 | \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max) |
|
106 | 106 | Axis emits signal when \a max of axis has changed. |
|
107 | 107 | */ |
|
108 | 108 | |
|
109 | 109 | /*! |
|
110 | 110 | \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max) |
|
111 | 111 | Axis emits signal when \a min or \a max of axis has changed. |
|
112 | 112 | */ |
|
113 | 113 | |
|
114 | 114 | /*! |
|
115 | 115 | Constructs an axis object which is a child of \a parent. |
|
116 | 116 | */ |
|
117 | 117 | QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent): |
|
118 | 118 | QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent) |
|
119 | 119 | { |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | Destroys the object |
|
124 | 124 | */ |
|
125 | 125 | QBarCategoriesAxis::~QBarCategoriesAxis() |
|
126 | 126 | { |
|
127 | 127 | } |
|
128 | 128 | |
|
129 | 129 | /*! |
|
130 | 130 | \internal |
|
131 | 131 | */ |
|
132 | 132 | QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) |
|
133 | 133 | { |
|
134 | 134 | |
|
135 | 135 | } |
|
136 | 136 | |
|
137 | 137 | /*! |
|
138 | 138 | Appends \a categories to axis |
|
139 | 139 | */ |
|
140 | 140 | void QBarCategoriesAxis::append(const QStringList &categories) |
|
141 | 141 | { |
|
142 | 142 | if(categories.isEmpty()) return; |
|
143 | 143 | |
|
144 | 144 | Q_D(QBarCategoriesAxis); |
|
145 | 145 | if (d->m_categories.isEmpty()) { |
|
146 |
|
|
|
147 |
|
|
|
146 | d->m_categories.append(categories); | |
|
147 | setRange(categories.first(),categories.last()); | |
|
148 | 148 | }else{ |
|
149 |
|
|
|
149 | d->m_categories.append(categories); | |
|
150 | 150 | } |
|
151 | 151 | emit d->updated(); |
|
152 | 152 | emit categoriesChanged(); |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | Appends \a category to axis |
|
157 | 157 | */ |
|
158 | 158 | void QBarCategoriesAxis::append(const QString &category) |
|
159 | 159 | { |
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
|
165 |
|
|
|
166 | } | |
|
167 |
|
|
|
168 |
|
|
|
160 | Q_D(QBarCategoriesAxis); | |
|
161 | if (d->m_categories.isEmpty()) { | |
|
162 | d->m_categories.append(category); | |
|
163 | setRange(category,category); | |
|
164 | }else{ | |
|
165 | d->m_categories.append(category); | |
|
166 | } | |
|
167 | emit d->updated(); | |
|
168 | emit categoriesChanged(); | |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | /*! |
|
172 | 172 | Removes \a category from axis |
|
173 | 173 | */ |
|
174 | 174 | void QBarCategoriesAxis::remove(const QString &category) |
|
175 | 175 | { |
|
176 | 176 | Q_D(QBarCategoriesAxis); |
|
177 | 177 | if (d->m_categories.contains(category)) { |
|
178 | 178 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
179 | 179 | setRange(d->m_categories.first(),d->m_categories.last()); |
|
180 | 180 | emit d->updated(); |
|
181 | 181 | emit categoriesChanged(); |
|
182 | 182 | } |
|
183 | 183 | } |
|
184 | 184 | |
|
185 | 185 | /*! |
|
186 | 186 | Inserts \a category to axis at \a index |
|
187 | 187 | */ |
|
188 | 188 | void QBarCategoriesAxis::insert(int index, const QString &category) |
|
189 | 189 | { |
|
190 | 190 | Q_D(QBarCategoriesAxis); |
|
191 | 191 | if (d->m_categories.isEmpty()) { |
|
192 |
|
|
|
193 |
|
|
|
192 | d->m_categories.insert(index,category); | |
|
193 | setRange(category,category); | |
|
194 | 194 | }else{ |
|
195 | 195 | d->m_categories.insert(index,category); |
|
196 | 196 | } |
|
197 | 197 | emit d->updated(); |
|
198 | 198 | emit categoriesChanged(); |
|
199 | 199 | } |
|
200 | 200 | |
|
201 | 201 | /*! |
|
202 | 202 | Removes all categories. |
|
203 | 203 | */ |
|
204 | 204 | void QBarCategoriesAxis::clear() |
|
205 | 205 | { |
|
206 | 206 | Q_D(QBarCategoriesAxis); |
|
207 | 207 | d->m_categories.clear(); |
|
208 | 208 | setRange(QString::null,QString::null); |
|
209 | 209 | emit d->updated(); |
|
210 | 210 | emit categoriesChanged(); |
|
211 | 211 | } |
|
212 | 212 | |
|
213 | 213 | void QBarCategoriesAxis::setCategories(const QStringList &categories) |
|
214 | 214 | { |
|
215 | 215 | Q_D(QBarCategoriesAxis); |
|
216 | 216 | if(d->m_categories!=categories){ |
|
217 | 217 | d->m_categories = categories; |
|
218 | 218 | setRange(categories.first(),categories.last()); |
|
219 | 219 | emit d->updated(); |
|
220 | 220 | emit categoriesChanged(); |
|
221 | 221 | } |
|
222 | 222 | } |
|
223 | 223 | |
|
224 | 224 | QStringList QBarCategoriesAxis::categories() |
|
225 | 225 | { |
|
226 | 226 | Q_D(QBarCategoriesAxis); |
|
227 | 227 | return d->m_categories; |
|
228 | 228 | } |
|
229 | 229 | |
|
230 | 230 | /*! |
|
231 | 231 | Returns number of categories. |
|
232 | 232 | */ |
|
233 | 233 | int QBarCategoriesAxis::count() const |
|
234 | 234 | { |
|
235 | 235 | Q_D(const QBarCategoriesAxis); |
|
236 | 236 | return d->m_categories.count(); |
|
237 | 237 | } |
|
238 | 238 | |
|
239 | 239 | /*! |
|
240 | 240 | Returns category at \a index. Index must be valid. |
|
241 | 241 | */ |
|
242 | 242 | QString QBarCategoriesAxis::at(int index) const |
|
243 | 243 | { |
|
244 | 244 | Q_D(const QBarCategoriesAxis); |
|
245 | 245 | return d->m_categories.at(index); |
|
246 | 246 | } |
|
247 | 247 | |
|
248 | 248 | /*! |
|
249 | 249 | Sets minimum category to \a min. |
|
250 | 250 | */ |
|
251 | 251 | void QBarCategoriesAxis::setMin(const QString& min) |
|
252 | 252 | { |
|
253 | 253 | Q_D(QBarCategoriesAxis); |
|
254 | 254 | setRange(min,d->m_maxCategory); |
|
255 | 255 | } |
|
256 | 256 | |
|
257 | 257 | /*! |
|
258 | 258 | Returns minimum category. |
|
259 | 259 | */ |
|
260 | 260 | QString QBarCategoriesAxis::min() const |
|
261 | 261 | { |
|
262 | 262 | Q_D(const QBarCategoriesAxis); |
|
263 | 263 | return d->m_minCategory; |
|
264 | 264 | } |
|
265 | 265 | |
|
266 | 266 | /*! |
|
267 | 267 | Sets maximum category to \a max. |
|
268 | 268 | */ |
|
269 | 269 | void QBarCategoriesAxis::setMax(const QString& max) |
|
270 | 270 | { |
|
271 | 271 | Q_D(QBarCategoriesAxis); |
|
272 | 272 | setRange(d->m_minCategory,max); |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | /*! |
|
276 | 276 | Returns maximum category |
|
277 | 277 | */ |
|
278 | 278 | QString QBarCategoriesAxis::max() const |
|
279 | 279 | { |
|
280 | 280 | Q_D(const QBarCategoriesAxis); |
|
281 | 281 | return d->m_maxCategory; |
|
282 | 282 | } |
|
283 | 283 | |
|
284 | 284 | /*! |
|
285 | 285 | Sets range from \a minCategory to \a maxCategory |
|
286 | 286 | */ |
|
287 | 287 | void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) |
|
288 | 288 | { |
|
289 | 289 | Q_D(QBarCategoriesAxis); |
|
290 | 290 | |
|
291 | 291 | int minIndex = d->m_categories.indexOf(minCategory); |
|
292 | 292 | if (minIndex == -1) { |
|
293 | 293 | return; |
|
294 | 294 | } |
|
295 | 295 | int maxIndex = d->m_categories.indexOf(maxCategory); |
|
296 | 296 | if (maxIndex == -1) { |
|
297 | 297 | return; |
|
298 | 298 | } |
|
299 | 299 | |
|
300 | 300 | if (maxIndex <= minIndex) { |
|
301 | 301 | // max must be greater than min |
|
302 | 302 | return; |
|
303 | 303 | } |
|
304 | 304 | |
|
305 | 305 | bool changed = false; |
|
306 | 306 | if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) { |
|
307 |
|
|
|
307 | d->m_minCategory = minCategory; | |
|
308 | 308 | d->m_min = minIndex; |
|
309 | 309 | emit minChanged(minCategory); |
|
310 | 310 | changed = true; |
|
311 | 311 | } |
|
312 | 312 | |
|
313 | 313 | if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) { |
|
314 | 314 | d->m_max = maxIndex; |
|
315 | 315 | d->m_maxCategory = maxCategory; |
|
316 | 316 | emit maxChanged(maxCategory); |
|
317 | 317 | changed = true; |
|
318 | 318 | } |
|
319 | 319 | |
|
320 | 320 | if (changed) { |
|
321 | 321 | d->emitRange(); |
|
322 | 322 | } |
|
323 | 323 | } |
|
324 | 324 | |
|
325 | 325 | /*! |
|
326 | 326 | Returns the type of the axis |
|
327 | 327 | */ |
|
328 | 328 | QAbstractAxis::AxisType QBarCategoriesAxis::type() const |
|
329 | 329 | { |
|
330 | 330 | return AxisTypeCategories; |
|
331 | 331 | } |
|
332 | 332 | |
|
333 | 333 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
334 | 334 | |
|
335 | 335 | QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): |
|
336 | 336 | QAbstractAxisPrivate(q) |
|
337 | 337 | { |
|
338 | 338 | |
|
339 | 339 | } |
|
340 | 340 | |
|
341 | 341 | QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() |
|
342 | 342 | { |
|
343 | 343 | |
|
344 | 344 | } |
|
345 | 345 | |
|
346 | 346 | void QBarCategoriesAxisPrivate::setMin(const QVariant &min) |
|
347 | 347 | { |
|
348 | 348 | setRange(min,m_maxCategory); |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | void QBarCategoriesAxisPrivate::setMax(const QVariant &max) |
|
352 | 352 | { |
|
353 | 353 | setRange(m_minCategory,max); |
|
354 | 354 | } |
|
355 | 355 | |
|
356 | 356 | void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
357 | 357 | { |
|
358 | 358 | Q_Q(QBarCategoriesAxis); |
|
359 | 359 | QString value1 = min.toString(); |
|
360 | 360 | QString value2 = max.toString(); |
|
361 | 361 | q->setRange(value1,value2); |
|
362 | 362 | } |
|
363 | 363 | |
|
364 | 364 | int QBarCategoriesAxisPrivate::ticksCount() const |
|
365 | 365 | { |
|
366 | 366 | return m_categories.count()+1; |
|
367 | 367 | } |
|
368 | 368 | |
|
369 | 369 | void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
370 | 370 | { |
|
371 | Q_Q(QBarCategoriesAxis); | |
|
372 | Q_UNUSED(count); | |
|
371 | 373 | m_min = min; |
|
372 | 374 | m_max = max; |
|
373 | m_ticksCount = count; | |
|
374 | //TODO: | |
|
375 | int minIndex = qFloor(min); | |
|
376 | int maxIndex = qFloor(max); | |
|
377 | ||
|
378 | if (minIndex < 0) { | |
|
379 | minIndex = 0; | |
|
380 | } | |
|
381 | if (maxIndex > m_categories.count()-1){ | |
|
382 | maxIndex = m_categories.count()-1; | |
|
383 | } | |
|
384 | ||
|
385 | bool changed = false; | |
|
386 | if (m_minCategory != m_categories.at(minIndex)) { | |
|
387 | m_minCategory = m_categories.at(minIndex); | |
|
388 | emit q->minChanged(m_minCategory); | |
|
389 | changed = true; | |
|
390 | } | |
|
391 | ||
|
392 | if (m_maxCategory != m_categories.at(maxIndex)) { | |
|
393 | m_maxCategory = m_categories.at(maxIndex); | |
|
394 | emit q->maxChanged(m_maxCategory); | |
|
395 | changed = true; | |
|
396 | } | |
|
397 | ||
|
398 | if (changed) { | |
|
399 | emit q->rangeChanged(m_minCategory, m_maxCategory); | |
|
400 | } | |
|
375 | 401 | } |
|
376 | 402 | |
|
377 | 403 | ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
378 | 404 | { |
|
379 | 405 | Q_Q(QBarCategoriesAxis); |
|
380 | 406 | if(m_orientation == Qt::Vertical){ |
|
381 | 407 | return new ChartCategoriesAxisY(q,presenter); |
|
382 | 408 | }else{ |
|
383 | 409 | return new ChartCategoriesAxisX(q,presenter); |
|
384 | 410 | } |
|
385 | 411 | } |
|
386 | 412 | |
|
387 | 413 | void QBarCategoriesAxisPrivate::emitRange() |
|
388 | 414 | { |
|
389 |
|
|
|
415 | emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false); | |
|
390 | 416 | } |
|
391 | 417 | |
|
392 | 418 | void QBarCategoriesAxisPrivate::initialize(Domain* domain) |
|
393 | 419 | { |
|
394 | Q_UNUSED(domain); | |
|
395 | //TODO: | |
|
420 | if (qFuzzyCompare(m_max, m_min)) { | |
|
421 | if(m_orientation==Qt::Vertical){ | |
|
422 | handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount()); | |
|
423 | }else{ | |
|
424 | handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount()); | |
|
425 | } | |
|
426 | } | |
|
396 | 427 | } |
|
397 | 428 | |
|
398 | 429 | #include "moc_qbarcategoriesaxis.cpp" |
|
399 | 430 | #include "moc_qbarcategoriesaxis_p.cpp" |
|
400 | 431 | |
|
401 | 432 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,323 +1,323 | |||
|
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 "qvaluesaxis.h" |
|
22 | 22 | #include "qvaluesaxis_p.h" |
|
23 | 23 | #include "chartvaluesaxisx_p.h" |
|
24 | 24 | #include "chartvaluesaxisy_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include <QDebug> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | /*! |
|
30 | 30 | \class QValuesAxis |
|
31 | 31 | \brief The QValuesAxis class is used for manipulating chart's axis. |
|
32 | 32 | \mainclass |
|
33 | 33 | |
|
34 | 34 | ValuesAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | 35 | Values of axis are drawn to position of ticks |
|
36 | 36 | */ |
|
37 | 37 | |
|
38 | 38 | /*! |
|
39 | 39 | \qmlclass ValuesAxis QValuesAxis |
|
40 | 40 | \brief The ValuesAxis element is used for manipulating chart's axes |
|
41 | 41 | |
|
42 | 42 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
43 | 43 | Values of axis are drawn to position of ticks |
|
44 | 44 | |
|
45 | 45 | To access Axes you can use ChartView API. For example: |
|
46 | 46 | \code |
|
47 | 47 | ChartView { |
|
48 | 48 | ValuesAxis { |
|
49 | 49 | id: xAxis |
|
50 | 50 | min: 0 |
|
51 | 51 | max: 10 |
|
52 | 52 | } |
|
53 | 53 | // Add a few series... |
|
54 | 54 | } |
|
55 | 55 | \endcode |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \property QValuesAxis::min |
|
60 | 60 | Defines the minimum value on the axis. |
|
61 | 61 | */ |
|
62 | 62 | /*! |
|
63 | 63 | \qmlproperty real ValuesAxis::min |
|
64 | 64 | Defines the minimum value on the axis. |
|
65 | 65 | */ |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | \property QValuesAxis::max |
|
69 | 69 | Defines the maximum value on the axis. |
|
70 | 70 | */ |
|
71 | 71 | /*! |
|
72 | 72 | \qmlproperty real ValuesAxis::max |
|
73 | 73 | Defines the maximum value on the axis. |
|
74 | 74 | */ |
|
75 | 75 | |
|
76 | 76 | /*! |
|
77 | 77 | \fn void QValuesAxis::minChanged(qreal min) |
|
78 | 78 | Axis emits signal when \a min of axis has changed. |
|
79 | 79 | */ |
|
80 | 80 | /*! |
|
81 | 81 | \qmlsignal ValuesAxis::onMinChanged(real min) |
|
82 | 82 | Axis emits signal when \a min of axis has changed. |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \fn void QValuesAxis::maxChanged(qreal max) |
|
87 | 87 | Axis emits signal when \a max of axis has changed. |
|
88 | 88 | */ |
|
89 | 89 | /*! |
|
90 | 90 | \qmlsignal ValuesAxis::onMaxChanged(real max) |
|
91 | 91 | Axis emits signal when \a max of axis has changed. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \fn void QValuesAxis::rangeChanged(qreal min, qreal max) |
|
96 | 96 | Axis emits signal when \a min or \a max of axis has changed. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QValuesAxis::ticksCount |
|
101 | 101 | The number of tick marks for the axis. |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | \qmlproperty int ValuesAxis::ticksCount |
|
106 | 106 | The number of tick marks for the axis. |
|
107 | 107 | */ |
|
108 | 108 | |
|
109 | 109 | /*! |
|
110 | 110 | \property QValuesAxis::niceNumbersEnabled |
|
111 | 111 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
112 | 112 | */ |
|
113 | 113 | |
|
114 | 114 | /*! |
|
115 | 115 | \qmlproperty bool ValuesAxis::niceNumbersEnabled |
|
116 | 116 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
117 | 117 | */ |
|
118 | 118 | |
|
119 | 119 | /*! |
|
120 | 120 | Constructs an axis object which is a child of \a parent. |
|
121 | 121 | */ |
|
122 | 122 | QValuesAxis::QValuesAxis(QObject *parent) : |
|
123 | 123 | QAbstractAxis(*new QValuesAxisPrivate(this),parent) |
|
124 | 124 | { |
|
125 | 125 | |
|
126 | 126 | } |
|
127 | 127 | |
|
128 | 128 | /*! |
|
129 | 129 | \internal |
|
130 | 130 | */ |
|
131 | 131 | QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) |
|
132 | 132 | { |
|
133 | 133 | |
|
134 | 134 | } |
|
135 | 135 | |
|
136 | 136 | /*! |
|
137 | 137 | Destroys the object |
|
138 | 138 | */ |
|
139 | 139 | QValuesAxis::~QValuesAxis() |
|
140 | 140 | { |
|
141 | 141 | |
|
142 | 142 | } |
|
143 | 143 | |
|
144 | 144 | void QValuesAxis::setMin(qreal min) |
|
145 | 145 | { |
|
146 | 146 | Q_D(QValuesAxis); |
|
147 | 147 | setRange(min,d->m_max); |
|
148 | 148 | } |
|
149 | 149 | |
|
150 | 150 | qreal QValuesAxis::min() const |
|
151 | 151 | { |
|
152 | 152 | Q_D(const QValuesAxis); |
|
153 | 153 | return d->m_min; |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | void QValuesAxis::setMax(qreal max) |
|
157 | 157 | { |
|
158 | 158 | Q_D(QValuesAxis); |
|
159 | 159 | setRange(d->m_min,max); |
|
160 | 160 | } |
|
161 | 161 | |
|
162 | 162 | qreal QValuesAxis::max() const |
|
163 | 163 | { |
|
164 | 164 | Q_D(const QValuesAxis); |
|
165 | 165 | return d->m_max; |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | /*! |
|
169 | 169 | Sets range from \a min to \a max on the axis. |
|
170 | 170 | */ |
|
171 | 171 | void QValuesAxis::setRange(qreal min, qreal max) |
|
172 | 172 | { |
|
173 | 173 | Q_D(QValuesAxis); |
|
174 | 174 | |
|
175 | 175 | bool changed = false; |
|
176 | 176 | if (!qFuzzyIsNull(d->m_min - min)) { |
|
177 | 177 | d->m_min = min; |
|
178 | 178 | changed = true; |
|
179 | 179 | emit minChanged(min); |
|
180 | 180 | } |
|
181 | 181 | |
|
182 | 182 | if (!qFuzzyIsNull(d->m_max - max)) { |
|
183 | 183 | d->m_max = max; |
|
184 | 184 | changed = true; |
|
185 | 185 | emit maxChanged(max); |
|
186 | 186 | } |
|
187 | 187 | |
|
188 | 188 | if (changed) { |
|
189 | 189 | d->emitRange(); |
|
190 | 190 | emit rangeChanged(d->m_min,d->m_max); |
|
191 | 191 | } |
|
192 | 192 | } |
|
193 | 193 | |
|
194 | 194 | /*! |
|
195 | 195 | Sets \a count for ticks on the axis. |
|
196 | 196 | */ |
|
197 | 197 | void QValuesAxis::setTicksCount(int count) |
|
198 | 198 | { |
|
199 | 199 | Q_D(QValuesAxis); |
|
200 | 200 | if (d->m_ticksCount != count) { |
|
201 | 201 | d->m_ticksCount = count; |
|
202 | 202 | emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); |
|
203 | 203 | } |
|
204 | 204 | } |
|
205 | 205 | |
|
206 | 206 | /*! |
|
207 | 207 | \fn int QValuesAxis::ticksCount() const |
|
208 | 208 | Return number of ticks on the axis |
|
209 | 209 | */ |
|
210 | 210 | int QValuesAxis::ticksCount() const |
|
211 | 211 | { |
|
212 | 212 | Q_D(const QValuesAxis); |
|
213 | 213 | return d->m_ticksCount; |
|
214 | 214 | } |
|
215 | 215 | |
|
216 | 216 | void QValuesAxis::setNiceNumbersEnabled(bool enable) |
|
217 | 217 | { |
|
218 | 218 | Q_D(QValuesAxis); |
|
219 | 219 | if (d->m_niceNumbers != enable){ |
|
220 | 220 | d->m_niceNumbers = enable; |
|
221 | 221 | emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); |
|
222 | 222 | } |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | bool QValuesAxis::niceNumbersEnabled() const |
|
226 | 226 | { |
|
227 | 227 | Q_D(const QValuesAxis); |
|
228 | 228 | return d->m_niceNumbers; |
|
229 | 229 | } |
|
230 | 230 | |
|
231 | 231 | /*! |
|
232 | 232 | Returns the type of the axis |
|
233 | 233 | */ |
|
234 | 234 | QAbstractAxis::AxisType QValuesAxis::type() const |
|
235 | 235 | { |
|
236 | 236 | return AxisTypeValues; |
|
237 | 237 | } |
|
238 | 238 | |
|
239 | 239 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
240 | 240 | |
|
241 | 241 | QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q): |
|
242 | 242 | QAbstractAxisPrivate(q), |
|
243 | 243 | m_niceNumbers(false) |
|
244 | 244 | { |
|
245 | 245 | |
|
246 | 246 | } |
|
247 | 247 | |
|
248 | 248 | QValuesAxisPrivate::~QValuesAxisPrivate() |
|
249 | 249 | { |
|
250 | 250 | |
|
251 | 251 | } |
|
252 | 252 | |
|
253 | 253 | void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
254 | 254 | { |
|
255 | 255 | Q_Q(QValuesAxis); |
|
256 | 256 | q->setRange(min,max); |
|
257 | 257 | q->setTicksCount(count); |
|
258 | 258 | } |
|
259 | 259 | |
|
260 | 260 | |
|
261 | 261 | void QValuesAxisPrivate::setMin(const QVariant &min) |
|
262 | 262 | { |
|
263 | 263 | Q_Q(QValuesAxis); |
|
264 | 264 | bool ok; |
|
265 | 265 | qreal value = min.toReal(&ok); |
|
266 | 266 | if(ok) q->setMin(value); |
|
267 | 267 | } |
|
268 | 268 | |
|
269 | 269 | void QValuesAxisPrivate::setMax(const QVariant &max) |
|
270 | 270 | { |
|
271 | 271 | |
|
272 | 272 | Q_Q(QValuesAxis); |
|
273 | 273 | bool ok; |
|
274 | 274 | qreal value = max.toReal(&ok); |
|
275 | 275 | if(ok) q->setMax(value); |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
279 | 279 | { |
|
280 | 280 | Q_Q(QValuesAxis); |
|
281 | 281 | bool ok1; |
|
282 | 282 | bool ok2; |
|
283 | 283 | qreal value1 = min.toReal(&ok1); |
|
284 | 284 | qreal value2 = max.toReal(&ok2); |
|
285 | 285 | if(ok1&&ok2) q->setRange(value1,value2); |
|
286 | 286 | } |
|
287 | 287 | |
|
288 | 288 | int QValuesAxisPrivate::ticksCount() const |
|
289 | 289 | { |
|
290 | 290 | return m_ticksCount; |
|
291 | 291 | } |
|
292 | 292 | |
|
293 | 293 | ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
294 | 294 | { |
|
295 | 295 | Q_Q(QValuesAxis); |
|
296 | 296 | if(m_orientation == Qt::Vertical){ |
|
297 | 297 | return new ChartValuesAxisY(q,presenter); |
|
298 | 298 | }else{ |
|
299 | 299 | return new ChartValuesAxisX(q,presenter); |
|
300 | 300 | } |
|
301 | 301 | |
|
302 | 302 | } |
|
303 | 303 | |
|
304 | 304 | void QValuesAxisPrivate::emitRange() |
|
305 | 305 | { |
|
306 | 306 | emit changed(m_min, m_max, m_ticksCount, m_niceNumbers); |
|
307 | 307 | } |
|
308 | 308 | |
|
309 | 309 | void QValuesAxisPrivate::initialize(Domain* domain) |
|
310 | 310 | { |
|
311 |
if(m_max |
|
|
311 | if(qFuzzyCompare(m_max,m_min)) { | |
|
312 | 312 | if(m_orientation==Qt::Vertical){ |
|
313 | 313 | handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount()); |
|
314 | 314 | }else{ |
|
315 | 315 | handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount()); |
|
316 | 316 | } |
|
317 | 317 | } |
|
318 | 318 | } |
|
319 | 319 | |
|
320 | 320 | #include "moc_qvaluesaxis.cpp" |
|
321 | 321 | #include "moc_qvaluesaxis_p.cpp" |
|
322 | 322 | |
|
323 | 323 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now