Skip to content

Commit

Permalink
[processing] new parameter type for point cloud attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Apr 3, 2023
1 parent dc77709 commit 1f77406
Show file tree
Hide file tree
Showing 10 changed files with 781 additions and 22 deletions.
Expand Up @@ -942,6 +942,16 @@ Evaluates the parameter with matching ``name`` to a range of values.
QStringList parameterAsFields( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a list of fields.

.. deprecated::
use :py:func:`~QgsProcessingAlgorithm.parameterAsStrings` instead.
%End

QStringList parameterAsStrings( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a list of strings (e.g. field names or point cloud atributes).

.. versionadded:: 3.32
%End

QgsPrintLayout *parameterAsLayout( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context );
Expand Down
122 changes: 122 additions & 0 deletions python/core/auto_generated/processing/qgsprocessingparameters.sip.in
Expand Up @@ -335,6 +335,8 @@ their acceptable ranges, defaults, etc.
sipType = sipType_QgsProcessingParameterPointCloudLayer;
else if ( sipCpp->type() == QgsProcessingParameterAnnotationLayer::typeName() )
sipType = sipType_QgsProcessingParameterAnnotationLayer;
else if ( sipCpp->type() == QgsProcessingParameterPointCloudAttribute::typeName() )
sipType = sipType_QgsProcessingParameterPointCloudAttribute;
else
sipType = nullptr;
%End
Expand Down Expand Up @@ -1477,13 +1479,33 @@ Evaluates the parameter with matching ``definition`` and ``value`` to a range of
static QStringList parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` to a list of fields.

.. deprecated::
use :py:func:`~QgsProcessingParameters.parameterAsStrings` instead.
%End

static QStringList parameterAsFields( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` and ``value`` to a list of fields.

.. versionadded:: 3.4

.. deprecated::
use :py:func:`~QgsProcessingParameters.parameterAsStrings` instead.
%End

static QStringList parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` to a list of strings (e.g. field names or point cloud attributes).

.. versionadded:: 3.32.
%End

static QStringList parameterAsStrings( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` and ``value`` to a list of strings (e.g. field names or point cloud attributes).

.. versionadded:: 3.32
%End

static QgsPrintLayout *parameterAsLayout( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
Expand Down Expand Up @@ -4762,6 +4784,106 @@ Creates a new parameter using the definition from a script code.
%End
};

class QgsProcessingParameterPointCloudAttribute : QgsProcessingParameterDefinition
{
%Docstring(signature="appended")
A point cloud layer attribute parameter for Processing algorithms.

.. versionadded:: 3.32
%End

%TypeHeaderCode
#include "qgsprocessingparameters.h"
%End
public:

QgsProcessingParameterPointCloudAttribute( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
const QString &parentLayerParameterName = QString(),
bool allowMultiple = false,
bool optional = false,
bool defaultToAllAttributes = false );
%Docstring
Constructor for :py:class:`QgsProcessingParameterField`.
%End

static QString typeName();
%Docstring
Returns the type name for the parameter class.
%End
virtual QgsProcessingParameterDefinition *clone() const /Factory/;

virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;

virtual QString asScriptCode() const;

virtual QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const;

virtual QStringList dependsOnOtherParameters() const;


QString parentLayerParameterName() const;
%Docstring
Returns the name of the parent layer parameter, or an empty string if this is not set.

.. seealso:: :py:func:`setParentLayerParameterName`
%End

void setParentLayerParameterName( const QString &parentLayerParameterName );
%Docstring
Sets the name of the parent layer parameter. Use an empty string if this is not required.

.. seealso:: :py:func:`parentLayerParameterName`
%End

bool allowMultiple() const;
%Docstring
Returns whether multiple field selections are permitted.

.. seealso:: :py:func:`setAllowMultiple`
%End

void setAllowMultiple( bool allowMultiple );
%Docstring
Sets whether multiple field selections are permitted.

.. seealso:: :py:func:`allowMultiple`
%End

bool defaultToAllAttributes() const;
%Docstring
Returns whether a parameter which allows multiple selections (see :py:func:`~QgsProcessingParameterPointCloudAttribute.allowMultiple`) should automatically
select all attributes as the default value.

If ``True``, this will override any existing :py:func:`~QgsProcessingParameterPointCloudAttribute.defaultValue` set on the parameter.

.. seealso:: :py:func:`setDefaultToAllAttributes`
%End

void setDefaultToAllAttributes( bool enabled );
%Docstring
Sets whether a parameter which allows multiple selections (see :py:func:`~QgsProcessingParameterPointCloudAttribute.allowMultiple`) should automatically
select all attributes as the default value.

If ``True``, this will override any existing :py:func:`~QgsProcessingParameterPointCloudAttribute.defaultValue` set on the parameter.

.. seealso:: :py:func:`defaultToAllAttributes`
%End

virtual QVariantMap toVariantMap() const;

virtual bool fromVariantMap( const QVariantMap &map );


static QgsProcessingParameterPointCloudAttribute *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
%Docstring
Creates a new parameter using the definition from a script code.
%End

};




Expand Down
7 changes: 6 additions & 1 deletion src/core/processing/qgsprocessingalgorithm.cpp
Expand Up @@ -837,7 +837,12 @@ QList<double> QgsProcessingAlgorithm::parameterAsRange( const QVariantMap &param

QStringList QgsProcessingAlgorithm::parameterAsFields( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsFields( parameterDefinition( name ), parameters, context );
return QgsProcessingParameters::parameterAsStrings( parameterDefinition( name ), parameters, context );
}

QStringList QgsProcessingAlgorithm::parameterAsStrings( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsStrings( parameterDefinition( name ), parameters, context );
}

QgsPrintLayout *QgsProcessingAlgorithm::parameterAsLayout( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
Expand Down
9 changes: 9 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -943,9 +943,18 @@ class CORE_EXPORT QgsProcessingAlgorithm

/**
* Evaluates the parameter with matching \a name to a list of fields.
*
* \deprecated use parameterAsStrings() instead.
*/
QStringList parameterAsFields( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;

/**
* Evaluates the parameter with matching \a name to a list of strings (e.g. field names or point cloud atributes).
*
* \since QGIS 3.32
*/
QStringList parameterAsStrings( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;

/**
* Evaluates the parameter with matching \a name to a print layout.
*
Expand Down

0 comments on commit 1f77406

Please sign in to comment.