DtkCore
DTK Core module
dsettingsbackend.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 <QScopedPointer>
22
23#include "dtkcore_global.h"
24
25DCORE_BEGIN_NAMESPACE
26
27class DSettings;
28class LIBDTKCORESHARED_EXPORT DSettingsBackend : public QObject
29{
30 Q_OBJECT
31public:
32 explicit DSettingsBackend(QObject *parent = Q_NULLPTR): QObject(parent)
33 {
34 connect(this, &DSettingsBackend::sync, this, &DSettingsBackend::doSync, Qt::QueuedConnection);
35 connect(this, &DSettingsBackend::setOption, this, &DSettingsBackend::doSetOption, Qt::QueuedConnection);
36 }
37 virtual ~DSettingsBackend() {}
38
39 virtual QStringList keys() const = 0;
40 virtual QVariant getOption(const QString &key) const = 0;
41
42 virtual void doSync() = 0;
43
44protected:
45 virtual void doSetOption(const QString &key, const QVariant &value) = 0;
46
47Q_SIGNALS:
48 void optionChanged(const QString &key, const QVariant &value);
49
50 // private signals;
51Q_SIGNALS:
52 void sync();
53 void setOption(const QString &key, const QVariant &value);
54};
55
56DCORE_END_NAMESPACE
DSettingsBackend is interface of DSettings storage class.
Definition: dsettingsbackend.h:29
virtual void doSync()=0
do the real sync action.
void setOption(const QString &key, const QVariant &value)
private signal, please do not use it.
void optionChanged(const QString &key, const QVariant &value)
emitted when option value changed.
virtual void doSetOption(const QString &key, const QVariant &value)=0
write key / value to storage.
void sync()
private signal, please do not use it.
virtual QVariant getOption(const QString &key) const =0
get value by key.
virtual QStringList keys() const =0
return all key of storage.