From 5a734e4657161e0877b32181df35a56241b21de4 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 22 May 2009 13:24:44 +0200 Subject: Fix the way the transform and the properties are marked as dirty in QGraphicsItem Acknowledged-by: Thierry --- src/gui/graphicsview/qgraphicsitem.cpp | 9 +++-- src/gui/graphicsview/qgraphicsitem_p.h | 2 +- tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 50 ++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index b7e88f4..828dd4f 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -2607,7 +2607,6 @@ QTransform QGraphicsItem::transform() const QVariant v(x); d_ptr->setExtra(QGraphicsItemPrivate::ExtraTransform, v); d_ptr->dirtyTransform = 0; - d_ptr->dirtyTransformComponents = 1; const_cast(this)->itemChange(ItemTransformHasChanged, v); return x; } @@ -3200,9 +3199,9 @@ void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine) prepareGeometryChange(); d_ptr->hasTransform = !newTransform.isIdentity(); d_ptr->setExtra(QGraphicsItemPrivate::ExtraTransform, newTransform); + d_ptr->dirtyTransformComponents = 1; + d_ptr->dirtyTransform = 0; d_ptr->invalidateSceneTransformCache(); - if (d_ptr->hasDecomposedTransform) - d_ptr->dirtyTransform = 1; // Send post-notification. // NB! We have to change the value from QMatrix to QTransform. @@ -3253,9 +3252,9 @@ void QGraphicsItem::setTransform(const QTransform &matrix, bool combine) prepareGeometryChange(); d_ptr->hasTransform = !newTransform.isIdentity(); d_ptr->setExtra(QGraphicsItemPrivate::ExtraTransform, newTransform); + d_ptr->dirtyTransformComponents = 1; + d_ptr->dirtyTransform = 0; d_ptr->invalidateSceneTransformCache(); - if (d_ptr->hasDecomposedTransform) - d_ptr->dirtyTransform = 1; // Send post-notification. itemChange(ItemTransformHasChanged, newTransformVariant); diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index cebc8ca..b2569c1 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -346,7 +346,7 @@ public: int globalStackingOrder; int sceneTransformIndex; - struct DecomposedTransform; + struct DecomposedTransform; DecomposedTransform *decomposedTransform() const { QGraphicsItemPrivate *that = const_cast(this); diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index d41b3b4..c03c420 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -6404,26 +6404,26 @@ void tst_QGraphicsItem::setTransformProperties_data() QTest::addColumn("shearY"); QTest::newRow("nothing") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) << qreal(0.0); + << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0); QTest::newRow("rotationZ") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(42.2) - << qreal(0.0) << qreal(0.0) << qreal(0.0) << qreal(0.0); + << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0); QTest::newRow("rotationXY") << QPointF() << qreal(12.5) << qreal(53.6) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) << qreal(0.0); + << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0); QTest::newRow("rotationXYZ") << QPointF() << qreal(-25) << qreal(12) << qreal(556) - << qreal(0.0) << qreal(0.0) << qreal(0.0) << qreal(0.0); + << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0); QTest::newRow("rotationXYZ dicentred") << QPointF(-53, 25.2) << qreal(-2578.2) << qreal(4565.2) << qreal(56) - << qreal(0.0) << qreal(0.0) << qreal(0.0) << qreal(0.0); + << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0); QTest::newRow("Scale") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0) << qreal(6) << qreal(0.5) << qreal(0.0) << qreal(0.0); QTest::newRow("Shear") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(2.2) << qreal(0.5); + << qreal(1) << qreal(1) << qreal(2.2) << qreal(0.5); QTest::newRow("Scale and Shear") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0) << qreal(5.2) << qreal(2.1) << qreal(5.2) << qreal(5.5); @@ -6475,6 +6475,44 @@ void tst_QGraphicsItem::setTransformProperties() QCOMPARE(item->transformOrigin(), origin); QCOMPARE(result, item->transform()); + + //----------------------------------------------------------------- + //Change the rotation Z + item->setZRotation(45); + QTransform result2; + result2.translate(origin.x(), origin.y()); + result2.rotate(rotationX, Qt::XAxis); + result2.rotate(rotationY, Qt::YAxis); + result2.rotate(45, Qt::ZAxis); + result2.shear(shearX, shearY); + result2.scale(scaleX, scaleY); + result2.translate(-origin.x(), -origin.y()); + + QCOMPARE(item->xRotation(), rotationX); + QCOMPARE(item->yRotation(), rotationY); + QCOMPARE(item->zRotation(), 45.0); + QCOMPARE(item->xScale(), scaleX); + QCOMPARE(item->yScale(), scaleY); + QCOMPARE(item->horizontalShear(), shearX); + QCOMPARE(item->verticalShear(), shearY); + QCOMPARE(item->transformOrigin(), origin); + + QCOMPARE(result2, item->transform()); + + //----------------------------------------------------------------- + // calling setTransform() should reset the properties to their default + item->setTransform(result); + + QCOMPARE(item->xRotation(), 0.0); + QCOMPARE(item->yRotation(), 0.0); + QCOMPARE(item->zRotation(), 0.0); + QCOMPARE(item->xScale(), 1.0); + QCOMPARE(item->yScale(), 1.0); + QCOMPARE(item->horizontalShear(), 0.0); + QCOMPARE(item->verticalShear(), 0.0); + QCOMPARE(item->transformOrigin(), QPointF(0,0)); + + QCOMPARE(result, item->transform()); } -- cgit v0.12