30#include <QGraphicsSceneMouseEvent>
33#include <QSvgRenderer>
35#include "moc_qgsmodelgraphicitem.cpp"
37using namespace Qt::StringLiterals;
41QgsModelDesignerFlatButtonGraphicItem::QgsModelDesignerFlatButtonGraphicItem( QGraphicsItem *parent,
const QPicture &picture,
const QPointF &position,
const QSizeF &size )
42 : QGraphicsObject( parent )
44 , mPosition( position )
47 setAcceptHoverEvents(
true );
48 setFlag( QGraphicsItem::ItemIsMovable,
false );
49 setCacheMode( QGraphicsItem::DeviceCoordinateCache );
52void QgsModelDesignerFlatButtonGraphicItem::paint( QPainter *painter,
const QStyleOptionGraphicsItem *, QWidget * )
54 if ( QgsModelGraphicsScene *modelScene = qobject_cast<QgsModelGraphicsScene *>( scene() ) )
56 if ( modelScene->flags() & QgsModelGraphicsScene::FlagHideControls )
62 painter->setPen( QPen( Qt::transparent, 1.0 ) );
63 painter->setBrush( QBrush( QColor( 55, 55, 55, 33 ), Qt::SolidPattern ) );
67 painter->setPen( QPen( Qt::transparent, 1.0 ) );
68 painter->setBrush( QBrush( Qt::transparent, Qt::SolidPattern ) );
70 const QPointF topLeft = mPosition - QPointF( std::floor( mSize.width() / 2 ), std::floor( mSize.height() / 2 ) );
71 const QRectF rect = QRectF( topLeft.x(), topLeft.y(), mSize.width(), mSize.height() );
72 painter->drawRect( rect );
73 painter->drawPicture( topLeft.x(), topLeft.y(), mPicture );
76QRectF QgsModelDesignerFlatButtonGraphicItem::boundingRect()
const
78 return QRectF( mPosition.x() - std::floor( mSize.width() / 2 ), mPosition.y() - std::floor( mSize.height() / 2 ), mSize.width(), mSize.height() );
81void QgsModelDesignerFlatButtonGraphicItem::hoverEnterEvent( QGraphicsSceneHoverEvent * )
83 if ( view()->tool() && !view()->tool()->allowItemInteraction() )
90void QgsModelDesignerFlatButtonGraphicItem::hoverLeaveEvent( QGraphicsSceneHoverEvent * )
96void QgsModelDesignerFlatButtonGraphicItem::mousePressEvent( QGraphicsSceneMouseEvent * )
98 if ( view()->tool() && view()->tool()->allowItemInteraction() )
104 if ( view()->tool() && !view()->tool()->allowItemInteraction() )
119 if ( view()->tool() && view()->tool()->allowItemInteraction() && event->button() == Qt::LeftButton )
121 QMetaObject::invokeMethod(
this,
"clicked", Qt::QueuedConnection );
127void QgsModelDesignerFlatButtonGraphicItem::setPosition(
const QPointF &position )
129 mPosition = position;
130 prepareGeometryChange();
134QgsModelGraphicsView *QgsModelDesignerFlatButtonGraphicItem::view()
136 return qobject_cast<QgsModelGraphicsView *>( scene()->views().first() );
139void QgsModelDesignerFlatButtonGraphicItem::setPicture(
const QPicture &picture )
149QgsModelDesignerFoldButtonGraphicItem::QgsModelDesignerFoldButtonGraphicItem( QGraphicsItem *parent,
bool folded,
const QPointF &position,
const QSizeF &size )
150 : QgsModelDesignerFlatButtonGraphicItem( parent, QPicture(), position, size )
154 QPainter painter( &mPlusPicture );
155 svg.render( &painter );
159 painter.begin( &mMinusPicture );
160 svg2.render( &painter );
163 setPicture( mFolded ? mPlusPicture : mMinusPicture );
166void QgsModelDesignerFoldButtonGraphicItem::mousePressEvent( QGraphicsSceneMouseEvent *event )
169 setPicture( mFolded ? mPlusPicture : mMinusPicture );
170 emit folded( mFolded );
171 QgsModelDesignerFlatButtonGraphicItem::mousePressEvent( event );
177 setPicture( mFolded ? mPlusPicture : mMinusPicture );
178 emit folded( mFolded );
179 QgsModelDesignerFlatButtonGraphicItem::modelPressEvent( event );
183QgsModelDesignerSocketGraphicItem::QgsModelDesignerSocketGraphicItem( QgsModelComponentGraphicItem *parent, QgsProcessingModelComponent *component,
int index,
const QPointF &position, Qt::Edge edge,
const QSizeF &size )
184 : QgsModelDesignerFlatButtonGraphicItem( parent, QPicture(), position, size )
185 , mComponentItem( parent )
186 , mComponent( component )
192void QgsModelDesignerSocketGraphicItem::paint( QPainter *painter,
const QStyleOptionGraphicsItem *, QWidget * )
194 QColor outlineColor = socketColor();
195 QColor fillColor = QColor( outlineColor );
199 fillColor.setAlpha( isDefaultParameterValue() ? 30 : 255 );
204 fillColor.setAlpha( 255 );
208 painter->setPen( QPen( outlineColor, mHoverState ? mSocketOutlineWidth * 2 : mSocketOutlineWidth ) );
211 painter->setBrush( QBrush( fillColor, Qt::SolidPattern ) );
213 painter->setRenderHint( QPainter::Antialiasing );
216 constexpr float DISPLAY_SIZE = 4;
219 constexpr float ELLIPSE_OFFSET = 0.4;
220 QPointF ellipsePosition = QPointF( position().x() + ELLIPSE_OFFSET, position().y() + ELLIPSE_OFFSET );
221 painter->drawEllipse( ellipsePosition, DISPLAY_SIZE, DISPLAY_SIZE );
226 painter->setPen( QPen() );
227 painter->setBrush( QBrush() );
228 painter->drawRect( boundingRect() );
234QColor QgsModelDesignerSocketGraphicItem::socketColor()
const
236 return mComponentItem->linkColor( mEdge, mIndex );
240bool QgsModelDesignerSocketGraphicItem::isDefaultParameterValue()
const
247 const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( mComponent );
254 bool isDefaultValue =
true;
257 if ( child->algorithm() )
269 const QString name = param->
name();
271 QgsProcessingModelChildParameterSources paramSources = child->parameterSources().value( name );
272 if ( paramSources.empty() )
280 isDefaultValue =
false;
284 isDefaultValue = paramSources[0].staticValue() == param->
defaultValue();
296 return isDefaultValue;
300QgsModelDesignerFeatureCountGraphicItem::QgsModelDesignerFeatureCountGraphicItem( QgsModelArrowItem *link,
const QString &text )
301 : QGraphicsTextItem( text )
304 connect( link, &QgsModelArrowItem::painterPathUpdated,
this, &QgsModelDesignerFeatureCountGraphicItem::setPosition );
306 QFont font = this->font();
307 font.setPointSize( FONT_SIZE );
310 setZValue( QgsModelGraphicsScene::ZValues::ArrowDecoration );
314void QgsModelDesignerFeatureCountGraphicItem::paint( QPainter *painter,
const QStyleOptionGraphicsItem *itemStyle, QWidget *widget )
316 const bool isDarkTheme = QApplication::palette().color( QPalette::Window ).lightness() < 128;
317 QPalette::ColorRole bgPalette = isDarkTheme ? QPalette::Dark : QPalette::Light;
320 QColor backgroundColor = QApplication::palette().color( bgPalette );
321 backgroundColor.setAlpha( 220 );
322 painter->setBrush( QBrush( backgroundColor ) );
323 painter->setPen( Qt::PenStyle::NoPen );
324 constexpr double RADIUS = 5;
325 painter->drawRoundedRect( boundingRect(), RADIUS, RADIUS );
328 setDefaultTextColor( QApplication::palette().color( QPalette::Text ) );
329 QGraphicsTextItem::paint( painter, itemStyle, widget );
332void QgsModelDesignerFeatureCountGraphicItem::setPosition()
334 QPointF middlePos = mLink->path().pointAtPercent( 0.5 );
335 QRectF rect = boundingRect();
336 QPointF offset = rect.center();
337 setPos( middlePos - offset );
@ StaticValue
Parameter value is a static value.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
A mouse event which is the result of a user interaction with a QgsModelGraphicsView.
Base class for the definition of processing parameters.
QVariant defaultValue() const
Returns the default value for the parameter.
QString name() const
Returns the name of the parameter.
QList< const QgsProcessingParameterDefinition * > QgsProcessingParameterDefinitions
List of processing parameters.