From 3debd927345edef6363cb6636f8d240dbdd09dda Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 17 May 2019 18:43:25 +0200 Subject: [PATCH] Undo: properly reference-count dive sites Recently, the undo code was changed to consider dive sites. The undo code uses a DiveToAdd structure, which was extended by the dive site to which the dive should be added. The split and merge commands were not adapted and therefore the dive counts of the dive sites were wrong after split and merge. Fix this by properly setting the dive site field and removing the reference in the dive structure (in the split case, the merge case already cleared the reference). Signed-off-by: Berthold Stoeger --- desktop-widgets/command_divelist.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp index 995a0ec15..c49159f5a 100644 --- a/desktop-widgets/command_divelist.cpp +++ b/desktop-widgets/command_divelist.cpp @@ -727,12 +727,20 @@ SplitDivesBase::SplitDivesBase(dive *d, std::array newDives) newDives[0]->selected = false; newDives[1]->selected = false; + // The new dives will be registered to the dive site using the site member + // of the DiveToAdd structure. For this to work, we must set the dive's + // dive_site member to null. Yes, that's subtle! + newDives[0]->dive_site = nullptr; + newDives[1]->dive_site = nullptr; + diveToSplit.dives.push_back(d); splitDives.dives.resize(2); splitDives.dives[0].dive.reset(newDives[0]); splitDives.dives[0].trip = d->divetrip; + splitDives.dives[0].site = d->dive_site; splitDives.dives[1].dive.reset(newDives[1]); splitDives.dives[1].trip = d->divetrip; + splitDives.dives[1].site = d->dive_site; } bool SplitDivesBase::workToBeDone() @@ -875,6 +883,7 @@ MergeDives::MergeDives(const QVector &dives) mergedDive.dives.resize(1); mergedDive.dives[0].dive = std::move(d); mergedDive.dives[0].trip = preferred_trip; + mergedDive.dives[0].site = preferred_site; divesToMerge.dives = dives.toStdVector(); }