| 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 | |
| 7 | QT_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 | |
| 18 | class QOpcUaRelativePathElementData : public QSharedData |
| 19 | { |
| 20 | public: |
| 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 | */ |
| 30 | QOpcUaRelativePathElement::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 | */ |
| 38 | QOpcUaRelativePathElement::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 | */ |
| 48 | QOpcUaRelativePathElement::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 | */ |
| 58 | QOpcUaRelativePathElement::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 | */ |
| 66 | QOpcUaRelativePathElement &QOpcUaRelativePathElement::operator=(const QOpcUaRelativePathElement &rhs) |
| 67 | { |
| 68 | if (this != &rhs) |
| 69 | data.operator=(o: rhs.data); |
| 70 | return *this; |
| 71 | } |
| 72 | |
| 73 | /*! |
| 74 | \fn bool QOpcUaRelativePathElement::operator==(const QOpcUaRelativePathElement &lhs, |
| 75 | const QOpcUaRelativePathElement &rhs) |
| 76 | |
| 77 | Returns \c true if \a lhs has the same value as \a rhs. |
| 78 | */ |
| 79 | bool comparesEqual(const QOpcUaRelativePathElement &lhs, |
| 80 | const QOpcUaRelativePathElement &rhs) noexcept |
| 81 | { |
| 82 | return lhs.includeSubtypes() == rhs.includeSubtypes() && |
| 83 | lhs.isInverse() == rhs.isInverse() && |
| 84 | lhs.referenceTypeId() == rhs.referenceTypeId() && |
| 85 | lhs.targetName() == rhs.targetName(); |
| 86 | } |
| 87 | |
| 88 | QOpcUaRelativePathElement::~QOpcUaRelativePathElement() |
| 89 | { |
| 90 | } |
| 91 | |
| 92 | /*! |
| 93 | Returns the qualified name of the reference's target. |
| 94 | */ |
| 95 | QOpcUaQualifiedName QOpcUaRelativePathElement::targetName() const |
| 96 | { |
| 97 | return data->targetName; |
| 98 | } |
| 99 | |
| 100 | /*! |
| 101 | Sets the target name to \a targetName, for example QOpcUaQualifiedName(0, "DataTypes"). |
| 102 | */ |
| 103 | void QOpcUaRelativePathElement::setTargetName(const QOpcUaQualifiedName &targetName) |
| 104 | { |
| 105 | data->targetName = targetName; |
| 106 | } |
| 107 | |
| 108 | /*! |
| 109 | Returns the value of the includeSubtypes flag. |
| 110 | */ |
| 111 | bool QOpcUaRelativePathElement::includeSubtypes() const |
| 112 | { |
| 113 | return data->includeSubtypes; |
| 114 | } |
| 115 | |
| 116 | /*! |
| 117 | Sets the includeSubtypes flag to \a includeSubtypes. |
| 118 | If the flag is \c true, the lookup also follows references with subtypes of \l referenceTypeId(). |
| 119 | */ |
| 120 | void QOpcUaRelativePathElement::setIncludeSubtypes(bool includeSubtypes) |
| 121 | { |
| 122 | data->includeSubtypes = includeSubtypes; |
| 123 | } |
| 124 | |
| 125 | /*! |
| 126 | \since 6.7 |
| 127 | |
| 128 | Returns a \l QVariant containing this relative path element. |
| 129 | */ |
| 130 | QOpcUaRelativePathElement::operator QVariant() const |
| 131 | { |
| 132 | return QVariant::fromValue(value: *this); |
| 133 | } |
| 134 | |
| 135 | /*! |
| 136 | Returns the value of the isInverse flag. |
| 137 | */ |
| 138 | bool QOpcUaRelativePathElement::isInverse() const |
| 139 | { |
| 140 | return data->isInverse; |
| 141 | } |
| 142 | |
| 143 | /*! |
| 144 | Sets the isInverse flag to \a isInverse. |
| 145 | If the flag is \c true, the lookup follows the reverse reference. |
| 146 | */ |
| 147 | void QOpcUaRelativePathElement::setIsInverse(bool isInverse) |
| 148 | { |
| 149 | data->isInverse = isInverse; |
| 150 | } |
| 151 | |
| 152 | /*! |
| 153 | Returns the type id of the reference connecting this node to the previous node. |
| 154 | */ |
| 155 | QString QOpcUaRelativePathElement::referenceTypeId() const |
| 156 | { |
| 157 | return data->referenceTypeId; |
| 158 | } |
| 159 | |
| 160 | /*! |
| 161 | Sets the reference type id to \a referenceTypeId. |
| 162 | */ |
| 163 | void QOpcUaRelativePathElement::setReferenceTypeId(const QString &referenceTypeId) |
| 164 | { |
| 165 | data->referenceTypeId = referenceTypeId; |
| 166 | } |
| 167 | |
| 168 | /*! |
| 169 | Sets the reference type id to \a referenceTypeId. |
| 170 | */ |
| 171 | void QOpcUaRelativePathElement::setReferenceTypeId(QOpcUa::ReferenceTypeId referenceTypeId) |
| 172 | { |
| 173 | data->referenceTypeId = QOpcUa::nodeIdFromReferenceType(referenceType: referenceTypeId); |
| 174 | } |
| 175 | |
| 176 | /*! |
| 177 | \fn bool QOpcUaRelativePathElement::operator!=(const QOpcUaRelativePathElement &lhs, |
| 178 | const QOpcUaRelativePathElement &rhs) |
| 179 | \since 6.7 |
| 180 | |
| 181 | Returns \c true if \a lhs has a different value than \a rhs. |
| 182 | */ |
| 183 | |
| 184 | QT_END_NAMESPACE |
| 185 | |