5#include <QGraphicsEllipseItem>
6#include <QGraphicsItem>
10#include "control_widget.h"
16#include "transition.h"
18#include "widgets/controls/canvas_control_widget.h"
21class QGraphicsSceneMouseEvent;
22class QGraphicsSceneHoverEvent;
44 explicit NodeItem(
const QString&
id, std::shared_ptr<NodeSaveInfo> info,
const QPointF& initialPosition, std::shared_ptr<NodeConfig> nodeConfig,
45 QGraphicsItem* parent =
nullptr);
57 int type()
const override;
64 virtual VoidResult
start();
71 virtual QRectF
nodeRect()
const override;
72 QRectF sceneNodeRect()
const;
73 virtual QRectF sceneAlignRect()
const;
78 void hideControlOfType()
83 if (
auto control = qobject_cast<T*>(mControlWidget->controlWidget()); control && !mControlWidget->permanent())
87 void highlight(
const QColor& color,
const QString& message,
int durationMs = 1000);
88 void dismissHighlight();
90 void showSimulationControls(maki::ControlWidget*
controls,
const QColor& highlightColor);
92 void dismissControl();
100 virtual QPainterPath
shape()
const override;
109 virtual void paint(QPainter* painter,
const QStyleOptionGraphicsItem* style, QWidget* widget)
override;
144 QVector<ControlsConfig>
controls()
const;
151 QVector<std::shared_ptr<IParameter>>
properties()
const;
165 Types::LibraryTypes
function()
const;
181 virtual void setProperty(
const QString& key,
const maki::Value& value);
188 PortItem* getPort(Types::Port
type,
const QString& subFlowId = Constants::MAIN_SUB_FLOW)
const;
197 QString parentSubFlow()
const;
204 QVector<NodeItem*>
children(
const QString& subflow = Constants::MAIN_SUB_FLOW)
const;
219 QVector<std::shared_ptr<IParameter>>
fields()
const;
236 VoidResult
setField(
const QString& key,
const QJsonObject& property);
245 VoidResult
setField(
const QString& key, std::shared_ptr<PropertyInfo> property);
267 QVector<std::shared_ptr<IFlow>>
flowConfigs()
const;
269 QVector<std::shared_ptr<IFlow>> eventConfigs()
const;
271 QVector<std::shared_ptr<IFlow>> allEventFlowConfigs()
const;
302 std::vector<std::shared_ptr<Flow>>
flows()
const;
311 PFlow
createFlow(std::shared_ptr<FlowSaveInfo> info);
319 PFlow
getFlow(
const QString& flowId)
const;
347 virtual void applySize(
const QSizeF& size);
354 void updatePosition(
const QPointF& position, Config::NodeMove reason = Config::NodeMove::User);
356 QPointF centerPosition()
const;
357 void setCenterPosition(
const QPointF& center);
360 std::function<void(
NodeItem* item)> nodeModified;
361 std::function<void(PFlow flow,
NodeItem* item)> flowAdded;
362 std::function<void(
NodeItem* item,
bool done)> nodeMoved;
363 std::function<void(
NodeItem* item,
const QRectF& oldRect)> geometryChanged;
364 std::function<void(
NodeItem* item,
bool enter)> nodeHovered;
365 std::function<void(
NodeItem* item,
const QString& subflowId,
bool collapsed)> subflowCollapsed;
366 std::function<void(
NodeItem* node,
const QString&
nodeId,
const QString& flowId,
int type)> focusOn;
367 std::function<void(
NodeItem* item,
const QPointF& scenePos, maki::ControlWidget* control)> nodeControlRequested;
398 virtual QRectF childAreaSceneRect(
const QString& subflow = Constants::MAIN_SUB_FLOW)
const;
406 std::shared_ptr<NodeSaveInfo> mStorage;
414 bool operator==(
const PortKey& other)
const
416 return subFlowId == other.subFlowId && type == other.type;
419 friend size_t qHash(
const PortKey& key,
size_t seed = 0)
noexcept
421 seed = ::qHash(key.subFlowId, seed);
422 seed = ::qHash(
static_cast<int>(key.type), seed);
428 QHash<PortKey, PortItem*> mPorts;
430 virtual void createPorts();
432 virtual bool constrainChildren()
const;
433 virtual QPointF constrainChildPosition(
const NodeItem* child,
const QPointF& proposedPosition)
const;
456 void hoverEnterEvent(QGraphicsSceneHoverEvent* event)
override;
457 void hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
override;
459 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
override;
468 virtual QVariant
itemChange(GraphicsItemChange change,
const QVariant& value)
override;
470 void paintDefaultNode(QPainter* painter,
const QStyleOptionGraphicsItem* style, QWidget* widget);
472 bool isHovered()
const;
480 std::vector<std::shared_ptr<Flow>> mFlows;
485 bool mControlActive =
false;
486 bool mHovered =
false;
503 QSizeF
clampSize(qreal width, qreal height)
const;
512 QPointF
clampPosInside(
const QRectF& inner,
const QRectF& childSceneRect)
const;
Definition canvas_message.h:8
Configuration for a flow or process.
Definition config.h:70
Configuration for help information.
Definition config.h:174
virtual QString nodeId() const
Retrieves the identifier of the node within its type.
Definition node_base.cpp:49
std::shared_ptr< NodeConfig > config() const
Retrieves the configuration settings for the node.
Definition node_base.cpp:54
NodeBase(const QString &id, const QString &nodeId, std::shared_ptr< NodeConfig > config, QGraphicsItem *parent)
Constructs a new NodeBase instance.
Definition node_base.cpp:16
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Handles mouse release events for this item.
Definition node.cpp:727
Types::LibraryTypes function() const
Returns the library type associated with this node's function.
Definition node.cpp:92
int type() const override
Returns the type of this item.
Definition node.cpp:87
std::vector< std::shared_ptr< Flow > > flows() const
Returns a list of flows associated with this node.
Definition node.cpp:906
friend QDataStream & operator<<(QDataStream &out, const NodeItem &config)
Saves the state of this NodeItem to a QDataStream.
virtual void setProperty(const QString &key, const maki::Value &value)
Sets a property with a given key and value.
Definition node.cpp:422
friend QDataStream & operator>>(QDataStream &in, NodeItem &config)
Loads the state of a NodeItem from a QDataStream.
QSizeF mSize
Save information for the node.
Definition node.h:407
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
Handles changes to the item's properties.
Definition node.cpp:782
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Handles mouse press events for this item.
Definition node.cpp:710
void updatePosition(const QPointF &position, Config::NodeMove reason=Config::NodeMove::User)
Updates the position of the node.
Definition node.cpp:797
virtual void updateExtrasPosition(Config::NodeMove reason)
Updates extra positions related to this node.
Definition node.cpp:867
QVector< std::shared_ptr< IParameter > > fields() const
Returns a list of fields associated with this node.
Definition node.cpp:389
bool mIsResizing
Last known position of the node.
Definition node.h:492
CanvasMessage * mHighlightMessage
List of child nodes.
Definition node.h:483
QPointF edgePointToward(const QPointF &targetScenePos) const
Calculates an edge point toward a target scene position.
Definition node.cpp:887
QPointF mDragStartPos
Base scale for the node.
Definition node.h:489
QPointF mResizeStartMousePos
Flag indicating if the node is being resized.
Definition node.h:493
const PropertyInfo * getProperty(const QString &key) const
Gets a property by key.
Definition node.cpp:414
QString nodeName() const
Returns the name of the node.
Definition node.cpp:109
QVector< TransitionConfig > configTransitions() const
Returns a list of configured transitions.
Definition node.cpp:901
QPointF mLastPosition
Position where dragging started.
Definition node.h:490
virtual void applySize(const QSizeF &size)
Applies a new size to the node.
Definition node.cpp:595
void deleteFlow(const QString &flowId)
Deletes a flow by its ID.
Definition node.cpp:935
QPointF clampPosInside(const QRectF &inner, const QRectF &childSceneRect) const
Clamps a position inside an inner rectangle.
Definition node.cpp:616
PFlow getFlow(const QString &flowId) const
Gets a flow by its ID.
Definition node.cpp:926
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Handles mouse move events for this item.
Definition node.cpp:686
NodeItem * parentNode() const
Returns the parent node of this item.
Definition node.cpp:556
QSizeF clampSize(qreal width, qreal height) const
Size of the node when resizing started.
Definition node.cpp:634
PFlow createFlow(std::shared_ptr< FlowSaveInfo > info)
Creates a new flow with the given name and save information.
Definition node.cpp:911
HelpConfig help() const
Returns help configuration for this node.
Definition node.cpp:571
QVector< std::shared_ptr< IFlow > > flowConfigs() const
Returns a list of events associated with this node.
Definition node.cpp:399
QVector< NodeItem * > children(const QString &subflow=Constants::MAIN_SUB_FLOW) const
Returns a list of child nodes.
Definition node.cpp:510
virtual void childPositionUpdated(NodeItem *node)
Called to tell the parent that the position of this node was updated.
Definition node.cpp:829
QVector< NodeItem * > mChildrenNodes
Parent node of this item, if any.
Definition node.h:482
NodeItem * mParentNode
List of flows associated with this node.
Definition node.h:481
virtual void childRemoved(NodeItem *child)
Handles when a child is removed from this item.
Definition node.cpp:550
virtual void addParent(NodeItem *node, const QString &subflow)
Adds a parent node to this item.
Definition node.cpp:515
QString behaviour() const
Returns the behavior of the node.
Definition node.cpp:566
VoidResult setField(const QString &key, const QJsonObject &property)
Sets a field with a given key and JSON object.
Definition node.cpp:474
virtual void addChild(NodeItem *node, std::shared_ptr< NodeSaveInfo > info)
Adds a child node with the given save information.
Definition node.cpp:541
void removeField(const QString &key)
Removes a field by key.
Definition node.cpp:502
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.
Definition node.cpp:29
qreal baseScale() const
Returns the base scale for this node.
Definition node.cpp:123
QVector< ControlsConfig > controls() const
Returns the controls configuration for this node.
Definition node.cpp:409
QSizeF mResizeStartSize
Mouse position when resizing started.
Definition node.h:494
QString nodeType() const
Returns the type of the node.
Definition node.cpp:117
void setEvent(int index, const FlowConfig &event)
Sets an event at the given index with the provided FlowConfig.
Definition node.cpp:463
QVector< PropertyConfig > configurationProperties() const
Returns the configuration properties of the node.
Definition node.cpp:379
NodeSaveInfo saveInfo() const
Returns the savable information for this node.
Definition node.cpp:882
void fitInsideParent(qreal padding)
Fits this node inside its parent with optional padding.
Definition node.cpp:657
virtual QRectF nodeRect() const override
Returns the bounding rectangle for this item.
Definition node.cpp:135
QRectF parentInnerSceneRect(qreal padding) const
Returns the inner scene rectangle of the parent, optionally padded.
Definition node.cpp:586
QVector< std::shared_ptr< IParameter > > properties() const
Returns the properties of the node.
Definition node.cpp:384
virtual QPainterPath shape() const override
Returns the shape of this item.
Definition node.cpp:369
virtual VoidResult start()
Starts the node.
Definition node.cpp:128
void renameNode()
Renames the node to a new name.
Definition node.cpp:437
PropertyInfo getField(const QString &key) const
Gets a property info by key.
Definition node.cpp:494
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *style, QWidget *widget) override
Paints the item using the given painter.
Definition node.cpp:364
Represents a node that can be saved and loaded.
Definition node_info.h:16
Represents a property with configuration and options.
Definition property_info.h:16
Definition canvas_control_widget.h:25
Current size of the node.
Definition node.h:410