88#include < stack>
99#include < stdexcept>
1010
11-
1211namespace QtNodes {
1312
1413DataFlowGraphModel::DataFlowGraphModel (std::shared_ptr<NodeDelegateModelRegistry> registry)
@@ -117,12 +116,10 @@ bool DataFlowGraphModel::connectionPossible(ConnectionId const connectionId) con
117116 // Check port bounds, i.e. that we do not connect non-existing port numbers
118117 auto checkPortBounds = [&](PortType const portType) {
119118 NodeId const nodeId = getNodeId (portType, connectionId);
120- auto portCountRole = (portType == PortType::Out) ?
121- NodeRole::OutPortCount :
122- NodeRole::InPortCount;
119+ auto portCountRole = (portType == PortType::Out) ? NodeRole::OutPortCount
120+ : NodeRole::InPortCount;
123121
124- std::size_t const portCount =
125- nodeData (nodeId, portCountRole).toUInt ();
122+ std::size_t const portCount = nodeData (nodeId, portCountRole).toUInt ();
126123
127124 return getPortIndex (portType, connectionId) < portCount;
128125 };
@@ -146,12 +143,9 @@ bool DataFlowGraphModel::connectionPossible(ConnectionId const connectionId) con
146143 return connected.empty () || (policy == ConnectionPolicy::Many);
147144 };
148145
149- bool const basicChecks =
150- getDataType (PortType::Out).id == getDataType (PortType::In).id
151- && portVacant (PortType::Out)
152- && portVacant (PortType::In)
153- && checkPortBounds (PortType::Out)
154- && checkPortBounds (PortType::In);
146+ bool const basicChecks = getDataType (PortType::Out).id == getDataType (PortType::In).id
147+ && portVacant (PortType::Out) && portVacant (PortType::In)
148+ && checkPortBounds (PortType::Out) && checkPortBounds (PortType::In);
155149
156150 // In data-flow mode (this class) it's important to forbid graph loops.
157151 // We perform depth-first graph traversal starting from the "Input" port of
@@ -161,17 +155,16 @@ bool DataFlowGraphModel::connectionPossible(ConnectionId const connectionId) con
161155 std::stack<NodeId> filo;
162156 filo.push (connectionId.inNodeId );
163157
164- while (!filo.empty ())
165- {
166- auto id = filo. top (); filo.pop ();
158+ while (!filo.empty ()) {
159+ auto id = filo. top ();
160+ filo.pop ();
167161
168162 if (id == connectionId.outNodeId ) { // LOOP!
169- return true ;
163+ return true ;
170164 }
171165
172166 // Add out-connections to continue interations
173- std::size_t const nOutPorts =
174- nodeData (id, NodeRole::OutPortCount).toUInt ();
167+ std::size_t const nOutPorts = nodeData (id, NodeRole::OutPortCount).toUInt ();
175168
176169 for (PortIndex index = 0 ; index < nOutPorts; ++index) {
177170 auto const &outConnectionIds = connections (id, PortType::Out, index);
@@ -188,7 +181,6 @@ bool DataFlowGraphModel::connectionPossible(ConnectionId const connectionId) con
188181 return basicChecks && (loopsEnabled () || !hasLoops ());
189182}
190183
191-
192184void DataFlowGraphModel::addConnection (ConnectionId const connectionId)
193185{
194186 _connectivity.insert (connectionId);
@@ -294,9 +286,14 @@ QVariant DataFlowGraphModel::nodeData(NodeId nodeId, NodeRole role) const
294286 break ;
295287
296288 case NodeRole::Widget: {
297- auto w = model->embeddedWidget ();
289+ auto * w = model->embeddedWidget ();
298290 result = QVariant::fromValue (w);
299291 } break ;
292+
293+ case NodeRole::ValidationState: {
294+ auto validationState = model->validationState ();
295+ result = QVariant::fromValue (validationState);
296+ } break ;
300297 }
301298
302299 return result;
@@ -356,6 +353,16 @@ bool DataFlowGraphModel::setNodeData(NodeId nodeId, NodeRole role, QVariant valu
356353
357354 case NodeRole::Widget:
358355 break ;
356+
357+ case NodeRole::ValidationState: {
358+ if (value.canConvert <NodeValidationState>()) {
359+ auto state = value.value <NodeValidationState>();
360+ if (auto node = delegateModel<NodeDelegateModel>(nodeId); node != nullptr ) {
361+ node->setValidatonState (state);
362+ }
363+ }
364+ Q_EMIT nodeUpdated (nodeId);
365+ } break ;
359366 }
360367
361368 return result;
@@ -538,7 +545,8 @@ void DataFlowGraphModel::loadNode(QJsonObject const &nodeJson)
538545 connect (model.get (),
539546 &NodeDelegateModel::portsAboutToBeDeleted,
540547 this ,
541- [restoredNodeId, this ](PortType const portType, PortIndex const first, PortIndex const last) {
548+ [restoredNodeId,
549+ this ](PortType const portType, PortIndex const first, PortIndex const last) {
542550 portsAboutToBeDeleted (restoredNodeId, portType, first, last);
543551 });
544552
@@ -550,7 +558,8 @@ void DataFlowGraphModel::loadNode(QJsonObject const &nodeJson)
550558 connect (model.get (),
551559 &NodeDelegateModel::portsAboutToBeInserted,
552560 this ,
553- [restoredNodeId, this ](PortType const portType, PortIndex const first, PortIndex const last) {
561+ [restoredNodeId,
562+ this ](PortType const portType, PortIndex const first, PortIndex const last) {
554563 portsAboutToBeInserted (restoredNodeId, portType, first, last);
555564 });
556565
0 commit comments