aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/completionmodels.cpp
blob: 8bd4f5441e63c4ebf928f9453fdb4a822d8c3536 (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
#include "completionmodels.h"
#include "dive.h"

#define CREATE_SINGLETON(X) \
X* X::instance() \
{ \
	static X* self = new X(); \
	return self; \
}

CREATE_SINGLETON(BuddyCompletionModel);
CREATE_SINGLETON(DiveMasterCompletionModel);
CREATE_SINGLETON(LocationCompletionModel);
CREATE_SINGLETON(SuitCompletionModel);

#undef CREATE_SINGLETON

#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); \
		} \
	} \
	setStringList(list); \
}

CREATE_UPDATE_METHOD(BuddyCompletionModel, buddy);
CREATE_UPDATE_METHOD(DiveMasterCompletionModel, divemaster);
CREATE_UPDATE_METHOD(LocationCompletionModel, location);
CREATE_UPDATE_METHOD(SuitCompletionModel, suit);