From 2706fa7b8e53438ba101fbe638eff150c8d2d154 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 8 Dec 2018 21:15:59 +0100 Subject: [PATCH] Dive list: remove trip from model only once In moveDivesBetweenTrips() a the model is informed of dives that are moved between trips. A flag tells the model to delete empty trips. If dives were removed in batches [use case: split a big trip into multiple smaller trips] the flag would be sent for every batch. This was handled gracefully by the model code, but it gave a warning message. Set the flag only for the last batch, when the trip is *really* empty. Signed-off-by: Berthold Stoeger --- desktop-widgets/command_divelist.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp index 4e5c455f3..29fd550f0 100644 --- a/desktop-widgets/command_divelist.cpp +++ b/desktop-widgets/command_divelist.cpp @@ -305,9 +305,12 @@ static void moveDivesBetweenTrips(DivesToTrip &dives) for (size_t k = i; k < j; ++k) divesInTrip[k - i] = divesMoved[k].d; - // Check if the from-trip was deleted: If yes, it was recorded in the tripsToAdd structure + // Check if the from-trip was deleted: If yes, it was recorded in the tripsToAdd structure. + // Only set the flag if this is that last time this trip is featured. bool deleteFrom = from && - std::find_if(dives.tripsToAdd.begin(), dives.tripsToAdd.end(), + std::find_if(divesMoved.begin() + j, divesMoved.end(), // Is this the last occurence of "from"? + [from](const DiveMoved &entry) { return entry.from == from; }) == divesMoved.end() && + std::find_if(dives.tripsToAdd.begin(), dives.tripsToAdd.end(), // Is "from" in tripsToAdd? [from](const OwningTripPtr &trip) { return trip.get() == from; }) != dives.tripsToAdd.end(); // Check if the to-trip has to be created. For this purpose, we saved an array of trips to be created. bool createTo = false;