diff options
-rw-r--r-- | core/selection.cpp | 13 | ||||
-rw-r--r-- | core/selection.h | 1 | ||||
-rw-r--r-- | desktop-widgets/divelistview.cpp | 26 | ||||
-rw-r--r-- | desktop-widgets/divelistview.h | 2 |
4 files changed, 16 insertions, 26 deletions
diff --git a/core/selection.cpp b/core/selection.cpp index 92bb631fc..6b5dfe726 100644 --- a/core/selection.cpp +++ b/core/selection.cpp @@ -210,3 +210,16 @@ std::vector<dive *> getDiveSelection() } return res; } + +// Select the first dive that is visible +extern "C" void select_newest_visible_dive() +{ + for (int i = dive_table.nr - 1; i >= 0; --i) { + dive *d = dive_table.dives[i]; + if (!d->hidden_by_filter) + return setSelection({ d }, d); + } + + // No visible dive -> deselect all + setSelection({}, nullptr); +} diff --git a/core/selection.h b/core/selection.h index e990a697c..a390f0dd7 100644 --- a/core/selection.h +++ b/core/selection.h @@ -19,6 +19,7 @@ extern void deselect_dive(struct dive *dive); extern struct dive *first_selected_dive(void); extern struct dive *last_selected_dive(void); extern bool consecutive_selected(void); +extern void select_newest_visible_dive(); #if DEBUG_SELECTION_TRACKING extern void dump_selection(void); diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index 05cd6fe72..4354fdb26 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -474,28 +474,6 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection) selectionChangeDone(); } -// Get index of first dive. This assumes that trips without dives are never shown. -// May return an invalid index if no dive is found. -QModelIndex DiveListView::indexOfFirstDive() -{ - // Fetch the first top-level item. If this is a trip, it is supposed to have at least - // one child. In that case return the child. Otherwise return the top-level item, which - // should be a dive. - QAbstractItemModel *m = model(); - QModelIndex firstDiveOrTrip = m->index(0, 0); - if (!firstDiveOrTrip.isValid()) - return QModelIndex(); - QModelIndex child = m->index(0, 0, firstDiveOrTrip); - return child.isValid() ? child : firstDiveOrTrip; -} - -void DiveListView::selectFirstDive() -{ - QModelIndex first = indexOfFirstDive(); - if (first.isValid()) - setCurrentIndex(first); -} - bool DiveListView::eventFilter(QObject *, QEvent *event) { if (event->type() != QEvent::KeyPress) @@ -544,7 +522,7 @@ void DiveListView::reload() if (amount_selected && current_dive != NULL) selectDive(get_divenr(current_dive), true); else - selectFirstDive(); + select_newest_visible_dive(); if (selectedIndexes().count()) { QModelIndex curr = selectedIndexes().first(); curr = curr.parent().isValid() ? curr.parent() : curr; @@ -1114,7 +1092,7 @@ void DiveListView::filterFinished() // If there are no more selected dives, select the first visible dive if (!selectionModel()->hasSelection()) - selectFirstDive(); + select_newest_visible_dive(); emit divesSelected(); } diff --git a/desktop-widgets/divelistview.h b/desktop-widgets/divelistview.h index 67b1b269b..f7676c58a 100644 --- a/desktop-widgets/divelistview.h +++ b/desktop-widgets/divelistview.h @@ -34,8 +34,6 @@ public: void selectDive(QModelIndex index, bool scrollto = false, bool toggle = false); void selectDive(int dive_table_idx, bool scrollto = false, bool toggle = false); void selectDives(const QList<int> &newDiveSelection); - void selectFirstDive(); - QModelIndex indexOfFirstDive(); void rememberSelection(); void restoreSelection(); void contextMenuEvent(QContextMenuEvent *event); |