DtkCore
DTK Core module
dsettingsoption.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 <QVariant>
21#include <QObject>
22#include <QPointer>
23
24#include "dtkcore_global.h"
25
26DCORE_BEGIN_NAMESPACE
27
28class DSettingsGroup;
29class DSettingsOptionPrivate;
30class LIBDTKCORESHARED_EXPORT DSettingsOption : public QObject
31{
32 Q_OBJECT
33 Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
34
35public:
36 explicit DSettingsOption(QObject *parent = Q_NULLPTR);
38
39 QPointer<DSettingsGroup> parentGroup() const;
40 void setParentGroup(QPointer<DSettingsGroup> parentGroup);
41
42 QString key() const;
43 QString name() const;
44 bool canReset() const;
45 QVariant defaultValue() const;
46 QVariant value() const;
47 QVariant data(const QString &dataType) const;
48
49 QString viewType() const;
50 bool isHidden() const;
51
52 static QPointer<DSettingsOption> fromJson(const QString &prefixKey, const QJsonObject &json);
53Q_SIGNALS:
54 void valueChanged(QVariant value);
55 void dataChanged(const QString &dataType, QVariant value);
56
57public Q_SLOTS:
58 void setValue(QVariant value);
59 void setData(const QString &dataType, QVariant value);
60
61private:
62 void parseJson(const QString &prefixKey, const QJsonObject &option);
63
64 QScopedPointer<DSettingsOptionPrivate> dd_ptr;
65 Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), DSettingsOption)
66};
67
68typedef QPointer<DSettingsOption> OptionPtr;
69
70DCORE_END_NAMESPACE
DSettingsOption is the base key/value item of DSettings.
Definition: dsettingsoption.h:31
void valueChanged(QVariant value)
Emit when option value change.
void dataChanged(const QString &dataType, QVariant value)
Emit when option data change.