Revert "fix subsribe to settings changes"

This reverts commit bd6dd8ecca2c0e2210b55e2fff1a3bee200736bc.
This commit is contained in:
Andrei Yankovich 2021-11-20 13:19:23 +03:00
parent bd6dd8ecca
commit eb7ba6cfcc
2 changed files with 12 additions and 48 deletions

View File

@ -7,46 +7,26 @@
#include "isettings.h"
#include "settingslistner.h"
#include "params.h"
namespace QuasarAppUtils {
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() {
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;
}
}

View File

@ -24,12 +24,6 @@ namespace QuasarAppUtils {
*
* @code{cpp}
* class MyClass : protected QuasarAppUtils::SettingsListner {
*
* public:
* MyClass(){
* handleSettings();
* }
*
* protected:
* void handleSettingsChanged(const QString& key, const QVariant& value) override {
*
@ -40,9 +34,6 @@ namespace QuasarAppUtils {
*
* };
* @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
*/
class QUASARAPPSHARED_EXPORT SettingsListner
@ -53,13 +44,6 @@ public:
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.
* @param key This is key of a changed settings.