@@ -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 | void QBarSetPrivate::append(QPointF value) |
|
556 | void QBarSetPrivate::append(QPointF value) | |
557 | { |
|
557 | { | |
558 | m_values.append(value); |
|
558 | if (isValidValue(value)) { | |
559 | emit restructuredBars(); |
|
559 | m_values.append(value); | |
|
560 | emit restructuredBars(); | |||
|
561 | } | |||
560 | } |
|
562 | } | |
561 |
|
563 | |||
562 | void QBarSetPrivate::append(QList<QPointF> values) |
|
564 | void QBarSetPrivate::append(QList<QPointF> values) | |
563 | { |
|
565 | { | |
564 | for (int i = 0; i < values.count(); i++) |
|
566 | for (int i = 0; i < values.count(); i++) { | |
565 |
|
|
567 | if (isValidValue(values.at(i))) | |
|
568 | m_values.append(values.at(i)); | |||
|
569 | } | |||
566 | emit restructuredBars(); |
|
570 | emit restructuredBars(); | |
567 | } |
|
571 | } | |
568 |
|
572 | |||
@@ -570,8 +574,10 void QBarSetPrivate::append(QList<qreal> values) | |||||
570 | { |
|
574 | { | |
571 | int index = m_values.count(); |
|
575 | int index = m_values.count(); | |
572 | for (int i = 0; i < values.count(); i++) { |
|
576 | for (int i = 0; i < values.count(); i++) { | |
573 | m_values.append(QPointF(index, values.at(i))); |
|
577 | if (isValidValue(values.at(i))) { | |
574 | index++; |
|
578 | m_values.append(QPointF(index, values.at(i))); | |
|
579 | index++; | |||
|
580 | } | |||
575 | } |
|
581 | } | |
576 | emit restructuredBars(); |
|
582 | emit restructuredBars(); | |
577 | } |
|
583 | } |
@@ -25,6 +25,7 | |||||
25 | #include <QPen> |
|
25 | #include <QPen> | |
26 | #include <QBrush> |
|
26 | #include <QBrush> | |
27 | #include <QFont> |
|
27 | #include <QFont> | |
|
28 | #include "charthelpers_p.h" | |||
28 |
|
29 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | class QBarSetPrivate; |
|
31 | class QBarSetPrivate; |
@@ -27,6 +27,7 | |||||
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 | #include "qabstractaxis.h" |
|
28 | #include "qabstractaxis.h" | |
29 | #include "pieanimation_p.h" |
|
29 | #include "pieanimation_p.h" | |
|
30 | #include "charthelpers_p.h" | |||
30 |
|
31 | |||
31 | #include "qpielegendmarker.h" |
|
32 | #include "qpielegendmarker.h" | |
32 |
|
33 | |||
@@ -400,6 +401,8 bool QPieSeries::append(QList<QPieSlice *> slices) | |||||
400 | return false; |
|
401 | return false; | |
401 | if (s->series()) // already added to some series |
|
402 | if (s->series()) // already added to some series | |
402 | return false; |
|
403 | return false; | |
|
404 | if (!isValidValue(s->value())) | |||
|
405 | return false; | |||
403 | } |
|
406 | } | |
404 |
|
407 | |||
405 | foreach (QPieSlice *s, slices) { |
|
408 | foreach (QPieSlice *s, slices) { | |
@@ -436,12 +439,17 QPieSeries &QPieSeries::operator << (QPieSlice *slice) | |||||
436 | /*! |
|
439 | /*! | |
437 | Appends a single slice to the series with give \a value and \a label. |
|
440 | Appends a single slice to the series with give \a value and \a label. | |
438 | Slice ownership is passed to the series. |
|
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 | QPieSlice *QPieSeries::append(QString label, qreal value) |
|
444 | QPieSlice *QPieSeries::append(QString label, qreal value) | |
441 | { |
|
445 | { | |
442 | QPieSlice *slice = new QPieSlice(label, value); |
|
446 | if (isValidValue(value)) { | |
443 | append(slice); |
|
447 | QPieSlice *slice = new QPieSlice(label, value); | |
444 |
|
|
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 | if (slice->series()) // already added to some series |
|
471 | if (slice->series()) // already added to some series | |
464 | return false; |
|
472 | return false; | |
465 |
|
473 | |||
|
474 | if (!isValidValue(slice->value())) | |||
|
475 | return false; | |||
|
476 | ||||
466 | slice->setParent(this); |
|
477 | slice->setParent(this); | |
467 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
478 | QPieSlicePrivate::fromSlice(slice)->m_series = this; | |
468 | d->m_slices.insert(index, slice); |
|
479 | d->m_slices.insert(index, slice); |
@@ -54,7 +54,8 PRIVATE_HEADERS += \ | |||||
54 | $$PWD/scroller_p.h \ |
|
54 | $$PWD/scroller_p.h \ | |
55 | $$PWD/qabstractseries_p.h \ |
|
55 | $$PWD/qabstractseries_p.h \ | |
56 | $$PWD/chartlayout_p.h \ |
|
56 | $$PWD/chartlayout_p.h \ | |
57 | $$PWD/charttitle_p.h |
|
57 | $$PWD/charttitle_p.h \ | |
|
58 | $$PWD/charthelpers_p.h | |||
58 | PUBLIC_HEADERS += \ |
|
59 | PUBLIC_HEADERS += \ | |
59 | $$PWD/qchart.h \ |
|
60 | $$PWD/qchart.h \ | |
60 | $$PWD/qchartglobal.h \ |
|
61 | $$PWD/qchartglobal.h \ |
@@ -24,6 +24,7 | |||||
24 | #include "qvalueaxis.h" |
|
24 | #include "qvalueaxis.h" | |
25 | #include "xychart_p.h" |
|
25 | #include "xychart_p.h" | |
26 | #include "qxylegendmarker.h" |
|
26 | #include "qxylegendmarker.h" | |
|
27 | #include "charthelpers_p.h" | |||
27 |
|
28 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
30 | |||
@@ -243,8 +244,11 void QXYSeries::append(qreal x, qreal y) | |||||
243 | void QXYSeries::append(const QPointF &point) |
|
244 | void QXYSeries::append(const QPointF &point) | |
244 | { |
|
245 | { | |
245 | Q_D(QXYSeries); |
|
246 | Q_D(QXYSeries); | |
246 | d->m_points << point; |
|
247 | ||
247 | emit pointAdded(d->m_points.count() - 1); |
|
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 | int index = d->m_points.indexOf(oldPoint); |
|
280 | int index = d->m_points.indexOf(oldPoint); | |
277 | if (index == -1) |
|
281 | if (index == -1) | |
278 | return; |
|
282 | return; | |
279 | d->m_points[index] = newPoint; |
|
283 | if (isValidValue(newPoint)) { | |
280 | emit pointReplaced(index); |
|
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 | void QXYSeries::insert(int index, const QPointF &point) |
|
328 | void QXYSeries::insert(int index, const QPointF &point) | |
323 | { |
|
329 | { | |
324 | Q_D(QXYSeries); |
|
330 | Q_D(QXYSeries); | |
325 | d->m_points.insert(index, point); |
|
331 | if (isValidValue(point)) { | |
326 | emit pointAdded(index); |
|
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