From 1e3d378ad9464fa49975f967de45272a0c835d9a Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Sat, 21 Jan 2023 13:09:44 +1300 Subject: [PATCH] Cylindermodel: Improve editing of tank use Use the drop down for editing the tank use in the gas list in both the equipment tab and the dive planner. The tank use column is now available in the equipment tab for all dives and not just CCR dives, as 'not used' is a valid entry in both cases. However, if the current dive is an OC dive, only 'OC-gas' and 'not used' are shown. There still seems to be a problem that in some cases, when opening the planner after selecting an existing CCR dive the drop down in the planner does not list CCR gas uses - for some reason `displayed_dive` does not seem to be updated correctly on opening of the planner. But I have not been able to reproduce this consistently, and changing 'Dive mode' fixes this. Signed-off-by: Michael Keller --- CHANGELOG.md | 1 + desktop-widgets/diveplanner.cpp | 1 + desktop-widgets/modeldelegates.cpp | 20 ++++++++++++++++--- .../tab-widgets/TabDiveEquipment.cpp | 5 ----- qt-models/cylindermodel.cpp | 11 +--------- qt-models/diveplannermodel.cpp | 2 +- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12c3bbc9f..ac3538d40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +desktop: use dynamic tank use drop down in equipment tab and planner desktop: fix brightness configuration for OSTC4 equipment: Use 'diluent' as default gas use type if the dive mode is 'CCR' htmlexport: fix search in HTML export diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp index 9cdb3754d..efbcaa088 100644 --- a/desktop-widgets/diveplanner.cpp +++ b/desktop-widgets/diveplanner.cpp @@ -51,6 +51,7 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent) : QWidget(parent, QFlag(0) view->setColumnHidden(CylindersModel::SIZE_INT, true); view->setColumnHidden(CylindersModel::SENSORS, true); view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this)); + view->setItemDelegateForColumn(CylindersModel::USE, new TankUseDelegate(this)); connect(ui.cylinderTableWidget, &TableView::addButtonClicked, plannerModel, &DivePlannerPointsModel::addCylinder_clicked); connect(ui.tableWidget, &TableView::addButtonClicked, plannerModel, &DivePlannerPointsModel::addDefaultStop); connect(cylinders, &CylindersModel::dataChanged, GasSelectionModel::instance(), &GasSelectionModel::repopulate); diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp index a7e3a6be2..d6f2d95e0 100644 --- a/desktop-widgets/modeldelegates.cpp +++ b/desktop-widgets/modeldelegates.cpp @@ -12,6 +12,7 @@ #include "qt-models/tankinfomodel.h" #include "qt-models/weightsysteminfomodel.h" #include "qt-models/weightmodel.h" +#include "qt-models/diveplannermodel.h" #include "qt-models/divetripmodel.h" #include "qt-models/divelocationmodel.h" #include "core/qthelper.h" @@ -254,9 +255,22 @@ TankUseDelegate::TankUseDelegate(QObject *parent) : QStyledItemDelegate(parent) QWidget *TankUseDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const { + struct divecomputer *currentDc; + if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) { + currentDc = &displayed_dive.dc; + } else { + currentDc = get_dive_dc(current_dive, dc_number); + } QComboBox *comboBox = new QComboBox(parent); - for (int i = 0; i < NUM_GAS_USE; i++) - comboBox->addItem(gettextFromC::tr(cylinderuse_text[i])); + if (!currentDc) { + return comboBox; + } + bool isCcrDive = currentDc->divemode == CCR; + for (int i = 0; i < NUM_GAS_USE; i++) { + if (isCcrDive || (i != DILUENT && i != OXYGEN)) { + comboBox->addItem(gettextFromC::tr(cylinderuse_text[i])); + } + } return comboBox; } @@ -270,7 +284,7 @@ void TankUseDelegate::setEditorData(QWidget *editor, const QModelIndex &index) c void TankUseDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { QComboBox *comboBox = qobject_cast(editor); - model->setData(index, comboBox->currentIndex()); + model->setData(index, cylinderuse_from_text(qPrintable(comboBox->currentText()))); } diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp index 2598ce808..2e5f7d937 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp @@ -142,11 +142,6 @@ void TabDiveEquipment::updateData() cylindersModel->updateDive(current_dive); weightModel->updateDive(current_dive); - bool is_ccr = current_dive && get_dive_dc(current_dive, dc_number)->divemode == CCR; - if (is_ccr) - ui.cylinders->view()->showColumn(CylindersModel::USE); - else - ui.cylinders->view()->hideColumn(CylindersModel::USE); if (current_dive && current_dive->suit) ui.suit->setText(QString(current_dive->suit)); else diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp index 6b95b032b..b2512070f 100644 --- a/qt-models/cylindermodel.cpp +++ b/qt-models/cylindermodel.cpp @@ -537,7 +537,7 @@ void CylindersModel::updateDive(dive *dIn) Qt::ItemFlags CylindersModel::flags(const QModelIndex &index) const { - if (index.column() == REMOVE || index.column() == USE) + if (index.column() == REMOVE) return Qt::ItemIsEnabled; return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; } @@ -549,15 +549,6 @@ void CylindersModel::remove(QModelIndex index) { if (!d) return; - if (index.column() == USE) { - cylinder_t *cyl = cylinderAt(index); - if (cyl->cylinder_use == OC_GAS) - cyl->cylinder_use = NOT_USED; - else if (cyl->cylinder_use == NOT_USED) - cyl->cylinder_use = OC_GAS; - dataChanged(index, index); - return; - } if (index.column() != REMOVE) return; diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index b10094194..fcf510f23 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -1042,7 +1042,7 @@ void DivePlannerPointsModel::createTemporaryPlan() struct divedatapoint *dp = NULL; for (int i = 0; i < d->cylinders.nr; i++) { cylinder_t *cyl = get_cylinder(d, i); - if (cyl->depth.mm && cyl->cylinder_use != NOT_USED) { + if (cyl->depth.mm && cyl->cylinder_use == OC_GAS) { dp = create_dp(0, cyl->depth.mm, i, 0); if (diveplan.dp) { dp->next = diveplan.dp;