From 8fce4e97ba8479a24bff167ce72ed43223076905 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Tue, 30 Jul 2013 18:08:10 +0200 Subject: Fix double transform for items ignoring parent transformations. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the topmost untransformable's scene transform, which includes the item's position and local transformation, was used to determine the item's anchoring position. This position was then passed on to be multiplied by the item's transform again. This works fine for toplevel untransformable items that don't have any transform set at all, but those who do would have their transforms applied twice - one to determine the anchoring position, and again to transform the item itself. Since only translation transformations can affect the first operation (the anchoring pos), this bug only applies to items that set ItemIgnoresTransformations and use a local transform that includes translation. Task-number: QTBUG-21618 Change-Id: I772d52d59dfd9f242d0140632a87e9c68dfe0ea1 Reviewed-by: Jan Arve Sæther --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 3e24257736..9353aa0eba 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -471,6 +471,7 @@ private slots: void QTBUG_16374_crashInDestructor(); void QTBUG_20699_focusScopeCrash(); void QTBUG_30990_rightClickSelection(); + void QTBUG_21618_untransformable_sceneTransform(); private: QList paintedItems; @@ -11496,5 +11497,65 @@ void tst_QGraphicsItem::QTBUG_30990_rightClickSelection() QVERIFY(!item2->isSelected()); } +void tst_QGraphicsItem::QTBUG_21618_untransformable_sceneTransform() +{ + QGraphicsScene scene(0, 0, 150, 150); + scene.addRect(-2, -2, 4, 4); + + QGraphicsItem *item1 = scene.addRect(0, 0, 100, 100, QPen(), Qt::red); + item1->setPos(50, 50); + item1->translate(50, 50); + item1->rotate(90); + QGraphicsItem *item2 = scene.addRect(0, 0, 100, 100, QPen(), Qt::green); + item2->setPos(50, 50); + item2->translate(50, 50); + item2->rotate(90); + item2->setFlags(QGraphicsItem::ItemIgnoresTransformations); + + QGraphicsRectItem *item1_topleft = new QGraphicsRectItem(QRectF(-2, -2, 4, 4)); + item1_topleft->setParentItem(item1); + item1_topleft->setBrush(Qt::black); + QGraphicsRectItem *item1_bottomright = new QGraphicsRectItem(QRectF(-2, -2, 4, 4)); + item1_bottomright->setParentItem(item1); + item1_bottomright->setPos(100, 100); + item1_bottomright->setBrush(Qt::yellow); + + QGraphicsRectItem *item2_topleft = new QGraphicsRectItem(QRectF(-2, -2, 4, 4)); + item2_topleft->setParentItem(item2); + item2_topleft->setBrush(Qt::black); + QGraphicsRectItem *item2_bottomright = new QGraphicsRectItem(QRectF(-2, -2, 4, 4)); + item2_bottomright->setParentItem(item2); + item2_bottomright->setPos(100, 100); + item2_bottomright->setBrush(Qt::yellow); + + QCOMPARE(item1->sceneTransform(), item2->sceneTransform()); + QCOMPARE(item1_topleft->sceneTransform(), item2_topleft->sceneTransform()); + QCOMPARE(item1_bottomright->sceneTransform(), item2_bottomright->sceneTransform()); + QCOMPARE(item1->deviceTransform(QTransform()), item2->deviceTransform(QTransform())); + QCOMPARE(item1->deviceTransform(QTransform()).map(QPointF()), QPointF(100, 100)); + QCOMPARE(item2->deviceTransform(QTransform()).map(QPointF()), QPointF(100, 100)); + QCOMPARE(item1->deviceTransform(QTransform()).map(QPointF(100, 100)), QPointF(0, 200)); + QCOMPARE(item2->deviceTransform(QTransform()).map(QPointF(100, 100)), QPointF(0, 200)); + QCOMPARE(item1_topleft->deviceTransform(QTransform()).map(QPointF()), QPointF(100, 100)); + QCOMPARE(item2_topleft->deviceTransform(QTransform()).map(QPointF()), QPointF(100, 100)); + QCOMPARE(item1_bottomright->deviceTransform(QTransform()).map(QPointF()), QPointF(0, 200)); + QCOMPARE(item2_bottomright->deviceTransform(QTransform()).map(QPointF()), QPointF(0, 200)); + + item2->setParentItem(item1); + + QCOMPARE(item2->deviceTransform(QTransform()).map(QPointF()), QPointF(100, 200)); + QCOMPARE(item2->deviceTransform(QTransform()).map(QPointF(100, 100)), QPointF(0, 300)); + QCOMPARE(item2_topleft->deviceTransform(QTransform()).map(QPointF()), QPointF(100, 200)); + QCOMPARE(item2_bottomright->deviceTransform(QTransform()).map(QPointF()), QPointF(0, 300)); + + QTransform tx = QTransform::fromTranslate(100, 0); + QCOMPARE(item1->deviceTransform(tx).map(QPointF()), QPointF(200, 100)); + QCOMPARE(item1->deviceTransform(tx).map(QPointF(100, 100)), QPointF(100, 200)); + QCOMPARE(item2->deviceTransform(tx).map(QPointF()), QPointF(200, 200)); + QCOMPARE(item2->deviceTransform(tx).map(QPointF(100, 100)), QPointF(100, 300)); + QCOMPARE(item2_topleft->deviceTransform(tx).map(QPointF()), QPointF(200, 200)); + QCOMPARE(item2_bottomright->deviceTransform(tx).map(QPointF()), QPointF(100, 300)); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" -- cgit v1.2.3