From 1a5e94006c5bcdf648ca791d1d9d1d44f1ec1a03 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 19 Nov 2013 05:00:09 -0800 Subject: 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 --- qt-ui/models.cpp | 14 ++++++++++---- 1 file 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: -- cgit v1.2.3-70-g09d2