paceholder / nodeeditor

Qt Node Editor. Dataflow programming framework
BSD 3-Clause "New" or "Revised" License
2.94k stars 796 forks source link

V3 GraphModel examples #295

Closed Daguerreo closed 2 years ago

Daguerreo commented 2 years ago

Hi, could you please add an example for v3-alpha with the new graph model and actual nodes with data type?

paceholder commented 2 years ago

Hi @Daguerreo ,

actually, there is a small example there https://github.com/paceholder/nodeeditor/tree/v3alpha/examples/graph.

I think I finished all the basic features of the framework in this branch. What still missing is fixing a couple of tests and re-working the CI-scripts -- they were broken due to changes on the CI-server sides.

Daguerreo commented 2 years ago

Hi @Daguerreo ,

actually, there is a small example there https://github.com/paceholder/nodeeditor/tree/v3alpha/examples/graph.

I think I finished all the basic features of the framework in this branch. What still missing is fixing a couple of tests and re-working the CI-scripts -- they were broken due to changes on the CI-server sides.

Yep I'm aware of that, I was trying to figure out how to deal with actual data and port type with the new version, maybe a porting of the calculator example would be enough?

paceholder commented 2 years ago

The actual data is stored inside the library user's model. It could be an arbitrary storage, it must just fulfill the interface of AbstractGraphModel. The port information is extracted using

QVariant AbstractGraphModel::portData(NodeId nodeId,
                                      PortType  portType,
                                      PortIndex index,
                                      PortRole  role) const = 0;

, particularly using PortRole::Data and PortRole::DataType, see Definitions.hpp.

The example Calculator is already adjusted to the new code, it just keeps using "delegates" a.k.a NodeModelData types from the previous version. Now it is all wrapped in an AbstractGraphModel instance.

Daguerreo commented 2 years ago

Ok, I will try being more specific: in the graph example, how can I manage the fact my custom NodeType1 output can't go in NodeType2 input port? That's why I talked about actual data.

paceholder commented 2 years ago

That's up to your concrete model implementation.

You'd need to implement an abstract function AbstractGraphModel::connectionPossible(ConnectionId const).

The ConnectionId is nothing else but a tuple of (node1_id, out_port_index, node2_id, in_port_index). This gives your model all the information to figure out the data types and the possibility of a connection.

In the graph example I simply check that the ports are empty. You could add extra checks for data types.

paceholder commented 2 years ago

I understood your point and will try to figure out another example

Daguerreo commented 2 years ago

I understood your point and will try to figure out another example

That would be great, thank you.