diff options
author | Liang Qi <liang.qi@qt.io> | 2018-07-03 10:01:05 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2018-07-03 10:26:00 +0200 |
commit | 49f40787dca56217703d93aee44d67fc38dc1511 (patch) | |
tree | 9a6bac52c0e1dca3ae07479a4e1b75c3ab58e06d /examples | |
parent | bd0b07caa0a5bb11e3599687b425e7e018f3b9f6 (diff) | |
parent | ec8595986aeb73b030c50dfa3596e3559222c388 (diff) |
Merge remote-tracking branch 'origin/5.11' into dev
Conflicts:
examples/opcua/opcuaviewer/treeitem.cpp
Change-Id: I33dd1d6125dc07847be73696c6dbb8924f529804
Diffstat (limited to 'examples')
-rw-r--r-- | examples/opcua/opcuaviewer/treeitem.cpp | 26 | ||||
-rw-r--r-- | examples/opcua/opcuaviewer/treeitem.h | 2 |
2 files changed, 22 insertions, 6 deletions
diff --git a/examples/opcua/opcuaviewer/treeitem.cpp b/examples/opcua/opcuaviewer/treeitem.cpp index fa733e1..eb94523 100644 --- a/examples/opcua/opcuaviewer/treeitem.cpp +++ b/examples/opcua/opcuaviewer/treeitem.cpp @@ -150,7 +150,7 @@ QVariant TreeItem::data(int column) if (!mAttributesReady) return tr("Loading ..."); - return mOpcNode->attribute(QOpcUa::NodeAttribute::Description); + return mOpcNode->attribute(QOpcUa::NodeAttribute::Description).value<QOpcUa::QLocalizedText>().text(); } return QVariant(); } @@ -169,7 +169,15 @@ TreeItem *TreeItem::parentItem() void TreeItem::appendChild(TreeItem *child) { - mChildItems.append(child); + if (!child) + return; + + if (!hasChildNodeItem(child->mNodeId)) { + mChildItems.append(child); + mChildNodeIds.insert(child->mNodeId); + } else { + child->deleteLater(); + } } QPixmap TreeItem::icon(int column) const @@ -198,6 +206,11 @@ QPixmap TreeItem::icon(int column) const return p; } +bool TreeItem::hasChildNodeItem(const QString &nodeId) const +{ + return mChildNodeIds.contains(nodeId); +} + void TreeItem::startBrowsing() { if (mBrowseStarted) @@ -217,8 +230,6 @@ void TreeItem::handleAttributes(QOpcUa::NodeAttributes attr) mNodeBrowseName = mOpcNode->attribute(QOpcUa::NodeAttribute::BrowseName).value<QOpcUa::QQualifiedName>().name(); if (attr & QOpcUa::NodeAttribute::DisplayName) mNodeDisplayName = mOpcNode->attribute(QOpcUa::NodeAttribute::DisplayName).value<QOpcUa::QLocalizedText>().text(); - if (attr & QOpcUa::NodeAttribute::NodeId) - mNodeDisplayName = mOpcNode->attribute(QOpcUa::NodeAttribute::NodeId).toString(); mAttributesReady = true; emit mModel->dataChanged(mModel->createIndex(row(), 0, this), mModel->createIndex(row(), numberOfDisplayColumns - 1, this)); @@ -234,14 +245,17 @@ void TreeItem::browseFinished(QVector<QOpcUaReferenceDescription> children, QOpc auto index = mModel->createIndex(row(), 0, this); for (const auto &item : children) { - mModel->beginInsertRows(index, mChildItems.size(), mChildItems.size() + children.size()); + if (hasChildNodeItem(item.nodeId())) + continue; + auto node = mModel->opcUaClient()->node(item.nodeId()); if (!node) { qWarning() << "Failed to instantiate node:" << item.nodeId(); continue; } - mChildItems.append(new TreeItem(node, mModel, item, this)); + mModel->beginInsertRows(index, mChildItems.size(), mChildItems.size() + 1); + appendChild(new TreeItem(node, mModel, item, this)); mModel->endInsertRows(); } diff --git a/examples/opcua/opcuaviewer/treeitem.h b/examples/opcua/opcuaviewer/treeitem.h index 7f97cf5..d67a2fa 100644 --- a/examples/opcua/opcuaviewer/treeitem.h +++ b/examples/opcua/opcuaviewer/treeitem.h @@ -76,6 +76,7 @@ public: TreeItem *parentItem(); void appendChild(TreeItem *child); QPixmap icon(int column) const; + bool hasChildNodeItem(const QString &nodeId) const; private slots: void startBrowsing(); @@ -96,6 +97,7 @@ private: bool mAttributesReady = false; bool mBrowseStarted = false; QList<TreeItem *> mChildItems; + QSet<QString> mChildNodeIds; TreeItem *mParentItem = nullptr; private: |