summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2016-11-08 21:17:35 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-11-09 06:25:11 -0800
commit05098f90cd89315a618907038e5e625e767e2b0e (patch)
treefdd74d471f76e7f886c3d339f850eb8fb78b7030 /qt-models
parent97be5fda2c9ed3cf135c31a0e2c77107ab2d7eb1 (diff)
downloadsubsurface-05098f90cd89315a618907038e5e625e767e2b0e.tar.gz
Use fake profile when replanning dives without samples
This can happen when the user asks to replan a dive that was imported from CSV. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/diveplannermodel.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index 27797d148..43e4686ff 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -4,6 +4,7 @@
#include "qt-models/cylindermodel.h"
#include "core/planner.h"
#include "qt-models/models.h"
+#include "core/device.h"
/* TODO: Port this to CleanerTableModel to remove a bit of boilerplate and
* use the signal warningMessage() to communicate errors to the MainWindow.
@@ -66,6 +67,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
int depthsum = 0;
int samplecount = 0;
bool oldRec = recalc;
+ struct divecomputer *dc = &(d->dc);
recalc = false;
CylindersModel::instance()->updateDive();
duration_t lasttime = {};
@@ -79,16 +81,18 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
bool hasMarkedSamples = false;
- if (d->dc.samples)
- hasMarkedSamples = d->dc.sample[0].manually_entered;
+ if (dc->samples)
+ hasMarkedSamples = dc->sample[0].manually_entered;
+ else
+ dc = fake_dc(dc, true);
// if this dive has more than 100 samples (so it is probably a logged dive),
// average samples so we end up with a total of 100 samples.
- int plansamples = d->dc.samples <= 100 ? d->dc.samples : 100;
+ int plansamples = dc->samples <= 100 ? dc->samples : 100;
int j = 0;
for (int i = 0; i < plansamples - 1; i++) {
- while (j * plansamples <= i * d->dc.samples) {
- const sample &s = d->dc.sample[j];
+ while (j * plansamples <= i * dc->samples) {
+ const sample &s = dc->sample[j];
if (s.time.seconds != 0 && (!hasMarkedSamples || s.manually_entered)) {
depthsum += s.depth.mm;
++samplecount;
@@ -97,7 +101,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
j++;
}
if (samplecount) {
- int cylinderid = get_cylinderid_at_time(d, &d->dc, lasttime);
+ int cylinderid = get_cylinderid_at_time(d, dc, lasttime);
addStop(depthsum / samplecount, newtime.seconds, cylinderid, 0, true);
lasttime = newtime;
depthsum = 0;