From c806406eabc8ce031a37c1063eca6995a89a726e Mon Sep 17 00:00:00 2001 From: hewenfei Date: Mon, 12 Dec 2022 14:18:13 +0800 Subject: [PATCH] =?UTF-8?q?setting=E5=A2=9E=E5=8A=A0=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/settings/settings.cpp | 13 ++++++++++++- src/settings/settings.h | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/settings/settings.cpp b/src/settings/settings.cpp index bca78eb..b1befa7 100644 --- a/src/settings/settings.cpp +++ b/src/settings/settings.cpp @@ -52,7 +52,7 @@ void GlobalSetting::initStyleSetting() connect(settings, &QGSettings::changed, this, [this, settings] (const QString &key) { if (key == UKUI_STYLE_NAME_KEY) { - m_cache.insert(StyleName, settings->get(key)); + updateData(StyleName, settings->get(key)); Q_EMIT styleChanged(StyleName); } }); @@ -61,9 +61,16 @@ void GlobalSetting::initStyleSetting() QVariant GlobalSetting::get(const GlobalSetting::Key& key) { + QMutexLocker locker(&mutex); return m_cache.value(key); } +void GlobalSetting::updateData(const GlobalSetting::Key &key, const QVariant &value) +{ + QMutexLocker locker(&mutex); + m_cache.insert(key, value); +} + MenuSetting *MenuSetting::instance() { static MenuSetting setting(nullptr); @@ -98,11 +105,13 @@ void MenuSetting::initSettings() QVariant MenuSetting::get(const QString &key) { + QMutexLocker locker(&mutex); return m_cache.value(key, {}); } bool MenuSetting::set(const QString &key, const QVariant &value) { + QMutexLocker locker(&mutex); if (m_gSettings) { m_gSettings->set(key, value); // m_cache.insert(key,value); @@ -115,7 +124,9 @@ bool MenuSetting::set(const QString &key, const QVariant &value) void MenuSetting::updateValue(const QString &key) { + mutex.lock(); m_cache.insert(key, m_gSettings->get(key)); + mutex.unlock(); Q_EMIT changed(key); } diff --git a/src/settings/settings.h b/src/settings/settings.h index 2e2bfd2..ed1e631 100644 --- a/src/settings/settings.h +++ b/src/settings/settings.h @@ -22,6 +22,8 @@ #include #include #include +#include +#include #define UKUI_STYLE_VALUE_DARK "ukui-dark" #define UKUI_STYLE_VALUE_LIGHT "ukui-light" @@ -55,8 +57,10 @@ Q_SIGNALS: private: explicit GlobalSetting(QObject *parent = nullptr); void initStyleSetting(); + void updateData(const GlobalSetting::Key& key, const QVariant &value); private: + QMutex mutex; QMap m_cache; }; @@ -83,6 +87,7 @@ private: void initSettings(); private: + QMutex mutex; QMap m_cache; QGSettings *m_gSettings{nullptr}; };