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/opcuarelativenodepath_p.h>
5#include <private/opcuanodeid_p.h>
6
7#include <QtOpcUa/qopcuaclient.h>
8#include <QLoggingCategory>
9#include <QMetaEnum>
10
11QT_BEGIN_NAMESPACE
12
13/*!
14 \qmltype RelativeNodePath
15 \inqmlmodule QtOpcUa
16 \brief Specifies a relative node path element.
17 \since QtOpcUa 5.12
18 \deprecated [6.9]
19
20 \code
21 import QtOpcUa as QtOpcUa
22
23 QtOpcUa.RelativeNodePath {
24 ns: "Test Namespace"
25 browseName: "SomeName"
26 }
27 \endcode
28
29 \sa Node, NodeId, RelativeNodeId
30*/
31
32/*!
33 \qmlproperty NodeId RelativeNodePath::ns
34
35 Namespace name of this path element.
36 The identifier can be the index as a number or the name as string.
37 A string which can be converted to an integer is considered a namespace index.
38*/
39
40/*!
41 \qmlproperty NodeId RelativeNodePath::browseName
42
43 Browse name of this path element.
44*/
45
46/*!
47 \qmlproperty bool RelativeNodePath::includeSubtypes
48
49 Whether subtypes are included when matching this path element.
50 The default value of this property is \c true.
51*/
52
53/*!
54 \qmlproperty bool RelativeNodePath::isInverse
55
56 Whether the reference to follow is inverse.
57 The default value of this property is \c false.
58*/
59
60/*!
61 \qmlproperty QOpcUa::ReferenceTypeId RelativeNodePath::referenceType
62
63 Type of reference when matching this path element.
64 This can be a \l QOpcUa::ReferenceTypeId or a \l NodeId.
65 The default value of this property is \c Constants.ReferenceTypeId.References.
66*/
67
68Q_DECLARE_LOGGING_CATEGORY(QT_OPCUA_PLUGINS_QML)
69
70OpcUaRelativeNodePath::OpcUaRelativeNodePath(QObject *parent) : QObject(parent)
71{
72 connect(sender: &m_browseNode, signal: &UniversalNode::namespaceNameChanged, context: this, slot: &OpcUaRelativeNodePath::nodeNamespaceChanged);
73 connect(sender: &m_browseNode, signal: &UniversalNode::nodeIdentifierChanged, context: this, slot: &OpcUaRelativeNodePath::browseNameChanged);
74}
75
76const QString &OpcUaRelativeNodePath::nodeNamespace() const
77{
78 return m_browseNode.namespaceName();
79}
80
81const QString &OpcUaRelativeNodePath::browseName() const
82{
83 return m_browseNode.nodeIdentifier();
84}
85
86QVariant OpcUaRelativeNodePath::referenceType() const
87{
88 return m_referenceType;
89}
90
91bool OpcUaRelativeNodePath::includeSubtypes() const
92{
93 return m_includeSubtypes;
94}
95
96void OpcUaRelativeNodePath::setNodeNamespace(QString ns)
97{
98 m_browseNode.setNamespace(ns);
99}
100
101void OpcUaRelativeNodePath::setBrowseName(QString browseName)
102{
103 m_browseNode.setNodeIdentifier(browseName);
104}
105
106void OpcUaRelativeNodePath::setReferenceType(const QVariant &referenceType)
107{
108 bool valid = false;
109
110 if (referenceType.userType() == qMetaTypeId<QObject*>() && qobject_cast<OpcUaNodeId*>(object: referenceType.value<QObject*>()))
111 valid = true;
112 else if (referenceType.userType() == QMetaType::Int && QMetaEnum::fromType<QOpcUa::ReferenceTypeId>().valueToKey(value: referenceType.toInt()))
113 valid = true;
114
115 if (!valid) {
116 qCWarning(QT_OPCUA_PLUGINS_QML) << "Invalid reference type:" << referenceType;
117 return;
118 }
119
120 if (m_referenceType == referenceType)
121 return;
122
123 m_referenceType = referenceType;
124 emit referenceTypeChanged();
125}
126
127void OpcUaRelativeNodePath::setIncludeSubtypes(bool includeSubtypes)
128{
129 if (m_includeSubtypes == includeSubtypes)
130 return;
131
132 m_includeSubtypes = includeSubtypes;
133 emit includeSubtypesChanged(includeSubtypes: m_includeSubtypes);
134}
135
136bool OpcUaRelativeNodePath::isInverse() const
137{
138 return m_isInverse;
139}
140
141QOpcUaRelativePathElement OpcUaRelativeNodePath::toRelativePathElement(QOpcUaClient *client) const
142{
143 m_browseNode.resolveNamespaceNameToIndex(client);
144
145 QOpcUaRelativePathElement x;
146 x.setIsInverse(isInverse());
147 x.setIncludeSubtypes(includeSubtypes());
148 x.setTargetName(m_browseNode.toQualifiedName());
149 if (m_referenceType.userType() == QMetaType::Int
150 || m_referenceType.userType() == qMetaTypeId<QOpcUa::ReferenceTypeId>())
151 x.setReferenceTypeId(m_referenceType.value<QOpcUa::ReferenceTypeId>());
152 else
153 x.setReferenceTypeId(m_referenceType.toString());
154
155 return x;
156}
157
158void OpcUaRelativeNodePath::setIsInverse(bool isInverse)
159{
160 if (m_isInverse == isInverse)
161 return;
162
163 m_isInverse = isInverse;
164 emit isInverseChanged(isInverse: m_isInverse);
165}
166
167QT_END_NAMESPACE
168

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