From e70fe301d919d059ad982574660149a1233a9649 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 23 Nov 2019 20:29:48 +0100 Subject: Widget autotests: replace deprecated QWidget::repaint() calls Replace QWidget::repaint() with update() + wait until the paint event is received. Task-number: QTBUG-80237 Change-Id: I57da7cd8fa119344484b849a88729bca7b48616c Reviewed-by: Richard Moe Gustavsen --- .../qgraphicsview/tst_qgraphicsview.cpp | 39 +++++++++++----------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'tests/auto/widgets/graphicsview/qgraphicsview') diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 4a33665cb9..ea89e2422b 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -358,13 +358,13 @@ void tst_QGraphicsView::renderHints() QCOMPARE(item->hints, 0); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - view.repaint(); + view.update(); QTRY_COMPARE(item->hints, view.renderHints()); view.setRenderHints(QPainter::Antialiasing); QCOMPARE(view.renderHints(), QPainter::Antialiasing); - view.repaint(); + view.update(); QTRY_COMPARE(item->hints, view.renderHints()); } @@ -2631,13 +2631,12 @@ void tst_QGraphicsView::optimizationFlags() class MessUpPainterItem : public QGraphicsRectItem { public: - MessUpPainterItem(const QRectF &rect) : QGraphicsRectItem(rect), dirtyPainter(false) - { } - - bool dirtyPainter; - + using QGraphicsRectItem::QGraphicsRectItem; + bool dirtyPainter = false; + bool receivedPaintEvent = false; void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *w) { + receivedPaintEvent = true; dirtyPainter = (painter->pen().color() != w->palette().color(w->foregroundRole())); painter->setPen(Qt::red); } @@ -2675,18 +2674,22 @@ void tst_QGraphicsView::optimizationFlags_dontSavePainterState() QGraphicsView view(&scene); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - view.viewport()->repaint(); + parent->receivedPaintEvent = false; + child->receivedPaintEvent = false; + view.viewport()->update(); + QTRY_VERIFY(parent->receivedPaintEvent); + QTRY_VERIFY(child->receivedPaintEvent); QVERIFY(!parent->dirtyPainter); QVERIFY(!child->dirtyPainter); view.setOptimizationFlags(QGraphicsView::DontSavePainterState); - view.viewport()->repaint(); + parent->receivedPaintEvent = false; + child->receivedPaintEvent = false; + view.viewport()->update(); -#ifdef Q_OS_MAC - // Repaint on OS X actually does require spinning the event loop. - QTest::qWait(100); -#endif + QTRY_VERIFY(parent->receivedPaintEvent); + QTRY_VERIFY(child->receivedPaintEvent); QVERIFY(!parent->dirtyPainter); QVERIFY(child->dirtyPainter); @@ -2753,7 +2756,7 @@ void tst_QGraphicsView::optimizationFlags_dontSavePainterState2() QVERIFY(QTest::qWaitForWindowExposed(&view)); // Make sure the view is repainted; otherwise the tests below will fail. - view.viewport()->repaint(); + view.viewport()->update(); QTRY_VERIFY(view.painted); // Make sure the painter's world transform is preserved after drawItems. @@ -4732,14 +4735,12 @@ void tst_QGraphicsView::QTBUG_5859_exposedRect() QGraphicsView view(&scene); view.scale(4.15, 4.15); view.showNormal(); - qApp->setActiveWindow(&view); + QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); - view.viewport()->repaint(10,10,20,20); - QApplication::processEvents(); - - QCOMPARE(item.lastExposedRect, scene.lastBackgroundExposedRect); + view.viewport()->update(10,10,20,20); + QTRY_COMPARE(item.lastExposedRect, scene.lastBackgroundExposedRect); } #ifndef QT_NO_CURSOR -- cgit v1.2.3