From 75814c0fde2fa23f1580338d2e29f9d9a28818db Mon Sep 17 00:00:00 2001 From: Cram42 Date: Sat, 3 Aug 2024 11:54:38 +0800 Subject: [PATCH] Connect onProfileSettingChanged to the Profiles Dialog and emit signal on checkbox values changing. --- src/profilesdialog.cpp | 26 ++++++++++++++++++-------- src/profilesdialog.h | 6 ++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 24eddc204..7d485e44a 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -91,6 +91,8 @@ ProfilesDialog::ProfilesDialog(const QString& profileName, OrganizerCore& organi &OrganizerCore::profileRenamed); connect(this, &ProfilesDialog::profileRemoved, &organizer, &OrganizerCore::profileRemoved); + connect(this, &ProfilesDialog::profileSettingChanged, &organizer, + &OrganizerCore::profileSettingChanged); } ProfilesDialog::~ProfilesDialog() @@ -328,11 +330,14 @@ void ProfilesDialog::on_invalidationBox_stateChanged(int state) } const Profile::Ptr currentProfile = currentItem->data(Qt::UserRole).value(); - if (state == Qt::Unchecked) { - currentProfile->deactivateInvalidation(); - } else { + + bool enable = (state == Qt::Checked); + if (enable) { currentProfile->activateInvalidation(); + } else { + currentProfile->deactivateInvalidation(); } + emit profileSettingChanged(currentProfile.get(), "Invalidation", !enable, enable); } catch (const std::exception& e) { reportError(tr("failed to change archive invalidation state: %1").arg(e.what())); } @@ -396,11 +401,13 @@ void ProfilesDialog::on_localSavesBox_stateChanged(int state) Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value(); - if (currentProfile->enableLocalSaves(state == Qt::Checked)) { - ui->transferButton->setEnabled(state == Qt::Checked); + bool enable = (state == Qt::Checked); + if (currentProfile->enableLocalSaves(enable)) { + ui->transferButton->setEnabled(enable); + emit profileSettingChanged(currentProfile.get(), "LocalSaves", !enable, enable); } else { // revert checkbox-state - ui->localSavesBox->setChecked(state != Qt::Checked); + ui->localSavesBox->setChecked(!enable); } } @@ -417,8 +424,11 @@ void ProfilesDialog::on_localIniFilesBox_stateChanged(int state) Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value(); - if (!currentProfile->enableLocalSettings(state == Qt::Checked)) { + bool enable = (state == Qt::Checked); + if (currentProfile->enableLocalSettings(enable)) { + emit profileSettingChanged(currentProfile.get(), "LocalSettings", !enable, enable); + } else { // revert checkbox-state - ui->localIniFilesBox->setChecked(state != Qt::Checked); + ui->localIniFilesBox->setChecked(!enable); } } diff --git a/src/profilesdialog.h b/src/profilesdialog.h index 1a2a36e24..139133d51 100644 --- a/src/profilesdialog.h +++ b/src/profilesdialog.h @@ -93,6 +93,12 @@ class ProfilesDialog : public MOBase::TutorableDialog */ void profileRemoved(QString const& profileName); + /** + * @brief Signal emitted when a profile's setting has been changed. + */ + void profileSettingChanged(Profile* profile, const QString& settingName, + const QVariant& oldValue, const QVariant& newValue); + protected: virtual void showEvent(QShowEvent* event);