mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
97be5fda2c
commit
05098f90cd
2 changed files with 12 additions and 8 deletions
|
@ -903,9 +903,9 @@ void MainWindow::setupForAddAndPlan(const char *model)
|
||||||
|
|
||||||
void MainWindow::on_actionReplanDive_triggered()
|
void MainWindow::on_actionReplanDive_triggered()
|
||||||
{
|
{
|
||||||
if (!plannerStateClean() || !current_dive || !current_dive->dc.model)
|
if (!plannerStateClean() || !current_dive)
|
||||||
return;
|
return;
|
||||||
else if (strcmp(current_dive->dc.model, "planned dive")) {
|
else if (!current_dive->dc.model || strcmp(current_dive->dc.model, "planned dive")) {
|
||||||
if (QMessageBox::warning(this, tr("Warning"), tr("Trying to replan a dive that's not a planned dive."),
|
if (QMessageBox::warning(this, tr("Warning"), tr("Trying to replan a dive that's not a planned dive."),
|
||||||
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel)
|
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "qt-models/cylindermodel.h"
|
#include "qt-models/cylindermodel.h"
|
||||||
#include "core/planner.h"
|
#include "core/planner.h"
|
||||||
#include "qt-models/models.h"
|
#include "qt-models/models.h"
|
||||||
|
#include "core/device.h"
|
||||||
|
|
||||||
/* TODO: Port this to CleanerTableModel to remove a bit of boilerplate and
|
/* TODO: Port this to CleanerTableModel to remove a bit of boilerplate and
|
||||||
* use the signal warningMessage() to communicate errors to the MainWindow.
|
* use the signal warningMessage() to communicate errors to the MainWindow.
|
||||||
|
@ -66,6 +67,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
|
||||||
int depthsum = 0;
|
int depthsum = 0;
|
||||||
int samplecount = 0;
|
int samplecount = 0;
|
||||||
bool oldRec = recalc;
|
bool oldRec = recalc;
|
||||||
|
struct divecomputer *dc = &(d->dc);
|
||||||
recalc = false;
|
recalc = false;
|
||||||
CylindersModel::instance()->updateDive();
|
CylindersModel::instance()->updateDive();
|
||||||
duration_t lasttime = {};
|
duration_t lasttime = {};
|
||||||
|
@ -79,16 +81,18 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
|
||||||
|
|
||||||
bool hasMarkedSamples = false;
|
bool hasMarkedSamples = false;
|
||||||
|
|
||||||
if (d->dc.samples)
|
if (dc->samples)
|
||||||
hasMarkedSamples = d->dc.sample[0].manually_entered;
|
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),
|
// 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.
|
// 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;
|
int j = 0;
|
||||||
for (int i = 0; i < plansamples - 1; i++) {
|
for (int i = 0; i < plansamples - 1; i++) {
|
||||||
while (j * plansamples <= i * d->dc.samples) {
|
while (j * plansamples <= i * dc->samples) {
|
||||||
const sample &s = d->dc.sample[j];
|
const sample &s = dc->sample[j];
|
||||||
if (s.time.seconds != 0 && (!hasMarkedSamples || s.manually_entered)) {
|
if (s.time.seconds != 0 && (!hasMarkedSamples || s.manually_entered)) {
|
||||||
depthsum += s.depth.mm;
|
depthsum += s.depth.mm;
|
||||||
++samplecount;
|
++samplecount;
|
||||||
|
@ -97,7 +101,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
if (samplecount) {
|
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);
|
addStop(depthsum / samplecount, newtime.seconds, cylinderid, 0, true);
|
||||||
lasttime = newtime;
|
lasttime = newtime;
|
||||||
depthsum = 0;
|
depthsum = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue