mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
undo/mobile: keep track of dive sites
When editing the dive site of a dive, the dive-table of the corresponding dive site was not properly updated by the undo commands. Try to get this right. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
039ed38067
commit
69d437bc86
3 changed files with 14 additions and 4 deletions
|
@ -1004,13 +1004,14 @@ void EditWeight::undo()
|
||||||
EditDive::EditDive(dive *oldDiveIn, dive *newDiveIn, dive_site *createDs, dive_site *editDs, location_t dsLocationIn)
|
EditDive::EditDive(dive *oldDiveIn, dive *newDiveIn, dive_site *createDs, dive_site *editDs, location_t dsLocationIn)
|
||||||
: oldDive(oldDiveIn)
|
: oldDive(oldDiveIn)
|
||||||
, newDive(newDiveIn)
|
, newDive(newDiveIn)
|
||||||
|
, newDiveSite(newDiveIn->dive_site)
|
||||||
, changedFields(DiveField::NONE)
|
, changedFields(DiveField::NONE)
|
||||||
, siteToRemove(nullptr)
|
, siteToRemove(nullptr)
|
||||||
, siteToAdd(createDs)
|
, siteToAdd(createDs)
|
||||||
, siteToEdit(editDs)
|
, siteToEdit(editDs)
|
||||||
, dsLocation(dsLocationIn)
|
, dsLocation(dsLocationIn)
|
||||||
{
|
{
|
||||||
if (!oldDive || ! newDive)
|
if (!oldDive || !newDive)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
setText(Command::Base::tr("Edit dive [%1]").arg(diveNumberOrDate(oldDive)));
|
setText(Command::Base::tr("Edit dive [%1]").arg(diveNumberOrDate(oldDive)));
|
||||||
|
@ -1061,6 +1062,8 @@ EditDive::EditDive(dive *oldDiveIn, dive *newDiveIn, dive_site *createDs, dive_s
|
||||||
changedFields |= DiveField::NOTES;
|
changedFields |= DiveField::NOTES;
|
||||||
if (oldDive->salinity != newDive->salinity)
|
if (oldDive->salinity != newDive->salinity)
|
||||||
changedFields |= DiveField::SALINITY;
|
changedFields |= DiveField::SALINITY;
|
||||||
|
|
||||||
|
newDive->dive_site = nullptr; // We will add the dive to the site manually and therefore saved the dive site.
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditDive::undo()
|
void EditDive::undo()
|
||||||
|
@ -1097,9 +1100,16 @@ void EditDive::exchangeDives()
|
||||||
|
|
||||||
// Bluntly exchange dive data by shallow copy.
|
// Bluntly exchange dive data by shallow copy.
|
||||||
// Don't forget to unregister the old and register the new dive!
|
// Don't forget to unregister the old and register the new dive!
|
||||||
|
// Likewise take care to add/remove the dive from the dive site.
|
||||||
fulltext_unregister(oldDive);
|
fulltext_unregister(oldDive);
|
||||||
|
dive_site *oldDiveSite = oldDive->dive_site;
|
||||||
|
if (oldDiveSite)
|
||||||
|
unregister_dive_from_dive_site(oldDive); // the dive-site pointer in the dive is now NULL
|
||||||
std::swap(*newDive, *oldDive);
|
std::swap(*newDive, *oldDive);
|
||||||
fulltext_register(oldDive);
|
fulltext_register(oldDive);
|
||||||
|
if (newDiveSite)
|
||||||
|
add_dive_to_dive_site(oldDive, newDiveSite);
|
||||||
|
newDiveSite = oldDiveSite; // remember the previous dive site
|
||||||
invalidate_dive_cache(oldDive);
|
invalidate_dive_cache(oldDive);
|
||||||
|
|
||||||
// Changing times may have unsorted the dive and trip tables
|
// Changing times may have unsorted the dive and trip tables
|
||||||
|
|
|
@ -386,6 +386,7 @@ public:
|
||||||
private:
|
private:
|
||||||
dive *oldDive; // Dive that is going to be overwritten
|
dive *oldDive; // Dive that is going to be overwritten
|
||||||
OwningDivePtr newDive; // New data
|
OwningDivePtr newDive; // New data
|
||||||
|
dive_site *newDiveSite;
|
||||||
int changedFields;
|
int changedFields;
|
||||||
|
|
||||||
dive_site *siteToRemove;
|
dive_site *siteToRemove;
|
||||||
|
|
|
@ -799,7 +799,7 @@ static void setupDivesite(DiveSiteChange &res, struct dive *d, struct dive_site
|
||||||
res.location = location;
|
res.location = location;
|
||||||
} else {
|
} else {
|
||||||
res.createdDs.reset(alloc_dive_site_with_name(locationtext));
|
res.createdDs.reset(alloc_dive_site_with_name(locationtext));
|
||||||
add_dive_to_dive_site(d, res.createdDs.get());
|
d->dive_site = res.createdDs.get();
|
||||||
}
|
}
|
||||||
res.changed = true;
|
res.changed = true;
|
||||||
}
|
}
|
||||||
|
@ -920,8 +920,7 @@ bool QMLManager::checkLocation(DiveSiteChange &res, const DiveObjectHelper &myDi
|
||||||
res.changed = true;
|
res.changed = true;
|
||||||
ds = res.createdDs.get();
|
ds = res.createdDs.get();
|
||||||
}
|
}
|
||||||
unregister_dive_from_dive_site(d);
|
d->dive_site = ds;
|
||||||
add_dive_to_dive_site(d, ds);
|
|
||||||
}
|
}
|
||||||
// now make sure that the GPS coordinates match - if the user changed the name but not
|
// now make sure that the GPS coordinates match - if the user changed the name but not
|
||||||
// the GPS coordinates, this still does the right thing as the now new dive site will
|
// the GPS coordinates, this still does the right thing as the now new dive site will
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue