From 517fb7a462c207e32cc7c5ed50e1e9b1f359dbd8 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 24 Nov 2018 12:31:35 +0100 Subject: Core: keep trips in table(s) Currently, all trips are kept in a linked list. Replace the list by a table in analogy to dive_table. Use this to keep the trip_table sorted as suggested by dump_trip_list(). When inserting a trip into the table do that after adding the dives, to avoid warnings coming out of dump_trip_list(). Signed-off-by: Berthold Stoeger --- desktop-widgets/command_divelist.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'desktop-widgets/command_divelist.cpp') diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp index 5e3f30ce2..b3c4f24e3 100644 --- a/desktop-widgets/command_divelist.cpp +++ b/desktop-widgets/command_divelist.cpp @@ -81,10 +81,10 @@ DiveToAdd DiveListBase::removeDive(struct dive *d) // Returns pointer to added dive (which is owned by the backend!) dive *DiveListBase::addDive(DiveToAdd &d) { - if (d.tripToAdd) - insert_trip(d.tripToAdd.release()); // Return ownership to backend if (d.trip) add_dive_to_trip(d.dive.get(), d.trip); + if (d.tripToAdd) + insert_trip(d.tripToAdd.release()); // Return ownership to backend dive *res = d.dive.release(); // Give up ownership of dive // Set the filter flag according to current filter settings @@ -530,6 +530,7 @@ void AddDive::redoit() currentDive = current_dive; divesToRemove = addDives(divesToAdd); + sort_trip_table(&trip_table); // Though unlikely, adding a dive may reorder trips mark_divelist_changed(true); // Select the newly added dive @@ -544,6 +545,7 @@ void AddDive::undoit() { // Simply remove the dive that was previously added... divesToAdd = removeDives(divesToRemove); + sort_trip_table(&trip_table); // Though unlikely, removing a dive may reorder trips // ...and restore the selection restoreSelection(selection, currentDive); @@ -566,6 +568,7 @@ bool DeleteDive::workToBeDone() void DeleteDive::undoit() { divesToDelete = addDives(divesToAdd); + sort_trip_table(&trip_table); // Though unlikely, removing a dive may reorder trips mark_divelist_changed(true); // Select all re-added dives and make the first one current @@ -576,6 +579,7 @@ void DeleteDive::undoit() void DeleteDive::redoit() { divesToAdd = removeDives(divesToDelete); + sort_trip_table(&trip_table); // Though unlikely, adding a dive may reorder trips mark_divelist_changed(true); // Deselect all dives and select dive that was close to the first deleted dive @@ -604,6 +608,7 @@ void ShiftTime::redoit() // Changing times may have unsorted the dive table sort_dive_table(&dive_table); + sort_trip_table(&trip_table); // We send one time changed signal per trip (see comments in DiveListNotifier.h). // Therefore, collect all dives in an array and sort by trip. @@ -667,6 +672,7 @@ bool TripBase::workToBeDone() void TripBase::redoit() { moveDivesBetweenTrips(divesToMove); + sort_trip_table(&trip_table); // Though unlikely, moving dives may reorder trips mark_divelist_changed(true); } -- cgit v1.2.3-70-g09d2