QtNodes Class Reference

Basic Classes

class AbstractGraphModel : public QObject

The central class in the Model-View approach. It delivers all kinds of information from the backing user data structures that represent the graph. The class allows to modify the graph structure: create and remove nodes and connections.

We use two types of the unique ids for graph manipulations:

Subclassed by QtNodes::DataFlowGraphModel

Public Functions

virtual NodeId newNodeId() = 0

Generates a new unique NodeId.

virtual std::unordered_set<NodeId> allNodeIds() const = 0

Returns the full set of unique Node Ids.

Model creator is responsible for generating unique unsigned int Ids for all the nodes in the graph. From an Id it should be possible to trace back to the model’s internal representation of the node.

virtual std::unordered_set<ConnectionId> allConnectionIds(NodeId const nodeId) const = 0

A collection of all input and output connections for the given nodeId.

virtual std::unordered_set<ConnectionId> connections(NodeId nodeId, PortType portType, PortIndex index) const = 0

Returns all connected Node Ids for given port.

The returned set of nodes and port indices correspond to the type opposite to the given portType.

virtual bool connectionExists(ConnectionId const connectionId) const = 0

Checks if two nodes with the given connectionId are connected.

virtual NodeId addNode(QString const nodeType = QString()) = 0

Creates a new node instance in the derived class.

The model is responsible for generating a unique NodeId.

Parameters:

nodeType[in] is free to be used and interpreted by the model on its own, it helps to distinguish between possible node types and create a correct instance inside.

virtual bool connectionPossible(ConnectionId const connectionId) const = 0

Model decides if a conection with a given connection Id possible.

The default implementation compares corresponding data types.

It is possible to override the function and connect non-equal data types.

inline virtual bool detachPossible(ConnectionId const) const

Defines if detaching the connection is possible.

virtual void addConnection(ConnectionId const connectionId) = 0

Creates a new connection between two nodes.

Default implementation emits signal connectionCreated(connectionId)

In the derived classes user must emite the signal to notify the scene about the changes.

virtual bool nodeExists(NodeId const nodeId) const = 0
Returns:

true if there is data in the model associated with the given nodeId.

virtual QVariant nodeData(NodeId nodeId, NodeRole role) const = 0

Returns node-related data for requested NodeRole.

Returns:

Node Caption, Node Caption Visibility, Node Position etc.

template<typename T>
inline T nodeData(NodeId nodeId, NodeRole role) const

A utility function that unwraps the QVariant value returned from the standard QVariant AbstractGraphModel::nodeData(NodeId, NodeRole) function.

inline virtual NodeFlags nodeFlags(NodeId nodeId) const
virtual bool setNodeData(NodeId nodeId, NodeRole role, QVariant value) = 0

Sets node properties.

Sets: Node Caption, Node Caption Visibility, Shyle, State, Node Position etc.

See also

NodeRole.

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

Returns port-related data for requested NodeRole.

Returns:

Port Data Type, Port Data, Connection Policy, Port Caption.

template<typename T>
inline T portData(NodeId nodeId, PortType portType, PortIndex index, PortRole role) const

A utility function that unwraps the QVariant value returned from the standard QVariant AbstractGraphModel::portData(...) function.

virtual bool setPortData(NodeId nodeId, PortType portType, PortIndex index, QVariant const &value, PortRole role = PortRole::Data) = 0
virtual bool deleteConnection(ConnectionId const connectionId) = 0
virtual bool deleteNode(NodeId const nodeId) = 0
inline virtual QJsonObject saveNode(NodeId const) const

Reimplement the function if you want to store/restore the node’s inner state during undo/redo node deletion operations.

inline virtual void loadNode(QJsonObject const&)

Reimplement the function if you want to support:

  • graph save/restore operations,

  • undo/redo operations after deleting the node.

QJsonObject must contain following fields:

{
  id : 5,
  position : { x : 100, y : 200 },
  internal-data {
    "your model specific data here"
  }
}

The function must do almost exacly the same thing as the normal addNode(). The main difference is in a model-specific inner-data processing.

void portsAboutToBeDeleted(NodeId const nodeId, PortType const portType, PortIndex const first, PortIndex const last)

Function clears connections attached to the ports that are scheduled to be deleted. It must be called right before the model removes its old port data.

Parameters:
  • nodeId – Defines the node to be modified

  • portType – Is either PortType::In or PortType::Out

  • first – Index of the first port to be removed

  • last – Index of the last port to be removed

void portsDeleted()

Signal emitted when model no longer has the old data associated with the given port indices and when the node must be repainted.

void portsAboutToBeInserted(NodeId const nodeId, PortType const portType, PortIndex const first, PortIndex const last)

Signal emitted when model is about to create new ports on the given node.

Function caches existing connections that are located after the

last port index. For such connections the new “post-insertion” addresses are computed and stored until the function AbstractGraphModel::portsInserted is called.

Parameters:
  • first – Is the first index of the new port after insertion.

  • last – Is the last index of the new port after insertion.

void portsInserted()

Function re-creates the connections that were shifted during the port insertion. After that the node is updated.

Signals

void connectionCreated(ConnectionId const connectionId)
void connectionDeleted(ConnectionId const connectionId)
void nodeCreated(NodeId const nodeId)
void nodeDeleted(NodeId const nodeId)
void nodeUpdated(NodeId const nodeId)
void nodeFlagsUpdated(NodeId const nodeId)
void nodePositionUpdated(NodeId const nodeId)
void modelReset()
struct NodeDataType

id represents an internal unique data type for the given port. name is a normal text description.

Public Members

QString id
QString name
class NodeData

Class represents data transferred between nodes.

Param type:

is used for comparing the types The actual data is stored in subtypes

Public Functions

virtual ~NodeData() = default
inline virtual bool sameType(NodeData const &nodeData) const
virtual NodeDataType type() const = 0

Type for inner use.

struct ConnectionId

A unique connection identificator that stores out NodeId, out PortIndex, in NodeId, in PortIndex

Public Members

NodeId outNodeId
PortIndex outPortIndex
NodeId inNodeId
PortIndex inPortIndex
class BasicGraphicsScene : public QGraphicsScene

An instance of QGraphicsScene, holds connections and nodes.

Subclassed by QtNodes::DataFlowGraphicsScene

Public Functions

BasicGraphicsScene(AbstractGraphModel &graphModel, QObject *parent = nullptr)
BasicGraphicsScene() = delete
~BasicGraphicsScene()
AbstractGraphModel const &graphModel() const
Returns:

associated AbstractGraphModel.

AbstractGraphModel &graphModel()
AbstractNodeGeometry &nodeGeometry()
AbstractNodePainter &nodePainter()
void setNodePainter(std::unique_ptr<AbstractNodePainter> newPainter)
QUndoStack &undoStack()
std::unique_ptr<ConnectionGraphicsObject> const &makeDraftConnection(ConnectionId const newConnectionId)

Creates a “draft” instance of ConnectionGraphicsObject.

The scene caches a “draft” connection which has one loose end. After attachment the “draft” instance is deleted and instead a normal “full” connection is created. Function

Returns:

the “draft” instance for further geometry manipulations.

void resetDraftConnection()

Deletes “draft” connection.

The function is called when user releases the mouse button during the construction of the new connection without attaching it to any node.

void clearScene()

Deletes all the nodes. Connections are removed automatically.

NodeGraphicsObject *nodeGraphicsObject(NodeId nodeId)
Returns:

NodeGraphicsObject associated with the given nodeId.

Returns:

nullptr when the object is not found.

ConnectionGraphicsObject *connectionGraphicsObject(ConnectionId connectionId)
Returns:

ConnectionGraphicsObject corresponding to connectionId.

Returns:

nullptr when the object is not found.

inline Qt::Orientation orientation() const
void setOrientation(Qt::Orientation const orientation)
virtual QMenu *createSceneMenu(QPointF const scenePos)

Can.

Returns:

an instance of the scene context menu in subclass. Default implementation returns nullptr.

Public Slots

void onConnectionDeleted(ConnectionId const connectionId)

Slot called when the connectionId is erased form the AbstractGraphModel.

void onConnectionCreated(ConnectionId const connectionId)

Slot called when the connectionId is created in the AbstractGraphModel.

void onNodeDeleted(NodeId const nodeId)
void onNodeCreated(NodeId const nodeId)
void onNodePositionUpdated(NodeId const nodeId)
void onNodeUpdated(NodeId const nodeId)
void onNodeClicked(NodeId const nodeId)
void onModelReset()

Signals

void nodeMoved(NodeId const nodeId, QPointF const &newLocation)
void nodeClicked(NodeId const nodeId)
void nodeSelected(NodeId const nodeId)
void nodeDoubleClicked(NodeId const nodeId)
void nodeHovered(NodeId const nodeId, QPoint const screenPos)
void nodeHoverLeft(NodeId const nodeId)
void connectionHovered(ConnectionId const connectionId, QPoint const screenPos)
void connectionHoverLeft(ConnectionId const connectionId)
void nodeContextMenu(NodeId const nodeId, QPointF const pos)

Signal allows showing custom context menu upon clicking a node.

class GraphicsView : public QGraphicsView

A central view able to render objects from BasicGraphicsScene.

Public Functions

GraphicsView(QWidget *parent = Q_NULLPTR)
GraphicsView(BasicGraphicsScene *scene, QWidget *parent = Q_NULLPTR)
GraphicsView(const GraphicsView&) = delete
GraphicsView operator=(const GraphicsView&) = delete
QAction *clearSelectionAction() const
QAction *deleteSelectionAction() const
void setScene(BasicGraphicsScene *scene)
void centerScene()
void setScaleRange(double minimum = 0, double maximum = 0)

max=0/min=0 indicates infinite zoom in/out

void setScaleRange(ScaleRange range)
double getScale() const

Public Slots

void scaleUp()
void scaleDown()
void setupScale(double scale)
void onDeleteSelectedObjects()
void onDuplicateSelectedObjects()
void onCopySelectedObjects()
void onPasteObjects()

Signals

void scaleChanged(double scale)
struct ScaleRange

Public Members

double minimum = 0
double maximum = 0
class GraphicsViewStyle : public QtNodes::Style

Public Functions

GraphicsViewStyle()
GraphicsViewStyle(QString jsonText)
~GraphicsViewStyle() = default

Public Members

QColor BackgroundColor
QColor FineGridColor
QColor CoarseGridColor

Public Static Functions

static void setStyle(QString jsonText)
class NodeGraphicsObject : public QGraphicsObject

Public Types

enum [anonymous]

Values:

enumerator Type

Public Functions

inline int type() const override
NodeGraphicsObject(BasicGraphicsScene &scene, NodeId node)
~NodeGraphicsObject() override = default
AbstractGraphModel &graphModel() const
BasicGraphicsScene *nodeScene() const
inline NodeId nodeId()
inline NodeId nodeId() const
inline NodeState &nodeState()
inline NodeState const &nodeState() const
QRectF boundingRect() const override
void setGeometryChanged()
void moveConnections() const

Visits all attached connections and corrects their corresponding end points.

void reactToConnection(ConnectionGraphicsObject const *cgo)

Repaints the node once with reacting ports.

class AbstractNodePainter

Class enables custom painting.

Subclassed by QtNodes::DefaultNodePainter

Public Functions

virtual ~AbstractNodePainter() = default
virtual void paint(QPainter *painter, NodeGraphicsObject &ngo) const = 0

Reimplement this function in order to have a custom painting.

Useful functions: NodeGraphicsObject::nodeScene()->nodeGeometry() NodeGraphicsObject::graphModel()

class DefaultNodePainter : public QtNodes::AbstractNodePainter

@ Lightweight class incapsulating paint code.

Public Functions

virtual void paint(QPainter *painter, NodeGraphicsObject &ngo) const override

Reimplement this function in order to have a custom painting.

Useful functions: NodeGraphicsObject::nodeScene()->nodeGeometry() NodeGraphicsObject::graphModel()

void drawNodeRect(QPainter *painter, NodeGraphicsObject &ngo) const
void drawConnectionPoints(QPainter *painter, NodeGraphicsObject &ngo) const
void drawFilledConnectionPoints(QPainter *painter, NodeGraphicsObject &ngo) const
void drawNodeCaption(QPainter *painter, NodeGraphicsObject &ngo) const
void drawEntryLabels(QPainter *painter, NodeGraphicsObject &ngo) const
void drawResizeRect(QPainter *painter, NodeGraphicsObject &ngo) const
class AbstractNodeGeometry

Subclassed by QtNodes::DefaultHorizontalNodeGeometry, QtNodes::DefaultVerticalNodeGeometry

Public Functions

AbstractNodeGeometry(AbstractGraphModel&)
inline virtual ~AbstractNodeGeometry()
virtual QRectF boundingRect(NodeId const nodeId) const

The node’s size plus some additional margin around it to account for drawing effects (for example shadows) or node’s parts outside the size rectangle (for example port points).

The default implementation returns QSize + 20 percent of width and heights at each side of the rectangle.

virtual QSize size(NodeId const nodeId) const = 0

A direct rectangle defining the borders of the node’s rectangle.

virtual void recomputeSize(NodeId const nodeId) const = 0

The function is triggeren when a nuber of ports is changed or when an embedded widget needs an update.

virtual QPointF portPosition(NodeId const nodeId, PortType const portType, PortIndex const index) const = 0

Port position in node’s coordinate system.

virtual QPointF portScenePosition(NodeId const nodeId, PortType const portType, PortIndex const index, QTransform const &t) const

A convenience function using the portPosition and a given transformation.

virtual QPointF portTextPosition(NodeId const nodeId, PortType const portType, PortIndex const portIndex) const = 0

Defines where to draw port label. The point corresponds to a font baseline.

virtual QPointF captionPosition(NodeId const nodeId) const = 0

Defines where to start drawing the caption. The point corresponds to a font baseline.

virtual QRectF captionRect(NodeId const nodeId) const = 0

Caption rect is needed for estimating the total node size.

virtual QPointF widgetPosition(NodeId const nodeId) const = 0

Position for an embedded widget. Return any value if you don’t embed.

virtual PortIndex checkPortHit(NodeId const nodeId, PortType const portType, QPointF const nodePoint) const
virtual QRect resizeHandleRect(NodeId const nodeId) const = 0
class DefaultHorizontalNodeGeometry : public QtNodes::AbstractNodeGeometry

Public Functions

DefaultHorizontalNodeGeometry(AbstractGraphModel &graphModel)
virtual QSize size(NodeId const nodeId) const override

A direct rectangle defining the borders of the node’s rectangle.

virtual void recomputeSize(NodeId const nodeId) const override

The function is triggeren when a nuber of ports is changed or when an embedded widget needs an update.

virtual QPointF portPosition(NodeId const nodeId, PortType const portType, PortIndex const index) const override

Port position in node’s coordinate system.

virtual QPointF portTextPosition(NodeId const nodeId, PortType const portType, PortIndex const PortIndex) const override

Defines where to draw port label. The point corresponds to a font baseline.

virtual QPointF captionPosition(NodeId const nodeId) const override

Defines where to start drawing the caption. The point corresponds to a font baseline.

virtual QRectF captionRect(NodeId const nodeId) const override

Caption rect is needed for estimating the total node size.

virtual QPointF widgetPosition(NodeId const nodeId) const override

Position for an embedded widget. Return any value if you don’t embed.

virtual QRect resizeHandleRect(NodeId const nodeId) const override
class DefaultVerticalNodeGeometry : public QtNodes::AbstractNodeGeometry

Public Functions

DefaultVerticalNodeGeometry(AbstractGraphModel &graphModel)
virtual QSize size(NodeId const nodeId) const override

A direct rectangle defining the borders of the node’s rectangle.

virtual void recomputeSize(NodeId const nodeId) const override

The function is triggeren when a nuber of ports is changed or when an embedded widget needs an update.

virtual QPointF portPosition(NodeId const nodeId, PortType const portType, PortIndex const index) const override

Port position in node’s coordinate system.

virtual QPointF portTextPosition(NodeId const nodeId, PortType const portType, PortIndex const PortIndex) const override

Defines where to draw port label. The point corresponds to a font baseline.

virtual QPointF captionPosition(NodeId const nodeId) const override

Defines where to start drawing the caption. The point corresponds to a font baseline.

virtual QRectF captionRect(NodeId const nodeId) const override

Caption rect is needed for estimating the total node size.

virtual QPointF widgetPosition(NodeId const nodeId) const override

Position for an embedded widget. Return any value if you don’t embed.

virtual QRect resizeHandleRect(NodeId const nodeId) const override
class NodeState

Stores bool for hovering connections and resizing flag.

Public Functions

NodeState(NodeGraphicsObject &ngo)
inline bool hovered() const
inline void setHovered(bool hovered = true)
void setResizing(bool resizing)
bool resizing() const
ConnectionGraphicsObject const *connectionForReaction() const
void storeConnectionForReaction(ConnectionGraphicsObject const *cgo)
void resetConnectionForReaction()
class NodeStyle : public QtNodes::Style

Public Functions

NodeStyle()
NodeStyle(QString jsonText)
NodeStyle(QJsonObject const &json)
virtual ~NodeStyle() = default
virtual void loadJson(QJsonObject const &json) override
virtual QJsonObject toJson() const override

Public Members

QColor NormalBoundaryColor
QColor SelectedBoundaryColor
QColor GradientColor0
QColor GradientColor1
QColor GradientColor2
QColor GradientColor3
QColor ShadowColor
QColor FontColor
QColor FontColorFaded
QColor ConnectionPointColor
QColor FilledConnectionPointColor
QColor WarningColor
QColor ErrorColor
float PenWidth
float HoveredPenWidth
float ConnectionPointDiameter
float Opacity

Public Static Functions

static void setNodeStyle(QString jsonText)
class ConnectionGraphicsObject : public QGraphicsObject

Graphic Object for connection. Adds itself to scene.

Public Types

enum [anonymous]

Values:

enumerator Type

Public Functions

inline int type() const override
ConnectionGraphicsObject(BasicGraphicsScene &scene, ConnectionId const connectionId)
~ConnectionGraphicsObject() = default
AbstractGraphModel &graphModel() const
BasicGraphicsScene *nodeScene() const
ConnectionId const &connectionId() const
QRectF boundingRect() const override
QPainterPath shape() const override
QPointF const &endPoint(PortType portType) const
inline QPointF out() const
inline QPointF in() const
std::pair<QPointF, QPointF> pointsC1C2() const
void setEndPoint(PortType portType, QPointF const &point)
void move()

Updates the position of both ends.

ConnectionState const &connectionState() const
ConnectionState &connectionState()
class ConnectionPainter

Public Static Functions

static void paint(QPainter *painter, ConnectionGraphicsObject const &cgo)
static QPainterPath getPainterStroke(ConnectionGraphicsObject const &cgo)
class ConnectionStyle : public QtNodes::Style

Public Functions

ConnectionStyle()
ConnectionStyle(QString jsonText)
~ConnectionStyle() = default
virtual void loadJson(QJsonObject const &json) override
virtual QJsonObject toJson() const override
QColor constructionColor() const
QColor normalColor() const
QColor normalColor(QString typeId) const
QColor selectedColor() const
QColor selectedHaloColor() const
QColor hoveredColor() const
float lineWidth() const
float constructionLineWidth() const
float pointDiameter() const
bool useDataDefinedColors() const

Public Static Functions

static void setConnectionStyle(QString jsonText)
class NodeConnectionInteraction

Class wraps conecting and disconnecting checks.

An instance should be created on the stack and destroyed automatically when the operation is completed

Public Functions

NodeConnectionInteraction(NodeGraphicsObject &ngo, ConnectionGraphicsObject &cgo, BasicGraphicsScene &scene)
bool canConnect(PortIndex *portIndex) const

Can connect when following conditions are met:

  1. Connection ‘requires’ a port.

  2. Connection loose end is above the node port.

  3. Source and target nodeIds are different.

  4. GraphModel permits connection.

bool tryConnect() const

Creates a new connectino if possible.

  1. Check conditions from ‘canConnect’.

  2. Creates new connection with GraphModel::addConnection.

  3. Adjust connection geometry.

bool disconnect(PortType portToDisconnect) const

  1. Delete connection with GraphModel::deleteConnection.

  2. Create a “draft” connection with incomplete ConnectionId.

  3. Repaint both previously connected nodes.

Undo Redo

class DeleteCommand : public QUndoCommand

Selected scene objects are serialized and then removed from the scene. The deleted elements could be restored in undo.

Public Functions

DeleteCommand(BasicGraphicsScene *scene)
void undo() override
void redo() override

Warning

doxygenclass: Cannot find class “QtNodes::DuplicateCommand” in doxygen xml output for project “QtNodes” from directory: _build/xml/

class DisconnectCommand : public QUndoCommand

Public Functions

DisconnectCommand(BasicGraphicsScene *scene, ConnectionId const)
void undo() override
void redo() override
class ConnectCommand : public QUndoCommand

Public Functions

ConnectCommand(BasicGraphicsScene *scene, ConnectionId const)
void undo() override
void redo() override
class MoveNodeCommand : public QUndoCommand

Public Functions

MoveNodeCommand(BasicGraphicsScene *scene, QPointF const &diff)
void undo() override
void redo() override
int id() const override

A command ID is used in command compression. It must be an integer unique to this command’s class, or -1 if the command doesn’t support compression.

bool mergeWith(QUndoCommand const *c) override

Several sequential movements could be merged into one command.

Dataflow Classes

class DataFlowGraphicsScene : public QtNodes::BasicGraphicsScene

An advanced scene working with data-propagating graphs.

The class represents a scene that existed in v2.x but built wit the new model-view approach in mind.

Public Functions

DataFlowGraphicsScene(DataFlowGraphModel &graphModel, QObject *parent = nullptr)
~DataFlowGraphicsScene() = default
std::vector<NodeId> selectedNodes() const
virtual QMenu *createSceneMenu(QPointF const scenePos) override

Can.

Returns:

an instance of the scene context menu in subclass. Default implementation returns nullptr.

Public Slots

void save() const
void load()

Signals

void sceneLoaded()
class DataFlowGraphModel : public QtNodes::AbstractGraphModel, public QtNodes::Serializable

Public Functions

DataFlowGraphModel(std::shared_ptr<NodeDelegateModelRegistry> registry)
inline std::shared_ptr<NodeDelegateModelRegistry> dataModelRegistry()
virtual std::unordered_set<NodeId> allNodeIds() const override

Returns the full set of unique Node Ids.

Model creator is responsible for generating unique unsigned int Ids for all the nodes in the graph. From an Id it should be possible to trace back to the model’s internal representation of the node.

virtual std::unordered_set<ConnectionId> allConnectionIds(NodeId const nodeId) const override

A collection of all input and output connections for the given nodeId.

virtual std::unordered_set<ConnectionId> connections(NodeId nodeId, PortType portType, PortIndex portIndex) const override

Returns all connected Node Ids for given port.

The returned set of nodes and port indices correspond to the type opposite to the given portType.

virtual bool connectionExists(ConnectionId const connectionId) const override

Checks if two nodes with the given connectionId are connected.

virtual NodeId addNode(QString const nodeType) override

Creates a new node instance in the derived class.

The model is responsible for generating a unique NodeId.

Parameters:

nodeType[in] is free to be used and interpreted by the model on its own, it helps to distinguish between possible node types and create a correct instance inside.

virtual bool connectionPossible(ConnectionId const connectionId) const override

Model decides if a conection with a given connection Id possible.

The default implementation compares corresponding data types.

It is possible to override the function and connect non-equal data types.

virtual void addConnection(ConnectionId const connectionId) override

Creates a new connection between two nodes.

Default implementation emits signal connectionCreated(connectionId)

In the derived classes user must emite the signal to notify the scene about the changes.

virtual bool nodeExists(NodeId const nodeId) const override
Returns:

true if there is data in the model associated with the given nodeId.

virtual QVariant nodeData(NodeId nodeId, NodeRole role) const override

Returns node-related data for requested NodeRole.

Returns:

Node Caption, Node Caption Visibility, Node Position etc.

virtual NodeFlags nodeFlags(NodeId nodeId) const override
virtual bool setNodeData(NodeId nodeId, NodeRole role, QVariant value) override

Sets node properties.

Sets: Node Caption, Node Caption Visibility, Shyle, State, Node Position etc.

See also

NodeRole.

virtual QVariant portData(NodeId nodeId, PortType portType, PortIndex portIndex, PortRole role) const override

Returns port-related data for requested NodeRole.

Returns:

Port Data Type, Port Data, Connection Policy, Port Caption.

virtual bool setPortData(NodeId nodeId, PortType portType, PortIndex portIndex, QVariant const &value, PortRole role = PortRole::Data) override
virtual bool deleteConnection(ConnectionId const connectionId) override
virtual bool deleteNode(NodeId const nodeId) override
virtual QJsonObject saveNode(NodeId const) const override

Reimplement the function if you want to store/restore the node’s inner state during undo/redo node deletion operations.

virtual QJsonObject save() const override
virtual void loadNode(QJsonObject const &nodeJson) override

Reimplement the function if you want to support:

  • graph save/restore operations,

  • undo/redo operations after deleting the node.

QJsonObject must contain following fields:

{
  id : 5,
  position : { x : 100, y : 200 },
  internal-data {
    "your model specific data here"
  }
}

The function must do almost exacly the same thing as the normal addNode(). The main difference is in a model-specific inner-data processing.

virtual void load(QJsonObject const &json) override
template<typename NodeDelegateModelType>
inline NodeDelegateModelType *delegateModel(NodeId const nodeId)

Fetches the NodeDelegateModel for the given nodeId and tries to cast the stored pointer to the given type

Signals

void inPortDataWasSet(NodeId const, PortType const, PortIndex const)
struct NodeGeometryData

Public Members

QSize size
QPointF pos
class NodeDelegateModel : public QObject, public QtNodes::Serializable

The class wraps Node-specific data operations and propagates it to the nesting DataFlowGraphModel which is a subclass of AbstractGraphModel. This class is the same what has been called NodeDataModel before v3.

Public Functions

NodeDelegateModel()
virtual ~NodeDelegateModel() = default
inline virtual bool captionVisible() const

It is possible to hide caption in GUI.

virtual QString caption() const = 0

Caption is used in GUI.

inline virtual bool portCaptionVisible(PortType, PortIndex) const

It is possible to hide port caption in GUI.

inline virtual QString portCaption(PortType, PortIndex) const

Port caption is used in GUI to label individual ports.

virtual QString name() const = 0

Name makes this model unique.

virtual QJsonObject save() const override
virtual void load(QJsonObject const&) override
virtual unsigned int nPorts(PortType portType) const = 0
virtual NodeDataType dataType(PortType portType, PortIndex portIndex) const = 0
virtual ConnectionPolicy portConnectionPolicy(PortType, PortIndex) const
NodeStyle const &nodeStyle() const
void setNodeStyle(NodeStyle const &style)
virtual void setInData(std::shared_ptr<NodeData> nodeData, PortIndex const portIndex) = 0
virtual std::shared_ptr<NodeData> outData(PortIndex const port) = 0
virtual QWidget *embeddedWidget() = 0

It is recommented to preform a lazy initialization for the embedded widget and create it inside this function, not in the constructor of the current model.

Our Model Registry is able to shortly instantiate models in order to call the non-static Model::name(). If the embedded widget is allocated in the constructor but not actually embedded into some QGraphicsProxyWidget, we’ll gonna have a dangling pointer.

inline virtual bool resizable() const

Public Slots

inline virtual void inputConnectionCreated(ConnectionId const&)
inline virtual void inputConnectionDeleted(ConnectionId const&)
inline virtual void outputConnectionCreated(ConnectionId const&)
inline virtual void outputConnectionDeleted(ConnectionId const&)

Signals

void dataUpdated(PortIndex const index)

Triggers the updates in the nodes downstream.

void dataInvalidated(PortIndex const index)

Triggers the propagation of the empty data downstream.

void computingStarted()
void computingFinished()
void embeddedWidgetSizeUpdated()
void portsAboutToBeDeleted(PortType const portType, PortIndex const first, PortIndex const last)

Call this function before deleting the data associated with ports.

The function notifies the Graph Model and makes it remove and recompute the affected connection addresses.

void portsDeleted()

Call this function when data and port moditications are finished.

void portsAboutToBeInserted(PortType const portType, PortIndex const first, PortIndex const last)

Call this function before inserting the data associated with ports.

The function notifies the Graph Model and makes it recompute the affected connection addresses.

void portsInserted()

Call this function when data and port moditications are finished.

class NodeDelegateModelRegistry

Class uses map for storing models (name, model)

Public Types

using RegistryItemPtr = std::unique_ptr<NodeDelegateModel>
using RegistryItemCreator = std::function<RegistryItemPtr()>
using RegisteredModelCreatorsMap = std::unordered_map<QString, RegistryItemCreator>
using RegisteredModelsCategoryMap = std::unordered_map<QString, QString>
using CategoriesSet = std::set<QString>

Public Functions

NodeDelegateModelRegistry() = default
~NodeDelegateModelRegistry() = default
NodeDelegateModelRegistry(NodeDelegateModelRegistry const&) = delete
NodeDelegateModelRegistry(NodeDelegateModelRegistry&&) = default
NodeDelegateModelRegistry &operator=(NodeDelegateModelRegistry const&) = delete
NodeDelegateModelRegistry &operator=(NodeDelegateModelRegistry&&) = default
template<typename ModelType>
inline void registerModel(RegistryItemCreator creator, QString const &category = "Nodes")
template<typename ModelType>
inline void registerModel(QString const &category = "Nodes")
std::unique_ptr<NodeDelegateModel> create(QString const &modelName)
RegisteredModelCreatorsMap const &registeredModelCreators() const
RegisteredModelsCategoryMap const &registeredModelsCategoryAssociation() const
CategoriesSet const &categories() const

Definitions

using QtNodes::NodeId = unsigned int

Unique Id associated with each node in the GraphModel.

using QtNodes::PortIndex = unsigned int

ports are consecutively numbered starting from zero.

enum QtNodes::NodeRole

Constants used for fetching QVariant data from GraphModel.

Values:

enumerator Type

Type of the current node, usually a string.

enumerator Position

QPointF positon of the node on the scene.

enumerator Size

QSize for resizable nodes.

enumerator CaptionVisible

bool for caption visibility.

enumerator Caption

QString for node caption.

enumerator Style

Custom NodeStyle as QJsonDocument.

enumerator InternalData

Node-stecific user data as QJsonObject.

enumerator InPortCount

unsigned int

enumerator OutPortCount

unsigned int

enumerator Widget

Optional QWidget* or nullptr

enum QtNodes::NodeFlag

Specific flags regulating node features and appeaarence.

Values:

enumerator NoFlags

Default NodeFlag.

enumerator Resizable

Lets the node be resizable.

enumerator Locked
enum QtNodes::PortRole

Constants for fetching port-related information from the GraphModel.

Values:

enumerator Data

std::shared_ptr<NodeData>.

enumerator DataType

QString describing the port data type.

enumerator ConnectionPolicyRole

enum ConnectionPolicyRole

enumerator CaptionVisible

bool for caption visibility.

enumerator Caption

QString for port caption.

enum QtNodes::ConnectionPolicy

Defines how many connections are possible to attach to ports. The values are fetched using PortRole::ConnectionPolicy.

Values:

enumerator One

Just one connection for each port.

enumerator Many

Any number of connections possible for the port.

enum QtNodes::PortType

Used for distinguishing input and output node ports.

Values:

enumerator In

Input node port (from the left).

enumerator Out

Output node port (from the right).

enumerator None