DtkCore
DTK Core module
dconfig.h
1/*
2 * Copyright (C) 2021 Uniontech Technology Co., Ltd.
3 *
4 * Author: zccrs <[email protected]>
5 *
6 * Maintainer: zccrs <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21#ifndef DCONFIG_H
22#define DCONFIG_H
23
24#include <dtkcore_global.h>
25#include <DObject>
26
27#include <QObject>
28#include <QVariant>
29
30DCORE_BEGIN_NAMESPACE
32public:
33 virtual ~DConfigBackend();
34 virtual bool isValid() const = 0;
35 virtual bool load(const QString &/*appId*/) = 0;
36 virtual QStringList keyList() const = 0;
37 virtual QVariant value(const QString &/*key*/, const QVariant &/*fallback*/) const = 0;
38 virtual void setValue(const QString &/*key*/, const QVariant &/*value*/) = 0;
39 virtual void reset(const QString &key) { setValue(key, QVariant());}
40 virtual QString name() const {return QString("");}
41};
42
43class DConfigPrivate;
44class LIBDTKCORESHARED_EXPORT DConfig : public QObject, public DObject
45{
46 Q_OBJECT
47 D_DECLARE_PRIVATE(DConfig)
48
49 Q_PROPERTY(QStringList keyList READ keyList FINAL)
50
51public:
52 explicit DConfig(const QString &name, const QString &subpath = QString(),
53 QObject *parent = nullptr);
54
55 explicit DConfig(DConfigBackend *backend, const QString &name, const QString &subpath = QString(),
56 QObject *parent = nullptr);
57
58 static DConfig *create(const QString &appId, const QString &name, const QString &subpath = QString(),
59 QObject *parent = nullptr);
60 static DConfig *create(DConfigBackend *backend, const QString &appId, const QString &name, const QString &subpath = QString(),
61 QObject *parent = nullptr);
62
63 QString backendName() const;
64
65 QStringList keyList() const;
66
67 bool isValid() const;
68 QVariant value(const QString &key, const QVariant &fallback = QVariant()) const;
69 void setValue(const QString &key, const QVariant &value);
70 void reset(const QString &key);
71
72 QString name() const;
73 QString subpath() const;
74
75Q_SIGNALS:
76 void valueChanged(const QString &key);
77
78private:
79 explicit DConfig(DConfigBackend *backend, const QString &appId, const QString &name, const QString &subpath,
80 QObject *parent = nullptr);
81};
82
83DCORE_END_NAMESPACE
84
85#endif // DCONFIG_H
配置后端的抽象接口.
Definition: dconfig.h:31
virtual QString name() const
后端配置的唯一标识
Definition: dconfig.h:40
virtual void setValue(const QString &, const QVariant &)=0
virtual QStringList keyList() const =0
virtual bool isValid() const =0
virtual bool load(const QString &)=0
初始化后端
virtual void reset(const QString &key)
Definition: dconfig.h:39
virtual QVariant value(const QString &, const QVariant &) const =0
配置策略提供的接口类
Definition: dconfig.h:45
一些宏的定义.
Definition: dobject.h:38