aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-26 07:48:22 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-04-02 13:53:23 -0700
commit1ec0790d504d8a9d5e6694afff04f9ae92d01af8 (patch)
treec799e7bdd7e20303f1030f771058c3561441e409 /desktop-widgets
parente419ebf55a28d2483951e52ca274aedd96f11789 (diff)
downloadsubsurface-1ec0790d504d8a9d5e6694afff04f9ae92d01af8.tar.gz
planner: remove displayed_dive from DivePlannerModel
To remove global state, make the dive that DivePlannerModel works on a member variable. Pass the dive in createSimpleDive() and loadFromDive(). Moreover, this should pave the way to more fine-grained undo in the planner. Ultimately, the planner should not be modal. Attention: for now, the dive must still be displayed_dive, because of the convoluted way in which the profile and the planner work on the same dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/diveplanner.cpp17
-rw-r--r--desktop-widgets/mainwindow.cpp3
2 files changed, 12 insertions, 8 deletions
diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp
index ab2fa8b75..94912cab6 100644
--- a/desktop-widgets/diveplanner.cpp
+++ b/desktop-widgets/diveplanner.cpp
@@ -545,7 +545,7 @@ void PlannerWidgets::planDive()
dc_number = 0;
// create a simple starting dive, using the first gas from the just copied cylinders
- DivePlannerPointsModel::instance()->createSimpleDive();
+ DivePlannerPointsModel::instance()->createSimpleDive(&displayed_dive);
// plan the dive in the same mode as the currently selected one
if (current_dive) {
@@ -563,17 +563,20 @@ void PlannerWidgets::planDive()
void PlannerWidgets::replanDive()
{
+ if (!current_dive)
+ return;
+ copy_dive(current_dive, &displayed_dive); // Planning works on a copy of the dive (for now).
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN);
+ DivePlannerPointsModel::instance()->loadFromDive(&displayed_dive);
MainWindow::instance()->graphics->setPlanState();
plannerWidget.setReplanButton(true);
- plannerWidget.setupStartTime(timestampToDateTime(current_dive->when));
- if (current_dive->surface_pressure.mbar)
- plannerWidget.setSurfacePressure(current_dive->surface_pressure.mbar);
- if (current_dive->salinity)
- plannerWidget.setSalinity(current_dive->salinity);
- DivePlannerPointsModel::instance()->loadFromDive(current_dive);
+ plannerWidget.setupStartTime(timestampToDateTime(displayed_dive.when));
+ if (displayed_dive.surface_pressure.mbar)
+ plannerWidget.setSurfacePressure(displayed_dive.surface_pressure.mbar);
+ if (displayed_dive.salinity)
+ plannerWidget.setSalinity(displayed_dive.salinity);
reset_cylinders(&displayed_dive, true);
DivePlannerPointsModel::instance()->cylindersModel()->updateDive(&displayed_dive);
}
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 2230b05fc..425aaa30f 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -1514,10 +1514,11 @@ void MainWindow::editCurrentDive()
return;
disableShortcuts();
+ copy_dive(current_dive, &displayed_dive); // Work on a copy of the dive
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
graphics->setAddState();
setApplicationState(ApplicationState::EditDive);
- DivePlannerPointsModel::instance()->loadFromDive(current_dive);
+ DivePlannerPointsModel::instance()->loadFromDive(&displayed_dive);
mainTab->enableEdition();
}