summaryrefslogtreecommitdiffstats
path: root/qt-ui/completionmodels.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-08-13 10:30:22 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-08-13 10:30:22 -0300
commit84f73a5fb199d79bcf79eaeab52ce1198668c3cb (patch)
tree12df4eefe30a9470be8e7abb1fcc5fb9bebd0d9b /qt-ui/completionmodels.cpp
parent663ab6e23eacd096bb5f64df507c1ee66404f302 (diff)
downloadsubsurface-84f73a5fb199d79bcf79eaeab52ce1198668c3cb.tar.gz
Added classes to handle the Completion of Dive Editions.
Added classes to handle the completion of dive editions, the classes are BuddyCompletionModel, DiveMasterCompletionModel, SuitCompletionModel and LocationCompletionModel, thanks to plain old C macros, code got really small. and I hope the logic is better than the Gtk version. :) Now next step is to integrate it to the Ui. shouldn't be hard. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui/completionmodels.cpp')
-rw-r--r--qt-ui/completionmodels.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/qt-ui/completionmodels.cpp b/qt-ui/completionmodels.cpp
new file mode 100644
index 000000000..a72c1a6c5
--- /dev/null
+++ b/qt-ui/completionmodels.cpp
@@ -0,0 +1,38 @@
+#include "completionmodels.h"
+#include "dive.h"
+#include <boost/graph/graph_concepts.hpp>
+
+#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);
+