DtkCore
DTK Core module
dsettings.h
1/*
2 * Copyright (C) 2016 ~ 2017 Deepin Technology Co., Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <QObject>
21#include <QPointer>
22#include <QScopedPointer>
23
24#include "dtkcore_global.h"
25
26DCORE_BEGIN_NAMESPACE
27
28class DSettingsBackend;
29class DSettingsOption;
30class DSettingsGroup;
31class DSettingsPrivate;
32class LIBDTKCORESHARED_EXPORT DSettings : public QObject
33{
34 Q_OBJECT
35public:
36 explicit DSettings(QObject *parent = Q_NULLPTR);
37 ~DSettings();
38
39 void setBackend(DSettingsBackend *backend = nullptr);
40
41 static QPointer<DSettings> fromJson(const QByteArray &json);
42 static QPointer<DSettings> fromJsonFile(const QString &filepath);
43 QJsonObject meta() const;
44
45 QStringList keys() const;
46 QList<QPointer<DSettingsOption>> options() const;
47 QPointer<DSettingsOption> option(const QString &key) const;
48 QVariant value(const QString &key) const;
49
50 QStringList groupKeys() const;
51 QList<QPointer<DSettingsGroup>> groups() const;
52 QPointer<DSettingsGroup> group(const QString &key) const;
53
54 QVariant getOption(const QString &key) const;
55
56Q_SIGNALS:
57 void valueChanged(const QString &key, const QVariant &value);
58
59public Q_SLOTS:
63 void sync() ;
64
65 void setOption(const QString &key, const QVariant &value);
66 void reset() ;
67
68private:
69 void parseJson(const QByteArray &json);
70 void loadValue();
71
72 QScopedPointer<DSettingsPrivate> dd_ptr;
73 Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), DSettings)
74};
75
76DCORE_END_NAMESPACE
DSettingsBackend is interface of DSettings storage class.
Definition: dsettingsbackend.h:29
DSettings是设计上为Dtk的应用程序提供统一的配置存储以及界面生成工具的基础库.
Definition: dsettings.h:33