summaryrefslogtreecommitdiffstats
path: root/qt-ui/divelistview.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-09 21:32:38 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-09 21:32:38 -0800
commit7cb307cf73c2662dac5a3e03a66fdb878d26e432 (patch)
tree6b470f3837664b0b17d5431f062b07c2700b1157 /qt-ui/divelistview.cpp
parentfd997c1b15e798bdf2aa1088e0c58467793a511d (diff)
downloadsubsurface-7cb307cf73c2662dac5a3e03a66fdb878d26e432.tar.gz
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
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r--qt-ui/divelistview.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 502cebcbd..96b9291ac 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -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();
- if (idx.parent().isValid())
- scrollTo(idx.parent());
- scrollTo(idx);
-
+ 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;