From 1fb9d6236baad81b95526b5424ca205a36e31072 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 8 Nov 2022 07:48:49 +0100 Subject: [PATCH] planner: initialize dive selection mode in constructor There is no point in repopulating this regularly, as the content does not change. Signed-off-by: Berthold Stoeger --- desktop-widgets/diveplanner.cpp | 2 -- qt-models/models.cpp | 10 ++++------ qt-models/models.h | 6 +----- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp index 390bfd585..eacff368a 100644 --- a/desktop-widgets/diveplanner.cpp +++ b/desktop-widgets/diveplanner.cpp @@ -582,7 +582,6 @@ void PlannerWidgets::planDive() DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); repopulateGasModel(); - diveTypeModel->repopulate(); // TODO: this doesn't change anything!? plannerWidget.setReplanButton(false); plannerWidget.setupStartTime(timestampToDateTime(planned_dive->when)); // This will reload the profile! } @@ -597,7 +596,6 @@ void PlannerWidgets::replanDive(int currentDC) DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); DivePlannerPointsModel::instance()->loadFromDive(planned_dive.get(), currentDC); - diveTypeModel->repopulate(); // TODO: this doesn't change anything!? plannerWidget.setReplanButton(true); plannerWidget.setupStartTime(timestampToDateTime(planned_dive->when)); if (planned_dive->surface_pressure.mbar) diff --git a/qt-models/models.cpp b/qt-models/models.cpp index 9ff9a9a1c..58ce7ca64 100644 --- a/qt-models/models.cpp +++ b/qt-models/models.cpp @@ -25,11 +25,11 @@ void GasSelectionModel::repopulate(const dive *d) QVariant GasSelectionModel::data(const QModelIndex &index, int role) const { - if (role == Qt::FontRole) { + if (role == Qt::FontRole) return defaultModelFont(); - } return QStringListModel::data(index, role); } + // Dive Type Model for the divetype combo box Qt::ItemFlags DiveTypeSelectionModel::flags(const QModelIndex&) const @@ -37,7 +37,7 @@ Qt::ItemFlags DiveTypeSelectionModel::flags(const QModelIndex&) const return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } -void DiveTypeSelectionModel::repopulate() +DiveTypeSelectionModel::DiveTypeSelectionModel() { QStringList modes; for (int i = 0; i < FREEDIVE; i++) @@ -47,13 +47,11 @@ void DiveTypeSelectionModel::repopulate() QVariant DiveTypeSelectionModel::data(const QModelIndex &index, int role) const { - if (role == Qt::FontRole) { + if (role == Qt::FontRole) return defaultModelFont(); - } return QStringListModel::data(index, role); } - // Language Model, The Model to populate the list of possible Languages. LanguageModel *LanguageModel::instance() diff --git a/qt-models/models.h b/qt-models/models.h index b83b0a9f1..d102fc3b5 100644 --- a/qt-models/models.h +++ b/qt-models/models.h @@ -26,19 +26,15 @@ class GasSelectionModel : public QStringListModel { public: Qt::ItemFlags flags(const QModelIndex &index) const; QVariant data(const QModelIndex &index, int role) const override; -public -slots: void repopulate(const dive *d); }; class DiveTypeSelectionModel : public QStringListModel { Q_OBJECT public: + DiveTypeSelectionModel(); Qt::ItemFlags flags(const QModelIndex &index) const; QVariant data(const QModelIndex &index, int role) const override; -public -slots: - void repopulate(); }; class LanguageModel : public QAbstractListModel {