| 1 | // Copyright (C) 2019 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 "qopcuahistorydata.h" | 
| 5 | |
| 6 | QT_BEGIN_NAMESPACE | 
| 7 | |
| 8 | /*! | 
| 9 | \class QOpcUaHistoryData | 
| 10 | \inmodule QtOpcUa | 
| 11 | \brief This class stores historical data values from a node. | 
| 12 | \since 6.3 | 
| 13 | |
| 14 | When a request to read history data is being handled, instances of this class | 
| 15 | are used to store information about which node has been read, its values and | 
| 16 | the status code. | 
| 17 | The finished signal of a history read request will return a list of QOpcUaHistoryData | 
| 18 | objects which can be parsed to review the results of the request. | 
| 19 | */ | 
| 20 | |
| 21 | class QOpcUaHistoryDataData : public QSharedData | 
| 22 | { | 
| 23 | public: | 
| 24 | QList<QOpcUaDataValue> result; | 
| 25 | QOpcUa::UaStatusCode statusCode; | 
| 26 | QString nodeId; | 
| 27 | }; | 
| 28 | |
| 29 | /*! | 
| 30 | Constructs an invalid history data item. | 
| 31 | */ | 
| 32 | QOpcUaHistoryData::QOpcUaHistoryData() | 
| 33 | : data(new QOpcUaHistoryDataData) | 
| 34 | { | 
| 35 | data->statusCode = QOpcUa::UaStatusCode::Good; | 
| 36 | } | 
| 37 | |
| 38 | /*! | 
| 39 | Constructs a history data item and stores which node it corresponds to. | 
| 40 | */ | 
| 41 | QOpcUaHistoryData::QOpcUaHistoryData(const QString &nodeId) | 
| 42 | : data(new QOpcUaHistoryDataData) | 
| 43 | { | 
| 44 | data->statusCode = QOpcUa::UaStatusCode::Good; | 
| 45 | data->nodeId = nodeId; | 
| 46 | } | 
| 47 | |
| 48 | /*! | 
| 49 | Constructs a history data item from \a other. | 
| 50 | */ | 
| 51 | QOpcUaHistoryData::QOpcUaHistoryData(const QOpcUaHistoryData &other) | 
| 52 | : data(other.data) | 
| 53 | { | 
| 54 | } | 
| 55 | |
| 56 | /*! | 
| 57 | Destroys the history data item. | 
| 58 | */ | 
| 59 | QOpcUaHistoryData::~QOpcUaHistoryData() | 
| 60 | { | 
| 61 | } | 
| 62 | |
| 63 | /*! | 
| 64 | \fn QOpcUaHistoryData::swap(QOpcUaHistoryData &other) | 
| 65 | |
| 66 | Swaps this data value instance with \a other. This function is very | 
| 67 | fast and never fails. | 
| 68 | */ | 
| 69 | |
| 70 | /*! | 
| 71 | Returns the status code which indicates if an error occurred while fetching the history data. | 
| 72 | */ | 
| 73 | QOpcUa::UaStatusCode QOpcUaHistoryData::statusCode() const | 
| 74 | { | 
| 75 | return data->statusCode; | 
| 76 | } | 
| 77 | |
| 78 | /*! | 
| 79 | Sets the status code to \a statusCode. | 
| 80 | */ | 
| 81 | void QOpcUaHistoryData::setStatusCode(QOpcUa::UaStatusCode statusCode) | 
| 82 | { | 
| 83 | data.detach(); | 
| 84 | data->statusCode = statusCode; | 
| 85 | } | 
| 86 | |
| 87 | /*! | 
| 88 | Returns the list of data value objects which contain the results of the history read request. | 
| 89 | */ | 
| 90 | QList<QOpcUaDataValue> QOpcUaHistoryData::result() const | 
| 91 | { | 
| 92 | return data->result; | 
| 93 | } | 
| 94 | |
| 95 | /*! | 
| 96 | Returns the number of available data value objects. | 
| 97 | */ | 
| 98 | int QOpcUaHistoryData::count() const | 
| 99 | { | 
| 100 | return data->result.size(); | 
| 101 | } | 
| 102 | |
| 103 | /*! | 
| 104 | Adds a data value object given by \a value. | 
| 105 | */ | 
| 106 | void QOpcUaHistoryData::addValue(const QOpcUaDataValue &value) | 
| 107 | { | 
| 108 | data.detach(); | 
| 109 | data->result.append(t: value); | 
| 110 | } | 
| 111 | |
| 112 | /*! | 
| 113 | Returns the nodeId of the node whose data has been stored. | 
| 114 | */ | 
| 115 | QString QOpcUaHistoryData::nodeId() const | 
| 116 | { | 
| 117 | return data->nodeId; | 
| 118 | } | 
| 119 | |
| 120 | /*! | 
| 121 | Sets the nodeId to \a nodeId. | 
| 122 | */ | 
| 123 | void QOpcUaHistoryData::setNodeId(const QString &nodeId) | 
| 124 | { | 
| 125 | data.detach(); | 
| 126 | data->nodeId = nodeId; | 
| 127 | } | 
| 128 | |
| 129 | /*! | 
| 130 | Sets the values from \a other in this history data item. | 
| 131 | */ | 
| 132 | QOpcUaHistoryData &QOpcUaHistoryData::operator=(const QOpcUaHistoryData &other) | 
| 133 | { | 
| 134 | if (this != &other) | 
| 135 | data.operator=(o: other.data); | 
| 136 | return *this; | 
| 137 | } | 
| 138 | |
| 139 | QT_END_NAMESPACE | 
| 140 | 
