DtkDeclarative
DTK Declarative module
载入中...
搜索中...
未找到
dconfigwrapper_p.h
1// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DCONFIGWRAPPER_H
6#define DCONFIGWRAPPER_H
7
8#include <dtkdeclarative_global.h>
9#include <QQmlParserStatus>
10#include <QtQml/qqml.h>
11
12DCORE_BEGIN_NAMESPACE
13class DConfig;
14class DThreadUtils;
15DCORE_END_NAMESPACE
16
18class DConfigWrapper : public QObject, public QQmlParserStatus
19{
20 Q_OBJECT
21 Q_INTERFACES(QQmlParserStatus)
22 Q_PROPERTY(QString name READ name WRITE setName)
23 Q_PROPERTY(QString subpath READ subpath WRITE setSubpath)
24 Q_PROPERTY(bool async READ async WRITE setAsync)
25#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
26 QML_NAMED_ELEMENT(Config)
27#endif
28public:
29 explicit DConfigWrapper(QObject *parent = nullptr);
30 ~DConfigWrapper() override;
31
32 QString name() const;
33 void setName(const QString &name);
34
35 QString subpath() const;
36 void setSubpath(const QString &subpath);
37
38 bool async() const;
39 void setAsync(bool newAsync);
40
41public Q_SLOTS:
42 QVariant value(const QString &key, const QVariant &fallback = QVariant()) const;
43 void setValue(const QString &key, const QVariant &value);
44 void resetValue(const QString &key);
45 QStringList keyList() const;
46 bool isValid() const;
47 bool isDefaultValue(const QString &key) const;
48
49Q_SIGNALS:
50 void valueChanged(const QString &key, const QVariant &value);
51 void initialized();
52
53private:
54 virtual void classBegin() override;
55 virtual void componentComplete() override;
56
57 void initializeProperties() const;
58
60 DConfigWrapperMetaObject *mo = nullptr;
61 std::unique_ptr<DTK_CORE_NAMESPACE::DConfig> impl;
62 QStringList configKeyList;
63 // If the key was set value, add it to the list
64 QStringList nonDefaultValueKeyList;
65 QMap<QByteArray, QVariant> initializeConfigs;
66
67 QString m_name;
68 QString m_subpath;
69 bool m_async = false;
70 Q_DISABLE_COPY(DConfigWrapper)
71};
72
73#endif // DCONFIGWRAPPER_H
一个 DTK 配置项中的配置信息类.
Definition dconfigwrapper.cpp:52
Definition dconfigwrapper_p.h:19
bool isValid() const
Definition dconfigwrapper.cpp:160
QStringList keyList() const
Definition dconfigwrapper.cpp:148
QVariant value(const QString &key, const QVariant &fallback=QVariant()) const
Definition dconfigwrapper.cpp:178
void setValue(const QString &key, const QVariant &value)
Definition dconfigwrapper.cpp:188