mirror of
https://github.com/QuasarApp/QuasarAppLib.git
synced 2025-04-29 03:04:40 +00:00
Revert "fix subsribe to settings changes"
This reverts commit bd6dd8ecca2c0e2210b55e2fff1a3bee200736bc.
This commit is contained in:
parent
bd6dd8ecca
commit
eb7ba6cfcc
@ -7,46 +7,26 @@
|
|||||||
|
|
||||||
#include "isettings.h"
|
#include "isettings.h"
|
||||||
#include "settingslistner.h"
|
#include "settingslistner.h"
|
||||||
#include "params.h"
|
|
||||||
|
|
||||||
namespace QuasarAppUtils {
|
namespace QuasarAppUtils {
|
||||||
|
|
||||||
SettingsListner::SettingsListner() {
|
SettingsListner::SettingsListner() {
|
||||||
|
|
||||||
|
auto settings = ISettings::instance();
|
||||||
|
if (settings) {
|
||||||
|
|
||||||
|
auto listner = [this](QString key, QVariant val){
|
||||||
|
this->handleSettingsChanged(key, val);
|
||||||
|
};
|
||||||
|
|
||||||
|
_listnerConnection = QObject::connect(settings,
|
||||||
|
&ISettings::valueChanged,
|
||||||
|
listner);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingsListner::~SettingsListner() {
|
SettingsListner::~SettingsListner() {
|
||||||
QObject::disconnect(_listnerConnection);
|
QObject::disconnect(_listnerConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SettingsListner::handleSettings() {
|
|
||||||
|
|
||||||
auto settings = ISettings::instance();
|
|
||||||
if (!settings) {
|
|
||||||
Params::log("Settings object is not initialised!"
|
|
||||||
"please invoke ISettings::init before subscribe",
|
|
||||||
Error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto listner = [this](QString key, QVariant val){
|
|
||||||
this->handleSettingsChanged(key, val);
|
|
||||||
};
|
|
||||||
|
|
||||||
QObject * thiz = dynamic_cast<QObject*>(this);
|
|
||||||
|
|
||||||
if (!thiz) {
|
|
||||||
Params::log("Object that use the SettingsListner should be QObject."
|
|
||||||
"The handleSettingsChanged method will not invoked when settings has changed",
|
|
||||||
Error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_listnerConnection = thiz->connect(settings,
|
|
||||||
&ISettings::valueChanged,
|
|
||||||
thiz, listner,
|
|
||||||
Qt::QueuedConnection);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,12 +24,6 @@ namespace QuasarAppUtils {
|
|||||||
*
|
*
|
||||||
* @code{cpp}
|
* @code{cpp}
|
||||||
* class MyClass : protected QuasarAppUtils::SettingsListner {
|
* class MyClass : protected QuasarAppUtils::SettingsListner {
|
||||||
*
|
|
||||||
* public:
|
|
||||||
* MyClass(){
|
|
||||||
* handleSettings();
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* protected:
|
* protected:
|
||||||
* void handleSettingsChanged(const QString& key, const QVariant& value) override {
|
* void handleSettingsChanged(const QString& key, const QVariant& value) override {
|
||||||
*
|
*
|
||||||
@ -40,9 +34,6 @@ namespace QuasarAppUtils {
|
|||||||
*
|
*
|
||||||
* };
|
* };
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
|
||||||
* @warning For correctly working this handler you should be create a class that inherit of the QObject class else
|
|
||||||
* the SettingsListner::handleSettingsChanged will nit invoked when settings has changed.
|
|
||||||
* @see ISettings
|
* @see ISettings
|
||||||
*/
|
*/
|
||||||
class QUASARAPPSHARED_EXPORT SettingsListner
|
class QUASARAPPSHARED_EXPORT SettingsListner
|
||||||
@ -53,13 +44,6 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief handleSettings This method subscribe this class to listning settings changes.
|
|
||||||
* @return true if subscribed successful else false.
|
|
||||||
* @see SettingsListner::handleSettingsChanged
|
|
||||||
*/
|
|
||||||
bool handleSettings();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief handleSettingsChanged This method will be invoked when settings of application has bean changed.
|
* @brief handleSettingsChanged This method will be invoked when settings of application has bean changed.
|
||||||
* @param key This is key of a changed settings.
|
* @param key This is key of a changed settings.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user