diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-05-15 11:40:39 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-05-17 07:55:34 -0700 |
commit | 9bb58338485c5c938b529a3ec643a985031f0c97 (patch) | |
tree | ce9e994ac1656bcb43285b521a2753f63e97a9a2 /desktop-widgets/command_divelist.cpp | |
parent | a969d1dd4518ce77e8fba920aec4a5d8cfd1f636 (diff) | |
download | subsurface-9bb58338485c5c938b529a3ec643a985031f0c97.tar.gz |
Undo: sort list of dives to add and delete
In 5729f93e1f512aa9e68b0e01743152aaee2b7c12, the dive addition /
deletion code was simplified in that indexes were calculated on
the fly. This made it, in principle, possible to pass in dives
in any order.
But there was a small oversight: the recipients of the dives-added
and dives-deleted signals expect the dives to be sorted as in
the core list. Only then will the lists be consistent.
Therefore, sort the lists before adding / deleting dives.
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.cpp | 12 |
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. |