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
66 Q_DECLARE_FLAGS( Flags, Flag )
76 QgsModelComponentGraphicItem( QgsProcessingModelComponent *component
SIP_TRANSFER,
77 QgsProcessingModelAlgorithm *model,
80 ~QgsModelComponentGraphicItem()
override;
85 virtual Flags flags()
const;
90 QgsProcessingModelComponent *component();
95 const QgsProcessingModelComponent *component() const
SIP_SKIP;
100 QgsProcessingModelAlgorithm *model();
105 QgsModelGraphicsView *view();
117 void setFont( const QFont &font );
124 void moveComponentBy( qreal dx, qreal dy );
129 void previewItemMove( qreal dx, qreal dy );
134 void setItemRect( QRectF rect );
141 QRectF previewItemRectChange( QRectF rect );
146 void finalizePreviewedItemRectChange( QRectF rect );
168 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event )
override;
169 void hoverEnterEvent( QGraphicsSceneHoverEvent *event )
override;
170 void hoverMoveEvent( QGraphicsSceneHoverEvent *event )
override;
171 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event )
override;
172 QVariant itemChange( GraphicsItemChange change,
const QVariant &value )
override;
173 QRectF boundingRect()
const override;
174 bool contains(
const QPointF &point )
const override;
175 void paint( QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget =
nullptr )
override;
180 QRectF itemRect(
bool storedRect =
false )
const;
187 QString label()
const;
194 void setLabel(
const QString &label );
204 virtual int linkPointCount( Qt::Edge edge )
const;
209 virtual QString linkPointText( Qt::Edge edge,
int index )
const;
214 QPointF linkPoint( Qt::Edge edge,
int index,
bool incoming )
const;
223 QPointF calculateAutomaticLinkPoint( QgsModelComponentGraphicItem *other, Qt::Edge &edge
SIP_OUT )
const;
232 QPointF calculateAutomaticLinkPoint(
const QPointF &point, Qt::Edge &edge
SIP_OUT )
const;
239 virtual void editComment() {}
244 virtual bool canDeleteComponent() {
return false; }
251 virtual void deleteComponent() {}
260 void requestModelRepaint();
269 void aboutToChange(
const QString &text,
int id = 0 );
280 void repaintArrows();
285 void updateArrowPaths();
290 void sizePositionChanged();
299 virtual void editComponent() {}
307 QString truncatedTextForItem(
const QString &text )
const;
312 virtual QColor fillColor( State state )
const = 0;
317 virtual QColor strokeColor( State state )
const = 0;
322 virtual QColor textColor( State state )
const = 0;
327 virtual Qt::PenStyle strokeStyle( State state )
const;
332 virtual Qt::Alignment titleAlignment()
const;
337 virtual QPicture iconPicture()
const;
342 virtual QPixmap iconPixmap()
const;
347 virtual void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size ) = 0;
352 void updateButtonPositions();
356 QSizeF itemSize()
const;
358 void updateToolTip(
const QPointF &pos );
360 void fold( Qt::Edge edge,
bool folded );
362 std::unique_ptr< QgsProcessingModelComponent > mComponent;
363 QgsProcessingModelAlgorithm *mModel =
nullptr;
365 bool mInitialized =
false;
366 QgsModelDesignerFoldButtonGraphicItem *mExpandTopButton =
nullptr;
367 QgsModelDesignerFoldButtonGraphicItem *mExpandBottomButton =
nullptr;
371 QgsModelDesignerFlatButtonGraphicItem *mEditButton =
nullptr;
372 QgsModelDesignerFlatButtonGraphicItem *mDeleteButton =
nullptr;
374 static constexpr
double MIN_COMPONENT_WIDTH = 70;
375 static constexpr
double MIN_COMPONENT_HEIGHT = 30;
377 static constexpr
double DEFAULT_BUTTON_WIDTH = 16;
378 static constexpr
double DEFAULT_BUTTON_HEIGHT = 16;
379 static constexpr
double BUTTON_MARGIN = 2;
380 static constexpr
double TEXT_MARGIN = 4;
381 static constexpr
double RECT_PEN_SIZE = 2;
382 QSizeF mButtonSize { DEFAULT_BUTTON_WIDTH, DEFAULT_BUTTON_HEIGHT };
386 bool mIsHovering =
false;
387 bool mIsMoving =
false;
399 class GUI_EXPORT QgsModelParameterGraphicItem :
public QgsModelComponentGraphicItem
413 QgsModelParameterGraphicItem( QgsProcessingModelParameter *parameter
SIP_TRANSFER,
414 QgsProcessingModelAlgorithm *model,
417 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
418 bool canDeleteComponent()
override;
422 QColor fillColor( State state )
const override;
423 QColor strokeColor( State state )
const override;
424 QColor textColor( State state )
const override;
425 QPicture iconPicture()
const override;
426 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
430 void deleteComponent()
override;
443 class GUI_EXPORT QgsModelChildAlgorithmGraphicItem :
public QgsModelComponentGraphicItem
457 QgsModelChildAlgorithmGraphicItem( QgsProcessingModelChildAlgorithm *child
SIP_TRANSFER,
458 QgsProcessingModelAlgorithm *model,
460 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
461 bool canDeleteComponent()
override;
466 void setResults(
const QVariantMap &results );
471 void setInputs(
const QVariantMap &inputs );
475 QColor fillColor( State state )
const override;
476 QColor strokeColor( State state )
const override;
477 QColor textColor( State state )
const override;
478 QPixmap iconPixmap()
const override;
479 QPicture iconPicture()
const override;
481 int linkPointCount( Qt::Edge edge )
const override;
482 QString linkPointText( Qt::Edge edge,
int index )
const override;
483 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
487 void deleteComponent()
override;
490 void deactivateAlgorithm();
491 void activateAlgorithm();
496 QVariantMap mResults;
498 bool mIsValid =
true;
508 class GUI_EXPORT QgsModelOutputGraphicItem :
public QgsModelComponentGraphicItem
522 QgsModelOutputGraphicItem( QgsProcessingModelOutput *output
SIP_TRANSFER,
523 QgsProcessingModelAlgorithm *model,
526 bool canDeleteComponent()
override;
530 QColor fillColor( State state )
const override;
531 QColor strokeColor( State state )
const override;
532 QColor textColor( State state )
const override;
533 QPicture iconPicture()
const override;
534 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
538 void deleteComponent()
override;
553 class GUI_EXPORT QgsModelCommentGraphicItem :
public QgsModelComponentGraphicItem
567 QgsModelCommentGraphicItem( QgsProcessingModelComment *comment
SIP_TRANSFER,
568 QgsModelComponentGraphicItem *parentItem,
569 QgsProcessingModelAlgorithm *model,
571 ~QgsModelCommentGraphicItem()
override;
572 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
573 bool canDeleteComponent()
override;
578 QgsModelComponentGraphicItem *parentComponentItem()
const;
582 QColor fillColor( State state )
const override;
583 QColor strokeColor( State state )
const override;
584 QColor textColor( State state )
const override;
585 Qt::PenStyle strokeStyle( State state )
const override;
586 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
590 void deleteComponent()
override;
591 void editComponent()
override;
594 QgsProcessingModelComment *modelComponent();
596 std::unique_ptr< QgsProcessingModelComponent > mParentComponent;
597 QPointer< QgsModelComponentGraphicItem > mParentItem;
609 class GUI_EXPORT QgsModelGroupBoxGraphicItem :
public QgsModelComponentGraphicItem
623 QgsModelGroupBoxGraphicItem( QgsProcessingModelGroupBox *box
SIP_TRANSFER,
624 QgsProcessingModelAlgorithm *model,
626 ~QgsModelGroupBoxGraphicItem()
override;
627 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
628 bool canDeleteComponent()
override;
631 QColor fillColor( State state )
const override;
632 QColor strokeColor( State state )
const override;
633 QColor textColor( State state )
const override;
634 Qt::PenStyle strokeStyle( State state )
const override;
635 Qt::Alignment titleAlignment()
const override;
636 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
640 void deleteComponent()
override;
641 void editComponent()
override;
649 #endif // QGSMODELCOMPONENTGRAPHICITEM_H