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;
388 bool mIsMoving =
false;
400class GUI_EXPORT QgsModelParameterGraphicItem :
public QgsModelComponentGraphicItem
414 QgsModelParameterGraphicItem( QgsProcessingModelParameter *parameter
SIP_TRANSFER,
415 QgsProcessingModelAlgorithm *model,
418 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
419 bool canDeleteComponent()
override;
423 QColor fillColor( State state )
const override;
424 QColor strokeColor( State state )
const override;
425 QColor textColor( State state )
const override;
426 QPicture iconPicture()
const override;
427 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
431 void deleteComponent()
override;
444class GUI_EXPORT QgsModelChildAlgorithmGraphicItem :
public QgsModelComponentGraphicItem
458 QgsModelChildAlgorithmGraphicItem( QgsProcessingModelChildAlgorithm *child
SIP_TRANSFER,
459 QgsProcessingModelAlgorithm *model,
461 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
462 bool canDeleteComponent()
override;
490 void showPreviousResults();
501 QColor fillColor( State state )
const override;
502 QColor strokeColor( State state )
const override;
503 QColor textColor( State state )
const override;
504 QPixmap iconPixmap()
const override;
505 QPicture iconPicture()
const override;
507 int linkPointCount( Qt::Edge edge )
const override;
508 QString linkPointText( Qt::Edge edge,
int index )
const override;
509 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
513 void deleteComponent()
override;
516 void deactivateAlgorithm();
517 void activateAlgorithm();
523 bool mIsValid =
true;
533class GUI_EXPORT QgsModelOutputGraphicItem :
public QgsModelComponentGraphicItem
547 QgsModelOutputGraphicItem( QgsProcessingModelOutput *output
SIP_TRANSFER,
548 QgsProcessingModelAlgorithm *model,
551 bool canDeleteComponent()
override;
555 QColor fillColor( State state )
const override;
556 QColor strokeColor( State state )
const override;
557 QColor textColor( State state )
const override;
558 QPicture iconPicture()
const override;
559 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
563 void deleteComponent()
override;
578class GUI_EXPORT QgsModelCommentGraphicItem :
public QgsModelComponentGraphicItem
592 QgsModelCommentGraphicItem( QgsProcessingModelComment *comment
SIP_TRANSFER,
593 QgsModelComponentGraphicItem *parentItem,
594 QgsProcessingModelAlgorithm *model,
596 ~QgsModelCommentGraphicItem()
override;
597 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
598 bool canDeleteComponent()
override;
603 QgsModelComponentGraphicItem *parentComponentItem()
const;
607 QColor fillColor( State state )
const override;
608 QColor strokeColor( State state )
const override;
609 QColor textColor( State state )
const override;
610 Qt::PenStyle strokeStyle( State state )
const override;
611 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
615 void deleteComponent()
override;
616 void editComponent()
override;
619 QgsProcessingModelComment *modelComponent();
621 std::unique_ptr< QgsProcessingModelComponent > mParentComponent;
622 QPointer< QgsModelComponentGraphicItem > mParentItem;
634class GUI_EXPORT QgsModelGroupBoxGraphicItem :
public QgsModelComponentGraphicItem
648 QgsModelGroupBoxGraphicItem( QgsProcessingModelGroupBox *box
SIP_TRANSFER,
649 QgsProcessingModelAlgorithm *model,
651 ~QgsModelGroupBoxGraphicItem()
override;
652 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
653 bool canDeleteComponent()
override;
656 QColor fillColor( State state )
const override;
657 QColor strokeColor( State state )
const override;
658 QColor textColor( State state )
const override;
659 Qt::PenStyle strokeStyle( State state )
const override;
660 Qt::Alignment titleAlignment()
const override;
661 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
665 void deleteComponent()
override;
666 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)