From dda8a57c085216db609f822837c50bae38006b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 3 Feb 2010 19:39:17 +0100 Subject: QGraphicsWidget is painted twice on the first show. We want to discard all update requests when we there's a full update pending. The problem was that 'updateAll' was reset too early causing update requests to fall through. To prevent this from happening we reset 'updateAll' right before the items are actually painted. Auto-test included. Task-number: QTBUG-6956 --- src/gui/graphicsview/qgraphicsscene.cpp | 7 +++++- tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 27 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 4bfe9ad..66707fc 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -373,7 +373,10 @@ void QGraphicsScenePrivate::_q_emitUpdated() } } } else { - updateAll = false; + if (views.isEmpty()) { + updateAll = false; + return; + } for (int i = 0; i < views.size(); ++i) views.at(i)->d_func()->processPendingUpdates(); // It's important that we update all views before we dispatch, hence two for-loops. @@ -4604,6 +4607,7 @@ void QGraphicsScenePrivate::drawItems(QPainter *painter, const QTransform *const if (!unpolishedItems.isEmpty()) _q_polishItems(); + updateAll = false; QRectF exposedSceneRect; if (exposedRegion && indexMethod != QGraphicsScene::NoIndex) { exposedSceneRect = exposedRegion->boundingRect().adjusted(-1, -1, 1, 1); @@ -5166,6 +5170,7 @@ void QGraphicsScene::drawItems(QPainter *painter, if (!d->unpolishedItems.isEmpty()) d->_q_polishItems(); + d->updateAll = false; QTransform viewTransform = painter->worldTransform(); Q_UNUSED(options); diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index d3132fe..526486e 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -164,6 +164,7 @@ private slots: void polishEvent(); void polishEvent2(); void initialShow(); + void initialShow2(); // Task fixes void task236127_bspTreeIndexFails(); @@ -2881,6 +2882,32 @@ void tst_QGraphicsWidget::initialShow() QCOMPARE(widget->repaints, 1); } +void tst_QGraphicsWidget::initialShow2() +{ + class MyGraphicsWidget : public QGraphicsWidget + { public: + MyGraphicsWidget() : repaints(0) {} + int repaints; + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) { ++repaints; } + void polishEvent() { update(); } + }; + + MyGraphicsWidget *widget = new MyGraphicsWidget; + widget->resize(100, 100); + + QGraphicsScene scene(0, 0, 200, 200); + scene.addItem(widget); + + QGraphicsView view(&scene); + view.show(); + // Not using QTest::qWaitForWindowShown(&view); on purpose, because there's + // a bug in qt_x11_wait_for_window_manager that prevents this test + // to pass. Denis is looking into it. + QTest::qWait(300); + + QCOMPARE(widget->repaints, 1); +} + void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() { QGraphicsScene scene; -- cgit v0.12