2013-08-13 10:30:22 -03:00
|
|
|
#include "completionmodels.h"
|
|
|
|
#include "dive.h"
|
2015-09-02 21:22:29 -03:00
|
|
|
#include <QSet>
|
|
|
|
#include <QString>
|
2013-08-13 10:30:22 -03:00
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
#define CREATE_UPDATE_METHOD(Class, diveStructMember) \
|
|
|
|
void Class::updateModel() \
|
|
|
|
{ \
|
|
|
|
QStringList list; \
|
|
|
|
struct dive *dive; \
|
|
|
|
int i = 0; \
|
2014-05-22 11:40:22 -07:00
|
|
|
for_each_dive (i, dive) \
|
2014-02-27 20:09:57 -08:00
|
|
|
{ \
|
|
|
|
QString buddy(dive->diveStructMember); \
|
|
|
|
if (!list.contains(buddy)) { \
|
|
|
|
list.append(buddy); \
|
|
|
|
} \
|
|
|
|
} \
|
2014-12-10 14:00:08 -02:00
|
|
|
std::sort(list.begin(), list.end()); \
|
2014-02-27 20:09:57 -08:00
|
|
|
setStringList(list); \
|
|
|
|
}
|
2013-08-13 10:30:22 -03:00
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
#define CREATE_CSV_UPDATE_METHOD(Class, diveStructMember) \
|
|
|
|
void Class::updateModel() \
|
|
|
|
{ \
|
|
|
|
QSet<QString> set; \
|
|
|
|
struct dive *dive; \
|
|
|
|
int i = 0; \
|
2014-05-22 11:40:22 -07:00
|
|
|
for_each_dive (i, dive) \
|
2014-02-27 20:09:57 -08:00
|
|
|
{ \
|
|
|
|
QString buddy(dive->diveStructMember); \
|
2014-05-22 11:40:22 -07:00
|
|
|
foreach (const QString &value, buddy.split(",", QString::SkipEmptyParts)) \
|
2014-02-27 20:09:57 -08:00
|
|
|
{ \
|
|
|
|
set.insert(value.trimmed()); \
|
|
|
|
} \
|
|
|
|
} \
|
2014-12-12 11:06:55 -02:00
|
|
|
QStringList setList = set.toList(); \
|
|
|
|
std::sort(setList.begin(), setList.end()); \
|
|
|
|
setStringList(setList); \
|
2014-02-27 20:09:57 -08:00
|
|
|
}
|
2014-01-15 22:35:13 +02:00
|
|
|
|
2014-01-19 19:27:49 +02:00
|
|
|
CREATE_CSV_UPDATE_METHOD(BuddyCompletionModel, buddy);
|
|
|
|
CREATE_CSV_UPDATE_METHOD(DiveMasterCompletionModel, divemaster);
|
2013-08-13 10:30:22 -03:00
|
|
|
CREATE_UPDATE_METHOD(SuitCompletionModel, suit);
|
|
|
|
|
2013-11-02 02:20:02 +01:00
|
|
|
void TagCompletionModel::updateModel()
|
|
|
|
{
|
2014-01-16 11:50:56 +07:00
|
|
|
if (g_tag_list == NULL)
|
2013-11-02 02:20:02 +01:00
|
|
|
return;
|
|
|
|
QStringList list;
|
2015-09-09 20:52:43 +02:00
|
|
|
struct tag_entry *current_tag_entry = g_tag_list;
|
2013-11-02 02:20:02 +01:00
|
|
|
while (current_tag_entry != NULL) {
|
|
|
|
list.append(QString(current_tag_entry->tag->name));
|
|
|
|
current_tag_entry = current_tag_entry->next;
|
|
|
|
}
|
|
|
|
setStringList(list);
|
|
|
|
}
|