diff options
author | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2009-07-02 12:59:51 (GMT) |
---|---|---|
committer | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2009-07-02 12:59:51 (GMT) |
commit | c4ae87721e011fe44f301c4039f0651a05394162 (patch) | |
tree | c5e35a6360a7b93463ae627a8781a3b0ad138499 /src/gui/graphicsview/qgraphicsitem.cpp | |
parent | 6d71de4283c05b1b42ef26fe4c23334ad34c8a54 (diff) | |
download | Qt-c4ae87721e011fe44f301c4039f0651a05394162.zip Qt-c4ae87721e011fe44f301c4039f0651a05394162.tar.gz Qt-c4ae87721e011fe44f301c4039f0651a05394162.tar.bz2 |
Speedup item-lookup in Graphics View.
We don't have to do a stable sort anymore because the lessThan operator
now accounts for the insertion order. This also means we don't have to
sort all top-level items to preserve the insertion order in
QGraphicsScenePrivate::topLevelItemsInStackingOrder.
Reviewed-by: Andreas
Diffstat (limited to 'src/gui/graphicsview/qgraphicsitem.cpp')
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 002eab9..9a27ef5 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -4310,6 +4310,7 @@ void QGraphicsItemPrivate::resolveDepth(int parentDepth) void QGraphicsItemPrivate::addChild(QGraphicsItem *child) { needSortChildren = 1; + child->d_ptr->siblingIndex = children.size(); children.append(child); } @@ -4319,6 +4320,10 @@ void QGraphicsItemPrivate::addChild(QGraphicsItem *child) void QGraphicsItemPrivate::removeChild(QGraphicsItem *child) { children.removeOne(child); + // NB! Do not use children.removeAt(child->d_ptr->siblingIndex) because + // the child is not guaranteed to be at the index after the list is sorted. + // (see ensureSortedChildren()). + child->d_ptr->siblingIndex = -1; } /*! |