planner: remove getRebreatherMode() from planner-model

There was this completely weird loop that the planner-widget would
call the planner-model to get the current rebreather mode, which
would then access the dive in the planner widget. Just keep those
things in the planner widgets.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-11-08 08:26:06 +01:00 committed by bstoeger
parent 1fb9d6236b
commit e70e3082c9
4 changed files with 17 additions and 16 deletions

View file

@ -216,9 +216,8 @@ void DivePlannerWidget::customSalinityChanged(double density)
}
}
void PlannerSettingsWidget::disableDecoElements(int mode)
void PlannerSettingsWidget::disableDecoElements(int mode, divemode_t rebreathermode)
{
divemode_t rebreathermode = DivePlannerPointsModel::instance()->getRebreatherMode();
if (mode == RECREATIONAL) {
ui.label_gflow->setDisabled(false);
ui.label_gfhigh->setDisabled(false);
@ -342,7 +341,7 @@ void PlannerSettingsWidget::disableBackgasBreaks(bool enabled)
}
}
PlannerSettingsWidget::PlannerSettingsWidget(QWidget *parent) : QWidget(parent, QFlag(0))
PlannerSettingsWidget::PlannerSettingsWidget(PlannerWidgets *parent)
{
ui.setupUi(this);
@ -373,7 +372,7 @@ PlannerSettingsWidget::PlannerSettingsWidget(QWidget *parent) : QWidget(parent,
ui.recreational_deco->setChecked(prefs.planner_deco_mode == RECREATIONAL);
ui.buehlmann_deco->setChecked(prefs.planner_deco_mode == BUEHLMANN);
ui.vpmb_deco->setChecked(prefs.planner_deco_mode == VPMB);
disableDecoElements((int) prefs.planner_deco_mode);
disableDecoElements((int) prefs.planner_deco_mode, OC);
// should be the same order as in dive_comp_type!
QStringList rebreather_modes = QStringList();
@ -412,9 +411,9 @@ PlannerSettingsWidget::PlannerSettingsWidget(QWidget *parent) : QWidget(parent,
connect(ui.rebreathermode, QOverload<int>::of(&QComboBox::currentIndexChanged), plannerModel, &DivePlannerPointsModel::setRebreatherMode);
connect(ui.rebreathermode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &PlannerSettingsWidget::setBailoutVisibility);
connect(ui.recreational_deco, &QAbstractButton::clicked, [this] { disableDecoElements(RECREATIONAL); });
connect(ui.buehlmann_deco, &QAbstractButton::clicked, [this] { disableDecoElements(BUEHLMANN); });
connect(ui.vpmb_deco, &QAbstractButton::clicked, [this] { disableDecoElements(VPMB); });
connect(ui.recreational_deco, &QAbstractButton::clicked, [this, parent] { disableDecoElements(RECREATIONAL, parent->getRebreatherMode()); });
connect(ui.buehlmann_deco, &QAbstractButton::clicked, [this, parent] { disableDecoElements(BUEHLMANN, parent->getRebreatherMode()); });
connect(ui.vpmb_deco, &QAbstractButton::clicked, [this, parent] { disableDecoElements(VPMB, parent->getRebreatherMode()); });
connect(ui.sacfactor, QOverload<double>::of(&QDoubleSpinBox::valueChanged), &PlannerShared::set_sacfactor);
connect(ui.problemsolvingtime, QOverload<int>::of(&QSpinBox::valueChanged), plannerModel, &DivePlannerPointsModel::setProblemSolvingTime);
@ -543,7 +542,8 @@ void PlannerDetails::setPlanNotes(QString plan)
PlannerWidgets::PlannerWidgets() :
planned_dive(alloc_dive()),
plannerWidget(*planned_dive, this)
plannerWidget(*planned_dive, this),
plannerSettingsWidget(this)
{
gasModel = std::make_unique<GasSelectionModel>();
diveTypeModel = std::make_unique<DiveTypeSelectionModel>();
@ -561,6 +561,11 @@ struct dive *PlannerWidgets::getDive() const
return planned_dive.get();
}
divemode_t PlannerWidgets::getRebreatherMode() const
{
return planned_dive->dc.divemode;
}
void PlannerWidgets::preparePlanDive(const dive *currentDive)
{
// create a simple starting dive, using the first gas from the just copied cylinders

View file

@ -2,6 +2,7 @@
#ifndef DIVEPLANNER_H
#define DIVEPLANNER_H
#include "core/divemode.h"
#include "core/owning_ptrs.h"
#include <QAbstractTableModel>
@ -43,13 +44,13 @@ private:
class PlannerSettingsWidget : public QWidget {
Q_OBJECT
public:
explicit PlannerSettingsWidget(QWidget *parent = 0);
explicit PlannerSettingsWidget(PlannerWidgets *parent);
~PlannerSettingsWidget();
public
slots:
void settingsChanged();
void setBackgasBreaks(bool dobreaks);
void disableDecoElements(int mode);
void disableDecoElements(int mode, divemode_t rebreathermode);
void disableBackgasBreaks(bool enabled);
void setDiveMode(int mode);
void setBailoutVisibility(int mode);
@ -86,6 +87,7 @@ public:
void prepareReplanDive(const dive *d); // Make a copy of the dive to be replanned
void replanDive(int currentDC);
struct dive *getDive() const;
divemode_t getRebreatherMode() const;
public
slots:
void printDecoPlan();

View file

@ -542,11 +542,6 @@ void DivePlannerPointsModel::setRebreatherMode(int mode)
emitDataChanged();
}
divemode_t DivePlannerPointsModel::getRebreatherMode() const
{
return d ? d->dc.divemode : OC;
}
void DivePlannerPointsModel::setVpmbConservatism(int level)
{
if (diveplan.vpmb_conservatism != level) {

View file

@ -63,7 +63,6 @@ public:
void loadFromDive(dive *d, int dcNr);
void addStop(int millimeters, int seconds);
divemode_t getRebreatherMode() const;
public
slots:
void addDefaultStop();