mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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>
This commit is contained in:
parent
10bedf02d0
commit
67d956b44c
1 changed files with 36 additions and 37 deletions
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue