@@ -0,0 +1,26 | |||
|
1 | #ifndef CHARTHELPERS_P_H | |
|
2 | #define CHARTHELPERS_P_H | |
|
3 | ||
|
4 | #include <qnumeric.h> | |
|
5 | #include <QPointF> | |
|
6 | ||
|
7 | static inline bool isValidValue(qreal value) | |
|
8 | { | |
|
9 | if (qIsNaN(value) || qIsInf(value)) { | |
|
10 | qWarning("Ignored NaN, Inf, or -Inf value."); | |
|
11 | return false; | |
|
12 | } | |
|
13 | return true; | |
|
14 | } | |
|
15 | ||
|
16 | static inline bool isValidValue(qreal x, qreal y) | |
|
17 | { | |
|
18 | return (isValidValue(x) && isValidValue(y)); | |
|
19 | } | |
|
20 | ||
|
21 | static inline bool isValidValue(const QPointF point) | |
|
22 | { | |
|
23 | return (isValidValue(point.x()) && isValidValue(point.y())); | |
|
24 | } | |
|
25 | ||
|
26 | #endif // CHARTHELPERS_P_H |
@@ -555,14 +555,18 QBarSetPrivate::~QBarSetPrivate() | |||
|
555 | 555 | |
|
556 | 556 | void QBarSetPrivate::append(QPointF value) |
|
557 | 557 | { |
|
558 | m_values.append(value); | |
|
559 | emit restructuredBars(); | |
|
558 | if (isValidValue(value)) { | |
|
559 | m_values.append(value); | |
|
560 | emit restructuredBars(); | |
|
561 | } | |
|
560 | 562 | } |
|
561 | 563 | |
|
562 | 564 | void QBarSetPrivate::append(QList<QPointF> values) |
|
563 | 565 | { |
|
564 | for (int i = 0; i < values.count(); i++) | |
|
565 |
|
|
|
566 | for (int i = 0; i < values.count(); i++) { | |
|
567 | if (isValidValue(values.at(i))) | |
|
568 | m_values.append(values.at(i)); | |
|
569 | } | |
|
566 | 570 | emit restructuredBars(); |
|
567 | 571 | } |
|
568 | 572 | |
@@ -570,8 +574,10 void QBarSetPrivate::append(QList<qreal> values) | |||
|
570 | 574 | { |
|
571 | 575 | int index = m_values.count(); |
|
572 | 576 | for (int i = 0; i < values.count(); i++) { |
|
573 | m_values.append(QPointF(index, values.at(i))); | |
|
574 | index++; | |
|
577 | if (isValidValue(values.at(i))) { | |
|
578 | m_values.append(QPointF(index, values.at(i))); | |
|
579 | index++; | |
|
580 | } | |
|
575 | 581 | } |
|
576 | 582 | emit restructuredBars(); |
|
577 | 583 | } |
@@ -25,6 +25,7 | |||
|
25 | 25 | #include <QPen> |
|
26 | 26 | #include <QBrush> |
|
27 | 27 | #include <QFont> |
|
28 | #include "charthelpers_p.h" | |
|
28 | 29 | |
|
29 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 31 | class QBarSetPrivate; |
@@ -27,6 +27,7 | |||
|
27 | 27 | #include "charttheme_p.h" |
|
28 | 28 | #include "qabstractaxis.h" |
|
29 | 29 | #include "pieanimation_p.h" |
|
30 | #include "charthelpers_p.h" | |
|
30 | 31 | |
|
31 | 32 | #include "qpielegendmarker.h" |
|
32 | 33 | |
@@ -400,6 +401,8 bool QPieSeries::append(QList<QPieSlice *> slices) | |||
|
400 | 401 | return false; |
|
401 | 402 | if (s->series()) // already added to some series |
|
402 | 403 | return false; |
|
404 | if (!isValidValue(s->value())) | |
|
405 | return false; | |
|
403 | 406 | } |
|
404 | 407 | |
|
405 | 408 | foreach (QPieSlice *s, slices) { |
@@ -436,12 +439,17 QPieSeries &QPieSeries::operator << (QPieSlice *slice) | |||
|
436 | 439 | /*! |
|
437 | 440 | Appends a single slice to the series with give \a value and \a label. |
|
438 | 441 | Slice ownership is passed to the series. |
|
442 | Returns NULL if value is NaN, Inf or -Inf and no slice is added to the series. | |
|
439 | 443 | */ |
|
440 | 444 | QPieSlice *QPieSeries::append(QString label, qreal value) |
|
441 | 445 | { |
|
442 | QPieSlice *slice = new QPieSlice(label, value); | |
|
443 | append(slice); | |
|
444 |
|
|
|
446 | if (isValidValue(value)) { | |
|
447 | QPieSlice *slice = new QPieSlice(label, value); | |
|
448 | append(slice); | |
|
449 | return slice; | |
|
450 | } else { | |
|
451 | return 0; | |
|
452 | } | |
|
445 | 453 | } |
|
446 | 454 | |
|
447 | 455 | /*! |
@@ -463,6 +471,9 bool QPieSeries::insert(int index, QPieSlice *slice) | |||
|
463 | 471 | if (slice->series()) // already added to some series |
|
464 | 472 | return false; |
|
465 | 473 | |
|
474 | if (!isValidValue(slice->value())) | |
|
475 | return false; | |
|
476 | ||
|
466 | 477 | slice->setParent(this); |
|
467 | 478 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
468 | 479 | d->m_slices.insert(index, slice); |
@@ -54,7 +54,8 PRIVATE_HEADERS += \ | |||
|
54 | 54 | $$PWD/scroller_p.h \ |
|
55 | 55 | $$PWD/qabstractseries_p.h \ |
|
56 | 56 | $$PWD/chartlayout_p.h \ |
|
57 | $$PWD/charttitle_p.h | |
|
57 | $$PWD/charttitle_p.h \ | |
|
58 | $$PWD/charthelpers_p.h | |
|
58 | 59 | PUBLIC_HEADERS += \ |
|
59 | 60 | $$PWD/qchart.h \ |
|
60 | 61 | $$PWD/qchartglobal.h \ |
@@ -24,6 +24,7 | |||
|
24 | 24 | #include "qvalueaxis.h" |
|
25 | 25 | #include "xychart_p.h" |
|
26 | 26 | #include "qxylegendmarker.h" |
|
27 | #include "charthelpers_p.h" | |
|
27 | 28 | |
|
28 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 30 | |
@@ -243,8 +244,11 void QXYSeries::append(qreal x, qreal y) | |||
|
243 | 244 | void QXYSeries::append(const QPointF &point) |
|
244 | 245 | { |
|
245 | 246 | Q_D(QXYSeries); |
|
246 | d->m_points << point; | |
|
247 | emit pointAdded(d->m_points.count() - 1); | |
|
247 | ||
|
248 | if (isValidValue(point)) { | |
|
249 | d->m_points << point; | |
|
250 | emit pointAdded(d->m_points.count() - 1); | |
|
251 | } | |
|
248 | 252 | } |
|
249 | 253 | |
|
250 | 254 | /*! |
@@ -276,8 +280,10 void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint) | |||
|
276 | 280 | int index = d->m_points.indexOf(oldPoint); |
|
277 | 281 | if (index == -1) |
|
278 | 282 | return; |
|
279 | d->m_points[index] = newPoint; | |
|
280 | emit pointReplaced(index); | |
|
283 | if (isValidValue(newPoint)) { | |
|
284 | d->m_points[index] = newPoint; | |
|
285 | emit pointReplaced(index); | |
|
286 | } | |
|
281 | 287 | } |
|
282 | 288 | |
|
283 | 289 | /*! |
@@ -322,8 +328,10 void QXYSeries::remove(const QPointF &point) | |||
|
322 | 328 | void QXYSeries::insert(int index, const QPointF &point) |
|
323 | 329 | { |
|
324 | 330 | Q_D(QXYSeries); |
|
325 | d->m_points.insert(index, point); | |
|
326 | emit pointAdded(index); | |
|
331 | if (isValidValue(point)) { | |
|
332 | d->m_points.insert(index, point); | |
|
333 | emit pointAdded(index); | |
|
334 | } | |
|
327 | 335 | } |
|
328 | 336 | |
|
329 | 337 | /*! |
General Comments 0
You need to be logged in to leave comments.
Login now