1 | // Copyright (C) 2017 Ford Motor Company |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qremoteobjectsettingsstore.h" |
5 | |
6 | #include "qremoteobjectnode_p.h" |
7 | |
8 | #include <QtCore/private/qobject_p.h> |
9 | #include <QtCore/qsettings.h> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | /*! |
14 | \qmltype SettingsStore |
15 | \inqmlmodule QtRemoteObjects |
16 | \brief A basic store for persisted properties. |
17 | |
18 | This type provides simple QSettings-based storage for properties marked as PERSISTED. It is used in |
19 | conjunction with Node::persistedStore: |
20 | |
21 | \code |
22 | Node { |
23 | persistedStore: SettingsStore {} |
24 | } |
25 | \endcode |
26 | */ |
27 | |
28 | class QRemoteObjectSettingsStorePrivate : public QRemoteObjectAbstractPersistedStorePrivate |
29 | { |
30 | public: |
31 | QRemoteObjectSettingsStorePrivate(); |
32 | virtual ~QRemoteObjectSettingsStorePrivate(); |
33 | |
34 | QSettings settings; |
35 | Q_DECLARE_PUBLIC(QRemoteObjectSettingsStore) |
36 | }; |
37 | |
38 | QRemoteObjectSettingsStorePrivate::QRemoteObjectSettingsStorePrivate() |
39 | { |
40 | } |
41 | |
42 | QRemoteObjectSettingsStorePrivate::~QRemoteObjectSettingsStorePrivate() |
43 | { |
44 | } |
45 | |
46 | QRemoteObjectSettingsStore::QRemoteObjectSettingsStore(QObject *parent) |
47 | : QRemoteObjectAbstractPersistedStore(*new QRemoteObjectSettingsStorePrivate, parent) |
48 | { |
49 | } |
50 | |
51 | QRemoteObjectSettingsStore::~QRemoteObjectSettingsStore() |
52 | { |
53 | } |
54 | |
55 | QVariantList QRemoteObjectSettingsStore::restoreProperties(const QString &repName, const QByteArray &repSig) |
56 | { |
57 | Q_D(QRemoteObjectSettingsStore); |
58 | d->settings.beginGroup(prefix: repName + QLatin1Char('/') + QString::fromLatin1(ba: repSig)); |
59 | QVariantList values = d->settings.value(QStringLiteral("values")).toList(); |
60 | d->settings.endGroup(); |
61 | return values; |
62 | } |
63 | |
64 | void QRemoteObjectSettingsStore::saveProperties(const QString &repName, const QByteArray &repSig, const QVariantList &values) |
65 | { |
66 | Q_D(QRemoteObjectSettingsStore); |
67 | d->settings.beginGroup(prefix: repName + QLatin1Char('/') + QString::fromLatin1(ba: repSig)); |
68 | d->settings.setValue(QStringLiteral("values"), value: values); |
69 | d->settings.endGroup(); |
70 | d->settings.sync(); |
71 | } |
72 | |
73 | QT_END_NAMESPACE |
74 |