30#include <QGraphicsSceneMouseEvent>
32#include <QSvgRenderer>
34#include "moc_qgsmodelgraphicitem.cpp"
38QgsModelDesignerFlatButtonGraphicItem::QgsModelDesignerFlatButtonGraphicItem( QGraphicsItem *parent,
const QPicture &picture,
const QPointF &position,
const QSizeF &size )
39 : QGraphicsObject( parent )
41 , mPosition( position )
44 setAcceptHoverEvents(
true );
45 setFlag( QGraphicsItem::ItemIsMovable,
false );
46 setCacheMode( QGraphicsItem::DeviceCoordinateCache );
49void QgsModelDesignerFlatButtonGraphicItem::paint( QPainter *painter,
const QStyleOptionGraphicsItem *, QWidget * )
51 if ( QgsModelGraphicsScene *modelScene = qobject_cast<QgsModelGraphicsScene *>( scene() ) )
53 if ( modelScene->flags() & QgsModelGraphicsScene::FlagHideControls )
59 painter->setPen( QPen( Qt::transparent, 1.0 ) );
60 painter->setBrush( QBrush( QColor( 55, 55, 55, 33 ), Qt::SolidPattern ) );
64 painter->setPen( QPen( Qt::transparent, 1.0 ) );
65 painter->setBrush( QBrush( Qt::transparent, Qt::SolidPattern ) );
67 const QPointF topLeft = mPosition - QPointF( std::floor( mSize.width() / 2 ), std::floor( mSize.height() / 2 ) );
68 const QRectF rect = QRectF( topLeft.x(), topLeft.y(), mSize.width(), mSize.height() );
69 painter->drawRect( rect );
70 painter->drawPicture( topLeft.x(), topLeft.y(), mPicture );
73QRectF QgsModelDesignerFlatButtonGraphicItem::boundingRect()
const
75 return QRectF( mPosition.x() - std::floor( mSize.width() / 2 ), mPosition.y() - std::floor( mSize.height() / 2 ), mSize.width(), mSize.height() );
78void QgsModelDesignerFlatButtonGraphicItem::hoverEnterEvent( QGraphicsSceneHoverEvent * )
80 if ( view()->tool() && !view()->tool()->allowItemInteraction() )
87void QgsModelDesignerFlatButtonGraphicItem::hoverLeaveEvent( QGraphicsSceneHoverEvent * )
93void QgsModelDesignerFlatButtonGraphicItem::mousePressEvent( QGraphicsSceneMouseEvent * )
95 if ( view()->tool() && view()->tool()->allowItemInteraction() )
101 if ( view()->tool() && !view()->tool()->allowItemInteraction() )
116 if ( view()->tool() && view()->tool()->allowItemInteraction() && event->button() == Qt::LeftButton )
118 QMetaObject::invokeMethod(
this,
"clicked", Qt::QueuedConnection );
124void QgsModelDesignerFlatButtonGraphicItem::setPosition(
const QPointF &position )
126 mPosition = position;
127 prepareGeometryChange();
131QgsModelGraphicsView *QgsModelDesignerFlatButtonGraphicItem::view()
133 return qobject_cast<QgsModelGraphicsView *>( scene()->views().first() );
136void QgsModelDesignerFlatButtonGraphicItem::setPicture(
const QPicture &picture )
146QgsModelDesignerFoldButtonGraphicItem::QgsModelDesignerFoldButtonGraphicItem( QGraphicsItem *parent,
bool folded,
const QPointF &position,
const QSizeF &size )
147 : QgsModelDesignerFlatButtonGraphicItem( parent, QPicture(), position, size )
151 QPainter painter( &mPlusPicture );
152 svg.render( &painter );
156 painter.begin( &mMinusPicture );
157 svg2.render( &painter );
160 setPicture( mFolded ? mPlusPicture : mMinusPicture );
163void QgsModelDesignerFoldButtonGraphicItem::mousePressEvent( QGraphicsSceneMouseEvent *event )
166 setPicture( mFolded ? mPlusPicture : mMinusPicture );
167 emit folded( mFolded );
168 QgsModelDesignerFlatButtonGraphicItem::mousePressEvent( event );
174 setPicture( mFolded ? mPlusPicture : mMinusPicture );
175 emit folded( mFolded );
176 QgsModelDesignerFlatButtonGraphicItem::modelPressEvent( event );
180QgsModelDesignerSocketGraphicItem::QgsModelDesignerSocketGraphicItem( QgsModelComponentGraphicItem *parent, QgsProcessingModelComponent *component,
int index,
const QPointF &position, Qt::Edge edge,
const QSizeF &size )
181 : QgsModelDesignerFlatButtonGraphicItem( parent, QPicture(), position, size )
182 , mComponentItem( parent )
183 , mComponent( component )
189void QgsModelDesignerSocketGraphicItem::paint( QPainter *painter,
const QStyleOptionGraphicsItem *, QWidget * )
191 QColor outlineColor = socketColor();
192 QColor fillColor = QColor( outlineColor );
196 fillColor.setAlpha( isDefaultParameterValue() ? 30 : 255 );
201 fillColor.setAlpha( 255 );
205 painter->setPen( QPen( outlineColor, mHoverState ? mSocketOutlineWidth * 2 : mSocketOutlineWidth ) );
208 painter->setBrush( QBrush( fillColor, Qt::SolidPattern ) );
210 painter->setRenderHint( QPainter::Antialiasing );
213 constexpr float DISPLAY_SIZE = 4;
216 constexpr float ELLIPSE_OFFSET = 0.4;
217 QPointF ellipsePosition = QPointF( position().x() + ELLIPSE_OFFSET, position().y() + ELLIPSE_OFFSET );
218 painter->drawEllipse( ellipsePosition, DISPLAY_SIZE, DISPLAY_SIZE );
223 painter->setPen( QPen() );
224 painter->setBrush( QBrush() );
225 painter->drawRect( boundingRect() );
231QColor QgsModelDesignerSocketGraphicItem::socketColor()
const
233 return mComponentItem->linkColor( mEdge, mIndex );
237bool QgsModelDesignerSocketGraphicItem::isDefaultParameterValue()
const
244 const QgsProcessingModelChildAlgorithm *child =
dynamic_cast<const QgsProcessingModelChildAlgorithm *
>( mComponent );
251 bool isDefaultValue =
true;
254 if ( child->algorithm() )
266 const QString name = param->
name();
268 QgsProcessingModelChildParameterSources paramSources = child->parameterSources().value( name );
269 if ( paramSources.empty() )
277 isDefaultValue =
false;
281 isDefaultValue = paramSources[0].staticValue() == param->
defaultValue();
293 return isDefaultValue;
@ 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.