45 mBezierRubberBand->update( event->
modelPoint(), Qt::KeyboardModifiers() );
48 const QList<QGraphicsItem *> items =
scene()->items( event->
modelPoint() );
50 QgsModelDesignerSocketGraphicItem *socket =
nullptr;
51 for ( QGraphicsItem *item : items )
53 socket =
dynamic_cast<QgsModelDesignerSocketGraphicItem *
>( item );
54 if ( !socket || mFromSocket == socket || mFromSocket->edge() == socket->edge() || mFromSocket->component() == socket->component() )
58 socket->modelHoverEnterEvent( event );
59 const QPointF rubberEndPos = socket->mapToScene( socket->position() );
60 mBezierRubberBand->update( rubberEndPos, Qt::KeyboardModifiers() );
64 if ( mLastHoveredSocket && socket != mLastHoveredSocket )
66 mLastHoveredSocket->modelHoverLeaveEvent( event );
67 mLastHoveredSocket =
nullptr;
70 if ( socket && socket != mLastHoveredSocket )
72 mLastHoveredSocket = socket;
78 if ( event->button() != Qt::LeftButton )
82 mBezierRubberBand->finish( event->
modelPoint() );
83 if ( mLastHoveredSocket )
85 mLastHoveredSocket->modelHoverLeaveEvent(
nullptr );
86 mLastHoveredSocket =
nullptr;
89 view()->setTool( mPreviousViewTool );
92 const QList<QGraphicsItem *> items =
scene()->items( event->
modelPoint() );
96 for ( QGraphicsItem *item : items )
98 if ( QgsModelDesignerSocketGraphicItem *socket =
dynamic_cast<QgsModelDesignerSocketGraphicItem *
>( item ) )
101 if ( mFromSocket->edge() == socket->edge() || mFromSocket->component() == socket->component() )
113 view()->endCommand();
118 view()->abortCommand();
121 if ( mFromSocket->edge() == mToSocket->edge() )
135 if ( !mToSocket->isInput() )
137 std::swap( mFromSocket, mToSocket );
140 QgsProcessingModelComponent *outputComponent = mFromSocket->component();
141 QgsProcessingModelChildAlgorithm *inputChildAlgorithm =
dynamic_cast<QgsProcessingModelChildAlgorithm *
>( mToSocket->component() );
142 if ( !inputChildAlgorithm )
145 QgsDebugError( QStringLiteral(
"Input is not a QgsProcessingModelChildAlgorithm" ) );
149 QgsProcessingModelChildParameterSource newInputParamSource;
151 QString outParamDescription;
152 if (
const QgsProcessingModelChildAlgorithm *outputChildAlgorithm =
dynamic_cast<QgsProcessingModelChildAlgorithm *
>( outputComponent ) )
154 const QString outParamName = outputChildAlgorithm->algorithm()->outputDefinitions().at( mFromSocket->index() )->name();
155 newInputParamSource = QgsProcessingModelChildParameterSource::fromChildOutput( outputChildAlgorithm->childId(), outParamName );
156 outParamDescription = outputChildAlgorithm->algorithm()->outputDefinitions().at( mFromSocket->index() )->description();
158 else if (
const QgsProcessingModelParameter *paramFrom =
dynamic_cast<QgsProcessingModelParameter *
>( outputComponent ) )
160 newInputParamSource = QgsProcessingModelChildParameterSource::fromModelParameter( paramFrom->parameterName() );
161 outParamDescription = paramFrom->description();
165 const QList<QgsProcessingModelChildParameterSource> compatibleInputParamSources =
scene()->model()->availableSourcesForChild( inputChildAlgorithm->childId(), inputParam );
166 if ( !compatibleInputParamSources.contains( newInputParamSource ) )
169 const QString title = tr(
"Sockets cannot be connected" );
170 const QString message = tr(
"Either the sockets are incompatible or there is a circular dependency" );
171 scene()->showWarning( message, title, message );
174 if ( mPreviousInputSocketNumber != -1 )
176 QgsProcessingModelChildAlgorithm previousChildAlgorithm =
scene()->model()->childAlgorithm( mPreviousInputChildId );
178 previousChildAlgorithm.addParameterSources( previousInputParam->
name(), { newInputParamSource } );
179 scene()->model()->setChildAlgorithm( previousChildAlgorithm );
180 scene()->requestRebuildRequired();
185 view()->beginCommand( tr(
"Link %1: %2 to %3: %4" ).arg( outputComponent->description(), outParamDescription, inputChildAlgorithm->description(), inputParam->
description() ) );
187 inputChildAlgorithm->addParameterSources( inputParam->
name(), { newInputParamSource } );
190 scene()->model()->setChildAlgorithm( *inputChildAlgorithm );
192 if ( inputChildAlgorithm->childId() == mPreviousInputChildId && mToSocket->index() == mPreviousInputSocketNumber )
195 view()->abortCommand();
199 view()->endCommand();
203 scene()->requestRebuildRequired();
234 mFromSocket = socket;
235 mPreviousInputChildId.clear();
236 mPreviousInputSocketNumber = -1;
239 if ( mFromSocket->isInput() )
241 QgsProcessingModelChildAlgorithm *childFrom =
dynamic_cast<QgsProcessingModelChildAlgorithm *
>( mFromSocket->component() );
245 mPreviousInputSocketNumber = mFromSocket->index();
247 const QList<QgsProcessingModelChildParameterSource> currentSources = childFrom->parameterSources().value( param->
name() );
248 mPreviousInputChildId = childFrom->childId();
250 for (
const QgsProcessingModelChildParameterSource &source : currentSources )
256 switch ( source.source() )
261 view()->beginCommand( tr(
"Unlink %1: %2",
"Unlink Algorithm: Input" ).arg( childFrom->description(), param->
description() ) );
264 QList<QgsProcessingModelChildParameterSource> newSources;
272 newSources << QgsProcessingModelChildParameterSource::fromModelParameter( QString() );
277 newSources << QgsProcessingModelChildParameterSource::fromStaticValue( param->
defaultValue() );
280 childFrom->addParameterSources( param->
name(), newSources );
282 scene()->model()->setChildAlgorithm( *childFrom );
284 scene()->requestRebuildRequired();
287 QgsModelComponentGraphicItem *item =
nullptr;
288 int socketIndex = -1;
291 item =
scene()->childAlgorithmItem( source.outputChildId() );
292 auto algSource =
dynamic_cast<QgsProcessingModelChildAlgorithm *
>( item->component() );
295 QgsDebugError( QStringLiteral(
"algSource not set, aborting!" ) );
302 item =
scene()->parameterItem( source.parameterName() );
308 QgsDebugError( QStringLiteral(
"item not set, aborting!" ) );
312 mFromSocket = item->outSocketAt( socketIndex );