aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-25 16:03:03 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-04-02 13:53:23 -0700
commit891839d254b8383abea7933ec45aa896d43100c7 (patch)
tree7655dc9ce69cd51079ef4fd15d6d55e65a8d745a /qt-models
parent91136b2c510f4a63d451678deadc2f5c131136aa (diff)
downloadsubsurface-891839d254b8383abea7933ec45aa896d43100c7.tar.gz
planner: move same-time check to DivePlannerPointsModel
There must not be two dive planner points at the same time stamp, as this violates the laws of physics (and internal assumptions). The corresponding test was done in the profile code at two different places with floating point arithmetics. This is a bad idea, because 1) code duplication 2) danger of rounding issues Instead, do this in one central point in the planner model and use integer arithmetics. Simply add a few seconds until a unique timestamp is obtained. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/diveplannermodel.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index f22dd931e..767edc80a 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -844,6 +844,18 @@ void DivePlannerPointsModel::editStop(int row, divedatapoint newData)
*/
int old_first_cylid = divepoints[0].cylinderid;
+ // Refuse creation of two points with the same time stamp.
+ // Note: "time" is moved in the positive direction to avoid
+ // time becoming zero or, worse, negative.
+ while (std::any_of(divepoints.begin(), divepoints.begin() + row,
+ [t = newData.time] (const divedatapoint &data)
+ { return data.time == t; }))
+ newData.time += 10;
+ while (std::any_of(divepoints.begin() + row + 1, divepoints.end(),
+ [t = newData.time] (const divedatapoint &data)
+ { return data.time == t; }))
+ newData.time += 10;
+
// Is it ok to change data first and then move the rows?
divepoints[row] = newData;