diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2010-06-16 09:00:15 (GMT) |
---|---|---|
committer | Qt Commercial Integration <QtCommercial@digia.com> | 2012-01-31 10:25:00 (GMT) |
commit | 9d465dd8333bd74f6f8976b76d1c4ccf95ae1586 (patch) | |
tree | 192350cdf4b5e2169b4c72d89f04ea85e78e69ba | |
parent | 6a6fcd8c8b6cdbfd35730b0d30d59bbfdb45ace5 (diff) | |
download | Qt-9d465dd8333bd74f6f8976b76d1c4ccf95ae1586.zip Qt-9d465dd8333bd74f6f8976b76d1c4ccf95ae1586.tar.gz Qt-9d465dd8333bd74f6f8976b76d1c4ccf95ae1586.tar.bz2 |
QListView: speedup QListView::setRowHidden()
Basically the same optimisation that had been made long ago in the tree view:
Use the right data structure for QListViewPrivate::hiddenRows
(QSet instead of QVector)
Task-number: QTBUG-11438
Reviewed-by: Gabriel
-rw-r--r-- | src/gui/itemviews/qlistview.cpp | 13 | ||||
-rw-r--r-- | src/gui/itemviews/qlistview_p.h | 7 |
2 files changed, 13 insertions, 7 deletions
diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp index e64bebe..bdcc53b 100644 --- a/src/gui/itemviews/qlistview.cpp +++ b/src/gui/itemviews/qlistview.cpp @@ -756,10 +756,13 @@ void QListView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int e // if the parent is above d->root in the tree, nothing will happen QAbstractItemView::rowsAboutToBeRemoved(parent, start, end); if (parent == d->root) { - for (int i = d->hiddenRows.count() - 1; i >= 0; --i) { - int hiddenRow = d->hiddenRows.at(i).row(); + QSet<QPersistentModelIndex>::iterator it = d->hiddenRows.begin(); + while (it != d->hiddenRows.end()) { + int hiddenRow = it->row(); if (hiddenRow >= start && hiddenRow <= end) { - d->hiddenRows.remove(i); + it = d->hiddenRows.erase(it); + } else { + ++it; } } } @@ -1842,12 +1845,12 @@ QAbstractItemView::DropIndicatorPosition QListViewPrivate::position(const QPoint void QCommonListViewBase::appendHiddenRow(int row) { - dd->hiddenRows.append(dd->model->index(row, 0, qq->rootIndex())); + dd->hiddenRows.insert(dd->model->index(row, 0, qq->rootIndex())); } void QCommonListViewBase::removeHiddenRow(int row) { - dd->hiddenRows.remove(dd->hiddenRows.indexOf(dd->model->index(row, 0, qq->rootIndex()))); + dd->hiddenRows.remove(dd->model->index(row, 0, qq->rootIndex())); } void QCommonListViewBase::updateHorizontalScrollBar(const QSize &step) diff --git a/src/gui/itemviews/qlistview_p.h b/src/gui/itemviews/qlistview_p.h index 6b4a65d..4587967 100644 --- a/src/gui/itemviews/qlistview_p.h +++ b/src/gui/itemviews/qlistview_p.h @@ -376,7 +376,10 @@ public: inline bool isSelectionRectVisible() const { return showElasticBand; } inline QModelIndex modelIndex(int row) const { return model->index(row, column, root); } - inline bool isHidden(int row) const { return hiddenRows.contains(model->index(row, 0, root)); } + inline bool isHidden(int row) const { + QModelIndex idx = model->index(row, 0, root); + return isPersistent(idx) && hiddenRows.contains(idx); + } inline bool isHiddenOrDisabled(int row) const { return isHidden(row) || !isIndexEnabled(modelIndex(row)); } inline void removeCurrentAndDisabled(QVector<QModelIndex> *indexes, const QModelIndex ¤t) const { @@ -430,7 +433,7 @@ public: QBasicTimer batchLayoutTimer; // used for hidden items - QVector<QPersistentModelIndex> hiddenRows; + QSet<QPersistentModelIndex> hiddenRows; int column; bool uniformItemSizes; |