34 mBezierRubberBand->setBrush( QBrush( QColor( 0, 0, 0, 63 ) ) );
35 mBezierRubberBand->setPen( QPen( QBrush( QColor( 0, 0, 0, 100 ) ), 0, Qt::SolidLine ) );
40 mBezierRubberBand->update( event->
modelPoint(), Qt::KeyboardModifiers() );
45 QgsModelDesignerSocketGraphicItem *socket =
nullptr;
46 for ( QGraphicsItem *item : items )
48 if ( ( socket =
dynamic_cast<QgsModelDesignerSocketGraphicItem *
>( item ) )
49 && ( mFromSocket != socket && mFromSocket->edge() != socket->edge() ) )
52 socket->modelHoverEnterEvent( event );
53 QPointF rubberEndPos = socket->mapToScene( socket->position() );
54 mBezierRubberBand->update( rubberEndPos, Qt::KeyboardModifiers() );
60 if ( mLastHoveredSocket && socket != mLastHoveredSocket )
62 mLastHoveredSocket->modelHoverLeaveEvent( event );
63 mLastHoveredSocket =
nullptr;
66 if ( socket && socket != mLastHoveredSocket )
68 mLastHoveredSocket = socket;
74 if ( event->button() != Qt::LeftButton )
78 mBezierRubberBand->finish( event->
modelPoint() );
79 if ( mLastHoveredSocket )
81 mLastHoveredSocket->modelHoverLeaveEvent(
nullptr );
82 mLastHoveredSocket =
nullptr;
85 view()->setTool( mPreviousViewTool );
92 for ( QGraphicsItem *item : items )
94 if ( QgsModelDesignerSocketGraphicItem *socket =
dynamic_cast<QgsModelDesignerSocketGraphicItem *
>( item ) )
108 if ( mFromSocket->edge() == mToSocket->edge() )
113 view()->beginCommand( tr(
"Edit link" ) );
115 QList<QgsProcessingModelChildParameterSource> sources;
117 QgsProcessingModelComponent *componentFrom =
nullptr;
118 QgsProcessingModelChildAlgorithm *childTo =
nullptr;
128 if ( !mToSocket->isInput() )
130 std::swap( mFromSocket, mToSocket );
133 componentFrom = mFromSocket->component();
134 childTo =
dynamic_cast<QgsProcessingModelChildAlgorithm *
>( mToSocket->component() );
139 QgsProcessingModelChildParameterSource source;
140 if ( QgsProcessingModelChildAlgorithm *childFrom =
dynamic_cast<QgsProcessingModelChildAlgorithm *
>( componentFrom ) )
142 QString outputName = childFrom->algorithm()->outputDefinitions().at( mFromSocket->index() )->name();
143 source = QgsProcessingModelChildParameterSource::fromChildOutput( childFrom->childId(), outputName );
145 else if ( QgsProcessingModelParameter *paramFrom =
dynamic_cast<QgsProcessingModelParameter *
>( componentFrom ) )
147 source = QgsProcessingModelChildParameterSource::fromModelParameter( paramFrom->parameterName() );
150 QList<QgsProcessingModelChildParameterSource> compatibleParamSources =
scene()->model()->availableSourcesForChild( childTo->childId(), toParam );
152 if ( !compatibleParamSources.contains( source ) )
155 const QString title = tr(
"Sockets cannot be connected" );
156 const QString message = tr(
"Either the sockets are incompatible or there is a circular dependency" );
157 scene()->showWarning( message, title, message );
162 childTo->addParameterSources( toParam->
name(), sources );
166 scene()->model()->setChildAlgorithm( *childTo );
168 view()->endCommand();
170 scene()->requestRebuildRequired();
201 mFromSocket = socket;
203 if ( mFromSocket->isInput() )
205 QgsProcessingModelChildAlgorithm *childFrom =
dynamic_cast<QgsProcessingModelChildAlgorithm *
>( mFromSocket->component() );
208 auto currentSources = childFrom->parameterSources().value( param->
name() );
210 QgsProcessingModelChildParameterSource oldSource;
211 for (
const QgsProcessingModelChildParameterSource &source : std::as_const( currentSources ) )
213 switch ( source.source() )
219 view()->beginCommand( tr(
"Edit link" ) );
222 QList<QgsProcessingModelChildParameterSource> newSources;
223 newSources << QgsProcessingModelChildParameterSource::fromStaticValue( param->
defaultValue() );
226 childFrom->addParameterSources( param->
name(), newSources );
228 scene()->model()->setChildAlgorithm( *childFrom );
230 scene()->requestRebuildRequired();
233 QgsModelComponentGraphicItem *item =
nullptr;
234 int socketIndex = -1;
237 item =
scene()->childAlgorithmItem( oldSource.outputChildId() );
238 auto algSource =
dynamic_cast<QgsProcessingModelChildAlgorithm *
>( item->component() );
241 QgsDebugError( QStringLiteral(
"algSource not set, aborting!" ) );
248 item =
scene()->parameterItem( source.parameterName() );
254 QgsDebugError( QStringLiteral(
"item not set, aborting!" ) );
258 mFromSocket = item->outSocketAt( socketIndex );