diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-05-17 18:43:25 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-05-17 10:36:23 -0700 |
commit | 3debd927345edef6363cb6636f8d240dbdd09dda (patch) | |
tree | 52b27b5cf1248f13886ce21914e5b3211bf93632 /desktop-widgets | |
parent | 77b5d714fb1c373d0f2c93c23607958ea9788b4b (diff) | |
download | subsurface-3debd927345edef6363cb6636f8d240dbdd09dda.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/command_divelist.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
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<dive *, 2> 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 <dive *> &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(); } |