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 "qopcuaqualifiedname.h"
5
6QT_BEGIN_NAMESPACE
7
8/*!
9 \class QOpcUaQualifiedName
10 \inmodule QtOpcUa
11 \brief The OPC UA QualifiedName type.
12
13 This is the Qt OPC UA representation for the OPC UA QualifiedName type defined in OPC-UA part 3, 8.3.
14 A QualifiedName is a name qualified by a namespace index. The namespace index corresponds to an entry in the server's namespace array.
15 QualifiedName is mainly used to represent the BrowseName attribute of a node.
16*/
17
18class QOpcUaQualifiedNameData : public QSharedData
19{
20public:
21 QString name;
22 quint16 namespaceIndex{0}; //OPC UA part 4, page 116: a string is converted to a qualified name by setting the namespace index to 0.
23};
24
25QOpcUaQualifiedName::QOpcUaQualifiedName()
26 : data(new QOpcUaQualifiedNameData)
27{
28}
29
30/*!
31 Constructs a qualified name from \a rhs.
32*/
33QOpcUaQualifiedName::QOpcUaQualifiedName(const QOpcUaQualifiedName &rhs)
34 : data(rhs.data)
35{
36}
37
38/*!
39 Constructs a qualified name with namespace index \a namespaceIndex and the name \a name.
40*/
41QOpcUaQualifiedName::QOpcUaQualifiedName(quint16 namespaceIndex, const QString &name)
42 : data(new QOpcUaQualifiedNameData)
43{
44 data->namespaceIndex = namespaceIndex;
45 data->name = name;
46}
47
48/*!
49 Returns \c true if this qualified name has the same value as \a rhs.
50*/
51bool QOpcUaQualifiedName::operator==(const QOpcUaQualifiedName &rhs) const
52{
53 return data->namespaceIndex == rhs.namespaceIndex() &&
54 data->name == rhs.name();
55}
56
57/*!
58 Converts this qualified name to \l QVariant.
59*/
60QOpcUaQualifiedName::operator QVariant() const
61{
62 return QVariant::fromValue(value: *this);
63}
64
65/*!
66 Sets the values from \a rhs in this qualified name.
67*/
68QOpcUaQualifiedName &QOpcUaQualifiedName::operator=(const QOpcUaQualifiedName &rhs)
69{
70 if (this != &rhs)
71 data.operator=(o: rhs.data);
72 return *this;
73}
74
75QOpcUaQualifiedName::~QOpcUaQualifiedName()
76{
77}
78
79/*!
80 Returns the namespace index.
81*/
82quint16 QOpcUaQualifiedName::namespaceIndex() const
83{
84 return data->namespaceIndex;
85}
86
87/*!
88 Sets the namespace index to \a namespaceIndex.
89*/
90void QOpcUaQualifiedName::setNamespaceIndex(quint16 namespaceIndex)
91{
92 data->namespaceIndex = namespaceIndex;
93}
94
95/*!
96 Returns the name.
97*/
98QString QOpcUaQualifiedName::name() const
99{
100 return data->name;
101}
102
103/*!
104 Sets the name to \a name.
105*/
106void QOpcUaQualifiedName::setName(const QString &name)
107{
108 data->name = name;
109}
110
111#ifndef QT_NO_DEBUG_STREAM
112
113/*!
114 \fn QDebug QOpcUaQualifiedName::operator<<(QDebug debug, const QOpcUaQualifiedName &name)
115 \since 6.3
116
117 Writes the qualified \a name to the \a debug output.
118
119 \sa QDebug
120*/
121QDebug operator<<(QDebug debug, const QOpcUaQualifiedName &qn)
122{
123 QDebugStateSaver saver(debug);
124 debug.nospace().quote() << "QOpcUaQualifiedname(" << qn.namespaceIndex() << ", " << qn.name() << ")";
125 return debug;
126}
127
128#endif
129
130QT_END_NAMESPACE
131

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