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:
Dirk Hohndel 2014-11-09 21:32:38 -08:00
parent fd997c1b15
commit 7cb307cf73

View file

@ -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;