4
0
mirror of https://github.com/QuasarApp/QuasarAppLib.git synced 2025-05-08 23:49:41 +00:00

ref Added intarface for settings

This commit is contained in:
IgorekLoschinin 2021-11-06 18:07:15 +03:00
parent bd14ed499f
commit 3994904b0a
2 changed files with 21 additions and 18 deletions

@ -9,7 +9,9 @@
#include <QSettings>
#include <QCoreApplication>
using namespace QuasarAppUtils;
namespace QuasarAppUtils {
ISettings* ISettings::_settings = nullptr;
ISettings::ISettings(SettingsSaveMode mode) {
_mode = mode;
@ -23,15 +25,6 @@ void ISettings::setMode(const SettingsSaveMode &mode) {
_mode = mode;
}
//ISettings *ISettings::initSettings(SettingsSaveMode mode) {
// static ISettings* res = new ISettings(mode);
// return res;
//}
//ISettings *ISettings::instance() {
// return initSettings();
//}
QVariant ISettings::getValue(const QString &key, const QVariant &def) {
return getValueImplementation(key, def);
}
@ -59,3 +52,5 @@ void ISettings::setValue(const QString key, const QVariant &value) {
void ISettings::setStrValue(const QString &key, const QString &value) {
setValue(key, value);
}
}

@ -36,11 +36,21 @@ class QUASARAPPSHARED_EXPORT ISettings : public QObject
public:
// /**
// * @brief instance This method return instance of the settings object
// * @return pointer to a settings object;
// */
// static ISettings* instance();
/**
* @brief instance This method return instance of the settings object
* @return pointer to a settings object;
*/
template <class Settingstype>
static ISettings* instance() {
static_assert (std::is_base_of<Settingstype, ISettings>::value,
"the Settingstype type must be ISettings");
if(_settings == nullptr){
_settings = new Settingstype();
}
return _settings;
}
/**
* @brief getValue This method return the value of the settings.
@ -132,9 +142,7 @@ protected:
private:
SettingsSaveMode _mode = SettingsSaveMode::Auto;
// static ISettings* initSettings(SettingsSaveMode mode = SettingsSaveMode::Auto);
static ISettings* _settings;
};
} ;