summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2009-05-05 15:56:43 (GMT)
committerAlexis Menard <alexis.menard@nokia.com>2009-05-05 15:56:43 (GMT)
commit7d39e871e679be8afc10c7109a5cc396ead886f7 (patch)
tree810c06e4304ee825f86f2dbd0c1c18077bc7e372
parent200afdbd684bc7b6dca96d6fccb59d4cd078a02e (diff)
downloadQt-7d39e871e679be8afc10c7109a5cc396ead886f7.zip
Qt-7d39e871e679be8afc10c7109a5cc396ead886f7.tar.gz
Qt-7d39e871e679be8afc10c7109a5cc396ead886f7.tar.bz2
Fix deletion of indexed items, and fix comments.
It was not a good idea to delete all items in the middle of the loop when clearing the scene since we change the content of indexedItems by deleting one of them. We need to store first all top level items in a temporary list and then delete them in one shot (that will delete their children as well).
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp9
-rw-r--r--tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp1
2 files changed, 5 insertions, 5 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index e9fad68..f2e5f57 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -2549,13 +2549,16 @@ void QGraphicsScene::clearSelection()
void QGraphicsScene::clear()
{
Q_D(QGraphicsScene);
+ QList<QGraphicsItem *> items;
// Recursive descent delete
for (int i = 0; i < d->index->indexedItems().size(); ++i) {
if (QGraphicsItem *item = d->index->indexedItems().at(i)) {
if (!item->parentItem())
- delete item;
+ items << item;
}
}
+ //We delete all top level items
+ qDeleteAll(items);
d->lastItemCount = 0;
d->index->clear();
d->largestUntransformableItem = QRectF();
@@ -2693,9 +2696,7 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
// Add the item to this scene
item->d_func()->scene = targetScene;
- // Indexing requires sceneBoundingRect(), but because \a item might
- // not be completely constructed at this point, we need to store it in
- // a temporary list and schedule an indexing for later.
+ // Add the item in the index
d->index->insertItem(item);
// Add to list of toplevels if this item is a toplevel.
diff --git a/tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp b/tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp
index f2a6bfd..617790c 100644
--- a/tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp
+++ b/tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp
@@ -687,7 +687,6 @@ void tst_QGraphicsLayout::ownership()
delete top;
//don't crash after that.
}
-
}
QTEST_MAIN(tst_QGraphicsLayout)