Skip to content
Permalink
Browse files

Add method to determine whether dependencies exist between model para…

…meters
  • Loading branch information
nyalldawson committed Jul 3, 2017
1 parent 6483984 commit 921939e4ec00bd69b335ec0d245b055c3d27505c
@@ -724,6 +724,16 @@ Copies are protected to avoid slicing
%Docstring
Returns true if any child algorithms depend on the model parameter
with the specified ``name``.
.. seealso:: otherParametersDependOnParameter()
:rtype: bool
%End

bool otherParametersDependOnParameter( const QString &name ) const;
%Docstring
Returns true if any other model parameters depend on the parameter
with the specified ``name`` (e.g. field parameters where ``name``
is the parent layer parameter).
.. seealso:: childAlgorithmsDependOnParameter()
:rtype: bool
%End

@@ -949,6 +949,19 @@ bool QgsProcessingModelAlgorithm::childAlgorithmsDependOnParameter( const QStrin
return false;
}

bool QgsProcessingModelAlgorithm::otherParametersDependOnParameter( const QString &name ) const
{
Q_FOREACH ( const QgsProcessingParameterDefinition *def, mParameters )
{
if ( def->name() == name )
continue;

if ( def->dependsOnOtherParameters().contains( name ) )
return true;
}
return false;
}

QMap<QString, QgsProcessingModelAlgorithm::ModelParameter> QgsProcessingModelAlgorithm::parameterComponents() const
{
return mParameterComponents;
@@ -718,9 +718,18 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
/**
* Returns true if any child algorithms depend on the model parameter
* with the specified \a name.
* \see otherParametersDependOnParameter()
*/
bool childAlgorithmsDependOnParameter( const QString &name ) const;

/**
* Returns true if any other model parameters depend on the parameter
* with the specified \a name (e.g. field parameters where \a name
* is the parent layer parameter).
* \see childAlgorithmsDependOnParameter()
*/
bool otherParametersDependOnParameter( const QString &name ) const;

/**
* Returns the map of parameter components used by the model. The keys
* should match the algorithm's parameter names (see parameterDefinitions() ).
@@ -4458,6 +4458,16 @@ void TestQgsProcessing::modelerAlgorithm()
alg4.setChildAlgorithm( c10 );
QVERIFY( alg4.childAlgorithmsDependOnParameter( "p1" ) );

QgsProcessingModelAlgorithm::ModelParameter vlP;
alg4.addModelParameter( new QgsProcessingParameterVectorLayer( "layer" ), vlP );
QgsProcessingModelAlgorithm::ModelParameter field;
alg4.addModelParameter( new QgsProcessingParameterField( "field", QString(), QVariant(), QStringLiteral( "layer" ) ), field );
QVERIFY( !alg4.otherParametersDependOnParameter( "p1" ) );
QVERIFY( !alg4.otherParametersDependOnParameter( "field" ) );
QVERIFY( alg4.otherParametersDependOnParameter( "layer" ) );





// to/from XML

0 comments on commit 921939e

Please sign in to comment.
You can’t perform that action at this time.