diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-11-09 21:55:17 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-11-10 11:17:58 -0800 |
commit | 02567ec790039195c3b22c604f84beb1f10280a9 (patch) | |
tree | a158dc13c7826555b6fabd3ffde0d9ea3a9b5bec /qt-ui/divelistview.cpp | |
parent | 7cb307cf73c2662dac5a3e03a66fdb878d26e432 (diff) | |
download | subsurface-02567ec790039195c3b22c604f84beb1f10280a9.tar.gz |
Be more careful when restoring a selection in the presence of filters
Try really hard to ensure there remains a valid selection. Only if none of
the dives are selectable should we give up.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r-- | qt-ui/divelistview.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 96b9291ac..0d7c4fa6d 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -313,6 +313,7 @@ void DiveListView::selectDive(int i, bool scrollto, bool toggle) void DiveListView::selectDives(const QList<int> &newDiveSelection) { + int firstInList, newSelection; if (!newDiveSelection.count()) return; @@ -321,9 +322,21 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection) // becomes the selected_dive that we scroll to QList<int> sortedSelection = newDiveSelection; qSort(sortedSelection.begin(), sortedSelection.end()); + newSelection = firstInList = sortedSelection.first(); + while (!sortedSelection.isEmpty()) selectDive(sortedSelection.takeLast()); + while (selected_dive == -1) { + // that can happen if we restored a selection after edit + // and the only selected dive is no longer visible because of a filter + newSelection--; + if (newSelection < 0) + newSelection = dive_table.nr - 1; + if (newSelection == firstInList) + break; + selectDive(newSelection); + } QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model()); QModelIndexList idxList = m->match(m->index(0, 0), DiveTripModel::DIVE_IDX, selected_dive, 2, Qt::MatchRecursive); if (!idxList.isEmpty()) { |