2018-09-29 15:56:04 +03:00
|
|
|
/*
|
2021-01-05 13:04:05 +03:00
|
|
|
* Copyright (C) 2018-2021 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SETTINGS_H
|
|
|
|
#define SETTINGS_H
|
|
|
|
|
|
|
|
#include "quasarapp_global.h"
|
|
|
|
#include <QObject>
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
class QSettings;
|
|
|
|
|
|
|
|
namespace QuasarAppUtils {
|
|
|
|
|
2019-09-28 16:41:43 +03:00
|
|
|
/**
|
|
|
|
* @brief The SettingsSaveMode enum
|
|
|
|
* Auto - value save on hard disk when calling method "value"
|
|
|
|
* manual - save all data on hard disk when calling method Settings::sync
|
|
|
|
*/
|
|
|
|
enum class SettingsSaveMode: quint64 {
|
|
|
|
Auto,
|
|
|
|
Manual
|
|
|
|
};
|
|
|
|
|
2018-09-29 15:56:04 +03:00
|
|
|
/**
|
|
|
|
* @brief The Settings class - singleton for QSettings
|
|
|
|
*/
|
|
|
|
class QUASARAPPSHARED_EXPORT Settings : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private:
|
2019-09-28 16:41:43 +03:00
|
|
|
explicit Settings(SettingsSaveMode mode = SettingsSaveMode::Auto);
|
|
|
|
QSettings *_settings = nullptr;
|
|
|
|
SettingsSaveMode _mode = SettingsSaveMode::Auto;
|
2019-09-23 18:36:29 +03:00
|
|
|
|
2019-09-28 16:41:43 +03:00
|
|
|
static Settings* initSettings(SettingsSaveMode mode = SettingsSaveMode::Auto);
|
2018-09-29 15:56:04 +03:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief get
|
|
|
|
* @return object of all settings app;
|
|
|
|
*/
|
|
|
|
static Settings* get();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief get
|
|
|
|
* @return const object of all settings app;
|
|
|
|
*/
|
|
|
|
static const Settings* getConst();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief getValue
|
|
|
|
* @param key - key of value
|
|
|
|
* @param def - default value if is value not finded
|
|
|
|
* @return value of key
|
|
|
|
*/
|
2019-10-13 18:45:16 +03:00
|
|
|
Q_INVOKABLE QVariant getValue(const QString &key, const QVariant& def);
|
2018-09-29 15:56:04 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief getStrValue some as getValue but work with QString
|
|
|
|
*/
|
2019-10-13 18:45:16 +03:00
|
|
|
Q_INVOKABLE QString getStrValue(const QString &key, const QString& def);
|
2018-09-29 15:56:04 +03:00
|
|
|
|
2019-09-28 16:41:43 +03:00
|
|
|
/**
|
|
|
|
* @brief sync - save all data on hard disk;
|
|
|
|
*/
|
|
|
|
void sync();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief getMode
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
SettingsSaveMode getMode() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief setMode
|
|
|
|
* @param mode
|
|
|
|
*/
|
|
|
|
void setMode(const SettingsSaveMode &mode);
|
|
|
|
|
2018-09-29 15:56:04 +03:00
|
|
|
public slots:
|
|
|
|
/**
|
|
|
|
* @brief setValue - set new value of key
|
|
|
|
* @param key - key pf settings
|
|
|
|
* @param value - new value
|
|
|
|
*/
|
|
|
|
void setValue(const QString key, const QVariant& value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief setStrValue - some as setValue< but use QString
|
|
|
|
*/
|
|
|
|
void setStrValue(const QString& key, const QString& value);
|
|
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void valueChanged(QString key, QVariant value);
|
|
|
|
void valueStrChanged(QString key, QString value);
|
|
|
|
|
|
|
|
};
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
#endif // SETTINGS_H
|