Revert "Speed up the removal of items from a QGraphicsScene"

This reverts commit bf2ec0183c.

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>
bb10
Dimitar Asenov 2014-09-03 14:43:25 +02:00
parent f750979b70
commit ed418f91d5
2 changed files with 7 additions and 39 deletions

View File

@ -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;

View File

@ -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