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(
184 QgsModelComponentGraphicItem *parent, QgsProcessingModelComponent *component,
int index,
const QPointF &position, Qt::Edge edge,
const QSizeF &size
186 : QgsModelDesignerFlatButtonGraphicItem( parent, QPicture(), position, size )
187 , mComponentItem( parent )
188 , mComponent( component )
193void QgsModelDesignerSocketGraphicItem::paint( QPainter *painter,
const QStyleOptionGraphicsItem *, QWidget * )
195 QColor outlineColor = socketColor();
196 QColor fillColor = QColor( outlineColor );
200 fillColor.setAlpha( isDefaultParameterValue() ? 30 : 255 );
205 fillColor.setAlpha( 255 );
209 painter->setPen( QPen( outlineColor, mHoverState ? mSocketOutlineWidth * 2 : mSocketOutlineWidth ) );
212 painter->setBrush( QBrush( fillColor, Qt::SolidPattern ) );
214 painter->setRenderHint( QPainter::Antialiasing );
217 constexpr float DISPLAY_SIZE = 4;
220 constexpr float ELLIPSE_OFFSET = 0.4;
221 QPointF ellipsePosition = QPointF( position().x() + ELLIPSE_OFFSET, position().y() + ELLIPSE_OFFSET );
222 painter->drawEllipse( ellipsePosition, DISPLAY_SIZE, DISPLAY_SIZE );
227 painter->setPen( QPen() );
228 painter->setBrush( QBrush() );
229 painter->drawRect( boundingRect() );
235QColor QgsModelDesignerSocketGraphicItem::socketColor()
const
237 return mComponentItem->linkColor( mEdge, mIndex );
241bool QgsModelDesignerSocketGraphicItem::isDefaultParameterValue()
const
248 const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( mComponent );
255 bool isDefaultValue =
true;
258 if ( child->algorithm() )
270 const QString name = param->
name();
272 QgsProcessingModelChildParameterSources paramSources = child->parameterSources().value( name );
273 if ( paramSources.empty() )
281 isDefaultValue =
false;
285 isDefaultValue = paramSources[0].staticValue() == param->
defaultValue();
297 return isDefaultValue;
301QgsModelDesignerFeatureCountGraphicItem::QgsModelDesignerFeatureCountGraphicItem( QgsModelArrowItem *link,
const QString &text )
302 : QGraphicsTextItem( text )
305 connect( link, &QgsModelArrowItem::painterPathUpdated,
this, &QgsModelDesignerFeatureCountGraphicItem::setPosition );
307 QFont font = this->font();
308 font.setPointSize( FONT_SIZE );
311 setZValue( QgsModelGraphicsScene::ZValues::ArrowDecoration );
315void QgsModelDesignerFeatureCountGraphicItem::paint( QPainter *painter,
const QStyleOptionGraphicsItem *itemStyle, QWidget *widget )
317 const bool isDarkTheme = QApplication::palette().color( QPalette::Window ).lightness() < 128;
318 QPalette::ColorRole bgPalette = isDarkTheme ? QPalette::Dark : QPalette::Light;
321 QColor backgroundColor = QApplication::palette().color( bgPalette );
322 backgroundColor.setAlpha( 220 );
323 painter->setBrush( QBrush( backgroundColor ) );
324 painter->setPen( Qt::PenStyle::NoPen );
325 constexpr double RADIUS = 5;
326 painter->drawRoundedRect( boundingRect(), RADIUS, RADIUS );
329 setDefaultTextColor( QApplication::palette().color( QPalette::Text ) );
330 QGraphicsTextItem::paint( painter, itemStyle, widget );
333void QgsModelDesignerFeatureCountGraphicItem::setPosition()
335 QPointF middlePos = mLink->path().pointAtPercent( 0.5 );
336 QRectF rect = boundingRect();
337 QPointF offset = rect.center();
338 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.