summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/command_divelist.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'desktop-widgets/command_divelist.cpp')
-rw-r--r--desktop-widgets/command_divelist.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp
index c9303c5df..995a0ec15 100644
--- a/desktop-widgets/command_divelist.cpp
+++ b/desktop-widgets/command_divelist.cpp
@@ -100,6 +100,11 @@ DivesAndTripsToAdd DiveListBase::removeDives(DivesAndSitesToRemove &divesAndSite
divesToAdd.reserve(divesAndSitesToDelete.dives.size());
sitesToAdd.reserve(divesAndSitesToDelete.sites.size());
+ // Make sure that the dive list is sorted. The added dives will be sent in a signal
+ // and the recipients assume that the dives are sorted the same way as they are
+ // in the core list.
+ std::sort(divesAndSitesToDelete.dives.begin(), divesAndSitesToDelete.dives.end(), dive_less_than);
+
for (dive *d: divesAndSitesToDelete.dives)
divesToAdd.push_back(removeDive(d, tripsToAdd));
divesAndSitesToDelete.dives.clear();
@@ -140,6 +145,13 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd)
res.resize(toAdd.dives.size());
sites.reserve(toAdd.sites.size());
+ // Make sure that the dive list is sorted. The added dives will be sent in a signal
+ // and the recipients assume that the dives are sorted the same way as they are
+ // in the core list.
+ std::sort(toAdd.dives.begin(), toAdd.dives.end(),
+ [](const DiveToAdd &d, const DiveToAdd &d2)
+ { return dive_less_than(d.dive.get(), d2.dive.get()); });
+
// Now, add the dives
// Note: the idiomatic STL-way would be std::transform, but let's use a loop since
// that is closer to classical C-style.