File: dsettings.h

package info (click to toggle)
dtkcore 5.7.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,728 kB
  • sloc: cpp: 22,021; ansic: 183; python: 68; xml: 58; makefile: 27; sh: 15
file content (63 lines) | stat: -rw-r--r-- 1,587 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#pragma once

#include <QObject>
#include <QPointer>
#include <QScopedPointer>

#include "dtkcore_global.h"

DCORE_BEGIN_NAMESPACE

class DSettingsBackend;
class DSettingsOption;
class DSettingsGroup;
class DSettingsPrivate;
class LIBDTKCORESHARED_EXPORT DSettings : public QObject
{
    Q_OBJECT
public:
    explicit DSettings(QObject *parent = Q_NULLPTR);
    ~DSettings();

    void setBackend(DSettingsBackend *backend = nullptr);

    static QPointer<DSettings> fromJson(const QByteArray &json);
    static QPointer<DSettings> fromJsonFile(const QString &filepath);
    QJsonObject meta() const;

    QStringList keys() const;
    QList<QPointer<DSettingsOption>> options() const;
    QPointer<DSettingsOption> option(const QString &key) const;
    QVariant value(const QString &key) const;

    QStringList groupKeys() const;
    QList<QPointer<DSettingsGroup>> groups() const;
    QPointer<DSettingsGroup> group(const QString &key) const;

    QVariant getOption(const QString &key) const;

Q_SIGNALS:
    void valueChanged(const QString &key, const QVariant &value);

public Q_SLOTS:
    //!
    //! \brief sync
    //! WARNING: sync will block
    void sync() ;

    void setOption(const QString &key, const QVariant &value);
    void reset() ;

private:
    void parseJson(const QByteArray &json);
    void loadValue();

    QScopedPointer<DSettingsPrivate> dd_ptr;
    Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), DSettings)
};

DCORE_END_NAMESPACE