diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-04-04 16:35:24 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-04-04 11:49:23 -0700 |
commit | 69d437bc8675267eb71f6658b05991b4afdfb6fb (patch) | |
tree | c6fe0aadca8532205c661af56969fea9557d33dc | |
parent | 039ed38067a9d34c8625b2b8b260822c8f65d63e (diff) | |
download | subsurface-69d437bc8675267eb71f6658b05991b4afdfb6fb.tar.gz |
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>
-rw-r--r-- | commands/command_edit.cpp | 12 | ||||
-rw-r--r-- | commands/command_edit.h | 1 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 5 |
3 files changed, 14 insertions, 4 deletions
diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp index e3ecf8cf8..46c206c98 100644 --- a/commands/command_edit.cpp +++ b/commands/command_edit.cpp @@ -1004,13 +1004,14 @@ void EditWeight::undo() EditDive::EditDive(dive *oldDiveIn, dive *newDiveIn, dive_site *createDs, dive_site *editDs, location_t dsLocationIn) : oldDive(oldDiveIn) , newDive(newDiveIn) + , newDiveSite(newDiveIn->dive_site) , changedFields(DiveField::NONE) , siteToRemove(nullptr) , siteToAdd(createDs) , siteToEdit(editDs) , dsLocation(dsLocationIn) { - if (!oldDive || ! newDive) + if (!oldDive || !newDive) return; 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; if (oldDive->salinity != newDive->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() @@ -1097,9 +1100,16 @@ void EditDive::exchangeDives() // Bluntly exchange dive data by shallow copy. // 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); + 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); fulltext_register(oldDive); + if (newDiveSite) + add_dive_to_dive_site(oldDive, newDiveSite); + newDiveSite = oldDiveSite; // remember the previous dive site invalidate_dive_cache(oldDive); // Changing times may have unsorted the dive and trip tables diff --git a/commands/command_edit.h b/commands/command_edit.h index e10934704..e99ce2407 100644 --- a/commands/command_edit.h +++ b/commands/command_edit.h @@ -386,6 +386,7 @@ public: private: dive *oldDive; // Dive that is going to be overwritten OwningDivePtr newDive; // New data + dive_site *newDiveSite; int changedFields; dive_site *siteToRemove; diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 177d0126e..0883d0389 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -799,7 +799,7 @@ static void setupDivesite(DiveSiteChange &res, struct dive *d, struct dive_site res.location = location; } else { 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; } @@ -920,8 +920,7 @@ bool QMLManager::checkLocation(DiveSiteChange &res, const DiveObjectHelper &myDi res.changed = true; ds = res.createdDs.get(); } - unregister_dive_from_dive_site(d); - add_dive_to_dive_site(d, ds); + d->dive_site = ds; } // 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 |