Planner: Improve Gas Handling in CCR Mode.

This has become a bit of a catch-all overhaul of a large portion of the
planner - I started out wanting to improve the CCR mode, but then as I
started pulling all the other threads that needed addressing started to
come with it.

Improve how the gas selection is handled when planning dives in CCR
mode, by making the type (OC / CCR) of segments dependent on the gas use
type that was set for the selected gas.
Add a preference to allow the user to chose to use OC gases as diluent,
in a similar fashion to the original implementation.
Hide gases that cannot be used in the currently selected dive mode in
all drop downs.
Include usage type in gas names if this is needed.
Hide columns and disable elements in the 'Dive planner points' table if
they can they can not be edited in the curently selected dive mode.
Visually identify gases and usage types that are not appropriate for the
currently selected dive mode.
Move the 'Dive mode' selection to the top of the planner view, to
accommodate the fact that this is a property of the dive and not a
planner setting.
Show a warning instead of the dive plan if the plan contains gases that
are not usable in the selected dive mode.
Fix the data entry for the setpoint in the 'Dive planner points' table.
Fix problems with enabling / disabling planner settings when switching
between dive modes.
Refactor some names to make them more appropriate for their current
usage.

One point that is still open is to hide gas usage graphs in the planner
profile if the gas isn't used for OC, as there is no way to meaningfully
interpolate such usage.

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2024-05-15 17:23:39 +12:00
parent 7106c4d5f0
commit 2d8e343221
63 changed files with 678 additions and 383 deletions

View file

@ -23,27 +23,32 @@
#include <QBuffer>
#endif
DivePlannerWidget::DivePlannerWidget(dive &planned_dive, int dcNr, PlannerWidgets *parent)
DivePlannerWidget::DivePlannerWidget(const dive &planned_dive, int &dcNr, PlannerWidgets *parent)
{
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
CylindersModel *cylinders = DivePlannerPointsModel::instance()->cylindersModel();
ui.setupUi(this);
// should be the same order as in dive_comp_type!
QStringList divemodes = QStringList();
for (int i = 0; i < FREEDIVE; i++)
divemodes.append(gettextFromC::tr(divemode_text_ui[i]));
ui.divemode->insertItems(0, divemodes);
ui.tableWidget->setTitle(tr("Dive planner points"));
ui.tableWidget->setBtnToolTip(tr("Add dive data point"));
ui.tableWidget->setModel(plannerModel);
connect(ui.tableWidget, &TableView::itemClicked, plannerModel, &DivePlannerPointsModel::remove);
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(planned_dive, this));
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DIVEMODE, new DiveTypesDelegate(this));
connect(ui.tableWidget, &TableView::addButtonClicked, plannerModel, &DivePlannerPointsModel::addDefaultStop);
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new GasTypesDelegate(planned_dive, dcNr, this));
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DIVEMODE, new DiveTypesDelegate(planned_dive, dcNr, this));
ui.cylinderTableWidget->setTitle(tr("Available gases"));
ui.cylinderTableWidget->setBtnToolTip(tr("Add cylinder"));
ui.cylinderTableWidget->setModel(cylinders);
connect(ui.cylinderTableWidget, &TableView::itemClicked, cylinders, &CylindersModel::remove);
ui.waterType->setItemData(0, FRESHWATER_SALINITY);
ui.waterType->setItemData(1, SEAWATER_SALINITY);
ui.waterType->setItemData(2, EN13319_SALINITY);
waterTypeUpdateTexts();
QTableView *view = ui.cylinderTableWidget->view();
connect(ui.cylinderTableWidget, &TableView::itemClicked, cylinders, &CylindersModel::remove);
view->setColumnHidden(CylindersModel::START, true);
view->setColumnHidden(CylindersModel::END, true);
view->setColumnHidden(CylindersModel::DEPTH, false);
@ -52,18 +57,22 @@ DivePlannerWidget::DivePlannerWidget(dive &planned_dive, int dcNr, PlannerWidget
view->setColumnHidden(CylindersModel::SENSORS, true);
view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this));
auto tankUseDelegate = new TankUseDelegate(this);
tankUseDelegate->setCurrentDC(planned_dive.get_dc(dcNr));
tankUseDelegate->setDiveDc(planned_dive, dcNr);
view->setItemDelegateForColumn(CylindersModel::USE, tankUseDelegate);
connect(ui.cylinderTableWidget, &TableView::addButtonClicked, plannerModel, &DivePlannerPointsModel::addCylinder_clicked);
connect(ui.tableWidget, &TableView::addButtonClicked, plannerModel, &DivePlannerPointsModel::addDefaultStop);
connect(cylinders, &CylindersModel::dataChanged, plannerModel, &DivePlannerPointsModel::emitDataChanged);
connect(cylinders, &CylindersModel::dataChanged, plannerModel, &DivePlannerPointsModel::cylinderModelEdited);
connect(cylinders, &CylindersModel::rowsInserted, plannerModel, &DivePlannerPointsModel::cylinderModelEdited);
connect(cylinders, &CylindersModel::rowsRemoved, plannerModel, &DivePlannerPointsModel::cylinderModelEdited);
ui.tableWidget->setBtnToolTip(tr("Add dive data point"));
ui.waterType->setItemData(0, FRESHWATER_SALINITY);
ui.waterType->setItemData(1, SEAWATER_SALINITY);
ui.waterType->setItemData(2, EN13319_SALINITY);
waterTypeUpdateTexts();
connect(ui.startTime, &QDateEdit::timeChanged, plannerModel, &DivePlannerPointsModel::setStartTime);
connect(ui.dateEdit, &QDateEdit::dateChanged, plannerModel, &DivePlannerPointsModel::setStartDate);
connect(ui.divemode, QOverload<int>::of(&QComboBox::currentIndexChanged), parent, &PlannerWidgets::setDiveMode);
connect(ui.ATMPressure, QOverload<int>::of(&QSpinBox::valueChanged), this, &DivePlannerWidget::atmPressureChanged);
connect(ui.atmHeight, QOverload<int>::of(&QSpinBox::valueChanged), this, &DivePlannerWidget::heightChanged);
connect(ui.waterType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DivePlannerWidget::waterTypeChanged);
@ -77,14 +86,14 @@ DivePlannerWidget::DivePlannerWidget(dive &planned_dive, int dcNr, PlannerWidget
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this);
connect(closeKey, &QShortcut::activated, plannerModel, &DivePlannerPointsModel::cancelPlan);
// This makes shure the spinbox gets a setMinimum(0) on it so we can't have negative time or depth.
// This makes sure the spinbox gets a setMinimum(0) on it so we can't have negative time or depth.
// Limit segments to a depth of 1000 m/3300 ft and a duration of 100 h. Setting the limit for
// the depth will be done in settingChanged() since this depends on the chosen units.
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::RUNTIME, new SpinBoxDelegate(0, INT_MAX, 1, this));
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DURATION, new SpinBoxDelegate(0, 6000, 1, this));
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::CCSETPOINT, new DoubleSpinBoxDelegate(0, 2, 0.01, this));
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &DivePlannerWidget::settingsChanged);
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, parent, &PlannerWidgets::settingsChanged);
/* set defaults. */
ui.ATMPressure->setValue(1013);
@ -116,11 +125,6 @@ void DivePlannerWidget::setSurfacePressure(int surface_pressure)
ui.ATMPressure->setValue(surface_pressure);
}
void PlannerSettingsWidget::setDiveMode(int mode)
{
ui.rebreathermode->setCurrentIndex(mode);
}
void DivePlannerWidget::setSalinity(int salinity)
{
bool mapped = false;
@ -212,7 +216,23 @@ void DivePlannerWidget::customSalinityChanged(double density)
}
}
void PlannerSettingsWidget::disableDecoElements(int mode, divemode_t rebreathermode)
void DivePlannerWidget::setDiveMode(int mode)
{
ui.divemode->setCurrentIndex(mode);
}
void DivePlannerWidget::setColumnVisibility(int mode)
{
ui.tableWidget->view()->setColumnHidden(DivePlannerPointsModel::CCSETPOINT, mode != CCR);
ui.tableWidget->view()->setColumnHidden(DivePlannerPointsModel::DIVEMODE, mode == OC || (mode == CCR && !prefs.allowOcGasAsDiluent));
// This is needed as Qt sets the column width to 0 when hiding a column
ui.tableWidget->view()->setVisible(false); // This will cause the resize to include rows outside the current viewport
ui.tableWidget->view()->resizeColumnsToContents();
ui.tableWidget->view()->setVisible(true);
}
void PlannerSettingsWidget::disableDecoElements(int mode, divemode_t divemode)
{
if (mode == RECREATIONAL) {
ui.label_gflow->setDisabled(false);
@ -265,7 +285,7 @@ void PlannerSettingsWidget::disableDecoElements(int mode, divemode_t rebreatherm
ui.backgasBreaks->setChecked(false);
ui.backgasBreaks->blockSignals(false);
}
ui.bailout->setDisabled(!(rebreathermode == CCR || rebreathermode == PSCR));
ui.bailout->setDisabled(!IS_REBREATHER_MODE(divemode));
ui.bottompo2->setDisabled(false);
ui.decopo2->setDisabled(false);
ui.safetystop->setDisabled(true);
@ -277,7 +297,7 @@ void PlannerSettingsWidget::disableDecoElements(int mode, divemode_t rebreatherm
ui.min_switch_duration->setDisabled(false);
ui.surface_segment->setDisabled(false);
ui.label_min_switch_duration->setDisabled(false);
ui.sacfactor->setDisabled(false);
ui.sacfactor->setDisabled(IS_REBREATHER_MODE(divemode));
ui.problemsolvingtime->setDisabled(false);
ui.sacfactor->setValue(PlannerShared::sacfactor());
ui.problemsolvingtime->setValue(prefs.problemsolvingtime);
@ -299,7 +319,7 @@ void PlannerSettingsWidget::disableDecoElements(int mode, divemode_t rebreatherm
ui.backgasBreaks->setChecked(false);
ui.backgasBreaks->blockSignals(false);
}
ui.bailout->setDisabled(!(rebreathermode == CCR || rebreathermode == PSCR));
ui.bailout->setDisabled(!IS_REBREATHER_MODE(divemode));
ui.bottompo2->setDisabled(false);
ui.decopo2->setDisabled(false);
ui.safetystop->setDisabled(true);
@ -311,7 +331,7 @@ void PlannerSettingsWidget::disableDecoElements(int mode, divemode_t rebreatherm
ui.min_switch_duration->setDisabled(false);
ui.surface_segment->setDisabled(false);
ui.label_min_switch_duration->setDisabled(false);
ui.sacfactor->setDisabled(false);
ui.sacfactor->setDisabled(IS_REBREATHER_MODE(divemode));
ui.problemsolvingtime->setDisabled(false);
ui.sacfactor->setValue(PlannerShared::sacfactor());
ui.problemsolvingtime->setValue(prefs.problemsolvingtime);
@ -359,7 +379,6 @@ PlannerSettingsWidget::PlannerSettingsWidget(PlannerWidgets *parent)
ui.decopo2->setValue(PlannerShared::decopo2());
ui.backgasBreaks->setChecked(prefs.doo2breaks);
PlannerShared::set_dobailout(false);
setBailoutVisibility(false);
ui.o2narcotic->setChecked(prefs.o2narcotic);
ui.drop_stone_mode->setChecked(prefs.drop_stone_mode);
ui.switch_at_req_stop->setChecked(prefs.switch_at_req_stop);
@ -370,12 +389,6 @@ PlannerSettingsWidget::PlannerSettingsWidget(PlannerWidgets *parent)
ui.vpmb_deco->setChecked(prefs.planner_deco_mode == VPMB);
disableDecoElements((int) prefs.planner_deco_mode, OC);
// should be the same order as in dive_comp_type!
QStringList rebreather_modes = QStringList();
for (int i = 0; i < FREEDIVE; i++)
rebreather_modes.append(gettextFromC::tr(divemode_text_ui[i]));
ui.rebreathermode->insertItems(0, rebreather_modes);
connect(ui.recreational_deco, &QAbstractButton::clicked, [] { PlannerShared::set_planner_deco_mode(RECREATIONAL); });
connect(ui.buehlmann_deco, &QAbstractButton::clicked, [] { PlannerShared::set_planner_deco_mode(BUEHLMANN); });
connect(ui.vpmb_deco, &QAbstractButton::clicked, [] { PlannerShared::set_planner_deco_mode(VPMB); });
@ -404,12 +417,10 @@ PlannerSettingsWidget::PlannerSettingsWidget(PlannerWidgets *parent)
connect(ui.switch_at_req_stop, &QAbstractButton::toggled, plannerModel, &DivePlannerPointsModel::setSwitchAtReqStop);
connect(ui.min_switch_duration, QOverload<int>::of(&QSpinBox::valueChanged), &PlannerShared::set_min_switch_duration);
connect(ui.surface_segment, QOverload<int>::of(&QSpinBox::valueChanged), &PlannerShared::set_surface_segment);
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, 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.recreational_deco, &QAbstractButton::clicked, [this, parent] { disableDecoElements(RECREATIONAL, parent->getDiveMode()); });
connect(ui.buehlmann_deco, &QAbstractButton::clicked, [this, parent] { disableDecoElements(BUEHLMANN, parent->getDiveMode()); });
connect(ui.vpmb_deco, &QAbstractButton::clicked, [this, parent] { disableDecoElements(VPMB, parent->getDiveMode()); });
connect(ui.sacfactor, QOverload<double>::of(&QDoubleSpinBox::valueChanged), &PlannerShared::set_sacfactor);
connect(ui.problemsolvingtime, QOverload<int>::of(&QSpinBox::valueChanged), plannerModel, &DivePlannerPointsModel::setProblemSolvingTime);
@ -519,8 +530,9 @@ void PlannerSettingsWidget::setBackgasBreaks(bool dobreaks)
void PlannerSettingsWidget::setBailoutVisibility(int mode)
{
ui.bailout->setDisabled(!(mode == CCR || mode == PSCR));
ui.sacFactor->setDisabled(mode == CCR);
bool isRebreatherMode = IS_REBREATHER_MODE(mode);
ui.bailout->setDisabled(!isRebreatherMode);
ui.sacfactor->setDisabled(isRebreatherMode);
}
PlannerDetails::PlannerDetails(QWidget *parent) : QWidget(parent)
@ -561,7 +573,7 @@ int PlannerWidgets::getDcNr()
return dcNr;
}
divemode_t PlannerWidgets::getRebreatherMode() const
divemode_t PlannerWidgets::getDiveMode() const
{
return planned_dive->get_dc(dcNr)->divemode;
}
@ -575,13 +587,14 @@ void PlannerWidgets::preparePlanDive(const dive *currentDive, int currentDcNr)
// plan the dive in the same mode as the currently selected one
if (currentDive) {
plannerSettingsWidget.setDiveMode(currentDive->get_dc(currentDcNr)->divemode);
plannerSettingsWidget.setBailoutVisibility(currentDive->get_dc(currentDcNr)->divemode);
planned_dive->get_dc(dcNr)->divemode = currentDive->get_dc(currentDcNr)->divemode;
if (currentDive->salinity)
plannerWidget.setSalinity(currentDive->salinity);
else // No salinity means salt water
plannerWidget.setSalinity(SEAWATER_SALINITY);
}
setDiveMode(getDiveMode());
}
void PlannerWidgets::planDive()
@ -589,6 +602,7 @@ void PlannerWidgets::planDive()
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN);
plannerWidget.setReplanButton(false);
plannerWidget.setupStartTime(timestampToDateTime(planned_dive->when)); // This will reload the profile!
}
@ -596,6 +610,8 @@ void PlannerWidgets::prepareReplanDive(const dive *currentDive, int currentDcNr)
{
copy_dive(currentDive, planned_dive.get());
dcNr = currentDcNr;
setDiveMode(getDiveMode());
}
void PlannerWidgets::replanDive()
@ -609,6 +625,7 @@ void PlannerWidgets::replanDive()
plannerWidget.setSurfacePressure(planned_dive->surface_pressure.mbar);
if (planned_dive->salinity)
plannerWidget.setSalinity(planned_dive->salinity);
reset_cylinders(planned_dive.get(), true);
DivePlannerPointsModel::instance()->cylindersModel()->updateDive(planned_dive.get(), dcNr);
}
@ -657,3 +674,16 @@ void PlannerWidgets::printDecoPlan()
plannerDetails.divePlanOutput()->setHtml(origPlan); // restore original plan
#endif
}
void PlannerWidgets::setDiveMode(int mode)
{
DivePlannerPointsModel::instance()->setDiveMode(mode);
plannerWidget.setColumnVisibility(mode);
plannerSettingsWidget.setBailoutVisibility(mode);
}
void PlannerWidgets::settingsChanged()
{
plannerWidget.settingsChanged();
setDiveMode(getDiveMode());
}

View file

@ -18,9 +18,11 @@ struct dive;
class DivePlannerWidget : public QWidget {
Q_OBJECT
public:
explicit DivePlannerWidget(dive &planned_dive, int dcNr, PlannerWidgets *parent);
explicit DivePlannerWidget(const dive &planned_dive, int &dcNr, PlannerWidgets *parent);
~DivePlannerWidget();
void setReplanButton(bool replan);
void setColumnVisibility(int mode);
void setDiveMode(int mode);
public
slots:
void setupStartTime(QDateTime startTime);
@ -48,9 +50,8 @@ public
slots:
void settingsChanged();
void setBackgasBreaks(bool dobreaks);
void disableDecoElements(int mode, divemode_t rebreathermode);
void disableDecoElements(int mode, divemode_t divemode);
void disableBackgasBreaks(bool enabled);
void setDiveMode(int mode);
void setBailoutVisibility(int mode);
private:
@ -86,10 +87,12 @@ public:
void replanDive();
struct dive *getDive() const;
int getDcNr();
divemode_t getRebreatherMode() const;
divemode_t getDiveMode() const;
void settingsChanged();
public
slots:
void printDecoPlan();
void setDiveMode(int mode);
private:
std::unique_ptr<dive> planned_dive;
int dcNr;

View file

@ -62,7 +62,7 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
@ -98,7 +98,30 @@
</property>
</widget>
</item>
<item row="1" column="2" colspan="2">
<item row="0" column="2">
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Dive mode</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="divemode">
<property name="currentText">
<string/>
</property>
<property name="maxVisibleItems">
<number>6</number>
</property>
</widget>
</item>
<item row="1" column="3" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -112,20 +135,20 @@
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Altitude</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>ATM pressure</string>
</property>
</widget>
</item>
<item row="2" column="2">
<item row="2" column="1">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Altitude</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Water type</string>
@ -133,6 +156,25 @@
</widget>
</item>
<item row="3" column="0">
<widget class="QSpinBox" name="ATMPressure">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="suffix">
<string>mbar</string>
</property>
<property name="minimum">
<number>689</number>
</property>
<property name="maximum">
<number>1100</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="atmHeight">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -154,26 +196,7 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="ATMPressure">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="suffix">
<string>mbar</string>
</property>
<property name="minimum">
<number>689</number>
</property>
<property name="maximum">
<number>1100</number>
</property>
</widget>
</item>
<item row="3" column="2">
<item row="3" column="3">
<widget class="QComboBox" name="waterType">
<item>
<property name="text">
@ -197,7 +220,7 @@
</item>
</widget>
</item>
<item row="3" column="3">
<item row="3" column="4">
<widget class="QDoubleSpinBox" name="customSalinity">
<property name="enabled">
<bool>false</bool>
@ -237,7 +260,7 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="4">
<item row="4" column="0" colspan="5">
<widget class="TableView" name="cylinderTableWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
@ -253,7 +276,7 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="4">
<item row="5" column="0" colspan="5">
<widget class="TableView" name="tableWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
@ -285,6 +308,7 @@
</customwidgets>
<tabstops>
<tabstop>startTime</tabstop>
<tabstop>divemode</tabstop>
<tabstop>buttonBox</tabstop>
<tabstop>scrollArea</tabstop>
</tabstops>

View file

@ -688,6 +688,7 @@ void MainWindow::on_actionDivePlanner_triggered()
setApplicationState(ApplicationState::PlanDive);
disableShortcuts(true);
profile->exitEditMode();
plannerWidgets->preparePlanDive(current_dive, profile->dc);
profile->setPlanState(plannerWidgets->getDive(), plannerWidgets->getDcNr());
plannerWidgets->planDive();

View file

@ -246,24 +246,32 @@ void TankInfoDelegate::editorClosed(QWidget *, QAbstractItemDelegate::EndEditHin
mymodel->setData(IDX(CylindersModel::TYPE), currCombo.activeText, CylindersModel::COMMIT_ROLE);
}
TankUseDelegate::TankUseDelegate(QObject *parent) : QStyledItemDelegate(parent), currentdc(nullptr)
TankUseDelegate::TankUseDelegate(QObject *parent) : QStyledItemDelegate(parent), currentDive(nullptr), currentDcNr(0)
{
}
void TankUseDelegate::setCurrentDC(divecomputer *dc)
void TankUseDelegate::setDiveDc(const dive &d, int &dcNr)
{
currentdc = dc;
currentDive = &d;
currentDcNr = &dcNr;
}
QWidget *TankUseDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
{
QComboBox *comboBox = new QComboBox(parent);
if (!currentdc)
const divecomputer *dc = currentDive->get_dc(*currentDcNr);
if (!dc)
return comboBox;
bool isCcrDive = currentdc->divemode == CCR;
bool isCcrDive = dc->divemode == CCR;
bool isFreeDive = dc->divemode == FREEDIVE;
for (int i = 0; i < NUM_GAS_USE; i++) {
if (isCcrDive || (i != DILUENT && i != OXYGEN))
comboBox->addItem(gettextFromC::tr(cylinderuse_text[i]));
if (isFreeDive && i != NOT_USED)
continue;
if (!isCcrDive && (i == DILUENT || i == OXYGEN))
continue;
comboBox->addItem(gettextFromC::tr(cylinderuse_text[i]));
}
return comboBox;
}
@ -350,21 +358,20 @@ WSInfoDelegate::WSInfoDelegate(QObject *parent) : ComboBoxDelegate(&createWSInfo
{
}
void AirTypesDelegate::editorClosed(QWidget *, QAbstractItemDelegate::EndEditHint)
void GasTypesDelegate::editorClosed(QWidget *, QAbstractItemDelegate::EndEditHint)
{
}
void AirTypesDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
void GasTypesDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if (!index.isValid())
return;
QComboBox *combo = qobject_cast<QComboBox *>(editor);
model->setData(index, QVariant(combo->currentIndex()));
model->setData(index, combo->currentData(Qt::UserRole));
}
AirTypesDelegate::AirTypesDelegate(const dive &d, QObject *parent) :
ComboBoxDelegate([&d] (QWidget *parent) { return new GasSelectionModel(d, parent); },
parent, false)
GasTypesDelegate::GasTypesDelegate(const dive &d, int &dcNr, QObject *parent) :
ComboBoxDelegate([&d, &dcNr] (QWidget *parent) { return new GasSelectionModel(d, dcNr, parent); }, parent, false)
{
}
@ -377,15 +384,11 @@ void DiveTypesDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
if (!index.isValid())
return;
QComboBox *combo = qobject_cast<QComboBox *>(editor);
model->setData(index, QVariant(combo->currentIndex()));
model->setData(index, combo->currentData(Qt::UserRole));
}
static QAbstractItemModel *createDiveTypeSelectionModel(QWidget *parent)
{
return new DiveTypeSelectionModel(parent);
}
DiveTypesDelegate::DiveTypesDelegate(QObject *parent) : ComboBoxDelegate(&createDiveTypeSelectionModel, parent, false)
DiveTypesDelegate::DiveTypesDelegate(const dive &d, int &dcNr, QObject *parent) :
ComboBoxDelegate([&d, &dcNr] (QWidget *parent) { return new DiveTypeSelectionModel(d, dcNr, parent); }, parent, false)
{
}

View file

@ -75,12 +75,13 @@ class TankUseDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
explicit TankUseDelegate(QObject *parent = 0);
void setCurrentDC(divecomputer *dc);
void setDiveDc(const dive &d, int &dcNr);
private:
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
divecomputer *currentdc;
const dive *currentDive;
int *currentDcNr;
};
class SensorDelegate : public QStyledItemDelegate {
@ -103,10 +104,10 @@ private:
void editorClosed(QWidget *widget, QAbstractItemDelegate::EndEditHint hint) override;
};
class AirTypesDelegate : public ComboBoxDelegate {
class GasTypesDelegate : public ComboBoxDelegate {
Q_OBJECT
public:
explicit AirTypesDelegate(const dive &d, QObject *parent = 0);
explicit GasTypesDelegate(const dive &d, int &dcNr, QObject *parent = 0);
private:
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
void editorClosed(QWidget *widget, QAbstractItemDelegate::EndEditHint hint) override;
@ -115,7 +116,7 @@ private:
class DiveTypesDelegate : public ComboBoxDelegate {
Q_OBJECT
public:
explicit DiveTypesDelegate(QObject *parent = 0);
explicit DiveTypesDelegate(const dive &d, int &dcNr, QObject *parent = 0);
private:
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
void editorClosed(QWidget *widget, QAbstractItemDelegate::EndEditHint hint) override;

View file

@ -255,7 +255,7 @@
<property name="spacing">
<number>2</number>
</property>
<item row="4" column="2">
<item row="3" column="2">
<widget class="QSpinBox" name="reserve_gas">
<property name="suffix">
<string>bar</string>
@ -274,7 +274,7 @@
</property>
</widget>
</item>
<item row="6" column="1">
<item row="5" column="1">
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -287,7 +287,7 @@
</property>
</spacer>
</item>
<item row="22" column="1" colspan="2">
<item row="21" column="1" colspan="2">
<widget class="QCheckBox" name="switch_at_req_stop">
<property name="toolTip">
<string>Postpone gas change if a stop is not required</string>
@ -297,14 +297,14 @@
</property>
</widget>
</item>
<item row="18" column="1" colspan="2">
<item row="17" column="1" colspan="2">
<widget class="QCheckBox" name="lastStop">
<property name="text">
<string>Last stop at 6m</string>
</property>
</widget>
</item>
<item row="15" column="2">
<item row="14" column="2">
<widget class="QSpinBox" name="vpmb_conservatism">
<property name="prefix">
<string>+</string>
@ -314,7 +314,7 @@
</property>
</widget>
</item>
<item row="12" column="2">
<item row="11" column="2">
<widget class="QSpinBox" name="gfhigh">
<property name="suffix">
<string>%</string>
@ -327,7 +327,7 @@
</property>
</widget>
</item>
<item row="23" column="2">
<item row="22" column="2">
<widget class="QSpinBox" name="min_switch_duration">
<property name="suffix">
<string>min</string>
@ -346,14 +346,14 @@
</property>
</widget>
</item>
<item row="20" column="1" colspan="2">
<item row="19" column="1" colspan="2">
<widget class="QCheckBox" name="backgasBreaks">
<property name="text">
<string>Plan backgas breaks</string>
</property>
</widget>
</item>
<item row="25" column="1">
<item row="24" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -366,21 +366,21 @@
</property>
</spacer>
</item>
<item row="23" column="1">
<item row="22" column="1">
<widget class="QLabel" name="label_min_switch_duration">
<property name="text">
<string>Min. switch duration O₂% below 100%</string>
</property>
</widget>
</item>
<item row="17" column="1" colspan="2">
<item row="16" column="1" colspan="2">
<widget class="QCheckBox" name="drop_stone_mode">
<property name="text">
<string>Drop to first depth</string>
</property>
</widget>
</item>
<item row="11" column="2">
<item row="10" column="2">
<widget class="QSpinBox" name="gflow">
<property name="suffix">
<string>%</string>
@ -393,7 +393,7 @@
</property>
</widget>
</item>
<item row="11" column="1">
<item row="10" column="1">
<widget class="QLabel" name="label_gflow">
<property name="text">
<string>GFLow</string>
@ -403,7 +403,7 @@
</property>
</widget>
</item>
<item row="12" column="1">
<item row="11" column="1">
<widget class="QLabel" name="label_gfhigh">
<property name="text">
<string>GFHigh</string>
@ -413,7 +413,7 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="2" column="1">
<widget class="QRadioButton" name="recreational_deco">
<property name="toolTip">
<string>Maximize bottom time allowed by gas and no decompression limits</string>
@ -423,7 +423,7 @@
</property>
</widget>
</item>
<item row="15" column="1">
<item row="14" column="1">
<widget class="QLabel" name="label_vpmb_conservatism">
<property name="text">
<string>Conservatism level</string>
@ -440,7 +440,7 @@
</property>
</widget>
</item>
<item row="5" column="1" alignment="Qt::AlignHCenter">
<item row="4" column="1" alignment="Qt::AlignHCenter">
<widget class="QCheckBox" name="safetystop">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
@ -453,7 +453,7 @@
</property>
</widget>
</item>
<item row="13" column="1">
<item row="12" column="1">
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -466,7 +466,7 @@
</property>
</spacer>
</item>
<item row="16" column="1">
<item row="15" column="1">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -479,24 +479,7 @@
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="rebreathermode">
<property name="currentText">
<string/>
</property>
<property name="maxVisibleItems">
<number>6</number>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_dive_type">
<property name="text">
<string>Dive mode</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="6" column="1">
<widget class="QRadioButton" name="buehlmann_deco">
<property name="text">
<string>Bühlmann deco</string>
@ -506,7 +489,7 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="3" column="1">
<widget class="QLabel" name="label_reserve_gas">
<property name="text">
<string>Reserve gas</string>
@ -516,21 +499,21 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="0" column="1">
<widget class="QCheckBox" name="bailout">
<property name="text">
<string>Bailout: Deco on OC</string>
<string>Rebreather: Bailout / Deco on OC</string>
</property>
</widget>
</item>
<item row="24" column="1">
<item row="23" column="1">
<widget class="QLabel" name="label_surface_segment">
<property name="text">
<string>Surface segment</string>
</property>
</widget>
</item>
<item row="24" column="2">
<item row="23" column="2">
<widget class="QSpinBox" name="surface_segment">
<property name="suffix">
<string>min</string>
@ -777,7 +760,7 @@
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="sacFactor">
<widget class="QLabel" name="label_sacfactor">
<property name="text">
<string>SAC factor</string>
</property>
@ -857,7 +840,7 @@
<tabstop>ascRateStops</tabstop>
<tabstop>ascRateLast6m</tabstop>
<tabstop>descRate</tabstop>
<tabstop>rebreathermode</tabstop>
<tabstop>divemode</tabstop>
<tabstop>recreational_deco</tabstop>
<tabstop>reserve_gas</tabstop>
<tabstop>safetystop</tabstop>

View file

@ -50,6 +50,7 @@ void PreferencesGraph::refreshSettings()
ui->pscrfactor->setValue(lrint(1000.0 / prefs.pscr_ratio));
ui->show_icd->setChecked(prefs.show_icd);
ui->allowOcGasAsDiluent->setChecked(prefs.allowOcGasAsDiluent);
}
void PreferencesGraph::syncSettings()
@ -75,6 +76,7 @@ void PreferencesGraph::syncSettings()
qPrefTechnicalDetails::set_show_scr_ocpo2(ui->show_scr_ocpo2->isChecked());
qPrefTechnicalDetails::set_show_icd(ui->show_icd->isChecked());
qPrefTechnicalDetails::set_display_deco_mode(ui->vpmb->isChecked() ? VPMB : BUEHLMANN);
qPrefTechnicalDetails::set_allowOcGasAsDiluent(ui->allowOcGasAsDiluent->isChecked());
}
static const char *danger_gf(int gf)

View file

@ -19,7 +19,7 @@
<property name="title">
<string>Gas pressure display setup</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout_1">
<item row="0" column="0">
<widget class="QLabel" name="label_12">
<property name="enabled">
@ -125,21 +125,30 @@
</property>
</widget>
</item>
<item row="4" column="0">
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Rebreather setup</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_26">
<property name="text">
<string>CCR options:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="0" column="1">
<widget class="QLabel" name="label_27">
<property name="text">
<string>Dive planner default setpoint</string>
</property>
</widget>
</item>
<item row="4" column="2">
<item row="0" column="2">
<widget class="QDoubleSpinBox" name="defaultSetpoint">
<property name="suffix">
<string>bar</string>
@ -155,38 +164,35 @@
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<item row="1" column="1" colspan="2">
<widget class="QCheckBox" name="show_ccr_sensors">
<property name="text">
<string>Show O₂ sensor values when viewing pO₂</string>
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<item row="2" column="1" colspan="2">
<widget class="QCheckBox" name="show_ccr_setpoint">
<property name="text">
<string>Show CCR setpoints when viewing pO₂</string>
</property>
</widget>
</item>
<item row="7" column="0">
<item row="3" column="0">
<widget class="QLabel" name="pSCR">
<property name="text">
<string>pSCR options:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="3" column="1">
<widget class="QLabel" name="MetabolicRate">
<property name="text">
<string>pSCR metabolic rate O₂</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="7" column="2">
<item row="3" column="2">
<widget class="QDoubleSpinBox" name="psro2rate">
<property name="suffix">
<string>/min</string>
@ -196,7 +202,7 @@
</property>
</widget>
</item>
<item row="7" column="3">
<item row="3" column="3">
<widget class="QLabel" name="label_28">
<property name="text">
<string>Dilution ratio</string>
@ -206,7 +212,7 @@
</property>
</widget>
</item>
<item row="7" column="4">
<item row="3" column="4">
<widget class="QSpinBox" name="pscrfactor">
<property name="suffix">
<string/>
@ -216,29 +222,45 @@
</property>
</widget>
</item>
<item row="8" column="1">
<item row="4" column="1">
<widget class="QCheckBox" name="show_scr_ocpo2">
<property name="text">
<string>Show equivalent OC pO₂ with pSCR pO₂</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QCheckBox" name="show_icd">
<property name="text">
<string>Show warnings for isobaric counterdiffusion</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>Planner setup</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QCheckBox" name="show_icd">
<property name="text">
<string>Show warnings for isobaric counterdiffusion</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="allowOcGasAsDiluent">
<property name="text">
<string>Allow open circuit gas to be used as diluent for CCR</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
<string>Ceiling display setup</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<layout class="QGridLayout" name="gridLayout_4">
<item row="3" column="3">
<widget class="QLabel" name="label_GFhigh">
<property name="text">

View file

@ -306,7 +306,6 @@ void ProfileWidget::cylindersChanged(struct dive *changed, int pos)
void ProfileWidget::setPlanState(const struct dive *d, int dcNr)
{
exitEditMode();
dc = dcNr;
view->setPlanState(d, dcNr);
setDive(d, dcNr);

View file

@ -26,6 +26,7 @@ public:
void setEnabledToolbar(bool enabled);
void nextDC();
void prevDC();
void exitEditMode();
dive *d;
int dc;
private
@ -45,7 +46,6 @@ private:
QStackedWidget *stack;
void setDive(const struct dive *d, int dcNr);
void editDive();
void exitEditMode();
void rotateDC(int dir);
std::unique_ptr<dive> editedDive;
bool placingCommand;

View file

@ -143,7 +143,7 @@ void TabDiveEquipment::updateData(const std::vector<dive *> &, dive *currentDive
cylindersModel->updateDive(currentDive, currentDC);
weightModel->updateDive(currentDive);
sensorDelegate.setCurrentDC(dc);
tankUseDelegate.setCurrentDC(dc);
tankUseDelegate.setDiveDc(*currentDive, currentDC);
if (currentDive && !currentDive->suit.empty())
ui.suit->setText(QString::fromStdString(currentDive->suit));