mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[processing] Some more framework for dynamic (data defined) parameters
This commit is contained in:
parent
618baf925d
commit
ecbc4718d4
@ -376,6 +376,69 @@ class QgsProcessingParameterDefinition
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
bool isDynamic() const;
|
||||
%Docstring
|
||||
Returns true if the parameter supports is dynamic, and can support data-defined values
|
||||
(i.e. QgsProperty based values).
|
||||
.. seealso:: setIsDynamic()
|
||||
.. seealso:: dynamicPropertyDefinition()
|
||||
.. seealso:: dynamicLayerParameterName()
|
||||
:rtype: bool
|
||||
%End
|
||||
|
||||
void setIsDynamic( bool dynamic );
|
||||
%Docstring
|
||||
Sets whether the parameter is ``dynamic``, and can support data-defined values
|
||||
(i.e. QgsProperty based values).
|
||||
.. seealso:: isDynamic()
|
||||
.. seealso:: setDynamicPropertyDefinition()
|
||||
.. seealso:: setDynamicLayerParameterName()
|
||||
%End
|
||||
|
||||
QgsPropertyDefinition dynamicPropertyDefinition() const;
|
||||
%Docstring
|
||||
Returns the property definition for dynamic properties.
|
||||
.. seealso:: isDynamic()
|
||||
.. seealso:: setDynamicPropertyDefinition()
|
||||
.. seealso:: dynamicLayerParameterName()
|
||||
:rtype: QgsPropertyDefinition
|
||||
%End
|
||||
|
||||
void setDynamicPropertyDefinition( const QgsPropertyDefinition &definition );
|
||||
%Docstring
|
||||
Sets the property ``definition`` for dynamic properties.
|
||||
.. seealso:: isDynamic()
|
||||
.. seealso:: dynamicPropertyDefinition()
|
||||
.. seealso:: setDynamicLayerParameterName()
|
||||
%End
|
||||
|
||||
QString dynamicLayerParameterName() const;
|
||||
%Docstring
|
||||
Returns the name of the parameter for a layer linked to a dynamic parameter, or an empty string if this is not set.
|
||||
|
||||
Dynamic parameters (see isDynamic()) can have an optional vector layer parameter linked to them,
|
||||
which indicates which layer the fields and values will be available from when evaluating
|
||||
the dynamic parameter.
|
||||
|
||||
.. seealso:: setDynamicLayerParameterName()
|
||||
.. seealso:: isDynamic()
|
||||
.. seealso:: dynamicPropertyDefinition()
|
||||
:rtype: str
|
||||
%End
|
||||
|
||||
void setDynamicLayerParameterName( const QString &name );
|
||||
%Docstring
|
||||
Sets the ``name`` for the parameter for a layer linked to a dynamic parameter, or an empty string if this is not set.
|
||||
|
||||
Dynamic parameters (see isDynamic()) can have an optional vector layer parameter linked to them,
|
||||
which indicates which layer the fields and values will be available from when evaluating
|
||||
the dynamic parameter.
|
||||
|
||||
.. seealso:: dynamicLayerParameterName()
|
||||
.. seealso:: isDynamic()
|
||||
.. seealso:: setDynamicPropertyDefinition()
|
||||
%End
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@ -385,6 +448,9 @@ class QgsProcessingParameterDefinition
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
QFlags<QgsProcessingParameterDefinition::Flag> operator|(QgsProcessingParameterDefinition::Flag f1, QFlags<QgsProcessingParameterDefinition::Flag> f2);
|
||||
|
@ -412,6 +412,66 @@ class CORE_EXPORT QgsProcessingParameterDefinition
|
||||
*/
|
||||
virtual QString toolTip() const;
|
||||
|
||||
/**
|
||||
* Returns true if the parameter supports is dynamic, and can support data-defined values
|
||||
* (i.e. QgsProperty based values).
|
||||
* \see setIsDynamic()
|
||||
* \see dynamicPropertyDefinition()
|
||||
* \see dynamicLayerParameterName()
|
||||
*/
|
||||
bool isDynamic() const { return mIsDynamic; }
|
||||
|
||||
/**
|
||||
* Sets whether the parameter is \a dynamic, and can support data-defined values
|
||||
* (i.e. QgsProperty based values).
|
||||
* \see isDynamic()
|
||||
* \see setDynamicPropertyDefinition()
|
||||
* \see setDynamicLayerParameterName()
|
||||
*/
|
||||
void setIsDynamic( bool dynamic ) { mIsDynamic = dynamic; }
|
||||
|
||||
/**
|
||||
* Returns the property definition for dynamic properties.
|
||||
* \see isDynamic()
|
||||
* \see setDynamicPropertyDefinition()
|
||||
* \see dynamicLayerParameterName()
|
||||
*/
|
||||
QgsPropertyDefinition dynamicPropertyDefinition() const { return mPropertyDefinition; }
|
||||
|
||||
/**
|
||||
* Sets the property \a definition for dynamic properties.
|
||||
* \see isDynamic()
|
||||
* \see dynamicPropertyDefinition()
|
||||
* \see setDynamicLayerParameterName()
|
||||
*/
|
||||
void setDynamicPropertyDefinition( const QgsPropertyDefinition &definition ) { mPropertyDefinition = definition; }
|
||||
|
||||
/**
|
||||
* Returns the name of the parameter for a layer linked to a dynamic parameter, or an empty string if this is not set.
|
||||
*
|
||||
* Dynamic parameters (see isDynamic()) can have an optional vector layer parameter linked to them,
|
||||
* which indicates which layer the fields and values will be available from when evaluating
|
||||
* the dynamic parameter.
|
||||
*
|
||||
* \see setDynamicLayerParameterName()
|
||||
* \see isDynamic()
|
||||
* \see dynamicPropertyDefinition()
|
||||
*/
|
||||
QString dynamicLayerParameterName() const { return mDynamicLayerParameterName; }
|
||||
|
||||
/**
|
||||
* Sets the \a name for the parameter for a layer linked to a dynamic parameter, or an empty string if this is not set.
|
||||
*
|
||||
* Dynamic parameters (see isDynamic()) can have an optional vector layer parameter linked to them,
|
||||
* which indicates which layer the fields and values will be available from when evaluating
|
||||
* the dynamic parameter.
|
||||
*
|
||||
* \see dynamicLayerParameterName()
|
||||
* \see isDynamic()
|
||||
* \see setDynamicPropertyDefinition()
|
||||
*/
|
||||
void setDynamicLayerParameterName( const QString &name ) { mDynamicLayerParameterName = name; }
|
||||
|
||||
protected:
|
||||
|
||||
//! Parameter name
|
||||
@ -432,6 +492,15 @@ class CORE_EXPORT QgsProcessingParameterDefinition
|
||||
//! Pointer to algorithm which owns this parameter
|
||||
QgsProcessingAlgorithm *mAlgorithm = nullptr;
|
||||
|
||||
//! True for dynamic parameters, which can have data-defined (QgsProperty) based values
|
||||
bool mIsDynamic = false;
|
||||
|
||||
//! Data defined property definition
|
||||
QgsPropertyDefinition mPropertyDefinition;
|
||||
|
||||
//! Linked vector layer parameter name for dynamic properties
|
||||
QString mDynamicLayerParameterName;
|
||||
|
||||
// To allow access to mAlgorithm. We don't want a public setter for this!
|
||||
friend class QgsProcessingAlgorithm;
|
||||
|
||||
|
@ -1445,6 +1445,7 @@ void TestQgsProcessing::parameters()
|
||||
// test parameter utilities
|
||||
|
||||
std::unique_ptr< QgsProcessingParameterDefinition > def;
|
||||
|
||||
QVariantMap params;
|
||||
params.insert( QStringLiteral( "prop" ), QgsProperty::fromField( "a_field" ) );
|
||||
params.insert( QStringLiteral( "string" ), QStringLiteral( "a string" ) );
|
||||
@ -1471,6 +1472,13 @@ void TestQgsProcessing::parameters()
|
||||
def->setName( QStringLiteral( "bad" ) );
|
||||
QCOMPARE( QgsProcessingParameters::parameterAsString( def.get(), params, context ), QString() );
|
||||
|
||||
def->setIsDynamic( true );
|
||||
QVERIFY( def->isDynamic() );
|
||||
def->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "Distance" ), QObject::tr( "Buffer distance" ), QgsPropertyDefinition::Double ) );
|
||||
QCOMPARE( def->dynamicPropertyDefinition().name(), QStringLiteral( "Distance" ) );
|
||||
def->setDynamicLayerParameterName( "parent" );
|
||||
QCOMPARE( def->dynamicLayerParameterName(), QStringLiteral( "parent" ) );
|
||||
|
||||
// string with dynamic property (feature not set)
|
||||
def->setName( QStringLiteral( "prop" ) );
|
||||
QCOMPARE( QgsProcessingParameters::parameterAsString( def.get(), params, context ), QString() );
|
||||
|
Loading…
x
Reference in New Issue
Block a user