summaryrefslogtreecommitdiffstats
path: root/commands/command_edit.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-03-21 18:30:49 +0100
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2020-03-31 21:53:19 +0200
commit91f7689787345735cfaac516ce2e77311f32f011 (patch)
tree0364ebfffe291264ffa05416f6b01d38b3f88607 /commands/command_edit.cpp
parentea813938a838be57d6a616b0175d5d650fb8c2a2 (diff)
downloadsubsurface-91f7689787345735cfaac516ce2e77311f32f011.tar.gz
undo: autogenerate string get() and data() functions using a template
Do this in analogy to other types. However, here we have to convert from / to QString. We could do this in an even more general way by using two templat parameters: one for the Qt type, one for the core type and define conversion functions. However, let's not do this for now. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'commands/command_edit.cpp')
-rw-r--r--commands/command_edit.cpp35
1 files changed, 13 insertions, 22 deletions
diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp
index d41f595dc..e3ecf8cf8 100644
--- a/commands/command_edit.cpp
+++ b/commands/command_edit.cpp
@@ -38,6 +38,19 @@ T EditDefaultSetter<T, ID, PTR>::data(struct dive *d) const
return d->*PTR;
}
+template <DiveField::Flags ID, char *dive::*PTR>
+void EditStringSetter<ID, PTR>::set(struct dive *d, QString v) const
+{
+ free(d->*PTR);
+ d->*PTR = copy_qstring(v);
+}
+
+template <DiveField::Flags ID, char *dive::*PTR>
+QString EditStringSetter<ID, PTR>::data(struct dive *d) const
+{
+ return QString(d->*PTR);
+}
+
static std::vector<dive *> getDives(bool currentDiveOnly)
{
if (currentDiveOnly)
@@ -176,34 +189,12 @@ void EditBase<T>::redo()
// Implementation of virtual functions
// ***** Notes *****
-void EditNotes::set(struct dive *d, QString s) const
-{
- free(d->notes);
- d->notes = strdup(qPrintable(s));
-}
-
-QString EditNotes::data(struct dive *d) const
-{
- return QString(d->notes);
-}
-
QString EditNotes::fieldName() const
{
return Command::Base::tr("notes");
}
// ***** Suit *****
-void EditSuit::set(struct dive *d, QString s) const
-{
- free(d->suit);
- d->suit = strdup(qPrintable(s));
-}
-
-QString EditSuit::data(struct dive *d) const
-{
- return QString(d->suit);
-}
-
QString EditSuit::fieldName() const
{
return Command::Base::tr("suit");