From e2382e11fdb8c863510ab599830c947419d37ab7 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Sat, 16 Aug 2014 17:11:18 +0200 Subject: [PATCH] Made SettingsDialog::exec() return whether a setting was changed Previously, exec() always returned true and a separate edited() method would indicate whether any settings were changed. --- src/gmenu2x.cpp | 6 +++--- src/settingsdialog.cpp | 10 ++-------- src/settingsdialog.h | 5 ++++- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 269f068..b4ae4ea 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -737,7 +737,7 @@ void GMenu2X::showSettings() { tr["Set button repetitions per second"], &confInt["buttonRepeatRate"], 0, 20))); - if (sd.exec() && sd.edited()) { + if (sd.exec()) { #ifdef ENABLE_CPUFREQ if (curMenuClock != confInt["menuClock"]) setClock(confInt["menuClock"]); #endif @@ -795,7 +795,7 @@ void GMenu2X::skinMenu() { tr["Color of the selection of the message box"], &skinConfColors[COLOR_MESSAGE_BOX_SELECTION]))); - if (sd.exec() && sd.edited()) { + if (sd.exec()) { if (curSkin != confStr["skin"]) { setSkin(confStr["skin"]); writeConfig(); @@ -979,7 +979,7 @@ void GMenu2X::editLink() { &linkApp->consoleApp))); } - if (sd.exec() && sd.edited()) { + if (sd.exec()) { linkApp->setTitle(linkTitle); linkApp->setDescription(linkDescription); linkApp->setIcon(linkIcon); diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index f1cdea5..ee72ae6 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -141,12 +141,6 @@ bool SettingsDialog::exec() { } } - return true; -} - -bool SettingsDialog::edited() { - for (uint i=0; i < settings.size(); i++) { - if (settings[i]->edited()) return true; - } - return false; + return any_of(settings.begin(), settings.end(), + [](unique_ptr& setting){ return setting->edited(); }); } diff --git a/src/settingsdialog.h b/src/settingsdialog.h index d225be7..9e8563d 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -48,7 +48,10 @@ public: settings.push_back(std::move(setting)); } - bool edited(); + /** + * Shows the dialog in a modal way. + * @return true iff any settings were changed. + */ bool exec(); };