Maki
Formally verified low-code orchestration
Loading...
Searching...
No Matches

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
struct  LayoutScope

Public Slots

void focusOnNode (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 (const QString &nodeId, bool selected)
 Emitted when a node is selected.
void nodeAdded (Canvas *canvas, NodeItem *node)
 Emitted when a node is added.
void nodeRemoved (Canvas *canvas, const QString &nodeId, const QString &parentId)
 Emitted when a node is removed.
void nodeModified (Canvas *canvas, const QString &nodeId)
 Emitted when a node is modified.
void transitionSelected (TransitionItem *transtion)
 Emitted when a transition is selected.
void createEvent (const QString &nodeId)
 Emitted when an event is created.
void openFlow (std::shared_ptr< FlowSaveInfo > flow, const QString &nodeId, const maki::FocusProperties &properties)
 Emitted when a flow is opened.
void focusOn (const QString &flowId, const QString &nodeId, const maki::FocusProperties &properties)
 Emitted when the user requests to focus on a node from the Canvas.
void flowAdded (const QString &flowId, const QString &nodeId)
 Emitted when a flow is added.
void flowRemoved (const QString &flowId, const QString &nodeId)
 Emitted when a flow is removed.

Public Member Functions

 Canvas (const QString &canvasId, 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.
void centerOnNodes ()
 Centers the canvas so the nodes are distributed.
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 settingsChanged (const AppearanceSettings &appearance)
 Handles settings change events.
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 materializeTransition (std::shared_ptr< TransitionSaveInfo > info)
 Creates a transition based on save information.
virtual 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.
std::pair< NodeItem *, PFlow > getFlow (const QString &flowId) const
 Returns a pointer to the flow if it exists;.
NodeItem * findNodeWithId (const QString &id) const
 Finds a node by its ID.

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.
CanvasView * parentView () const
 Returns the parent view of this canvas.

Protected Attributes

QUndoStack * mUndoStack = nullptr
 Pointer to the system edge router.
EventDispatcher< DocumentEvent >::Subscription mDocumentSubscription
 Pointer to the undo stack.

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.
QList< NodeItem * > selectedNodes () const
 Returns a list of currently selected nodes.
QVector< QGraphicsItem * > removeNode (NodeItem *node)
 Creates a context menu for alignment options.
void clearSelectedNodes ()
 Removes a node and its associated connections.
void clearNodeControls ()
 Clears all selected nodes.
bool isModifierSet (QGraphicsSceneMouseEvent *event, Qt::KeyboardModifier modifier)
 Clears all the active node controls.
bool nodeClickHandler (QGraphicsSceneMouseEvent *event, QGraphicsItem *item)
 Checks if a specific keyboard modifier is set.
bool transitionClickHandler (QGraphicsSceneMouseEvent *event, QGraphicsItem *item)
 Handles node click events.
bool beginTransitionFromOutPort (PortItem *port, const QPointF &cursorScenePos)
 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, const 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< 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.

◆ 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 ( const QString & nodeId)
signal

Emitted when an event is created.

Parameters
nodePointer to the node where the event is created.

◆ 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

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 ( const QString & flowId,
const QString & nodeId )
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,
const QString & nodeId )
signal

Emitted when a flow is removed.

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

◆ focusOn

void Canvas::focusOn ( const QString & flowId,
const QString & nodeId,
const maki::FocusProperties & properties )
signal

Emitted when the user requests to focus on a node from the Canvas.

Parameters
flowIdId of the flow.
nodeIdId of the flow owner.
propertiesThe focus properties.

◆ focusOnNode

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

Handles focus on a node.

Parameters
nodeIdThe ID of the focused node.

◆ 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.

◆ materializeTransition()

void Canvas::materializeTransition ( std::shared_ptr< TransitionSaveInfo > info)

Creates a transition based on save information.

Parameters
infoThe save information for the transition.

◆ 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 ( Canvas * canvas,
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 ( Canvas * canvas,
const QString & nodeId )
signal

Emitted when a node is modified.

Parameters
nodePointer to the modified node.

◆ nodeRemoved

void Canvas::nodeRemoved ( Canvas * canvas,
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 ( const QString & nodeId,
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.

◆ 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 ( std::shared_ptr< FlowSaveInfo > 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)
virtual

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.

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