QtNodes Class Reference
This page provides auto-generated API documentation from the source code.
Core Classes
Graph Model
-
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:
NodeId
Subclassed by QtNodes::DataFlowGraphModel
Public Functions
-
virtual std::unordered_set<NodeId> allNodeIds() const = 0
Returns the full set of unique Node Ids.
Model creator is responsible for generating unique
unsigned intIds 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
connectionIdare 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:
trueif there is data in the model associated with the givennodeId.
-
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
QVariantvalue returned from the standardQVariant AbstractGraphModel::nodeData(NodeId, NodeRole)function.
-
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
QVariantvalue returned from the standardQVariant 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
-
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-dataprocessing.
-
inline virtual bool loopsEnabled() const
-
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
lastport 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 modelReset()
-
class DataFlowGraphModel : public QtNodes::AbstractGraphModel, public QtNodes::Serializable
Public Functions
-
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 intIds 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
connectionIdare 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:
trueif there is data in the model associated with the givennodeId.
-
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 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 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 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-dataprocessing.
-
virtual QJsonObject save() const override
-
virtual void load(QJsonObject const &json) override
-
template<typename NodeDelegateModelType>
inline NodeDelegateModelType *delegateModel(NodeId const nodeId) Fetches the NodeDelegateModel for the given
nodeIdand tries to cast the stored pointer to the given type
-
inline virtual bool loopsEnabled() const override
Loops do not make any sense in uni-direction data propagation.
-
struct NodeGeometryData
-
inline std::shared_ptr<NodeDelegateModelRegistry> dataModelRegistry()
Scene and View
-
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 const &nodeGeometry() const
-
AbstractNodeGeometry &nodeGeometry()
-
AbstractNodePainter &nodePainter()
-
AbstractConnectionPainter &connectionPainter()
-
void setNodePainter(std::unique_ptr<AbstractNodePainter> newPainter)
-
void setConnectionPainter(std::unique_ptr<AbstractConnectionPainter> newPainter)
-
void setNodeGeometry(std::unique_ptr<AbstractNodeGeometry> newGeom)
-
QUndoStack &undoStack()
-
void setGroupingEnabled(bool enabled)
Setter for the _groupingEnabled flag.
- Parameters:
boolean – to set or not the flag.
-
inline bool groupingEnabled() const
Getter for the _groupingEnabled flag.
-
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.
-
std::vector<std::shared_ptr<ConnectionId>> connectionsWithinGroup(GroupId groupID)
Creates a list of the connections that are incident only to nodes within a given group.
- Parameters:
groupID – ID of the desired group.
- Returns:
List of (pointers of) connections whose both endpoints belong to members of the specified group.
-
std::weak_ptr<NodeGroup> createGroup(std::vector<NodeGraphicsObject*> &nodes, QString name = QStringLiteral(""), GroupId groupId = InvalidGroupId)
Creates a group in the scene containing the given nodes.
- Parameters:
nodes – Reference to the list of nodes to be included in the group.
name – Group’s name.
groupId – Group’s id.
- Returns:
Pointer to the newly-created group.
-
std::weak_ptr<NodeGroup> createGroupFromSelection(QString groupName = QStringLiteral(""))
Creates a group in the scene containing the currently selected nodes.
- Parameters:
name – Group’s name
- Returns:
Pointer to the newly-created group.
-
std::pair<std::weak_ptr<NodeGroup>, std::unordered_map<GroupId, GroupId>> restoreGroup(QJsonObject const &groupJson, QHash<NodeId, QJsonObject> const &nodeById = {})
Restores a group from a JSON object.
- Parameters:
groupJson – JSON object containing the group data.
- Returns:
Pair consisting of a pointer to the newly-created group and the mapping between old and new nodes.
-
std::unordered_map<GroupId, std::shared_ptr<NodeGroup>> const &groups() const
Returns a const reference to the mapping of existing groups.
-
std::weak_ptr<NodeGroup> loadGroupFile()
Loads a group from a file specified by the user.
- Returns:
Pointer to the newly-created group.
-
void saveGroupFile(GroupId groupID)
Saves a group in a .group file.
- Parameters:
groupID – Group’s id.
-
std::vector<NodeGraphicsObject*> selectedNodes() const
Calculates the selected nodes.
- Returns:
Vector containing the NodeGraphicsObject pointers related to the selected nodes.
-
std::vector<GroupGraphicsObject*> selectedGroups() const
Calculates the selected groups.
- Returns:
Vector containing the GroupGraphicsObject pointers related to the selected groups.
-
void addNodeToGroup(NodeId nodeId, GroupId groupId)
Adds a node to a group, if both node and group exists.
- Parameters:
nodeId – Node’s id.
groupId – Group’s id.
-
void removeNodeFromGroup(NodeId nodeId)
Removes a node from a group, if the node exists and is within a group.
- Parameters:
nodeId – Node’s id.
-
std::unordered_map<QUuid, QUuid> loadItems(const QByteArray &data, QPointF pastePos, bool usePastePos = true)
Loads serialized item (nodes, connections and groups) into the scene.
- Parameters:
data – Serialized scene payload.
pastePos – Reference position used when pasting content.
usePastePos – When true, places the loaded content relative to pastePos position.
- Returns:
Mapping between original node UUIDs and newly created node UUIDs.
-
std::unordered_map<QUuid, QUuid> loadFromMemory(const QByteArray &data)
Loads scene data from memory.
- Parameters:
data – Serialized scene payload.
- Returns:
Mapping between original node UUIDs and newly created node UUIDs.
-
QUuid encodeNodeId(NodeId nodeId)
Encodes NodeId into a QUuid representation.
- Parameters:
nodeId – Node identifier.
- Returns:
QUuid carrying the binary value of nodeId.
-
NodeId decodeNodeUuid(QUuid const &uuid)
Decodes a node QUuid into a NodeId.
- Parameters:
uuid – QUuid containing an encoded node id.
- Returns:
Decoded NodeId.
-
std::unordered_map<NodeId, NodeId> convertMap(std::unordered_map<QUuid, QUuid> const &uuidMap)
Converts a QUuid-to-QUuid map into a NodeId-to-NodeId map.
- Parameters:
uuidMap – Map containing encoded old and new node QUuid pairs.
- Returns:
Map with decoded NodeId pairs, excluding invalid entries.
-
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:
nullptrwhen 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.
-
void freezeModelAndConnections(bool isFreeze)
Freezes and unfreezes the model and connections of the selected nodes.
- Parameters:
isFreeze – reference for freezing or unfreezing the model and connections of the selected nodes.
-
QMenu *createStdMenu(QPointF const scenePos)
Creates the default menu when a node is selected.
-
QMenu *createGroupMenu(QPointF const scenePos, GroupGraphicsObject *groupGo)
Creates the menu when a group is selected.
- Parameters:
groupGo – reference to the GroupGraphicsObject related to the selected group.
Public Slots
-
virtual void onConnectionDeleted(ConnectionId const connectionId)
Slot called when the
connectionIdis erased form the AbstractGraphModel.
-
virtual void onConnectionCreated(ConnectionId const connectionId)
Slot called when the
connectionIdis created in the AbstractGraphModel.
-
virtual void onModelReset()
-
inline void onCopySelectedObjects()
Slot called to trigger the copy command action.
-
inline void onDeleteSelectedObjects()
Slot called to trigger the delete command action.
Signals
-
void modified(BasicGraphicsScene*)
-
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.
-
void zoomFitAllClicked()
Signals to call Graphics View’s zoomFit methods.
-
void zoomFitSelectedClicked()
-
BasicGraphicsScene(AbstractGraphModel &graphModel, QObject *parent = nullptr)
-
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
-
virtual QMenu *createSceneMenu(QPointF const scenePos) override
Can
- Returns:
an instance of the scene context menu in subclass. Default implementation returns
nullptr.
-
void updateConnectionGraphics(const std::unordered_set<ConnectionId> &connections, bool state)
Signals
-
void sceneLoaded()
-
DataFlowGraphicsScene(DataFlowGraphModel &graphModel, QObject *parent = nullptr)
-
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
-
inline BasicGraphicsScene *getNodeScene()
Public Slots
-
void scaleUp()
-
void scaleDown()
-
void setupScale(double scale)
-
virtual void onDeleteSelectedObjects()
-
virtual void onDuplicateSelectedObjects()
-
virtual void onCopySelectedObjects()
-
virtual void onPasteObjects()
-
void zoomFitAll()
-
void zoomFitSelected()
Signals
-
void scaleChanged(double scale)
-
struct ScaleRange
-
GraphicsView(QWidget *parent = Q_NULLPTR)
Node Classes
Graphics
-
class NodeGraphicsObject : public QGraphicsObject
Public Types
-
enum [anonymous]
Values:
-
enumerator Type
-
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.
-
void lock(bool locked)
Lockes/unlockes nodes in a selected node group.
-
void updateQWidgetEmbedPos()
-
QJsonObject save() const
Saves node in a QJsonObject save file.
-
void setNodeGroup(std::shared_ptr<NodeGroup> group)
Setter for the NodeGroup object.
- Parameters:
shared – pointer to the node group.
-
inline void unsetNodeGroup()
Unsets NodeGroup, setting it to an empty pointer.
-
inline std::weak_ptr<NodeGroup> nodeGroup() const
Getter for the NodeGroup object.
-
enum [anonymous]
-
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()
-
NodeState(NodeGraphicsObject &ngo)
Painting
-
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()
-
virtual ~AbstractNodePainter() = default
-
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 drawNodeLabel(QPainter *painter, NodeGraphicsObject &ngo) const
-
void drawEntryLabels(QPainter *painter, NodeGraphicsObject &ngo) const
-
void drawResizeRect(QPainter *painter, NodeGraphicsObject &ngo) const
-
void drawProcessingIndicator(QPainter *painter, NodeGraphicsObject &ngo) const
-
void drawValidationIcon(QPainter *painter, NodeGraphicsObject &ngo) const
-
void drawProgressValue(QPainter *painter, NodeGraphicsObject &ngo) const
-
virtual void paint(QPainter *painter, NodeGraphicsObject &ngo) const override
Geometry
-
class AbstractNodeGeometry
Subclassed by QtNodes::DefaultHorizontalNodeGeometry, QtNodes::DefaultVerticalNodeGeometry
Public Functions
-
AbstractNodeGeometry(AbstractGraphModel&)
-
inline virtual ~AbstractNodeGeometry()
-
virtual QRectF boundingRect(NodeId const nodeId) const = 0
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).
-
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
portPositionand 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 labelPosition(NodeId const nodeId) const = 0
Defines where to start drawing the label. The point corresponds to a font baseline.
-
virtual QRectF labelRect(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 int getPortSpacing() = 0
-
AbstractNodeGeometry(AbstractGraphModel&)
-
class DefaultHorizontalNodeGeometry : public QtNodes::AbstractNodeGeometry
Public Functions
-
DefaultHorizontalNodeGeometry(AbstractGraphModel &graphModel)
-
virtual QRectF boundingRect(NodeId const nodeId) const override
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).
-
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 labelPosition(const NodeId nodeId) const override
Defines where to start drawing the label. The point corresponds to a font baseline.
-
virtual QRectF labelRect(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.
-
inline virtual int getPortSpacing() override
-
DefaultHorizontalNodeGeometry(AbstractGraphModel &graphModel)
-
class DefaultVerticalNodeGeometry : public QtNodes::AbstractNodeGeometry
Public Functions
-
DefaultVerticalNodeGeometry(AbstractGraphModel &graphModel)
-
virtual QRectF boundingRect(NodeId const nodeId) const override
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).
-
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 labelPosition(const NodeId nodeId) const override
Defines where to start drawing the label. The point corresponds to a font baseline.
-
virtual QRectF labelRect(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.
-
inline virtual int getPortSpacing() override
-
DefaultVerticalNodeGeometry(AbstractGraphModel &graphModel)
Connection Classes
-
class ConnectionGraphicsObject : public QGraphicsObject
Graphic Object for connection. Adds itself to scene.
Public Types
-
enum [anonymous]
Values:
-
enumerator Type
-
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()
-
enum [anonymous]
-
class AbstractConnectionPainter
Class enables custom painting for connections.
Subclassed by QtNodes::DefaultConnectionPainter
Public Functions
-
virtual ~AbstractConnectionPainter() = default
-
virtual void paint(QPainter *painter, ConnectionGraphicsObject const &cgo) const = 0
Reimplement this function in order to have a custom connection painting.
-
virtual QPainterPath getPainterStroke(ConnectionGraphicsObject const &cgo) const = 0
-
virtual ~AbstractConnectionPainter() = default
-
class DefaultConnectionPainter : public QtNodes::AbstractConnectionPainter
Public Functions
-
virtual void paint(QPainter *painter, ConnectionGraphicsObject const &cgo) const override
Reimplement this function in order to have a custom connection painting.
-
virtual QPainterPath getPainterStroke(ConnectionGraphicsObject const &cgo) const override
-
virtual void paint(QPainter *painter, ConnectionGraphicsObject const &cgo) const override
-
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
We check connection possibility from the perspecpive of ConnectionGraphicsObject first and just then ask the GraphModel.
Can connect when following conditions are met:
ConnectionGrachicsObject::connectionState() ‘requires’ a port.
Connection loose end is geometrically above the node port.
GraphModel permits connection
Here we check specific data type
multi-connection policy
New connection does not introduce a loop if
AbstractGrphModel::loopsEnabled()forbits it.
-
bool tryConnect() const
Creates a new connectino if possible.
Check conditions from ‘canConnect’.
Creates new connection with
GraphModel::addConnection.Adjust connection geometry.
-
bool disconnect(PortType portToDisconnect) const
Delete connection with
GraphModel::deleteConnection.Create a “draft” connection with incomplete
ConnectionId.Repaint both previously connected nodes.
-
inline NodeGraphicsObject &nodeGraphicsObject()
Getter for the NodeGraphicsObject object.
-
NodeConnectionInteraction(NodeGraphicsObject &ngo, ConnectionGraphicsObject &cgo, BasicGraphicsScene &scene)
Data Flow Classes
-
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
-
virtual QString name() const = 0
Name makes this model unique.
-
virtual QString caption() const = 0
Caption is used in GUI.
-
inline virtual bool captionVisible() const
It is possible to hide caption in GUI.
-
inline virtual QString portCaption(PortType, PortIndex) const
Port caption is used in GUI to label individual ports.
-
inline virtual bool portCaptionVisible(PortType, PortIndex) const
It is possible to hide port caption in GUI.
-
inline virtual QString label() const
Nicknames can be assigned to nodes and shown in GUI.
-
inline virtual bool labelVisible() const
It is possible to hide the nickname in GUI.
-
inline virtual bool labelEditable() const
Controls whether the label can be edited or not.
-
inline virtual NodeValidationState validationState() const
Validation State will default to Valid, but you can manipulate it by overriding in an inherited class.
-
inline virtual NodeProcessingStatus processingStatus() const
Returns the curent processing status.
-
inline virtual QString progressValue() const
Progress is used in GUI.
-
virtual QJsonObject save() const override
-
virtual void load(QJsonObject const&) override
-
void setNodeProcessingStatus(NodeProcessingStatus status)
-
void setValidationState(const NodeValidationState &validationState)
-
virtual NodeDataType dataType(PortType portType, PortIndex portIndex) const = 0
-
virtual ConnectionPolicy portConnectionPolicy(PortType, PortIndex) const
-
void setBackgroundColor(QColor const &color)
Convenience helper to change the node background color.
-
QPixmap processingStatusIcon() const
-
void setStatusIcon(NodeProcessingStatus status, const QPixmap &pixmap)
-
void setStatusIconStyle(ProcessingIconStyle const &style)
-
inline void setProgressValue(QString new_progress)
-
virtual QWidget *embeddedWidget() = 0
It is recommented to preform 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
-
inline bool frozen() const
-
inline void setFrozenState(bool state)
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 computingStarted()
-
void computingFinished()
-
void embeddedWidgetSizeUpdated()
-
void requestNodeUpdate()
Request an update of the node’s UI.
Emit this signal whenever some internal state change requires the node to be repainted. The containing graph model will propagate the update to the scene.
-
void portsAboutToBeDeleted(PortType const portType, PortIndex const first, PortIndex const last)
Call this function before deleting the data associated with ports.
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.
-
NodeDelegateModel()
-
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")
-
template<typename ModelCreator>
inline void registerModel(ModelCreator &&creator, QString const &category = "Nodes")
-
std::unique_ptr<NodeDelegateModel> create(QString const &modelName)
-
RegisteredModelCreatorsMap const ®isteredModelCreators() const
-
RegisteredModelsCategoryMap const ®isteredModelsCategoryAssociation() const
-
CategoriesSet const &categories() const
-
using RegistryItemPtr = std::unique_ptr<NodeDelegateModel>
-
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
-
virtual NodeDataType type() const = 0
Type for inner use.
Styling
-
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
-
void setBackgroundColor(QColor const &color)
Set uniform background color for the node.
-
QColor backgroundColor() const
Current uniform background color.
Public Members
-
QColor NormalBoundaryColor
-
QColor SelectedBoundaryColor
-
QColor GradientColor0
-
QColor GradientColor1
-
QColor GradientColor2
-
QColor GradientColor3
-
QColor ShadowColor
-
bool ShadowEnabled
-
QColor FontColor
-
QColor FontColorFaded
-
QColor ConnectionPointColor
-
QColor FilledConnectionPointColor
-
QColor WarningColor
-
QColor ErrorColor
-
QColor ToolTipIconColor
-
float PenWidth
-
float HoveredPenWidth
-
float ConnectionPointDiameter
-
float Opacity
-
QIcon statusUpdated
-
QIcon statusProcessing
-
QIcon statusPending
-
QIcon statusInvalid
-
QIcon statusEmpty
-
QIcon statusPartial
-
ProcessingIconStyle processingIconStyle = {}
Public Static Functions
-
static void setNodeStyle(QString jsonText)
-
NodeStyle()
-
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)
-
ConnectionStyle()
-
class GraphicsViewStyle : public QtNodes::Style
Public Functions
-
GraphicsViewStyle()
-
GraphicsViewStyle(QString jsonText)
-
~GraphicsViewStyle() = default
Public Static Functions
-
static void setStyle(QString jsonText)
-
GraphicsViewStyle()
-
class StyleCollection
Public Static Functions
-
static ConnectionStyle const &connectionStyle()
-
static GraphicsViewStyle const &flowViewStyle()
-
static void setConnectionStyle(ConnectionStyle)
-
static void setGraphicsViewStyle(GraphicsViewStyle)
-
static ConnectionStyle const &connectionStyle()
Undo Commands
-
class CreateCommand : public QUndoCommand
Public Functions
-
CreateCommand(BasicGraphicsScene *scene, QString const name, QPointF const &mouseScenePos)
-
void undo() override
-
void redo() override
-
CreateCommand(BasicGraphicsScene *scene, QString const name, QPointF const &mouseScenePos)
-
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
-
DeleteCommand(BasicGraphicsScene *scene)
-
class ConnectCommand : public QUndoCommand
Public Functions
-
ConnectCommand(BasicGraphicsScene *scene, ConnectionId const)
-
void undo() override
-
void redo() override
-
ConnectCommand(BasicGraphicsScene *scene, ConnectionId const)
-
class DisconnectCommand : public QUndoCommand
Public Functions
-
DisconnectCommand(BasicGraphicsScene *scene, ConnectionId const)
-
void undo() override
-
void redo() override
-
DisconnectCommand(BasicGraphicsScene *scene, ConnectionId const)
-
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.
-
MoveNodeCommand(BasicGraphicsScene *scene, QPointF const &diff)
-
class CopyCommand : public QUndoCommand
Public Functions
-
CopyCommand(BasicGraphicsScene *scene)
-
CopyCommand(BasicGraphicsScene *scene)
-
class PasteCommand : public QUndoCommand
Public Functions
-
PasteCommand(BasicGraphicsScene *scene, QPointF const &mouseScenePos)
-
void undo() override
-
void redo() override
-
PasteCommand(BasicGraphicsScene *scene, QPointF const &mouseScenePos)
Data Types
Structs
-
struct NodeDataType
idrepresents an internal unique data type for the given port.nameis a normal text description.
-
struct ConnectionId
A unique connection identificator that stores out
NodeId, outPortIndex, inNodeId, inPortIndex
-
struct NodeValidationState
Describes whether a node configuration is usable and defines a description message
Public Types
-
struct ProcessingIconStyle
Defines the processing icon style;
Public Members
-
ProcessingIconPos _pos = {ProcessingIconPos::BottomRight}
-
double _size = {20.0}
-
double _margin = {8.0}
-
int _resolution = {64}
-
ProcessingIconPos _pos = {ProcessingIconPos::BottomRight}
Type 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.
Enumerations
-
enum class QtNodes::NodeRole
Constants used for fetching QVariant data from GraphModel.
Values:
-
enumerator Type
Type of the current node, usually a string.
-
enumerator Position
QPointFpositon of the node on the scene.
-
enumerator Size
QSizefor resizable nodes.
-
enumerator CaptionVisible
boolfor caption visibility.
-
enumerator Caption
QStringfor node caption.
-
enumerator InternalData
Node-stecific user data as QJsonObject.
-
enumerator InPortCount
unsigned int
-
enumerator OutPortCount
unsigned int
-
enumerator Widget
Optional
QWidget*ornullptr
-
enumerator ValidationState
Enum NodeValidationState of the node.
-
enumerator LabelVisible
boolfor label visibility.
-
enumerator ProcessingStatus
Enum NodeProcessingStatus of the node.
-
enumerator ProgressValue
‘QString’ for the progress value
-
enumerator Label
QStringfor node label.
-
enumerator LabelEditable
boolto indicate label editing support.
-
enumerator Type
-
enum QtNodes::NodeFlag
Specific flags regulating node features and appeaarence.
Values:
-
enumerator NoFlags
Default NodeFlag.
-
enumerator Resizable
Lets the node be resizable.
-
enumerator Locked
-
enumerator NoFlags
-
enum class QtNodes::PortRole
Constants for fetching port-related information from the GraphModel.
Values:
-
enumerator DataType
QStringdescribing the port data type.
-
enumerator ConnectionPolicyRole
enumConnectionPolicyRole
-
enumerator CaptionVisible
boolfor caption visibility.
-
enumerator Caption
QStringfor port caption.
-
enumerator DataType
-
enum class 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
-
enumerator In
-
enum class 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.
-
enumerator One
-
enum class QtNodes::NodeProcessingStatus : int
Describes the node status, depending on its current situation
Values:
-
enumerator NoStatus
No processing status is shown in the Node UI.
-
enumerator Updated
Node is up to date; its outputs reflect the current inputs and parameters.
-
enumerator Processing
Node is currently running a computation.
-
enumerator Pending
Node is out of date and waiting to be recomputed (e.g. manual/queued run).
-
enumerator Empty
Node has no valid input data; nothing to compute.
-
enumerator Failed
The last computation ended with an error.
-
enumerator Partial
Computation finished incompletely; only partial results are available.
-
enumerator NoStatus