Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add method to determine whether dependencies exist between model para…
…meters
  • Loading branch information
nyalldawson committed Jul 3, 2017
1 parent 6483984 commit 921939e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/core/processing/qgsprocessingmodelalgorithm.sip
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions src/core/processing/qgsprocessingmodelalgorithm.cpp
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/core/processing/qgsprocessingmodelalgorithm.h
Expand Up @@ -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() ).
Expand Down
10 changes: 10 additions & 0 deletions tests/src/core/testqgsprocessing.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 921939e

Please sign in to comment.