16#ifndef QGSMODELCOMPONENTGRAPHICITEM_H
17#define QGSMODELCOMPONENTGRAPHICITEM_H
22#include <QGraphicsObject>
27class QgsProcessingModelComponent;
28class QgsProcessingModelParameter;
29class QgsProcessingModelChildAlgorithm;
30class QgsProcessingModelOutput;
31class QgsProcessingModelComment;
32class QgsProcessingModelAlgorithm;
33class QgsModelDesignerFlatButtonGraphicItem;
34class QgsModelDesignerFoldButtonGraphicItem;
35class QgsModelGraphicsView;
37class QgsProcessingModelGroupBox;
47class GUI_EXPORT QgsModelComponentGraphicItem :
public QGraphicsObject
67 Q_DECLARE_FLAGS( Flags, Flag )
77 QgsModelComponentGraphicItem( QgsProcessingModelComponent *component
SIP_TRANSFER,
78 QgsProcessingModelAlgorithm *model,
81 ~QgsModelComponentGraphicItem()
override;
86 virtual Flags flags()
const;
91 QgsProcessingModelComponent *component();
96 const QgsProcessingModelComponent *component() const
SIP_SKIP;
101 QgsProcessingModelAlgorithm *model();
106 QgsModelGraphicsView *view();
118 void setFont( const QFont &font );
125 void moveComponentBy( qreal dx, qreal dy );
130 void previewItemMove( qreal dx, qreal dy );
135 void setItemRect( QRectF rect );
142 QRectF previewItemRectChange( QRectF rect );
147 void finalizePreviewedItemRectChange( QRectF rect );
169 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event )
override;
170 void hoverEnterEvent( QGraphicsSceneHoverEvent *event )
override;
171 void hoverMoveEvent( QGraphicsSceneHoverEvent *event )
override;
172 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event )
override;
173 QVariant itemChange( GraphicsItemChange change,
const QVariant &value )
override;
174 QRectF boundingRect()
const override;
175 bool contains(
const QPointF &point )
const override;
176 void paint( QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget =
nullptr )
override;
181 QRectF itemRect(
bool storedRect =
false )
const;
188 QString label()
const;
195 void setLabel(
const QString &label );
205 virtual int linkPointCount( Qt::Edge edge )
const;
210 virtual QString linkPointText( Qt::Edge edge,
int index )
const;
215 QPointF linkPoint( Qt::Edge edge,
int index,
bool incoming )
const;
224 QPointF calculateAutomaticLinkPoint( QgsModelComponentGraphicItem *other, Qt::Edge &edge
SIP_OUT )
const;
233 QPointF calculateAutomaticLinkPoint(
const QPointF &point, Qt::Edge &edge
SIP_OUT )
const;
240 virtual void editComment() {}
245 virtual bool canDeleteComponent() {
return false; }
252 virtual void deleteComponent() {}
261 void requestModelRepaint();
270 void aboutToChange(
const QString &text,
int id = 0 );
281 void repaintArrows();
286 void updateArrowPaths();
291 void sizePositionChanged();
300 virtual void editComponent() {}
308 QString truncatedTextForItem(
const QString &text )
const;
313 virtual QColor fillColor( State state )
const = 0;
318 virtual QColor strokeColor( State state )
const = 0;
323 virtual QColor textColor( State state )
const = 0;
328 virtual Qt::PenStyle strokeStyle( State state )
const;
333 virtual Qt::Alignment titleAlignment()
const;
338 virtual QPicture iconPicture()
const;
343 virtual QPixmap iconPixmap()
const;
348 virtual void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size ) = 0;
353 void updateButtonPositions();
357 QSizeF itemSize()
const;
359 void updateToolTip(
const QPointF &pos );
361 void fold( Qt::Edge edge,
bool folded );
363 std::unique_ptr< QgsProcessingModelComponent > mComponent;
364 QgsProcessingModelAlgorithm *mModel =
nullptr;
366 bool mInitialized =
false;
367 QgsModelDesignerFoldButtonGraphicItem *mExpandTopButton =
nullptr;
368 QgsModelDesignerFoldButtonGraphicItem *mExpandBottomButton =
nullptr;
372 QgsModelDesignerFlatButtonGraphicItem *mEditButton =
nullptr;
373 QgsModelDesignerFlatButtonGraphicItem *mDeleteButton =
nullptr;
375 static constexpr double MIN_COMPONENT_WIDTH = 70;
376 static constexpr double MIN_COMPONENT_HEIGHT = 30;
378 static constexpr double DEFAULT_BUTTON_WIDTH = 16;
379 static constexpr double DEFAULT_BUTTON_HEIGHT = 16;
380 static constexpr double BUTTON_MARGIN = 2;
381 static constexpr double TEXT_MARGIN = 4;
382 static constexpr double RECT_PEN_SIZE = 2;
383 QSizeF mButtonSize { DEFAULT_BUTTON_WIDTH, DEFAULT_BUTTON_HEIGHT };
387 bool mIsHovering =
false;
399class 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;
443class GUI_EXPORT QgsModelChildAlgorithmGraphicItem :
public QgsModelComponentGraphicItem
457 QgsModelChildAlgorithmGraphicItem( QgsProcessingModelChildAlgorithm *child
SIP_TRANSFER,
458 QgsProcessingModelAlgorithm *model,
460 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
461 bool canDeleteComponent()
override;
489 void showPreviousResults();
500 QColor fillColor( State state )
const override;
501 QColor strokeColor( State state )
const override;
502 QColor textColor( State state )
const override;
503 QPixmap iconPixmap()
const override;
504 QPicture iconPicture()
const override;
506 int linkPointCount( Qt::Edge edge )
const override;
507 QString linkPointText( Qt::Edge edge,
int index )
const override;
508 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
512 void deleteComponent()
override;
515 void deactivateAlgorithm();
516 void activateAlgorithm();
522 bool mIsValid =
true;
532class GUI_EXPORT QgsModelOutputGraphicItem :
public QgsModelComponentGraphicItem
546 QgsModelOutputGraphicItem( QgsProcessingModelOutput *output
SIP_TRANSFER,
547 QgsProcessingModelAlgorithm *model,
550 bool canDeleteComponent()
override;
554 QColor fillColor( State state )
const override;
555 QColor strokeColor( State state )
const override;
556 QColor textColor( State state )
const override;
557 QPicture iconPicture()
const override;
558 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
562 void deleteComponent()
override;
577class GUI_EXPORT QgsModelCommentGraphicItem :
public QgsModelComponentGraphicItem
591 QgsModelCommentGraphicItem( QgsProcessingModelComment *comment
SIP_TRANSFER,
592 QgsModelComponentGraphicItem *parentItem,
593 QgsProcessingModelAlgorithm *model,
595 ~QgsModelCommentGraphicItem()
override;
596 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
597 bool canDeleteComponent()
override;
602 QgsModelComponentGraphicItem *parentComponentItem()
const;
606 QColor fillColor( State state )
const override;
607 QColor strokeColor( State state )
const override;
608 QColor textColor( State state )
const override;
609 Qt::PenStyle strokeStyle( State state )
const override;
610 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
614 void deleteComponent()
override;
615 void editComponent()
override;
618 QgsProcessingModelComment *modelComponent();
620 std::unique_ptr< QgsProcessingModelComponent > mParentComponent;
621 QPointer< QgsModelComponentGraphicItem > mParentItem;
633class GUI_EXPORT QgsModelGroupBoxGraphicItem :
public QgsModelComponentGraphicItem
647 QgsModelGroupBoxGraphicItem( QgsProcessingModelGroupBox *box
SIP_TRANSFER,
648 QgsProcessingModelAlgorithm *model,
650 ~QgsModelGroupBoxGraphicItem()
override;
651 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
652 bool canDeleteComponent()
override;
655 QColor fillColor( State state )
const override;
656 QColor strokeColor( State state )
const override;
657 QColor textColor( State state )
const override;
658 Qt::PenStyle strokeStyle( State state )
const override;
659 Qt::Alignment titleAlignment()
const override;
660 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
664 void deleteComponent()
override;
665 void editComponent()
override;
A QgsModelViewMouseEvent is the result of a user interaction with the mouse on a QgsModelGraphicsView...
Encapsulates the results of running a child algorithm within a model.
#define SIP_ENUM_BASETYPE(type)
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)