From f8fbff9f7d1c55434ba8991ad55cd4198df2564d Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 8 Aug 2021 15:22:15 +0200 Subject: [PATCH] profile: set profile-mode in ProfileWidget, not MainWindow The mode of the profile (profile, edit, plan) was set in MainWindow and ProfileWidget. For consistency move the one setProfileState() call from MainWindow to ProfileWidget. This removes a direct access to the profile-view and therefore improves encapsulation. Also, clear the profile, when no dive is shown to remove any potentially dangling references. Signed-off-by: Berthold Stoeger --- desktop-widgets/mainwindow.cpp | 3 +-- desktop-widgets/profilewidget.cpp | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index af5d13e21..2ece1975f 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -577,7 +577,7 @@ void MainWindow::enableShortcuts() void MainWindow::showProfile() { enableShortcuts(); - profile->view->setProfileState(current_dive, dc_number); + profile->plotCurrentDive(); setApplicationState(ApplicationState::Default); } @@ -629,7 +629,6 @@ bool MainWindow::plannerStateClean() void MainWindow::refreshProfile() { showProfile(); - profile->plotCurrentDive(); } void MainWindow::planCanceled() diff --git a/desktop-widgets/profilewidget.cpp b/desktop-widgets/profilewidget.cpp index fa264cd70..2de113699 100644 --- a/desktop-widgets/profilewidget.cpp +++ b/desktop-widgets/profilewidget.cpp @@ -197,8 +197,10 @@ void ProfileWidget::plotCurrentDive() ui.profScaled->setDisabled(false); // measuring and scaling ui.profTogglePicture->setDisabled(false); ui.profHR->setDisabled(false); + view->setProfileState(current_dive, dc_number); view->plotDive(current_dive, dc_number); } else { + view->clear(); stack->setCurrentIndex(0); } }