diff options
author | Stephen Bowline <sbowline@ilm.com> | 2010-08-16 21:38:11 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-08-27 12:37:43 (GMT) |
commit | d34287af6fc1c7558e8ed15dbb29c0e6b58b7b00 (patch) | |
tree | 67968ca82cb7be560bb61e1ddd38f1958d5483d2 /src/gui/itemviews/qabstractitemview_p.h | |
parent | 708978d1c18cf938a4e0c29a5a90be5de4e82140 (diff) | |
download | Qt-d34287af6fc1c7558e8ed15dbb29c0e6b58b7b00.zip Qt-d34287af6fc1c7558e8ed15dbb29c0e6b58b7b00.tar.gz Qt-d34287af6fc1c7558e8ed15dbb29c0e6b58b7b00.tar.bz2 |
QAbstractItemView: optimize handling of editors for view with large numbers of editors.
This change improves algorithmic time complexity for item views during
operations which directly (or indirectly such as layout) require
bi-directional lookups between model indices and persistent editor widgets.
The previous implementation scaled as O(n^2) due to the unordered search
through a QVector.
Implementations that use large numbers of persistent editors are most
dramatically improved. In one "real world" test case with 648 persistent
editors, profiling indicates an improvement of layout from 45 seconds
to 8 seconds with this change alone.
Reviewed-by: Olivier Goffart
Merge-Request: 2452
Diffstat (limited to 'src/gui/itemviews/qabstractitemview_p.h')
-rw-r--r-- | src/gui/itemviews/qabstractitemview_p.h | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/gui/itemviews/qabstractitemview_p.h b/src/gui/itemviews/qabstractitemview_p.h index 969553a..03b413a 100644 --- a/src/gui/itemviews/qabstractitemview_p.h +++ b/src/gui/itemviews/qabstractitemview_p.h @@ -70,22 +70,18 @@ QT_BEGIN_NAMESPACE -struct QEditorInfo -{ - QEditorInfo() : isStatic(false) - { - } - - QEditorInfo(const QPersistentModelIndex &i, QWidget *e, bool b) : index(i), editor(e), isStatic(b) - { - } - - QPersistentModelIndex index; - QPointer<QWidget> editor; - bool isStatic; //true when called from setIndexWidget +struct QEditorInfo { + QEditorInfo(QWidget *e, bool s): widget(QWeakPointer<QWidget>(e)), isStatic(s) {} + QEditorInfo(): isStatic(false) {} + QWeakPointer<QWidget> widget; + bool isStatic; }; +// Fast associativity between Persistent editors and indices. +typedef QHash<QWidget *, QPersistentModelIndex> QEditorIndexHash; +typedef QHash<QPersistentModelIndex, QEditorInfo> QIndexEditorHash; + typedef QPair<QRect, QModelIndex> QItemViewPaintPair; typedef QList<QItemViewPaintPair> QItemViewPaintPairs; @@ -248,9 +244,9 @@ public: : q->horizontalOffset(), q->verticalOffset()); } - QEditorInfo editorForIndex(const QModelIndex &index) const; + const QEditorInfo &editorForIndex(const QModelIndex &index) const; inline bool hasEditor(const QModelIndex &index) const { - return editorForIndex(index).editor != 0; + return indexEditorHash.find(index) != indexEditorHash.constEnd(); } QModelIndex indexForEditor(QWidget *editor) const; @@ -353,7 +349,8 @@ public: QAbstractItemView::SelectionMode selectionMode; QAbstractItemView::SelectionBehavior selectionBehavior; - QList<QEditorInfo> editors; + QEditorIndexHash editorIndexHash; + QIndexEditorHash indexEditorHash; QSet<QWidget*> persistent; QWidget *currentlyCommittingEditor; |