summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-11-12 17:48:54 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-11-14 10:01:50 -0800
commit67d956b44c8d15eb661596ffde31e348fcbe7bb4 (patch)
treee6b4ed1bc0812ed9d815bb26fa687a07b3b5599d
parent10bedf02d03ab0d855385abd233881f56ab7e023 (diff)
downloadsubsurface-67d956b44c8d15eb661596ffde31e348fcbe7bb4.tar.gz
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 <bstoeger@mail.tuwien.ac.at>
-rw-r--r--qt-models/completionmodels.cpp73
1 files 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 <QSet>
#include <QString>
-#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<QString> 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<QString> 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()
{