Skip to content

Commit 921939e

Browse files
committed
Add method to determine whether dependencies exist between model parameters
1 parent 6483984 commit 921939e

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

python/core/processing/qgsprocessingmodelalgorithm.sip

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,16 @@ Copies are protected to avoid slicing
724724
%Docstring
725725
Returns true if any child algorithms depend on the model parameter
726726
with the specified ``name``.
727+
.. seealso:: otherParametersDependOnParameter()
728+
:rtype: bool
729+
%End
730+
731+
bool otherParametersDependOnParameter( const QString &name ) const;
732+
%Docstring
733+
Returns true if any other model parameters depend on the parameter
734+
with the specified ``name`` (e.g. field parameters where ``name``
735+
is the parent layer parameter).
736+
.. seealso:: childAlgorithmsDependOnParameter()
727737
:rtype: bool
728738
%End
729739

src/core/processing/qgsprocessingmodelalgorithm.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,19 @@ bool QgsProcessingModelAlgorithm::childAlgorithmsDependOnParameter( const QStrin
949949
return false;
950950
}
951951

952+
bool QgsProcessingModelAlgorithm::otherParametersDependOnParameter( const QString &name ) const
953+
{
954+
Q_FOREACH ( const QgsProcessingParameterDefinition *def, mParameters )
955+
{
956+
if ( def->name() == name )
957+
continue;
958+
959+
if ( def->dependsOnOtherParameters().contains( name ) )
960+
return true;
961+
}
962+
return false;
963+
}
964+
952965
QMap<QString, QgsProcessingModelAlgorithm::ModelParameter> QgsProcessingModelAlgorithm::parameterComponents() const
953966
{
954967
return mParameterComponents;

src/core/processing/qgsprocessingmodelalgorithm.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,18 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
718718
/**
719719
* Returns true if any child algorithms depend on the model parameter
720720
* with the specified \a name.
721+
* \see otherParametersDependOnParameter()
721722
*/
722723
bool childAlgorithmsDependOnParameter( const QString &name ) const;
723724

725+
/**
726+
* Returns true if any other model parameters depend on the parameter
727+
* with the specified \a name (e.g. field parameters where \a name
728+
* is the parent layer parameter).
729+
* \see childAlgorithmsDependOnParameter()
730+
*/
731+
bool otherParametersDependOnParameter( const QString &name ) const;
732+
724733
/**
725734
* Returns the map of parameter components used by the model. The keys
726735
* should match the algorithm's parameter names (see parameterDefinitions() ).

tests/src/core/testqgsprocessing.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4458,6 +4458,16 @@ void TestQgsProcessing::modelerAlgorithm()
44584458
alg4.setChildAlgorithm( c10 );
44594459
QVERIFY( alg4.childAlgorithmsDependOnParameter( "p1" ) );
44604460

4461+
QgsProcessingModelAlgorithm::ModelParameter vlP;
4462+
alg4.addModelParameter( new QgsProcessingParameterVectorLayer( "layer" ), vlP );
4463+
QgsProcessingModelAlgorithm::ModelParameter field;
4464+
alg4.addModelParameter( new QgsProcessingParameterField( "field", QString(), QVariant(), QStringLiteral( "layer" ) ), field );
4465+
QVERIFY( !alg4.otherParametersDependOnParameter( "p1" ) );
4466+
QVERIFY( !alg4.otherParametersDependOnParameter( "field" ) );
4467+
QVERIFY( alg4.otherParametersDependOnParameter( "layer" ) );
4468+
4469+
4470+
44614471

44624472

44634473
// to/from XML

0 commit comments

Comments
 (0)