1 | // Copyright (C) 2018 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #pragma once |
5 | |
6 | #include <private/opcuaconnection_p.h> |
7 | #include <private/opcuanodeid_p.h> |
8 | #include <private/universalnode_p.h> |
9 | #include <private/opcuaattributecache_p.h> |
10 | #include <private/opcuaeventfilter_p.h> |
11 | #include <private/opcuanodeidtype_p.h> |
12 | |
13 | #include <QtOpcUa/qopcualocalizedtext.h> |
14 | |
15 | #include <QDateTime> |
16 | #include <QObject> |
17 | |
18 | #include <QtQml/qqml.h> |
19 | |
20 | // |
21 | // W A R N I N G |
22 | // ------------- |
23 | // |
24 | // This file is not part of the Qt API. It exists purely as an |
25 | // implementation detail. This header file may change from version to |
26 | // version without notice, or even be removed. |
27 | // |
28 | // We mean it. |
29 | // |
30 | |
31 | QT_BEGIN_NAMESPACE |
32 | |
33 | class OpcUaNode : public QObject |
34 | { |
35 | Q_OBJECT |
36 | Q_DISABLE_COPY(OpcUaNode) |
37 | Q_CLASSINFO("RegisterEnumClassesUnscoped" , "false" ) |
38 | |
39 | Q_PROPERTY(OpcUaNodeIdType* nodeId READ nodeId WRITE setNodeId NOTIFY nodeIdChanged) |
40 | Q_PROPERTY(OpcUaConnection* connection READ connection WRITE setConnection NOTIFY connectionChanged) |
41 | Q_PROPERTY(bool readyToUse READ readyToUse NOTIFY readyToUseChanged) |
42 | Q_PROPERTY(OpcUaNode::Status status READ status NOTIFY statusChanged) |
43 | Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) |
44 | Q_PROPERTY(OpcUaEventFilter *eventFilter READ eventFilter WRITE setEventFilter NOTIFY eventFilterChanged) |
45 | |
46 | // basic node properties |
47 | Q_PROPERTY(QString browseName READ browseName WRITE setBrowseName NOTIFY browseNameChanged) |
48 | Q_PROPERTY(QOpcUa::NodeClass nodeClass READ nodeClass NOTIFY nodeClassChanged) |
49 | Q_PROPERTY(QOpcUaLocalizedText displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged) |
50 | Q_PROPERTY(QOpcUaLocalizedText description READ description WRITE setDescription NOTIFY descriptionChanged) |
51 | |
52 | Q_ENUM(QOpcUa::NodeClass); |
53 | |
54 | QML_NAMED_ELEMENT(Node) |
55 | QML_ADDED_IN_VERSION(5, 12) |
56 | |
57 | public: |
58 | enum class Status { |
59 | Valid, |
60 | InvalidNodeId, |
61 | NoConnection, |
62 | InvalidNodeType, |
63 | InvalidClient, |
64 | FailedToResolveNode, |
65 | InvalidObjectNode, |
66 | FailedToReadAttributes, |
67 | FailedToSetupMonitoring, |
68 | FailedToWriteAttribute, |
69 | FailedToModifyMonitoring, |
70 | FailedToDisableMonitoring |
71 | }; |
72 | Q_ENUM(Status); |
73 | |
74 | OpcUaNode(QObject *parent = nullptr); |
75 | ~OpcUaNode(); |
76 | OpcUaNodeIdType *nodeId() const; |
77 | OpcUaConnection *connection(); |
78 | bool readyToUse() const; |
79 | |
80 | void setBrowseName(const QString &value); |
81 | QString browseName(); |
82 | |
83 | QOpcUa::NodeClass nodeClass(); |
84 | |
85 | void setDisplayName(const QOpcUaLocalizedText &value); |
86 | QOpcUaLocalizedText displayName(); |
87 | |
88 | void setDescription(const QOpcUaLocalizedText &value); |
89 | QOpcUaLocalizedText description(); |
90 | |
91 | OpcUaNode::Status status() const; |
92 | const QString &errorMessage() const; |
93 | |
94 | using QObject::eventFilter; |
95 | OpcUaEventFilter *eventFilter() const; |
96 | void setEventFilter(OpcUaEventFilter *eventFilter); |
97 | |
98 | Q_INVOKABLE QDateTime getSourceTimestamp(QOpcUa::NodeAttribute) const; |
99 | Q_INVOKABLE QDateTime getServerTimestamp(QOpcUa::NodeAttribute) const; |
100 | |
101 | // This function is not exposed to QML |
102 | const UniversalNode &resolvedNode() const; |
103 | |
104 | // This function is not exposed to QML |
105 | QOpcUaNode* node() const; |
106 | |
107 | public slots: |
108 | void setNodeId(OpcUaNodeIdType *nodeId); |
109 | void setConnection(OpcUaConnection *); |
110 | |
111 | signals: |
112 | void nodeIdChanged(OpcUaNodeIdType *nodeId); |
113 | void connectionChanged(OpcUaConnection *); |
114 | void nodeChanged(); |
115 | void readyToUseChanged(); |
116 | void browseNameChanged(); |
117 | void nodeClassChanged(); |
118 | void displayNameChanged(); |
119 | void descriptionChanged(); |
120 | void statusChanged(); |
121 | void errorMessageChanged(); |
122 | void eventFilterChanged(); |
123 | void eventOccurred(const QVariantList&values); |
124 | |
125 | protected slots: |
126 | virtual void setupNode(const QString &absoluteNodePath); |
127 | void updateNode(); |
128 | void updateEventFilter(); |
129 | |
130 | protected: |
131 | void setStatus(Status status, const QString &message = QString()); |
132 | void setAttributesToRead(QOpcUa::NodeAttributes attributes); |
133 | QOpcUa::NodeAttributes attributesToRead() const; |
134 | void retrieveAbsoluteNodePath(OpcUaNodeIdType *, std::function<void (const QString &)>); |
135 | void setReadyToUse(bool value = true); |
136 | virtual bool checkValidity(); |
137 | |
138 | OpcUaNodeIdType *m_nodeId = nullptr; |
139 | QOpcUaNode *m_node = nullptr; |
140 | OpcUaConnection *m_connection = nullptr; |
141 | QString m_absoluteNodePath; // not exposed |
142 | bool m_readyToUse = false; |
143 | UniversalNode m_resolvedNode; |
144 | OpcUaAttributeCache m_attributeCache; |
145 | QOpcUa::NodeAttributes m_attributesToRead; |
146 | Status m_status; |
147 | QString m_errorMessage; |
148 | OpcUaEventFilter *m_eventFilter = nullptr; |
149 | bool m_eventFilterActive = false; |
150 | |
151 | QMetaObject::Connection m_attributeUpdatedConnection; |
152 | QMetaObject::Connection m_attributeReadConnection; |
153 | QMetaObject::Connection m_enableMonitoringFinishedConnection; |
154 | QMetaObject::Connection m_disableMonitoringFinishedConnection; |
155 | QMetaObject::Connection m_monitoringStatusChangedConnection; |
156 | QMetaObject::Connection m_eventOccurredConnection; |
157 | }; |
158 | |
159 | QT_END_NAMESPACE |
160 | |