summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-06-23 09:01:15 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-06-23 10:41:30 (GMT)
commita8a0c956f747cd09ca04cfe8b33d09a8476c6453 (patch)
tree5eaefe921a5f45f290d5dcb701eb71f142f68f25
parentaacf96f414651c516b11518d9a921d9853d09e69 (diff)
downloadQt-a8a0c956f747cd09ca04cfe8b33d09a8476c6453.zip
Qt-a8a0c956f747cd09ca04cfe8b33d09a8476c6453.tar.gz
Qt-a8a0c956f747cd09ca04cfe8b33d09a8476c6453.tar.bz2
Regression against 4.4 in QRectF::operator|.
In 4.4 QRectF handled flat rectangles in the same fashion as QRect does, but that changed with Lars' and Jo's optmizations done in the falcon branch. The difference is that the optimized version only checks whether the width or height is 0, whereas in 4.4 both had to be 0 (isNull()) before we bailed out. This regression also introduced a regression in QGraphicsItem::childrenBoundingRect(). Auto-test included. Task-number: 254995 Reviewed-by: Lars
-rw-r--r--src/corelib/tools/qrect.cpp62
-rw-r--r--src/corelib/tools/qrect.h2
-rw-r--r--tests/auto/qrect/tst_qrect.cpp2
3 files changed, 31 insertions, 35 deletions
diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp
index 2082794..b4fe070 100644
--- a/src/corelib/tools/qrect.cpp
+++ b/src/corelib/tools/qrect.cpp
@@ -2154,48 +2154,42 @@ bool QRectF::contains(const QRectF &r) const
QRectF QRectF::operator|(const QRectF &r) const
{
- qreal l1 = xp;
- qreal r1 = xp;
- if (w < 0)
- l1 += w;
- else
- r1 += w;
- if (l1 == r1) // null rect
+ if (isNull())
return r;
+ if (r.isNull())
+ return *this;
- qreal l2 = r.xp;
- qreal r2 = r.xp;
- if (r.w < 0)
- l2 += r.w;
+ qreal left = xp;
+ qreal right = xp;
+ if (w < 0)
+ left += w;
else
- r2 += r.w;
- if (l2 == r2) // null rect
- return *this;
+ right += w;
- qreal t1 = yp;
- qreal b1 = yp;
+ if (r.w < 0) {
+ left = qMin(left, r.xp + r.w);
+ right = qMax(right, r.xp);
+ } else {
+ left = qMin(left, r.xp);
+ right = qMax(right, r.xp + r.w);
+ }
+
+ qreal top = yp;
+ qreal bottom = yp;
if (h < 0)
- t1 += h;
+ top += h;
else
- b1 += h;
- if (t1 == b1) // null rect
- return r;
+ bottom += h;
- qreal t2 = r.yp;
- qreal b2 = r.yp;
- if (r.h < 0)
- t2 += r.h;
- else
- b2 += r.h;
- if (t2 == b2) // null rect
- return *this;
+ if (r.h < 0) {
+ top = qMin(top, r.yp + r.h);
+ bottom = qMax(bottom, r.yp);
+ } else {
+ top = qMin(top, r.yp);
+ bottom = qMax(bottom, r.yp + r.h);
+ }
- QRectF tmp;
- tmp.xp = qMin(l1, l2);
- tmp.yp = qMin(t1, t2);
- tmp.w = qMax(r1, r2) - tmp.xp;
- tmp.h = qMax(b1, b2) - tmp.yp;
- return tmp;
+ return QRectF(left, top, right - left, bottom - top);
}
/*!
diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h
index 0740fe5..efdc24d 100644
--- a/src/corelib/tools/qrect.h
+++ b/src/corelib/tools/qrect.h
@@ -653,7 +653,7 @@ inline QRectF::QRectF(const QRect &r)
}
inline bool QRectF::isNull() const
-{ return qIsNull(w) && qIsNull(h); }
+{ return w == 0. && h == 0.; }
inline bool QRectF::isEmpty() const
{ return w <= 0. || h <= 0.; }
diff --git a/tests/auto/qrect/tst_qrect.cpp b/tests/auto/qrect/tst_qrect.cpp
index cdb5560..5a91636 100644
--- a/tests/auto/qrect/tst_qrect.cpp
+++ b/tests/auto/qrect/tst_qrect.cpp
@@ -4125,6 +4125,7 @@ void tst_QRect::unitedRect_data()
QTest::newRow("test 13") << QRect() << QRect(10, 10, 10, 10) << QRect(10, 10, 10, 10);
QTest::newRow("test 14") << QRect(10, 10, 10, 10) << QRect() << QRect(10, 10, 10, 10);
QTest::newRow("test 15") << QRect() << QRect() << QRect();
+ QTest::newRow("test 16") << QRect(0, 0, 100, 0) << QRect(0, 0, 0, 100) << QRect(0, 0, 100, 100);
}
void tst_QRect::unitedRect()
@@ -4160,6 +4161,7 @@ void tst_QRect::unitedRectF_data()
QTest::newRow("test 13") << QRectF() << QRectF(10, 10, 10, 10) << QRectF(10, 10, 10, 10);
QTest::newRow("test 14") << QRectF(10, 10, 10, 10) << QRectF() << QRectF(10, 10, 10, 10);
QTest::newRow("test 15") << QRectF() << QRectF() << QRectF();
+ QTest::newRow("test 16") << QRectF(0, 0, 100, 0) << QRectF(0, 0, 0, 100) << QRectF(0, 0, 100, 100);
}
void tst_QRect::unitedRectF()