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