##// END OF EJS Templates
Use qFuzzyIsNull to compare (in)equality of real values
Jani Honkonen -
r768:dd9d32f835df
parent child
Show More
@@ -108,7 +108,7 public Q_SLOTS:
108
108
109 void updateWidth(double width)
109 void updateWidth(double width)
110 {
110 {
111 if (width != m_pen.widthF()) {
111 if (!qFuzzyIsNull(width - m_pen.widthF())) {
112 m_pen.setWidthF(width);
112 m_pen.setWidthF(width);
113 emit changed();
113 emit changed();
114 }
114 }
@@ -337,7 +337,7 void Axis::setLayout(QVector<qreal> &layout)
337
337
338 bool Axis::isEmpty()
338 bool Axis::isEmpty()
339 {
339 {
340 return m_rect.isEmpty() || m_min==m_max || m_ticksCount==0;
340 return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0;
341 }
341 }
342
342
343 //handlers
343 //handlers
@@ -390,7 +390,8 void Axis::handleAxisUpdated()
390
390
391 void Axis::handleRangeChanged(qreal min, qreal max,int tickCount)
391 void Axis::handleRangeChanged(qreal min, qreal max,int tickCount)
392 {
392 {
393 if (min==max || tickCount<2) return;
393 if (qFuzzyIsNull(min - max) || tickCount < 2)
394 return;
394
395
395 m_min = min;
396 m_min = min;
396 m_max = max;
397 m_max = max;
@@ -328,13 +328,13 void QChartAxis::setMax(qreal max)
328 void QChartAxis::setRange(qreal min, qreal max)
328 void QChartAxis::setRange(qreal min, qreal max)
329 {
329 {
330 bool changed = false;
330 bool changed = false;
331 if (m_min != min) {
331 if (!qFuzzyIsNull(m_min - min)) {
332 m_min = min;
332 m_min = min;
333 changed = true;
333 changed = true;
334 emit minChanged(min);
334 emit minChanged(min);
335 }
335 }
336
336
337 if (m_max != max) {
337 if (!qFuzzyIsNull(m_max - max)) {
338 m_max = max;
338 m_max = max;
339 changed = true;
339 changed = true;
340 emit maxChanged(max);
340 emit maxChanged(max);
@@ -139,7 +139,7 QVector<QRectF> BarChartItem::calculateLayout()
139 value->setPos(xPos, yPos-barHeight / 2);
139 value->setPos(xPos, yPos-barHeight / 2);
140 value->setPen(barSet->floatingValuePen());
140 value->setPen(barSet->floatingValuePen());
141
141
142 if (m_series->valueAt(set,category) != 0) {
142 if (!qFuzzyIsNull(m_series->valueAt(set,category))) {
143 value->setValueString(QString::number(m_series->valueAt(set, category)));
143 value->setValueString(QString::number(m_series->valueAt(set, category)));
144 } else {
144 } else {
145 value->setValueString(QString(""));
145 value->setValueString(QString(""));
@@ -58,7 +58,7 QVector<QRectF> PercentBarChartItem::calculateLayout()
58 value->setPos(xPos, yPos-barHeight / 2);
58 value->setPos(xPos, yPos-barHeight / 2);
59 value->setPen(barSet->floatingValuePen());
59 value->setPen(barSet->floatingValuePen());
60
60
61 if (m_series->valueAt(set,category) != 0) {
61 if (!qFuzzyIsNull(m_series->valueAt(set,category))) {
62 int p = m_series->percentageAt(set,category) * 100;
62 int p = m_series->percentageAt(set,category) * 100;
63 QString vString(QString::number(p));
63 QString vString(QString::number(p));
64 vString.truncate(3);
64 vString.truncate(3);
@@ -64,7 +64,7 QVector<QRectF> StackedBarChartItem::calculateLayout()
64 value->setPos(xPos, yPos-barHeight / 2);
64 value->setPos(xPos, yPos-barHeight / 2);
65 value->setPen(barSet->floatingValuePen());
65 value->setPen(barSet->floatingValuePen());
66
66
67 if (m_series->valueAt(set, category) != 0) {
67 if (!qFuzzyIsNull(m_series->valueAt(set, category))) {
68 value->setValueString(QString::number(m_series->valueAt(set,category)));
68 value->setValueString(QString::number(m_series->valueAt(set,category)));
69 } else {
69 } else {
70 value->setValueString(QString(""));
70 value->setValueString(QString(""));
@@ -39,7 +39,7 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCo
39 tickYChanged=true;
39 tickYChanged=true;
40 }
40 }
41
41
42 if(m_minX!=minX || m_maxX!=maxX) {
42 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
43 if(m_niceNumbers) looseNiceNumbers(minX, maxX, m_tickXCount);
43 if(m_niceNumbers) looseNiceNumbers(minX, maxX, m_tickXCount);
44 m_minX=minX;
44 m_minX=minX;
45 m_maxX=maxX;
45 m_maxX=maxX;
@@ -48,7 +48,7 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCo
48 emit rangeXChanged(minX,maxX, m_tickXCount);
48 emit rangeXChanged(minX,maxX, m_tickXCount);
49 }
49 }
50
50
51 if(m_minY!=minY || m_maxY!=maxY) {
51 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
52 if(m_niceNumbers) looseNiceNumbers(minY, maxY, m_tickYCount);
52 if(m_niceNumbers) looseNiceNumbers(minY, maxY, m_tickYCount);
53 m_minY=minY;
53 m_minY=minY;
54 m_maxY=maxY;
54 m_maxY=maxY;
@@ -124,7 +124,7 qreal Domain::spanY() const
124
124
125 bool Domain::isEmpty() const
125 bool Domain::isEmpty() const
126 {
126 {
127 return spanX()==0 || spanY()==0;
127 return qFuzzyIsNull(spanX()) || qFuzzyIsNull(spanY());
128 }
128 }
129
129
130 void Domain::zoomIn(const QRectF& rect, const QSizeF& size)
130 void Domain::zoomIn(const QRectF& rect, const QSizeF& size)
@@ -235,10 +235,10 qreal Domain::niceNumber(qreal x,bool ceiling)
235
235
236 bool operator== (const Domain &domain1, const Domain &domain2)
236 bool operator== (const Domain &domain1, const Domain &domain2)
237 {
237 {
238 return (domain1.m_maxX == domain2.m_maxX &&
238 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
239 domain1.m_maxY == domain2.m_maxY &&
239 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
240 domain1.m_minX == domain2.m_minX &&
240 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
241 domain1.m_minY == domain2.m_minY);
241 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
242 }
242 }
243
243
244 bool operator!= (const Domain &domain1, const Domain &domain2)
244 bool operator!= (const Domain &domain1, const Domain &domain2)
@@ -56,7 +56,7 public:
56
56
57 bool operator!=(const PieSliceData &other)
57 bool operator!=(const PieSliceData &other)
58 {
58 {
59 if (m_value != other.m_value)
59 if (!qFuzzyIsNull(m_value - other.m_value))
60 return true;
60 return true;
61
61
62 if (m_slicePen != other.m_slicePen ||
62 if (m_slicePen != other.m_slicePen ||
@@ -89,7 +89,7 qreal QScatterSeries::size() const
89 */
89 */
90 void QScatterSeries::setSize(qreal size)
90 void QScatterSeries::setSize(qreal size)
91 {
91 {
92 if (m_size != size) {
92 if (!qFuzzyIsNull(m_size - size)) {
93 m_size = size;
93 m_size = size;
94 emit updated();
94 emit updated();
95 }
95 }
@@ -143,7 +143,7 void XYChartItem::handleGeometryChanged(const QRectF &rect)
143
143
144 bool XYChartItem::isEmpty()
144 bool XYChartItem::isEmpty()
145 {
145 {
146 return !m_clipRect.isValid() || m_maxX - m_minX == 0 || m_maxY - m_minY ==0 ;
146 return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY);
147 }
147 }
148
148
149 void XYChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
149 void XYChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
@@ -99,12 +99,12 void tst_Domain::handleAxisRangeXChanged()
99 domain.handleAxisXChanged(min, max);
99 domain.handleAxisXChanged(min, max);
100
100
101 QList<QVariant> arg0 = spy0.first();
101 QList<QVariant> arg0 = spy0.first();
102 QVERIFY(arg0.at(0).toReal() == min);
102 QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min));
103 QVERIFY(arg0.at(1).toReal() == max);
103 QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max));
104
104
105 QList<QVariant> arg1 = spy1.first();
105 QList<QVariant> arg1 = spy1.first();
106 QVERIFY(arg1.at(0).toReal() == min);
106 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
107 QVERIFY(arg1.at(1).toReal() == max);
107 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
108
108
109 QCOMPARE(spy0.count(), 1);
109 QCOMPARE(spy0.count(), 1);
110 QCOMPARE(spy1.count(), 1);
110 QCOMPARE(spy1.count(), 1);
@@ -136,12 +136,12 void tst_Domain::handleAxisRangeYChanged()
136 domain.handleAxisYChanged(min, max,5);
136 domain.handleAxisYChanged(min, max,5);
137
137
138 QList<QVariant> arg0 = spy0.first();
138 QList<QVariant> arg0 = spy0.first();
139 QVERIFY(arg0.at(2).toReal() == min);
139 QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min));
140 QVERIFY(arg0.at(3).toReal() == max);
140 QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max));
141
141
142 QList<QVariant> arg1 = spy2.first();
142 QList<QVariant> arg1 = spy2.first();
143 QVERIFY(arg1.at(0).toReal() == min);
143 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
144 QVERIFY(arg1.at(1).toReal() == max);
144 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
145
145
146 QCOMPARE(spy0.count(), 1);
146 QCOMPARE(spy0.count(), 1);
147 QCOMPARE(spy1.count(), 0);
147 QCOMPARE(spy1.count(), 0);
@@ -415,12 +415,12 void tst_Domain::setRangeX()
415 domain.setRangeX(min, max);
415 domain.setRangeX(min, max);
416
416
417 QList<QVariant> arg0 = spy0.first();
417 QList<QVariant> arg0 = spy0.first();
418 QVERIFY(arg0.at(0).toReal() == min);
418 QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min));
419 QVERIFY(arg0.at(1).toReal() == max);
419 QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max));
420
420
421 QList<QVariant> arg1 = spy1.first();
421 QList<QVariant> arg1 = spy1.first();
422 QVERIFY(arg1.at(0).toReal() == min);
422 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
423 QVERIFY(arg1.at(1).toReal() == max);
423 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
424
424
425 QCOMPARE(spy0.count(), 1);
425 QCOMPARE(spy0.count(), 1);
426 QCOMPARE(spy1.count(), 1);
426 QCOMPARE(spy1.count(), 1);
@@ -450,12 +450,12 void tst_Domain::setRangeY()
450 domain.setRangeY(min, max);
450 domain.setRangeY(min, max);
451
451
452 QList<QVariant> arg0 = spy0.first();
452 QList<QVariant> arg0 = spy0.first();
453 QVERIFY(arg0.at(2).toReal() == min);
453 QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min));
454 QVERIFY(arg0.at(3).toReal() == max);
454 QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max));
455
455
456 QList<QVariant> arg1 = spy2.first();
456 QList<QVariant> arg1 = spy2.first();
457 QVERIFY(arg1.at(0).toReal() == min);
457 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
458 QVERIFY(arg1.at(1).toReal() == max);
458 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
459
459
460 QCOMPARE(spy0.count(), 1);
460 QCOMPARE(spy0.count(), 1);
461 QCOMPARE(spy1.count(), 0);
461 QCOMPARE(spy1.count(), 0);
General Comments 0
You need to be logged in to leave comments. Login now