From c64e4b159f38ce4e59766a363687ad3170c04cc9 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Sun, 17 Jun 2018 13:41:06 +0200 Subject: Copy divemode to Replan this needs copying the divemode from the dive to the plan. Signed-off-by: Robert C. Helling --- profile-widget/profilewidget2.cpp | 2 +- qt-models/diveplannermodel.cpp | 28 ++++++++++++++++++---------- qt-models/diveplannermodel.h | 2 +- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 4f86760d1..7570e4deb 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -996,7 +996,7 @@ void ProfileWidget2::mouseDoubleClickEvent(QMouseEvent *event) int minutes = lrint(timeAxis->valueAt(mappedPos) / 60); int milimeters = lrint(profileYAxis->valueAt(mappedPos) / M_OR_FT(1, 1)) * M_OR_FT(1, 1); - plannerModel->addStop(milimeters, minutes * 60, -1, 0, true); + plannerModel->addStop(milimeters, minutes * 60, -1, 0, true, UNDEF_COMP_TYPE); } } diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index 5791c3292..b5e34a769 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -46,12 +46,12 @@ void DivePlannerPointsModel::createSimpleDive() // If we're in drop_stone_mode, don't add a first point. // It will be added implicit. if (!prefs.drop_stone_mode) - addStop(M_OR_FT(15, 45), 1 * 60, cylinderid, 0, true); + addStop(M_OR_FT(15, 45), 1 * 60, cylinderid, 0, true, UNDEF_COMP_TYPE); - addStop(M_OR_FT(15, 45), 20 * 60, 0, 0, true); + addStop(M_OR_FT(15, 45), 20 * 60, 0, 0, true, UNDEF_COMP_TYPE); if (!isPlanner()) { - addStop(M_OR_FT(5, 15), 42 * 60, 0, cylinderid, true); - addStop(M_OR_FT(5, 15), 45 * 60, 0, cylinderid, true); + addStop(M_OR_FT(5, 15), 42 * 60, 0, cylinderid, true, UNDEF_COMP_TYPE); + addStop(M_OR_FT(5, 15), 45 * 60, 0, cylinderid, true, UNDEF_COMP_TYPE); } updateMaxDepth(); GasSelectionModel::instance()->repopulate(); @@ -81,6 +81,8 @@ void DivePlannerPointsModel::loadFromDive(dive *d) o2pressure_t last_sp; bool oldRec = recalc; struct divecomputer *dc = &(d->dc); + struct event *evd = NULL; + enum divemode_t current_divemode = UNDEF_COMP_TYPE; recalc = false; CylindersModel::instance()->updateDive(); duration_t lasttime = { 0 }; @@ -124,7 +126,8 @@ void DivePlannerPointsModel::loadFromDive(dive *d) if (samplecount) { cylinderid = get_cylinderid_at_time(d, dc, lasttime); if (newtime.seconds - lastrecordedtime.seconds > 10) { - addStop(depthsum / samplecount, newtime.seconds, cylinderid, last_sp.mbar, true); + current_divemode = get_current_divemode(dc, newtime.seconds + 1, &evd, ¤t_divemode); + addStop(depthsum / samplecount, newtime.seconds, cylinderid, last_sp.mbar, true, current_divemode); lastrecordedtime = newtime; } lasttime = newtime; @@ -133,8 +136,9 @@ void DivePlannerPointsModel::loadFromDive(dive *d) } } // make sure we get the last point right so the duration is correct + current_divemode = get_current_divemode(dc, d->dc.duration.seconds, &evd, ¤t_divemode); if (!hasMarkedSamples && !dc->last_manual_time.seconds) - addStop(0, d->dc.duration.seconds,cylinderid, last_sp.mbar, true); + addStop(0, d->dc.duration.seconds,cylinderid, last_sp.mbar, true, current_divemode); recalc = oldRec; emitDataChanged(); } @@ -668,11 +672,11 @@ int DivePlannerPointsModel::lastEnteredPoint() } // cylinderid_in == -1 means same gas as before. -int DivePlannerPointsModel::addStop(int milimeters, int seconds, int cylinderid_in, int ccpoint, bool entered) +// divemode == UNDEF_COMP_TYPE means determine from previous point. +int DivePlannerPointsModel::addStop(int milimeters, int seconds, int cylinderid_in, int ccpoint, bool entered, enum divemode_t divemode) { int cylinderid = 0; bool usePrevious = false; - enum divemode_t divemode = displayed_dive.dc.divemode; if (cylinderid_in >= 0) cylinderid = cylinderid_in; else @@ -715,12 +719,16 @@ int DivePlannerPointsModel::addStop(int milimeters, int seconds, int cylinderid_ if (usePrevious) { if (row < divepoints.count()) { cylinderid = divepoints.at(row).cylinderid; - divemode = divepoints.at(row).divemode; + if (divemode == UNDEF_COMP_TYPE) + divemode = divepoints.at(row).divemode; } else if (row > 0) { cylinderid = divepoints.at(row - 1).cylinderid; - divemode = divepoints.at(row - 1).divemode; + if (divemode == UNDEF_COMP_TYPE) + divemode = divepoints.at(row - 1).divemode; } } + if (divemode == UNDEF_COMP_TYPE) + divemode = displayed_dive.dc.divemode; // add the new stop beginInsertRows(QModelIndex(), row, row); diff --git a/qt-models/diveplannermodel.h b/qt-models/diveplannermodel.h index 371afb30c..57d1a9c50 100644 --- a/qt-models/diveplannermodel.h +++ b/qt-models/diveplannermodel.h @@ -60,7 +60,7 @@ public: public slots: - int addStop(int millimeters = 0, int seconds = 0, int cylinderid_in = -1, int ccpoint = 0, bool entered = true); + int addStop(int millimeters = 0, int seconds = 0, int cylinderid_in = -1, int ccpoint = 0, bool entered = true, enum divemode_t = UNDEF_COMP_TYPE); void addCylinder_clicked(); void setGFHigh(const int gfhigh); void setGFLow(const int gflow); -- cgit v1.2.3-70-g09d2