Planner: Improve Exit Warning.

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>
This commit is contained in:
Michael Keller 2024-05-16 14:39:43 +12:00
parent b579342639
commit a66bdb1bf5
2 changed files with 28 additions and 10 deletions

View file

@ -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();
@ -986,14 +986,10 @@ 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);
@ -1001,8 +997,17 @@ bool MainWindow::askSaveChanges()
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();
@ -1057,9 +1062,21 @@ void MainWindow::writeSettings()
void MainWindow::closeEvent(QCloseEvent *event)
{
if (inPlanner()) {
on_actionQuit_triggered();
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)) {

View file

@ -178,6 +178,7 @@ private:
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();