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#include <private/opcuaattributecache_p.h>
5#include <private/opcuaattributevalue_p.h>
6
7QT_BEGIN_NAMESPACE
8
9/*!
10 \class OpcUaAttributeCache
11 \inqmlmodule QtOpcUa
12 \brief Flexible attribute value cache providing signals.
13 \deprecated [6.9]
14 \internal
15
16 This class is just for internal use in the declarative backend and not exposed to users.
17
18 It caches node attribute values and provides access. Main purpose is to
19 let \l OpcUaAttributeValue provide separate value change signals for each attribute.
20
21 \sa OpcUaAttributeValue
22*/
23
24OpcUaAttributeCache::OpcUaAttributeCache(QObject *parent) : QObject(parent)
25{
26}
27
28void OpcUaAttributeCache::setAttributeValue(QOpcUa::NodeAttribute attr, const QVariant &value)
29{
30 attribute(attribute: attr)->setValue(value);
31}
32
33void OpcUaAttributeCache::invalidate()
34{
35 // Reset all values in the cache to invalid.
36 // Do not clear() the cache because there are still objects with
37 // connections waiting for notifications
38 for (auto i = m_attributeCache.constBegin(); i != m_attributeCache.constEnd(); ++i)
39 i.value()->invalidate();
40}
41
42OpcUaAttributeValue *OpcUaAttributeCache::attribute(QOpcUa::NodeAttribute attr)
43{
44 if (!m_attributeCache.contains(key: attr))
45 m_attributeCache.insert(key: attr, value: new OpcUaAttributeValue(this));
46 return m_attributeCache.value(key: attr);
47}
48
49const QVariant &OpcUaAttributeCache::attributeValue(QOpcUa::NodeAttribute attr)
50{
51 return attribute(attr)->value();
52}
53
54QT_END_NAMESPACE
55

source code of qtopcua/src/declarative_opcua/opcuaattributecache.cpp