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
66 Q_DECLARE_FLAGS( Flags, Flag )
76 QgsModelComponentGraphicItem( QgsProcessingModelComponent *component
SIP_TRANSFER, QgsProcessingModelAlgorithm *model, QGraphicsItem *parent
SIP_TRANSFERTHIS );
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() {}
304 QString truncatedTextForItem(
const QString &text )
const;
309 virtual QColor fillColor( State state )
const = 0;
314 virtual QColor strokeColor( State state )
const = 0;
319 virtual QColor textColor( State state )
const = 0;
324 virtual Qt::PenStyle strokeStyle( State state )
const;
329 virtual Qt::Alignment titleAlignment()
const;
334 virtual QPicture iconPicture()
const;
339 virtual QPixmap iconPixmap()
const;
344 virtual void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size ) = 0;
349 void updateButtonPositions();
352 QSizeF itemSize()
const;
354 void updateToolTip(
const QPointF &pos );
356 void fold( Qt::Edge edge,
bool folded );
358 std::unique_ptr<QgsProcessingModelComponent> mComponent;
359 QgsProcessingModelAlgorithm *mModel =
nullptr;
361 bool mInitialized =
false;
362 QgsModelDesignerFoldButtonGraphicItem *mExpandTopButton =
nullptr;
363 QgsModelDesignerFoldButtonGraphicItem *mExpandBottomButton =
nullptr;
367 QgsModelDesignerFlatButtonGraphicItem *mEditButton =
nullptr;
368 QgsModelDesignerFlatButtonGraphicItem *mDeleteButton =
nullptr;
370 static constexpr double MIN_COMPONENT_WIDTH = 70;
371 static constexpr double MIN_COMPONENT_HEIGHT = 30;
373 static constexpr double DEFAULT_BUTTON_WIDTH = 16;
374 static constexpr double DEFAULT_BUTTON_HEIGHT = 16;
375 static constexpr double BUTTON_MARGIN = 2;
376 static constexpr double TEXT_MARGIN = 4;
377 static constexpr double RECT_PEN_SIZE = 2;
378 QSizeF mButtonSize { DEFAULT_BUTTON_WIDTH, DEFAULT_BUTTON_HEIGHT };
382 bool mIsHovering =
false;
393class GUI_EXPORT QgsModelParameterGraphicItem :
public QgsModelComponentGraphicItem
406 QgsModelParameterGraphicItem( QgsProcessingModelParameter *parameter
SIP_TRANSFER, QgsProcessingModelAlgorithm *model, QGraphicsItem *parent
SIP_TRANSFERTHIS );
408 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
409 bool canDeleteComponent()
override;
412 QColor fillColor( State state )
const override;
413 QColor strokeColor( State state )
const override;
414 QColor textColor( State state )
const override;
415 QPicture iconPicture()
const override;
416 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
420 void deleteComponent()
override;
432class GUI_EXPORT QgsModelChildAlgorithmGraphicItem :
public QgsModelComponentGraphicItem
445 QgsModelChildAlgorithmGraphicItem( QgsProcessingModelChildAlgorithm *child
SIP_TRANSFER, QgsProcessingModelAlgorithm *model, QGraphicsItem *parent
SIP_TRANSFERTHIS );
446 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
447 bool canDeleteComponent()
override;
475 void showPreviousResults();
485 QColor fillColor( State state )
const override;
486 QColor strokeColor( State state )
const override;
487 QColor textColor( State state )
const override;
488 QPixmap iconPixmap()
const override;
489 QPicture iconPicture()
const override;
491 int linkPointCount( Qt::Edge edge )
const override;
492 QString linkPointText( Qt::Edge edge,
int index )
const override;
493 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
497 void deleteComponent()
override;
500 void deactivateAlgorithm();
501 void activateAlgorithm();
507 bool mIsValid =
true;
517class GUI_EXPORT QgsModelOutputGraphicItem :
public QgsModelComponentGraphicItem
530 QgsModelOutputGraphicItem( QgsProcessingModelOutput *output
SIP_TRANSFER, QgsProcessingModelAlgorithm *model, QGraphicsItem *parent
SIP_TRANSFERTHIS );
532 bool canDeleteComponent()
override;
535 QColor fillColor( State state )
const override;
536 QColor strokeColor( State state )
const override;
537 QColor textColor( State state )
const override;
538 QPicture iconPicture()
const override;
539 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
543 void deleteComponent()
override;
556class GUI_EXPORT QgsModelCommentGraphicItem :
public QgsModelComponentGraphicItem
569 QgsModelCommentGraphicItem( QgsProcessingModelComment *comment
SIP_TRANSFER, QgsModelComponentGraphicItem *parentItem, QgsProcessingModelAlgorithm *model, QGraphicsItem *parent
SIP_TRANSFERTHIS );
570 ~QgsModelCommentGraphicItem()
override;
571 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
572 bool canDeleteComponent()
override;
577 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;
605class GUI_EXPORT QgsModelGroupBoxGraphicItem :
public QgsModelComponentGraphicItem
618 QgsModelGroupBoxGraphicItem( QgsProcessingModelGroupBox *box
SIP_TRANSFER, QgsProcessingModelAlgorithm *model, QGraphicsItem *parent
SIP_TRANSFERTHIS );
619 ~QgsModelGroupBoxGraphicItem()
override;
620 void contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
override;
621 bool canDeleteComponent()
override;
624 QColor fillColor( State state )
const override;
625 QColor strokeColor( State state )
const override;
626 QColor textColor( State state )
const override;
627 Qt::PenStyle strokeStyle( State state )
const override;
628 Qt::Alignment titleAlignment()
const override;
629 void updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
override;
633 void deleteComponent()
override;
634 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)