Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added propagation control functions and fix implicit string conversion in headers. #367

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions include/QtNodes/internal/ConnectionIdUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,21 @@ inline QJsonObject toJson(ConnectionId const &connId)
{
QJsonObject connJson;

connJson["outNodeId"] = static_cast<qint64>(connId.outNodeId);
connJson["outPortIndex"] = static_cast<qint64>(connId.outPortIndex);
connJson["intNodeId"] = static_cast<qint64>(connId.inNodeId);
connJson["inPortIndex"] = static_cast<qint64>(connId.inPortIndex);
connJson[QLatin1String("outNodeId")] = static_cast<qint64>(connId.outNodeId);
connJson[QLatin1String("outPortIndex")] = static_cast<qint64>(connId.outPortIndex);
connJson[QLatin1String("intNodeId")] = static_cast<qint64>(connId.inNodeId);
connJson[QLatin1String("inPortIndex")] = static_cast<qint64>(connId.inPortIndex);

return connJson;
}

inline ConnectionId fromJson(QJsonObject const &connJson)
{
ConnectionId connId{static_cast<NodeId>(connJson["outNodeId"].toInt(InvalidNodeId)),
static_cast<PortIndex>(connJson["outPortIndex"].toInt(InvalidPortIndex)),
static_cast<NodeId>(connJson["intNodeId"].toInt(InvalidNodeId)),
static_cast<PortIndex>(connJson["inPortIndex"].toInt(InvalidPortIndex))};
ConnectionId connId{
static_cast<NodeId>(connJson[QLatin1String("outNodeId")].toInt(InvalidNodeId)),
static_cast<PortIndex>(connJson[QLatin1String("outPortIndex")].toInt(InvalidPortIndex)),
static_cast<NodeId>(connJson[QLatin1String("intNodeId")].toInt(InvalidNodeId)),
static_cast<PortIndex>(connJson[QLatin1String("inPortIndex")].toInt(InvalidPortIndex))};

return connId;
}
Expand Down
12 changes: 9 additions & 3 deletions include/QtNodes/internal/DataFlowGraphModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,23 @@ class NODE_EDITOR_PUBLIC DataFlowGraphModel : public AbstractGraphModel, public
return model;
}

public Q_SLOTS:
virtual void propagate(NodeId const nodeId);

protected:
virtual bool canPropagate(ConnectionId const) { return true; }
rayment marked this conversation as resolved.
Show resolved Hide resolved

Q_SIGNALS:
void inPortDataWasSet(NodeId const, PortType const, PortIndex const);

private:
NodeId newNodeId() override { return _nextNodeId++; }

protected Q_SLOTS:
void sendConnectionCreation(ConnectionId const connectionId);

void sendConnectionDeletion(ConnectionId const connectionId);

private Q_SLOTS:
/**
* Fuction is called in three cases:
*
Expand All @@ -115,10 +121,10 @@ private Q_SLOTS:
* - When a node restored from JSON an needs to send data downstream.
* @see DataFlowGraphModel::loadNode
*/
void onOutPortDataUpdated(NodeId const nodeId, PortIndex const portIndex);
virtual void onOutPortDataUpdated(NodeId const nodeId, PortIndex const portIndex);

/// Function is called after detaching a connection.
void propagateEmptyDataTo(NodeId const nodeId, PortIndex const portIndex);
virtual void propagateEmptyDataTo(NodeId const nodeId, PortIndex const portIndex);

private:
std::shared_ptr<NodeDelegateModelRegistry> _registry;
Expand Down
8 changes: 4 additions & 4 deletions include/QtNodes/internal/NodeDelegateModelRegistry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class NODE_EDITOR_PUBLIC NodeDelegateModelRegistry

public:
template<typename ModelType>
void registerModel(RegistryItemCreator creator, QString const &category = "Nodes")
void registerModel(RegistryItemCreator creator, QString const &category = QLatin1String("Nodes"))
{
QString const name = computeName<ModelType>(HasStaticMethodName<ModelType>{}, creator);
if (!_registeredItemCreators.count(name)) {
Expand All @@ -52,7 +52,7 @@ class NODE_EDITOR_PUBLIC NodeDelegateModelRegistry
}

template<typename ModelType>
void registerModel(QString const &category = "Nodes")
void registerModel(QString const &category = QLatin1String("Nodes"))
{
RegistryItemCreator creator = []() { return std::make_unique<ModelType>(); };
registerModel<ModelType>(std::move(creator), category);
Expand All @@ -62,15 +62,15 @@ class NODE_EDITOR_PUBLIC NodeDelegateModelRegistry
template<typename ModelType>
void
registerModel(RegistryItemCreator creator,
QString const& category = "Nodes")
QString const& category = QLatin1String("Nodes"))
{
registerModel<ModelType>(std::move(creator), category);
}


template <typename ModelCreator>
void
registerModel(ModelCreator&& creator, QString const& category = "Nodes")
registerModel(ModelCreator&& creator, QString const& category = QLatin1String("Nodes"))
{
using ModelType = compute_model_type_t<decltype(creator())>;
registerModel<ModelType>(std::forward<ModelCreator>(creator), category);
Expand Down
29 changes: 22 additions & 7 deletions src/DataFlowGraphModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@ void DataFlowGraphModel::addConnection(ConnectionId const connectionId)
PortType::Out,
connectionId.outPortIndex,
PortRole::Data);

setPortData(connectionId.inNodeId,
PortType::In,
connectionId.inPortIndex,
portDataToPropagate,
PortRole::Data);
if (canPropagate(connectionId)) {
setPortData(connectionId.inNodeId,
PortType::In,
connectionId.inPortIndex,
portDataToPropagate,
PortRole::Data);
}
}

void DataFlowGraphModel::sendConnectionCreation(ConnectionId const connectionId)
Expand Down Expand Up @@ -518,7 +519,21 @@ void DataFlowGraphModel::onOutPortDataUpdated(NodeId const nodeId, PortIndex con
QVariant const portDataToPropagate = portData(nodeId, PortType::Out, portIndex, PortRole::Data);

for (auto const &cn : connected) {
setPortData(cn.inNodeId, PortType::In, cn.inPortIndex, portDataToPropagate, PortRole::Data);
if (canPropagate(cn)) {
setPortData(cn.inNodeId,
PortType::In,
cn.inPortIndex,
portDataToPropagate,
PortRole::Data);
}
}
}

void DataFlowGraphModel::propagate(NodeId const nodeId)
{
unsigned int nPorts = nodeData(nodeId, NodeRole::OutPortCount).toUInt();
for (PortIndex idx = 0; idx < nPorts; ++idx) {
onOutPortDataUpdated(nodeId, idx);
}
}

Expand Down