This fix is reasonably straightforward when the divedatapoint structure stores
the cylinder rather than gasmix.

Fixes #970

Signed-off-by: Rick Walsh <[email protected]>
---
 desktop-widgets/diveplanner.cpp |  3 +++
 qt-models/cylindermodel.cpp     | 16 ++++++++++++++++
 qt-models/cylindermodel.h       |  1 +
 3 files changed, 20 insertions(+)

diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp
index 4e462cc..7ac88f9 100644
--- a/desktop-widgets/diveplanner.cpp
+++ b/desktop-widgets/diveplanner.cpp
@@ -514,7 +514,10 @@ void PlannerSettingsWidget::setBottomPo2(double po2)
 
 void PlannerSettingsWidget::setDecoPo2(double po2)
 {
+       pressure_t olddecopo2;
+       olddecopo2.mbar = prefs.decopo2;
        prefs.decopo2 = (int) (po2 * 1000.0);
+       CylindersModel::instance()->updateDecoDepths(olddecopo2);
 }
 
 void PlannerSettingsWidget::setBestmixEND(int depth)
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index 6ea27f1..8296393 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -426,3 +426,19 @@ void CylindersModel::remove(const QModelIndex &index)
                dc = dc->next;
        }
 }
+
+void CylindersModel::updateDecoDepths(pressure_t olddecopo2)
+{
+       pressure_t decopo2;
+       decopo2.mbar = prefs.decopo2;
+       for (int i = 0; i < MAX_CYLINDERS; i++) {
+               cylinder_t *cyl = &displayed_dive.cylinder[i];
+               struct gasmix *mygas = &cyl->gasmix;
+               /* If the gas's deco MOD matches the old pO2, it will have been 
automatically calculated and should be updated.
+                * If they don't match, we should leave the user entered depth 
as it is */
+               if (cyl->depth.mm == gas_mod(&cyl->gasmix, olddecopo2, 
&displayed_dive, M_OR_FT(3, 10)).mm) {
+                       cyl->depth = gas_mod(&cyl->gasmix, decopo2, 
&displayed_dive, M_OR_FT(3, 10));
+               }
+       }
+       emit dataChanged(createIndex(0, 0), createIndex(MAX_CYLINDERS - 1, 
COLUMNS - 1));
+}
diff --git a/qt-models/cylindermodel.h b/qt-models/cylindermodel.h
index 7115dbe..f2ae012 100644
--- a/qt-models/cylindermodel.h
+++ b/qt-models/cylindermodel.h
@@ -35,6 +35,7 @@ public:
        void clear();
        void updateDive();
        void copyFromDive(struct dive *d);
+       void updateDecoDepths(pressure_t olddecopo2);
        cylinder_t *cylinderAt(const QModelIndex &index);
        bool changed;
 
-- 
2.7.4

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

Reply via email to