summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/command_divelist.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-24 12:31:35 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-01-09 20:58:04 -0800
commit517fb7a462c207e32cc7c5ed50e1e9b1f359dbd8 (patch)
tree2ce9dd590f60743f5f565af320ea77c474c2e1c4 /desktop-widgets/command_divelist.cpp
parent54fcda4c32029c1afd9eb02fb0c4a5e1949da175 (diff)
downloadsubsurface-517fb7a462c207e32cc7c5ed50e1e9b1f359dbd8.tar.gz
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/command_divelist.cpp')
-rw-r--r--desktop-widgets/command_divelist.cpp10
1 files changed, 8 insertions, 2 deletions
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);
}