summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-04-21 15:57:05 +0200
committerJason McDonald <jason.mcdonald@nokia.com>2009-04-22 09:17:07 +1000
commit386eee20daaf77fd3b0a2c4c33de00083d538c65 (patch)
tree9e90acc5d5caa0a4d8650b4b6f36faf369c15123
parent830751ef09d7605ce3152ffe507c98aa92ca47a2 (diff)
BT: Fix update regression for cached QGraphicsItem (Elastic Nodes stuck)
This fixes a bug in 4.5.0 where cached items that call update() after they have been moved or transformed failed to get a call to paint(), so the last cache image was used to draw. The easiest way to reproduce this bug is in the Elastic Nodes example. If you press, wait, then release, the nodes will consistently move to sunken state, then back to normal state. But if you click quickly while moving the mouse, the nodes will stay sunken. The bug was that the item was marked as dirty as a result of being moved, and when the mouse button was released, the node item's call to update() was discarded, as the item was "already dirty". The fix is to allow invalidation of the cache even if the item is marked as dirty. Reviewed-by: bnilsen (cherry picked from commit 08feb22f9a924ce120da8b5c6e1669d2a630dd54)
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp14
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp42
2 files changed, 55 insertions, 1 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index de4332c1a7..d02052d071 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -3950,17 +3950,29 @@ bool QGraphicsItemPrivate::isProxyWidget() const
*/
void QGraphicsItem::update(const QRectF &rect)
{
- if ((rect.isEmpty() && !rect.isNull()) || d_ptr->discardUpdateRequest())
+ if (rect.isEmpty() && !rect.isNull())
return;
if (CacheMode(d_ptr->cacheMode) != NoCache) {
QGraphicsItemCache *cache = d_ptr->extraItemCache();
+ if (d_ptr->discardUpdateRequest(/* ignoreVisibleBit = */ false,
+ /* ignoreClipping = */ false,
+ /* ignoreDirtyBit = */ true)) {
+ return;
+ }
+
+ // Invalidate cache.
if (rect.isNull()) {
cache->allExposed = true;
cache->exposed.clear();
} else {
cache->exposed.append(rect);
}
+ // Only invalidate cache; item is already dirty.
+ if (d_ptr->dirty)
+ return;
+ } else if (d_ptr->discardUpdateRequest()) {
+ return;
}
// Effectively the same as updateHelper(rect);
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index 2d221f968a..0f7c827673 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -218,6 +218,7 @@ private slots:
void tabChangesFocus();
void tabChangesFocus_data();
void cacheMode();
+ void updateCachedItemAfterMove();
// task specific tests below me
void task141694_textItemEnsureVisible();
@@ -6077,6 +6078,47 @@ void tst_QGraphicsItem::cacheMode()
QCOMPARE(testerChild2->repaints, 6);
}
+void tst_QGraphicsItem::updateCachedItemAfterMove()
+{
+ // A simple item that uses ItemCoordinateCache
+ EventTester *tester = new EventTester;
+ tester->setCacheMode(QGraphicsItem::ItemCoordinateCache);
+
+ // Add to a scene, show in a view, ensure it's painted and reset its
+ // repaint counter.
+ QGraphicsScene scene;
+ scene.addItem(tester);
+ QGraphicsView view(&scene);
+ view.show();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&view);
+#endif
+ QTest::qWait(125);
+ tester->repaints = 0;
+
+ // Move the item, should not cause repaints
+ tester->setPos(10, 0);
+ QTest::qWait(125);
+ QCOMPARE(tester->repaints, 0);
+
+ // Move then update, should cause one repaint
+ tester->setPos(20, 0);
+ tester->update();
+ QTest::qWait(125);
+ QCOMPARE(tester->repaints, 1);
+
+ // Hiding the item doesn't cause a repaint
+ tester->hide();
+ QTest::qWait(125);
+ QCOMPARE(tester->repaints, 1);
+
+ // Moving a hidden item doesn't cause a repaint
+ tester->setPos(30, 0);
+ tester->update();
+ QTest::qWait(125);
+ QCOMPARE(tester->repaints, 1);
+}
+
QTEST_MAIN(tst_QGraphicsItem)
#include "tst_qgraphicsitem.moc"
#endif