desktop: prevent exit only in plan but not in edit mode

Currently, when the profile is in edit mode, the user can't
save, exit, plan a new dive and is requested to save the
current dive. However, this makes no sense anymore, since
the profile always switches to edit mode when showing a
manually added dive.

If the user has any unsaved profile changes, the usual
dirty checks of the undo-system apply.

Only show above behavior when in the planner. There it is
useful because, these are not included in the undo system.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-03-12 12:48:12 +01:00
parent b1384b286f
commit fd35fbb349
2 changed files with 10 additions and 6 deletions

View file

@ -457,8 +457,7 @@ void MainWindow::on_actionCloudOnline_triggered()
return;
// Refuse to go online if there is an edit in progress
if (!isOffline &&
(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING)) {
if (!isOffline && inPlanner()) {
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before going online"));
// We didn't switch to online, therefore uncheck the checkbox
ui.actionCloudOnline->setChecked(false);
@ -491,7 +490,7 @@ void MainWindow::on_actionCloudOnline_triggered()
bool MainWindow::okToClose(QString message)
{
if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) {
if (inPlanner()) {
QMessageBox::warning(this, tr("Warning"), message);
return false;
}
@ -614,13 +613,18 @@ void MainWindow::on_actionDivelogs_de_triggered()
DivelogsDeWebServices::instance()->downloadDives();
}
bool MainWindow::inPlanner()
{
return DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::PLAN;
}
bool MainWindow::plannerStateClean()
{
if (progressDialog)
// we are accessing the cloud, so let's not switch into Add or Plan mode
return false;
if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) {
if (inPlanner()) {
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to add a dive."));
return false;
}
@ -1031,7 +1035,7 @@ void MainWindow::writeSettings()
void MainWindow::closeEvent(QCloseEvent *event)
{
if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) {
if (inPlanner()) {
on_actionQuit_triggered();
event->ignore();
return;

View file

@ -70,7 +70,6 @@ public:
void importFiles(const QStringList importFiles);
void setToolButtonsEnabled(bool enabled);
void setApplicationState(ApplicationState state);
bool inPlanner();
NotificationWidget *getNotificationWidget();
void enableDisableCloudActions();
void enableDisableOtherDCsActions();
@ -194,6 +193,7 @@ private:
UpdateManager *updateManager;
std::unique_ptr<LocationInformationWidget> diveSiteEdit;
bool inPlanner();
bool plannerStateClean();
void setupSocialNetworkMenu();
QDialog *findMovedImagesDialog;