From c1dc0c9ce0c0b8482dffba0b7becdec44d6f6bec Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Mon, 23 Jan 2017 17:35:27 +0100 Subject: [PATCH] Allow user to disable a cylinder in planner In the cylinder table, the last column ("use") always showed OC-GAS. Editing was enabled, but the user had to guess to enter a small integer meaning dilluent or CCR oxygen cylingder. I guess, nobody has ever done that. This patch makes this column clickable. A click toggles if the cylinder is used for planning or not. This wait it is much easier to investigate the consequences of gas loss on a plan. Signed-off-by: Robert C. Helling --- core/dive.c | 2 +- core/dive.h | 2 +- qt-models/cylindermodel.cpp | 13 ++++++++++++- qt-models/diveplannermodel.cpp | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/dive.c b/core/dive.c index 75f48e8a9..772b556e5 100644 --- a/core/dive.c +++ b/core/dive.c @@ -30,7 +30,7 @@ static const char *default_tags[] = { }; const char *cylinderuse_text[] = { - QT_TRANSLATE_NOOP("gettextFromC", "OC-gas"), QT_TRANSLATE_NOOP("gettextFromC", "diluent"), QT_TRANSLATE_NOOP("gettextFromC", "oxygen") + QT_TRANSLATE_NOOP("gettextFromC", "OC-gas"), QT_TRANSLATE_NOOP("gettextFromC", "diluent"), QT_TRANSLATE_NOOP("gettextFromC", "oxygen"), QT_TRANSLATE_NOOP("gettextFromC", "not used") }; const char *divemode_text[] = { "OC", "CCR", "PSCR", "Freedive" }; diff --git a/core/dive.h b/core/dive.h index 3a1492ed9..2578850a6 100644 --- a/core/dive.h +++ b/core/dive.h @@ -56,7 +56,7 @@ extern "C" { extern int last_xml_version; enum dive_comp_type {OC, CCR, PSCR, FREEDIVE, NUM_DC_TYPE}; // Flags (Open-circuit and Closed-circuit-rebreather) for setting dive computer type -enum cylinderuse {OC_GAS, DILUENT, OXYGEN, NUM_GAS_USE}; // The different uses for cylinders +enum cylinderuse {OC_GAS, DILUENT, OXYGEN, NOT_USED, NUM_GAS_USE}; // The different uses for cylinders extern const char *cylinderuse_text[]; extern const char *divemode_text[]; diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp index 767ba7621..fe63cf6f2 100644 --- a/qt-models/cylindermodel.cpp +++ b/qt-models/cylindermodel.cpp @@ -480,7 +480,7 @@ void CylindersModel::copyFromDive(dive *d) Qt::ItemFlags CylindersModel::flags(const QModelIndex &index) const { - if (index.column() == REMOVE) + if (index.column() == REMOVE || index.column() == USE) return Qt::ItemIsEnabled; return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; } @@ -488,6 +488,17 @@ Qt::ItemFlags CylindersModel::flags(const QModelIndex &index) const void CylindersModel::remove(const QModelIndex &index) { int mapping[MAX_CYLINDERS]; + + 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; + changed = true; + dataChanged(index, index); + return; + } if (index.column() != REMOVE) { return; } diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index d214ebaac..28941e2e9 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -798,7 +798,7 @@ void DivePlannerPointsModel::createTemporaryPlan() struct divedatapoint *dp = NULL; for (int i = 0; i < MAX_CYLINDERS; i++) { cylinder_t *cyl = &displayed_dive.cylinder[i]; - if (cyl->depth.mm) { + if (cyl->depth.mm && cyl->cylinder_use != NOT_USED) { dp = create_dp(0, cyl->depth.mm, i, 0); if (diveplan.dp) { dp->next = diveplan.dp;