summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2010-05-27 15:28:26 +0200
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2010-05-27 16:01:52 +0200
commit2c54f49584023633c5992579d23dc6819ec79c9e (patch)
tree9a0478fccf23b8de47f85a838a2fee04a8ec325f
parentddf119a57001edd71eb6b84dffc7cda4a8ca2c0e (diff)
Wrong QGraphicsItem::childrenBoundingRect() when applying effects.
Problem was that we used the children's raw bounding rect instead of using their effective bounding rect when calculating the bounds. Auto test included. Task-number: QTBUG-10756
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp6
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp29
2 files changed, 32 insertions, 3 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index db6c4c513d..36d21a6238 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -1275,14 +1275,14 @@ void QGraphicsItemPrivate::childrenBoundingRectHelper(QTransform *x, QRectF *rec
QTransform matrix = childd->transformToParent();
if (x)
matrix *= *x;
- *rect |= matrix.mapRect(child->boundingRect());
+ *rect |= matrix.mapRect(child->d_ptr->effectiveBoundingRect());
if (!childd->children.isEmpty())
childd->childrenBoundingRectHelper(&matrix, rect);
} else {
if (x)
- *rect |= x->mapRect(child->boundingRect());
+ *rect |= x->mapRect(child->d_ptr->effectiveBoundingRect());
else
- *rect |= child->boundingRect();
+ *rect |= child->d_ptr->effectiveBoundingRect();
if (!childd->children.isEmpty())
childd->childrenBoundingRectHelper(x, rect);
}
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index 300afc3ffe..5547b02820 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -348,6 +348,7 @@ private slots:
void childrenBoundingRect2();
void childrenBoundingRect3();
void childrenBoundingRect4();
+ void childrenBoundingRect5();
void group();
void setGroup();
void setGroup2();
@@ -3369,6 +3370,34 @@ void tst_QGraphicsItem::childrenBoundingRect4()
QCOMPARE(rect2->childrenBoundingRect(), rect3->boundingRect());
}
+void tst_QGraphicsItem::childrenBoundingRect5()
+{
+ QGraphicsScene scene;
+
+ QGraphicsRectItem *parent = scene.addRect(QRectF(0, 0, 100, 100));
+ QGraphicsRectItem *child = scene.addRect(QRectF(0, 0, 100, 100));
+ child->setParentItem(parent);
+
+ QGraphicsView view(&scene);
+ view.show();
+
+ QTest::qWaitForWindowShown(&view);
+
+ // Try to mess up the cached bounding rect.
+ QRectF expectedChildrenBoundingRect = parent->boundingRect();
+ QCOMPARE(parent->childrenBoundingRect(), expectedChildrenBoundingRect);
+
+ // Apply some effects.
+ QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect;
+ dropShadow->setOffset(25, 25);
+ child->setGraphicsEffect(dropShadow);
+ parent->setGraphicsEffect(new QGraphicsOpacityEffect);
+
+ QVERIFY(parent->childrenBoundingRect() != expectedChildrenBoundingRect);
+ expectedChildrenBoundingRect |= dropShadow->boundingRect();
+ QCOMPARE(parent->childrenBoundingRect(), expectedChildrenBoundingRect);
+}
+
void tst_QGraphicsItem::group()
{
QGraphicsScene scene;