Undo: implement undo of dive site country editing

Simply copy the code of notes editing, but use the taxonomy_* functions
to read and set the value. Moreover, replace the three TAXONOMY_n field
ids by a single TAXONOMY id. We will probably never show one column per
taxonomy field, but rather a single column with a string derived from all
taxonomy fields.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-03-14 08:26:50 +01:00 committed by Dirk Hohndel
parent 4d183e0d75
commit 021aa4bd57
8 changed files with 54 additions and 20 deletions

View file

@ -4,6 +4,7 @@
#include "core/divesite.h"
#include "core/subsurface-qt/DiveListNotifier.h"
#include "core/qthelper.h"
#include "core/subsurface-string.h"
#include "qt-models/divelocationmodel.h"
namespace Command {
@ -182,4 +183,29 @@ void EditDiveSiteNotes::undo()
redo();
}
EditDiveSiteCountry::EditDiveSiteCountry(dive_site *dsIn, const QString &country) : ds(dsIn),
value(country)
{
setText(tr("Edit dive site country"));
}
bool EditDiveSiteCountry::workToBeDone()
{
return !same_string(qPrintable(value), taxonomy_get_country(&ds->taxonomy));
}
void EditDiveSiteCountry::redo()
{
QString old = taxonomy_get_country(&ds->taxonomy);
taxonomy_set_country(&ds->taxonomy, copy_qstring(value), taxonomy_origin::GEOMANUAL);
value = old;
emit diveListNotifier.diveSiteChanged(ds, LocationInformationModel::TAXONOMY); // Inform frontend of changed dive site.
}
void EditDiveSiteCountry::undo()
{
// Undo and redo do the same
redo();
}
} // namespace Command