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 /profile-widget | |
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 'profile-widget')
-rw-r--r-- | profile-widget/profilewidget2.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 9df668002..ea09ad040 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -542,13 +542,7 @@ void ProfileWidget2::plotDive(const struct dive *dIn, int dcIn, bool force, bool decoModelParameters->setText(QString("GF %1/%2").arg(prefs.gflow).arg(prefs.gfhigh)); #ifndef SUBSURFACE_MOBILE } else { - plannerModel->createTemporaryPlan(); - plannerModel->recalcTemporaryPlan(); struct diveplan &diveplan = plannerModel->getDiveplan(); - if (!diveplan.dp) { - plannerModel->deleteTemporaryPlan(); - return; - } if (decoMode(currentState == PLAN) == VPMB) decoModelParameters->setText(QString("VPM-B +%1").arg(diveplan.vpmb_conservatism)); else @@ -558,7 +552,7 @@ void ProfileWidget2::plotDive(const struct dive *dIn, int dcIn, bool force, bool const struct divecomputer *currentdc = get_dive_dc_const(d, dc); if (!currentdc || !currentdc->samples) - return setEmptyState(); + return; // special handling when switching from empty state animSpeed = instant || currentState == EMPTY ? 0 : qPrefDisplay::animation_speed(); @@ -1742,8 +1736,9 @@ void ProfileWidget2::pointInserted(const QModelIndex &, int from, int to) gases.emplace(gases.begin() + i, createGas()); } - if (plannerModel->recalcQ()) - replot(); + // Note: we don't replot the dive here, because when removing multiple + // points, these might trickle in one-by-one. Instead, the model will + // emit a data-changed signal. } void ProfileWidget2::pointsRemoved(const QModelIndex &, int start, int end) @@ -1752,7 +1747,10 @@ void ProfileWidget2::pointsRemoved(const QModelIndex &, int start, int end) handles.erase(handles.begin() + start, handles.begin() + end + 1); gases.erase(gases.begin() + start, gases.begin() + end + 1); scene()->clearSelection(); - replot(); + + // Note: we don't replot the dive here, because when removing multiple + // points, these might trickle in one-by-one. Instead, the model will + // emit a data-changed signal. } void ProfileWidget2::pointsMoved(const QModelIndex &, int start, int end, const QModelIndex &, int row) |