Add MOD and MND fields to cylindermodel

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 <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Rick Walsh 2016-07-06 22:40:32 +10:00 committed by Dirk Hohndel
parent 9fbd11744f
commit 6ed5e0d621
2 changed files with 26 additions and 11 deletions

View file

@ -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();

View file

@ -19,6 +19,8 @@ public:
O2,
HE,
DEPTH,
MOD,
MND,
USE,
COLUMNS
};