summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitar Asenov <dimitar.asenov@gmail.com>2014-09-03 14:43:25 +0200
committerDimitar Asenov <dimitar.asenov@gmail.com>2014-09-03 16:11:41 +0200
commited418f91d525ccf43362d2bf04fe117d7ebb5570 (patch)
tree0ed6211946f42471adbfb17c413141d456037514
parentf750979b70400e8681204b30282473aa6353ea06 (diff)
Revert "Speed up the removal of items from a QGraphicsScene"
This reverts commit bf2ec0183cb62034f2a4e700b7ab741371fcb106. That patch changed the way the linear index works in QGraphicsScene in order to speed up item removal. That patch occasionally rebuilt the index by recursively exploring all items in the scene, starting with the top level. Further testing revealved that in some circumstances, rebuilding the index in this way can be slow, thereby significantly slowing down the index compared to the unpatched version. The original patch only exists in the qt 5.4 branch and has not been released. Change-Id: I081dbcdcc86196ef382466c3e800a33eab9a5b79 Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>
-rw-r--r--src/widgets/graphicsview/qgraphicsscene.h1
-rw-r--r--src/widgets/graphicsview/qgraphicsscenelinearindex_p.h45
2 files changed, 7 insertions, 39 deletions
diff --git a/src/widgets/graphicsview/qgraphicsscene.h b/src/widgets/graphicsview/qgraphicsscene.h
index d95237baef..ba47d45d63 100644
--- a/src/widgets/graphicsview/qgraphicsscene.h
+++ b/src/widgets/graphicsview/qgraphicsscene.h
@@ -313,7 +313,6 @@ private:
friend class QGraphicsEffect;
friend class QGraphicsSceneIndex;
friend class QGraphicsSceneIndexPrivate;
- friend class QGraphicsSceneLinearIndex;
friend class QGraphicsSceneBspTreeIndex;
friend class QGraphicsSceneBspTreeIndexPrivate;
friend class QGraphicsItemEffectSourcePrivate;
diff --git a/src/widgets/graphicsview/qgraphicsscenelinearindex_p.h b/src/widgets/graphicsview/qgraphicsscenelinearindex_p.h
index baf3de3755..7debcfb501 100644
--- a/src/widgets/graphicsview/qgraphicsscenelinearindex_p.h
+++ b/src/widgets/graphicsview/qgraphicsscenelinearindex_p.h
@@ -70,62 +70,31 @@ class Q_AUTOTEST_EXPORT QGraphicsSceneLinearIndex : public QGraphicsSceneIndex
Q_OBJECT
public:
- QGraphicsSceneLinearIndex(QGraphicsScene *scene = 0) : QGraphicsSceneIndex(scene), m_itemsIsValid(true)
+ QGraphicsSceneLinearIndex(QGraphicsScene *scene = 0) : QGraphicsSceneIndex(scene)
{ }
QList<QGraphicsItem *> items(Qt::SortOrder order = Qt::DescendingOrder) const
- {
- Q_UNUSED(order);
- return validList();
- }
+ { Q_UNUSED(order); return m_items; }
virtual QList<QGraphicsItem *> estimateItems(const QRectF &rect, Qt::SortOrder order) const
{
Q_UNUSED(rect);
Q_UNUSED(order);
- return validList();
+ return m_items;
}
protected :
virtual void clear()
- {
- m_items.clear();
- m_itemsIsValid = true;
- }
+ { m_items.clear(); }
virtual void addItem(QGraphicsItem *item)
- {
- if (m_itemsIsValid)
- m_items << item;
- }
+ { m_items << item; }
virtual void removeItem(QGraphicsItem *item)
- {
- Q_UNUSED(item);
- m_itemsIsValid = false;
- }
+ { m_items.removeOne(item); }
private:
- mutable QList<QGraphicsItem*> m_items;
- mutable bool m_itemsIsValid;
-
- QList<QGraphicsItem*>& validList() const
- {
- if (!m_itemsIsValid)
- {
- m_items.clear();
-
- QList<QGraphicsItem*> stack = scene()->d_func()->topLevelItems;
- m_items << stack;
- while (!stack.isEmpty())
- {
- m_items << stack.last()->childItems();
- stack << stack.takeLast()->childItems();
- }
- m_itemsIsValid = true;
- }
- return m_items;
- }
+ QList<QGraphicsItem*> m_items;
};
#endif // QT_NO_GRAPHICSVIEW