From 67d956b44c8d15eb661596ffde31e348fcbe7bb4 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 12 Nov 2020 17:48:54 +0100 Subject: [PATCH] cleanup: remove macros from qt-models/completionmodels.cpp There were macros to auto-generate functions to reload the models. One was only used once and therefore is pointless. The other can be replaced by a function with a pointer-to-member-variable argument. While doing this, adapt the coding style. Signed-off-by: Berthold Stoeger --- qt-models/completionmodels.cpp | 73 +++++++++++++++++----------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/qt-models/completionmodels.cpp b/qt-models/completionmodels.cpp index 701848384..2ed8de204 100644 --- a/qt-models/completionmodels.cpp +++ b/qt-models/completionmodels.cpp @@ -5,51 +5,50 @@ #include #include -#define CREATE_UPDATE_METHOD(Class, diveStructMember) \ - void Class::updateModel() \ - { \ - QStringList list; \ - struct dive *dive; \ - int i = 0; \ - for_each_dive (i, dive) \ - { \ - QString buddy(dive->diveStructMember); \ - if (!list.contains(buddy)) { \ - list.append(buddy); \ - } \ - } \ - std::sort(list.begin(), list.end()); \ - setStringList(list); \ - } - #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) #define SKIP_EMPTY Qt::SkipEmptyParts #else #define SKIP_EMPTY QString::SkipEmptyParts #endif -#define CREATE_CSV_UPDATE_METHOD(Class, diveStructMember) \ - void Class::updateModel() \ - { \ - QSet set; \ - struct dive *dive; \ - int i = 0; \ - for_each_dive (i, dive) \ - { \ - QString buddy(dive->diveStructMember); \ - foreach (const QString &value, buddy.split(",", SKIP_EMPTY)) \ - { \ - set.insert(value.trimmed()); \ - } \ - } \ - QStringList setList = set.values(); \ - std::sort(setList.begin(), setList.end()); \ - setStringList(setList); \ +static QStringList getCSVList(char *dive::*item) +{ + QSet set; + struct dive *dive; + int i = 0; + for_each_dive (i, dive) { + QString str(dive->*item); + for (const QString &value: str.split(",", SKIP_EMPTY)) + set.insert(value.trimmed()); } + QStringList setList = set.values(); + std::sort(setList.begin(), setList.end()); + return setList; +} -CREATE_CSV_UPDATE_METHOD(BuddyCompletionModel, buddy); -CREATE_CSV_UPDATE_METHOD(DiveMasterCompletionModel, divemaster); -CREATE_UPDATE_METHOD(SuitCompletionModel, suit); +void BuddyCompletionModel::updateModel() +{ + setStringList(getCSVList(&dive::buddy)); +} + +void DiveMasterCompletionModel::updateModel() +{ + setStringList(getCSVList(&dive::divemaster)); +} + +void SuitCompletionModel::updateModel() +{ + QStringList list; + struct dive *dive; + int i = 0; + for_each_dive (i, dive) { + QString suit(dive->suit); + if (!list.contains(suit)) + list.append(suit); + } + std::sort(list.begin(), list.end()); + setStringList(list); +} void TagCompletionModel::updateModel() {