From e19344a6bb00305ca254adecf77a77c113bd789a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Wed, 12 Mar 2014 18:08:00 +0100 Subject: [PATCH] Add "Yes to all" and "No to all" options to user data saving dialog on exit --- datamanager.cpp | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/datamanager.cpp b/datamanager.cpp index 0428d7c..3d624ef 100644 --- a/datamanager.cpp +++ b/datamanager.cpp @@ -50,6 +50,9 @@ DataManager::DataManager(QObject* parent) : void DataManager::saveUserDataOnExit() { + enum class Choice { YESTOALL, NOTOALL, ASK }; + Choice c = Choice::ASK; + for (NameSequencePair& nsp : m_sequences) { const QString seqName = nsp.first; std::shared_ptr seq = nsp.second; @@ -57,14 +60,37 @@ void DataManager::saveUserDataOnExit() while (it != seq->end()) { std::shared_ptr sr = it->second; + if (sr->userDataModified()) { - const QString srName = QString::fromStdString(it->first); - int ret = QMessageBox::question(nullptr, "Save changes?" , "User data in sequence " + seqName + ", signal " + srName + " have been modified. " - "Would you like to save the changes?", QMessageBox::Yes, QMessageBox::No); - if (ret == QMessageBox::Yes) + switch (c) { + case Choice::YESTOALL: sr->saveUserDataToJSON(); + break; + case Choice::NOTOALL: + return; + case Choice::ASK: { + const QString srName = QString::fromStdString(it->first); + int ret = QMessageBox::question(nullptr, "Save changes?" , "User data in sequence " + seqName + ", signal " + srName + " have been modified. " + "Would you like to save the changes?", + QMessageBox::YesToAll | QMessageBox::Yes | QMessageBox::No | QMessageBox::NoToAll, + QMessageBox::Yes); + switch (ret) { + case QMessageBox::YesToAll: + c = Choice::YESTOALL; + case QMessageBox::Yes: + sr->saveUserDataToJSON(); + break; + case QMessageBox::NoToAll: + c = Choice::NOTOALL; + break; + default: + break; + } + } } - ++it; + } + + ++it; } } } -- 2.43.5