##// END OF EJS Templates
barcategories axis initialisation crash commented out. add to known issues list
sauimone -
r1664:8fb25c9f2d87
parent child
Show More
@@ -1,432 +1,442
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 146 d->m_categories.append(categories);
147 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 160 Q_D(QBarCategoriesAxis);
161 161 if (d->m_categories.isEmpty()) {
162 162 d->m_categories.append(category);
163 163 setRange(category,category);
164 164 }else{
165 165 d->m_categories.append(category);
166 166 }
167 167 emit d->updated();
168 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 192 d->m_categories.insert(index,category);
193 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 // Q_Q(QBarCategoriesAxis);
373 372 m_min = min;
374 373 m_max = max;
374 m_ticksCount = count;
375 // TODO: causes crash in some situations. added to known issues
376 /*
375 377 int minIndex = qFloor(min);
376 378 int maxIndex = qFloor(max);
377 379
378 380 if (minIndex < 0) {
379 381 minIndex = 0;
380 382 }
381 383 if (maxIndex > m_categories.count()-1){
382 384 maxIndex = m_categories.count()-1;
385 if (maxIndex<0) {
386 maxIndex = 0;
387 }
383 388 }
384 389
385 390 bool changed = false;
386 391 if (m_minCategory != m_categories.at(minIndex)) {
387 392 m_minCategory = m_categories.at(minIndex);
388 393 emit q->minChanged(m_minCategory);
389 394 changed = true;
390 395 }
391 396
392 397 if (m_maxCategory != m_categories.at(maxIndex)) {
393 398 m_maxCategory = m_categories.at(maxIndex);
394 399 emit q->maxChanged(m_maxCategory);
395 400 changed = true;
396 401 }
397 402
398 403 if (changed) {
399 404 emit q->rangeChanged(m_minCategory, m_maxCategory);
400 405 }
406 */
401 407 }
402 408
403 409 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
404 410 {
405 411 Q_Q(QBarCategoriesAxis);
406 412 if(m_orientation == Qt::Vertical){
407 413 return new ChartCategoriesAxisY(q,presenter);
408 414 }else{
409 415 return new ChartCategoriesAxisX(q,presenter);
410 416 }
411 417 }
412 418
413 419 void QBarCategoriesAxisPrivate::emitRange()
414 420 {
415 421 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
416 422 }
417 423
418 424 void QBarCategoriesAxisPrivate::initialize(Domain* domain)
419 425 {
426 Q_UNUSED(domain);
427 // TODO: this causes crash now. added to known issues.
428 /*
420 429 if (qFuzzyCompare(m_max, m_min)) {
421 430 if(m_orientation==Qt::Vertical){
422 431 handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount());
423 432 }else{
424 433 handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount());
425 434 }
426 435 }
436 */
427 437 }
428 438
429 439 #include "moc_qbarcategoriesaxis.cpp"
430 440 #include "moc_qbarcategoriesaxis_p.cpp"
431 441
432 442 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now