summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2020-07-11 13:15:21 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-07-11 10:37:49 -0700
commit912e1faaf21afbfac0cec07db036d97b13ed847c (patch)
treebe163ed3780ee79cd2bda0b5a27842cb29516109
parent4ec88aa564d7f5b02fda66342b11ba03fc82d7cf (diff)
downloadsubsurface-912e1faaf21afbfac0cec07db036d97b13ed847c.tar.gz
Make MND display depend on O2 narcotic preference
A while ago, we introduced a preference whether O2 should be considered narcotic. We used this when computing best mix or when entering the He content via MND. But we forgot to make the displayed MND depend on this preference. This patch add this. Fixes #2895 Signed-off-by: Robert C. Helling <helling@atdotde.de>
-rw-r--r--CHANGELOG.md1
-rw-r--r--backend-shared/plannershared.cpp2
-rw-r--r--core/dive.c5
-rw-r--r--qt-models/cylindermodel.cpp6
-rw-r--r--qt-models/cylindermodel.h1
5 files changed, 12 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 924f99933..ebbe1115f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,4 @@
+planner: Honor the "O2 narcotic" preference when computing MND
desktop: fix broken merging of dives with multiple cylinders
mobile: add information about the cloud sync state to the Subsurface plate in the menu
diff --git a/backend-shared/plannershared.cpp b/backend-shared/plannershared.cpp
index 164c4cf46..1f67c2c48 100644
--- a/backend-shared/plannershared.cpp
+++ b/backend-shared/plannershared.cpp
@@ -126,7 +126,7 @@ void PlannerShared::set_o2narcotic(bool value)
{
qPrefDivePlanner::set_o2narcotic(value);
DivePlannerPointsModel::instance()->emitDataChanged();
- DivePlannerPointsModel::instance()->cylindersModel()->updateBestMixes();
+ DivePlannerPointsModel::instance()->cylindersModel()->emitDataChanged();
}
double PlannerShared::bottompo2()
diff --git a/core/dive.c b/core/dive.c
index 427b6a624..b2f29db8b 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -3767,7 +3767,10 @@ depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int rou
pressure_t ppo2n2;
ppo2n2.mbar = depth_to_mbar(end.mm, dive);
- int maxambient = (int)lrint(ppo2n2.mbar / (1 - get_he(mix) / 1000.0));
+ int maxambient = prefs.o2narcotic ?
+ (int)lrint(ppo2n2.mbar / (1 - get_he(mix) / 1000.0))
+ :
+ (int)lrint(ppo2n2.mbar * N2_IN_AIR / (1000 - get_he(mix) - get_o2(mix)));
rounded_depth.mm = (int)lrint(((double)mbar_to_depth(maxambient, dive)) / roundto) * roundto;
return rounded_depth;
}
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index 0055849ff..84e9b063f 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -663,10 +663,14 @@ bool CylindersModel::updateBestMixes()
/* This slot is called when the bottom pO2 and END preferences are updated, we want to
* emit dataChanged so MOD and MND are refreshed, even if the gas mix hasn't been changed */
if (gasUpdated)
- emit dataChanged(createIndex(0, 0), createIndex(d->cylinders.nr - 1, COLUMNS - 1));
+ emitDataChanged();
return gasUpdated;
}
+void CylindersModel::emitDataChanged() {
+ emit dataChanged(createIndex(0, 0), createIndex(d->cylinders.nr - 1, COLUMNS - 1));
+}
+
void CylindersModel::cylindersReset(const QVector<dive *> &dives)
{
// This model only concerns the currently displayed dive. If this is not among the
diff --git a/qt-models/cylindermodel.h b/qt-models/cylindermodel.h
index b8ed7e0eb..e7477193e 100644
--- a/qt-models/cylindermodel.h
+++ b/qt-models/cylindermodel.h
@@ -49,6 +49,7 @@ public:
void moveAtFirst(int cylid);
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
bool updateBestMixes();
+ void emitDataChanged();
bool cylinderUsed(int i) const;
signals: