diff options
author | Yoann Lopes <yoann.lopes@nokia.com> | 2010-03-25 13:27:56 (GMT) |
---|---|---|
committer | Yoann Lopes <yoann.lopes@nokia.com> | 2010-03-25 13:33:11 (GMT) |
commit | 96ac1964b827ef01ef2edb6411ecb7540ed76ce2 (patch) | |
tree | 775fadd51dbb921fab0f654ed5ab73cd9d4058f0 /tests/auto/qgraphicsitem | |
parent | c84d5afab9b61ae3f955de48a75c8dfd26528a36 (diff) | |
download | Qt-96ac1964b827ef01ef2edb6411ecb7540ed76ce2.zip Qt-96ac1964b827ef01ef2edb6411ecb7540ed76ce2.tar.gz Qt-96ac1964b827ef01ef2edb6411ecb7540ed76ce2.tar.bz2 |
Prevents a useless repaint with QGraphicsItem cache mode.
No repaint is triggered anymore when setting the cache mode to
DeviceCoordinateMode when already using that mode.
Also added an autotest for checking repaints when setting cache modes.
Task-number: QTBUG-9391
Reviewed-by: ahanssen
Diffstat (limited to 'tests/auto/qgraphicsitem')
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 75fb337..2b507cb 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -384,6 +384,7 @@ private slots: void tabChangesFocus(); void tabChangesFocus_data(); void cacheMode(); + void cacheMode2(); void updateCachedItemAfterMove(); void deviceTransform_data(); void deviceTransform(); @@ -6926,6 +6927,78 @@ void tst_QGraphicsItem::cacheMode() QCOMPARE(testerChild2->repaints, 6); } +void tst_QGraphicsItem::cacheMode2() +{ + QGraphicsScene scene(0, 0, 100, 100); + QGraphicsView view(&scene); + view.resize(150, 150); + view.show(); + QApplication::setActiveWindow(&view); + QTest::qWaitForWindowShown(&view); + + // Increase the probability of window activation + // not causing another repaint of test items. + QTest::qWait(50); + + EventTester *tester = new EventTester; + scene.addItem(tester); + QTest::qWait(10); + QTRY_COMPARE(tester->repaints, 1); + + // Switching from NoCache to NoCache (no repaint) + tester->setCacheMode(QGraphicsItem::NoCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 1); + + // Switching from NoCache to DeviceCoordinateCache (no repaint) + tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 1); + + // Switching from DeviceCoordinateCache to DeviceCoordinateCache (no repaint) + tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 1); + + // Switching from DeviceCoordinateCache to NoCache (no repaint) + tester->setCacheMode(QGraphicsItem::NoCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 1); + + // Switching from NoCache to ItemCoordinateCache (repaint) + tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 2); + + // Switching from ItemCoordinateCache to ItemCoordinateCache (no repaint) + tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 2); + + // Switching from ItemCoordinateCache to ItemCoordinateCache with different size (repaint) + tester->setCacheMode(QGraphicsItem::ItemCoordinateCache, QSize(100, 100)); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 3); + + // Switching from ItemCoordinateCache to NoCache (repaint) + tester->setCacheMode(QGraphicsItem::NoCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 4); + + // Switching from DeviceCoordinateCache to ItemCoordinateCache (repaint) + tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 4); + tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 5); + + // Switching from ItemCoordinateCache to DeviceCoordinateCache (repaint) + tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 6); +} + void tst_QGraphicsItem::updateCachedItemAfterMove() { // A simple item that uses ItemCoordinateCache |