34#include <QApplication>
35#include <QGraphicsSceneHoverEvent>
42#include <QSvgRenderer>
44#include "moc_qgsmodelcomponentgraphicitem.cpp"
46using namespace Qt::StringLiterals;
50QgsModelComponentGraphicItem::QgsModelComponentGraphicItem( QgsProcessingModelComponent *component, QgsProcessingModelAlgorithm *model, QGraphicsItem *parent )
51 : QGraphicsObject( parent )
52 , mComponent( component )
55 setAcceptHoverEvents(
true );
56 setFlag( QGraphicsItem::ItemIsSelectable,
true );
57 setFlag( QGraphicsItem::ItemSendsGeometryChanges,
true );
58 setZValue( QgsModelGraphicsScene::ZValues::ModelComponent );
60 mFont.setPixelSize( 12 );
64 QPainter painter( &editPicture );
65 svg.render( &painter );
67 mEditButton =
new QgsModelDesignerFlatButtonGraphicItem(
this, editPicture, QPointF( 0, 0 ) );
68 connect( mEditButton, &QgsModelDesignerFlatButtonGraphicItem::clicked,
this, &QgsModelComponentGraphicItem::editComponent );
71 QPicture deletePicture;
72 painter.begin( &deletePicture );
73 svg2.render( &painter );
75 mDeleteButton =
new QgsModelDesignerFlatButtonGraphicItem(
this, deletePicture, QPointF( 0, 0 ) );
76 connect( mDeleteButton, &QgsModelDesignerFlatButtonGraphicItem::clicked,
this, &QgsModelComponentGraphicItem::deleteComponent );
78 updateButtonPositions();
81QgsModelComponentGraphicItem::Flags QgsModelComponentGraphicItem::flags()
const
83 return QgsModelComponentGraphicItem::Flags();
86QgsModelComponentGraphicItem::~QgsModelComponentGraphicItem() =
default;
88QgsProcessingModelComponent *QgsModelComponentGraphicItem::component()
90 return mComponent.get();
93const QgsProcessingModelComponent *QgsModelComponentGraphicItem::component()
const
95 return mComponent.get();
98QgsProcessingModelAlgorithm *QgsModelComponentGraphicItem::model()
103const QgsProcessingModelAlgorithm *QgsModelComponentGraphicItem::model()
const
108QgsModelGraphicsView *QgsModelComponentGraphicItem::view()
110 if ( scene()->views().isEmpty() )
113 return qobject_cast<QgsModelGraphicsView *>( scene()->views().first() );
116QFont QgsModelComponentGraphicItem::font()
const
121void QgsModelComponentGraphicItem::setFont(
const QFont &font )
127void QgsModelComponentGraphicItem::moveComponentBy( qreal dx, qreal dy )
129 setPos( mComponent->position().x() + dx, mComponent->position().y() + dy );
130 mComponent->setPosition( pos() );
132 emit aboutToChange( tr(
"Move %1" ).arg( mComponent->description() ) );
133 updateStoredComponentPosition( pos(), mComponent->size() );
136 emit sizePositionChanged();
137 emit updateArrowPaths();
140void QgsModelComponentGraphicItem::previewItemMove( qreal dx, qreal dy )
142 setPos( mComponent->position().x() + dx, mComponent->position().y() + dy );
143 emit updateArrowPaths();
146void QgsModelComponentGraphicItem::setItemRect( QRectF rect )
148 rect = rect.normalized();
150 if ( rect.width() < MIN_COMPONENT_WIDTH )
151 rect.setWidth( MIN_COMPONENT_WIDTH );
152 if ( rect.height() < MIN_COMPONENT_HEIGHT )
153 rect.setHeight( MIN_COMPONENT_HEIGHT );
155 setPos( rect.center() );
156 prepareGeometryChange();
158 emit aboutToChange( tr(
"Resize %1" ).arg( mComponent->description() ) );
160 mComponent->setPosition( pos() );
161 mComponent->setSize( rect.size() );
162 updateStoredComponentPosition( pos(), mComponent->size() );
164 updateButtonPositions();
167 emit updateArrowPaths();
168 emit sizePositionChanged();
171QRectF QgsModelComponentGraphicItem::previewItemRectChange( QRectF rect )
173 rect = rect.normalized();
175 if ( rect.width() < MIN_COMPONENT_WIDTH )
176 rect.setWidth( MIN_COMPONENT_WIDTH );
177 if ( rect.height() < MIN_COMPONENT_HEIGHT )
178 rect.setHeight( MIN_COMPONENT_HEIGHT );
180 setPos( rect.center() );
181 prepareGeometryChange();
183 mTempSize = rect.size();
185 updateButtonPositions();
186 emit updateArrowPaths();
191void QgsModelComponentGraphicItem::finalizePreviewedItemRectChange( QRectF )
193 mComponent->setPosition( pos() );
194 prepareGeometryChange();
195 mComponent->setSize( mTempSize );
196 mTempSize = QSizeF();
198 emit aboutToChange( tr(
"Resize %1" ).arg( mComponent->description() ) );
199 updateStoredComponentPosition( pos(), mComponent->size() );
201 updateButtonPositions();
205 emit sizePositionChanged();
206 emit updateArrowPaths();
211 if ( view() && view()->tool() && view()->tool()->allowItemInteraction() )
212 updateToolTip( mapFromScene( event->
modelPoint() ) );
217 if ( view() && view()->tool() && view()->tool()->allowItemInteraction() )
218 updateToolTip( mapFromScene( event->
modelPoint() ) );
223 if ( view() && view()->tool() && view()->tool()->allowItemInteraction() )
225 setToolTip( QString() );
230 emit repaintArrows();
237 if ( view() && view()->tool() && view()->tool()->allowItemInteraction() )
241void QgsModelComponentGraphicItem::mouseDoubleClickEvent( QGraphicsSceneMouseEvent * )
243 if ( view() && view()->tool() && view()->tool()->allowItemInteraction() )
247void QgsModelComponentGraphicItem::hoverEnterEvent( QGraphicsSceneHoverEvent *event )
249 if ( view() && view()->tool() && view()->tool()->allowItemInteraction() )
250 updateToolTip( event->pos() );
253void QgsModelComponentGraphicItem::hoverMoveEvent( QGraphicsSceneHoverEvent *event )
255 if ( view() && view()->tool() && view()->tool()->allowItemInteraction() )
256 updateToolTip( event->pos() );
259void QgsModelComponentGraphicItem::hoverLeaveEvent( QGraphicsSceneHoverEvent * )
261 modelHoverLeaveEvent(
nullptr );
264QVariant QgsModelComponentGraphicItem::itemChange( QGraphicsItem::GraphicsItemChange change,
const QVariant &value )
268 case QGraphicsItem::ItemSelectedChange:
270 emit repaintArrows();
274 case QGraphicsItem::ItemSceneChange:
279 if ( linkPointCount( Qt::TopEdge ) )
281 mExpandTopButton =
new QgsModelDesignerFoldButtonGraphicItem(
this, mComponent->linksCollapsed( Qt::TopEdge ), QPointF( 0, 0 ) );
282 connect( mExpandTopButton, &QgsModelDesignerFoldButtonGraphicItem::folded,
this, [
this](
bool folded ) { fold( Qt::TopEdge, folded ); } );
284 for (
int idx = 0; idx < linkPointCount( Qt::TopEdge ); ++idx )
286 mInSockets.append(
new QgsModelDesignerSocketGraphicItem(
this, mComponent.get(), idx, QPointF( 0, 0 ), Qt::TopEdge ) );
289 if ( linkPointCount( Qt::BottomEdge ) )
291 mExpandBottomButton =
new QgsModelDesignerFoldButtonGraphicItem(
this, mComponent->linksCollapsed( Qt::BottomEdge ), QPointF( 0, 0 ) );
292 connect( mExpandBottomButton, &QgsModelDesignerFoldButtonGraphicItem::folded,
this, [
this](
bool folded ) { fold( Qt::BottomEdge, folded ); } );
294 for (
int idx = 0; idx < linkPointCount( Qt::BottomEdge ); ++idx )
296 mOutSockets.append(
new QgsModelDesignerSocketGraphicItem(
this, mComponent.get(), idx, QPointF( 0, 0 ), Qt::BottomEdge ) );
300 updateButtonPositions();
309 return QGraphicsObject::itemChange( change, value );
312QRectF QgsModelComponentGraphicItem::boundingRect()
const
314 const QFontMetricsF fm( mFont );
315 const int linksAbove = linkPointCount( Qt::TopEdge );
316 const int linksBelow = linkPointCount( Qt::BottomEdge );
318 const double hUp = linksAbove == 0 ? 0 : fm.height() * 1.2 * ( ( mComponent->linksCollapsed( Qt::TopEdge ) ? 0 : linksAbove ) + 2 );
319 const double hDown = linksBelow == 0 ? 0 : fm.height() * 1.2 * ( ( mComponent->linksCollapsed( Qt::BottomEdge ) ? 0 : linksBelow ) + 2 );
321 double outlineSize = 0;
322 if ( outlineColor().isValid() )
324 outlineSize = RECT_OUTLINE_SIZE + 0.5;
328 -( itemSize().width() ) / 2 - RECT_PEN_SIZE - outlineSize,
329 -( itemSize().height() ) / 2 - hUp - RECT_PEN_SIZE - outlineSize,
330 itemSize().width() + 2 * RECT_PEN_SIZE + outlineSize * 2,
331 itemSize().height() + hDown + hUp + 2 * RECT_PEN_SIZE + outlineSize * 2
335bool QgsModelComponentGraphicItem::contains(
const QPointF &point )
const
337 const QRectF paintingBounds = boundingRect();
338 if ( point.x() < paintingBounds.left() + RECT_PEN_SIZE )
340 if ( point.x() > paintingBounds.right() - RECT_PEN_SIZE )
342 if ( point.y() < paintingBounds.top() + RECT_PEN_SIZE )
344 if ( point.y() > paintingBounds.bottom() - RECT_PEN_SIZE )
350void QgsModelComponentGraphicItem::paintBackground( QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget )
352 const QRectF rect = itemRect();
355 if ( mComponent->color().isValid() )
357 color = mComponent->color();
361 color = color.darker( 110 );
364 color = color.darker( 105 );
370 stroke = color.darker( 110 );
374 color = fillColor( state() );
375 stroke = strokeColor( state() );
378 paintOutline( painter, option, widget );
380 QPen strokePen = QPen( stroke, 0 );
381 strokePen.setStyle( strokeStyle( state() ) );
382 painter->setPen( strokePen );
383 painter->setBrush( QBrush( color, Qt::SolidPattern ) );
384 painter->drawRect( rect );
387void QgsModelComponentGraphicItem::paintOutline( QPainter *painter,
const QStyleOptionGraphicsItem *, QWidget * )
389 const QColor outline = outlineColor();
390 if ( outline.isValid() )
393 const bool wasAntiAliased = painter->testRenderHint( QPainter::RenderHint::Antialiasing );
394 painter->setRenderHint( QPainter::RenderHint::Antialiasing );
395 QPen strokePen = QPen( outline, RECT_OUTLINE_SIZE );
396 strokePen.setJoinStyle( Qt::MiterJoin );
397 strokePen.setStyle( strokeStyle( state() ) );
398 painter->setPen( strokePen );
399 painter->setBrush( Qt::NoBrush );
400 const QRectF rect = itemRect();
401 painter->drawRect( rect );
402 painter->setRenderHint( QPainter::RenderHint::Antialiasing, wasAntiAliased );
406void QgsModelComponentGraphicItem::paint( QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget )
408 paintBackground( painter, option, widget );
410 const QRectF rect = itemRect();
412 if ( mComponent->color().isValid() )
414 QColor color = mComponent->color();
418 color = color.darker( 110 );
421 color = color.darker( 105 );
427 foreColor = color.lightness() > 150 ? QColor( 0, 0, 0 ) : QColor( 255, 255, 255 );
431 foreColor = textColor( state() );
433 painter->setFont( font() );
434 painter->setPen( QPen( foreColor ) );
438 const QSizeF componentSize = itemSize();
440 const QFontMetricsF fm( font() );
441 double h = fm.ascent();
442 QPointF pt( -componentSize.width() / 2 + 25, componentSize.height() / 2.0 - h + 1 );
444 if ( iconPicture().isNull() && iconPixmap().isNull() )
446 const QRectF labelRect = QRectF( rect.left() + TEXT_MARGIN, rect.top() + TEXT_MARGIN, rect.width() - 2 * TEXT_MARGIN - mButtonSize.width() - BUTTON_MARGIN, rect.height() - 2 * TEXT_MARGIN );
448 painter->drawText( labelRect, Qt::TextWordWrap | titleAlignment(), text );
452 const QRectF labelRect = QRectF( rect.left() + 21 + TEXT_MARGIN, rect.top() + TEXT_MARGIN, rect.width() - 2 * TEXT_MARGIN - mButtonSize.width() - BUTTON_MARGIN - 21, rect.height() - 2 * TEXT_MARGIN );
454 painter->drawText( labelRect, Qt::TextWordWrap | Qt::AlignVCenter, text );
457 painter->setPen( QPen( QApplication::palette().color( QPalette::Text ) ) );
459 if ( linkPointCount( Qt::TopEdge ) )
461 h = -( fm.height() * 1.2 );
462 h = h - componentSize.height() / 2.0 + 5;
463 pt = QPointF( -componentSize.width() / 2 + 25, h );
464 painter->drawText( pt, QObject::tr(
"In" ) );
466 if ( !mComponent->linksCollapsed( Qt::TopEdge ) )
468 for (
int idx = 0; idx < linkPointCount( Qt::TopEdge ); ++idx )
470 text = linkPointText( Qt::TopEdge, idx );
471 h = -( fm.height() * 1.2 ) * ( i + 1 );
472 h = h - componentSize.height() / 2.0 + 5;
473 pt = QPointF( -componentSize.width() / 2 + 33, h );
474 painter->drawText( pt, text );
479 if ( linkPointCount( Qt::BottomEdge ) )
481 h = fm.height() * 1.1;
482 h = h + componentSize.height() / 2.0;
483 pt = QPointF( -componentSize.width() / 2 + 25, h );
484 painter->drawText( pt, QObject::tr(
"Out" ) );
485 if ( !mComponent->linksCollapsed( Qt::BottomEdge ) )
487 for (
int idx = 0; idx < linkPointCount( Qt::BottomEdge ); ++idx )
489 text = linkPointText( Qt::BottomEdge, idx );
490 h = fm.height() * 1.2 * ( idx + 2 );
491 h = h + componentSize.height() / 2.0;
492 pt = QPointF( -componentSize.width() / 2 + 33, h );
493 painter->drawText( pt, text );
498 const QPixmap px = iconPixmap();
501 painter->drawPixmap( QPointF( -( componentSize.width() / 2.0 ) + 3, -8 ), px );
505 const QPicture pic = iconPicture();
508 painter->drawPicture( QPointF( -( componentSize.width() / 2.0 ) + 3, -8 ), pic );
513QRectF QgsModelComponentGraphicItem::itemRect(
bool storedRect )
const
517 return QRectF( mComponent->position().x() - ( mComponent->size().width() ) / 2.0, mComponent->position().y() - ( mComponent->size().height() ) / 2.0, mComponent->size().width(), mComponent->size().height() );
520 return QRectF( -( itemSize().width() ) / 2.0, -( itemSize().height() ) / 2.0, itemSize().width(), itemSize().height() );
523QString QgsModelComponentGraphicItem::truncatedTextForItem(
const QString &text )
const
525 const QFontMetricsF fm( mFont );
526 double width = fm.boundingRect( text ).width();
527 if ( width < itemSize().width() - 25 - mButtonSize.width() )
531 t = t.left( t.length() - 3 ) + QChar( 0x2026 );
532 width = fm.boundingRect( t ).width();
533 while ( width > itemSize().width() - 25 - mButtonSize.width() )
535 if ( t.length() < 5 )
538 t = t.left( t.length() - 4 ) + QChar( 0x2026 );
539 width = fm.boundingRect( t ).width();
544Qt::PenStyle QgsModelComponentGraphicItem::strokeStyle( QgsModelComponentGraphicItem::State )
const
546 return Qt::SolidLine;
549Qt::Alignment QgsModelComponentGraphicItem::titleAlignment()
const
551 return Qt::AlignLeft;
554QPicture QgsModelComponentGraphicItem::iconPicture()
const
559QPixmap QgsModelComponentGraphicItem::iconPixmap()
const
565void QgsModelComponentGraphicItem::updateButtonPositions()
567 mEditButton->setPosition( QPointF( itemSize().width() / 2.0 - mButtonSize.width() / 2.0 - BUTTON_MARGIN, itemSize().height() / 2.0 - mButtonSize.height() / 2.0 - BUTTON_MARGIN ) );
568 mDeleteButton->setPosition( QPointF( itemSize().width() / 2.0 - mButtonSize.width() / 2.0 - BUTTON_MARGIN, mButtonSize.height() / 2.0 - itemSize().height() / 2.0 + BUTTON_MARGIN ) );
570 if ( mExpandBottomButton )
572 const QPointF pt = linkPoint( Qt::BottomEdge, -1,
false );
573 mExpandBottomButton->setPosition( QPointF( 0, pt.y() ) );
575 bool collapsed = mComponent->linksCollapsed( Qt::BottomEdge );
576 for ( QgsModelDesignerSocketGraphicItem *socket : std::as_const( mOutSockets ) )
578 const QPointF pt = linkPoint( Qt::BottomEdge, socket->index(),
false );
579 socket->setPosition( pt );
580 socket->setVisible( !collapsed );
585 if ( mExpandTopButton )
587 const QPointF pt = linkPoint( Qt::TopEdge, -1,
true );
588 mExpandTopButton->setPosition( QPointF( 0, pt.y() ) );
590 bool collapsed = mComponent->linksCollapsed( Qt::TopEdge );
591 for ( QgsModelDesignerSocketGraphicItem *socket : std::as_const( mInSockets ) )
593 const QPointF pt = linkPoint( Qt::TopEdge, socket->index(),
true );
594 socket->setPosition( pt );
595 socket->setVisible( !collapsed );
601QSizeF QgsModelComponentGraphicItem::itemSize()
const
603 return !mTempSize.isValid() ? mComponent->size() : mTempSize;
606void QgsModelComponentGraphicItem::updateToolTip(
const QPointF &pos )
608 const bool prevHoverStatus = mIsHovering;
609 if ( itemRect().contains( pos ) )
611 setToolTip( mLabel );
616 setToolTip( QString() );
619 if ( mIsHovering != prevHoverStatus )
622 emit repaintArrows();
626void QgsModelComponentGraphicItem::fold( Qt::Edge edge,
bool folded )
628 emit aboutToChange( !folded ? tr(
"Expand Item" ) : tr(
"Collapse Item" ) );
629 mComponent->setLinksCollapsed( edge, folded );
633 if ( QgsProcessingModelChildAlgorithm *child =
dynamic_cast<QgsProcessingModelChildAlgorithm *
>( mComponent.get() ) )
635 mModel->childAlgorithm( child->childId() ).setLinksCollapsed( edge, folded );
637 else if ( QgsProcessingModelParameter *param =
dynamic_cast<QgsProcessingModelParameter *
>( mComponent.get() ) )
639 mModel->parameterComponent( param->parameterName() ).setLinksCollapsed( edge, folded );
641 else if ( QgsProcessingModelOutput *output =
dynamic_cast<QgsProcessingModelOutput *
>( mComponent.get() ) )
643 mModel->childAlgorithm( output->childId() ).modelOutput( output->name() ).setLinksCollapsed( edge, folded );
646 updateButtonPositions();
647 prepareGeometryChange();
648 emit updateArrowPaths();
653QString QgsModelComponentGraphicItem::label()
const
658void QgsModelComponentGraphicItem::setLabel(
const QString &label )
664QgsModelComponentGraphicItem::State QgsModelComponentGraphicItem::state()
const
668 else if ( mIsHovering )
674int QgsModelComponentGraphicItem::linkPointCount( Qt::Edge )
const
679QString QgsModelComponentGraphicItem::linkPointText( Qt::Edge,
int )
const
684QPointF QgsModelComponentGraphicItem::linkPoint( Qt::Edge edge,
int index,
bool incoming )
const
690 if ( linkPointCount( Qt::BottomEdge ) )
693 if ( mComponent->linksCollapsed( Qt::BottomEdge ) )
697 const int pointIndex = !mComponent->linksCollapsed( Qt::BottomEdge ) ? index : -1;
698 const QString text = truncatedTextForItem( linkPointText( Qt::BottomEdge, index ) );
699 const QFontMetricsF fm( mFont );
700 const double w = fm.boundingRect( text ).width();
701 const double h = fm.height() * 1.2 * ( pointIndex + 1 ) + fm.height() / 2.0;
702 const double y = h + itemSize().height() / 2.0 + 6.4;
703 const double x = !mComponent->linksCollapsed( Qt::BottomEdge ) ? ( -itemSize().width() / 2 + 33 + w + 10 ) : 10.4;
704 return QPointF( incoming ? -itemSize().width() / 2 + offsetX : x, y );
711 if ( linkPointCount( Qt::TopEdge ) )
714 int paramIndex = index;
715 if ( mComponent->linksCollapsed( Qt::TopEdge ) )
720 const QFontMetricsF fm( mFont );
721 const QString text = truncatedTextForItem( linkPointText( Qt::TopEdge, index ) );
722 const double w = fm.boundingRect( text ).width();
723 double h = -( fm.height() * 1.2 ) * ( paramIndex + 2 ) - fm.height() / 2.0 + 8;
724 h = h - itemSize().height() / 2.0;
725 return QPointF( incoming ? -itemSize().width() / 2 + offsetX : ( !mComponent->linksCollapsed( Qt::TopEdge ) ? ( -itemSize().width() / 2 + 33 + w + 5 ) : 10 ), h );
737QPointF QgsModelComponentGraphicItem::calculateAutomaticLinkPoint( QgsModelComponentGraphicItem *other, Qt::Edge &edge )
const
740 const QgsRectangle otherRect( other->itemRect().translated( other->pos() ) );
742 const QPointF leftPoint = pos() + QPointF( -itemSize().width() / 2.0, 0 );
743 const double distLeft = otherRect.distance(
QgsPointXY( leftPoint ) );
745 const QPointF rightPoint = pos() + QPointF( itemSize().width() / 2.0, 0 );
746 const double distRight = otherRect.distance(
QgsPointXY( rightPoint ) );
748 const QPointF topPoint = pos() + QPointF( 0, -itemSize().height() / 2.0 );
749 const double distTop = otherRect.distance(
QgsPointXY( topPoint ) );
751 const QPointF bottomPoint = pos() + QPointF( 0, itemSize().height() / 2.0 );
752 const double distBottom = otherRect.distance(
QgsPointXY( bottomPoint ) );
754 if ( distLeft <= distRight && distLeft <= distTop && distLeft <= distBottom )
759 else if ( distRight <= distTop && distRight <= distBottom )
761 edge = Qt::RightEdge;
764 else if ( distBottom <= distTop )
766 edge = Qt::BottomEdge;
776QPointF QgsModelComponentGraphicItem::calculateAutomaticLinkPoint(
const QPointF &point, Qt::Edge &edge )
const
780 const QPointF leftPoint = pos() + QPointF( -itemSize().width() / 2.0, 0 );
781 const double distLeft = otherPt.distance(
QgsPointXY( leftPoint ) );
783 const QPointF rightPoint = pos() + QPointF( itemSize().width() / 2.0, 0 );
784 const double distRight = otherPt.distance(
QgsPointXY( rightPoint ) );
786 const QPointF topPoint = pos() + QPointF( 0, -itemSize().height() / 2.0 );
787 const double distTop = otherPt.distance(
QgsPointXY( topPoint ) );
789 const QPointF bottomPoint = pos() + QPointF( 0, itemSize().height() / 2.0 );
790 const double distBottom = otherPt.distance(
QgsPointXY( bottomPoint ) );
792 if ( distLeft <= distRight && distLeft <= distTop && distLeft <= distBottom )
797 else if ( distRight <= distTop && distRight <= distBottom )
799 edge = Qt::RightEdge;
802 else if ( distBottom <= distTop )
804 edge = Qt::BottomEdge;
814QgsModelDesignerSocketGraphicItem *QgsModelComponentGraphicItem::outSocketAt(
int index )
const
816 if ( index < 0 || index >= mOutSockets.size() )
820 return mOutSockets.at( index );
823QList<QgsModelArrowItem *> QgsModelComponentGraphicItem::incomingArrows()
825 const QList<QGraphicsItem *> allItems = scene()->items();
826 QList<QgsModelArrowItem *> arrows;
827 for ( QGraphicsItem *item : allItems )
829 if (
auto arrowItem =
dynamic_cast< QgsModelArrowItem *
>( item ) )
831 if ( arrowItem->endItem() ==
this )
840QList<QgsModelArrowItem *> QgsModelComponentGraphicItem::outgoingArrows()
842 const QList<QGraphicsItem *> allItems = scene()->items();
843 QList<QgsModelArrowItem *> arrows;
844 for ( QGraphicsItem *item : allItems )
846 if (
auto arrowItem =
dynamic_cast< QgsModelArrowItem *
>( item ) )
848 if ( arrowItem->startItem() ==
this )
857QgsModelParameterGraphicItem::QgsModelParameterGraphicItem( QgsProcessingModelParameter *parameter, QgsProcessingModelAlgorithm *model, QGraphicsItem *parent )
858 : QgsModelComponentGraphicItem( parameter, model, parent )
861 QPainter painter( &mPicture );
862 svg.render( &painter );
866 setLabel( parameterDefinition->description() );
868 setLabel( QObject::tr(
"Error (%1)" ).arg( parameter->parameterName() ) );
871void QgsModelParameterGraphicItem::contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
873 QMenu *popupmenu =
new QMenu( event->widget() );
874 QAction *removeAction = popupmenu->addAction( QObject::tr(
"Remove" ) );
875 connect( removeAction, &QAction::triggered,
this, &QgsModelParameterGraphicItem::deleteComponent );
876 QAction *editAction = popupmenu->addAction( QObject::tr(
"Edit…" ) );
877 connect( editAction, &QAction::triggered,
this, &QgsModelParameterGraphicItem::editComponent );
878 QAction *editCommentAction = popupmenu->addAction( component()->comment()->description().isEmpty() ? QObject::tr(
"Add Comment…" ) : QObject::tr(
"Edit Comment…" ) );
879 connect( editCommentAction, &QAction::triggered,
this, &QgsModelParameterGraphicItem::editComment );
881 popupmenu->exec( event->screenPos() );
884QColor QgsModelParameterGraphicItem::fillColor( QgsModelComponentGraphicItem::State state )
const
886 QColor
c( 238, 242, 131 );
902QColor QgsModelParameterGraphicItem::strokeColor( QgsModelComponentGraphicItem::State state )
const
907 return QColor( 116, 113, 68 );
910 return QColor( 234, 226, 118 );
915QColor QgsModelParameterGraphicItem::textColor( QgsModelComponentGraphicItem::State )
const
920QPicture QgsModelParameterGraphicItem::iconPicture()
const
925int QgsModelParameterGraphicItem::linkPointCount( Qt::Edge edge )
const
940QString QgsModelParameterGraphicItem::linkPointText( Qt::Edge,
int index )
const
947 if (
const QgsProcessingModelParameter *parameter =
dynamic_cast< const QgsProcessingModelParameter *
>( component() ) )
949 QString text = this->model()->parameterDefinition( parameter->parameterName() )->type();
954 const QVariant paramValue = paramDef->defaultValue();
956 if ( paramValue.isValid() )
958 text +=
": " + paramDef->userFriendlyString( paramValue );
961 return truncatedTextForItem( text );
967QColor QgsModelParameterGraphicItem::linkColor( Qt::Edge ,
int index )
const
971 return FALLBACK_COLOR;
974 if (
const QgsProcessingModelParameter *parameter =
dynamic_cast< const QgsProcessingModelParameter *
>( component() ) )
978 return parameterDefinition->modelColor();
982 return FALLBACK_COLOR;
985void QgsModelParameterGraphicItem::updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
987 if ( QgsProcessingModelParameter *param =
dynamic_cast<QgsProcessingModelParameter *
>( component() ) )
989 model()->parameterComponent( param->parameterName() ).setPosition( pos );
990 model()->parameterComponent( param->parameterName() ).setSize( size );
994bool QgsModelParameterGraphicItem::canDeleteComponent()
996 if (
const QgsProcessingModelParameter *param =
dynamic_cast<const QgsProcessingModelParameter *
>( component() ) )
998 if ( model()->childAlgorithmsDependOnParameter( param->parameterName() ) )
1002 else if ( model()->otherParametersDependOnParameter( param->parameterName() ) )
1014void QgsModelParameterGraphicItem::deleteComponent()
1016 if (
const QgsProcessingModelParameter *param =
dynamic_cast<const QgsProcessingModelParameter *
>( component() ) )
1018 if ( model()->childAlgorithmsDependOnParameter( param->parameterName() ) )
1020 QMessageBox::warning(
1022 QObject::tr(
"Could not remove input" ),
1024 "Algorithms depend on the selected input.\n"
1025 "Remove them before trying to remove it."
1029 else if ( model()->otherParametersDependOnParameter( param->parameterName() ) )
1031 QMessageBox::warning(
1033 QObject::tr(
"Could not remove input" ),
1035 "Other inputs depend on the selected input.\n"
1036 "Remove them before trying to remove it."
1042 emit aboutToChange( tr(
"Delete Input %1" ).arg( param->description() ) );
1043 model()->removeModelParameter( param->parameterName() );
1045 emit requestModelRepaint();
1051QgsModelChildAlgorithmGraphicItem::QgsModelChildAlgorithmGraphicItem( QgsProcessingModelChildAlgorithm *child, QgsProcessingModelAlgorithm *model, QGraphicsItem *parent )
1052 : QgsModelComponentGraphicItem( child, model, parent )
1054 if ( child->algorithm() && !child->algorithm()->svgIconPath().isEmpty() )
1056 QSvgRenderer svg( child->algorithm()->svgIconPath() );
1057 const QSizeF size = svg.defaultSize();
1058 QPainter painter( &mPicture );
1059 painter.scale( 16.0 / size.width(), 16.0 / size.width() );
1060 svg.render( &painter );
1063 else if ( child->algorithm() )
1065 mPixmap = child->algorithm()->icon().pixmap( 15, 15 );
1068 setLabel( child->description() );
1071 mIsValid = model->validateChildAlgorithm( child->childId(), issues );
1074void QgsModelChildAlgorithmGraphicItem::contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
1076 QMenu *popupmenu =
new QMenu( event->widget() );
1080 QAction *runSelectedStepsAction = popupmenu->addAction( QObject::tr(
"Run Selected Steps…" ) );
1082 connect( runSelectedStepsAction, &QAction::triggered,
this, &QgsModelChildAlgorithmGraphicItem::runSelected );
1085 QAction *runFromHereAction = popupmenu->addAction( QObject::tr(
"Run from Here…" ) );
1087 connect( runFromHereAction, &QAction::triggered,
this, &QgsModelChildAlgorithmGraphicItem::runFromHere );
1089 popupmenu->addSeparator();
1091 QAction *removeAction = popupmenu->addAction( QObject::tr(
"Remove" ) );
1092 connect( removeAction, &QAction::triggered,
this, &QgsModelChildAlgorithmGraphicItem::deleteComponent );
1093 QAction *editAction = popupmenu->addAction( QObject::tr(
"Edit…" ) );
1094 connect( editAction, &QAction::triggered,
this, &QgsModelChildAlgorithmGraphicItem::editComponent );
1095 QAction *editCommentAction = popupmenu->addAction( component()->comment()->description().isEmpty() ? QObject::tr(
"Add Comment…" ) : QObject::tr(
"Edit Comment…" ) );
1096 connect( editCommentAction, &QAction::triggered,
this, &QgsModelParameterGraphicItem::editComment );
1097 popupmenu->addSeparator();
1099 if (
const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( component() ) )
1101 if ( !child->isActive() )
1103 QAction *activateAction = popupmenu->addAction( QObject::tr(
"Activate" ) );
1104 connect( activateAction, &QAction::triggered,
this, &QgsModelChildAlgorithmGraphicItem::activateAlgorithm );
1108 QAction *deactivateAction = popupmenu->addAction( QObject::tr(
"Deactivate" ) );
1109 connect( deactivateAction, &QAction::triggered,
this, &QgsModelChildAlgorithmGraphicItem::deactivateAlgorithm );
1115 const QList<const QgsProcessingParameterDefinition *> outputParams =
algorithm->destinationParameterDefinitions();
1116 if ( !outputParams.isEmpty() )
1118 popupmenu->addSeparator();
1119 QAction *viewOutputLayersAction = popupmenu->addAction( QObject::tr(
"View Output Layers" ) );
1121 connect( viewOutputLayersAction, &QAction::triggered,
this, &QgsModelChildAlgorithmGraphicItem::showPreviousResults );
1123 switch ( mResults.executionStatus() )
1127 viewOutputLayersAction->setEnabled(
false );
1136 QAction *viewLogAction = popupmenu->addAction( QObject::tr(
"View Log…" ) );
1137 connect( viewLogAction, &QAction::triggered,
this, &QgsModelChildAlgorithmGraphicItem::showLog );
1139 switch ( mResults.executionStatus() )
1142 viewLogAction->setEnabled(
false );
1151 popupmenu->exec( event->screenPos() );
1154QColor QgsModelChildAlgorithmGraphicItem::fillColor( QgsModelComponentGraphicItem::State state )
const
1159 c = QColor( 255, 255, 255 );
1161 c = QColor( 208, 0, 0 );
1166 c =
c.darker( 110 );
1169 c =
c.darker( 105 );
1178QColor QgsModelChildAlgorithmGraphicItem::strokeColor( QgsModelComponentGraphicItem::State state )
const
1183 return mIsValid ? QColor( 50, 50, 50 ) : QColor( 80, 0, 0 );
1186 return mIsValid ? Qt::gray : QColor( 134, 0, 0 );
1191QColor QgsModelChildAlgorithmGraphicItem::textColor( QgsModelComponentGraphicItem::State )
const
1193 return mIsValid ? ( qgis::down_cast<const QgsProcessingModelChildAlgorithm *>( component() )->isActive() ? Qt::black : Qt::gray ) : QColor( 255, 255, 255 );
1196QColor QgsModelChildAlgorithmGraphicItem::outlineColor()
const
1200 return QColor( 150, 150, 0 );
1203 switch ( mResults.executionStatus() )
1208 return QColor( 150, 150, 150 );
1212 return QColor( 55, 160, 55 );
1214 return QColor( 208, 0, 0 );
1219QPixmap QgsModelChildAlgorithmGraphicItem::iconPixmap()
const
1224QPicture QgsModelChildAlgorithmGraphicItem::iconPicture()
const
1229int QgsModelChildAlgorithmGraphicItem::linkPointCount( Qt::Edge edge )
const
1231 if (
const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( component() ) )
1233 if ( !child->algorithm() )
1238 case Qt::BottomEdge:
1239 return child->algorithm()->outputDefinitions().size();
1244 std::remove_if( params.begin(), params.end(), [](
const QgsProcessingParameterDefinition *param ) { return param->flags() & Qgis::ProcessingParameterFlag::Hidden || param->isDestination(); } ),
1247 return params.size();
1258QColor QgsModelComponentGraphicItem::linkColor( Qt::Edge edge,
int index )
const
1260 if (
const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( component() ) )
1262 if ( !child->algorithm() )
1264 return FALLBACK_COLOR;
1269 case Qt::BottomEdge:
1271 if ( index <= child->
algorithm()->outputDefinitions().size() - 1 )
1273 return child->algorithm()->outputDefinitions().at( index )->modelColor();
1275 return FALLBACK_COLOR;
1281 if ( index <= params.size() - 1 )
1283 return params.at( index )->modelColor();
1286 return FALLBACK_COLOR;
1295 return FALLBACK_COLOR;
1298QString QgsModelChildAlgorithmGraphicItem::linkPointText( Qt::Edge edge,
int index )
const
1303 if (
const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( component() ) )
1305 if ( !child->algorithm() )
1310 case Qt::BottomEdge:
1312 if ( index >= child->algorithm()->outputDefinitions().length() )
1321 return truncatedTextForItem( title );
1328 std::remove_if( params.begin(), params.end(), [](
const QgsProcessingParameterDefinition *param ) { return param->flags() & Qgis::ProcessingParameterFlag::Hidden || param->isDestination(); } ),
1332 if ( index >= params.length() )
1340 QString name = param->
name();
1342 QgsProcessingModelChildParameterSources paramSources = child->parameterSources().value( name );
1343 QString parameterValueAsString;
1345 if ( !paramSources.empty() )
1347 QgsProcessingModelChildParameterSource firstParameterSource = paramSources[0];
1349 switch ( firstParameterSource.source() )
1352 parameterValueAsString = u
": %1"_s.arg( firstParameterSource.friendlyIdentifier(
const_cast<QgsProcessingModelAlgorithm *
>( model() ) ) );
1356 parameterValueAsString = u
": %1"_s.arg( firstParameterSource.expression() );
1361 parameterValueAsString = u
": %1"_s.arg( firstParameterSource.expressionText() );
1366 parameterValueAsString = u
": <%1>"_s.arg( firstParameterSource.friendlyIdentifier(
const_cast<QgsProcessingModelAlgorithm *
>( model() ) ) );
1371 const QString friendlyName = firstParameterSource.friendlyIdentifier(
const_cast<QgsProcessingModelAlgorithm *
>( model() ) );
1372 parameterValueAsString = friendlyName.isEmpty() ? u
":"_s : u
": <%1>"_s.arg( friendlyName );
1377 const QVariant paramValue = paramSources[0].staticValue();
1380 title += parameterValueAsString;
1383 return truncatedTextForItem( title );
1394void QgsModelChildAlgorithmGraphicItem::updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
1396 if ( QgsProcessingModelChildAlgorithm *child =
dynamic_cast<QgsProcessingModelChildAlgorithm *
>( component() ) )
1398 model()->childAlgorithm( child->childId() ).setPosition( pos );
1399 model()->childAlgorithm( child->childId() ).setSize( size );
1403bool QgsModelChildAlgorithmGraphicItem::canDeleteComponent()
1405 if (
const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( component() ) )
1407 return model()->dependentChildAlgorithms( child->childId() ).empty();
1414 if ( mResults == results )
1418 const QList< QgsModelArrowItem * > arrows = outgoingArrows();
1421 for ( QgsModelArrowItem *arrow : arrows )
1423 arrow->setShowBadge(
false );
1428 if (
const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( component() ) )
1432 const QVariantMap outputs = results.
outputs();
1433 for (
auto it = outputs.constBegin(); it != outputs.constEnd(); ++it )
1440 const int index = indexForOutput( it.key() );
1443 for ( QgsModelArrowItem *arrow : arrows )
1445 if ( arrow->startIndex() == index && arrow->startEdge() == Qt::BottomEdge )
1447 arrow->setShowBadge(
true );
1448 arrow->badgeItem()->setValue( it.value() );
1460 emit updateArrowPaths();
1463void QgsModelChildAlgorithmGraphicItem::setSourceFeatureCount(
const QString ¶meterName,
long long featureCount )
1465 const int index = indexForInput( parameterName );
1469 const QList< QgsModelArrowItem * > arrows = incomingArrows();
1470 for ( QgsModelArrowItem *arrow : arrows )
1472 if ( arrow->endIndex() == index && arrow->endEdge() == Qt::TopEdge )
1474 arrow->setShowBadge(
true );
1475 arrow->badgeItem()->setValue( featureCount );
1480void QgsModelChildAlgorithmGraphicItem::setSinkFeatureCount(
const QString &outputName,
long long featureCount )
1482 const int index = indexForOutput( outputName );
1486 const QList< QgsModelArrowItem * > arrows = outgoingArrows();
1487 for ( QgsModelArrowItem *arrow : arrows )
1489 if ( arrow->startIndex() == index && arrow->startEdge() == Qt::BottomEdge )
1491 arrow->setShowBadge(
true );
1492 arrow->badgeItem()->setValue( featureCount );
1497void QgsModelChildAlgorithmGraphicItem::setProgress(
double progress )
1499 if ( mProgress == progress )
1502 mProgress = progress;
1506void QgsModelChildAlgorithmGraphicItem::setStarted()
1512void QgsModelChildAlgorithmGraphicItem::setOutdated()
1518int QgsModelChildAlgorithmGraphicItem::indexForInput(
const QString ¶meterName )
const
1520 if (
const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( component() ) )
1530int QgsModelChildAlgorithmGraphicItem::indexForOutput(
const QString &output )
const
1532 if (
const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( component() ) )
1542void QgsModelChildAlgorithmGraphicItem::paintBackground( QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget )
1544 if ( mProgress < 0 )
1546 QgsModelComponentGraphicItem::paintBackground( painter, option, widget );
1550 paintOutline( painter, option, widget );
1552 const QRectF rect = itemRect();
1555 if ( component()->color().isValid() )
1557 color = component()->color();
1561 color = color.darker( 110 );
1564 color = color.darker( 105 );
1570 stroke = color.darker( 110 );
1574 color = fillColor( state() );
1575 stroke = strokeColor( state() );
1578 QPen strokePen = QPen( stroke, 0 );
1579 strokePen.setStyle( strokeStyle( state() ) );
1580 painter->setPen( strokePen );
1582 const QColor colorLeft = color.darker( 120 );
1583 QColor colorRight = color;
1585 constexpr double fadeSize = 5;
1586 const double fadeSizeProportionRect = fadeSize / rect.width();
1588 if ( mProgress < 98 )
1590 QLinearGradient gradient( rect.topLeft(), rect.topRight() );
1591 gradient.setColorAt( 0.0, colorLeft );
1592 gradient.setColorAt( std::max( 0.0, mProgress / 100 - fadeSizeProportionRect / 2 ), colorLeft );
1593 gradient.setColorAt( std::min( 1.0, mProgress / 100 + fadeSizeProportionRect / 2 ), colorRight );
1594 gradient.setColorAt( 1.0, colorRight );
1596 painter->setBrush( QBrush( gradient ) );
1600 painter->setBrush( QBrush( colorLeft ) );
1602 painter->drawRect( rect );
1605void QgsModelChildAlgorithmGraphicItem::deleteComponent()
1607 if (
const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( component() ) )
1609 emit aboutToChange( tr(
"Remove %1" ).arg( child->algorithm() ? child->algorithm()->displayName() : tr(
"Algorithm" ) ) );
1610 if ( !model()->removeChildAlgorithm( child->childId() ) )
1612 QMessageBox::warning(
1614 QObject::tr(
"Could not remove algorithm" ),
1616 "Other algorithms depend on the selected one.\n"
1617 "Remove them before trying to remove it."
1624 emit requestModelRepaint();
1629void QgsModelChildAlgorithmGraphicItem::deactivateAlgorithm()
1631 if (
const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( component() ) )
1633 model()->deactivateChildAlgorithm( child->childId() );
1634 emit requestModelRepaint();
1638void QgsModelChildAlgorithmGraphicItem::activateAlgorithm()
1640 if (
const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( component() ) )
1642 if ( model()->activateChildAlgorithm( child->childId() ) )
1644 emit requestModelRepaint();
1648 QMessageBox::warning(
1650 QObject::tr(
"Could not activate algorithm" ),
1652 "The selected algorithm depends on other currently non-active algorithms.\n"
1653 "Activate them them before trying to activate it.."
1661QgsModelOutputGraphicItem::QgsModelOutputGraphicItem( QgsProcessingModelOutput *output, QgsProcessingModelAlgorithm *model, QGraphicsItem *parent )
1662 : QgsModelComponentGraphicItem( output, model, parent )
1665 QPainter painter( &mPicture );
1666 svg.render( &painter );
1668 setLabel( output->description() );
1671QColor QgsModelOutputGraphicItem::fillColor( QgsModelComponentGraphicItem::State state )
const
1673 QColor
c( 172, 196, 114 );
1677 c =
c.darker( 110 );
1680 c =
c.darker( 105 );
1689QColor QgsModelOutputGraphicItem::strokeColor( QgsModelComponentGraphicItem::State state )
const
1694 return QColor( 42, 65, 42 );
1697 return QColor( 90, 140, 90 );
1702QColor QgsModelOutputGraphicItem::textColor( QgsModelComponentGraphicItem::State )
const
1707QPicture QgsModelOutputGraphicItem::iconPicture()
const
1712void QgsModelOutputGraphicItem::updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
1714 if ( QgsProcessingModelOutput *output =
dynamic_cast<QgsProcessingModelOutput *
>( component() ) )
1716 model()->childAlgorithm( output->childId() ).modelOutput( output->name() ).setPosition( pos );
1717 model()->childAlgorithm( output->childId() ).modelOutput( output->name() ).setSize( size );
1721bool QgsModelOutputGraphicItem::canDeleteComponent()
1723 if (
dynamic_cast<const QgsProcessingModelOutput *
>( component() ) )
1730void QgsModelOutputGraphicItem::deleteComponent()
1732 if (
const QgsProcessingModelOutput *output =
dynamic_cast<const QgsProcessingModelOutput *
>( component() ) )
1734 emit aboutToChange( tr(
"Delete Output %1" ).arg( output->description() ) );
1735 model()->childAlgorithm( output->childId() ).removeModelOutput( output->name() );
1736 model()->updateDestinationParameters();
1738 emit requestModelRepaint();
1747QgsModelGroupBoxGraphicItem::QgsModelGroupBoxGraphicItem( QgsProcessingModelGroupBox *box, QgsProcessingModelAlgorithm *model, QGraphicsItem *parent )
1748 : QgsModelComponentGraphicItem( box, model, parent )
1750 setZValue( QgsModelGraphicsScene::ZValues::GroupBox );
1751 setLabel( box->description() );
1755 f.setPixelSize( 14 );
1759void QgsModelGroupBoxGraphicItem::contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
1761 QMenu *popupmenu =
new QMenu( event->widget() );
1762 QAction *removeAction = popupmenu->addAction( QObject::tr(
"Remove" ) );
1763 connect( removeAction, &QAction::triggered,
this, &QgsModelGroupBoxGraphicItem::deleteComponent );
1764 QAction *editAction = popupmenu->addAction( QObject::tr(
"Edit…" ) );
1765 connect( editAction, &QAction::triggered,
this, &QgsModelGroupBoxGraphicItem::editComponent );
1766 popupmenu->exec( event->screenPos() );
1769QgsModelGroupBoxGraphicItem::~QgsModelGroupBoxGraphicItem() =
default;
1771QColor QgsModelGroupBoxGraphicItem::fillColor( QgsModelComponentGraphicItem::State state )
const
1773 QColor
c( 230, 230, 230 );
1777 c =
c.darker( 110 );
1780 c =
c.darker( 105 );
1789QColor QgsModelGroupBoxGraphicItem::strokeColor( QgsModelComponentGraphicItem::State state )
const
1794 return QColor( 50, 50, 50 );
1797 return QColor( 150, 150, 150 );
1802QColor QgsModelGroupBoxGraphicItem::textColor( QgsModelComponentGraphicItem::State )
const
1804 return QColor( 100, 100, 100 );
1807Qt::PenStyle QgsModelGroupBoxGraphicItem::strokeStyle( QgsModelComponentGraphicItem::State )
const
1812Qt::Alignment QgsModelGroupBoxGraphicItem::titleAlignment()
const
1814 return Qt::AlignHCenter;
1817void QgsModelGroupBoxGraphicItem::updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
1819 if ( QgsProcessingModelGroupBox *box =
dynamic_cast<QgsProcessingModelGroupBox *
>( component() ) )
1821 box->setPosition( pos );
1822 box->setSize( size );
1823 model()->addGroupBox( *box );
1827bool QgsModelGroupBoxGraphicItem::canDeleteComponent()
1829 if (
dynamic_cast<QgsProcessingModelGroupBox *
>( component() ) )
1836void QgsModelGroupBoxGraphicItem::applyEdit(
const QgsProcessingModelGroupBox &groupBox )
1838 const QString commandId = u
"groupbox:%1"_s.arg( groupBox.uuid() );
1839 emit aboutToChange( tr(
"Edit Group Box" ), commandId );
1840 model()->addGroupBox( groupBox );
1842 emit requestModelRepaint();
1845void QgsModelGroupBoxGraphicItem::deleteComponent()
1847 if (
const QgsProcessingModelGroupBox *box =
dynamic_cast<const QgsProcessingModelGroupBox *
>( component() ) )
1849 emit aboutToChange( tr(
"Delete Group Box" ) );
1850 model()->removeGroupBox( box->uuid() );
1852 emit requestModelRepaint();
1856void QgsModelGroupBoxGraphicItem::editComponent()
1858 if (
const QgsProcessingModelGroupBox *box =
dynamic_cast<const QgsProcessingModelGroupBox *
>( component() ) )
1864 applyEdit( dlg.groupBox() );
1873QgsModelCommentGraphicItem::QgsModelCommentGraphicItem( QgsProcessingModelComment *comment, QgsModelComponentGraphicItem *parentItem, QgsProcessingModelAlgorithm *model, QGraphicsItem *parent )
1874 : QgsModelComponentGraphicItem( comment, model, parent )
1875 , mParentComponent( parentItem->component()->clone() )
1876 , mParentItem( parentItem )
1878 setLabel( comment->description() );
1881 f.setPixelSize( 9 );
1885void QgsModelCommentGraphicItem::contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
1887 QMenu *popupmenu =
new QMenu( event->widget() );
1888 QAction *removeAction = popupmenu->addAction( QObject::tr(
"Remove" ) );
1889 connect( removeAction, &QAction::triggered,
this, &QgsModelCommentGraphicItem::deleteComponent );
1890 QAction *editAction = popupmenu->addAction( QObject::tr(
"Edit…" ) );
1891 connect( editAction, &QAction::triggered,
this, &QgsModelCommentGraphicItem::editComponent );
1892 popupmenu->exec( event->screenPos() );
1895QgsModelCommentGraphicItem::~QgsModelCommentGraphicItem() =
default;
1897QColor QgsModelCommentGraphicItem::fillColor( QgsModelComponentGraphicItem::State state )
const
1899 QColor
c( 230, 230, 230 );
1903 c =
c.darker( 110 );
1906 c =
c.darker( 105 );
1915QColor QgsModelCommentGraphicItem::strokeColor( QgsModelComponentGraphicItem::State state )
const
1920 return QColor( 50, 50, 50 );
1923 return QColor( 150, 150, 150 );
1928QColor QgsModelCommentGraphicItem::textColor( QgsModelComponentGraphicItem::State )
const
1930 return QColor( 100, 100, 100 );
1933Qt::PenStyle QgsModelCommentGraphicItem::strokeStyle( QgsModelComponentGraphicItem::State )
const
1938void QgsModelCommentGraphicItem::updateStoredComponentPosition(
const QPointF &pos,
const QSizeF &size )
1940 if ( QgsProcessingModelComment *comment = modelComponent() )
1942 comment->setPosition( pos );
1943 comment->setSize( size );
1947bool QgsModelCommentGraphicItem::canDeleteComponent()
1949 if ( modelComponent() )
1956void QgsModelCommentGraphicItem::deleteComponent()
1958 if ( QgsProcessingModelComment *comment = modelComponent() )
1960 emit aboutToChange( tr(
"Delete Comment" ) );
1961 comment->setDescription( QString() );
1963 emit requestModelRepaint();
1967void QgsModelCommentGraphicItem::editComponent()
1971 mParentItem->editComment();
1975QgsProcessingModelComment *QgsModelCommentGraphicItem::modelComponent()
1977 if (
const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( mParentComponent.get() ) )
1979 return model()->childAlgorithm( child->childId() ).comment();
1981 else if (
const QgsProcessingModelParameter *param =
dynamic_cast<const QgsProcessingModelParameter *
>( mParentComponent.get() ) )
1983 return model()->parameterComponent( param->parameterName() ).comment();
1985 else if (
const QgsProcessingModelOutput *output =
dynamic_cast<const QgsProcessingModelOutput *
>( mParentComponent.get() ) )
1987 return model()->childAlgorithm( output->childId() ).modelOutput( output->name() ).comment();
1992QgsModelComponentGraphicItem *QgsModelCommentGraphicItem::parentComponentItem()
const
@ Success
Child was successfully executed.
@ NotExecuted
Child has not been executed.
@ Failed
Child encountered an error while executing.
@ Warning
Warning message.
@ ExpressionText
Parameter value is taken from a text with expressions, evaluated just before the algorithm runs.
@ ModelOutput
Parameter value is linked to an output parameter for the model.
@ ChildOutput
Parameter value is taken from an output generated by a child algorithm.
@ ModelParameter
Parameter value is taken from a parent model parameter.
@ StaticValue
Parameter value is a static value.
@ Expression
Parameter value is taken from an expression, evaluated just before the algorithm runs.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
A dialog which allows users to specify the properties of a model group box.
A mouse event which is the result of a user interaction with a QgsModelGraphicsView.
QPointF modelPoint() const
Returns the event point location in model coordinates.
Abstract base class for processing algorithms.
Encapsulates the results of running a child algorithm within a model.
QVariantMap outputs() const
Returns the outputs generated by the child algorithm.
Qgis::ProcessingModelChildAlgorithmExecutionStatus executionStatus() const
Returns the status of executing the child algorithm.
Base class for the definition of processing outputs.
QString description() const
Returns the description for the output.
Base class for the definition of processing parameters.
virtual QString userFriendlyString(const QVariant &value) const
Returns a user-friendly string representation of the provided parameter value.
QString description() const
Returns the description for the parameter.
QString name() const
Returns the name of the parameter.
static int parameterDefinitionIndex(const QgsProcessingAlgorithm *algorithm, const QString &name)
Returns the index of the parameter with matching name for a specified algorithm.
static int outputDefinitionIndex(const QgsProcessingAlgorithm *algorithm, const QString &name)
Returns the index of the output matching name for a specified algorithm.
A rectangle specified with double values.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
#define Q_NOWARN_DEPRECATED_POP
#define BUILTIN_UNREACHABLE
#define Q_NOWARN_DEPRECATED_PUSH
QList< const QgsProcessingParameterDefinition * > QgsProcessingParameterDefinitions
List of processing parameters.