From b8c94cad69e59e0b0584c23b39ca9a519c84db94 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Tue, 8 May 2018 17:26:48 +0200 Subject: Planner: Add combo box for dive mode selection I am not really sure what I am doing here but I copied code from the gas selection. Signed-off-by: Robert C. Helling --- qt-models/diveplannermodel.cpp | 1 + qt-models/models.cpp | 30 ++++++++++++++++++++++++++++++ qt-models/models.h | 11 +++++++++++ 3 files changed, 42 insertions(+) (limited to 'qt-models') diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index c86526c1a..7a21ef6ce 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -55,6 +55,7 @@ void DivePlannerPointsModel::createSimpleDive() } updateMaxDepth(); GasSelectionModel::instance()->repopulate(); + DiveTypeSelectionModel::instance()->repopulate(); } void DivePlannerPointsModel::setupStartTime() diff --git a/qt-models/models.cpp b/qt-models/models.cpp index a799b605d..f15073111 100644 --- a/qt-models/models.cpp +++ b/qt-models/models.cpp @@ -67,6 +67,36 @@ QVariant GasSelectionModel::data(const QModelIndex &index, int role) const } return QStringListModel::data(index, role); } +// Dive Type Model for the divetype combo box + +Qt::ItemFlags DiveTypeSelectionModel::flags(const QModelIndex &index) const +{ + Q_UNUSED(index); + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +DiveTypeSelectionModel *DiveTypeSelectionModel::instance() +{ + static DiveTypeSelectionModel self; + return &self; +} + +void DiveTypeSelectionModel::repopulate() +{ + QStringList modes = QStringList(); + for (int i = 0; i < FREEDIVE; i++) + modes.append(QString(divemode_text[i])); + setStringList(modes); +} + +QVariant DiveTypeSelectionModel::data(const QModelIndex &index, int role) const +{ + if (role == Qt::FontRole) { + return defaultModelFont(); + } + return QStringListModel::data(index, role); +} + // Language Model, The Model to populate the list of possible Languages. diff --git a/qt-models/models.h b/qt-models/models.h index ab8130a57..445e3a2a6 100644 --- a/qt-models/models.h +++ b/qt-models/models.h @@ -33,6 +33,17 @@ slots: void repopulate(); }; +class DiveTypeSelectionModel : public QStringListModel { + Q_OBJECT +public: + static DiveTypeSelectionModel *instance(); + Qt::ItemFlags flags(const QModelIndex &index) const; + virtual QVariant data(const QModelIndex &index, int role) const; +public +slots: + void repopulate(); +}; + class LanguageModel : public QAbstractListModel { Q_OBJECT -- cgit v1.2.3-70-g09d2