1// Copyright (C) 2021 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 "qopcuadatavalue.h"
5
6QT_BEGIN_NAMESPACE
7
8/*!
9 \class QOpcUaDataValue
10 \inmodule QtOpcUa
11 \brief This class stores OPC UA value data and associated metadata.
12 \since 6.3
13
14 This class corresponds to the OPC UA DataValue type.
15*/
16class QOpcUaDataValueData : public QSharedData
17{
18public:
19 QDateTime serverTimestamp;
20 QDateTime sourceTimestamp;
21 QOpcUa::UaStatusCode statusCode {QOpcUa::UaStatusCode::Good};
22 QVariant value;
23};
24
25/*!
26 Constructs an invalid data value.
27*/
28QOpcUaDataValue::QOpcUaDataValue()
29 : data(new QOpcUaDataValueData)
30{
31}
32
33/*!
34 Constructs a data value from \a other.
35*/
36QOpcUaDataValue::QOpcUaDataValue(const QOpcUaDataValue &other)
37 : data(other.data)
38{
39}
40
41/*!
42 Sets the values from \a other in this data value.
43*/
44QOpcUaDataValue &QOpcUaDataValue::operator=(const QOpcUaDataValue &other)
45{
46 if (this != &other)
47 data.operator=(o: other.data);
48 return *this;
49}
50
51/*!
52 Destroys the data value.
53*/
54QOpcUaDataValue::~QOpcUaDataValue()
55{
56}
57
58/*!
59 \fn QOpcUaDataValue::swap(QOpcUaDataValue &other)
60
61 Swaps this data value instance with \a other. This function is very
62 fast and never fails.
63*/
64
65/*!
66 Returns the value.
67*/
68QVariant QOpcUaDataValue::value() const
69{
70 return data->value;
71}
72
73/*!
74 Sets the value to \a value.
75*/
76void QOpcUaDataValue::setValue(const QVariant &value)
77{
78 data.detach();
79 data->value = value;
80}
81
82/*!
83 Returns the status code for this data value. If the status code is not \l {QOpcUa::UaStatusCode} {Good}, the
84 value and the timestamps are invalid.
85*/
86QOpcUa::UaStatusCode QOpcUaDataValue::statusCode() const
87{
88 return data->statusCode;
89}
90
91/*!
92 Sets the status code to \a statusCode.
93*/
94void QOpcUaDataValue::setStatusCode(QOpcUa::UaStatusCode statusCode)
95{
96 data.detach();
97 data->statusCode = statusCode;
98}
99
100/*!
101 Returns the source timestamp for \l value().
102*/
103QDateTime QOpcUaDataValue::sourceTimestamp() const
104{
105 return data->sourceTimestamp;
106}
107
108/*!
109 Sets the source timestamp to \a sourceTimestamp.
110*/
111void QOpcUaDataValue::setSourceTimestamp(const QDateTime &sourceTimestamp)
112{
113 data.detach();
114 data->sourceTimestamp = sourceTimestamp;
115}
116
117/*!
118 Returns the server timestamp for \l value().
119*/
120QDateTime QOpcUaDataValue::serverTimestamp() const
121{
122 return data->serverTimestamp;
123}
124
125/*!
126 Sets the server timestamp to \a serverTimestamp.
127*/
128void QOpcUaDataValue::setServerTimestamp(const QDateTime &serverTimestamp)
129{
130 data.detach();
131 data->serverTimestamp = serverTimestamp;
132}
133
134QT_END_NAMESPACE
135

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