From 91f7689787345735cfaac516ce2e77311f32f011 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 21 Mar 2020 18:30:49 +0100 Subject: 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 --- commands/command_edit.cpp | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'commands/command_edit.cpp') 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::data(struct dive *d) const return d->*PTR; } +template +void EditStringSetter::set(struct dive *d, QString v) const +{ + free(d->*PTR); + d->*PTR = copy_qstring(v); +} + +template +QString EditStringSetter::data(struct dive *d) const +{ + return QString(d->*PTR); +} + static std::vector getDives(bool currentDiveOnly) { if (currentDiveOnly) @@ -176,34 +189,12 @@ void EditBase::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"); -- cgit v1.2.3-70-g09d2