Adds fields to the planner cylinder model for maximum operating depth (MOD)
for a bottom mix gas, and maximum narcotic depth (MND). Fields are read/write,
so changing MOD changes %O2 and vice-versa. Changing MND changes %He and
vice-versa.

When setting MOD directly, the %O2 is truncated (rounded down) to an integer,
which re-calculates the MOD, which is sometimes a few metres greater than the
input depth. This is desireable behaviour, as the rounding is conservative.

Signed-off-by: Rick Walsh <[email protected]>
---
 qt-models/cylindermodel.cpp | 35 ++++++++++++++++++++++++-----------
 qt-models/cylindermodel.h   |  2 ++
 2 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index 20b7207..34bf36c 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -12,9 +12,9 @@ CylindersModel::CylindersModel(QObject *parent) :
        changed(false),
        rows(0)
 {
-       //      enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, 
DEPTH};
+       //      enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, 
DEPTH, MOD, MND, USE};
        setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << 
tr("Work press.") << tr("Start press.") << tr("End press.") << tr("O₂%") << 
tr("He%")
-                                                << tr("Switch at") << 
tr("Use"));
+                                                << tr("Switch at") <<tr("Bot. 
MOD") <<tr("MND") << tr("Use"));
 
 }
 
@@ -134,6 +134,14 @@ QVariant CylindersModel::data(const QModelIndex &index, 
int role) const
                case DEPTH:
                        ret = get_depth_string(cyl->depth, true);
                        break;
+               case MOD:
+                       pressure_t modpO2;
+                       modpO2.mbar = prefs.bottompo2;
+                       ret = get_depth_string(gas_mod(&cyl->gasmix, modpO2, 
&displayed_dive, M_OR_FT(1,1)));
+                       break;
+               case MND:
+                       ret = get_depth_string(gas_mnd(&cyl->gasmix, 
prefs.bestmixend, &displayed_dive, M_OR_FT(1,1)));
+                       break;
                case USE:
                        ret = 
gettextFromC::instance()->trGettext(cylinderuse_text[cyl->cylinder_use]);
                        break;
@@ -273,19 +281,24 @@ bool CylindersModel::setData(const QModelIndex &index, 
const QVariant &value, in
                break;
        case DEPTH:
                if (CHANGED()) {
-                       /* Calculate best nitrox mix for cylinder depth if 
input text ends with "bn",
-                        * or best (trimix) mix if input text ends with "b" */
-                       if (vString.toLower().endsWith("bn")) {
-                               cyl->gasmix.o2 = 
best_o2(string_to_depth(vString.toUtf8().data()), &displayed_dive);
-                               cyl->gasmix.he.permille = 0;
-                       } else if (vString.toLower().endsWith("b")) {
-                               cyl->gasmix.o2 = 
best_o2(string_to_depth(vString.toUtf8().data()), &displayed_dive);
-                               cyl->gasmix.he = 
best_He(string_to_depth(vString.toUtf8().data()), &displayed_dive);
-                       }
                        cyl->depth = string_to_depth(vString.toUtf8().data());
                        changed = true;
                }
                break;
+       case MOD:
+               if (CHANGED()) {
+                       // Calculate fO2 for input depth
+                       cyl->gasmix.o2 = 
best_o2(string_to_depth(vString.toUtf8().data()), &displayed_dive);
+                       changed = true;
+               }
+               break;
+       case MND:
+               if (CHANGED()) {
+                       // Calculate fHe for input depth
+                       cyl->gasmix.he = 
best_He(string_to_depth(vString.toUtf8().data()), &displayed_dive);
+                       changed = true;
+               }
+               break;
        case USE:
                if (CHANGED()) {
                        int use = vString.toInt();
diff --git a/qt-models/cylindermodel.h b/qt-models/cylindermodel.h
index 7115dbe..b7c1393 100644
--- a/qt-models/cylindermodel.h
+++ b/qt-models/cylindermodel.h
@@ -19,6 +19,8 @@ public:
                O2,
                HE,
                DEPTH,
+               MOD,
+               MND,
                USE,
                COLUMNS
        };
-- 
2.7.4

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to