1// Copyright (C) 2018 The Qt Company Ltd.
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 <private/opcuarelativenodeid_p.h>
5#include <private/opcuanodeid_p.h>
6#include <private/opcuarelativenodepath_p.h>
7
8QT_BEGIN_NAMESPACE
9
10/*!
11 \qmltype RelativeNodeId
12 \inqmlmodule QtOpcUa
13 \brief Specifies a relative node by a start node and a path.
14 \since QtOpcUa 5.12
15 \deprecated [6.9]
16
17 Proceeding from the given start node, the server tries to match the content
18 of the path property to any existing nodes on the server. Only if the path fully
19 matches to exactly one single target node, it will be used. Partial or multiple
20 matches can not be handled and are treated as error.
21
22 \code
23 import QtOpcUa as QtOpcUa
24
25 QtOpcUa.RelativeNodeId {
26 startNode: QtOpcUa.RelativeNodeId {
27 identifier: "s=Example.Node"
28 ns: "Example Namespace"
29 }
30 path: [ QtOpcUa.RelativeNodePath {
31 ns: "Test Namespace"
32 browseName: "SomeName"
33 }
34 ...
35 ]
36 }
37 }
38 \endcode
39
40 \sa NodeId, Node
41*/
42
43/*!
44 \qmlproperty NodeId RelativeNodeId::startNode
45
46 Namespace of the node identifier.
47 The start node specifies the node where resolving the path starts.
48 It can be an absolute or relative node ID.
49
50 \sa NodeId, RelativeNodeId
51*/
52
53/*!
54 \qmlproperty list RelativeNodeId::path
55
56 Search path for the designated node.
57 This is a list of \c OpcUaRelativeNodePath objects specifying the path where
58 the target node can be found relative to the start node.
59*/
60
61/*!
62 \qmlsignal Relative::nodeChanged()
63
64 Emitted when the underlying node has changed.
65 This happens when the namespace or identifier has changed.
66*/
67
68OpcUaRelativeNodeId::OpcUaRelativeNodeId(QObject *parent) : OpcUaNodeIdType(parent)
69{
70}
71
72OpcUaNodeIdType *OpcUaRelativeNodeId::startNode() const
73{
74 return m_startNode;
75}
76
77void OpcUaRelativeNodeId::setStartNode(OpcUaNodeIdType *startNode)
78{
79 if (m_startNode == startNode)
80 return;
81
82 if (m_startNode)
83 disconnect(receiver: m_startNode);
84
85 m_startNode = startNode;
86 connect(sender: m_startNode, signal: &OpcUaNodeIdType::nodeChanged, context: this, slot: &OpcUaRelativeNodeId::nodeChanged);
87
88 emit startNodeChanged(startNode: m_startNode);
89 emit nodeChanged();
90}
91
92QQmlListProperty<OpcUaRelativeNodePath> OpcUaRelativeNodeId::paths()
93{
94 return QQmlListProperty<OpcUaRelativeNodePath>(this, this,
95 &OpcUaRelativeNodeId::appendPath,
96 &OpcUaRelativeNodeId::pathCount,
97 &OpcUaRelativeNodeId::path,
98 &OpcUaRelativeNodeId::clearPaths);
99}
100
101void OpcUaRelativeNodeId::appendPath(OpcUaRelativeNodePath* p) {
102 if (!p)
103 return;
104 m_paths.append(t: p);
105 emit pathChanged();
106 emit nodeChanged();
107}
108
109int OpcUaRelativeNodeId::pathCount() const
110{
111 return m_paths.size();
112}
113
114OpcUaRelativeNodePath *OpcUaRelativeNodeId::path(int index) const
115{
116 return m_paths.at(i: index);
117}
118
119void OpcUaRelativeNodeId::clearPaths() {
120 m_paths.clear();
121 emit pathChanged();
122 emit nodeChanged();
123}
124
125void OpcUaRelativeNodeId::appendPath(QQmlListProperty<OpcUaRelativeNodePath>* list, OpcUaRelativeNodePath* p) {
126 reinterpret_cast< OpcUaRelativeNodeId* >(list->data)->appendPath(p);
127}
128
129void OpcUaRelativeNodeId::clearPaths(QQmlListProperty<OpcUaRelativeNodePath>* list) {
130 reinterpret_cast< OpcUaRelativeNodeId* >(list->data)->clearPaths();
131}
132
133OpcUaRelativeNodePath* OpcUaRelativeNodeId::path(QQmlListProperty<OpcUaRelativeNodePath>* list, qsizetype i) {
134 return reinterpret_cast< OpcUaRelativeNodeId* >(list->data)->path(index: i);
135}
136
137qsizetype OpcUaRelativeNodeId::pathCount(QQmlListProperty<OpcUaRelativeNodePath>* list) {
138 return reinterpret_cast< OpcUaRelativeNodeId* >(list->data)->pathCount();
139}
140
141QT_END_NAMESPACE
142

source code of qtopcua/src/declarative_opcua/opcuarelativenodeid.cpp