summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-19 05:00:09 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-19 05:02:08 -0800
commit1a5e94006c5bcdf648ca791d1d9d1d44f1ec1a03 (patch)
tree4236d0c3135d42e5f5cb7f747c5583b1bf0b04ca
parent4619bfd9ca1d4ee6c32acd8776a4dd460dc3835f (diff)
downloadsubsurface-1a5e94006c5bcdf648ca791d1d9d1d44f1ec1a03.tar.gz
Sanity check on gas percentages
O2 + He + N2 = 100% (well, there are some other gases, but this is close enough) Since N2 can't be negative that means we should refuse any change where O2 + He > 100% (or o2.permille + he.permille > 1000). Fixes #280 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/models.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index b76bd6b8e..2a0f9e98e 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -284,14 +284,20 @@ bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, in
break;
case O2:
if (CHANGED(toDouble, "%", "%")) {
- cyl->gasmix.o2.permille = value.toString().remove('%').toDouble() * 10 + 0.5;
- changed = true;
+ int o2 = value.toString().remove('%').toDouble() * 10 + 0.5;
+ if (cyl->gasmix.he.permille + o2 <= 1000) {
+ cyl->gasmix.o2.permille = o2;
+ changed = true;
+ }
}
break;
case HE:
if (CHANGED(toDouble, "%", "%")) {
- cyl->gasmix.he.permille = value.toString().remove('%').toDouble() * 10 + 0.5;
- changed = true;
+ int he = value.toString().remove('%').toDouble() * 10 + 0.5;
+ if (cyl->gasmix.o2.permille + he <= 1000) {
+ cyl->gasmix.he.permille = he;
+ changed = true;
+ }
}
break;
case DEPTH: