From eb24d90c8e0aae60c0f0af4a9c7894007be47269 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 3 Jun 2014 19:04:50 -0300 Subject: Add a static 'instance()' member for the Photos model. This will make referencing it from a few places more easy. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/divepicturewidget.cpp | 8 +++++++- qt-ui/divepicturewidget.h | 3 ++- qt-ui/maintab.cpp | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/qt-ui/divepicturewidget.cpp b/qt-ui/divepicturewidget.cpp index e5824e608..5da7c73a4 100644 --- a/qt-ui/divepicturewidget.cpp +++ b/qt-ui/divepicturewidget.cpp @@ -8,7 +8,13 @@ void DivePictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o QStyledItemDelegate::paint(painter, option, index); } -DivePictureModel::DivePictureModel(QObject *parent): QAbstractTableModel(parent) +DivePictureModel *DivePictureModel::instance() +{ + static DivePictureModel* self = new DivePictureModel(); + return self; +} + +DivePictureModel::DivePictureModel() { } diff --git a/qt-ui/divepicturewidget.h b/qt-ui/divepicturewidget.h index 4660bd070..351ae445c 100644 --- a/qt-ui/divepicturewidget.h +++ b/qt-ui/divepicturewidget.h @@ -9,12 +9,13 @@ class DivePictureModel : public QAbstractTableModel { Q_OBJECT public: - DivePictureModel(QObject *parent); + static DivePictureModel *instance(); virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; void updateDivePictures(int divenr); private: + DivePictureModel(); int numberOfPictures; // Currently, load the images on the fly // Later, use a thread to load the images diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index e274b7485..fe579acb9 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -32,7 +32,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), weightModel(new WeightModel(this)), cylindersModel(CylindersModel::instance()), editMode(NONE), - divePictureModel(new DivePictureModel(this)) + divePictureModel(DivePictureModel::instance()) { ui.setupUi(this); -- cgit v1.2.3-70-g09d2