From 2d68d40b591c4ad360727b245795e61ab9c2f72c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 14 Aug 2021 16:00:42 +0300 Subject: [PATCH] Restore the maybe save warning. --- src/app/puzzle/vpmainwindow.cpp | 68 +++++++++++++++------------------ src/app/puzzle/vpmainwindow.h | 2 +- 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 415b45abe..b5f49c621 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -928,50 +928,42 @@ void VPMainWindow::WriteSettings() } //--------------------------------------------------------------------------------------------------------------------- -bool VPMainWindow::MaybeSave() +auto VPMainWindow::MaybeSave() -> bool { // TODO: Implement maybe save check -// if (this->isWindowModified()) -// { -// if (curFile.isEmpty() && ui->tableWidget->rowCount() == 0) -// { -// return true;// Don't ask if file was created without modifications. -// } + if (this->isWindowModified()) + { + QScopedPointer messageBox(new QMessageBox(tr("Unsaved changes"), + tr("Measurements have been modified.\n" + "Do you want to save your changes?"), + QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No, + QMessageBox::Cancel, this, Qt::Sheet)); -// QScopedPointer messageBox(new QMessageBox(tr("Unsaved changes"), -// tr("Measurements have been modified.\n" -// "Do you want to save your changes?"), -// QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No, -// QMessageBox::Cancel, this, Qt::Sheet)); + messageBox->setDefaultButton(QMessageBox::Yes); + messageBox->setEscapeButton(QMessageBox::Cancel); -// messageBox->setDefaultButton(QMessageBox::Yes); -// messageBox->setEscapeButton(QMessageBox::Cancel); + messageBox->setButtonText(QMessageBox::Yes, curFile.isEmpty() || lIsReadOnly ? tr("Save…") : tr("Save")); + messageBox->setButtonText(QMessageBox::No, tr("Don't Save")); -// messageBox->setButtonText(QMessageBox::Yes, curFile.isEmpty() || mIsReadOnly ? tr("Save…") : tr("Save")); -// messageBox->setButtonText(QMessageBox::No, tr("Don't Save")); + messageBox->setWindowModality(Qt::ApplicationModal); + const auto ret = static_cast(messageBox->exec()); -// messageBox->setWindowModality(Qt::ApplicationModal); -// const auto ret = static_cast(messageBox->exec()); - -// switch (ret) -// { -// case QMessageBox::Yes: -// if (mIsReadOnly) -// { -// return FileSaveAs(); -// } -// else -// { -// return FileSave(); -// } -// case QMessageBox::No: -// return true; -// case QMessageBox::Cancel: -// return false; -// default: -// break; -// } -// } + switch (ret) + { + case QMessageBox::Yes: + if (lIsReadOnly) + { + return on_actionSaveAs_triggered(); + } + return on_actionSave_triggered(); + case QMessageBox::No: + return true; + case QMessageBox::Cancel: + return false; + default: + break; + } + } return true; } diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 995b73359..06997a441 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -544,7 +544,7 @@ private: void ReadSettings(); void WriteSettings(); - bool MaybeSave(); + auto MaybeSave() -> bool; /** * @brief generateTiledPdf Generates the tiled Pdf in the given filename