diff options
author | Tim Angus <tim@ngus.net> | 2018-03-12 10:57:10 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2018-03-13 09:42:36 +0000 |
commit | 5c7f6ee51f2678dc540e59686c49517176603087 (patch) | |
tree | 538ae1f6a3949013be6007a838f8b13d20979cd5 /src | |
parent | 1c98cb2b04ba07cda92133811c4fbfbf4637b0df (diff) |
QSFPM: Faster row removes
When the source model of a QSortFilterProxyModel has rows removed, a
mapping is performed in order to figure out which corresponding rows in
the sorted and filtered view of the model are affected. In doing so it
constructs a vector of removal intervals which are subsequently used to
emit rowsRemoved signals. In the case where many rows are removed (e.g.
all of them), many removal intervals are identified that are often
adjacent and could be simplified, which is what this patch does. i.e.
instead of emitting 3 rowsRemoved for 0-3, 4-6, 7-12, now a single
rowsRemoved is emitted for 0-12.
Change-Id: Ia503091cc4928378c88257cd8b431582e9ff454e
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/itemmodels/qsortfilterproxymodel.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index 220c6be79e..c99a06fad8 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -577,6 +577,19 @@ QVector<QPair<int, int > > QSortFilterProxyModelPrivate::proxy_intervals_for_sou proxy_intervals.append(QPair<int, int>(first_proxy_item, last_proxy_item)); } std::stable_sort(proxy_intervals.begin(), proxy_intervals.end()); + // Consolidate adjacent intervals + for (int i = proxy_intervals.size()-1; i > 0; --i) { + QPair<int, int> &interval = proxy_intervals[i]; + QPair<int, int> &preceeding_interval = proxy_intervals[i - 1]; + if (interval.first == preceeding_interval.second + 1) { + preceeding_interval.second = interval.second; + interval.first = interval.second = -1; + } + } + proxy_intervals.erase( + std::remove_if(proxy_intervals.begin(), proxy_intervals.end(), + [](QPair<int, int> &interval) { return interval.first < 0; }), + proxy_intervals.end()); return proxy_intervals; } |