Maki
Formally verfied low-code orchestration
Loading...
Searching...
No Matches
NodeItem Class Reference

Represents a graphical node item in a flowchart. More...

#include <node.h>

Inheritance diagram for NodeItem:
NodeBase

Public Member Functions

 NodeItem (const QString &id, std::shared_ptr< NodeSaveInfo > info, const QPointF &initialPosition, std::shared_ptr< NodeConfig > nodeConfig, QGraphicsItem *parent=nullptr)
 Constructs a new NodeItem with the given parameters.
virtual ~NodeItem ()
 Destructor for the NodeItem.
int type () const override
 Returns the type of this item.
VoidResult start () override
 Starts the node.
QRectF nodeRect () const override
 Returns the bounding rectangle for this item.
QPainterPath shape () const override
 Returns the shape of this item.
void paint (QPainter *painter, const QStyleOptionGraphicsItem *style, QWidget *widget) override
 Paints the item using the given painter.
HelpConfig help () const
 Returns help configuration for this node.
QString nodeName () const
 Returns the name of the node.
QString nodeType () const
 Returns the type of the node.
QString behaviour () const
 Returns the behavior of the node.
QVector< ControlsConfig > controls () const
 Returns the controls configuration for this node.
QVector< std::shared_ptr< IParameter > > properties () const
 Returns the properties of the node.
QVector< PropertyConfig > configurationProperties () const
 Returns the configuration properties of the node.
Types::LibraryTypes function () const
 Returns the library type associated with this node's function.
const PropertyInfo * getProperty (const QString &key) const
 Gets a property by key.
void setProperty (const QString &key, const maki::Value &value)
 Sets a property with a given key and value.
void renameNode (const QString &name)
 Renames the node to a new name.
NodeItem * parentNode () const
 Returns the parent node of this item.
QVector< NodeItem * > children () const
 Returns a list of child nodes.
QPointF edgePointToward (const QPointF &targetScenePos) const
 Calculates an edge point toward a target scene position.
QVector< std::shared_ptr< IParameter > > fields () const
 Returns a list of fields associated with this node.
PropertyInfo getField (const QString &key) const
 Gets a property info by key.
VoidResult setField (const QString &key, const QJsonObject &property)
 Sets a field with a given key and JSON object.
VoidResult setField (const QString &key, std::shared_ptr< PropertyInfo > property)
 Sets a field with a given key and PropertyInfo object.
void removeField (const QString &key)
 Removes a field by key.
void setEvent (int index, const FlowConfig &event)
 Sets an event at the given index with the provided FlowConfig.
QVector< std::shared_ptr< IFlow > > flowConfigs () const
 Returns a list of events associated with this node.
void addParent (NodeItem *node)
 Adds a parent node to this item.
void addChild (NodeItem *node, std::shared_ptr< NodeSaveInfo > info)
 Adds a child node with the given save information.
void childRemoved (NodeItem *child)
 Handles when a child is removed from this item.
QVector< Flow * > flows () const
 Returns a list of flows associated with this node.
Flow * createFlow (const QString &flowName, std::shared_ptr< FlowSaveInfo > info)
 Creates a new flow with the given name and save information.
Flow * getFlow (const QString &flowId) const
 Gets a flow by its ID.
void deleteFlow (const QString &flowId)
 Deletes a flow by its ID.
void updateFlow ()
 Updates all flows associated with this node.
qreal baseScale () const
 Returns the base scale for this node.
QVector< TransitionConfig > configTransitions () const
 Returns a list of configured transitions.
void applySize (const QSizeF &size)
 Applies a new size to the node.
void updatePosition (const QPointF &position)
 Updates the position of the node.
NodeSaveInfo saveInfo () const
 Returns the savable information for this node.
Public Member Functions inherited from NodeBase
 NodeBase (const QString &id, const QString &nodeId, std::shared_ptr< NodeConfig > config, QGraphicsItem *parent)
 Constructs a new NodeBase instance.
virtual ~NodeBase ()
 Destructor.
QString id () const
 Retrieves the unique identifier of the node.
virtual QString nodeId () const
 Retrieves the identifier of the node within its type.
virtual std::shared_ptr< NodeConfig > config () const
 Retrieves the configuration settings for the node.
virtual QRectF boundingRect () const override
 Returns the bounding rectangle of the node.
virtual QRectF labelBoundingRect () const
 Returns the bounding rectangle of the label.
virtual QRectF scaledRect () const
 Returns the scaled rectangle of the node.
virtual QRectF drawingRect (const QRectF &input) const
 Returns the drawing rectangle based on the input rectangle.
virtual QPainterPath nodeShape (const QRectF &bounds) const
 Returns the node shape as a QPainterPath.
void paintNode (const QRectF &bounds, const QColor &background, const QPen &text, QPainter *painter)
 Paints the node using the provided painter.
virtual QPixmap nodePixmap () const
 Retrieves the pixmap of the node.
virtual QString nodeIcon () const
 Retrieves the icon path of the node.
virtual void toggleLabelVisibility ()
 Toggles the visibility of the label.

Protected Member Functions

void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override
 Handles mouse move events for this item.
void mousePressEvent (QGraphicsSceneMouseEvent *event) override
 Handles mouse press events for this item.
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override
 Handles mouse release events for this item.
QVariant itemChange (GraphicsItemChange change, const QVariant &value) override
 Handles changes to the item's properties.
Protected Member Functions inherited from NodeBase
virtual void setPixmap (const QPixmap &pixmap)
 Pointer to the SVG icon item.
virtual void setIcon (const QString &path, const QColor &iconColor)
 Sets the icon for the node.
virtual void setLabel (const QString &name, qreal fontSize)
 Sets the label text and font size.
virtual void setLabelName (const QString &name)
 Sets the label text.
virtual void setLabelSize (qreal fontSize, const QSizeF &boundingSize)
 Sets the font size and bounding size for the label.
virtual void paintLabel (QPainter *painter, const QRectF &area, const QPen &pen) const
 Paints the label using the provided painter.
virtual void paintPixmap (QPainter *painter) const
 Paints the pixmap using the provided painter.

Private Member Functions

void updateExtrasPosition ()
 Size of the node when resizing started.
QSizeF clampSize (qreal width, qreal height) const
 Clamps a size within valid limits.
QPointF clampPosInside (const QRectF &inner, const QRectF &childSceneRect) const
 Clamps a position inside an inner rectangle.
void fitInsideParent (qreal padding)
 Fits this node inside its parent with optional padding.
QRectF parentInnerSceneRect (qreal padding) const
 Returns the inner scene rectangle of the parent, optionally padded.

Private Attributes

QVector< Flow * > mFlows
 Save information for the node.
NodeItem * mParentNode
 List of flows associated with this node.
QVector< NodeItem * > mChildrenNodes
 Parent node of this item, if any.
CanvasMessage * mHighlightMessage = nullptr
 List of child nodes.
QSizeF mSize {0, 0}
 Base scale for the node.
QPointF mDragStartPos {0, 0}
 Current size of the node.
QPointF mLastPosition {0, 0}
 Position where dragging started.
bool mIsResizing {false}
 Last known position of the node.
QPointF mResizeStartMousePos {0, 0}
 Flag indicating if the node is being resized.
QSizeF mResizeStartSize {0, 0}
 Mouse position when resizing started.

Friends

QDataStream & operator<< (QDataStream &out, const NodeItem &config)
 Saves the state of this NodeItem to a QDataStream.
QDataStream & operator>> (QDataStream &in, NodeItem &config)
 Loads the state of a NodeItem from a QDataStream.

Additional Inherited Members

Protected Attributes inherited from NodeBase
QGraphicsPixmapItem * mPixmapItem = nullptr
 Configuration settings for the node.
QString mIconPath = ""
 Pointer to the pixmap item.
QGraphicsSvgItem * mIconItem = nullptr
 Path to the icon image.

Detailed Description

Represents a graphical node item in a flowchart.

Constructor & Destructor Documentation

◆ NodeItem()

NodeItem::NodeItem ( const QString & id,
std::shared_ptr< NodeSaveInfo > info,
const QPointF & initialPosition,
std::shared_ptr< NodeConfig > nodeConfig,
QGraphicsItem * parent = nullptr )

Constructs a new NodeItem with the given parameters.

Parameters
idThe unique identifier for the node.
infoThe save information for the node.
initialPositionThe initial position of the node in scene coordinates.
nodeConfigThe configuration for the node.
parentThe parent graphics item, if any.

Member Function Documentation

◆ addChild()

void NodeItem::addChild ( NodeItem * node,
std::shared_ptr< NodeSaveInfo > info )

Adds a child node with the given save information.

Parameters
nodeThe NodeItem to add as a child.
infoThe save information for the child node.

◆ addParent()

void NodeItem::addParent ( NodeItem * node)

Adds a parent node to this item.

Parameters
nodeThe NodeItem to add as a parent.

◆ applySize()

void NodeItem::applySize ( const QSizeF & size)

Applies a new size to the node.

Parameters
sizeThe new QSizeF for the node.

◆ baseScale()

qreal NodeItem::baseScale ( ) const

Returns the base scale for this node.

Returns
The base scale value.

◆ behaviour()

QString NodeItem::behaviour ( ) const

Returns the behavior of the node.

Returns
The behavior string.

◆ childRemoved()

void NodeItem::childRemoved ( NodeItem * child)

Handles when a child is removed from this item.

Parameters
childThe NodeItem that was removed.

◆ children()

QVector< NodeItem * > NodeItem::children ( ) const

Returns a list of child nodes.

Returns
The QVector of child NodeItems.

◆ clampPosInside()

QPointF NodeItem::clampPosInside ( const QRectF & inner,
const QRectF & childSceneRect ) const
private

Clamps a position inside an inner rectangle.

Parameters
innerThe inner QRectF.
childSceneRectThe scene rectangle of the child item.
Returns
The clamped QPointF value.

◆ clampSize()

QSizeF NodeItem::clampSize ( qreal width,
qreal height ) const
private

Clamps a size within valid limits.

Parameters
widthThe width to clamp.
heightThe height to clamp.
Returns
The clamped QSizeF value.

◆ configTransitions()

QVector< TransitionConfig > NodeItem::configTransitions ( ) const

Returns a list of configured transitions.

Returns
The QVector of TransitionConfig objects.

◆ configurationProperties()

QVector< PropertyConfig > NodeItem::configurationProperties ( ) const

Returns the configuration properties of the node.

Returns
The QVector of PropertyConfig objects.

◆ controls()

QVector< ControlsConfig > NodeItem::controls ( ) const

Returns the controls configuration for this node.

Returns
The QVector of ControlsConfig objects.

◆ createFlow()

Flow * NodeItem::createFlow ( const QString & flowName,
std::shared_ptr< FlowSaveInfo > info )

Creates a new flow with the given name and save information.

Parameters
flowNameThe name of the flow.
infoThe save information for the flow.
Returns
The created Flow object, if successful.

◆ deleteFlow()

void NodeItem::deleteFlow ( const QString & flowId)

Deletes a flow by its ID.

Parameters
flowIdThe ID of the flow to delete.

◆ edgePointToward()

QPointF NodeItem::edgePointToward ( const QPointF & targetScenePos) const

Calculates an edge point toward a target scene position.

Parameters
targetScenePosThe target scene position.
Returns
The QPointF representing the edge point.

◆ fields()

QVector< std::shared_ptr< IParameter > > NodeItem::fields ( ) const

Returns a list of fields associated with this node.

Returns
The QVector of IParameter pointers.

◆ fitInsideParent()

void NodeItem::fitInsideParent ( qreal padding)
private

Fits this node inside its parent with optional padding.

Parameters
paddingThe padding to apply when fitting.

◆ flowConfigs()

QVector< std::shared_ptr< IFlow > > NodeItem::flowConfigs ( ) const

Returns a list of events associated with this node.

Returns
The QVector of IFlow pointers.

◆ flows()

QVector< Flow * > NodeItem::flows ( ) const

Returns a list of flows associated with this node.

Returns
The QVector of Flow pointers.

◆ function()

Types::LibraryTypes NodeItem::function ( ) const

Returns the library type associated with this node's function.

Returns
The Types::LibraryTypes enum value.

◆ getField()

PropertyInfo NodeItem::getField ( const QString & key) const

Gets a property info by key.

Parameters
keyThe property key.
Returns
The PropertyInfo object for the given key.

◆ getFlow()

Flow * NodeItem::getFlow ( const QString & flowId) const

Gets a flow by its ID.

Parameters
flowIdThe ID of the flow to retrieve.
Returns
The Flow object, if found.

◆ getProperty()

const PropertyInfo * NodeItem::getProperty ( const QString & key) const

Gets a property by key.

Parameters
keyThe property key.
Returns
The QVariant value of the property.

◆ help()

HelpConfig NodeItem::help ( ) const

Returns help configuration for this node.

Returns
The HelpConfig object.

◆ itemChange()

QVariant NodeItem::itemChange ( GraphicsItemChange change,
const QVariant & value )
overrideprotected

Handles changes to the item's properties.

Parameters
changeThe GraphicsItemChange enum value.
valueThe new value for the property.
Returns
The modified QVariant value.

◆ mouseMoveEvent()

void NodeItem::mouseMoveEvent ( QGraphicsSceneMouseEvent * event)
overrideprotected

Handles mouse move events for this item.

Parameters
eventThe QGraphicsSceneMouseEvent object.

◆ mousePressEvent()

void NodeItem::mousePressEvent ( QGraphicsSceneMouseEvent * event)
overrideprotected

Handles mouse press events for this item.

Parameters
eventThe QGraphicsSceneMouseEvent object.

◆ mouseReleaseEvent()

void NodeItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event)
overrideprotected

Handles mouse release events for this item.

Parameters
eventThe QGraphicsSceneMouseEvent object.

◆ nodeName()

QString NodeItem::nodeName ( ) const

Returns the name of the node.

Returns
The node name.

◆ nodeRect()

QRectF NodeItem::nodeRect ( ) const
overridevirtual

Returns the bounding rectangle for this item.

Returns
The bounding rectangle.

Reimplemented from NodeBase.

◆ nodeType()

QString NodeItem::nodeType ( ) const

Returns the type of the node.

Returns
The node type.

◆ paint()

void NodeItem::paint ( QPainter * painter,
const QStyleOptionGraphicsItem * style,
QWidget * widget )
override

Paints the item using the given painter.

Parameters
painterThe painter to use for drawing.
styleThe style option for the graphics item.
widgetThe parent widget, if any.

◆ parentInnerSceneRect()

QRectF NodeItem::parentInnerSceneRect ( qreal padding) const
private

Returns the inner scene rectangle of the parent, optionally padded.

Parameters
paddingThe padding to apply.
Returns
The QRectF representing the inner scene rectangle.

◆ parentNode()

NodeItem * NodeItem::parentNode ( ) const

Returns the parent node of this item.

Returns
The parent NodeItem, if any.

◆ properties()

QVector< std::shared_ptr< IParameter > > NodeItem::properties ( ) const

Returns the properties of the node.

Returns
The QMap of property keys to QVariant values.

◆ removeField()

void NodeItem::removeField ( const QString & key)

Removes a field by key.

Parameters
keyThe property key to remove.

◆ renameNode()

void NodeItem::renameNode ( const QString & name)

Renames the node to a new name.

Parameters
nameThe new name for the node.

◆ saveInfo()

NodeSaveInfo NodeItem::saveInfo ( ) const

Returns the savable information for this node.

Returns
A NodeSaveInfo class populated with the information from this node

◆ setEvent()

void NodeItem::setEvent ( int index,
const FlowConfig & event )

Sets an event at the given index with the provided FlowConfig.

Parameters
indexThe index of the event.
eventThe FlowConfig object for the event.

◆ setField() [1/2]

VoidResult NodeItem::setField ( const QString & key,
const QJsonObject & property )

Sets a field with a given key and JSON object.

Parameters
keyThe property key.
propertyThe QJsonObject representing the property.
Returns
VoidResult indicating success or failure.

◆ setField() [2/2]

VoidResult NodeItem::setField ( const QString & key,
std::shared_ptr< PropertyInfo > property )

Sets a field with a given key and PropertyInfo object.

Parameters
keyThe property key.
propertyThe PropertyInfo object to set.
Returns
VoidResult indicating success or failure.

◆ setProperty()

void NodeItem::setProperty ( const QString & key,
const maki::Value & value )

Sets a property with a given key and value.

Parameters
keyThe property key.
valueThe new value for the property.

◆ shape()

QPainterPath NodeItem::shape ( ) const
override

Returns the shape of this item.

Returns
The QPainterPath representing the shape.

◆ start()

VoidResult NodeItem::start ( )
overridevirtual

Starts the node.

Returns
VoidResult indicating success or failure.

Reimplemented from NodeBase.

◆ type()

int NodeItem::type ( ) const
overridevirtual

Returns the type of this item.

Returns
The type of the item.

Reimplemented from NodeBase.

◆ updateExtrasPosition()

void NodeItem::updateExtrasPosition ( )
private

Size of the node when resizing started.

Updates extra positions related to this node.

◆ updatePosition()

void NodeItem::updatePosition ( const QPointF & position)

Updates the position of the node.

Parameters
positionThe new QPointF for the node's position.

◆ operator<<

QDataStream & operator<< ( QDataStream & out,
const NodeItem & config )
friend

Saves the state of this NodeItem to a QDataStream.

Parameters
outThe QDataStream to save to.
configThe NodeItem to save.
Returns
The modified QDataStream.

◆ operator>>

QDataStream & operator>> ( QDataStream & in,
NodeItem & config )
friend

Loads the state of a NodeItem from a QDataStream.

Parameters
inThe QDataStream to load from.
configThe NodeItem to load into.
Returns
The modified QDataStream.

The documentation for this class was generated from the following files:
  • /__w/maki/maki/app/elements/node.h
  • /__w/maki/maki/app/elements/node.cpp