From 0d3c17fc672a762085f74d0e436ef842370729ec Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 18 Oct 2010 11:04:04 +0200 Subject: Fixed QGraphicsItem to send ItemScenePositionHasChanged when appropriate Task-number: QTBUG-13473 Merge-request: 812 Reviewed-by: Alexis Menard --- src/gui/graphicsview/qgraphicsitem.cpp | 6 +++++- tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 27 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index e63acac..2b6aaf5 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -3706,6 +3706,8 @@ void QGraphicsItem::setPos(const QPointF &pos) d_ptr->setPosHelper(pos); if (d_ptr->isWidget) static_cast(this)->d_func()->setGeometryFromSetPos(); + if (d_ptr->scenePosDescendants) + d_ptr->sendScenePosChange(); return; } @@ -4388,8 +4390,10 @@ void QGraphicsItem::setTransform(const QTransform &matrix, bool combine) return; // Update and set the new transformation. - if (!(d_ptr->flags & ItemSendsGeometryChanges)) { + if (!(d_ptr->flags & (ItemSendsGeometryChanges | ItemSendsScenePositionChanges))) { d_ptr->setTransformHelper(newTransform); + if (d_ptr->scenePosDescendants) + d_ptr->sendScenePosChange(); return; } diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 2ddccd2..30199bb 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -466,6 +466,7 @@ private slots: void doNotMarkFullUpdateIfNotInScene(); void itemDiesDuringDraggingOperation(); void QTBUG_12112_focusItem(); + void QTBUG_13473_sceneposchange(); private: QList paintedItems; @@ -11018,5 +11019,31 @@ void tst_QGraphicsItem::QTBUG_12112_focusItem() QVERIFY(item2->focusItem()); } +void tst_QGraphicsItem::QTBUG_13473_sceneposchange() +{ + ScenePosChangeTester* parent = new ScenePosChangeTester; + ScenePosChangeTester* child = new ScenePosChangeTester(parent); + + // parent's disabled ItemSendsGeometryChanges flag must not affect + // child's scene pos change notifications + parent->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); + child->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true); + + QGraphicsScene scene; + scene.addItem(parent); + + // ignore uninteresting changes + parent->clear(); + child->clear(); + + // move + parent->moveBy(1.0, 1.0); + QCOMPARE(child->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 1); + + // transform + parent->setTransform(QTransform::fromScale(0.5, 0.5)); + QCOMPARE(child->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 2); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" -- cgit v0.12