From 5465ddc91f1b30823c5fc3def93138cbec4c9394 Mon Sep 17 00:00:00 2001 From: Finn Rayment Date: Thu, 26 Jan 2023 14:58:27 +1100 Subject: [PATCH] Fixed non-emit of NodeDelegateModel::in/outputConnectionCreated/Deleted. The four virtual functions in NodeDelegateModel were not being called anywhere in code as the logic was removed when FlowScene.cpp was removed as part of the v3 upgrade. This functionality has been restored thanks to two new functions `DataFlowGraphModel::sendConnectionCreation` and `DataFlowGraphModel::sendConnectionDeletion` which call the slots on both the input and output nodes of any given connection. Functions are: - inputConnectionCreated - inputConnectionDeleted - outputConnectionCreated - outputConnectionDeleted Signed-off-by: Finn Rayment --- .../QtNodes/internal/DataFlowGraphModel.hpp | 4 +++ .../QtNodes/internal/NodeDelegateModel.hpp | 2 +- src/DataFlowGraphModel.cpp | 32 +++++++++++++++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/include/QtNodes/internal/DataFlowGraphModel.hpp b/include/QtNodes/internal/DataFlowGraphModel.hpp index f01e583d9..268800202 100644 --- a/include/QtNodes/internal/DataFlowGraphModel.hpp +++ b/include/QtNodes/internal/DataFlowGraphModel.hpp @@ -100,6 +100,10 @@ class NODE_EDITOR_PUBLIC DataFlowGraphModel : public AbstractGraphModel, public private: NodeId newNodeId() override { return _nextNodeId++; } + void sendConnectionCreation(ConnectionId const connectionId); + + void sendConnectionDeletion(ConnectionId const connectionId); + private Q_SLOTS: /** * Fuction is called in three cases: diff --git a/include/QtNodes/internal/NodeDelegateModel.hpp b/include/QtNodes/internal/NodeDelegateModel.hpp index 027ff16c2..6301164db 100644 --- a/include/QtNodes/internal/NodeDelegateModel.hpp +++ b/include/QtNodes/internal/NodeDelegateModel.hpp @@ -17,7 +17,7 @@ class StyleCollection; /** * The class wraps Node-specific data operations and propagates it to * the nesting DataFlowGraphModel which is a subclass of - * AbstractGrapModel. + * AbstractGraphModel. * This class is the same what has been called NodeDataModel before v3. */ class NODE_EDITOR_PUBLIC NodeDelegateModel : public QObject, public Serializable diff --git a/src/DataFlowGraphModel.cpp b/src/DataFlowGraphModel.cpp index fe88f14f6..a5ba8734f 100644 --- a/src/DataFlowGraphModel.cpp +++ b/src/DataFlowGraphModel.cpp @@ -132,7 +132,7 @@ void DataFlowGraphModel::addConnection(ConnectionId const connectionId) { _connectivity.insert(connectionId); - Q_EMIT connectionCreated(connectionId); + sendConnectionCreation(connectionId); QVariant const portDataToPropagate = portData(connectionId.outNodeId, PortType::Out, @@ -146,6 +146,34 @@ void DataFlowGraphModel::addConnection(ConnectionId const connectionId) PortRole::Data); } +void DataFlowGraphModel::sendConnectionCreation(ConnectionId const connectionId) +{ + Q_EMIT connectionCreated(connectionId); + + auto iti = _models.find(connectionId.inNodeId); + auto ito = _models.find(connectionId.outNodeId); + if (iti != _models.end() && ito != _models.end()) { + auto &modeli = iti->second; + auto &modelo = ito->second; + modeli->inputConnectionCreated(connectionId); + modelo->outputConnectionCreated(connectionId); + } +} + +void DataFlowGraphModel::sendConnectionDeletion(ConnectionId const connectionId) +{ + Q_EMIT connectionDeleted(connectionId); + + auto iti = _models.find(connectionId.inNodeId); + auto ito = _models.find(connectionId.outNodeId); + if (iti != _models.end() && ito != _models.end()) { + auto &modeli = iti->second; + auto &modelo = ito->second; + modeli->inputConnectionDeleted(connectionId); + modelo->outputConnectionDeleted(connectionId); + } +} + bool DataFlowGraphModel::nodeExists(NodeId const nodeId) const { return (_models.find(nodeId) != _models.end()); @@ -355,7 +383,7 @@ bool DataFlowGraphModel::deleteConnection(ConnectionId const connectionId) } if (disconnected) { - Q_EMIT connectionDeleted(connectionId); + sendConnectionDeletion(connectionId); propagateEmptyDataTo(getNodeId(PortType::In, connectionId), getPortIndex(PortType::In, connectionId));