49 mBezierRubberBand->update( event->
modelPoint(), Qt::KeyboardModifiers() );
52 const QList<QGraphicsItem *> items =
scene()->items( event->
modelPoint() );
54 QgsModelDesignerSocketGraphicItem *socket =
nullptr;
55 for ( QGraphicsItem *item : items )
57 socket =
dynamic_cast<QgsModelDesignerSocketGraphicItem *
>( item );
58 if ( !socket || mFromSocket == socket || mFromSocket->edge() == socket->edge() || mFromSocket->component() == socket->component() )
62 socket->modelHoverEnterEvent( event );
63 const QPointF rubberEndPos = socket->mapToScene( socket->position() );
64 mBezierRubberBand->update( rubberEndPos, Qt::KeyboardModifiers() );
68 if ( mLastHoveredSocket && socket != mLastHoveredSocket )
70 mLastHoveredSocket->modelHoverLeaveEvent( event );
71 mLastHoveredSocket =
nullptr;
74 if ( socket && socket != mLastHoveredSocket )
76 mLastHoveredSocket = socket;
82 if ( event->button() != Qt::LeftButton )
86 mBezierRubberBand->finish( event->
modelPoint() );
87 if ( mLastHoveredSocket )
89 mLastHoveredSocket->modelHoverLeaveEvent(
nullptr );
90 mLastHoveredSocket =
nullptr;
93 view()->setTool( mPreviousViewTool );
96 const QList<QGraphicsItem *> items =
scene()->items( event->
modelPoint() );
100 for ( QGraphicsItem *item : items )
102 if ( QgsModelDesignerSocketGraphicItem *socket =
dynamic_cast<QgsModelDesignerSocketGraphicItem *
>( item ) )
105 if ( mFromSocket->edge() == socket->edge() || mFromSocket->component() == socket->component() )
117 view()->endCommand();
122 view()->abortCommand();
125 if ( mFromSocket->edge() == mToSocket->edge() )
139 if ( !mToSocket->isInput() )
141 std::swap( mFromSocket, mToSocket );
144 QgsProcessingModelComponent *outputComponent = mFromSocket->component();
145 QgsProcessingModelChildAlgorithm *inputChildAlgorithm =
dynamic_cast<QgsProcessingModelChildAlgorithm *
>( mToSocket->component() );
146 if ( !inputChildAlgorithm )
149 QgsDebugError( u
"Input is not a QgsProcessingModelChildAlgorithm"_s );
153 QgsProcessingModelChildParameterSource newInputParamSource;
155 QString outParamDescription;
156 if (
const QgsProcessingModelChildAlgorithm *outputChildAlgorithm =
dynamic_cast<QgsProcessingModelChildAlgorithm *
>( outputComponent ) )
158 const QString outParamName = outputChildAlgorithm->algorithm()->outputDefinitions().at( mFromSocket->index() )->name();
159 newInputParamSource = QgsProcessingModelChildParameterSource::fromChildOutput( outputChildAlgorithm->childId(), outParamName );
160 outParamDescription = outputChildAlgorithm->algorithm()->outputDefinitions().at( mFromSocket->index() )->description();
162 else if (
const QgsProcessingModelParameter *paramFrom =
dynamic_cast<QgsProcessingModelParameter *
>( outputComponent ) )
164 newInputParamSource = QgsProcessingModelChildParameterSource::fromModelParameter( paramFrom->parameterName() );
165 outParamDescription = paramFrom->description();
169 const QList<QgsProcessingModelChildParameterSource> compatibleInputParamSources =
scene()->model()->availableSourcesForChild( inputChildAlgorithm->childId(), inputParam );
170 if ( !compatibleInputParamSources.contains( newInputParamSource ) )
173 const QString title = tr(
"Sockets cannot be connected" );
174 const QString message = tr(
"Either the sockets are incompatible or there is a circular dependency" );
175 scene()->showWarning( message, title, message );
178 if ( mPreviousInputSocketNumber != -1 )
180 QgsProcessingModelChildAlgorithm previousChildAlgorithm =
scene()->model()->childAlgorithm( mPreviousInputChildId );
182 previousChildAlgorithm.addParameterSources( previousInputParam->
name(), { newInputParamSource } );
183 scene()->model()->setChildAlgorithm( previousChildAlgorithm );
184 scene()->requestRebuildRequired();
189 view()->beginCommand( tr(
"Link %1: %2 to %3: %4" ).arg( outputComponent->description(), outParamDescription, inputChildAlgorithm->description(), inputParam->
description() ) );
191 inputChildAlgorithm->addParameterSources( inputParam->
name(), { newInputParamSource } );
194 scene()->model()->setChildAlgorithm( *inputChildAlgorithm );
196 if ( inputChildAlgorithm->childId() == mPreviousInputChildId && mToSocket->index() == mPreviousInputSocketNumber )
199 view()->abortCommand();
203 view()->endCommand();
207 scene()->requestRebuildRequired();
238 mFromSocket = socket;
239 mPreviousInputChildId.clear();
240 mPreviousInputSocketNumber = -1;
243 if ( mFromSocket->isInput() )
245 QgsProcessingModelChildAlgorithm *childFrom =
dynamic_cast<QgsProcessingModelChildAlgorithm *
>( mFromSocket->component() );
249 mPreviousInputSocketNumber = mFromSocket->index();
251 const QList<QgsProcessingModelChildParameterSource> currentSources = childFrom->parameterSources().value( param->
name() );
252 mPreviousInputChildId = childFrom->childId();
254 for (
const QgsProcessingModelChildParameterSource &source : currentSources )
260 switch ( source.source() )
265 view()->beginCommand( tr(
"Unlink %1: %2",
"Unlink Algorithm: Input" ).arg( childFrom->description(), param->
description() ) );
268 QList<QgsProcessingModelChildParameterSource> newSources;
276 newSources << QgsProcessingModelChildParameterSource::fromModelParameter( QString() );
281 newSources << QgsProcessingModelChildParameterSource::fromStaticValue( param->
defaultValue() );
284 childFrom->addParameterSources( param->
name(), newSources );
286 scene()->model()->setChildAlgorithm( *childFrom );
288 scene()->requestRebuildRequired();
291 QgsModelComponentGraphicItem *item =
nullptr;
292 int socketIndex = -1;
295 item =
scene()->childAlgorithmItem( source.outputChildId() );
296 auto algSource =
dynamic_cast<QgsProcessingModelChildAlgorithm *
>( item->component() );
306 item =
scene()->parameterItem( source.parameterName() );
316 mFromSocket = item->outSocketAt( socketIndex );