1// Copyright (C) 2015 basysKom GmbH, opensource@basyskom.com
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 "qopcuarelativepathelement.h"
5#include "qopcuaqualifiedname.h"
6
7QT_BEGIN_NAMESPACE
8
9/*!
10 \class QOpcUaRelativePathElement
11 \inmodule QtOpcUa
12 \brief The OPC UA RelativePathElement.
13
14 QOpcUaRelativePathElement defines an element of a relative path on an OPC UA server.
15 This is needed for resolution of browse paths to node ids in \l QOpcUaNode::resolveBrowsePath().
16*/
17
18class QOpcUaRelativePathElementData : public QSharedData
19{
20public:
21 QString referenceTypeId;
22 bool isInverse{false};
23 bool includeSubtypes{false};
24 QOpcUaQualifiedName targetName;
25};
26
27/*!
28 Constructs a relative path element with both flags set to \c false.
29*/
30QOpcUaRelativePathElement::QOpcUaRelativePathElement()
31 : data(new QOpcUaRelativePathElementData())
32{
33}
34
35/*!
36 Constructs a relative path element with targetName \a target, reference type node id \a refType and both flags set to \c false.
37*/
38QOpcUaRelativePathElement::QOpcUaRelativePathElement(const QOpcUaQualifiedName &target, const QString &refType)
39 : data(new QOpcUaRelativePathElementData())
40{
41 data->referenceTypeId = refType;
42 data->targetName = target;
43}
44
45/*!
46 Constructs a relative path element with targetName \a target, \l QOpcUa::ReferenceTypeId \a refType and both flags set to \c false.
47*/
48QOpcUaRelativePathElement::QOpcUaRelativePathElement(const QOpcUaQualifiedName &target, QOpcUa::ReferenceTypeId refType)
49 : data(new QOpcUaRelativePathElementData())
50{
51 data->referenceTypeId = QOpcUa::nodeIdFromReferenceType(referenceType: refType);
52 data->targetName = target;
53}
54
55/*!
56 Constructs a relative path element from \a rhs.
57*/
58QOpcUaRelativePathElement::QOpcUaRelativePathElement(const QOpcUaRelativePathElement &rhs)
59 : data(rhs.data)
60{
61}
62
63/*!
64 Sets the values of \a rhs in this relative path element.
65*/
66QOpcUaRelativePathElement &QOpcUaRelativePathElement::operator=(const QOpcUaRelativePathElement &rhs)
67{
68 if (this != &rhs)
69 data.operator=(o: rhs.data);
70 return *this;
71}
72
73/*!
74 Returns \c true if this relative path element has the same value as \a rhs.
75*/
76bool QOpcUaRelativePathElement::operator==(const QOpcUaRelativePathElement &rhs) const
77{
78 return data->includeSubtypes == rhs.includeSubtypes() &&
79 data->isInverse == rhs.isInverse() &&
80 data->referenceTypeId == rhs.referenceTypeId() &&
81 data->targetName == rhs.targetName();
82}
83
84QOpcUaRelativePathElement::~QOpcUaRelativePathElement()
85{
86}
87
88/*!
89 Returns the qualified name of the reference's target.
90*/
91QOpcUaQualifiedName QOpcUaRelativePathElement::targetName() const
92{
93 return data->targetName;
94}
95
96/*!
97 Sets the target name to \a targetName, for example QOpcUaQualifiedName(0, "DataTypes").
98*/
99void QOpcUaRelativePathElement::setTargetName(const QOpcUaQualifiedName &targetName)
100{
101 data->targetName = targetName;
102}
103
104/*!
105 Returns the value of the includeSubtypes flag.
106*/
107bool QOpcUaRelativePathElement::includeSubtypes() const
108{
109 return data->includeSubtypes;
110}
111
112/*!
113 Sets the includeSubtypes flag to \a includeSubtypes.
114 If the flag is \c true, the lookup also follows references with subtypes of \l referenceTypeId().
115*/
116void QOpcUaRelativePathElement::setIncludeSubtypes(bool includeSubtypes)
117{
118 data->includeSubtypes = includeSubtypes;
119}
120
121/*!
122 Returns the value of the isInverse flag.
123*/
124bool QOpcUaRelativePathElement::isInverse() const
125{
126 return data->isInverse;
127}
128
129/*!
130 Sets the isInverse flag to \a isInverse.
131 If the flag is \c true, the lookup follows the reverse reference.
132*/
133void QOpcUaRelativePathElement::setIsInverse(bool isInverse)
134{
135 data->isInverse = isInverse;
136}
137
138/*!
139 Returns the type id of the reference connecting this node to the previous node.
140*/
141QString QOpcUaRelativePathElement::referenceTypeId() const
142{
143 return data->referenceTypeId;
144}
145
146/*!
147 Sets the reference type id to \a referenceTypeId.
148*/
149void QOpcUaRelativePathElement::setReferenceTypeId(const QString &referenceTypeId)
150{
151 data->referenceTypeId = referenceTypeId;
152}
153
154/*!
155 Sets the reference type id to \a referenceTypeId.
156*/
157void QOpcUaRelativePathElement::setReferenceTypeId(QOpcUa::ReferenceTypeId referenceTypeId)
158{
159 data->referenceTypeId = QOpcUa::nodeIdFromReferenceType(referenceType: referenceTypeId);
160}
161
162QT_END_NAMESPACE
163

source code of qtopcua/src/opcua/client/qopcuarelativepathelement.cpp