summaryrefslogtreecommitdiffstats
path: root/qt-models/completionmodels.cpp
blob: 7839398ee15560931e204f661bdd9e6d20398315 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "qt-models/completionmodels.h"
#include "core/dive.h"
#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);                           \
	}

#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(",", QString::SkipEmptyParts)) \
			{                                                                        \
				set.insert(value.trimmed());                                     \
			}                                                                        \
		}                                                                                \
		QStringList setList = set.toList();                                              \
		std::sort(setList.begin(), setList.end());                                       \
		setStringList(setList);                                                     \
	}

CREATE_CSV_UPDATE_METHOD(BuddyCompletionModel, buddy);
CREATE_CSV_UPDATE_METHOD(DiveMasterCompletionModel, divemaster);
CREATE_UPDATE_METHOD(SuitCompletionModel, suit);

void TagCompletionModel::updateModel()
{
	if (g_tag_list == NULL)
		return;
	QStringList list;
	struct tag_entry *current_tag_entry = g_tag_list;
	while (current_tag_entry != NULL) {
		list.append(QString(current_tag_entry->tag->name));
		current_tag_entry = current_tag_entry->next;
	}
	setStringList(list);
}