Undo: implement undo of buddy editing

This was mostly trivial by reusing the code for tag-editing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-02-07 21:00:09 +01:00 committed by Dirk Hohndel
parent 8c89f6fe15
commit a9bd0690fe
6 changed files with 63 additions and 13 deletions

View file

@ -3,6 +3,7 @@
#include "command_edit.h"
#include "core/divelist.h"
#include "core/qthelper.h" // for copy_qstring
#include "desktop-widgets/mapwidget.h" // TODO: Replace desktop-dependency by signal
namespace Command {
@ -450,4 +451,36 @@ DiveField EditTags::fieldId() const
return DiveField::TAGS;
}
// String list helper
static QStringList stringToList(const QString &s)
{
QStringList res = s.split(",", QString::SkipEmptyParts);
for (QString &str: res)
str = str.trimmed();
return res;
}
// ***** Buddies *****
QStringList EditBuddies::data(struct dive *d) const
{
return stringToList(d->buddy);
}
void EditBuddies::set(struct dive *d, const QStringList &v) const
{
QString text = v.join(", ");
free(d->buddy);
d->buddy = copy_qstring(text);
}
QString EditBuddies::fieldName() const
{
return tr("buddies");
}
DiveField EditBuddies::fieldId() const
{
return DiveField::BUDDY;
}
} // namespace Command