summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-11-02 17:01:13 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-11-02 17:01:13 (GMT)
commit20cfe1e790295254370cf472df39813f864de7ea (patch)
tree98ac008f7c468ed37a61c051870810db2bbf2360 /tests/auto/qgraphicsview/tst_qgraphicsview.cpp
parent83e497fdae56e11c79d913cdc665e78615291e9c (diff)
parent2ed925753cb194970712330edca4da8e91fa8f28 (diff)
downloadQt-20cfe1e790295254370cf472df39813f864de7ea.zip
Qt-20cfe1e790295254370cf472df39813f864de7ea.tar.gz
Qt-20cfe1e790295254370cf472df39813f864de7ea.tar.bz2
Merge remote branch 'mainline/4.6' into 4.6
Diffstat (limited to 'tests/auto/qgraphicsview/tst_qgraphicsview.cpp')
-rw-r--r--tests/auto/qgraphicsview/tst_qgraphicsview.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
index 9b5e114..f07453c 100644
--- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
@@ -194,6 +194,8 @@ private slots:
void acceptDrops();
void optimizationFlags();
void optimizationFlags_dontSavePainterState();
+ void optimizationFlags_dontSavePainterState2_data();
+ void optimizationFlags_dontSavePainterState2();
void levelOfDetail_data();
void levelOfDetail();
void scrollBarRanges_data();
@@ -2455,6 +2457,57 @@ void tst_QGraphicsView::optimizationFlags_dontSavePainterState()
QTest::qWaitForWindowShown(&painter2);
}
+void tst_QGraphicsView::optimizationFlags_dontSavePainterState2_data()
+{
+ QTest::addColumn<bool>("savePainter");
+ QTest::newRow("With painter state protection") << true;
+ QTest::newRow("Without painter state protection") << false;
+}
+
+void tst_QGraphicsView::optimizationFlags_dontSavePainterState2()
+{
+ QFETCH(bool, savePainter);
+
+ class MyScene : public QGraphicsScene
+ {
+ public:
+ void drawBackground(QPainter *p, const QRectF &)
+ { transformInDrawBackground = p->worldTransform(); }
+
+ void drawForeground(QPainter *p, const QRectF &)
+ { transformInDrawForeground = p->worldTransform(); }
+
+ QTransform transformInDrawBackground;
+ QTransform transformInDrawForeground;
+ };
+
+ MyScene scene;
+ // Add transformed dummy items to make sure the painter's worldTransform() is changed in drawItems.
+ scene.addRect(0, 0, 20, 20)->setTransform(QTransform::fromScale(2, 2));
+ scene.addRect(50, 50, 20, 20)->setTransform(QTransform::fromTranslate(200, 200));
+
+ CustomView view(&scene);
+ if (!savePainter)
+ view.setOptimizationFlag(QGraphicsView::DontSavePainterState);
+ view.rotate(45);
+ view.scale(1.5, 1.5);
+ view.show();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&view);
+#endif
+
+ // Make sure the view is repainted; otherwise the tests below will fail.
+ view.viewport()->repaint();
+ QTest::qWait(200);
+ QVERIFY(view.painted);
+
+ // Make sure the painter's world transform is preserved after drawItems.
+ const QTransform expectedTransform = view.viewportTransform();
+ QVERIFY(!expectedTransform.isIdentity());
+ QCOMPARE(scene.transformInDrawForeground, expectedTransform);
+ QCOMPARE(scene.transformInDrawBackground, expectedTransform);
+}
+
class LodItem : public QGraphicsRectItem
{
public: