Fix dive planner sidebar depth units

Linus Torvalds torvalds at linux-foundation.org
Fri Oct 11 16:39:40 UTC 2013


The dive planner always showed the depth in our internal units, ie 
millimeter, in the sidebar that showed the plan points.

That made little sense in metric mode, and none at all in imperial. The 
_graph_ showed things in meter and feet.

So make the DivePlannerPointsModel always convert things to and from the 
user units.

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

This seems to do the right thing. 

 dive.c                | 7 +++++++
 dive.h                | 2 ++
 qt-ui/diveplanner.cpp | 4 ++--
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/dive.c b/dive.c
index c03d124a4344..a98b104125b1 100644
--- a/dive.c
+++ b/dive.c
@@ -101,6 +101,13 @@ double get_volume_units(unsigned int ml, int *frac, const char **units)
 	return vol;
 }
 
+unsigned int units_to_depth(double depth)
+{
+	if (get_units()->length == METERS)
+		return rint(depth * 1000);
+	return feet_to_mm(depth);
+}
+
 double get_depth_units(unsigned int mm, int *frac, const char **units)
 {
 	int decimals;
diff --git a/dive.h b/dive.h
index aec59f6f945c..fd9431a3015e 100644
--- a/dive.h
+++ b/dive.h
@@ -185,6 +185,8 @@ extern double get_temp_units(unsigned int mk, const char **units);
 extern double get_weight_units(unsigned int grams, int *frac, const char **units);
 extern double get_vertical_speed_units(unsigned int mms, int *frac, const char **units);
 
+extern unsigned int units_to_depth(double depth);
+
 static inline double grams_to_lbs(int grams)
 {
 	return grams / 453.6;
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 7c7957e67798..2078ff8a83ed 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -937,7 +937,7 @@ QVariant DivePlannerPointsModel::data(const QModelIndex& index, int role) const
 		divedatapoint p = divepoints.at(index.row());
 		switch(index.column()) {
 			case CCSETPOINT: return p.po2;
-			case DEPTH: return p.depth;
+			case DEPTH: return rint(get_depth_units(p.depth, NULL, NULL));
 			case DURATION: return p.time / 60;
 			case GAS: return strForAir(p);
 		}
@@ -956,7 +956,7 @@ bool DivePlannerPointsModel::setData(const QModelIndex& index, const QVariant& v
 	if(role == Qt::EditRole) {
 		divedatapoint& p = divepoints[index.row()];
 		switch(index.column()) {
-			case DEPTH: p.depth = value.toInt(); break;
+			case DEPTH: p.depth = units_to_depth(value.toInt()); break;
 			case DURATION: p.time = value.toInt() * 60; break;
 			case CCSETPOINT:{
 				int po2 = 0;


More information about the subsurface mailing list