Skip to content

Commit 33c63d5

Browse files
authoredJun 30, 2017
Merge pull request #4798 from nyalldawson/intput_list
Convert model child algorithm parameter sources to a list
2 parents bc4aae7 + 77588b9 commit 33c63d5

File tree

7 files changed

+285
-116
lines changed

7 files changed

+285
-116
lines changed
 

‎python/core/conversions.sip

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,112 @@ template<double, TYPE>
11981198
};
11991199

12001200

1201+
template<TYPE2>
1202+
%MappedType QMap<QString, QList<TYPE2> >
1203+
{
1204+
%TypeHeaderCode
1205+
#include <QMap>
1206+
#include <QList>
1207+
%End
1208+
1209+
%ConvertFromTypeCode
1210+
// Create the dictionary.
1211+
PyObject *d = PyDict_New();
1212+
1213+
if (!d)
1214+
return NULL;
1215+
1216+
const sipMappedType *qlist_type = sipFindMappedType("QList<TYPE2>");
1217+
1218+
// Set the dictionary elements.
1219+
QMap<QString, QList< TYPE2 > >::const_iterator i;
1220+
1221+
for (i = sipCpp->constBegin(); i != sipCpp->constEnd(); ++i)
1222+
{
1223+
QString *t1 = new QString(i.key());
1224+
1225+
PyObject *t1obj = sipConvertFromNewType(t1, sipType_QString, sipTransferObj);
1226+
1227+
QList< TYPE2 > *t2 = new QList< TYPE2 >( i.value() );
1228+
1229+
PyObject *t2obj = sipConvertFromMappedType(t2, qlist_type, sipTransferObj);
1230+
1231+
if (t1obj == NULL || t2obj == NULL || PyDict_SetItem(d, t1obj, t2obj) < 0)
1232+
{
1233+
Py_DECREF(d);
1234+
1235+
if (t1obj)
1236+
Py_DECREF(t1obj);
1237+
1238+
if (t2obj)
1239+
Py_DECREF(t2obj);
1240+
else
1241+
delete t2;
1242+
1243+
return NULL;
1244+
}
1245+
1246+
Py_DECREF(t1obj);
1247+
Py_DECREF(t2obj);
1248+
}
1249+
1250+
return d;
1251+
%End
1252+
1253+
%ConvertToTypeCode
1254+
PyObject *t1obj, *t2obj;
1255+
Py_ssize_t i = 0;
1256+
1257+
1258+
const sipMappedType *qlist_type = sipFindMappedType("QList<TYPE2>");
1259+
1260+
1261+
// Check the type if that is all that is required.
1262+
if (sipIsErr == NULL)
1263+
{
1264+
if (!PyDict_Check(sipPy))
1265+
return 0;
1266+
1267+
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
1268+
{
1269+
if (!sipCanConvertToType(t1obj, sipType_QString, SIP_NOT_NONE))
1270+
return 0;
1271+
}
1272+
1273+
return 1;
1274+
}
1275+
1276+
QMap<QString, QList< TYPE2 > > *qm = new QMap<QString, QList< TYPE2 > >;
1277+
1278+
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
1279+
{
1280+
int state;
1281+
1282+
QString *t1 = reinterpret_cast<QString *>(sipConvertToType(t1obj, sipType_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
1283+
1284+
QList<TYPE2> *t2 = reinterpret_cast< QList<TYPE2> * >(sipConvertToMappedType(t2obj, qlist_type, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
1285+
if (*sipIsErr)
1286+
{
1287+
sipReleaseType(t2, sipType_TYPE2, state);
1288+
delete qm;
1289+
return 0;
1290+
}
1291+
1292+
if ( t2 )
1293+
qm->insert(*t1, *t2);
1294+
else
1295+
qm->insert(*t1, QList<TYPE2>() );
1296+
1297+
sipReleaseType(t1, sipType_QString, state);
1298+
1299+
sipReleaseType(t2, sipType_TYPE2, state);
1300+
}
1301+
1302+
*sipCppPtr = qm;
1303+
1304+
return sipGetState(sipTransferObj);
1305+
%End
1306+
};
12011307

12021308
template<double, TYPE2>
12031309
%MappedType QMultiMap<double, TYPE2>

‎python/core/processing/qgsprocessingmodelalgorithm.sip

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class QgsProcessingModelAlgorithm : QgsProcessingAlgorithm
161161

162162
};
163163

164+
164165
class Component
165166
{
166167
%Docstring
@@ -415,30 +416,30 @@ Copies are protected to avoid slicing
415416
:rtype: QgsProcessingAlgorithm
416417
%End
417418

418-
QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSource > parameterSources() const;
419+
QMap< QString, QList< QgsProcessingModelAlgorithm::ChildParameterSource > > parameterSources() const;
419420
%Docstring
420421
Returns a map of parameter sources. The keys are the child algorithm
421-
parameter names, the values are the source for that parameter.
422+
parameter names, the values are the sources for that parameter.
422423
.. seealso:: setParameterSources()
423-
.. seealso:: addParameterSource()
424-
:rtype: QMap< str, QgsProcessingModelAlgorithm.ChildParameterSource >
424+
.. seealso:: addParameterSources()
425+
:rtype: QMap< str, QList< QgsProcessingModelAlgorithm.ChildParameterSource > >
425426
%End
426427

427-
void setParameterSources( const QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSource > &sources );
428+
void setParameterSources( const QMap< QString, QList< QgsProcessingModelAlgorithm::ChildParameterSource > > &sources );
428429
%Docstring
429430
Sets the map of parameter ``sources``. The keys are the child algorithm
430-
parameter names, the values are the source for that parameter.
431+
parameter names, the values are the sources for that parameter.
431432
.. seealso:: parameterSources()
432-
.. seealso:: addParameterSource()
433+
.. seealso:: addParameterSources()
433434
%End
434435

435-
void addParameterSource( const QString &name, const QgsProcessingModelAlgorithm::ChildParameterSource &source );
436+
void addParameterSources( const QString &name, const QList< QgsProcessingModelAlgorithm::ChildParameterSource > &source );
436437
%Docstring
437438
Adds a parameter source. The ``name`` argument should match
438-
one of the child algorithm's parameter names, and the ``source``
439-
argument is used to set the source for that parameter.
439+
one of the child algorithm's parameter names, and the ``sources``
440+
argument is used to set the sources for that parameter.
440441

441-
Any existing parameter source with matching name will be replaced.
442+
Any existing parameter sources with matching name will be replaced.
442443
.. seealso:: parameterSources()
443444
.. seealso:: setParameterSources()
444445
%End

‎python/plugins/processing/modeler/ModelerParametersDialog.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ def setPreviousValues(self):
285285
continue
286286
if param.name() in alg.parameterSources():
287287
value = alg.parameterSources()[param.name()]
288+
if isinstance(value, list) and len(value) == 1:
289+
value = value[0]
288290
else:
289291
value = param.defaultValue()
290292

@@ -325,9 +327,11 @@ def createAlgorithm(self):
325327
if val is None:
326328
continue
327329
elif isinstance(val, QgsProcessingModelAlgorithm.ChildParameterSource):
328-
alg.addParameterSource(param.name(), val)
330+
alg.addParameterSources(param.name(), [val])
331+
elif isinstance(val, list):
332+
alg.addParameterSources(param.name(), val)
329333
else:
330-
alg.addParameterSource(param.name(), QgsProcessingModelAlgorithm.ChildParameterSource.fromStaticValue(val))
334+
alg.addParameterSources(param.name(), [QgsProcessingModelAlgorithm.ChildParameterSource.fromStaticValue(val)])
331335

332336
outputs = {}
333337
for dest in self._alg.destinationParameterDefinitions():

‎python/plugins/processing/modeler/ModelerScene.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,18 @@ def paintModel(self, model, controls=True):
109109
for parameter in alg.algorithm().parameterDefinitions():
110110
if not parameter.isDestination() and not parameter.flags() & QgsProcessingParameterDefinition.FlagHidden:
111111
if parameter.name() in alg.parameterSources():
112-
value = alg.parameterSources()[parameter.name()]
112+
sources = alg.parameterSources()[parameter.name()]
113113
else:
114-
value = None
115-
sourceItems = self.getItemsFromParamValue(value)
116-
for sourceItem, sourceIdx in sourceItems:
117-
arrow = ModelerArrowItem(sourceItem, sourceIdx, self.algItems[alg.childId()], idx)
118-
sourceItem.addArrow(arrow)
119-
self.algItems[alg.childId()].addArrow(arrow)
120-
arrow.updatePath()
121-
self.addItem(arrow)
122-
idx += 1
114+
sources = []
115+
for source in sources:
116+
sourceItems = self.getItemsFromParamValue(source)
117+
for sourceItem, sourceIdx in sourceItems:
118+
arrow = ModelerArrowItem(sourceItem, sourceIdx, self.algItems[alg.childId()], idx)
119+
sourceItem.addArrow(arrow)
120+
self.algItems[alg.childId()].addArrow(arrow)
121+
arrow.updatePath()
122+
self.addItem(arrow)
123+
idx += 1
123124
for depend in alg.dependencies():
124125
arrow = ModelerArrowItem(self.algItems[depend], -1,
125126
self.algItems[alg.childId()], -1)

‎src/core/processing/qgsprocessingmodelalgorithm.cpp

Lines changed: 90 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ void QgsProcessingModelAlgorithm::Component::setDescription( const QString &desc
4747
mDescription = description;
4848
}
4949

50-
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSource> QgsProcessingModelAlgorithm::ChildAlgorithm::parameterSources() const
50+
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources> QgsProcessingModelAlgorithm::ChildAlgorithm::parameterSources() const
5151
{
5252
return mParams;
5353
}
5454

55-
void QgsProcessingModelAlgorithm::ChildAlgorithm::setParameterSources( const QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSource > &params )
55+
void QgsProcessingModelAlgorithm::ChildAlgorithm::setParameterSources( const QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSources > &params )
5656
{
5757
mParams = params;
5858
}
5959

60-
void QgsProcessingModelAlgorithm::ChildAlgorithm::addParameterSource( const QString &name, const ChildParameterSource &source )
60+
void QgsProcessingModelAlgorithm::ChildAlgorithm::addParameterSources( const QString &name, const ChildParameterSources &source )
6161
{
6262
mParams.insert( name, source );
6363
}
@@ -157,10 +157,15 @@ QVariant QgsProcessingModelAlgorithm::ChildAlgorithm::toVariant() const
157157
saveCommonProperties( map );
158158

159159
QVariantMap paramMap;
160-
QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSource >::const_iterator paramIt = mParams.constBegin();
160+
QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSources >::const_iterator paramIt = mParams.constBegin();
161161
for ( ; paramIt != mParams.constEnd(); ++paramIt )
162162
{
163-
paramMap.insert( paramIt.key(), paramIt.value().toVariant() );
163+
QVariantList sources;
164+
Q_FOREACH ( const ChildParameterSource &source, paramIt.value() )
165+
{
166+
sources << source.toVariant();
167+
}
168+
paramMap.insert( paramIt.key(), sources );
164169
}
165170
map.insert( "params", paramMap );
166171

@@ -193,11 +198,15 @@ bool QgsProcessingModelAlgorithm::ChildAlgorithm::loadVariant( const QVariant &c
193198
QVariantMap::const_iterator paramIt = paramMap.constBegin();
194199
for ( ; paramIt != paramMap.constEnd(); ++paramIt )
195200
{
196-
ChildParameterSource param;
197-
if ( !param.loadVariant( paramIt.value().toMap() ) )
198-
return false;
199-
200-
mParams.insert( paramIt.key(), param );
201+
ChildParameterSources sources;
202+
Q_FOREACH ( const QVariant &sourceVar, paramIt->toList() )
203+
{
204+
ChildParameterSource param;
205+
if ( !param.loadVariant( sourceVar.toMap() ) )
206+
return false;
207+
sources << param;
208+
}
209+
mParams.insert( paramIt.key(), sources );
201210
}
202211

203212
mModelOutputs.clear();
@@ -223,12 +232,20 @@ QString QgsProcessingModelAlgorithm::ChildAlgorithm::asPythonCode() const
223232
return QString();
224233

225234
QStringList paramParts;
226-
QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSource >::const_iterator paramIt = mParams.constBegin();
235+
QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSources >::const_iterator paramIt = mParams.constBegin();
227236
for ( ; paramIt != mParams.constEnd(); ++paramIt )
228237
{
229-
QString part = paramIt->asPythonCode();
230-
if ( !part.isEmpty() )
231-
paramParts << QStringLiteral( "'%1':%2" ).arg( paramIt.key(), part );
238+
QStringList sourceParts;
239+
Q_FOREACH ( const ChildParameterSource &source, paramIt.value() )
240+
{
241+
QString part = source.asPythonCode();
242+
if ( !part.isEmpty() )
243+
sourceParts << QStringLiteral( "'%1':%2" ).arg( paramIt.key(), part );
244+
}
245+
if ( sourceParts.count() == 1 )
246+
paramParts << sourceParts.at( 0 );
247+
else
248+
paramParts << QStringLiteral( "[%1]" ).arg( paramParts.join( ',' ) );
232249
}
233250

234251
lines << QStringLiteral( "outputs['%1']=processing.run('%2', {%3}, context=context, feedback=feedback)" ).arg( mId, mAlgorithmId, paramParts.join( ',' ) );
@@ -347,24 +364,34 @@ QVariantMap QgsProcessingModelAlgorithm::parametersForChildAlgorithm( const Chil
347364
if ( !child.parameterSources().contains( def->name() ) )
348365
continue; // use default value
349366

350-
ChildParameterSource paramSource = child.parameterSources().value( def->name() );
351-
switch ( paramSource.source() )
352-
{
353-
case ChildParameterSource::StaticValue:
354-
childParams.insert( def->name(), paramSource.staticValue() );
355-
break;
367+
ChildParameterSources paramSources = child.parameterSources().value( def->name() );
356368

357-
case ChildParameterSource::ModelParameter:
358-
childParams.insert( def->name(), modelParameters.value( paramSource.parameterName() ) );
359-
break;
360-
361-
case ChildParameterSource::ChildOutput:
369+
QVariantList paramParts;
370+
Q_FOREACH ( const ChildParameterSource &source, paramSources )
371+
{
372+
switch ( source.source() )
362373
{
363-
QVariantMap linkedChildResults = results.value( paramSource.outputChildId() );
364-
childParams.insert( def->name(), linkedChildResults.value( paramSource.outputName() ) );
365-
break;
374+
case ChildParameterSource::StaticValue:
375+
paramParts << source.staticValue();
376+
break;
377+
378+
case ChildParameterSource::ModelParameter:
379+
paramParts << modelParameters.value( source.parameterName() );
380+
break;
381+
382+
case ChildParameterSource::ChildOutput:
383+
{
384+
QVariantMap linkedChildResults = results.value( source.outputChildId() );
385+
paramParts << linkedChildResults.value( source.outputName() );
386+
break;
387+
}
366388
}
367389
}
390+
if ( paramParts.count() == 1 )
391+
childParams.insert( def->name(), paramParts.at( 0 ) );
392+
else
393+
childParams.insert( def->name(), paramParts );
394+
368395
}
369396
else
370397
{
@@ -416,15 +443,18 @@ bool QgsProcessingModelAlgorithm::childOutputIsRequired( const QString &childId,
416443
continue;
417444

418445
// look through all sources for child
419-
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSource> candidateChildParams = childIt->parameterSources();
420-
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSource>::const_iterator childParamIt = candidateChildParams.constBegin();
446+
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources> candidateChildParams = childIt->parameterSources();
447+
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources>::const_iterator childParamIt = candidateChildParams.constBegin();
421448
for ( ; childParamIt != candidateChildParams.constEnd(); ++childParamIt )
422449
{
423-
if ( childParamIt->source() == ChildParameterSource::ChildOutput
424-
&& childParamIt->outputChildId() == childId
425-
&& childParamIt->outputName() == outputName )
450+
Q_FOREACH ( const ChildParameterSource &source, childParamIt.value() )
426451
{
427-
return true;
452+
if ( source.source() == ChildParameterSource::ChildOutput
453+
&& source.outputChildId() == childId
454+
&& source.outputName() == outputName )
455+
{
456+
return true;
457+
}
428458
}
429459
}
430460
}
@@ -902,14 +932,17 @@ bool QgsProcessingModelAlgorithm::childAlgorithmsDependOnParameter( const QStrin
902932
for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt )
903933
{
904934
// check whether child requires this parameter
905-
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSource> childParams = childIt->parameterSources();
906-
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSource>::const_iterator paramIt = childParams.constBegin();
935+
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources> childParams = childIt->parameterSources();
936+
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources>::const_iterator paramIt = childParams.constBegin();
907937
for ( ; paramIt != childParams.constEnd(); ++paramIt )
908938
{
909-
if ( paramIt->source() == ChildParameterSource::ModelParameter
910-
&& paramIt->parameterName() == name )
939+
Q_FOREACH ( const ChildParameterSource &source, paramIt.value() )
911940
{
912-
return true;
941+
if ( source.source() == ChildParameterSource::ModelParameter
942+
&& source.parameterName() == name )
943+
{
944+
return true;
945+
}
913946
}
914947
}
915948
}
@@ -938,16 +971,19 @@ void QgsProcessingModelAlgorithm::dependentChildAlgorithmsRecursive( const QStri
938971
}
939972

940973
// check whether child requires any outputs from the target alg
941-
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSource> childParams = childIt->parameterSources();
942-
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSource>::const_iterator paramIt = childParams.constBegin();
974+
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources> childParams = childIt->parameterSources();
975+
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources>::const_iterator paramIt = childParams.constBegin();
943976
for ( ; paramIt != childParams.constEnd(); ++paramIt )
944977
{
945-
if ( paramIt->source() == ChildParameterSource::ChildOutput
946-
&& paramIt->outputChildId() == childId )
978+
Q_FOREACH ( const ChildParameterSource &source, paramIt.value() )
947979
{
948-
depends.insert( childIt->childId() );
949-
dependsOnChildAlgorithmsRecursive( childIt->childId(), depends );
950-
break;
980+
if ( source.source() == ChildParameterSource::ChildOutput
981+
&& source.outputChildId() == childId )
982+
{
983+
depends.insert( childIt->childId() );
984+
dependsOnChildAlgorithmsRecursive( childIt->childId(), depends );
985+
break;
986+
}
951987
}
952988
}
953989
}
@@ -985,14 +1021,17 @@ void QgsProcessingModelAlgorithm::dependsOnChildAlgorithmsRecursive( const QStri
9851021
}
9861022

9871023
// check through parameter dependencies
988-
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSource> childParams = alg.parameterSources();
989-
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSource>::const_iterator paramIt = childParams.constBegin();
1024+
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources> childParams = alg.parameterSources();
1025+
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources>::const_iterator paramIt = childParams.constBegin();
9901026
for ( ; paramIt != childParams.constEnd(); ++paramIt )
9911027
{
992-
if ( paramIt->source() == ChildParameterSource::ChildOutput && !depends.contains( paramIt->outputChildId() ) )
1028+
Q_FOREACH ( const ChildParameterSource &source, paramIt.value() )
9931029
{
994-
depends.insert( paramIt->outputChildId() );
995-
dependsOnChildAlgorithmsRecursive( paramIt->outputChildId(), depends );
1030+
if ( source.source() == ChildParameterSource::ChildOutput && !depends.contains( source.outputChildId() ) )
1031+
{
1032+
depends.insert( source.outputChildId() );
1033+
dependsOnChildAlgorithmsRecursive( source.outputChildId(), depends );
1034+
}
9961035
}
9971036
}
9981037
}

‎src/core/processing/qgsprocessingmodelalgorithm.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
168168

169169
};
170170

171+
#ifndef SIP_RUN
172+
//! List of child parameter sources
173+
typedef QList< QgsProcessingModelAlgorithm::ChildParameterSource > ChildParameterSources;
174+
#endif
175+
171176
/**
172177
* Represents a component of a model algorithm.
173178
* \since QGIS 3.0
@@ -413,30 +418,30 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
413418

414419
/**
415420
* Returns a map of parameter sources. The keys are the child algorithm
416-
* parameter names, the values are the source for that parameter.
421+
* parameter names, the values are the sources for that parameter.
417422
* \see setParameterSources()
418-
* \see addParameterSource()
423+
* \see addParameterSources()
419424
*/
420-
QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSource > parameterSources() const;
425+
QMap< QString, QList< QgsProcessingModelAlgorithm::ChildParameterSource > > parameterSources() const;
421426

422427
/**
423428
* Sets the map of parameter \a sources. The keys are the child algorithm
424-
* parameter names, the values are the source for that parameter.
429+
* parameter names, the values are the sources for that parameter.
425430
* \see parameterSources()
426-
* \see addParameterSource()
431+
* \see addParameterSources()
427432
*/
428-
void setParameterSources( const QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSource > &sources );
433+
void setParameterSources( const QMap< QString, QList< QgsProcessingModelAlgorithm::ChildParameterSource > > &sources );
429434

430435
/**
431436
* Adds a parameter source. The \a name argument should match
432-
* one of the child algorithm's parameter names, and the \a source
433-
* argument is used to set the source for that parameter.
437+
* one of the child algorithm's parameter names, and the \a sources
438+
* argument is used to set the sources for that parameter.
434439
*
435-
* Any existing parameter source with matching name will be replaced.
440+
* Any existing parameter sources with matching name will be replaced.
436441
* \see parameterSources()
437442
* \see setParameterSources()
438443
*/
439-
void addParameterSource( const QString &name, const QgsProcessingModelAlgorithm::ChildParameterSource &source );
444+
void addParameterSources( const QString &name, const QList< QgsProcessingModelAlgorithm::ChildParameterSource > &source );
440445

441446
/**
442447
* Returns true if the child algorithm is active.
@@ -554,7 +559,7 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
554559
QString mAlgorithmId;
555560

556561
//! A map of parameter sources. Keys are algorithm parameter names.
557-
QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSource > mParams;
562+
QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSources > mParams;
558563

559564
//! A map of ModelOutput for final model outputs generated by this child algorithm. Keys are output names from the child algorithm.
560565
QMap< QString, QgsProcessingModelAlgorithm::ModelOutput > mModelOutputs;

‎tests/src/core/testqgsprocessing.cpp

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4180,13 +4180,15 @@ void TestQgsProcessing::modelerAlgorithm()
41804180
child.setDependencies( QStringList() << "a" << "b" );
41814181
QCOMPARE( child.dependencies(), QStringList() << "a" << "b" );
41824182

4183-
QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSource > sources;
4184-
sources.insert( QStringLiteral( "a" ), QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ) );
4183+
QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSources > sources;
4184+
sources.insert( QStringLiteral( "a" ), QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ) );
41854185
child.setParameterSources( sources );
4186-
QCOMPARE( child.parameterSources().value( QStringLiteral( "a" ) ).staticValue().toInt(), 5 );
4187-
child.addParameterSource( QStringLiteral( "b" ), QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 7 ) );
4188-
QCOMPARE( child.parameterSources().value( QStringLiteral( "a" ) ).staticValue().toInt(), 5 );
4189-
QCOMPARE( child.parameterSources().value( QStringLiteral( "b" ) ).staticValue().toInt(), 7 );
4186+
QCOMPARE( child.parameterSources().value( QStringLiteral( "a" ) ).at( 0 ).staticValue().toInt(), 5 );
4187+
child.addParameterSources( QStringLiteral( "b" ), QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 7 ) << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 9 ) );
4188+
QCOMPARE( child.parameterSources().value( QStringLiteral( "a" ) ).at( 0 ).staticValue().toInt(), 5 );
4189+
QCOMPARE( child.parameterSources().value( QStringLiteral( "b" ) ).count(), 2 );
4190+
QCOMPARE( child.parameterSources().value( QStringLiteral( "b" ) ).at( 0 ).staticValue().toInt(), 7 );
4191+
QCOMPARE( child.parameterSources().value( QStringLiteral( "b" ) ).at( 1 ).staticValue().toInt(), 9 );
41904192

41914193
QgsProcessingModelAlgorithm::ModelOutput testModelOut;
41924194
testModelOut.setChildId( QStringLiteral( "my_id" ) );
@@ -4358,7 +4360,7 @@ void TestQgsProcessing::modelerAlgorithm()
43584360
// dependency via parameter source
43594361
QgsProcessingModelAlgorithm::ChildAlgorithm c9;
43604362
c9.setChildId( "c9" );
4361-
c9.addParameterSource( "x", QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "c8", "x" ) );
4363+
c9.addParameterSources( "x", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "c8", "x" ) );
43624364
alg3.addChildAlgorithm( c9 );
43634365
QVERIFY( alg3.dependentChildAlgorithms( "c9" ).isEmpty() );
43644366
QCOMPARE( alg3.dependentChildAlgorithms( "c8" ).count(), 1 );
@@ -4441,10 +4443,10 @@ void TestQgsProcessing::modelerAlgorithm()
44414443
QgsProcessingModelAlgorithm::ModelParameter bool2;
44424444
alg4.addModelParameter( new QgsProcessingParameterBoolean( "p1", "desc" ), bool2 );
44434445
QVERIFY( !alg4.childAlgorithmsDependOnParameter( "p1" ) );
4444-
c10.addParameterSource( "x", QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "p2" ) );
4446+
c10.addParameterSources( "x", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "p2" ) );
44454447
alg4.setChildAlgorithm( c10 );
44464448
QVERIFY( !alg4.childAlgorithmsDependOnParameter( "p1" ) );
4447-
c10.addParameterSource( "y", QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "p1" ) );
4449+
c10.addParameterSources( "y", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "p1" ) );
44484450
alg4.setChildAlgorithm( c10 );
44494451
QVERIFY( alg4.childAlgorithmsDependOnParameter( "p1" ) );
44504452

@@ -4457,9 +4459,12 @@ void TestQgsProcessing::modelerAlgorithm()
44574459
QgsProcessingModelAlgorithm::ChildAlgorithm alg5c1;
44584460
alg5c1.setChildId( "cx1" );
44594461
alg5c1.setAlgorithmId( "buffer" );
4460-
alg5c1.addParameterSource( "x", QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "p1" ) );
4461-
alg5c1.addParameterSource( "y", QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx2", "out3" ) );
4462-
alg5c1.addParameterSource( "z", QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ) );
4462+
alg5c1.addParameterSources( "x", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "p1" ) );
4463+
alg5c1.addParameterSources( "y", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx2", "out3" ) );
4464+
alg5c1.addParameterSources( "z", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 5 ) );
4465+
alg5c1.addParameterSources( "zm", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 6 )
4466+
<< QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "p2" )
4467+
<< QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx2", "out4" ) );
44634468
alg5c1.setActive( true );
44644469
alg5c1.setOutputsCollapsed( true );
44654470
alg5c1.setParametersCollapsed( true );
@@ -4504,14 +4509,22 @@ void TestQgsProcessing::modelerAlgorithm()
45044509
QCOMPARE( alg6c1.description(), QStringLiteral( "child 1" ) );
45054510
QCOMPARE( alg6c1.position().x(), 1.0 );
45064511
QCOMPARE( alg6c1.position().y(), 2.0 );
4507-
QCOMPARE( alg6c1.parameterSources().count(), 3 );
4508-
QCOMPARE( alg6c1.parameterSources().value( "x" ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter );
4509-
QCOMPARE( alg6c1.parameterSources().value( "x" ).parameterName(), QStringLiteral( "p1" ) );
4510-
QCOMPARE( alg6c1.parameterSources().value( "y" ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput );
4511-
QCOMPARE( alg6c1.parameterSources().value( "y" ).outputChildId(), QStringLiteral( "cx2" ) );
4512-
QCOMPARE( alg6c1.parameterSources().value( "y" ).outputName(), QStringLiteral( "out3" ) );
4513-
QCOMPARE( alg6c1.parameterSources().value( "z" ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::StaticValue );
4514-
QCOMPARE( alg6c1.parameterSources().value( "z" ).staticValue().toInt(), 5 );
4512+
QCOMPARE( alg6c1.parameterSources().count(), 4 );
4513+
QCOMPARE( alg6c1.parameterSources().value( "x" ).at( 0 ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter );
4514+
QCOMPARE( alg6c1.parameterSources().value( "x" ).at( 0 ).parameterName(), QStringLiteral( "p1" ) );
4515+
QCOMPARE( alg6c1.parameterSources().value( "y" ).at( 0 ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput );
4516+
QCOMPARE( alg6c1.parameterSources().value( "y" ).at( 0 ).outputChildId(), QStringLiteral( "cx2" ) );
4517+
QCOMPARE( alg6c1.parameterSources().value( "y" ).at( 0 ).outputName(), QStringLiteral( "out3" ) );
4518+
QCOMPARE( alg6c1.parameterSources().value( "z" ).at( 0 ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::StaticValue );
4519+
QCOMPARE( alg6c1.parameterSources().value( "z" ).at( 0 ).staticValue().toInt(), 5 );
4520+
QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 0 ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::StaticValue );
4521+
QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 0 ).staticValue().toInt(), 6 );
4522+
QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 1 ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::ModelParameter );
4523+
QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 1 ).parameterName(), QStringLiteral( "p2" ) );
4524+
QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 2 ).source(), QgsProcessingModelAlgorithm::ChildParameterSource::ChildOutput );
4525+
QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 2 ).outputChildId(), QStringLiteral( "cx2" ) );
4526+
QCOMPARE( alg6c1.parameterSources().value( "zm" ).at( 2 ).outputName(), QStringLiteral( "out4" ) );
4527+
45154528
QCOMPARE( alg6c1.modelOutputs().count(), 1 );
45164529
QCOMPARE( alg6c1.modelOutputs().value( QStringLiteral( "a" ) ).description(), QStringLiteral( "my output" ) );
45174530
QCOMPARE( alg6c1.modelOutput( "a" ).description(), QStringLiteral( "my output" ) );
@@ -4602,12 +4615,12 @@ void TestQgsProcessing::modelExecution()
46024615
QgsProcessingModelAlgorithm::ChildAlgorithm algc2;
46034616
algc2.setChildId( "cx2" );
46044617
algc2.setAlgorithmId( "native:centroids" );
4605-
algc2.addParameterSource( "x", QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx1", "p1" ) );
4618+
algc2.addParameterSources( "x", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx1", "p1" ) );
46064619
model1.addChildAlgorithm( algc2 );
46074620
QgsProcessingModelAlgorithm::ChildAlgorithm algc3;
46084621
algc3.setChildId( "cx3" );
46094622
algc3.setAlgorithmId( "native:centroids" );
4610-
algc3.addParameterSource( "x", QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx1", "p2" ) );
4623+
algc3.addParameterSources( "x", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx1", "p2" ) );
46114624
algc3.setActive( false );
46124625
model1.addChildAlgorithm( algc3 );
46134626

@@ -4624,12 +4637,12 @@ void TestQgsProcessing::modelExecution()
46244637
QgsProcessingModelAlgorithm::ChildAlgorithm alg2c1;
46254638
alg2c1.setChildId( "cx1" );
46264639
alg2c1.setAlgorithmId( "native:buffer" );
4627-
alg2c1.addParameterSource( "INPUT", QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "SOURCE_LAYER" ) );
4628-
alg2c1.addParameterSource( "DISTANCE", QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "DIST" ) );
4629-
alg2c1.addParameterSource( "SEGMENTS", QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 16 ) );
4630-
alg2c1.addParameterSource( "END_CAP_STYLE", QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 1 ) );
4631-
alg2c1.addParameterSource( "JOIN_STYLE", QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 2 ) );
4632-
alg2c1.addParameterSource( "DISSOLVE", QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( false ) );
4640+
alg2c1.addParameterSources( "INPUT", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "SOURCE_LAYER" ) );
4641+
alg2c1.addParameterSources( "DISTANCE", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( "DIST" ) );
4642+
alg2c1.addParameterSources( "SEGMENTS", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 16 ) );
4643+
alg2c1.addParameterSources( "END_CAP_STYLE", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 1 ) );
4644+
alg2c1.addParameterSources( "JOIN_STYLE", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( 2 ) );
4645+
alg2c1.addParameterSources( "DISSOLVE", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( false ) );
46334646
QMap<QString, QgsProcessingModelAlgorithm::ModelOutput> outputs1;
46344647
QgsProcessingModelAlgorithm::ModelOutput out1( "MODEL_OUT_LAYER" );
46354648
out1.setChildOutputName( "OUTPUT_LAYER" );
@@ -4660,7 +4673,7 @@ void TestQgsProcessing::modelExecution()
46604673
QgsProcessingModelAlgorithm::ChildAlgorithm alg2c2;
46614674
alg2c2.setChildId( "cx2" );
46624675
alg2c2.setAlgorithmId( "native:centroids" );
4663-
alg2c2.addParameterSource( "INPUT", QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx1", "OUTPUT_LAYER" ) );
4676+
alg2c2.addParameterSources( "INPUT", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx1", "OUTPUT_LAYER" ) );
46644677
model2.addChildAlgorithm( alg2c2 );
46654678
params = model2.parametersForChildAlgorithm( model2.childAlgorithm( "cx2" ), modelInputs, childResults );
46664679
QCOMPARE( params.value( "INPUT" ).toString(), QStringLiteral( "dest.shp" ) );
@@ -4671,8 +4684,8 @@ void TestQgsProcessing::modelExecution()
46714684
QgsProcessingModelAlgorithm::ChildAlgorithm alg2c3;
46724685
alg2c3.setChildId( "cx3" );
46734686
alg2c3.setAlgorithmId( "native:extractbyexpression" );
4674-
alg2c3.addParameterSource( "INPUT", QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx1", "OUTPUT_LAYER" ) );
4675-
alg2c3.addParameterSource( "EXPRESSION", QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( "true" ) );
4687+
alg2c3.addParameterSources( "INPUT", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( "cx1", "OUTPUT_LAYER" ) );
4688+
alg2c3.addParameterSources( "EXPRESSION", QgsProcessingModelAlgorithm::ChildParameterSources() << QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( "true" ) );
46764689
alg2c3.setDependencies( QStringList() << "cx2" );
46774690
model2.addChildAlgorithm( alg2c3 );
46784691
params = model2.parametersForChildAlgorithm( model2.childAlgorithm( "cx3" ), modelInputs, childResults );

0 commit comments

Comments
 (0)
Please sign in to comment.