Skip to content

Commit

Permalink
Planner: Improve Exit Warning.
Browse files Browse the repository at this point in the history
Improve the warning shown to the user when closing the application wile
in the planner. We now allow the user to directly discard the planned
dive, save it into the dive log, or cancel the operation altogether.
If they save into the dive log, or if they modified the dive log before
starting the planner, a second warning about the unsaved dive log
changes will be shown.

Signed-off-by: Michael Keller <mikeller@042.ch>
  • Loading branch information
mikeller committed May 17, 2024
1 parent b579342 commit a66bdb1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
37 changes: 27 additions & 10 deletions desktop-widgets/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ void MainWindow::on_actionPreferences_triggered()

void MainWindow::on_actionQuit_triggered()
{
if (!okToClose(tr("Please save or cancel the current dive edit before quiting the application.")))
if (!okToClose(tr("Please save or cancel the current dive edit before quitting the application.")))
return;

writeSettings();
Expand Down Expand Up @@ -986,23 +986,28 @@ QString MainWindow::filter_import_dive_sites()
return f;
}

bool MainWindow::askSaveChanges()
int MainWindow::saveChangesConfirmationBox(QString message)
{
QMessageBox response(this);

QString message = !existing_filename.empty() ?
tr("Do you want to save the changes that you made in the file %1?").arg(displayedFilename(existing_filename)) :
tr("Do you want to save the changes that you made in the data file?");

response.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
response.setDefaultButton(QMessageBox::Save);
response.setText(message);
response.setWindowTitle(tr("Save changes?")); // Not displayed on MacOSX as described in Qt API
response.setInformativeText(tr("Changes will be lost if you don't save them."));
response.setIcon(QMessageBox::Warning);
response.setWindowModality(Qt::WindowModal);
int ret = response.exec();

return response.exec();
}

bool MainWindow::askSaveChanges()
{
QString message = !existing_filename.empty() ?
tr("Do you want to save the changes that you made in the file %1?").arg(displayedFilename(existing_filename)) :
tr("Do you want to save the changes that you made in the data file?");

int ret = saveChangesConfirmationBox(message);
switch (ret) {
case QMessageBox::Save:
file_save();
Expand Down Expand Up @@ -1057,9 +1062,21 @@ void MainWindow::writeSettings()
void MainWindow::closeEvent(QCloseEvent *event)
{
if (inPlanner()) {
on_actionQuit_triggered();
event->ignore();
return;
int ret = saveChangesConfirmationBox("Do you want to save the changes that you made in the planner into your dive log?");
switch (ret) {
case QMessageBox::Save:
DivePlannerPointsModel::instance()->savePlan();

break;
case QMessageBox::Cancel:
event->ignore();

return;
case QMessageBox::Discard:
DivePlannerPointsModel::instance()->cancelPlan();

break;
}
}

if (!Command::isClean() && (askSaveChanges() == false)) {
Expand Down
1 change: 1 addition & 0 deletions desktop-widgets/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public
QString filter_import_dive_sites();
static MainWindow *m_Instance;
QString displayedFilename(const std::string &fullFilename);
int saveChangesConfirmationBox(QString message);
bool askSaveChanges();
bool okToClose(QString message);
void closeCurrentFile();
Expand Down

0 comments on commit a66bdb1

Please sign in to comment.