diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-02-27 22:06:05 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-04-02 13:53:23 -0700 |
commit | 77a6bc6d623148632d247048b254e8b8b40c9ab1 (patch) | |
tree | f8b8daee71f4dfeb0e2976459283db5ff5caed37 /qt-models/diveplannermodel.cpp | |
parent | 337d9318ad37e2917672897f2625f78ebe049657 (diff) | |
download | subsurface-77a6bc6d623148632d247048b254e8b8b40c9ab1.tar.gz |
profile/planner: don't update dive in ProfileWidget2::plotDive()
In planner or profile-edit mode, the plotDive() function takes
the current plan and turns it into a dive profile. Not only
is this a layering violation (the display layer modifying the
dive), it is also fundamentally flawed. The control-flow is
out of control, if you wish. There are numerous reasons why
the profile needs to be replot, many of which do not need
a recalculated dive profile.
Move the code that updates the dive-profile to the
DivePlannerPointsModel. Thus, the profile recalculations
and replots can be pooled. This will break the planner, since
there now might be missing calls to the profile recalculation.
But it already has some positive effects: when removing
multiple points, the profile is only recalculated once.
This will need much more work, but it is a start.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/diveplannermodel.cpp')
-rw-r--r-- | qt-models/diveplannermodel.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index 56d22bd15..3cdf3f70b 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -40,6 +40,8 @@ void DivePlannerPointsModel::removeSelectedPoints(const QVector<int> &rows) divepoints.erase(divepoints.begin() + v2[i]); endRemoveRows(); } + updateDiveProfile(); + emitDataChanged(); cylinders.updateTrashIcon(); } @@ -73,7 +75,7 @@ void DivePlannerPointsModel::createSimpleDive(struct dive *dIn) 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(); + updateDiveProfile(); GasSelectionModel::instance()->repopulate(); DiveTypeSelectionModel::instance()->repopulate(); } @@ -170,6 +172,8 @@ void DivePlannerPointsModel::loadFromDive(dive *dIn) recalc = oldRec; DiveTypeSelectionModel::instance()->repopulate(); preserved_until = d->duration; + + updateDiveProfile(); emitDataChanged(); } @@ -753,6 +757,7 @@ void DivePlannerPointsModel::addDefaultStop() void DivePlannerPointsModel::addStop(int milimeters, int seconds) { addStop(milimeters, seconds, -1, 0, true, UNDEF_COMP_TYPE); + updateDiveProfile(); } // cylinderid_in == -1 means same gas as before. @@ -887,6 +892,7 @@ void DivePlannerPointsModel::editStop(int row, divedatapoint newData) if (divepoints[0].cylinderid != old_first_cylid) cylinders.moveAtFirst(divepoints[0].cylinderid); + updateDiveProfile(); emit dataChanged(createIndex(row, 0), createIndex(row, COLUMNS - 1)); } @@ -932,10 +938,14 @@ void DivePlannerPointsModel::remove(const QModelIndex &index) beginRemoveRows(QModelIndex(), index.row(), index.row()); divepoints.remove(index.row()); } + endRemoveRows(); cylinders.updateTrashIcon(); if (divepoints[0].cylinderid != old_first_cylid) cylinders.moveAtFirst(divepoints[0].cylinderid); + + updateDiveProfile(); + emitDataChanged(); } struct diveplan &DivePlannerPointsModel::getDiveplan() @@ -1035,8 +1045,9 @@ void DivePlannerPointsModel::createTemporaryPlan() #endif } -void DivePlannerPointsModel::recalcTemporaryPlan() +void DivePlannerPointsModel::updateDiveProfile() { + createTemporaryPlan(); if (diveplan_empty(&diveplan)) return; @@ -1047,6 +1058,7 @@ void DivePlannerPointsModel::recalcTemporaryPlan() memset(&plan_deco_state, 0, sizeof(struct deco_state)); plan(&plan_deco_state, &diveplan, d, DECOTIMESTEP, stoptable, &cache, isPlanner(), false); + updateMaxDepth(); plan_copy = (struct diveplan *)malloc(sizeof(struct diveplan)); lock_planner(); cloneDiveplan(&diveplan, plan_copy); |