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/qtreeview.cpp | |
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/qtreeview.cpp')
-rw-r--r-- | src/gui/itemviews/qtreeview.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index ccc8e00..e393902 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -1493,7 +1493,7 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, // when the row contains an index widget which has focus, // we want to paint the entire row as active bool indexWidgetHasFocus = false; - if ((current.row() == index.row()) && !d->editors.isEmpty()) { + if ((current.row() == index.row()) && !d->editorIndexHash.isEmpty()) { const int r = index.row(); QWidget *fw = QApplication::focusWidget(); for (int c = 0; c < header->count(); ++c) { @@ -2388,7 +2388,7 @@ void QTreeView::scrollContentsBy(int dx, int dy) int viewCount = d->viewport->height() / itemHeight; int maxDeltaY = qMin(d->viewItems.count(), viewCount); // no need to do a lot of work if we are going to redraw the whole thing anyway - if (qAbs(dy) > qAbs(maxDeltaY) && d->editors.isEmpty()) { + if (qAbs(dy) > qAbs(maxDeltaY) && d->editorIndexHash.isEmpty()) { verticalScrollBar()->update(); d->viewport->update(); return; @@ -2718,7 +2718,7 @@ int QTreeView::sizeHintForColumn(int column) const continue; // we have no good size hint QModelIndex index = viewItems.at(i).index; index = index.sibling(index.row(), column); - QWidget *editor = d->editorForIndex(index).editor; + QWidget *editor = d->editorForIndex(index).widget.data(); if (editor && d->persistent.contains(editor)) { w = qMax(w, editor->sizeHint().width()); int min = editor->minimumSize().width(); @@ -2782,7 +2782,7 @@ int QTreeView::indexRowSizeHint(const QModelIndex &index) const continue; QModelIndex idx = d->model->index(index.row(), logicalColumn, parent); if (idx.isValid()) { - QWidget *editor = d->editorForIndex(idx).editor; + QWidget *editor = d->editorForIndex(idx).widget.data(); if (editor && d->persistent.contains(editor)) { height = qMax(height, editor->sizeHint().height()); int min = editor->minimumSize().height(); @@ -3031,9 +3031,9 @@ QPixmap QTreeViewPrivate::renderTreeToPixmapForAnimation(const QRect &rect) cons //and now let's render the editors the editors QStyleOptionViewItemV4 option = viewOptionsV4(); - for (QList<QEditorInfo>::const_iterator it = editors.constBegin(); it != editors.constEnd(); ++it) { - QWidget *editor = it->editor; - QModelIndex index = it->index; + for (QEditorIndexHash::const_iterator it = editorIndexHash.constBegin(); it != editorIndexHash.constEnd(); ++it) { + QWidget *editor = it.key(); + const QModelIndex &index = it.value(); option.rect = q->visualRect(index); if (option.rect.isValid()) { |