summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannis Voelker <jannis.voelker@basyskom.com>2018-06-25 13:53:22 +0200
committerJannis Völker <jannis.voelker@basyskom.com>2018-06-27 12:30:34 +0000
commit5e2b027283970f2f424d2b57ce035d9a57d29789 (patch)
treebd56d9a213e7bc6571a75122ec654b3c689cbd03
parent4149a11384a5b336f0d4d1ac8b5298ad2847028d (diff)
opcuaviewer: Don't add children for duplicate references
An object may have more than one reference to the same node. Creating a new child for both references leads to duplicates in the tree view. Task-number: QTBUG-69103 Change-Id: Ib5245ac0f9eeb2ade39463f456f6310bf5587597 Reviewed-by: Frank Meerkoetter <frank.meerkoetter@basyskom.com> Reviewed-by: Rainer Keller <Rainer.Keller@qt.io>
-rw-r--r--examples/opcua/opcuaviewer/treeitem.cpp20
-rw-r--r--examples/opcua/opcuaviewer/treeitem.h2
2 files changed, 20 insertions, 2 deletions
diff --git a/examples/opcua/opcuaviewer/treeitem.cpp b/examples/opcua/opcuaviewer/treeitem.cpp
index 9f4a7d1..b98f9e7 100644
--- a/examples/opcua/opcuaviewer/treeitem.cpp
+++ b/examples/opcua/opcuaviewer/treeitem.cpp
@@ -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)
@@ -234,6 +247,9 @@ void TreeItem::browseFinished(QVector<QOpcUaReferenceDescription> children, QOpc
auto index = mModel->createIndex(row(), 0, this);
for (const auto &item : children) {
+ if (hasChildNodeItem(item.nodeId()))
+ continue;
+
auto node = mModel->opcUaClient()->node(item.nodeId());
if (!node) {
qWarning() << "Failed to instantiate node:" << item.nodeId();
@@ -241,7 +257,7 @@ void TreeItem::browseFinished(QVector<QOpcUaReferenceDescription> children, QOpc
}
mModel->beginInsertRows(index, mChildItems.size(), mChildItems.size() + 1);
- mChildItems.append(new TreeItem(node, mModel, item, this));
+ 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: