diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-12-08 21:15:59 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-12-14 00:09:05 +0800 |
commit | 2706fa7b8e53438ba101fbe638eff150c8d2d154 (patch) | |
tree | 549cde86dad51d2c2b23640fcaee7a089130d0eb | |
parent | 3cdc2661d2a2417e557042abe1a0d9e5107822eb (diff) | |
download | subsurface-2706fa7b8e53438ba101fbe638eff150c8d2d154.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | desktop-widgets/command_divelist.cpp | 7 |
1 files 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; |