From 71144265ea09a087b517279d9e1d837d73308780 Mon Sep 17 00:00:00 2001 From: Palo Kisa Date: Mon, 14 Mar 2022 11:44:30 +0100 Subject: [PATCH] panel/plugin: Fix settings storing/restoring - Add emitting settingsChanged() into PluginSettings::loadFromCache() to notify plugin/users, that settings were updated. Previously the signal was probably emitted by the underlying object detecting the settings file changed, but this is not the case any more (probably enhancement in the underlying Qt's QSettings optimization). - Add PlutingSettings::storeToCache() for the plugin configure dialog to be able to store to cache on closing the dialog. - Delete plugin's config dialog before deleting the plugin object itself, as the config dialog can rely/use other plugin objects and deleting/closing the dialog late after plugin object destroyed can cause problems (invalid memory access). --- panel/lxqtpanelpluginconfigdialog.cpp | 9 +++++++++ panel/lxqtpanelpluginconfigdialog.h | 4 ++++ panel/plugin.cpp | 3 ++- panel/pluginsettings.cpp | 9 +++++++++ panel/pluginsettings.h | 1 + 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/panel/lxqtpanelpluginconfigdialog.cpp b/panel/lxqtpanelpluginconfigdialog.cpp index 0978f13a6..a92d46c81 100644 --- a/panel/lxqtpanelpluginconfigdialog.cpp +++ b/panel/lxqtpanelpluginconfigdialog.cpp @@ -58,6 +58,15 @@ PluginSettings& LXQtPanelPluginConfigDialog::settings() const } +/************************************************ + + ************************************************/ +void LXQtPanelPluginConfigDialog::closeEvent(QCloseEvent *event) +{ + mSettings.storeToCache(); + return QDialog::closeEvent(event); +} + /************************************************ diff --git a/panel/lxqtpanelpluginconfigdialog.h b/panel/lxqtpanelpluginconfigdialog.h index 93bd4e0d5..8fdb14e7b 100644 --- a/panel/lxqtpanelpluginconfigdialog.h +++ b/panel/lxqtpanelpluginconfigdialog.h @@ -35,6 +35,7 @@ #include "pluginsettings.h" class QComboBox; +class QCloseEvent; class LXQT_PANEL_API LXQtPanelPluginConfigDialog : public QDialog { @@ -46,6 +47,9 @@ class LXQT_PANEL_API LXQtPanelPluginConfigDialog : public QDialog PluginSettings &settings() const; +protected: + virtual void closeEvent(QCloseEvent *event) override; + protected slots: /* Saves settings in conf file. diff --git a/panel/plugin.cpp b/panel/plugin.cpp index c4d3c440d..25903a100 100644 --- a/panel/plugin.cpp +++ b/panel/plugin.cpp @@ -188,6 +188,8 @@ Plugin::Plugin(const LXQt::PluginInfo &desktopFile, LXQt::Settings *settings, co ************************************************/ Plugin::~Plugin() { + if (mConfigDialog) + delete mConfigDialog.data(); delete mPlugin; delete mPluginLoader; delete mSettings; @@ -515,7 +517,6 @@ void Plugin::showConfigureDialog() if (!mConfigDialog) return; - connect(this, &Plugin::destroyed, mConfigDialog.data(), &QWidget::close); mPanel->willShowWindow(mConfigDialog); mConfigDialog->show(); mConfigDialog->raise(); diff --git a/panel/pluginsettings.cpp b/panel/pluginsettings.cpp index d5a2be958..925db67b1 100644 --- a/panel/pluginsettings.cpp +++ b/panel/pluginsettings.cpp @@ -207,6 +207,15 @@ void PluginSettings::loadFromCache() d->mSettings->beginGroup(d->mGroup); d->mOldSettings.loadToSettings(); d->mSettings->endGroup(); + emit settingsChanged(); +} + +void PluginSettings::storeToCache() +{ + Q_D(PluginSettings); + d->mSettings->beginGroup(d->mGroup); + d->mOldSettings.loadFromSettings(); + d->mSettings->endGroup(); } PluginSettings* PluginSettingsFactory::create(LXQt::Settings *settings, const QString &group, QObject *parent/* = nullptr*/) diff --git a/panel/pluginsettings.h b/panel/pluginsettings.h index 19e5f5f7b..d9b01d554 100644 --- a/panel/pluginsettings.h +++ b/panel/pluginsettings.h @@ -81,6 +81,7 @@ class LXQT_PANEL_API PluginSettings : public QObject void endGroup(); void loadFromCache(); + void storeToCache(); signals: void settingsChanged();