mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
fix copy/paste of dive-site
The copy/pasting of dive-sites was fundamentally broken in at least two ways: 1) The dive-site pointer in struct dive was simply overwritten, which breaks internal consistency. Also, no dive-site changed signals where sent. 2) The copied dive-site was stored as a pointer in a struct dive. Thus, the user could copy a dive, then delete the dive-site and paste. This would lead to a dangling pointer and ultimately crash the application. Fix this by storing the UUID of the dive-site, not a pointer. To do that, don't store a copy of the dive, but collect all the data in a `dive_paste_data` structure. If the dive site has been deleted on paste, do nothing. Send the appropriate signals on pasting. The mobile version had an additional bug: It kept a pointer to the dive to be copied, which might become stale by undo. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
48b4308a7d
commit
152e6966c9
17 changed files with 359 additions and 425 deletions
|
@ -203,40 +203,6 @@ void copy_dive(const struct dive *s, struct dive *d)
|
|||
d->invalidate_cache();
|
||||
}
|
||||
|
||||
#define CONDITIONAL_COPY_STRING(_component) \
|
||||
if (what._component) \
|
||||
d->_component = s->_component
|
||||
|
||||
// copy elements, depending on bits in what that are set
|
||||
void selective_copy_dive(const struct dive *s, struct dive *d, struct dive_components what, bool clear)
|
||||
{
|
||||
if (clear)
|
||||
d->clear();
|
||||
CONDITIONAL_COPY_STRING(notes);
|
||||
CONDITIONAL_COPY_STRING(diveguide);
|
||||
CONDITIONAL_COPY_STRING(buddy);
|
||||
CONDITIONAL_COPY_STRING(suit);
|
||||
if (what.rating)
|
||||
d->rating = s->rating;
|
||||
if (what.visibility)
|
||||
d->visibility = s->visibility;
|
||||
if (what.divesite) {
|
||||
unregister_dive_from_dive_site(d);
|
||||
s->dive_site->add_dive(d);
|
||||
}
|
||||
if (what.tags)
|
||||
d->tags = s->tags;
|
||||
if (what.cylinders)
|
||||
copy_cylinder_types(s, d);
|
||||
if (what.weights)
|
||||
d->weightsystems = s->weightsystems;
|
||||
if (what.number)
|
||||
d->number = s->number;
|
||||
if (what.when)
|
||||
d->when = s->when;
|
||||
}
|
||||
#undef CONDITIONAL_COPY_STRING
|
||||
|
||||
/* copies all events from the given dive computer before a given time
|
||||
this is used when editing a dive in the planner to preserve the events
|
||||
of the old dive */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue