summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-04-23 15:46:54 (GMT)
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-04-23 15:49:36 (GMT)
commit5423ba187c62ea861ccfcc013fb15fcc4a5ae28d (patch)
tree81135e3cf5ec81aff1c533c1a1157ae519d2d352 /tests
parent4ec0d20bda2d7c4dfd1da41d52404481f5ecd42c (diff)
downloadQt-5423ba187c62ea861ccfcc013fb15fcc4a5ae28d.zip
Qt-5423ba187c62ea861ccfcc013fb15fcc4a5ae28d.tar.gz
Qt-5423ba187c62ea861ccfcc013fb15fcc4a5ae28d.tar.bz2
Fix bugs in QGraphicsItem::childrenBoundingRect()
While working on layering in Graphics View I stumbled over this bug. The QGraphicsItem::childrenBoundingRect() function had an accumulating error caused by recursive adding of rectangles that individually were mapped to the local parent using QGraphicsItem::mapRectToParent() / QTransform::mapRect. This caused the brect to be way too large for items with children that are rotated (fex, alternating 45 and -45 degrees). The new version should be just as fast, but with no loss of precision. Reviewed-by: bnilsen
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index 57e441b..88c64d3 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -172,6 +172,7 @@ private slots:
void boundingRects2();
void sceneBoundingRect();
void childrenBoundingRect();
+ void childrenBoundingRectTransformed();
void group();
void setGroup();
void nestedGroups();
@@ -2917,9 +2918,57 @@ void tst_QGraphicsItem::childrenBoundingRect()
childChild->setParentItem(child);
childChild->setPos(500, 500);
child->rotate(90);
+
+
+ scene.addPolygon(parent->mapToScene(parent->boundingRect() | parent->childrenBoundingRect()))->setPen(QPen(Qt::red));;
+
+ QGraphicsView view(&scene);
+ view.show();
+
+ QTest::qWait(5000);
+
QCOMPARE(parent->childrenBoundingRect(), QRectF(-500, -100, 600, 800));
}
+void tst_QGraphicsItem::childrenBoundingRectTransformed()
+{
+ QGraphicsScene scene;
+
+ QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100));
+ QGraphicsRectItem *rect2 = scene.addRect(QRectF(0, 0, 100, 100));
+ QGraphicsRectItem *rect3 = scene.addRect(QRectF(0, 0, 100, 100));
+ QGraphicsRectItem *rect4 = scene.addRect(QRectF(0, 0, 100, 100));
+ QGraphicsRectItem *rect5 = scene.addRect(QRectF(0, 0, 100, 100));
+ rect2->setParentItem(rect);
+ rect3->setParentItem(rect2);
+ rect4->setParentItem(rect3);
+ rect5->setParentItem(rect4);
+
+ rect2->setTransform(QTransform().translate(50, 50).rotate(45));
+ rect2->setPos(25, 25);
+ rect3->setTransform(QTransform().translate(50, 50).rotate(45));
+ rect3->setPos(25, 25);
+ rect4->setTransform(QTransform().translate(50, 50).rotate(45));
+ rect4->setPos(25, 25);
+ rect5->setTransform(QTransform().translate(50, 50).rotate(45));
+ rect5->setPos(25, 25);
+
+ QRectF subTreeRect = rect->childrenBoundingRect();
+ QCOMPARE(subTreeRect.left(), qreal(-206.0660171779821));
+ QCOMPARE(subTreeRect.top(), qreal(75.0));
+ QCOMPARE(subTreeRect.width(), qreal(351.7766952966369));
+ QCOMPARE(subTreeRect.height(), qreal(251.7766952966369));
+
+ rect->rotate(45);
+ rect2->rotate(-45);
+ rect3->rotate(45);
+ rect4->rotate(-45);
+ rect5->rotate(45);
+
+ subTreeRect = rect->childrenBoundingRect();
+ QCOMPARE(rect->childrenBoundingRect(), QRectF(-100, 75, 275, 250));
+}
+
void tst_QGraphicsItem::group()
{
QGraphicsScene scene;