QuasarAppLib/settings.h

107 lines
3.1 KiB
C
Raw Permalink Normal View History

2018-09-29 15:56:04 +03:00
/*
2024-12-30 22:39:49 +01:00
* Copyright (C) 2021-2025 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.
*/
2018-09-29 15:56:04 +03:00
#ifndef SETTINGS_H
#define SETTINGS_H
#include "quasarapp_global.h"
#include "isettings.h"
#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
*/
class QUASARAPPSHARED_EXPORT Settings: public ISettings
2018-09-29 15:56:04 +03:00
{
Q_OBJECT
2018-09-29 15:56:04 +03:00
public:
Settings();
2018-09-29 15:56:04 +03:00
// ISettings interface
/**
* @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();
2025-02-18 14:12:54 +01:00
/**
* @brief deinitService This method destroy default object of the QuasarAppUtils::Settings type.
* @see ISettings::deinitService
*/
static ISettings *autoInstance();
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
/**
* @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
private:
QSettings *_settings = nullptr;
QSet<QString> _boolOptions;
2018-09-29 15:56:04 +03:00
};
}
2018-09-29 15:56:04 +03:00
#endif // SETTINGS_H