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

The Canvas class represents the main drawing area for nodes and transitions. More...

#include <canvas.h>

Inheritance diagram for Canvas:
BehaviourCanvas StructureCanvas PipelineCanvas

Classes

struct  CopiedNode

Public Slots

void onFocusNode (const QString &flowId, const QString &nodeId, const maki::FocusProperties &properties)
 Handles focus on a node.
void onRemoveNode (const QString &flowId, const QString &nodeId)
 Handles removal of a node.
void onFlowSelected (const QString &flowId, const QString &nodeId)
 Handles selection of a flow.
void onFlowRemoved (const QString &flowId, const QString &nodeId)
 Handles removal of a flow.

Signals

void nodeSelected (NodeItem *node, bool selected)
 Emitted when a node is selected.
void nodeAdded (NodeItem *node)
 Emitted when a node is added.
void nodeRemoved (const QString &nodeId, const QString &parentId)
 Emitted when a node is removed.
void nodeModified (NodeItem *node)
 Emitted when a node is modified.
void transitionSelected (TransitionItem *transtion)
 Emitted when a transition is selected.
void createEvent (NodeItem *node)
 Emitted when an event is created.
void openFlow (Flow *flow, const QString &nodeId, const maki::FocusProperties &properties)
 Emitted when a flow is opened.
void flowAdded (Flow *flow, NodeItem *node)
 Emitted when a flow is added.
void flowRemoved (const QString &flowId, NodeItem *node)
 Emitted when a flow is removed.

Public Member Functions

 Canvas (const QString &canvasId, std::shared_ptr< ConfigurationTable > configTable, std::shared_ptr< EdgeRouter > router, QObject *parent=nullptr)
 Constructs a new Canvas object.
QString id () const
 Returns the unique identifier for this canvas.
void pasteCopiedItems ()
 Pastes copied items onto the canvas.
void copySelectedItems (NodeItem *node)
 Copies selected items to the clipboard.
void deleteSelectedItems ()
 Deletes selected items from the canvas.
qreal getScale () const
 Returns the current scale of the canvas.
QPointF getCenter () const
 Returns the center position of the canvas.
VoidResult loadFromSave (const SaveInfo &info)
 Loads the canvas from save information.
QList< NodeItem * > availableNodes ()
 Returns a list of available node items.
virtual Types::LibraryTypes type () const
 Returns the type of library this canvas belongs to.
QUndoStack * undoStack () const
 Returns a pointer to the undo stack associated with this canvas.
void nodeClicked (NodeItem *node)
 Handles node click events.
void populate (const FlowSaveInfo &flow)
 Populates the canvas with a given flow.
void themeChanged ()
 Handles theme change events.
void createNode (const NodeSaveInfo &info, NodeCreation creation)
 Creates a node based on save information.
void removeNode (const NodeSaveInfo &info)
 Removes a node based on save information.
void moveNodeTo (const QString &nodeId, const QPointF &position)
 Moves a node to a new position.
void setNodeSize (const QString &nodeId, const QSizeF &size)
 Sets the size of a node.
void createTransition (const TransitionSaveInfo &info)
 Creates a transition based on save information.
void removeTransition (const TransitionSaveInfo &info)
 Removes a transition based on save information.
void requestAlignNodes (const QList< Types::AlignmentNode > &items, Types::AlignmentMode mode, Types::AlignmentDirection direction)
 Requests alignment of nodes.
void alignNodes (const QList< Types::AlignmentNode > &items, Types::AlignmentMode mode, Types::AlignmentDirection direction, bool useGiven)
 Aligns nodes based on the given parameters.

Protected Member Functions

void dragEnterEvent (QGraphicsSceneDragDropEvent *event) override
 Handles drag enter events.
void dragMoveEvent (QGraphicsSceneDragDropEvent *event) override
 Handles drag move events.
void dropEvent (QGraphicsSceneDragDropEvent *event) override
 Handles drop events.
void mousePressEvent (QGraphicsSceneMouseEvent *event) override
 Handles mouse press events.
void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override
 Handles mouse move events.
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override
 Handles mouse release events.
void contextMenuEvent (QGraphicsSceneContextMenuEvent *event) override
 Handles context menu events.
virtual void updateParent (NodeItem *node, std::shared_ptr< NodeSaveInfo > storage, bool adding)
 Updates the parent of a node.
std::shared_ptr< NodeConfig > getNodeConfig (const QString &key) const
 Pointer to the undo stack.
NodeItem * createNode (NodeCreation creation, std::shared_ptr< NodeSaveInfo > info, const QPointF &position, NodeItem *parent)
 Creates a new node based on save information and other parameters.
CanvasView * parentView () const
 Returns the parent view of this canvas.

Protected Attributes

std::shared_ptr< EdgeRouter > mRouter
 Pointer to the configuration table.
QUndoStack * mUndoStack = nullptr
 Pointer to the system edge router.

Private Member Functions

void clearCanvas ()
 Clears all items from the canvas.
void selectNode (NodeItem *node, bool select)
 Selects a node and updates its selection state.
NodeItem * findNodeWithId (const QString &id) const
 Finds a node by its ID.
QList< NodeItem * > selectedNodes () const
 Returns a list of currently selected nodes.
void alignNodesHorizontally (const QList< Types::AlignmentNode > &items, Types::AlignmentDirection direction)
 Aligns nodes horizontally based on the given parameters.
void alignNodesVertically (const QList< Types::AlignmentNode > &items, Types::AlignmentDirection direction)
 Aligns nodes vertically based on the given parameters.
QVector< QGraphicsItem * > removeNode (NodeItem *node)
 Creates a context menu for alignment options.
void clearSelectedNodes ()
 Removes a node and its associated connections.
bool isModifierSet (QGraphicsSceneMouseEvent *event, Qt::KeyboardModifier modifier)
 Clears all selected nodes.
bool nodeClickHandler (QGraphicsSceneMouseEvent *event, QGraphicsItem *item)
 Checks if a specific keyboard modifier is set.
bool transitionClickHandler (QGraphicsSceneMouseEvent *event, QGraphicsItem *item)
 Handles node click events.
void createNodeContextMenu (QMenu *menu, NodeItem *node, const QList< NodeItem * > &items)
 Handles transition click events.
void createTransitionContextMenu (QMenu *menu, const QList< NodeItem * > &items)
 Creates a context menu for nodes.
bool isParentSelected (NodeItem *node)
 Creates a context menu for transitions.
void pasteCopiedItems (const QPointF &mousePosition, NodeItem *parentNode, QList< CopiedNode > nodes, bool relative)
 Checks if the parent of a node is selected.
VoidResult loadFromSave (const QVector< std::shared_ptr< INode > > &nodes, NodeItem *parent)
 Pastes copied items at a specified position.
void onSelectionChanged ()
 Loads nodes and their children from save information.

Private Attributes

TransitionItem * mTransition = nullptr
 Pointer to the hovered node.
NodeItem * mNode = nullptr
 Pointer to the current transition being created.
QPointF mStartDragPosition
 Pointer to the currently clicked node.
bool mDragging = false
 The starting position of a drag operation.
bool mMouseDown = false
 Whether a drag operation is in progress.
QPointF mSelectionStart
 Whether the mouse button is pressed.
QList< CopiedNode > mCopiedNodes
 Unique identifier for this canvas.
QList< NodeItem * > mSelectedNodes
 List of copied nodes.
NodeItem * mSuggestionSourceNode = nullptr
 List of currently selected nodes.

Detailed Description

The Canvas class represents the main drawing area for nodes and transitions.

Constructor & Destructor Documentation

◆ Canvas()

Canvas::Canvas ( const QString & canvasId,
std::shared_ptr< ConfigurationTable > configTable,
std::shared_ptr< EdgeRouter > router,
QObject * parent = nullptr )

Constructs a new Canvas object.

Parameters
canvasIdThe unique identifier for this canvas.
storageShared pointer to the save information.
configTableShared pointer to the configuration table.
parentPointer to the parent object.

Member Function Documentation

◆ alignNodes()

void Canvas::alignNodes ( const QList< Types::AlignmentNode > & items,
Types::AlignmentMode mode,
Types::AlignmentDirection direction,
bool useGiven )

Aligns nodes based on the given parameters.

Parameters
itemsList of alignment nodes.
modeThe alignment mode.
directionThe alignment direction.
useGivenWhether to use the given positions for alignment.

◆ alignNodesHorizontally()

void Canvas::alignNodesHorizontally ( const QList< Types::AlignmentNode > & items,
Types::AlignmentDirection direction )
private

Aligns nodes horizontally based on the given parameters.

Parameters
itemsList of alignment nodes.
directionThe alignment direction.

◆ alignNodesVertically()

void Canvas::alignNodesVertically ( const QList< Types::AlignmentNode > & items,
Types::AlignmentDirection direction )
private

Aligns nodes vertically based on the given parameters.

Parameters
itemsList of alignment nodes.
directionThe alignment direction.

◆ availableNodes()

QList< NodeItem * > Canvas::availableNodes ( )

Returns a list of available node items.

Returns
List of NodeItem pointers.

◆ contextMenuEvent()

void Canvas::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event)
overrideprotected

Handles context menu events.

Parameters
eventPointer to the QGraphicsSceneContextMenuEvent.

◆ copySelectedItems()

void Canvas::copySelectedItems ( NodeItem * node)

Copies selected items to the clipboard.

Parameters
nodePointer to the clicked node, if any.

◆ createEvent

void Canvas::createEvent ( NodeItem * node)
signal

Emitted when an event is created.

Parameters
nodePointer to the node where the event is created.

◆ createNode() [1/2]

void Canvas::createNode ( const NodeSaveInfo & info,
NodeCreation creation )

Creates a node based on save information.

Parameters
infoThe save information for the node.

◆ createNode() [2/2]

NodeItem * Canvas::createNode ( NodeCreation creation,
std::shared_ptr< NodeSaveInfo > info,
const QPointF & position,
NodeItem * parent )
protected

Creates a new node based on save information and other parameters.

Parameters
creationThe type of node creation (e.g., dropping, pasting).
infoShared pointer to the save information for the node.
positionThe initial position of the node.
parentPointer to the parent node.
Returns
Pointer to the created NodeItem.

◆ createTransition()

void Canvas::createTransition ( const TransitionSaveInfo & info)

Creates a transition based on save information.

Parameters
infoThe save information for the transition.

◆ dragEnterEvent()

void Canvas::dragEnterEvent ( QGraphicsSceneDragDropEvent * event)
overrideprotected

Handles drag enter events.

Parameters
eventPointer to the QGraphicsSceneDragDropEvent.

◆ dragMoveEvent()

void Canvas::dragMoveEvent ( QGraphicsSceneDragDropEvent * event)
overrideprotected

Handles drag move events.

Parameters
eventPointer to the QGraphicsSceneDragDropEvent.

◆ dropEvent()

void Canvas::dropEvent ( QGraphicsSceneDragDropEvent * event)
overrideprotected

Handles drop events.

Parameters
eventPointer to the QGraphicsSceneDragDropEvent.

◆ findNodeWithId()

NodeItem * Canvas::findNodeWithId ( const QString & id) const
private

Finds a node by its ID.

Parameters
idThe ID of the node to find.
Returns
Pointer to the found NodeItem, or nullptr if not found.

◆ flowAdded

void Canvas::flowAdded ( Flow * flow,
NodeItem * node )
signal

Emitted when a flow is added.

Parameters
flowPointer to the added flow.
nodePointer to the node associated with the flow.

◆ flowRemoved

void Canvas::flowRemoved ( const QString & flowId,
NodeItem * node )
signal

Emitted when a flow is removed.

Parameters
flowIdThe ID of the removed flow.
nodeIdThe ID of the node associated with the flow.

◆ getCenter()

QPointF Canvas::getCenter ( ) const

Returns the center position of the canvas.

Returns
The center position as a QPointF.

◆ getScale()

qreal Canvas::getScale ( ) const

Returns the current scale of the canvas.

Returns
The scale value.

◆ id()

QString Canvas::id ( ) const

Returns the unique identifier for this canvas.

Returns
The canvas ID.

◆ loadFromSave()

VoidResult Canvas::loadFromSave ( const SaveInfo & info)

Loads the canvas from save information.

Parameters
infoThe save information to load.
Returns
VoidResult indicating success or failure.

◆ mouseMoveEvent()

void Canvas::mouseMoveEvent ( QGraphicsSceneMouseEvent * event)
overrideprotected

Handles mouse move events.

Parameters
eventPointer to the QGraphicsSceneMouseEvent.

◆ mousePressEvent()

void Canvas::mousePressEvent ( QGraphicsSceneMouseEvent * event)
overrideprotected

Handles mouse press events.

Parameters
eventPointer to the QGraphicsSceneMouseEvent.

◆ mouseReleaseEvent()

void Canvas::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event)
overrideprotected

Handles mouse release events.

Parameters
eventPointer to the QGraphicsSceneMouseEvent.

◆ moveNodeTo()

void Canvas::moveNodeTo ( const QString & nodeId,
const QPointF & position )

Moves a node to a new position.

Parameters
nodeIdThe ID of the node to move.
positionThe new position for the node.

◆ nodeAdded

void Canvas::nodeAdded ( NodeItem * node)
signal

Emitted when a node is added.

Parameters
nodePointer to the added node.

◆ nodeClicked()

void Canvas::nodeClicked ( NodeItem * node)

Handles node click events.

Parameters
nodePointer to the clicked node.

◆ nodeModified

void Canvas::nodeModified ( NodeItem * node)
signal

Emitted when a node is modified.

Parameters
nodePointer to the modified node.

◆ nodeRemoved

void Canvas::nodeRemoved ( const QString & nodeId,
const QString & parentId )
signal

Emitted when a node is removed.

Parameters
nodeIdThe ID of the removed node.
parentIdThe ID of the parent node.

◆ nodeSelected

void Canvas::nodeSelected ( NodeItem * node,
bool selected )
signal

Emitted when a node is selected.

Parameters
nodePointer to the selected node.
selectedWhether the node is selected or not.

◆ onFlowRemoved

void Canvas::onFlowRemoved ( const QString & flowId,
const QString & nodeId )
slot

Handles removal of a flow.

Parameters
flowIdThe ID of the removed flow.
nodeIdThe ID of the node associated with the flow.

◆ onFlowSelected

void Canvas::onFlowSelected ( const QString & flowId,
const QString & nodeId )
slot

Handles selection of a flow.

Parameters
flowIdThe ID of the selected flow.
nodeIdThe ID of the node associated with the flow.

◆ onFocusNode

void Canvas::onFocusNode ( const QString & flowId,
const QString & nodeId,
const maki::FocusProperties & properties )
slot

Handles focus on a node.

Parameters
flowIdThe ID of the flow that contains the given node.
nodeIdThe ID of the focused node.

◆ onRemoveNode

void Canvas::onRemoveNode ( const QString & flowId,
const QString & nodeId )
slot

Handles removal of a node.

Parameters
nodeIdThe ID of the node to remove.

◆ openFlow

void Canvas::openFlow ( Flow * flow,
const QString & nodeId,
const maki::FocusProperties & properties )
signal

Emitted when a flow is opened.

Parameters
flowPointer to the opened flow.
nodePointer to the node associated with the flow.

◆ parentView()

CanvasView * Canvas::parentView ( ) const
protected

Returns the parent view of this canvas.

Returns
Pointer to CanvasView.

◆ populate()

void Canvas::populate ( const FlowSaveInfo & flow)

Populates the canvas with a given flow.

Parameters
flowPointer to the flow to populate.

◆ removeNode()

void Canvas::removeNode ( const NodeSaveInfo & info)

Removes a node based on save information.

Parameters
infoThe save information for the node.

◆ removeTransition()

void Canvas::removeTransition ( const TransitionSaveInfo & info)

Removes a transition based on save information.

Parameters
infoThe save information for the transition.

◆ requestAlignNodes()

void Canvas::requestAlignNodes ( const QList< Types::AlignmentNode > & items,
Types::AlignmentMode mode,
Types::AlignmentDirection direction )

Requests alignment of nodes.

Parameters
itemsList of alignment nodes.
modeThe alignment mode.
directionThe alignment direction.

◆ selectedNodes()

QList< NodeItem * > Canvas::selectedNodes ( ) const
private

Returns a list of currently selected nodes.

Returns
List of NodeItem pointers.

◆ selectNode()

void Canvas::selectNode ( NodeItem * node,
bool select )
private

Selects a node and updates its selection state.

Parameters
nodePointer to the node to select.
selectWhether to select or deselect the node.

◆ setNodeSize()

void Canvas::setNodeSize ( const QString & nodeId,
const QSizeF & size )

Sets the size of a node.

Parameters
nodeIdThe ID of the node to resize.
sizeThe new size for the node.

◆ transitionSelected

void Canvas::transitionSelected ( TransitionItem * transtion)
signal

Emitted when a transition is selected.

Parameters
transtionPointer to the selected transition.

◆ type()

Types::LibraryTypes Canvas::type ( ) const
virtual

Returns the type of library this canvas belongs to.

Returns
The library type as Types::LibraryTypes.

Reimplemented in BehaviourCanvas, PipelineCanvas, and StructureCanvas.

◆ undoStack()

QUndoStack * Canvas::undoStack ( ) const

Returns a pointer to the undo stack associated with this canvas.

Returns
Pointer to QUndoStack.

◆ updateParent()

void Canvas::updateParent ( NodeItem * node,
std::shared_ptr< NodeSaveInfo > storage,
bool adding )
protectedvirtual

Updates the parent of a node.

Parameters
nodePointer to the node.
storageShared pointer to the save information.
addingWhether this is an addition or removal.

Reimplemented in BehaviourCanvas, and StructureCanvas.


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