From 96a17c9f4069ef3b8af44f6b653de2e9c5f7eb09 Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Mon, 11 May 2020 22:01:05 -0700 Subject: [PATCH] settings: Only save settings for visited pages Set a flag when a page is shown. On apply or accept, only save if that flag is set. --- src/ui/settingspage.cpp | 23 ++++++++++++++++++++--- src/ui/settingspage.h | 7 ++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/ui/settingspage.cpp b/src/ui/settingspage.cpp index dfb32657b..f21affe32 100644 --- a/src/ui/settingspage.cpp +++ b/src/ui/settingspage.cpp @@ -17,18 +17,35 @@ #include "settingsdialog.h" #include "settingspage.h" +#include "core/logging.h" SettingsPage::SettingsPage(SettingsDialog* dialog) - : QWidget(dialog), dialog_(dialog) {} + : QWidget(dialog), maybe_changed_(false), dialog_(dialog) {} + +void SettingsPage::showEvent(QShowEvent* event) { + QWidget::showEvent(event); + maybe_changed_ = true; +} void SettingsPage::Apply() { - Save(); + if (maybe_changed_) { + qLog(Debug) << "Saving" << windowTitle(); + Save(); + if (!isVisible()) + // Don't expect additional changes until the page is visible again. + maybe_changed_ = false; + } } void SettingsPage::Accept() { - Save(); + if (maybe_changed_) { + qLog(Debug) << "Saving" << windowTitle(); + Save(); + maybe_changed_ = false; + } } void SettingsPage::Reject() { Cancel(); + maybe_changed_ = false; } diff --git a/src/ui/settingspage.h b/src/ui/settingspage.h index 22858dc3b..852e2d697 100644 --- a/src/ui/settingspage.h +++ b/src/ui/settingspage.h @@ -45,10 +45,15 @@ class SettingsPage : public QWidget { // The dialog that this page belongs to. SettingsDialog* dialog() const { return dialog_; } -signals: + signals: void NotificationPreview(OSD::Behaviour, QString, QString); void SetWiimotedevInterfaceActived(bool); + protected: + void showEvent(QShowEvent* event); + + bool maybe_changed_; + private: virtual void Save() = 0; virtual void Cancel() {}