@@ -327,6 +327,43 @@ QgsProcessingModelAlgorithm::ModelParameter &QgsProcessingModelAlgorithm::parame
327
327
return mParameterComponents [ name ];
328
328
}
329
329
330
+ void QgsProcessingModelAlgorithm::updateDestinationParameters ()
331
+ {
332
+ // delete existing destination parameters
333
+ QMutableListIterator<const QgsProcessingParameterDefinition *> it ( mParameters );
334
+ while ( it.hasNext () )
335
+ {
336
+ const QgsProcessingParameterDefinition *def = it.next ();
337
+ if ( def->isDestination () )
338
+ {
339
+ delete def;
340
+ it.remove ();
341
+ }
342
+ }
343
+
344
+ QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms .constBegin ();
345
+ for ( ; childIt != mChildAlgorithms .constEnd (); ++childIt )
346
+ {
347
+ QMap<QString, QgsProcessingModelAlgorithm::ModelOutput> outputs = childIt->modelOutputs ();
348
+ QMap<QString, QgsProcessingModelAlgorithm::ModelOutput>::const_iterator outputIt = outputs.constBegin ();
349
+ for ( ; outputIt != outputs.constEnd (); ++outputIt )
350
+ {
351
+ if ( !childIt->isActive () || !childIt->algorithm () )
352
+ continue ;
353
+
354
+ // child algorithm has a destination parameter set, copy it to the model
355
+ const QgsProcessingParameterDefinition *source = childIt->algorithm ()->parameterDefinition ( outputIt->outputName () );
356
+ if ( !source )
357
+ continue ;
358
+
359
+ QgsProcessingParameterDefinition *param = QgsProcessingParameters::parameterFromVariantMap ( source->toVariantMap () );
360
+ param->setName ( outputIt->childId () + ' :' + outputIt->outputName () );
361
+ param->setDescription ( outputIt->description () );
362
+ addParameter ( param );
363
+ }
364
+ }
365
+ }
366
+
330
367
QVariant QgsProcessingModelAlgorithm::toVariant () const
331
368
{
332
369
QVariantMap map;
@@ -403,6 +440,8 @@ bool QgsProcessingModelAlgorithm::loadVariant( const QVariant &model )
403
440
addParameter ( param );
404
441
}
405
442
443
+ updateDestinationParameters ();
444
+
406
445
return true ;
407
446
}
408
447
@@ -443,11 +482,13 @@ bool QgsProcessingModelAlgorithm::fromFile( const QString &path )
443
482
void QgsProcessingModelAlgorithm::setChildAlgorithms ( const QMap<QString, ChildAlgorithm> &childAlgorithms )
444
483
{
445
484
mChildAlgorithms = childAlgorithms;
485
+ updateDestinationParameters ();
446
486
}
447
487
448
488
void QgsProcessingModelAlgorithm::setChildAlgorithm ( const QgsProcessingModelAlgorithm::ChildAlgorithm &algorithm )
449
489
{
450
490
mChildAlgorithms .insert ( algorithm.childId (), algorithm );
491
+ updateDestinationParameters ();
451
492
}
452
493
453
494
QString QgsProcessingModelAlgorithm::addChildAlgorithm ( ChildAlgorithm &algorithm )
@@ -456,6 +497,7 @@ QString QgsProcessingModelAlgorithm::addChildAlgorithm( ChildAlgorithm &algorith
456
497
algorithm.generateChildId ( *this );
457
498
458
499
mChildAlgorithms .insert ( algorithm.childId (), algorithm );
500
+ updateDestinationParameters ();
459
501
return algorithm.childId ();
460
502
}
461
503
@@ -470,6 +512,7 @@ bool QgsProcessingModelAlgorithm::removeChildAlgorithm( const QString &id )
470
512
return false ;
471
513
472
514
mChildAlgorithms .remove ( id );
515
+ updateDestinationParameters ();
473
516
return true ;
474
517
}
475
518
@@ -480,6 +523,7 @@ void QgsProcessingModelAlgorithm::deactivateChildAlgorithm( const QString &id )
480
523
childAlgorithm ( child ).setActive ( false );
481
524
}
482
525
childAlgorithm ( id ).setActive ( false );
526
+ updateDestinationParameters ();
483
527
}
484
528
485
529
bool QgsProcessingModelAlgorithm::activateChildAlgorithm ( const QString &id )
@@ -490,6 +534,7 @@ bool QgsProcessingModelAlgorithm::activateChildAlgorithm( const QString &id )
490
534
return false ;
491
535
}
492
536
childAlgorithm ( id ).setActive ( true );
537
+ updateDestinationParameters ();
493
538
return true ;
494
539
}
495
540
0 commit comments