diff options
author | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2010-09-22 15:52:13 (GMT) |
---|---|---|
committer | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2010-09-22 17:09:41 (GMT) |
commit | eaeaba06cea2ca0668a3c904744bab06b11077d0 (patch) | |
tree | 580421c42e0172ec5e26252aa81dc7900342d5a0 /tests/auto/qgraphicsview | |
parent | a8ddc56b1d80b16a3229286d7f0e02323c4203bc (diff) | |
download | Qt-eaeaba06cea2ca0668a3c904744bab06b11077d0.zip Qt-eaeaba06cea2ca0668a3c904744bab06b11077d0.tar.gz Qt-eaeaba06cea2ca0668a3c904744bab06b11077d0.tar.bz2 |
QPainter not restored correctly in Graphics View.
World transform and opacity was sometimes not restored correctly after
drawing items.
Auto test included.
Task-number: Discovered while working on QTBUG-12760
Diffstat (limited to 'tests/auto/qgraphicsview')
-rw-r--r-- | tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index 7b5ac7a..af02c55 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -2492,25 +2492,31 @@ void tst_QGraphicsView::optimizationFlags_dontSavePainterState() void tst_QGraphicsView::optimizationFlags_dontSavePainterState2_data() { QTest::addColumn<bool>("savePainter"); - QTest::newRow("With painter state protection") << true; - QTest::newRow("Without painter state protection") << false; + QTest::addColumn<bool>("indirectPainting"); + QTest::newRow("With painter state protection, without indirect painting") << true << false; + QTest::newRow("Without painter state protection, without indirect painting") << false << false; + QTest::newRow("With painter state protectionm, with indirect painting") << true << true; + QTest::newRow("Without painter state protection, with indirect painting") << false << true; } void tst_QGraphicsView::optimizationFlags_dontSavePainterState2() { QFETCH(bool, savePainter); + QFETCH(bool, indirectPainting); class MyScene : public QGraphicsScene { public: void drawBackground(QPainter *p, const QRectF &) - { transformInDrawBackground = p->worldTransform(); } + { transformInDrawBackground = p->worldTransform(); opacityInDrawBackground = p->opacity(); } void drawForeground(QPainter *p, const QRectF &) - { transformInDrawForeground = p->worldTransform(); } + { transformInDrawForeground = p->worldTransform(); opacityInDrawForeground = p->opacity(); } QTransform transformInDrawBackground; QTransform transformInDrawForeground; + qreal opacityInDrawBackground; + qreal opacityInDrawForeground; }; MyScene scene; @@ -2518,9 +2524,13 @@ void tst_QGraphicsView::optimizationFlags_dontSavePainterState2() scene.addRect(0, 0, 20, 20)->setTransform(QTransform::fromScale(2, 2)); scene.addRect(50, 50, 20, 20)->setTransform(QTransform::fromTranslate(200, 200)); + foreach (QGraphicsItem *item, scene.items()) + item->setOpacity(0.6); + CustomView view(&scene); if (!savePainter) view.setOptimizationFlag(QGraphicsView::DontSavePainterState); + view.setOptimizationFlag(QGraphicsView::IndirectPainting, indirectPainting); view.rotate(45); view.scale(1.5, 1.5); view.show(); @@ -2534,10 +2544,38 @@ void tst_QGraphicsView::optimizationFlags_dontSavePainterState2() QVERIFY(view.painted); // Make sure the painter's world transform is preserved after drawItems. - const QTransform expectedTransform = view.viewportTransform(); + QTransform expectedTransform = view.viewportTransform(); QVERIFY(!expectedTransform.isIdentity()); QCOMPARE(scene.transformInDrawForeground, expectedTransform); QCOMPARE(scene.transformInDrawBackground, expectedTransform); + + qreal expectedOpacity = 1.0; + QCOMPARE(scene.opacityInDrawBackground, expectedOpacity); + QCOMPARE(scene.opacityInDrawForeground, expectedOpacity); + + // Trigger more painting, this time from QGraphicsScene::render. + QImage image(scene.sceneRect().size().toSize(), QImage::Format_RGB32); + QPainter painter(&image); + scene.render(&painter); + painter.end(); + + expectedTransform = QTransform(); + QCOMPARE(scene.transformInDrawForeground, expectedTransform); + QCOMPARE(scene.transformInDrawBackground, expectedTransform); + QCOMPARE(scene.opacityInDrawBackground, expectedOpacity); + QCOMPARE(scene.opacityInDrawForeground, expectedOpacity); + + // Trigger more painting with another opacity on the painter. + painter.begin(&image); + painter.setOpacity(0.4); + expectedOpacity = 0.4; + scene.render(&painter); + painter.end(); + + QCOMPARE(scene.transformInDrawForeground, expectedTransform); + QCOMPARE(scene.transformInDrawBackground, expectedTransform); + QCOMPARE(scene.opacityInDrawBackground, expectedOpacity); + QCOMPARE(scene.opacityInDrawForeground, expectedOpacity); } class LodItem : public QGraphicsRectItem |