aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models/diveplannermodel.cpp
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2020-08-22 13:03:51 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-08-24 08:31:40 -0700
commite946ce98feb6144548d0f3a12d8c39b5b2a6d02d (patch)
tree0626dce2c43d886cfae7699f663fc3bf6e47a2b7 /qt-models/diveplannermodel.cpp
parent6ad55cd63b80a19b3e8981fd18fb98a3b28d3df7 (diff)
downloadsubsurface-e946ce98feb6144548d0f3a12d8c39b5b2a6d02d.tar.gz
Planner: enforce minimal segement duration
You cannot be at two depths at the same time (and it confuses the planner). So give yourself at least 10 seconds. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-models/diveplannermodel.cpp')
-rw-r--r--qt-models/diveplannermodel.cpp34
1 files changed, 26 insertions, 8 deletions
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index bdc79c9e6..5be22b08d 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -339,17 +339,35 @@ bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &v
}
break;
case RUNTIME:
- p.time = value.toInt() * 60;
- break;
- case DURATION:
+ {
+ int secs = value.toInt() * 60;
i = index.row();
+ int duration = secs;
if (i)
- shift = divepoints[i].time - divepoints[i - 1].time - value.toInt() * 60;
- else
- shift = divepoints[i].time - value.toInt() * 60;
- while (i < divepoints.size())
- divepoints[i++].time -= shift;
+ duration -= divepoints[i-1].time;
+ // Make sure segments have a minimal duration
+ if (duration <= 0)
+ secs += 10 - duration;
+ p.time = secs;
+ while (++i < divepoints.size())
+ if (divepoints[i].time < divepoints[i - 1].time + 10)
+ divepoints[i].time = divepoints[i - 1].time + 10;
+ }
break;
+ case DURATION:
+ {
+ int secs = value.toInt() * 60;
+ if (!secs)
+ secs = 10;
+ i = index.row();
+ if (i)
+ shift = divepoints[i].time - divepoints[i - 1].time - secs;
+ else
+ shift = divepoints[i].time - secs;
+ while (i < divepoints.size())
+ divepoints[i++].time -= shift;
+ }
+ break;
case CCSETPOINT: {
int po2 = 0;
QByteArray gasv = value.toByteArray();