summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-05-02 18:14:44 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-05-03 15:02:21 -0700
commit769915f3fe75bcef8029e82fdfed7ae206182390 (patch)
treeab38f02413b4d55d1feafffcd31267b527467cda /core
parent51471317011bef1b6e51a42951f61073bb8be905 (diff)
downloadsubsurface-769915f3fe75bcef8029e82fdfed7ae206182390.tar.gz
selection: create global single_selected_trip() function
The DiveListView had a singleSelectedTrip function that returns the selected trip if exactly one trip is selected. This could be very slow if numerous non-trip items were selected, because all the selection indices were back- translated by the proxy model. This could make selection changes very slow, because the MainTab used said function to determine whether it should show trip or dive data.. Indeed, with a 3500 dive test log, when selecting all dives in tree mode, the updating of the TabWidgets is sped up from 130 ms to 5 ms this commit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/selection.cpp12
-rw-r--r--core/selection.h1
2 files changed, 13 insertions, 0 deletions
diff --git a/core/selection.cpp b/core/selection.cpp
index 48bb1a76f..d6267c78a 100644
--- a/core/selection.cpp
+++ b/core/selection.cpp
@@ -254,6 +254,18 @@ extern "C" void deselect_trip(struct dive_trip *trip)
}
}
+extern "C" struct dive_trip *single_selected_trip()
+{
+ if (amount_trips_selected != 1)
+ return NULL;
+ for (int i = 0; i < trip_table.nr; ++i) {
+ if (trip_table.trips[i]->selected)
+ return trip_table.trips[i];
+ }
+ fprintf(stderr, "warning: found no selected trip even though one should be selected\n");
+ return NULL; // shouldn't happen
+}
+
extern "C" void clear_selection(void)
{
current_dive = nullptr;
diff --git a/core/selection.h b/core/selection.h
index beab31eaf..713e1b229 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 struct dive_trip *single_selected_trip(); // returns trip if exactly one trip is selected, NULL otherwise.
extern void clear_selection(void);
#if DEBUG_SELECTION_TRACKING