From 862236dc7cdff27305c4a3ade9c802eafce03c80 Mon Sep 17 00:00:00 2001 From: Bjoern Erik Nilsen Date: Wed, 15 Jul 2009 18:04:23 +0200 Subject: QGraphicsItems not painted after QGraphicsScene::clear(). The problem was that we didn't regenerate the bsp when adding items after calling QGraphicsScene::clear. Reviewed-by: alexis --- .../graphicsview/qgraphicsscenebsptreeindex.cpp | 1 + .../tst_qgraphicssceneindex.cpp | 34 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp b/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp index a54ade9..110e892 100644 --- a/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp +++ b/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp @@ -542,6 +542,7 @@ void QGraphicsSceneBspTreeIndex::clear() d->indexedItems.clear(); d->unindexedItems.clear(); d->untransformableItems.clear(); + d->regenerateIndex = true; } /*! diff --git a/tests/auto/qgraphicssceneindex/tst_qgraphicssceneindex.cpp b/tests/auto/qgraphicssceneindex/tst_qgraphicssceneindex.cpp index 3ce5b16..7a00e60 100644 --- a/tests/auto/qgraphicssceneindex/tst_qgraphicssceneindex.cpp +++ b/tests/auto/qgraphicssceneindex/tst_qgraphicssceneindex.cpp @@ -66,6 +66,7 @@ private slots: void movingItems(); void connectedToSceneRectChanged(); void items(); + void clear(); private: void common_data(); @@ -267,5 +268,38 @@ void tst_QGraphicsSceneIndex::items() QCOMPARE(scene.items().size(), 3); } +void tst_QGraphicsSceneIndex::clear() +{ + class MyItem : public QGraphicsItem + { + public: + MyItem(QGraphicsItem *parent = 0) : QGraphicsItem(parent), numPaints(0) {} + int numPaints; + protected: + QRectF boundingRect() const { return QRectF(0, 0, 10, 10); } + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + { ++numPaints; } + }; + + QGraphicsScene scene; + scene.setSceneRect(0, 0, 100, 100); + scene.addItem(new MyItem); + + QGraphicsView view(&scene); + view.show(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&view); +#endif + QTest::qWait(250); + scene.clear(); + + // Make sure the index is re-generated after QGraphicsScene::clear(); + // otherwise no items will be painted. + MyItem *item = new MyItem; + scene.addItem(item); + qApp->processEvents(); + QCOMPARE(item->numPaints, 1); +} + QTEST_MAIN(tst_QGraphicsSceneIndex) #include "tst_qgraphicssceneindex.moc" -- cgit v0.12