diff options
author | Andreas Aardal Hanssen <andreas@hanssen.name> | 2013-07-30 18:08:10 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-05 20:15:53 +0200 |
commit | 8fce4e97ba8479a24bff167ce72ed43223076905 (patch) | |
tree | f1704d41e3ec163434c57931c17e75a7591d75eb /tests | |
parent | 12571cc095ce1d789f27f94bfc530efb32d9d1b3 (diff) |
Fix double transform for items ignoring parent transformations.
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 <jan-arve.saether@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
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<QGraphicsItem *> 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" |