mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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>
This commit is contained in:
parent
4f438d1e32
commit
6e83135fba
1 changed files with 17 additions and 9 deletions
|
@ -208,16 +208,24 @@ void DiveListView::diveSelectionChanged(const QVector<QModelIndex> &indices)
|
||||||
programmaticalSelectionChange = true;
|
programmaticalSelectionChange = true;
|
||||||
|
|
||||||
clearSelection();
|
clearSelection();
|
||||||
QItemSelectionModel *s = selectionModel();
|
QItemSelection selection;
|
||||||
for (const QModelIndex &index: indices) {
|
for (const QModelIndex &index: indices)
|
||||||
s->select(index, QItemSelectionModel::Rows | QItemSelectionModel::Select);
|
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.
|
// Expand all unexpanded trips
|
||||||
if (index.parent().isValid() && !isExpanded(index.parent())) {
|
std::vector<int> affectedTrips;
|
||||||
setAnimated(false);
|
for (const QModelIndex &index: indices) {
|
||||||
expand(index.parent());
|
if (!index.parent().isValid())
|
||||||
setAnimated(true);
|
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();
|
selectionChangeDone();
|
||||||
|
|
Loading…
Add table
Reference in a new issue