diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-05-02 14:41:52 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-05-03 15:02:21 -0700 |
commit | f961ec7a8b399683b5b9aedc56827fa307511487 (patch) | |
tree | 5723cc305f2a6252dbc3b681af0643b32e0176e3 | |
parent | 09b7fcbcf4e26d19529486ddd2a0e672e60dce32 (diff) | |
download | subsurface-f961ec7a8b399683b5b9aedc56827fa307511487.tar.gz |
selection: introduce clear_selection() function
The DiveListView would touch the selection-innards directly.
Let's encapsulate that. Moreover, take care to reset the trip
selection when resetting the core data.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | core/divelist.c | 1 | ||||
-rw-r--r-- | core/selection.cpp | 13 | ||||
-rw-r--r-- | core/selection.h | 1 | ||||
-rw-r--r-- | desktop-widgets/divelistview.cpp | 13 |
4 files changed, 16 insertions, 12 deletions
diff --git a/core/divelist.c b/core/divelist.c index 778811db5..4325df595 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -1354,6 +1354,7 @@ int get_dive_id_closest_to(timestamp_t when) void clear_dive_file_data() { fulltext_unregister_all(); + clear_selection(); while (dive_table.nr) delete_single_dive(0); diff --git a/core/selection.cpp b/core/selection.cpp index f763afcc6..48bb1a76f 100644 --- a/core/selection.cpp +++ b/core/selection.cpp @@ -253,3 +253,16 @@ extern "C" void deselect_trip(struct dive_trip *trip) amount_trips_selected--; } } + +extern "C" void clear_selection(void) +{ + current_dive = nullptr; + amount_selected = 0; + amount_trips_selected = 0; + int i; + struct dive *dive; + for_each_dive (i, dive) + dive->selected = false; + for (int i = 0; i < trip_table.nr; ++i) + trip_table.trips[i]->selected = false; +} diff --git a/core/selection.h b/core/selection.h index 55055de4a..beab31eaf 100644 --- a/core/selection.h +++ b/core/selection.h @@ -23,6 +23,7 @@ extern void select_newest_visible_dive(); extern void select_single_dive(struct dive *d); // wrapper for setSelection() with a single dive. NULL clears the selection. extern void select_trip(struct dive_trip *trip); extern void deselect_trip(struct dive_trip *trip); +extern void clear_selection(void); #if DEBUG_SELECTION_TRACKING extern void dump_selection(void); diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index f95afee25..8edcb0655 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -292,20 +292,9 @@ void DiveListView::selectTrip(dive_trip_t *trip) void DiveListView::unselectDives() { - // make sure we don't try to redraw the dives during the selection change - current_dive = nullptr; - amount_selected = 0; + clear_selection(); // clear the Qt selection selectionModel()->clearSelection(); - // clearSelection should emit selectionChanged() but sometimes that - // appears not to happen - // since we are unselecting all dives there is no need to use deselect_dive() - that - // would only cause pointless churn - int i; - struct dive *dive; - for_each_dive (i, dive) { - dive->selected = false; - } } // This function returns a trip if there is one selected trip or NULL. |