| 1 |
// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <QObject> |
| 8 |
#include <QPointer> |
| 9 |
#include <QScopedPointer> |
| 10 |
|
| 11 |
#include "dtkcore_global.h" |
| 12 |
|
| 13 |
DCORE_BEGIN_NAMESPACE |
| 14 |
|
| 15 |
class DSettingsBackend; |
| 16 |
class DSettingsOption; |
| 17 |
class DSettingsGroup; |
| 18 |
class DSettingsPrivate; |
| 19 |
class LIBDTKCORESHARED_EXPORT DSettings : public QObject |
| 20 |
{ |
| 21 |
Q_OBJECT |
| 22 |
public: |
| 23 |
explicit DSettings(QObject *parent = Q_NULLPTR); |
| 24 |
~DSettings(); |
| 25 |
|
| 26 |
void setBackend(DSettingsBackend *backend = nullptr); |
| 27 |
|
| 28 |
static QPointer<DSettings> fromJson(const QByteArray &json); |
| 29 |
static QPointer<DSettings> fromJsonFile(const QString &filepath); |
| 30 |
QJsonObject meta() const; |
| 31 |
|
| 32 |
QStringList keys() const; |
| 33 |
QList<QPointer<DSettingsOption>> options() const; |
| 34 |
QPointer<DSettingsOption> option(const QString &key) const; |
| 35 |
QVariant value(const QString &key) const; |
| 36 |
|
| 37 |
QStringList groupKeys() const; |
| 38 |
QList<QPointer<DSettingsGroup>> groups() const; |
| 39 |
QPointer<DSettingsGroup> group(const QString &key) const; |
| 40 |
|
| 41 |
QVariant getOption(const QString &key) const; |
| 42 |
|
| 43 |
Q_SIGNALS: |
| 44 |
void valueChanged(const QString &key, const QVariant &value); |
| 45 |
|
| 46 |
public Q_SLOTS: |
| 47 |
//! |
| 48 |
//! \brief sync |
| 49 |
//! WARNING: sync will block |
| 50 |
void sync() ; |
| 51 |
|
| 52 |
void setOption(const QString &key, const QVariant &value); |
| 53 |
void reset() ; |
| 54 |
|
| 55 |
private: |
| 56 |
void parseJson(const QByteArray &json); |
| 57 |
void loadValue(); |
| 58 |
|
| 59 |
QScopedPointer<DSettingsPrivate> dd_ptr; |
| 60 |
Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), DSettings) |
| 61 |
}; |
| 62 |
|
| 63 |
DCORE_END_NAMESPACE |