diff options
author | Ariya Hidayat <ariya.hidayat@trolltech.com> | 2009-03-18 19:41:27 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@trolltech.com> | 2009-04-07 18:24:30 (GMT) |
commit | f4c03e0eec3b39145471f25d0a1cdcdba604790c (patch) | |
tree | 4bd24bc57f5497538cf9e73bf0df7bddfc8631d5 | |
parent | 980e01d69a29e2710a954e2bcd47d78039c76dbd (diff) | |
download | Qt-f4c03e0eec3b39145471f25d0a1cdcdba604790c.zip Qt-f4c03e0eec3b39145471f25d0a1cdcdba604790c.tar.gz Qt-f4c03e0eec3b39145471f25d0a1cdcdba604790c.tar.bz2 |
Fixes: Recreate the index properly when switching the index method.
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 4b40d3b..f8f8e98 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -2372,6 +2372,17 @@ QGraphicsScene::ItemIndexMethod QGraphicsScene::itemIndexMethod() const Q_D(const QGraphicsScene); return d->indexMethod; } + +// Possibilities +// NoIndex -> CustomIndex : warning +// BspTreeIndex -> CustomIndex : warning +// CustomIndex -> CustomIndex : warning +// NoIndex -> BspTreeIndex : create an empty BSP if necessary +// BspTreeIndex -> BspTreeIndex : nothing +// CustomIndex -> BspTreeIndex : create BSP and transfer items +// NoIndex -> NoIndex : nothing +// BspTreeIndex -> NoIndex : nothing +// CustomIndex -> NoIndex : create BSP tree but do not populate void QGraphicsScene::setItemIndexMethod(ItemIndexMethod method) { Q_D(QGraphicsScene); @@ -2383,11 +2394,25 @@ void QGraphicsScene::setItemIndexMethod(ItemIndexMethod method) return; } d->resetIndex(); - if (method == BspTreeIndex) { - delete d->index; + + if (d->indexMethod == NoIndex && method == BspTreeIndex) { + QGraphicsSceneBspTree *tree = qobject_cast<QGraphicsSceneBspTree*>(d->index); + if (!tree) { + delete d->index; + d->index = new QGraphicsSceneBspTree(this); + } + } + + if (d->indexMethod == CustomIndex && method == BspTreeIndex) { + QGraphicsSceneIndex *oldIndex = d->index; d->index = new QGraphicsSceneBspTree(this); - // ### FIXME: transfer the items + d->index->insertItems(oldIndex->items(oldIndex->rect())); } + + if (d->indexMethod == CustomIndex && method == NoIndex) { + d->index = new QGraphicsSceneBspTree(this); + } + d->indexMethod = method; } |