Undo: Implement undo of dive site name editing

Implement an undo command that edits the name of a dive site.
Connect it to the dive site table, so that names can be edited
directly in the table.

Send signals on undo / redo so that the dive site table and
the dive site edit widget can be updated.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-03-12 23:51:39 +01:00 committed by Dirk Hohndel
parent 8e1f736d2b
commit 0e1b0cf1da
9 changed files with 97 additions and 2 deletions

View file

@ -3,6 +3,8 @@
#include "command_divesite.h"
#include "core/divesite.h"
#include "core/subsurface-qt/DiveListNotifier.h"
#include "core/qthelper.h"
#include "qt-models/divelocationmodel.h"
namespace Command {
@ -80,4 +82,29 @@ void DeleteDiveSites::undo()
sitesToRemove = std::move(addDiveSites(sitesToAdd));
}
EditDiveSiteName::EditDiveSiteName(dive_site *dsIn, const QString &name) : ds(dsIn),
value(name)
{
}
bool EditDiveSiteName::workToBeDone()
{
return value != QString(ds->name);
}
void EditDiveSiteName::redo()
{
QString s = ds->name;
free(ds->name);
ds->name = copy_qstring(value);
value = s;
emit diveListNotifier.diveSiteChanged(ds, LocationInformationModel::NAME); // Inform frontend of changed dive site.
}
void EditDiveSiteName::undo()
{
// Undo and redo do the same
redo();
}
} // namespace Command