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:
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 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 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
QVariant
value 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
QVariant
value 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-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 modelReset()
-
struct NodeDataType
id
represents an internal unique data type for the given port.name
is a normal text description.
-
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.
-
struct ConnectionId
A unique connection identificator that stores out
NodeId
, outPortIndex
, inNodeId
, 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 onModelReset()
Signals
-
void connectionHovered(ConnectionId const connectionId, QPoint const screenPos)
-
void connectionHoverLeft(ConnectionId const connectionId)
-
BasicGraphicsScene(AbstractGraphModel &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
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
-
GraphicsView(QWidget *parent = Q_NULLPTR)
-
class GraphicsViewStyle : public QtNodes::Style
Public Functions
-
GraphicsViewStyle()
-
GraphicsViewStyle(QString jsonText)
-
~GraphicsViewStyle() = default
Public Static Functions
-
static void setStyle(QString jsonText)
-
GraphicsViewStyle()
-
class NodeGraphicsObject : public QGraphicsObject
-
Public Functions
-
inline int type() const override
-
NodeGraphicsObject(BasicGraphicsScene &scene, NodeId node)
-
~NodeGraphicsObject() override = default
-
AbstractGraphModel &graphModel() const
-
BasicGraphicsScene *nodeScene() 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.
-
inline int type() const override
-
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 drawEntryLabels(QPainter *painter, NodeGraphicsObject &ngo) const
-
void drawResizeRect(QPainter *painter, NodeGraphicsObject &ngo) const
-
virtual void paint(QPainter *painter, NodeGraphicsObject &ngo) const override
-
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.
Defines where to start drawing the caption. The point corresponds to a font baseline.
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.
-
AbstractNodeGeometry(AbstractGraphModel&)
-
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.
Defines where to start drawing the caption. The point corresponds to a font baseline.
Caption rect is needed for estimating the total node size.
-
DefaultHorizontalNodeGeometry(AbstractGraphModel &graphModel)
-
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.
Defines where to start drawing the caption. The point corresponds to a font baseline.
Caption rect is needed for estimating the total node size.
-
DefaultVerticalNodeGeometry(AbstractGraphModel &graphModel)
-
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)
-
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)
-
NodeStyle()
-
class ConnectionGraphicsObject : public QGraphicsObject
Graphic Object for connection. Adds itself to scene.
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
-
inline QPointF out() const
-
inline QPointF in() const
-
std::pair<QPointF, QPointF> pointsC1C2() const
-
void move()
Updates the position of both ends.
-
ConnectionState const &connectionState() const
-
ConnectionState &connectionState()
-
inline int type() const override
-
class ConnectionPainter
Public Static Functions
-
static void paint(QPainter *painter, ConnectionGraphicsObject const &cgo)
-
static QPainterPath getPainterStroke(ConnectionGraphicsObject const &cgo)
-
static void paint(QPainter *painter, 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)
-
ConnectionStyle()
-
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:
Connection ‘requires’ a port.
Connection loose end is above the node port.
Source and target
nodeId
s are different.GraphModel permits connection.
-
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.
-
NodeConnectionInteraction(NodeGraphicsObject &ngo, ConnectionGraphicsObject &cgo, BasicGraphicsScene &scene)
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
-
DeleteCommand(BasicGraphicsScene *scene)
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
-
DisconnectCommand(BasicGraphicsScene *scene, ConnectionId const)
-
class ConnectCommand : public QUndoCommand
Public Functions
-
ConnectCommand(BasicGraphicsScene *scene, ConnectionId const)
-
void undo() override
-
void redo() override
-
ConnectCommand(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)
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
-
virtual QMenu *createSceneMenu(QPointF const scenePos) override
Can.
- Returns:
an instance of the scene context menu in subclass. Default implementation returns
nullptr
.
Signals
-
void sceneLoaded()
-
DataFlowGraphicsScene(DataFlowGraphModel &graphModel, QObject *parent = nullptr)
-
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 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 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 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
-
struct NodeGeometryData
-
inline std::shared_ptr<NodeDelegateModelRegistry> dataModelRegistry()
-
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
It is possible to hide caption in GUI.
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 NodeDataType dataType(PortType portType, PortIndex portIndex) const = 0
-
virtual ConnectionPolicy portConnectionPolicy(PortType, PortIndex) const
-
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 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.
-
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")
-
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>
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 InternalData
Node-stecific user data as QJsonObject.
-
enumerator InPortCount
unsigned int
-
enumerator OutPortCount
unsigned int
-
enumerator Widget
Optional
QWidget*
ornullptr
-
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 QtNodes::PortRole
Constants for fetching port-related information from the GraphModel.
Values:
-
enumerator DataType
QString
describing the port data type.
-
enumerator ConnectionPolicyRole
enum
ConnectionPolicyRole
-
enumerator CaptionVisible
bool
for caption visibility.
-
enumerator Caption
QString
for port caption.
-
enumerator DataType