When selection gets confused, don't try to select non-existing dive

While the argument could be made that this is just a symptom of Subsurface
getting very confused about the selection (which it still gets at times -
most likely we are calling select_dive() instead of selectDive()  (or the
corresponding deselect functions) in places where we shouldn't), but
either way, we should not crash.

Fixes #220

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-11-13 13:59:02 +09:00
parent 17b5618c39
commit 25e432e1d1

View file

@ -119,6 +119,8 @@ void DiveListView::unselectDives()
void DiveListView::selectDive(struct dive *dive, bool scrollto, bool toggle)
{
if (dive == NULL)
return;
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
QModelIndexList match = m->match(m->index(0,0), DiveTripModel::NR, dive->number, 1, Qt::MatchRecursive);
QItemSelectionModel::SelectionFlags flags;
@ -227,7 +229,7 @@ void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
return;
sortByColumn(sortColumn, currentOrder);
if (amount_selected && selected_dive >= 0) {
if (amount_selected && current_dive != NULL) {
selectDive(current_dive, true);
} else {
QModelIndex firstDiveOrTrip = m->index(0,0);