diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2009-09-15 07:22:11 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2009-09-15 07:27:41 (GMT) |
commit | e37f8ef98f1c4fe4a45b4579a294e17734d7dff6 (patch) | |
tree | 315295e82508d49f881f9328abf75b1a91253f9c /tests | |
parent | afd7ba59f1fd9f14c4b7cd85aba764ef6066d64e (diff) | |
download | Qt-e37f8ef98f1c4fe4a45b4579a294e17734d7dff6.zip Qt-e37f8ef98f1c4fe4a45b4579a294e17734d7dff6.tar.gz Qt-e37f8ef98f1c4fe4a45b4579a294e17734d7dff6.tar.bz2 |
Fix update issues in QGraphicsView.
The bug appeared only when calling collidingItems right after setPos.
When calling setPos on a parent the sceneTransform is mark as dirty, so
when we paint the parent and its children if the scene transform of the
parent was dirty then we update all children sceneTransform. In our
case here, collidingItems call ensureTransform on one of the children
which go recursively to the top most dirty item and update the
sceneTransform. The problem is that all sibling children are not mark
their sceneTransform dirty so next paint will skip them (since the parent
is not dirty anymore).
Task-number:260711
Reviewed-by:bnilsen
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 5e8f4c4..c2acac9 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -293,6 +293,7 @@ private slots: void setActivePanelOnInactiveScene(); void activationOnShowHide(); void moveWhileDeleting(); + void ensureDirtySceneTransform(); // task specific tests below me void task141694_textItemEnsureVisible(); @@ -8156,5 +8157,90 @@ void tst_QGraphicsItem::moveWhileDeleting() delete rect; } +class MyRectItem : public QGraphicsWidget +{ + Q_OBJECT +public: + MyRectItem(QGraphicsItem *parent = 0) : QGraphicsWidget(parent) + { + + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + { + painter->setBrush(brush); + painter->drawRect(boundingRect()); + } + +public slots : + void move() + { + setPos(-100,-100); + topLevel->collidingItems(Qt::IntersectsItemBoundingRect); + } +public: + QGraphicsItem *topLevel; + QBrush brush; +}; + + +void tst_QGraphicsItem::ensureDirtySceneTransform() +{ + QGraphicsScene scene; + + MyRectItem *topLevel = new MyRectItem; + topLevel->setGeometry(0, 0, 100, 100); + topLevel->setPos(-50, -50); + topLevel->brush = QBrush(QColor(Qt::black)); + scene.addItem(topLevel); + + MyRectItem *parent = new MyRectItem; + parent->topLevel = topLevel; + parent->setGeometry(0, 0, 100, 100); + parent->setPos(0, 0); + parent->brush = QBrush(QColor(Qt::magenta)); + parent->setObjectName("parent"); + scene.addItem(parent); + + MyRectItem *child = new MyRectItem(parent); + child->setGeometry(0, 0, 80, 80); + child->setPos(10, 10); + child->setObjectName("child"); + child->brush = QBrush(QColor(Qt::blue)); + + MyRectItem *child2 = new MyRectItem(parent); + child2->setGeometry(0, 0, 80, 80); + child2->setPos(15, 15); + child2->setObjectName("child2"); + child2->brush = QBrush(QColor(Qt::green)); + + MyRectItem *child3 = new MyRectItem(parent); + child3->setGeometry(0, 0, 80, 80); + child3->setPos(20, 20); + child3->setObjectName("child3"); + child3->brush = QBrush(QColor(Qt::gray)); + + QGraphicsView view(&scene); + view.show(); + QTest::qWait(500); + + //We move the parent + parent->move(); + QTest::qWait(500); + + //We check if all items moved + QCOMPARE(child->pos(), QPointF(10, 10)); + QCOMPARE(child2->pos(), QPointF(15, 15)); + QCOMPARE(child3->pos(), QPointF(20, 20)); + + QCOMPARE(child->sceneBoundingRect(), QRectF(-90, -90, 80, 80)); + QCOMPARE(child2->sceneBoundingRect(), QRectF(-85, -85, 80, 80)); + QCOMPARE(child3->sceneBoundingRect(), QRectF(-80, -80, 80, 80)); + + QCOMPARE(child->sceneTransform(), QTransform::fromTranslate(-90, -90)); + QCOMPARE(child2->sceneTransform(), QTransform::fromTranslate(-85, -85)); + QCOMPARE(child3->sceneTransform(), QTransform::fromTranslate(-80, -80)); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" |