From b6b0469e2d3aba2a163fab8c4b2fda4ab775b7f7 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Wed, 3 Jun 2009 17:06:24 +0200 Subject: Add BSP tree support to the recursive drawing algorithm. The code looks ugly and needs to be refactored, but at least this reintroduces the BSP so the chip demo works fine again. --- src/gui/graphicsview/qgraphicsscene.cpp | 41 +++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 96800a3..7a6c21c 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -5167,22 +5167,49 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * } // Find and sort children. - QList &children = item ? item->d_ptr->children : (topLevelItems ? *topLevelItems : this->topLevelItems); + QList tmp; + QList *children = 0; + if (item) { + children = &item->d_ptr->children; + } else if (topLevelItems) { + children = topLevelItems; + } else if (indexMethod == QGraphicsScene::NoIndex || !exposedRegion) { + children = &this->topLevelItems; + } else { + tmp = estimateItemsInRect(viewTransform.inverted().mapRect(exposedRegion->boundingRect())); + + QList tli; + for (int i = 0; i < tmp.size(); ++i) { + QGraphicsItem *it = tmp.at(i)->topLevelItem(); + if (!it->d_ptr->itemDiscovered) { + tli << it; + it->d_ptr->itemDiscovered = 1; + } + } + for (int i = 0; i < tli.size(); ++i) + tli.at(i)->d_ptr->itemDiscovered = 0; + + tmp = tli; + children = &tmp; + } + if (!dontDrawChildren) { if (item && item->d_ptr->needSortChildren) { item->d_ptr->needSortChildren = 0; - qStableSort(children.begin(), children.end(), qt_notclosestLeaf); + qStableSort(children->begin(), children->end(), qt_notclosestLeaf); } else if (!item && needSortTopLevelItems) { needSortTopLevelItems = false; - qStableSort(children.begin(), children.end(), qt_notclosestLeaf); + qStableSort(children->begin(), children->end(), qt_notclosestLeaf); + } else if (!item && children == &tmp) { + qStableSort(children->begin(), children->end(), qt_notclosestLeaf); } } // Draw children behind int i = 0; if (!dontDrawChildren) { - for (i = 0; i < children.size(); ++i) { - QGraphicsItem *child = children.at(i); + for (i = 0; i < children->size(); ++i) { + QGraphicsItem *child = children->at(i); if (wasDirtyParentSceneTransform) child->d_ptr->dirtySceneTransform = 1; if (!(child->d_ptr->flags & QGraphicsItem::ItemStacksBehindParent)) @@ -5213,8 +5240,8 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * // Draw children in front if (!dontDrawChildren) { - for (; i < children.size(); ++i) { - QGraphicsItem *child = children.at(i); + for (; i < children->size(); ++i) { + QGraphicsItem *child = children->at(i); if (wasDirtyParentSceneTransform) child->d_ptr->dirtySceneTransform = 1; drawSubtreeRecursive(child, painter, viewTransform, exposedRegion, -- cgit v0.12