summaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-26 21:21:44 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-04-26 13:54:59 -0700
commit6e83135fba49680fe1e951d19d6bc6690328c5d8 (patch)
treee5ea44ebffd77018b2959d8554d89321aab8f3f1 /desktop-widgets
parent4f438d1e32a8a690c77f7eba8f80711e35e85df5 (diff)
downloadsubsurface-6e83135fba49680fe1e951d19d6bc6690328c5d8.tar.gz
desktop: select dives at once
The old code would call QItemSelectionModel::select() once for every dive. Instead collect the selection in a QItemSelection and only call QItemSelectionModel::select() once. This makes selecting multiple dives significantly faster. The loop also expanded the trips with selections. This has now to be done in an extra loop. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/divelistview.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp
index e9c898641..3e26ca125 100644
--- a/desktop-widgets/divelistview.cpp
+++ b/desktop-widgets/divelistview.cpp
@@ -208,16 +208,24 @@ void DiveListView::diveSelectionChanged(const QVector<QModelIndex> &indices)
programmaticalSelectionChange = true;
clearSelection();
- QItemSelectionModel *s = selectionModel();
- for (const QModelIndex &index: indices) {
- s->select(index, QItemSelectionModel::Rows | QItemSelectionModel::Select);
+ QItemSelection selection;
+ for (const QModelIndex &index: indices)
+ selection.select(index, index); // Is there a faster way to do this?
+ selectionModel()->select(selection, QItemSelectionModel::Rows | QItemSelectionModel::Select);
- // If an item of a not-yet expanded trip is selected, expand the trip.
- if (index.parent().isValid() && !isExpanded(index.parent())) {
- setAnimated(false);
- expand(index.parent());
- setAnimated(true);
- }
+ // Expand all unexpanded trips
+ std::vector<int> affectedTrips;
+ for (const QModelIndex &index: indices) {
+ if (!index.parent().isValid())
+ continue;
+ int row = index.parent().row();
+ if (std::find(affectedTrips.begin(), affectedTrips.end(), row) == affectedTrips.end())
+ affectedTrips.push_back(row);
+ }
+ MultiFilterSortModel *m = MultiFilterSortModel::instance();
+ for (int row: affectedTrips) {
+ QModelIndex idx = m->index(row, 0);
+ expand(idx);
}
selectionChangeDone();