| 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 "qopcuaargument.h" |
| 5 | #include "qopcuatype.h" |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | /*! |
| 10 | \class QOpcUaArgument |
| 11 | \inmodule QtOpcUa |
| 12 | \brief The OPC UA Argument type. |
| 13 | |
| 14 | This is the Qt OPC UA representation for the Argument type defined in OPC UA 1.05 part 3, 8.6. |
| 15 | |
| 16 | The Argument type is mainly used for the values of the InputArguments and OutputArguments properties |
| 17 | which describe the parameters and return values of method nodes. |
| 18 | */ |
| 19 | class QOpcUaArgumentData : public QSharedData |
| 20 | { |
| 21 | public: |
| 22 | QString name; |
| 23 | QString dataTypeId; |
| 24 | qint32 valueRank{-2}; |
| 25 | QList<quint32> arrayDimensions; |
| 26 | QOpcUaLocalizedText description; |
| 27 | }; |
| 28 | |
| 29 | /*! |
| 30 | Default constructs an argument with no parameters set. |
| 31 | */ |
| 32 | QOpcUaArgument::QOpcUaArgument() |
| 33 | : data(new QOpcUaArgumentData) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | QOpcUaArgument::QOpcUaArgument(const QOpcUaArgument &rhs) |
| 38 | : data(rhs.data) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | /*! |
| 43 | Constructs an argument with name \a name, data type id \a dataTypeId, value rank \a valueRank, |
| 44 | array dimensions \a arrayDimensions and description \a description. |
| 45 | */ |
| 46 | QOpcUaArgument::QOpcUaArgument(const QString &name, const QString &dataTypeId, qint32 valueRank, |
| 47 | const QList<quint32> &arrayDimensions, const QOpcUaLocalizedText &description) |
| 48 | : data(new QOpcUaArgumentData) |
| 49 | { |
| 50 | setName(name); |
| 51 | setDataTypeId(dataTypeId); |
| 52 | setValueRank(valueRank); |
| 53 | setArrayDimensions(arrayDimensions); |
| 54 | setDescription(description); |
| 55 | } |
| 56 | |
| 57 | /*! |
| 58 | Sets the values from \a rhs in this argument. |
| 59 | */ |
| 60 | QOpcUaArgument &QOpcUaArgument::operator=(const QOpcUaArgument &rhs) |
| 61 | { |
| 62 | if (this != &rhs) |
| 63 | data.operator=(o: rhs.data); |
| 64 | return *this; |
| 65 | } |
| 66 | |
| 67 | /*! |
| 68 | Returns true if this argument has the same value as \a other. |
| 69 | */ |
| 70 | bool QOpcUaArgument::operator==(const QOpcUaArgument &other) const |
| 71 | { |
| 72 | return data->arrayDimensions == other.arrayDimensions() && |
| 73 | QOpcUa::nodeIdEquals(first: data->dataTypeId, second: other.dataTypeId()) && |
| 74 | data->description == other.description() && |
| 75 | data->name == other.name() && |
| 76 | data->valueRank == other.valueRank(); |
| 77 | } |
| 78 | |
| 79 | /*! |
| 80 | Converts this argument to \l QVariant. |
| 81 | */ |
| 82 | QOpcUaArgument::operator QVariant() const |
| 83 | { |
| 84 | return QVariant::fromValue(value: *this); |
| 85 | } |
| 86 | |
| 87 | QOpcUaArgument::~QOpcUaArgument() |
| 88 | { |
| 89 | } |
| 90 | |
| 91 | /*! |
| 92 | Returns the name of the argument. |
| 93 | */ |
| 94 | QString QOpcUaArgument::name() const |
| 95 | { |
| 96 | return data->name; |
| 97 | } |
| 98 | |
| 99 | /*! |
| 100 | Sets the name of the argument to \a name. |
| 101 | */ |
| 102 | void QOpcUaArgument::setName(const QString &name) |
| 103 | { |
| 104 | data->name = name; |
| 105 | } |
| 106 | |
| 107 | /*! |
| 108 | Returns the data type node id of the argument. |
| 109 | */ |
| 110 | QString QOpcUaArgument::dataTypeId() const |
| 111 | { |
| 112 | return data->dataTypeId; |
| 113 | } |
| 114 | |
| 115 | /*! |
| 116 | Sets the data type node id of the argument to \a dataTypeId. |
| 117 | */ |
| 118 | void QOpcUaArgument::setDataTypeId(const QString &dataTypeId) |
| 119 | { |
| 120 | data->dataTypeId = dataTypeId; |
| 121 | } |
| 122 | |
| 123 | /*! |
| 124 | Returns the value rank of the argument. |
| 125 | The value rank describes the structure of the value. |
| 126 | \table |
| 127 | \header |
| 128 | \li ValueRank |
| 129 | \li Meaning |
| 130 | \row |
| 131 | \li -3 |
| 132 | \li Scalar or one dimensional array |
| 133 | \row |
| 134 | \li -2 |
| 135 | \li Scalar or array with any number of dimensions |
| 136 | \row |
| 137 | \li -1 |
| 138 | \li Not an array |
| 139 | \row |
| 140 | \li 0 |
| 141 | \li Array with one or more dimensions |
| 142 | \row |
| 143 | \li 1 |
| 144 | \li One dimensional array |
| 145 | \row |
| 146 | \li >1 |
| 147 | \li Array with n dimensions |
| 148 | \endtable |
| 149 | */ |
| 150 | qint32 QOpcUaArgument::valueRank() const |
| 151 | { |
| 152 | return data->valueRank; |
| 153 | } |
| 154 | |
| 155 | /*! |
| 156 | Sets the value rank of the argument to \a valueRank. |
| 157 | */ |
| 158 | void QOpcUaArgument::setValueRank(qint32 valueRank) |
| 159 | { |
| 160 | data->valueRank = valueRank; |
| 161 | } |
| 162 | |
| 163 | /*! |
| 164 | Returns the array dimensions of the argument. |
| 165 | |
| 166 | The array dimensions describe the length of each array dimension. |
| 167 | */ |
| 168 | QList<quint32> QOpcUaArgument::arrayDimensions() const |
| 169 | { |
| 170 | return data->arrayDimensions; |
| 171 | } |
| 172 | |
| 173 | /*! |
| 174 | Returns a reference to the array dimensions of the argument. |
| 175 | */ |
| 176 | QList<quint32> &QOpcUaArgument::arrayDimensionsRef() |
| 177 | { |
| 178 | return data->arrayDimensions; |
| 179 | } |
| 180 | |
| 181 | /*! |
| 182 | Sets the array dimensions of the argument to \a arrayDimensions. |
| 183 | */ |
| 184 | void QOpcUaArgument::setArrayDimensions(const QList<quint32> &arrayDimensions) |
| 185 | { |
| 186 | data->arrayDimensions = arrayDimensions; |
| 187 | } |
| 188 | |
| 189 | /*! |
| 190 | Returns the description of the argument. |
| 191 | */ |
| 192 | QOpcUaLocalizedText QOpcUaArgument::description() const |
| 193 | { |
| 194 | return data->description; |
| 195 | } |
| 196 | |
| 197 | /*! |
| 198 | Sets the description of the argument to \a description. |
| 199 | */ |
| 200 | void QOpcUaArgument::setDescription(const QOpcUaLocalizedText &description) |
| 201 | { |
| 202 | data->description = description; |
| 203 | } |
| 204 | |
| 205 | QT_END_NAMESPACE |
| 206 | |