From 5a669b17d9974819bd09af4a2321168398df1156 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 PlutingSettings::storeToCache() for the plugin configure dialog to be able to store to cache on closing the dialog -> after re-showing or showing freshly created one, we expect to be able to reset to the values shown initialy in this 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 | 8 ++++++++ panel/pluginsettings.h | 1 + 5 files changed, 24 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..d9f798443 100644 --- a/panel/pluginsettings.cpp +++ b/panel/pluginsettings.cpp @@ -209,6 +209,14 @@ void PluginSettings::loadFromCache() d->mSettings->endGroup(); } +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*/) { return new PluginSettings{settings, group, parent}; 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();