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

source code of qtremoteobjects/src/remoteobjects/qremoteobjectsettingsstore.cpp