From 7c63956ee4798a835794eee8189b73e3df07594d Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 15 Mar 2019 14:32:55 +0100 Subject: Undo: implement undo of geo lookup Simply copy code of the other edit dive site functions. Here though introduce a destructor in the undo command to free the taxonomy data. Remove the taxonomy member of the LocationInformationWidget class, because it is not needed anymore. Signed-off-by: Berthold Stoeger --- desktop-widgets/command_divesite.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'desktop-widgets/command_divesite.cpp') diff --git a/desktop-widgets/command_divesite.cpp b/desktop-widgets/command_divesite.cpp index 91a6dbe81..04ee3b212 100644 --- a/desktop-widgets/command_divesite.cpp +++ b/desktop-widgets/command_divesite.cpp @@ -235,4 +235,35 @@ void EditDiveSiteLocation::undo() redo(); } +EditDiveSiteTaxonomy::EditDiveSiteTaxonomy(dive_site *dsIn, taxonomy_data &taxonomy) : ds(dsIn), + value(taxonomy) +{ + // We did a dumb copy. Erase the source to remove double references to strings. + memset(&taxonomy, 0, sizeof(taxonomy)); + setText(tr("Edit dive site taxonomy")); +} + +EditDiveSiteTaxonomy::~EditDiveSiteTaxonomy() +{ + free_taxonomy(&value); +} + +bool EditDiveSiteTaxonomy::workToBeDone() +{ + // TODO: Apparently we have no way of comparing taxonomies? + return true; +} + +void EditDiveSiteTaxonomy::redo() +{ + std::swap(value, ds->taxonomy); + emit diveListNotifier.diveSiteChanged(ds, LocationInformationModel::TAXONOMY); // Inform frontend of changed dive site. +} + +void EditDiveSiteTaxonomy::undo() +{ + // Undo and redo do the same + redo(); +} + } // namespace Command -- cgit v1.2.3-70-g09d2