1// Copyright (C) 2018 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 "qopcuareaditem.h"
5
6QT_BEGIN_NAMESPACE
7
8/*!
9 \class QOpcUaReadItem
10 \inmodule QtOpcUa
11 \brief This class stores the options for a read operation.
12
13 A read operation on an OPC UA server returns the entire value or a certain index range of the value of an
14 attribute of a node on the server. This class contains the necessary information for the backend to make
15 a read request to the server.
16
17 One or multiple objects of this class make up the request of a \l QOpcUaClient::readNodeAttributes() operation.
18
19 \sa QOpcUaClient::readNodeAttributes() QOpcUaReadResult
20*/
21
22class QOpcUaReadItemData : public QSharedData
23{
24public:
25 QString nodeId;
26 QOpcUa::NodeAttribute attribute {QOpcUa::NodeAttribute::Value};
27 QString indexRange;
28};
29
30QOpcUaReadItem::QOpcUaReadItem()
31 : data(new QOpcUaReadItemData)
32{
33
34}
35
36/*!
37 Constructs a read item from \a other.
38*/
39QOpcUaReadItem::QOpcUaReadItem(const QOpcUaReadItem &other)
40 : data(other.data)
41{
42}
43
44/*!
45 Constructs a read item for the index range \a indexRange of the attribute \a attr of node \a nodeId.
46*/
47QOpcUaReadItem::QOpcUaReadItem(const QString &nodeId, QOpcUa::NodeAttribute attr, const QString &indexRange)
48 : data(new QOpcUaReadItemData)
49{
50 setNodeId(nodeId);
51 setAttribute(attr);
52 setIndexRange(indexRange);
53}
54
55/*!
56 Sets the values from \a rhs in this read item.
57*/
58QOpcUaReadItem &QOpcUaReadItem::operator=(const QOpcUaReadItem &rhs)
59{
60 if (this != &rhs)
61 data.operator=(o: rhs.data);
62 return *this;
63}
64
65QOpcUaReadItem::~QOpcUaReadItem()
66{
67}
68
69/*!
70 Returns the index range.
71*/
72QString QOpcUaReadItem::indexRange() const
73{
74 return data->indexRange;
75}
76
77/*!
78 Sets the index range to \a indexRange.
79*/
80void QOpcUaReadItem::setIndexRange(const QString &indexRange)
81{
82 data->indexRange = indexRange;
83}
84
85/*!
86 Returns the node attribute id.
87*/
88QOpcUa::NodeAttribute QOpcUaReadItem::attribute() const
89{
90 return data->attribute;
91}
92
93/*!
94 Sets the node attribute id to \a attribute.
95*/
96void QOpcUaReadItem::setAttribute(QOpcUa::NodeAttribute attribute)
97{
98 data->attribute = attribute;
99}
100
101/*!
102 Returns the node id.
103*/
104QString QOpcUaReadItem::nodeId() const
105{
106 return data->nodeId;
107}
108
109/*!
110 Sets the node id to \a nodeId.
111*/
112void QOpcUaReadItem::setNodeId(const QString &nodeId)
113{
114 data->nodeId = nodeId;
115}
116
117/*!
118 \fn bool QOpcUaReadItem::operator==(const QOpcUaReadItem &lhs, const QOpcUaReadItem &rhs)
119
120 Returns \c true if \a lhs is equal to \a rhs; otherwise returns \c false.
121
122 Two read items are considered equal if their \c nodeId, \c attribute, and \c indexRange are
123 equal.
124*/
125bool operator==(const QOpcUaReadItem &lhs, const QOpcUaReadItem &rhs) noexcept
126{
127 return lhs.data->nodeId == rhs.data->nodeId &&
128 lhs.data->attribute == rhs.data->attribute &&
129 lhs.data->indexRange == rhs.data->indexRange;
130}
131
132/*!
133 \fn bool QOpcUaReadItem::operator!=(const QOpcUaReadItem &lhs, const QOpcUaReadItem &rhs)
134
135 Returns \c true if \a lhs is not equal to \a rhs; otherwise returns \c false.
136
137 Two read items are considered not equal if their \c nodeId, \c attribute or \c indexRange are
138 not equal.
139*/
140
141QT_END_NAMESPACE
142

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