From 2e77b47ea120d0bc1b044a651c1ba4239ee66828 Mon Sep 17 00:00:00 2001 From: pajlada Date: Sat, 9 Mar 2024 12:29:25 +0100 Subject: [PATCH] fix: settings "Cancel" button doesn't work first time (#5229) --- CHANGELOG.md | 1 + src/singletons/Settings.cpp | 5 +++++ src/widgets/dialogs/SettingsDialog.cpp | 11 +++-------- src/widgets/settingspages/SettingsPage.cpp | 5 ----- src/widgets/settingspages/SettingsPage.hpp | 3 --- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 731d39a4b..e07661c88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ - Bugfix: Fixed link info not updating without moving the cursor. (#5178) - Bugfix: Fixed an upload sometimes failing when copying an image from a browser if it contained extra properties. (#5156) - Bugfix: Fixed tooltips getting out of bounds when loading images. (#5186) +- Bugfix: Fixed the "Cancel" button in the settings dialog only working after opening the settings dialog twice. (#5229) - Bugfix: Fixed split header tooltips showing in the wrong position on Windows. (#5230) - Bugfix: Fixed split header tooltips appearing too tall. (#5232) - Dev: Run miniaudio in a separate thread, and simplify it to not manage the device ourselves. There's a chance the simplification is a bad idea. (#4978) diff --git a/src/singletons/Settings.cpp b/src/singletons/Settings.cpp index 6cc603c20..b05c13409 100644 --- a/src/singletons/Settings.cpp +++ b/src/singletons/Settings.cpp @@ -8,6 +8,7 @@ #include "controllers/ignores/IgnorePhrase.hpp" #include "controllers/moderationactions/ModerationAction.hpp" #include "controllers/nicknames/Nickname.hpp" +#include "debug/Benchmark.hpp" #include "util/Clamp.hpp" #include "util/PersistSignalVector.hpp" #include "util/WindowsHelper.hpp" @@ -195,6 +196,8 @@ Settings::~Settings() void Settings::saveSnapshot() { + BenchmarkGuard benchmark("Settings::saveSnapshot"); + rapidjson::Document *d = new rapidjson::Document(rapidjson::kObjectType); rapidjson::Document::AllocatorType &a = d->GetAllocator(); @@ -230,6 +233,8 @@ void Settings::restoreSnapshot() return; } + BenchmarkGuard benchmark("Settings::restoreSnapshot"); + const auto &snapshot = *(this->snapshot_.get()); if (!snapshot.IsObject()) diff --git a/src/widgets/dialogs/SettingsDialog.cpp b/src/widgets/dialogs/SettingsDialog.cpp index c8f7c3b49..49cdf8e35 100644 --- a/src/widgets/dialogs/SettingsDialog.cpp +++ b/src/widgets/dialogs/SettingsDialog.cpp @@ -341,6 +341,9 @@ void SettingsDialog::showDialog(QWidget *parent, } hasShownBefore = true; + // Resets the cancel button. + getSettings()->saveSnapshot(); + switch (preferredTab) { case SettingsDialogPreference::Accounts: @@ -379,9 +382,6 @@ void SettingsDialog::showDialog(QWidget *parent, void SettingsDialog::refresh() { - // Resets the cancel button. - getSettings()->saveSnapshot(); - // Updates tabs. for (auto *tab : this->tabs_) { @@ -440,11 +440,6 @@ void SettingsDialog::onOkClicked() void SettingsDialog::onCancelClicked() { - for (auto &tab : this->tabs_) - { - tab->page()->cancel(); - } - getSettings()->restoreSnapshot(); this->close(); diff --git a/src/widgets/settingspages/SettingsPage.cpp b/src/widgets/settingspages/SettingsPage.cpp index c78bddee3..4acf26791 100644 --- a/src/widgets/settingspages/SettingsPage.cpp +++ b/src/widgets/settingspages/SettingsPage.cpp @@ -87,11 +87,6 @@ void SettingsPage::setTab(SettingsDialogTab *tab) this->tab_ = tab; } -void SettingsPage::cancel() -{ - this->onCancel_.invoke(); -} - QCheckBox *SettingsPage::createCheckBox( const QString &text, pajlada::Settings::Setting &setting) { diff --git a/src/widgets/settingspages/SettingsPage.hpp b/src/widgets/settingspages/SettingsPage.hpp index f982114cb..213836fb7 100644 --- a/src/widgets/settingspages/SettingsPage.hpp +++ b/src/widgets/settingspages/SettingsPage.hpp @@ -56,8 +56,6 @@ public: SettingsDialogTab *tab() const; void setTab(SettingsDialogTab *tab); - void cancel(); - QCheckBox *createCheckBox(const QString &text, pajlada::Settings::Setting &setting); QComboBox *createComboBox(const QStringList &items, @@ -86,7 +84,6 @@ public: protected: SettingsDialogTab *tab_{}; - pajlada::Signals::NoArgSignal onCancel_; pajlada::Signals::SignalHolder managedConnections_; };