From 84f73a5fb199d79bcf79eaeab52ce1198668c3cb Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 13 Aug 2013 10:30:22 -0300 Subject: 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 --- Makefile | 2 ++ qt-ui/completionmodels.cpp | 38 ++++++++++++++++++++++++++++++++++++++ qt-ui/completionmodels.h | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 qt-ui/completionmodels.cpp create mode 100644 qt-ui/completionmodels.h diff --git a/Makefile b/Makefile index 1936de901..ef86c93a0 100644 --- a/Makefile +++ b/Makefile @@ -56,6 +56,7 @@ HEADERS = \ qt-ui/printdialog.h \ qt-ui/printoptions.h \ qt-ui/printlayout.h \ + qt-ui/completionmodels.h \ SOURCES = \ @@ -100,6 +101,7 @@ SOURCES = \ qt-ui/printdialog.cpp \ qt-ui/printoptions.cpp \ qt-ui/printlayout.cpp \ + qt-ui/completionmodels.cpp \ $(RESFILE) 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 + +#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); + diff --git a/qt-ui/completionmodels.h b/qt-ui/completionmodels.h new file mode 100644 index 000000000..42b81946c --- /dev/null +++ b/qt-ui/completionmodels.h @@ -0,0 +1,34 @@ +#ifndef COMPLETIONMODELS_H +#define COMPLETIONMODELS_H + +#include + +class BuddyCompletionModel : public QStringListModel { + Q_OBJECT +public: + static BuddyCompletionModel* instance(); + void updateModel(); +}; + +class DiveMasterCompletionModel : public QStringListModel { + Q_OBJECT +public: + static DiveMasterCompletionModel* instance(); + void updateModel(); +}; + +class LocationCompletionModel : public QStringListModel { + Q_OBJECT +public: + static LocationCompletionModel* instance(); + void updateModel(); +}; + +class SuitCompletionModel : public QStringListModel { + Q_OBJECT +public: + static SuitCompletionModel* instance(); + void updateModel(); +}; + +#endif -- cgit v1.2.3-70-g09d2