16 #ifndef QGSMODELCOMPONENTGRAPHICITEM_H
17 #define QGSMODELCOMPONENTGRAPHICITEM_H
21 #include <QGraphicsObject>
26 class QgsProcessingModelComponent;
27 class QgsProcessingModelParameter;
28 class QgsProcessingModelChildAlgorithm;
29 class QgsProcessingModelOutput;
30 class QgsProcessingModelComment;
31 class QgsProcessingModelAlgorithm;
32 class QgsModelDesignerFlatButtonGraphicItem;
33 class QgsModelDesignerFoldButtonGraphicItem;
34 class QgsModelGraphicsView;
36 class QgsProcessingModelGroupBox;
46 class GUI_EXPORT QgsModelComponentGraphicItem :
public QGraphicsObject
64 Q_DECLARE_FLAGS( Flags, Flag )
74 QgsModelComponentGraphicItem( QgsProcessingModelComponent *component
SIP_TRANSFER,
75 QgsProcessingModelAlgorithm *model,
78 ~QgsModelComponentGraphicItem()
override;
83 virtual Flags flags()
const;
88 QgsProcessingModelComponent *component();
93 const QgsProcessingModelComponent *component() const
SIP_SKIP;
98 QgsProcessingModelAlgorithm *model();
103 QgsModelGraphicsView *view();
115 void setFont( const QFont &font );
122 void moveComponentBy( qreal dx, qreal dy );
127 void previewItemMove( qreal dx, qreal dy );
132 void setItemRect( QRectF rect );
139 QRectF previewItemRectChange( QRectF rect );
144 void finalizePreviewedItemRectChange( QRectF rect );
166 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event )
override;
167 void hoverEnterEvent( QGraphicsSceneHoverEvent *event )
override;
168 void hoverMoveEvent( QGraphicsSceneHoverEvent *event )
override;
169 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event )
override;
170 QVariant itemChange( GraphicsItemChange change,
const QVariant &value )
override;
171 QRectF boundingRect()
const override;
172 bool contains(
const QPointF &point )
const override;
173 void paint( QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget =
nullptr )
override;
178 QRectF itemRect(
bool storedRect =
false )
const;
185 QString label()
const;
192 void setLabel(
const QString &label );
202 virtual int linkPointCount( Qt::Edge edge )
const;
207 virtual QString linkPointText( Qt::Edge edge,
int index )
const;
212 QPointF linkPoint( Qt::Edge edge,
int index,
bool incoming )
const;
221 QPointF calculateAutomaticLinkPoint( QgsModelComponentGraphicItem *other, Qt::Edge &edge
SIP_OUT )
const;
230 QPointF calculateAutomaticLinkPoint(
const QPointF &point, Qt::Edge &edge
SIP_OUT )
const;
237 virtual void editComment() {}
242 virtual bool canDeleteComponent() {
return false; }
249 virtual void deleteComponent() {}
258 void requestModelRepaint();
267 void aboutToChange(
const QString &text,
int id = 0 );
278 void repaintArrows();
283 void updateArrowPaths();
288 void sizePositionChanged();
297 virtual void editComponent() {}
305 QString truncatedTextForItem(
const QString &text )
const;
310 virtual QColor fillColor( State state )
const = 0;
315 virtual QColor strokeColor( State state )
const = 0;
320 virtual QColor textColor( State state )
const = 0;
325 virtual Qt::PenStyle strokeStyle( State state )
const;
330 virtual Qt::Alignment titleAlignment()
const;
335 virtual QPicture iconPicture()
const;
340 virtual QPixmap iconPixmap()
const;
345 virtual void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size ) = 0;
350 void updateButtonPositions();
354 QSizeF itemSize()
const;
356 void updateToolTip(
const QPointF &pos );
358 void fold( Qt::Edge edge,
bool folded );
360 std::unique_ptr< QgsProcessingModelComponent > mComponent;
361 QgsProcessingModelAlgorithm *mModel =
nullptr;
363 bool mInitialized =
false;
364 QgsModelDesignerFoldButtonGraphicItem *mExpandTopButton =
nullptr;
365 QgsModelDesignerFoldButtonGraphicItem *mExpandBottomButton =
nullptr;
369 QgsModelDesignerFlatButtonGraphicItem *mEditButton =
nullptr;
370 QgsModelDesignerFlatButtonGraphicItem *mDeleteButton =
nullptr;
372 static constexpr
double MIN_COMPONENT_WIDTH = 70;
373 static constexpr
double MIN_COMPONENT_HEIGHT = 30;
375 static constexpr
double DEFAULT_BUTTON_WIDTH = 16;
376 static constexpr
double DEFAULT_BUTTON_HEIGHT = 16;
377 static constexpr
double BUTTON_MARGIN = 2;
378 static constexpr
double TEXT_MARGIN = 4;
379 static constexpr
double RECT_PEN_SIZE = 2;
380 QSizeF mButtonSize { DEFAULT_BUTTON_WIDTH, DEFAULT_BUTTON_HEIGHT };
384 bool mIsHovering =
false;
385 bool mIsMoving =
false;
397 class GUI_EXPORT QgsModelParameterGraphicItem :
public QgsModelComponentGraphicItem
411 QgsModelParameterGraphicItem( QgsProcessingModelParameter *parameter
SIP_TRANSFER,
412 QgsProcessingModelAlgorithm *model,
415 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
416 bool canDeleteComponent()
override;
420 QColor fillColor( State state )
const override;
421 QColor strokeColor( State state )
const override;
422 QColor textColor( State state )
const override;
423 QPicture iconPicture()
const override;
424 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
428 void deleteComponent()
override;
441 class GUI_EXPORT QgsModelChildAlgorithmGraphicItem :
public QgsModelComponentGraphicItem
455 QgsModelChildAlgorithmGraphicItem( QgsProcessingModelChildAlgorithm *child
SIP_TRANSFER,
456 QgsProcessingModelAlgorithm *model,
458 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
459 bool canDeleteComponent()
override;
464 void setResults(
const QVariantMap &results );
469 void setInputs(
const QVariantMap &inputs );
473 QColor fillColor( State state )
const override;
474 QColor strokeColor( State state )
const override;
475 QColor textColor( State state )
const override;
476 QPixmap iconPixmap()
const override;
477 QPicture iconPicture()
const override;
479 int linkPointCount( Qt::Edge edge )
const override;
480 QString linkPointText( Qt::Edge edge,
int index )
const override;
481 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
485 void deleteComponent()
override;
488 void deactivateAlgorithm();
489 void activateAlgorithm();
494 QVariantMap mResults;
496 bool mIsValid =
true;
506 class GUI_EXPORT QgsModelOutputGraphicItem :
public QgsModelComponentGraphicItem
520 QgsModelOutputGraphicItem( QgsProcessingModelOutput *output
SIP_TRANSFER,
521 QgsProcessingModelAlgorithm *model,
524 bool canDeleteComponent()
override;
528 QColor fillColor( State state )
const override;
529 QColor strokeColor( State state )
const override;
530 QColor textColor( State state )
const override;
531 QPicture iconPicture()
const override;
532 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
536 void deleteComponent()
override;
551 class GUI_EXPORT QgsModelCommentGraphicItem :
public QgsModelComponentGraphicItem
565 QgsModelCommentGraphicItem( QgsProcessingModelComment *comment
SIP_TRANSFER,
566 QgsModelComponentGraphicItem *parentItem,
567 QgsProcessingModelAlgorithm *model,
569 ~QgsModelCommentGraphicItem()
override;
570 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
571 bool canDeleteComponent()
override;
576 QgsModelComponentGraphicItem *parentComponentItem()
const;
580 QColor fillColor( State state )
const override;
581 QColor strokeColor( State state )
const override;
582 QColor textColor( State state )
const override;
583 Qt::PenStyle strokeStyle( State state )
const override;
584 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
588 void deleteComponent()
override;
589 void editComponent()
override;
592 QgsProcessingModelComment *modelComponent();
594 std::unique_ptr< QgsProcessingModelComponent > mParentComponent;
595 QPointer< QgsModelComponentGraphicItem > mParentItem;
607 class GUI_EXPORT QgsModelGroupBoxGraphicItem :
public QgsModelComponentGraphicItem
621 QgsModelGroupBoxGraphicItem( QgsProcessingModelGroupBox *box
SIP_TRANSFER,
622 QgsProcessingModelAlgorithm *model,
624 ~QgsModelGroupBoxGraphicItem()
override;
625 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
626 bool canDeleteComponent()
override;
629 QColor fillColor( State state )
const override;
630 QColor strokeColor( State state )
const override;
631 QColor textColor( State state )
const override;
632 Qt::PenStyle strokeStyle( State state )
const override;
633 Qt::Alignment titleAlignment()
const override;
634 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
638 void deleteComponent()
override;
639 void editComponent()
override;
647 #endif // QGSMODELCOMPONENTGRAPHICITEM_H