mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Don't crash when restoring the selection
If we end up trying to restore the selection where the selected dive is no longer visible (i.e., it's now filtered away), this code caused a crash by falling first() on an empty list. Let's not do that. Fixes #758
This commit is contained in:
parent
fd997c1b15
commit
7cb307cf73
1 changed files with 7 additions and 5 deletions
|
@ -325,11 +325,13 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection)
|
|||
selectDive(sortedSelection.takeLast());
|
||||
|
||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model());
|
||||
QModelIndex idx = m->match(m->index(0, 0), DiveTripModel::DIVE_IDX, selected_dive, 2, Qt::MatchRecursive).first();
|
||||
QModelIndexList idxList = m->match(m->index(0, 0), DiveTripModel::DIVE_IDX, selected_dive, 2, Qt::MatchRecursive);
|
||||
if (!idxList.isEmpty()) {
|
||||
QModelIndex idx = idxList.first();
|
||||
if (idx.parent().isValid())
|
||||
scrollTo(idx.parent());
|
||||
scrollTo(idx);
|
||||
|
||||
}
|
||||
// now that everything is up to date, update the widgets
|
||||
Q_EMIT currentDiveChanged(selected_dive);
|
||||
dontEmitDiveChangedSignal = false;
|
||||
|
|
Loading…
Add table
Reference in a new issue