2018-09-29 15:56:04 +03:00
|
|
|
/*
|
2023-12-31 09:23:23 +01:00
|
|
|
* Copyright (C) 2021-2024 QuasarApp.
|
2018-09-29 15:56:04 +03:00
|
|
|
* Distributed under the lgplv3 software license, see the accompanying
|
|
|
|
* Everyone is permitted to copy and distribute verbatim copies
|
|
|
|
* of this license document, but changing it is not allowed.
|
|
|
|
*/
|
|
|
|
|
2021-11-05 23:58:23 +03:00
|
|
|
|
2018-09-29 15:56:04 +03:00
|
|
|
#ifndef SETTINGS_H
|
|
|
|
#define SETTINGS_H
|
|
|
|
|
|
|
|
#include "quasarapp_global.h"
|
2021-11-05 23:58:23 +03:00
|
|
|
#include "isettings.h"
|
2022-06-24 23:54:04 +03:00
|
|
|
#include <QSet>
|
2018-09-29 15:56:04 +03:00
|
|
|
|
|
|
|
namespace QuasarAppUtils {
|
|
|
|
|
2022-02-22 17:01:53 +03:00
|
|
|
/**
|
|
|
|
* @brief The Settings class This is wraper of the QSettings object.
|
|
|
|
*
|
|
|
|
* Example of initialisation :
|
|
|
|
*
|
2022-08-21 22:25:59 +03:00
|
|
|
* @code{cpp}
|
|
|
|
* auto settingsInstance = QuasarAppUtils::Setting::initService();
|
|
|
|
*
|
|
|
|
* // on any another site you can use the instance method for get settings instance object.
|
|
|
|
* auto settingsInstance = QuasarAppUtils::Setting::instance();
|
|
|
|
*
|
|
|
|
* // and you can destroy setting object if they are not needed anymore
|
|
|
|
* QuasarAppUtils::Setting::deinitService();
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* **Or** you can use the Settings::autoInstance method.
|
|
|
|
*
|
|
|
|
* @code{cpp}
|
|
|
|
* auto settingsInstance = QuasarAppUtils::Setting::autoInstance();
|
|
|
|
* @endcode
|
2022-02-22 17:01:53 +03:00
|
|
|
*
|
|
|
|
* @see Settings::init
|
|
|
|
*/
|
2022-06-21 19:14:59 +03:00
|
|
|
class QUASARAPPSHARED_EXPORT Settings: public ISettings
|
2018-09-29 15:56:04 +03:00
|
|
|
{
|
2022-06-22 19:12:11 +03:00
|
|
|
Q_OBJECT
|
2018-09-29 15:56:04 +03:00
|
|
|
public:
|
2021-11-05 23:58:23 +03:00
|
|
|
Settings();
|
2018-09-29 15:56:04 +03:00
|
|
|
|
2021-11-05 23:58:23 +03:00
|
|
|
// ISettings interface
|
2022-06-24 23:54:04 +03:00
|
|
|
/**
|
|
|
|
* @brief boolOptions returns current map with keys that has a bool type.
|
|
|
|
* @return current map with keys that has a bool type
|
|
|
|
* @see Settings::setBoolOptions
|
|
|
|
* @see Settings::isBool
|
|
|
|
*/
|
|
|
|
const QSet<QString> &boolOptions() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief setBoolOptions This method sets new map of the boolean options.
|
|
|
|
* @param newBoolOptions This is new map of the boolean options.
|
|
|
|
* @see Settings::boolOptions
|
|
|
|
* @see Settings::isBool
|
|
|
|
*/
|
|
|
|
void setBoolOptions(const QSet<QString> &newBoolOptions);
|
|
|
|
|
2023-08-16 13:34:40 +02:00
|
|
|
/**
|
|
|
|
* @brief initService This method initialize default object of the QuasarAppUtils::Settings type.
|
|
|
|
* @return true if initialization finished successfull else false.
|
|
|
|
* @see ISettings::initService
|
|
|
|
*/
|
|
|
|
static bool initService();
|
|
|
|
|
2021-11-05 23:58:23 +03:00
|
|
|
protected:
|
2022-02-22 17:01:53 +03:00
|
|
|
|
2022-08-21 22:25:59 +03:00
|
|
|
void syncImplementation() override;
|
|
|
|
QVariant getValueImplementation(const QString &key, const QVariant &def) override;
|
|
|
|
void setValueImplementation(const QString key, const QVariant &value) override;
|
|
|
|
bool ignoreToRest(const QString &) const override;
|
|
|
|
QHash<QString, QVariant> defaultSettings() override;
|
2019-09-28 16:41:43 +03:00
|
|
|
|
2022-06-24 23:54:04 +03:00
|
|
|
/**
|
|
|
|
* @brief isBool This method should be return true if the key's type is bool.
|
|
|
|
* This is needed because QVariant will be converted alvays to true value in a qml code.
|
|
|
|
* @param key This is key of checks setting.
|
|
|
|
* @return true if the key is boolean variable.
|
|
|
|
* The default implementation check key in the inner map.
|
|
|
|
*
|
|
|
|
* @see Settings::setBoolOptions
|
|
|
|
* @see Settings::boolOptions
|
|
|
|
*/
|
|
|
|
virtual bool isBool(const QString& key) const;
|
2022-06-24 00:29:23 +03:00
|
|
|
void setGroup(const QString&);
|
2018-09-29 15:56:04 +03:00
|
|
|
|
2021-04-26 11:27:19 +03:00
|
|
|
private:
|
|
|
|
QSettings *_settings = nullptr;
|
2022-06-24 23:54:04 +03:00
|
|
|
QSet<QString> _boolOptions;
|
2018-09-29 15:56:04 +03:00
|
|
|
};
|
|
|
|
|
2021-11-05 23:58:23 +03:00
|
|
|
}
|
2018-09-29 15:56:04 +03:00
|
|
|
|
|
|
|
#endif // SETTINGS_H
|