Skip to content
Permalink
Browse files

Allow access to parent algorithm for processing parameters

  • Loading branch information
nyalldawson committed Nov 6, 2017
1 parent 7cfbb6f commit 2a280d69aa852068e6a7123ecfd1426bc444942f
@@ -353,13 +353,22 @@ class QgsProcessingParameterDefinition
:rtype: list of str
%End

QgsProcessingAlgorithm *algorithm() const;
%Docstring
Returns a pointer to the algorithm which owns this parameter. May be None
for non-owned parameters.
:rtype: QgsProcessingAlgorithm
%End

protected:








};

QFlags<QgsProcessingParameterDefinition::Flag> operator|(QgsProcessingParameterDefinition::Flag f1, QFlags<QgsProcessingParameterDefinition::Flag> f2);
@@ -242,6 +242,7 @@ bool QgsProcessingAlgorithm::addParameter( QgsProcessingParameterDefinition *def
}

mParameters << definition;
definition->mAlgorithm = this;

if ( createOutput )
return createAutoOutputForParameter( definition );
@@ -1237,6 +1237,11 @@ bool QgsProcessingParameterDefinition::fromVariantMap( const QVariantMap &map )
return true;
}

QgsProcessingAlgorithm *QgsProcessingParameterDefinition::algorithm() const
{
return mAlgorithm;
}

QgsProcessingParameterBoolean::QgsProcessingParameterBoolean( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
{}
@@ -391,6 +391,12 @@ class CORE_EXPORT QgsProcessingParameterDefinition
*/
virtual QStringList dependsOnOtherParameters() const { return QStringList(); }

/**
* Returns a pointer to the algorithm which owns this parameter. May be nullptr
* for non-owned parameters.
*/
QgsProcessingAlgorithm *algorithm() const;

protected:

//! Parameter name
@@ -408,6 +414,12 @@ class CORE_EXPORT QgsProcessingParameterDefinition
//! Freeform metadata for parameter. Mostly used by widget wrappers to customise their appearance and behavior.
QVariantMap mMetadata;

//! Pointer to algorithm which owns this parameter
QgsProcessingAlgorithm *mAlgorithm = nullptr;

// To allow access to mAlgorithm. We don't want a public setter for this!
friend class QgsProcessingAlgorithm;

};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProcessingParameterDefinition::Flags )
@@ -75,6 +75,7 @@ class DummyAlgorithm : public QgsProcessingAlgorithm
QVERIFY( addParameter( new QgsProcessingParameterBoolean( "p1" ) ) );
QCOMPARE( parameterDefinitions().count(), 1 );
QCOMPARE( parameterDefinitions().at( 0 )->name(), QString( "p1" ) );
QCOMPARE( parameterDefinitions().at( 0 )->algorithm(), this );

QVERIFY( !addParameter( nullptr ) );
QCOMPARE( parameterDefinitions().count(), 1 );

0 comments on commit 2a280d6

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