1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtSystems module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34#include "qdeclarativevaluespacesubscriber_p.h"
35
36QT_BEGIN_NAMESPACE
37
38/*!
39 \qmltype ValueSpaceSubscriber
40 \instantiates QDeclarativeValueSpaceSubscriber
41 \inqmlmodule QtPublishSubscribe
42 \ingroup qml-publishsubscribe
43
44 \brief The QValueSpaceSubscriber class allows applications to read and subscribe to Value Space.
45
46 Each \l ValueSpaceSubscriber element represents a single value or path in the Value Space. The
47 path is set using the \e path property.
48
49 Note that unlike the C++ class QValueSpaceSubscriber, the QML element has no default path. A path
50 must be set before the subscriber will connect to the Value Space and begin receiving notifications.
51
52 \code
53 ValueSpaceSubscriber {
54 id: nowPlaying
55 path: "/applications/mediaplayer/now-playing"
56 }
57 \endcode
58
59 The value is accessed using the \e value property:
60
61 \code
62 Text {
63 text: nowPlaying.value
64 }
65 \endcode
66*/
67
68QDeclarativeValueSpaceSubscriber::QDeclarativeValueSpaceSubscriber()
69 : d_ptr(0)
70{
71}
72
73QDeclarativeValueSpaceSubscriber::~QDeclarativeValueSpaceSubscriber()
74{
75}
76
77/*!
78 \qmlproperty string ValueSpaceSubscriber::path
79
80 This property holds the base path of the subscriber, and it should be set before connecting to
81 any Value Space layers and receiving notifications.
82*/
83void QDeclarativeValueSpaceSubscriber::setPath(QString path)
84{
85 if (!d_ptr) {
86 d_ptr = new QValueSpaceSubscriber(path, this);
87 connect(sender: d_ptr, SIGNAL(contentsChanged()), receiver: this, SIGNAL(contentsChanged()));
88 } else {
89 d_ptr->setPath(path);
90 emit pathChanged();
91 }
92}
93
94QString QDeclarativeValueSpaceSubscriber::path() const
95{
96 if (d_ptr)
97 return d_ptr->path();
98 else
99 return QString::null;
100}
101
102/*!
103 \qmlproperty QVariant ValueSpaceSubscriber::value
104
105 This property holds the value of the key at the set path in the Value Space.
106 Read-only.
107*/
108QVariant QDeclarativeValueSpaceSubscriber::value(const QString &subPath, const QVariant &def) const
109{
110 if (d_ptr)
111 return d_ptr->value(subPath, def);
112 else
113 return QVariant();
114}
115
116/*!
117 \qmlproperty QStringList ValueSpaceSubscriber::subPaths
118
119 This property holds a list of known sub-paths of the currently set path.
120*/
121QStringList QDeclarativeValueSpaceSubscriber::subPaths() const
122{
123 if (d_ptr)
124 return d_ptr->subPaths();
125 else
126 return QStringList();
127}
128
129/*!
130 \qmlproperty bool ValueSpaceSubscriber::connected
131
132 This property holds whether the subscriber is currently connected to the
133 backing store of the Value Space.
134*/
135bool QDeclarativeValueSpaceSubscriber::isConnected() const
136{
137 if (d_ptr)
138 return d_ptr->isConnected();
139 else
140 return false;
141}
142
143QT_END_NAMESPACE
144

source code of qtsystems/src/imports/publishsubscribe/qdeclarativevaluespacesubscriber.cpp