Migrate MainTab models(QStringListModel)

Migrate MainTab models
  from static xxxCompletioModel::instance()
  to private MainTab variable members.

Signed-off-by: Boris Barbulovski <bbarbulovski@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Boris Barbulovski 2014-02-11 18:46:14 +01:00 committed by Dirk Hohndel
parent af8c44fa22
commit 507a929a27
4 changed files with 17 additions and 30 deletions

View file

@ -2,21 +2,6 @@
#include "dive.h" #include "dive.h"
#include "mainwindow.h" #include "mainwindow.h"
#define CREATE_SINGLETON(X) \
X* X::instance() \
{ \
static QScopedPointer<X> self(new X()); \
return self.data(); \
}
CREATE_SINGLETON(BuddyCompletionModel);
CREATE_SINGLETON(DiveMasterCompletionModel);
CREATE_SINGLETON(LocationCompletionModel);
CREATE_SINGLETON(SuitCompletionModel);
CREATE_SINGLETON(TagCompletionModel);
#undef CREATE_SINGLETON
#define CREATE_UPDATE_METHOD(Class, diveStructMember) \ #define CREATE_UPDATE_METHOD(Class, diveStructMember) \
void Class::updateModel() \ void Class::updateModel() \
{ \ { \

View file

@ -6,35 +6,30 @@
class BuddyCompletionModel : public QStringListModel { class BuddyCompletionModel : public QStringListModel {
Q_OBJECT Q_OBJECT
public: public:
static BuddyCompletionModel* instance();
void updateModel(); void updateModel();
}; };
class DiveMasterCompletionModel : public QStringListModel { class DiveMasterCompletionModel : public QStringListModel {
Q_OBJECT Q_OBJECT
public: public:
static DiveMasterCompletionModel* instance();
void updateModel(); void updateModel();
}; };
class LocationCompletionModel : public QStringListModel { class LocationCompletionModel : public QStringListModel {
Q_OBJECT Q_OBJECT
public: public:
static LocationCompletionModel* instance();
void updateModel(); void updateModel();
}; };
class SuitCompletionModel : public QStringListModel { class SuitCompletionModel : public QStringListModel {
Q_OBJECT Q_OBJECT
public: public:
static SuitCompletionModel* instance();
void updateModel(); void updateModel();
}; };
class TagCompletionModel : public QStringListModel { class TagCompletionModel : public QStringListModel {
Q_OBJECT Q_OBJECT
public: public:
static TagCompletionModel* instance();
void updateModel(); void updateModel();
}; };

View file

@ -89,11 +89,11 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui.weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate(this)); ui.weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate(this));
// disabled as this column is pointless outside the disabled planner // disabled as this column is pointless outside the disabled planner
// ui.cylinders->view()->setColumnHidden(CylindersModel::DEPTH, true); // ui.cylinders->view()->setColumnHidden(CylindersModel::DEPTH, true);
completers.buddy = new QCompleter(BuddyCompletionModel::instance(), ui.buddy); completers.buddy = new QCompleter(&buddyModel, ui.buddy);
completers.divemaster = new QCompleter(DiveMasterCompletionModel::instance(), ui.divemaster); completers.divemaster = new QCompleter(&diveMasterModel, ui.divemaster);
completers.location = new QCompleter(LocationCompletionModel::instance(), ui.location); completers.location = new QCompleter(&locationModel, ui.location);
completers.suit = new QCompleter(SuitCompletionModel::instance(), ui.suit); completers.suit = new QCompleter(&suitModel, ui.suit);
completers.tags = new QCompleter(TagCompletionModel::instance(), ui.tagWidget); completers.tags = new QCompleter(&tagModel, ui.tagWidget);
completers.buddy->setCaseSensitivity(Qt::CaseInsensitive); completers.buddy->setCaseSensitivity(Qt::CaseInsensitive);
completers.divemaster->setCaseSensitivity(Qt::CaseInsensitive); completers.divemaster->setCaseSensitivity(Qt::CaseInsensitive);
completers.location->setCaseSensitivity(Qt::CaseInsensitive); completers.location->setCaseSensitivity(Qt::CaseInsensitive);
@ -563,11 +563,11 @@ void MainTab::addWeight_clicked()
void MainTab::reload() void MainTab::reload()
{ {
SuitCompletionModel::instance()->updateModel(); suitModel.updateModel();
BuddyCompletionModel::instance()->updateModel(); buddyModel.updateModel();
LocationCompletionModel::instance()->updateModel(); locationModel.updateModel();
DiveMasterCompletionModel::instance()->updateModel(); diveMasterModel.updateModel();
TagCompletionModel::instance()->updateModel(); tagModel.updateModel();
} }
void MainTab::acceptChanges() void MainTab::acceptChanges()

View file

@ -13,6 +13,7 @@
#include "models.h" #include "models.h"
#include "ui_maintab.h" #include "ui_maintab.h"
#include "completionmodels.h"
class QCompleter; class QCompleter;
struct dive; struct dive;
@ -94,6 +95,12 @@ private:
QMap<dive*, NotesBackup> notesBackup; QMap<dive*, NotesBackup> notesBackup;
EditMode editMode; EditMode editMode;
BuddyCompletionModel buddyModel;
DiveMasterCompletionModel diveMasterModel;
LocationCompletionModel locationModel;
SuitCompletionModel suitModel;
TagCompletionModel tagModel;
/* since the multi-edition of the equipment is fairly more /* since the multi-edition of the equipment is fairly more
* complex than a single item, because it involves a Qt * complex than a single item, because it involves a Qt
* Model to edit things, we are copying the first selected * Model to edit things, we are copying the first selected