| 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 | |
| 6 | QT_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 1.05 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 | |
| 18 | class QOpcUaQualifiedNameData : public QSharedData | 
| 19 | { | 
| 20 | public: | 
| 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 | |
| 25 | /*! | 
| 26 | Default constructs a qualified name with no parameters set. | 
| 27 | */ | 
| 28 | QOpcUaQualifiedName::QOpcUaQualifiedName() | 
| 29 | : data(new QOpcUaQualifiedNameData) | 
| 30 | { | 
| 31 | } | 
| 32 | |
| 33 | /*! | 
| 34 | Constructs a qualified name from \a rhs. | 
| 35 | */ | 
| 36 | QOpcUaQualifiedName::QOpcUaQualifiedName(const QOpcUaQualifiedName &rhs) | 
| 37 | : data(rhs.data) | 
| 38 | { | 
| 39 | } | 
| 40 | |
| 41 | /*! | 
| 42 | Constructs a qualified name with namespace index \a namespaceIndex and the name \a name. | 
| 43 | */ | 
| 44 | QOpcUaQualifiedName::QOpcUaQualifiedName(quint16 namespaceIndex, const QString &name) | 
| 45 | : data(new QOpcUaQualifiedNameData) | 
| 46 | { | 
| 47 | data->namespaceIndex = namespaceIndex; | 
| 48 | data->name = name; | 
| 49 | } | 
| 50 | |
| 51 | /*! | 
| 52 | Returns \c true if this qualified name has the same value as \a rhs. | 
| 53 | */ | 
| 54 | bool QOpcUaQualifiedName::operator==(const QOpcUaQualifiedName &rhs) const | 
| 55 | { | 
| 56 | return data->namespaceIndex == rhs.namespaceIndex() && | 
| 57 | data->name == rhs.name(); | 
| 58 | } | 
| 59 | |
| 60 | /*! | 
| 61 | Converts this qualified name to \l QVariant. | 
| 62 | */ | 
| 63 | QOpcUaQualifiedName::operator QVariant() const | 
| 64 | { | 
| 65 | return QVariant::fromValue(value: *this); | 
| 66 | } | 
| 67 | |
| 68 | /*! | 
| 69 | Sets the values from \a rhs in this qualified name. | 
| 70 | */ | 
| 71 | QOpcUaQualifiedName &QOpcUaQualifiedName::operator=(const QOpcUaQualifiedName &rhs) | 
| 72 | { | 
| 73 | if (this != &rhs) | 
| 74 | data.operator=(o: rhs.data); | 
| 75 | return *this; | 
| 76 | } | 
| 77 | |
| 78 | QOpcUaQualifiedName::~QOpcUaQualifiedName() | 
| 79 | { | 
| 80 | } | 
| 81 | |
| 82 | /*! | 
| 83 | Returns the namespace index. | 
| 84 | */ | 
| 85 | quint16 QOpcUaQualifiedName::namespaceIndex() const | 
| 86 | { | 
| 87 | return data->namespaceIndex; | 
| 88 | } | 
| 89 | |
| 90 | /*! | 
| 91 | Sets the namespace index to \a namespaceIndex. | 
| 92 | */ | 
| 93 | void QOpcUaQualifiedName::setNamespaceIndex(quint16 namespaceIndex) | 
| 94 | { | 
| 95 | data->namespaceIndex = namespaceIndex; | 
| 96 | } | 
| 97 | |
| 98 | /*! | 
| 99 | Returns the name. | 
| 100 | */ | 
| 101 | QString QOpcUaQualifiedName::name() const | 
| 102 | { | 
| 103 | return data->name; | 
| 104 | } | 
| 105 | |
| 106 | /*! | 
| 107 | Sets the name to \a name. | 
| 108 | */ | 
| 109 | void QOpcUaQualifiedName::setName(const QString &name) | 
| 110 | { | 
| 111 | data->name = name; | 
| 112 | } | 
| 113 | |
| 114 | #ifndef QT_NO_DEBUG_STREAM | 
| 115 | |
| 116 | /*! | 
| 117 | \fn QDebug QOpcUaQualifiedName::operator<<(QDebug debug, const QOpcUaQualifiedName &name) | 
| 118 | \since 6.3 | 
| 119 | |
| 120 | Writes the qualified \a name to the \a debug output. | 
| 121 | |
| 122 | \sa QDebug | 
| 123 | */ | 
| 124 | QDebug operator<<(QDebug debug, const QOpcUaQualifiedName &qn) | 
| 125 | { | 
| 126 | QDebugStateSaver saver(debug); | 
| 127 |     debug.nospace().quote() << "QOpcUaQualifiedname("<< qn.namespaceIndex() << ", "<< qn.name() << ")";  | 
| 128 | return debug; | 
| 129 | } | 
| 130 | |
| 131 | #endif | 
| 132 | |
| 133 | QT_END_NAMESPACE | 
| 134 | 
