Merge pull request #4826 from nyalldawson/processing_cleanups

Some more cleanups and misc fixes to processing code
This commit is contained in:
Nyall Dawson 2017-07-08 21:57:58 +10:00 committed by GitHub
commit 40d833ff5f
82 changed files with 3919 additions and 3200 deletions

View File

@ -117,6 +117,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/layout
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/processing
${CMAKE_SOURCE_DIR}/src/core/processing/models
${CMAKE_SOURCE_DIR}/src/core/providers
${CMAKE_SOURCE_DIR}/src/core/providers/memory
${CMAKE_SOURCE_DIR}/src/core/raster

View File

@ -161,12 +161,18 @@
%Include layout/qgslayoutsize.sip
%Include metadata/qgslayermetadata.sip
%Include metadata/qgslayermetadatavalidator.sip
%Include processing/qgsprocessing.sip
%Include processing/qgsprocessingalgorithm.sip
%Include processing/qgsprocessingcontext.sip
%Include processing/qgsprocessingmodelalgorithm.sip
%Include processing/qgsprocessingoutputs.sip
%Include processing/qgsprocessingparameters.sip
%Include processing/qgsprocessingutils.sip
%Include processing/models/qgsprocessingmodelalgorithm.sip
%Include processing/models/qgsprocessingmodelchildalgorithm.sip
%Include processing/models/qgsprocessingmodelchildparametersource.sip
%Include processing/models/qgsprocessingmodelcomponent.sip
%Include processing/models/qgsprocessingmodeloutput.sip
%Include processing/models/qgsprocessingmodelparameter.sip
%Include providers/memory/qgsmemoryproviderutils.sip
%Include raster/qgsbilinearrasterresampler.sip
%Include raster/qgsbrightnesscontrastfilter.sip

View File

@ -0,0 +1,379 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/models/qgsprocessingmodelalgorithm.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsProcessingModelAlgorithm : QgsProcessingAlgorithm
{
%Docstring
Model based algorithm with processing.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingmodelalgorithm.h"
%End
public:
QgsProcessingModelAlgorithm( const QString &name = QString(), const QString &group = QString() );
%Docstring
Constructor for QgsProcessingModelAlgorithm.
%End
virtual QString name() const;
virtual QString displayName() const;
virtual QString group() const;
virtual QIcon icon() const;
virtual QString svgIconPath() const;
virtual QString shortHelpString() const;
virtual QString helpUrl() const;
virtual bool canExecute( QString *errorMessage /Out/ = 0 ) const;
virtual QString asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const;
virtual QgsProcessingModelAlgorithm *create() const /Factory/;
void setName( const QString &name );
%Docstring
Sets the model ``name``.
.. seealso:: name()
%End
void setGroup( const QString &group );
%Docstring
Sets the model ``group``.
.. seealso:: group()
%End
QMap<QString, QgsProcessingModelChildAlgorithm> childAlgorithms() const;
%Docstring
Returns the map of child algorithms contained in the model. The keys
are the child algorithm ids (see QgsProcessingModelAlgorithm.ChildAlgorithm.childId()).
.. seealso:: childAlgorithm()
.. seealso:: setChildAlgorithms()
.. seealso:: addChildAlgorithm()
:rtype: QMap<str, QgsProcessingModelChildAlgorithm>
%End
void setChildAlgorithms( const QMap<QString, QgsProcessingModelChildAlgorithm> &childAlgorithms );
%Docstring
Sets the map of child algorithms contained in the model. The keys
are the child algorithm ids (see QgsProcessingModelAlgorithm.ChildAlgorithm.childId()).
All existing child algorithms will be replaced.
.. seealso:: childAlgorithms()
.. seealso:: childAlgorithm()
.. seealso:: setChildAlgorithm()
.. seealso:: addChildAlgorithm()
%End
void setChildAlgorithm( const QgsProcessingModelChildAlgorithm &algorithm );
%Docstring
Sets the child ``algorithm`` within the model. If a child algorithm already
exists in the model with the same child ID then that algorithm will be replaced.
.. seealso:: addChildAlgorithm()
.. seealso:: setChildAlgorithms()
%End
QString addChildAlgorithm( QgsProcessingModelChildAlgorithm &algorithm );
%Docstring
Adds a new child ``algorithm`` to the model. If a child algorithm already exists
in the model with the same child ID then ``algorithm`` will be assigned a new
autogenerated unique ID.
The assigned child ID will be returned.
.. seealso:: childAlgorithms()
.. seealso:: childAlgorithm()
.. seealso:: setChildAlgorithm()
.. seealso:: setChildAlgorithms()
:rtype: str
%End
QgsProcessingModelChildAlgorithm &childAlgorithm( const QString &id );
%Docstring
Returns the child algorithm with matching ``id``. If no child algorithm exists with
this ID a new algorithm will be added to the model and returned.
.. seealso:: addChildAlgorithm()
.. seealso:: childAlgorithms()
:rtype: QgsProcessingModelChildAlgorithm
%End
bool removeChildAlgorithm( const QString &id );
%Docstring
Attempts to remove the child algorithm with matching ``id``.
Returns true if the algorithm could be removed, or false
if the algorithm could not be removed (e.g. due to other
child algorithms depending on it).
.. seealso:: deactivateChildAlgorithm()
:rtype: bool
%End
void deactivateChildAlgorithm( const QString &id );
%Docstring
Deactivates the child algorithm with matching ``id``.
All other child algorithms which depend on the child
algorithm will also be deactivated.
.. seealso:: removeChildAlgorithm()
.. seealso:: activateChildAlgorithm()
%End
bool activateChildAlgorithm( const QString &id );
%Docstring
Attempts to activate the child algorithm with matching ``id``.
If any child algorithms on which the child depends are not active,
then the child will not be activated and false will be returned.
.. seealso:: deactivateChildAlgorithm()
:rtype: bool
%End
QSet< QString > dependentChildAlgorithms( const QString &childId ) const;
%Docstring
Returns a list of the child algorithm IDs depending on the child
algorithm with the specified ``childId``.
.. seealso:: dependsOnChildAlgorithms()
:rtype: set of str
%End
QSet< QString > dependsOnChildAlgorithms( const QString &childId ) const;
%Docstring
Returns a list of the child algorithm IDs on which the child
algorithm with the specified ``childId`` depends upon.
.. seealso:: dependentChildAlgorithms()
:rtype: set of str
%End
void addModelParameter( QgsProcessingParameterDefinition *definition /Transfer/, const QgsProcessingModelParameter &component );
%Docstring
Adds a new parameter to the model, with the specified ``definition`` and graphical ``component``.
Ownership of ``definition`` is transferred to the model.
.. seealso:: updateModelParameter()
.. seealso:: removeModelParameter()
%End
void updateModelParameter( QgsProcessingParameterDefinition *definition /Transfer/ );
%Docstring
Replaces the definition of an existing parameter (by parameter name) with a new ``definition``. Ownership of
``definition`` is transferred to the model, and any existing parameter is deleted.
.. seealso:: addModelParameter()
.. seealso:: removeModelParameter()
%End
void removeModelParameter( const QString &name );
%Docstring
Removes an existing model parameter by ``name``. The definition of the matching parameter
is deleted.
.. seealso:: addModelParameter()
.. seealso:: updateModelParameter()
%End
bool childAlgorithmsDependOnParameter( const QString &name ) const;
%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
QMap<QString, QgsProcessingModelParameter> parameterComponents() const;
%Docstring
Returns the map of parameter components used by the model. The keys
should match the algorithm's parameter names (see parameterDefinitions() ).
.. seealso:: setParameterComponent()
.. seealso:: parameterComponent()
:rtype: QMap<str, QgsProcessingModelParameter>
%End
void setParameterComponents( const QMap<QString, QgsProcessingModelParameter> &parameterComponents );
%Docstring
Sets the map of parameter components used by the model. The keys
should match the algorithm's parameter names (see parameterDefinitions() ).
All existing parameter components will be replaced.
.. seealso:: parameterComponents()
.. seealso:: setParameterComponent()
.. seealso:: parameterComponent()
%End
void setParameterComponent( const QgsProcessingModelParameter &component );
%Docstring
Sets a parameter ``component`` for the model. If a parameter component already
exists in the model with the same parameter name then that component will be replaced.
.. seealso:: parameterComponents()
.. seealso:: setParameterComponents()
.. seealso:: parameterComponent()
%End
QgsProcessingModelParameter &parameterComponent( const QString &name );
%Docstring
Returns the parameter component with matching ``name``. If no parameter component exists with
this name a new component will be added to the model and returned.
.. seealso:: parameterComponents()
.. seealso:: setParameterComponents()
.. seealso:: setParameterComponent()
:rtype: QgsProcessingModelParameter
%End
void updateDestinationParameters();
%Docstring
Updates the model's parameter definitions to include all relevant destination
parameters as required by child algorithm ModelOutputs.
Must be called whenever child algorithm ModelOutputs are altered.
%End
bool toFile( const QString &path ) const;
%Docstring
Writes the model to a file, at the specified ``path``.
.. seealso:: fromFile()
:rtype: bool
%End
bool fromFile( const QString &path );
%Docstring
Reads the model from a file, at the specified ``path``.
.. seealso:: toFile()
:rtype: bool
%End
QVariantMap &helpContent();
%Docstring
Returns the model's help contents (a free-form map of values describing the algorithm's
use and metadata).
.. seealso:: setHelpContent()
:rtype: QVariantMap
%End
void setHelpContent( const QVariantMap &contents );
%Docstring
Sets the model's help ``contents`` (a free-form map of values describing the algorithm's
use and metadata).
.. seealso:: helpContent()
%End
QString sourceFilePath() const;
%Docstring
Returns the source file path for the model, if available.
.. seealso:: setSourceFilePath()
:rtype: str
%End
void setSourceFilePath( const QString &path );
%Docstring
Sets the source file ``path`` for the model, if available.
.. seealso:: sourceFilePath()
%End
QString asPythonCode() const;
%Docstring
Attempts to convert the model to executable Python code.
:rtype: str
%End
QList< QgsProcessingModelChildParameterSource > availableSourcesForChild( const QString &childId, const QStringList &parameterTypes = QStringList(),
const QStringList &outputTypes = QStringList(), const QList< int > dataTypes = QList< int >() ) const;
%Docstring
Returns a list of possible sources which can be used for the parameters for a child
algorithm in the model. Returned sources are those which match either one of the
specified ``parameterTypes`` (see QgsProcessingParameterDefinition.type() ) or
on of the specified ``outputTypes`` (see QgsProcessingOutputDefinition.type() ).
If specified, an optional list of ``dataTypes`` can be used to filter the returned
sources to those with compatible data types for the parameter/outputs.
:rtype: list of QgsProcessingModelChildParameterSource
%End
class VariableDefinition
{
%Docstring
Definition of a expression context variable available during model execution.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingmodelalgorithm.h"
%End
public:
VariableDefinition( const QVariant &value = QVariant(), const QgsProcessingModelChildParameterSource &source = QgsProcessingModelChildParameterSource::fromStaticValue( QVariant() ), const QString &description = QString() );
%Docstring
Constructor for a new VariableDefinition with the specified ``value`` and original
parameter ``source``, and ``description``.
%End
QVariant value;
%Docstring
Value of variable
%End
QgsProcessingModelChildParameterSource source;
%Docstring
Original source of variable's value
%End
QString description;
%Docstring
Translated description of variable
%End
};
QMap< QString, QgsProcessingModelAlgorithm::VariableDefinition > variablesForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(),
const QVariantMap &results = QVariantMap() ) const;
%Docstring
Returns a map of variable name to variable definition for expression context variables which are available
for use by child algorithm during model execution.
The child algorithm ``childId`` and processing ``context``
are manadatory. If ``modelParameters`` and ``results`` are not specified, then only the variable names and sources
will be returned, but all variable values will be null. This can be used to determine in advance which variables
will be available for a specific child algorithm, e.g. for use in expression builder widgets.
In order to calculate the actual variable value, the input model ``modelParameters`` and already executed child
algorithm ``results`` must be passed.
.. seealso:: createExpressionContextScopeForChildAlgorithm()
:rtype: QMap< str, QgsProcessingModelAlgorithm.VariableDefinition >
%End
QgsExpressionContextScope *createExpressionContextScopeForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(),
const QVariantMap &results = QVariantMap() ) const /Factory/;
%Docstring
Creates a new expression context scope for a child algorithm within the model.
.. seealso:: variablesForChildAlgorithm()
:rtype: QgsExpressionContextScope
%End
protected:
virtual QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/models/qgsprocessingmodelalgorithm.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -0,0 +1,236 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/models/qgsprocessingmodelchildalgorithm.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsProcessingModelChildAlgorithm : QgsProcessingModelComponent
{
%Docstring
Child algorithm representing a single component of a QgsProcessingModelAlgorithm.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingmodelchildalgorithm.h"
%End
public:
QgsProcessingModelChildAlgorithm( const QString &algorithmId = QString() );
%Docstring
Constructor for QgsProcessingModelChildAlgorithm. The ``algorithmId`` parameter
should be set to a QgsProcessingAlgorithm algorithm ID.
%End
QString childId() const;
%Docstring
Returns the child algorithm's unique ID string, used the identify
this child algorithm within its parent model.
.. seealso:: setChildId()
.. seealso:: generateChildId()
:rtype: str
%End
void setChildId( const QString &id );
%Docstring
Sets the child algorithm's unique ``id`` string, used the identify
this child algorithm within its parent model.
.. seealso:: childId()
.. seealso:: generateChildId()
%End
void generateChildId( const QgsProcessingModelAlgorithm &model );
%Docstring
Automatically generates a unique childId() for the algorithm,
avoiding child IDs which are already present in ``model``.
.. seealso:: childId()
.. seealso:: setChildId()
%End
QString algorithmId() const;
%Docstring
Returns the underlying child algorithm's ID.
.. seealso:: algorithm()
.. seealso:: setAlgorithmId()
:rtype: str
%End
void setAlgorithmId( const QString &algorithmId );
%Docstring
Sets the underlying child algorithm's ID. This
should be set to an existing QgsProcessingAlgorithm algorithm ID.
.. seealso:: algorithm()
.. seealso:: algorithmId()
%End
const QgsProcessingAlgorithm *algorithm() const;
%Docstring
Returns the underlying child algorithm, or a None
if a matching algorithm is not available.
.. seealso:: algorithmId()
:rtype: QgsProcessingAlgorithm
%End
QMap< QString, QList< QgsProcessingModelChildParameterSource > > parameterSources() const;
%Docstring
Returns a map of parameter sources. The keys are the child algorithm
parameter names, the values are the sources for that parameter.
.. seealso:: setParameterSources()
.. seealso:: addParameterSources()
:rtype: QMap< str, QList< QgsProcessingModelChildParameterSource > >
%End
void setParameterSources( const QMap< QString, QList< QgsProcessingModelChildParameterSource > > &sources );
%Docstring
Sets the map of parameter ``sources``. The keys are the child algorithm
parameter names, the values are the sources for that parameter.
.. seealso:: parameterSources()
.. seealso:: addParameterSources()
%End
void addParameterSources( const QString &name, const QList< QgsProcessingModelChildParameterSource > &source );
%Docstring
Adds a parameter source. The ``name`` argument should match
one of the child algorithm's parameter names, and the ``sources``
argument is used to set the sources for that parameter.
Any existing parameter sources with matching name will be replaced.
.. seealso:: parameterSources()
.. seealso:: setParameterSources()
%End
bool isActive() const;
%Docstring
Returns true if the child algorithm is active.
.. seealso:: setActive()
:rtype: bool
%End
void setActive( bool active );
%Docstring
Sets whether the child algorithm is active.
.. seealso:: isActive()
%End
QStringList dependencies() const;
%Docstring
Returns the list of child algorithms from the parent model on which this
algorithm is dependent. The returned list contains the id() of the
dependent algorithms.
.. seealso:: setDependencies()
:rtype: list of str
%End
void setDependencies( const QStringList &dependencies );
%Docstring
Sets the list of child algorithms from the parent model on which this
algorithm is dependent. The list should contain the id() of the
dependent algorithms.
.. seealso:: dependencies()
%End
bool parametersCollapsed() const;
%Docstring
Returns true if the list of parameters for this algorithm should be collapsed
in the graphical modeller.
.. seealso:: setParametersCollapsed()
.. seealso:: outputsCollapsed()
:rtype: bool
%End
void setParametersCollapsed( bool collapsed );
%Docstring
Sets whether the list of parameters for this algorithm should be collapsed
in the graphical modeller.
.. seealso:: parametersCollapsed()
.. seealso:: setOutputsCollapsed()
%End
bool outputsCollapsed() const;
%Docstring
Returns true if the list of outputs for this algorithm should be collapsed
in the graphical modeller.
.. seealso:: setParametersCollapsed()
.. seealso:: parametersCollapsed()
:rtype: bool
%End
void setOutputsCollapsed( bool collapsed );
%Docstring
Sets whether the list of outputs for this algorithm should be collapsed
in the graphical modeller.
.. seealso:: outputsCollapsed()
.. seealso:: setParametersCollapsed()
%End
QMap<QString, QgsProcessingModelOutput> modelOutputs() const;
%Docstring
Returns the map of final model outputs which are generated by this child algorithm.
The keys are the output names from this child algorithm. Only outputs which are
part of the final outputs from the model are included in this map.
.. seealso:: setModelOutputs()
.. seealso:: modelOutput()
:rtype: QMap<str, QgsProcessingModelOutput>
%End
QgsProcessingModelOutput &modelOutput( const QString &name );
%Docstring
Returns the final model output with matching ``name``. If no output
exists with the name, a new one will be created and returned.
If child model outputs are altered by this method, QgsProcessingModelAlgorithm.updateDestinationParameters()
must be called on the parent model.
.. seealso:: modelOutputs()
.. seealso:: setModelOutputs()
:rtype: QgsProcessingModelOutput
%End
void setModelOutputs( const QMap<QString, QgsProcessingModelOutput> &outputs );
%Docstring
Sets the map of final model ``outputs`` which are generated by this child algorithm.
Only outputs which are part of the final outputs from the model should be included in this map.
If child model outputs are altered by this method, QgsProcessingModelAlgorithm.updateDestinationParameters()
must be called on the parent model.
.. seealso:: modelOutputs()
%End
QVariant toVariant() const;
%Docstring
Saves this child to a QVariant.
.. seealso:: loadVariant()
:rtype: QVariant
%End
bool loadVariant( const QVariant &child );
%Docstring
Loads this child from a QVariant.
.. seealso:: toVariant()
:rtype: bool
%End
QString asPythonCode() const;
%Docstring
Attempts to convert the child to executable Python code.
:rtype: str
%End
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/models/qgsprocessingmodelchildalgorithm.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -0,0 +1,192 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/models/qgsprocessingmodelchildparametersource.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsProcessingModelChildParameterSource
{
%Docstring
Source for the value of a parameter for a child algorithm within a model.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingmodelchildparametersource.h"
%End
public:
enum Source
{
ModelParameter,
ChildOutput,
StaticValue,
Expression,
};
QgsProcessingModelChildParameterSource();
%Docstring
Constructor for QgsProcessingModelChildParameterSource. It is recommended that the static methods
fromStaticValue(), fromModelParameter(), fromChildOutput() and fromExpression() are used instead.
%End
bool operator==( const QgsProcessingModelChildParameterSource &other ) const;
bool operator!=( const QgsProcessingModelChildParameterSource &other ) const;
%Docstring
:rtype: bool
%End
static QgsProcessingModelChildParameterSource fromStaticValue( const QVariant &value );
%Docstring
Returns a new QgsProcessingModelChildParameterSource which takes its value from a static ``value``.
.. seealso:: fromModelParameter()
.. seealso:: fromChildOutput()
.. seealso:: fromExpression()
:rtype: QgsProcessingModelChildParameterSource
%End
static QgsProcessingModelChildParameterSource fromModelParameter( const QString &parameterName );
%Docstring
Returns a new QgsProcessingModelChildParameterSource which takes its value from a parent model parameter.
.. seealso:: fromStaticValue()
.. seealso:: fromChildOutput()
.. seealso:: fromExpression()
:rtype: QgsProcessingModelChildParameterSource
%End
static QgsProcessingModelChildParameterSource fromChildOutput( const QString &childId, const QString &outputName );
%Docstring
Returns a new QgsProcessingModelChildParameterSource which takes its value from an output generated by a child algorithm.
.. seealso:: fromStaticValue()
.. seealso:: fromModelParameter()
.. seealso:: fromExpression()
:rtype: QgsProcessingModelChildParameterSource
%End
static QgsProcessingModelChildParameterSource fromExpression( const QString &expression );
%Docstring
Returns a new QgsProcessingModelChildParameterSource which takes its value from an expression. The expression
is evaluated just before the child algorithm executes, and can use functions available
in its expression context to include results calculated from the child algorithms already
executed by the model.
.. seealso:: fromStaticValue()
.. seealso:: fromChildOutput()
.. seealso:: fromModelParameter()
:rtype: QgsProcessingModelChildParameterSource
%End
Source source() const;
%Docstring
Returns the parameter value's source.
:rtype: Source
%End
QVariant staticValue() const;
%Docstring
Returns the source's static value. This is only used when the source() is StaticValue.
.. seealso:: setStaticValue()
:rtype: QVariant
%End
void setStaticValue( const QVariant &value );
%Docstring
Sets the source's static value. Calling this will also change the source() to StaticValue.
.. seealso:: staticValue()
%End
QString parameterName() const;
%Docstring
Returns the source's model parameter name. This is only used when the source() is ModelParameter.
.. seealso:: setParameterName()
:rtype: str
%End
void setParameterName( const QString &name );
%Docstring
Sets the source's model parameter ``name``. Calling this will also change the source() to ModelParameter.
.. seealso:: parameterName()
%End
QString outputChildId() const;
%Docstring
Returns the source's child algorithm ID from which the output value will be taken. This is only used when the source() is ChildOutput.
.. seealso:: setOutputChildId()
.. seealso:: outputName()
:rtype: str
%End
void setOutputChildId( const QString &id );
%Docstring
Sets the source's child algorithm ``id`` from which the output value will be taken. Calling this will also change the source() to ChildOutput.
.. seealso:: parameterName()
.. seealso:: setOutputName()
%End
QString outputName() const;
%Docstring
Returns the source's child algorithm output name from which the output value will be taken. This is only used when the source() is ChildOutput.
.. seealso:: setOutputName()
.. seealso:: outputChildId()
:rtype: str
%End
void setOutputName( const QString &name );
%Docstring
Sets the source's child algorithm output ``name`` from which the output value will be taken. Calling this will also change the source() to ChildOutput.
.. seealso:: outputName()
.. seealso:: setOutputChildId()
%End
QString expression() const;
%Docstring
Returns the source's expression. This is only used when the source() is Expression.
.. seealso:: setExpression()
:rtype: str
%End
void setExpression( const QString &expression );
%Docstring
Sets the source's expression. Calling this will also change the source() to Expression.
The expression is evaluated just before the child algorithm executes, and can use functions available
in its expression context to include results calculated from the child algorithms already
executed by the model.
.. seealso:: expression()
%End
QVariant toVariant() const;
%Docstring
Saves this source to a QVariant.
.. seealso:: loadVariant()
:rtype: QVariant
%End
bool loadVariant( const QVariantMap &map );
%Docstring
Loads this source from a QVariantMap.
.. seealso:: toVariant()
:rtype: bool
%End
QString asPythonCode() const;
%Docstring
Attempts to convert the source to executable Python code.
:rtype: str
%End
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/models/qgsprocessingmodelchildparametersource.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -0,0 +1,85 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/models/qgsprocessingmodelcomponent.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsProcessingModelComponent
{
%Docstring
Represents a component of a model algorithm.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingmodelcomponent.h"
%End
public:
QString description() const;
%Docstring
Returns the friendly description text for the component.
.. seealso:: setDescription()
:rtype: str
%End
void setDescription( const QString &description );
%Docstring
Sets the friendly ``description`` text for the component.
.. seealso:: description()
%End
QPointF position() const;
%Docstring
Returns the position of the model component within the graphical modeler.
.. seealso:: setPosition()
:rtype: QPointF
%End
void setPosition( const QPointF &position );
%Docstring
Sets the ``position`` of the model component within the graphical modeler.
.. seealso:: position()
%End
protected:
QgsProcessingModelComponent( const QString &description = QString() );
%Docstring
Only subclasses can be created
%End
QgsProcessingModelComponent( const QgsProcessingModelComponent &other );
%Docstring
Copies are protected to avoid slicing
%End
void saveCommonProperties( QVariantMap &map ) const;
%Docstring
Saves the component properties to a QVariantMap.
.. seealso:: restoreCommonProperties()
%End
void restoreCommonProperties( const QVariantMap &map );
%Docstring
Restores the component properties from a QVariantMap.
.. seealso:: saveCommonProperties()
%End
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/models/qgsprocessingmodelcomponent.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -0,0 +1,92 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/models/qgsprocessingmodeloutput.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsProcessingModelOutput : QgsProcessingModelComponent
{
%Docstring
Represents a final output created by the model.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingmodeloutput.h"
%End
public:
QgsProcessingModelOutput( const QString &name = QString(), const QString &description = QString() );
%Docstring
Constructor for QgsProcessingModelOutput with the specified ``name`` and ``description``.
%End
QString name() const;
%Docstring
Returns the model output name.
.. seealso:: setName()
:rtype: str
%End
void setName( const QString &name );
%Docstring
Sets the model output ``name``.
.. seealso:: name()
%End
QString childId() const;
%Docstring
Returns the child algorithm ID from which this output is generated.
.. seealso:: setChildId()
:rtype: str
%End
void setChildId( const QString &id );
%Docstring
Sets the child algorithm ``id`` from which this output is generated.
.. seealso:: childId()
%End
QString childOutputName() const;
%Docstring
Returns the child algorithm output name from which this output is generated.
.. seealso:: setOutputName()
:rtype: str
%End
void setChildOutputName( const QString &name );
%Docstring
Sets the child algorithm output ``name`` from which this output is generated.
.. seealso:: outputName()
%End
QVariant toVariant() const;
%Docstring
Saves this output to a QVariant.
.. seealso:: loadVariant()
:rtype: QVariant
%End
bool loadVariant( const QVariantMap &map );
%Docstring
Loads this output from a QVariantMap.
.. seealso:: toVariant()
:rtype: bool
%End
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/models/qgsprocessingmodeloutput.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -0,0 +1,70 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/models/qgsprocessingmodelparameter.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsProcessingModelParameter : QgsProcessingModelComponent
{
%Docstring
Represents an input parameter used by the model.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingmodelparameter.h"
%End
public:
QgsProcessingModelParameter( const QString &parameterName = QString() );
%Docstring
Constructor for QgsProcessingModelParameter. The parameter name should match one of the
parameters from the parent model.
%End
QString parameterName() const;
%Docstring
Returns the associated parameter name. The parameter name should match one of the
parameters from the parent model.
.. seealso:: parameterName()
:rtype: str
%End
void setParameterName( const QString &name );
%Docstring
Sets the associated parameter name. The parameter name should match one of the
parameters from the parent model.
.. seealso:: parameterName()
%End
QVariant toVariant() const;
%Docstring
Saves this parameter to a QVariant.
.. seealso:: loadVariant()
:rtype: QVariant
%End
bool loadVariant( const QVariantMap &map );
%Docstring
Loads this parameter from a QVariantMap.
.. seealso:: toVariant()
:rtype: bool
%End
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/models/qgsprocessingmodelparameter.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -0,0 +1,51 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessing.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsProcessing
{
%Docstring
Contains enumerations and other constants for use in processing algorithms
and parameters.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessing.h"
%End
public:
enum LayerType
{
TypeAny,
TypeVectorAny,
TypeVectorPoint,
TypeVectorLine,
TypeVectorPolygon,
TypeRaster,
TypeFile,
TypeTable,
};
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessing.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -514,7 +514,7 @@ class QgsProcessingAlgorithm
QgsProcessingFeatureSource *parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const /Factory/;
%Docstring
Evaluates the parameter with matching ``definition`` to a feature source.
Evaluates the parameter with matching ``name`` to a feature source.
Sources will either be taken from ``context``'s active project, or loaded from external
sources and stored temporarily in the ``context``.
@ -523,6 +523,22 @@ class QgsProcessingAlgorithm
:rtype: QgsProcessingFeatureSource
%End
QString parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name,
QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = 0 );
%Docstring
Evaluates the parameter with matching ``name`` to a source vector layer file path of compatible format.
If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the
``compatibleFormats`` argument, then the layer will first be exported to a compatible format
in a temporary location. The function will then return the path to that temporary file.
``compatibleFormats`` should consist entirely of lowercase file extensions, e.g. 'shp'.
The ``preferredFormat`` argument is used to specify to desired file extension to use when a temporary
layer export is required.
:rtype: str
%End
QgsMapLayer *parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a map layer.
@ -543,9 +559,9 @@ class QgsProcessingAlgorithm
:rtype: QgsRasterLayer
%End
QString parameterAsRasterOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
QString parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a raster output layer destination.
Evaluates the parameter with matching ``name`` to a output layer destination.
:rtype: str
%End

View File

@ -1,955 +0,0 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingmodelalgorithm.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsProcessingModelAlgorithm : QgsProcessingAlgorithm
{
%Docstring
Model based algorithm with processing.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingmodelalgorithm.h"
%End
public:
class ChildParameterSource
{
%Docstring
Source for the value of a parameter for a child algorithm within a model.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingmodelalgorithm.h"
%End
public:
enum Source
{
ModelParameter,
ChildOutput,
StaticValue,
Expression,
};
ChildParameterSource();
%Docstring
Constructor for ChildParameterSource. It is recommended that the static methods
fromStaticValue(), fromModelParameter(), fromChildOutput() and fromExpression() are used instead.
%End
bool operator==( const QgsProcessingModelAlgorithm::ChildParameterSource &other ) const;
bool operator!=( const QgsProcessingModelAlgorithm::ChildParameterSource &other ) const;
%Docstring
:rtype: bool
%End
static QgsProcessingModelAlgorithm::ChildParameterSource fromStaticValue( const QVariant &value );
%Docstring
Returns a new ChildParameterSource which takes its value from a static ``value``.
.. seealso:: fromModelParameter()
.. seealso:: fromChildOutput()
.. seealso:: fromExpression()
:rtype: QgsProcessingModelAlgorithm.ChildParameterSource
%End
static QgsProcessingModelAlgorithm::ChildParameterSource fromModelParameter( const QString &parameterName );
%Docstring
Returns a new ChildParameterSource which takes its value from a parent model parameter.
.. seealso:: fromStaticValue()
.. seealso:: fromChildOutput()
.. seealso:: fromExpression()
:rtype: QgsProcessingModelAlgorithm.ChildParameterSource
%End
static QgsProcessingModelAlgorithm::ChildParameterSource fromChildOutput( const QString &childId, const QString &outputName );
%Docstring
Returns a new ChildParameterSource which takes its value from an output generated by a child algorithm.
.. seealso:: fromStaticValue()
.. seealso:: fromModelParameter()
.. seealso:: fromExpression()
:rtype: QgsProcessingModelAlgorithm.ChildParameterSource
%End
static QgsProcessingModelAlgorithm::ChildParameterSource fromExpression( const QString &expression );
%Docstring
Returns a new ChildParameterSource which takes its value from an expression. The expression
is evaluated just before the child algorithm executes, and can use functions available
in its expression context to include results calculated from the child algorithms already
executed by the model.
.. seealso:: fromStaticValue()
.. seealso:: fromChildOutput()
.. seealso:: fromModelParameter()
:rtype: QgsProcessingModelAlgorithm.ChildParameterSource
%End
Source source() const;
%Docstring
Returns the parameter value's source.
:rtype: Source
%End
QVariant staticValue() const;
%Docstring
Returns the source's static value. This is only used when the source() is StaticValue.
.. seealso:: setStaticValue()
:rtype: QVariant
%End
void setStaticValue( const QVariant &value );
%Docstring
Sets the source's static value. Calling this will also change the source() to StaticValue.
.. seealso:: staticValue()
%End
QString parameterName() const;
%Docstring
Returns the source's model parameter name. This is only used when the source() is ModelParameter.
.. seealso:: setParameterName()
:rtype: str
%End
void setParameterName( const QString &name );
%Docstring
Sets the source's model parameter ``name``. Calling this will also change the source() to ModelParameter.
.. seealso:: parameterName()
%End
QString outputChildId() const;
%Docstring
Returns the source's child algorithm ID from which the output value will be taken. This is only used when the source() is ChildOutput.
.. seealso:: setOutputChildId()
.. seealso:: outputName()
:rtype: str
%End
void setOutputChildId( const QString &id );
%Docstring
Sets the source's child algorithm ``id`` from which the output value will be taken. Calling this will also change the source() to ChildOutput.
.. seealso:: parameterName()
.. seealso:: setOutputName()
%End
QString outputName() const;
%Docstring
Returns the source's child algorithm output name from which the output value will be taken. This is only used when the source() is ChildOutput.
.. seealso:: setOutputName()
.. seealso:: outputChildId()
:rtype: str
%End
void setOutputName( const QString &name );
%Docstring
Sets the source's child algorithm output ``name`` from which the output value will be taken. Calling this will also change the source() to ChildOutput.
.. seealso:: outputName()
.. seealso:: setOutputChildId()
%End
QString expression() const;
%Docstring
Returns the source's expression. This is only used when the source() is Expression.
.. seealso:: setExpression()
:rtype: str
%End
void setExpression( const QString &expression );
%Docstring
Sets the source's expression. Calling this will also change the source() to Expression.
The expression is evaluated just before the child algorithm executes, and can use functions available
in its expression context to include results calculated from the child algorithms already
executed by the model.
.. seealso:: expression()
%End
QVariant toVariant() const;
%Docstring
Saves this source to a QVariant.
.. seealso:: loadVariant()
:rtype: QVariant
%End
bool loadVariant( const QVariantMap &map );
%Docstring
Loads this source from a QVariantMap.
.. seealso:: toVariant()
:rtype: bool
%End
QString asPythonCode() const;
%Docstring
Attempts to convert the source to executable Python code.
:rtype: str
%End
};
class Component
{
%Docstring
Represents a component of a model algorithm.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingmodelalgorithm.h"
%End
public:
QString description() const;
%Docstring
Returns the friendly description text for the component.
.. seealso:: setDescription()
:rtype: str
%End
void setDescription( const QString &description );
%Docstring
Sets the friendly ``description`` text for the component.
.. seealso:: description()
%End
QPointF position() const;
%Docstring
Returns the position of the model component within the graphical modeler.
.. seealso:: setPosition()
:rtype: QPointF
%End
void setPosition( const QPointF &position );
%Docstring
Sets the ``position`` of the model component within the graphical modeler.
.. seealso:: position()
%End
protected:
Component( const QString &description = QString() );
%Docstring
Only subclasses can be created
%End
Component( const QgsProcessingModelAlgorithm::Component &other );
%Docstring
Copies are protected to avoid slicing
%End
void saveCommonProperties( QVariantMap &map ) const;
%Docstring
Saves the component properties to a QVariantMap.
.. seealso:: restoreCommonProperties()
%End
void restoreCommonProperties( const QVariantMap &map );
%Docstring
Restores the component properties from a QVariantMap.
.. seealso:: saveCommonProperties()
%End
};
class ModelParameter : QgsProcessingModelAlgorithm::Component
{
%Docstring
Represents an input parameter used by the model.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingmodelalgorithm.h"
%End
public:
ModelParameter( const QString &parameterName = QString() );
%Docstring
Constructor for ModelParameter. The parameter name should match one of the
parameters from the parent model.
%End
QString parameterName() const;
%Docstring
Returns the associated parameter name. The parameter name should match one of the
parameters from the parent model.
.. seealso:: parameterName()
:rtype: str
%End
void setParameterName( const QString &name );
%Docstring
Sets the associated parameter name. The parameter name should match one of the
parameters from the parent model.
.. seealso:: parameterName()
%End
QVariant toVariant() const;
%Docstring
Saves this parameter to a QVariant.
.. seealso:: loadVariant()
:rtype: QVariant
%End
bool loadVariant( const QVariantMap &map );
%Docstring
Loads this parameter from a QVariantMap.
.. seealso:: toVariant()
:rtype: bool
%End
};
class ModelOutput : QgsProcessingModelAlgorithm::Component
{
%Docstring
Represents a final output created by the model.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingmodelalgorithm.h"
%End
public:
ModelOutput( const QString &name = QString(), const QString &description = QString() );
%Docstring
Constructor for ModelOutput with the specified ``name`` and ``description``.
%End
QString name() const;
%Docstring
Returns the model output name.
.. seealso:: setName()
:rtype: str
%End
void setName( const QString &name );
%Docstring
Sets the model output ``name``.
.. seealso:: name()
%End
QString childId() const;
%Docstring
Returns the child algorithm ID from which this output is generated.
.. seealso:: setChildId()
:rtype: str
%End
void setChildId( const QString &id );
%Docstring
Sets the child algorithm ``id`` from which this output is generated.
.. seealso:: childId()
%End
QString childOutputName() const;
%Docstring
Returns the child algorithm output name from which this output is generated.
.. seealso:: setOutputName()
:rtype: str
%End
void setChildOutputName( const QString &name );
%Docstring
Sets the child algorithm output ``name`` from which this output is generated.
.. seealso:: outputName()
%End
QVariant toVariant() const;
%Docstring
Saves this output to a QVariant.
.. seealso:: loadVariant()
:rtype: QVariant
%End
bool loadVariant( const QVariantMap &map );
%Docstring
Loads this output from a QVariantMap.
.. seealso:: toVariant()
:rtype: bool
%End
};
class ChildAlgorithm : QgsProcessingModelAlgorithm::Component
{
%Docstring
Child algorithm representing a single component of a QgsProcessingModelAlgorithm.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingmodelalgorithm.h"
%End
public:
ChildAlgorithm( const QString &algorithmId = QString() );
%Docstring
Constructor for ChildAlgorithm. The ``algorithmId`` parameter
should be set to a QgsProcessingAlgorithm algorithm ID.
%End
QString childId() const;
%Docstring
Returns the child algorithm's unique ID string, used the identify
this child algorithm within its parent model.
.. seealso:: setChildId()
.. seealso:: generateChildId()
:rtype: str
%End
void setChildId( const QString &id );
%Docstring
Sets the child algorithm's unique ``id`` string, used the identify
this child algorithm within its parent model.
.. seealso:: childId()
.. seealso:: generateChildId()
%End
void generateChildId( const QgsProcessingModelAlgorithm &model );
%Docstring
Automatically generates a unique childId() for the algorithm,
avoiding child IDs which are already present in ``model``.
.. seealso:: childId()
.. seealso:: setChildId()
%End
QString algorithmId() const;
%Docstring
Returns the underlying child algorithm's ID.
.. seealso:: algorithm()
.. seealso:: setAlgorithmId()
:rtype: str
%End
void setAlgorithmId( const QString &algorithmId );
%Docstring
Sets the underlying child algorithm's ID. This
should be set to an existing QgsProcessingAlgorithm algorithm ID.
.. seealso:: algorithm()
.. seealso:: algorithmId()
%End
const QgsProcessingAlgorithm *algorithm() const;
%Docstring
Returns the underlying child algorithm, or a None
if a matching algorithm is not available.
.. seealso:: algorithmId()
:rtype: QgsProcessingAlgorithm
%End
QMap< QString, QList< QgsProcessingModelAlgorithm::ChildParameterSource > > parameterSources() const;
%Docstring
Returns a map of parameter sources. The keys are the child algorithm
parameter names, the values are the sources for that parameter.
.. seealso:: setParameterSources()
.. seealso:: addParameterSources()
:rtype: QMap< str, QList< QgsProcessingModelAlgorithm.ChildParameterSource > >
%End
void setParameterSources( const QMap< QString, QList< QgsProcessingModelAlgorithm::ChildParameterSource > > &sources );
%Docstring
Sets the map of parameter ``sources``. The keys are the child algorithm
parameter names, the values are the sources for that parameter.
.. seealso:: parameterSources()
.. seealso:: addParameterSources()
%End
void addParameterSources( const QString &name, const QList< QgsProcessingModelAlgorithm::ChildParameterSource > &source );
%Docstring
Adds a parameter source. The ``name`` argument should match
one of the child algorithm's parameter names, and the ``sources``
argument is used to set the sources for that parameter.
Any existing parameter sources with matching name will be replaced.
.. seealso:: parameterSources()
.. seealso:: setParameterSources()
%End
bool isActive() const;
%Docstring
Returns true if the child algorithm is active.
.. seealso:: setActive()
:rtype: bool
%End
void setActive( bool active );
%Docstring
Sets whether the child algorithm is active.
.. seealso:: isActive()
%End
QStringList dependencies() const;
%Docstring
Returns the list of child algorithms from the parent model on which this
algorithm is dependent. The returned list contains the id() of the
dependent algorithms.
.. seealso:: setDependencies()
:rtype: list of str
%End
void setDependencies( const QStringList &dependencies );
%Docstring
Sets the list of child algorithms from the parent model on which this
algorithm is dependent. The list should contain the id() of the
dependent algorithms.
.. seealso:: dependencies()
%End
bool parametersCollapsed() const;
%Docstring
Returns true if the list of parameters for this algorithm should be collapsed
in the graphical modeller.
.. seealso:: setParametersCollapsed()
.. seealso:: outputsCollapsed()
:rtype: bool
%End
void setParametersCollapsed( bool collapsed );
%Docstring
Sets whether the list of parameters for this algorithm should be collapsed
in the graphical modeller.
.. seealso:: parametersCollapsed()
.. seealso:: setOutputsCollapsed()
%End
bool outputsCollapsed() const;
%Docstring
Returns true if the list of outputs for this algorithm should be collapsed
in the graphical modeller.
.. seealso:: setParametersCollapsed()
.. seealso:: parametersCollapsed()
:rtype: bool
%End
void setOutputsCollapsed( bool collapsed );
%Docstring
Sets whether the list of outputs for this algorithm should be collapsed
in the graphical modeller.
.. seealso:: outputsCollapsed()
.. seealso:: setParametersCollapsed()
%End
QMap<QString, QgsProcessingModelAlgorithm::ModelOutput> modelOutputs() const;
%Docstring
Returns the map of final model outputs which are generated by this child algorithm.
The keys are the output names from this child algorithm. Only outputs which are
part of the final outputs from the model are included in this map.
.. seealso:: setModelOutputs()
.. seealso:: modelOutput()
:rtype: QMap<str, QgsProcessingModelAlgorithm.ModelOutput>
%End
QgsProcessingModelAlgorithm::ModelOutput &modelOutput( const QString &name );
%Docstring
Returns the final model output with matching ``name``. If no output
exists with the name, a new one will be created and returned.
If child model outputs are altered by this method, QgsProcessingModelAlgorithm.updateDestinationParameters()
must be called on the parent model.
.. seealso:: modelOutputs()
.. seealso:: setModelOutputs()
:rtype: QgsProcessingModelAlgorithm.ModelOutput
%End
void setModelOutputs( const QMap<QString, QgsProcessingModelAlgorithm::ModelOutput> &outputs );
%Docstring
Sets the map of final model ``outputs`` which are generated by this child algorithm.
Only outputs which are part of the final outputs from the model should be included in this map.
If child model outputs are altered by this method, QgsProcessingModelAlgorithm.updateDestinationParameters()
must be called on the parent model.
.. seealso:: modelOutputs()
%End
QVariant toVariant() const;
%Docstring
Saves this child to a QVariant.
.. seealso:: loadVariant()
:rtype: QVariant
%End
bool loadVariant( const QVariant &child );
%Docstring
Loads this child from a QVariant.
.. seealso:: toVariant()
:rtype: bool
%End
QString asPythonCode() const;
%Docstring
Attempts to convert the child to executable Python code.
:rtype: str
%End
};
QgsProcessingModelAlgorithm( const QString &name = QString(), const QString &group = QString() );
%Docstring
Constructor for QgsProcessingModelAlgorithm.
%End
virtual QString name() const;
virtual QString displayName() const;
virtual QString group() const;
virtual QIcon icon() const;
virtual QString svgIconPath() const;
virtual QString shortHelpString() const;
virtual QString helpUrl() const;
virtual bool canExecute( QString *errorMessage /Out/ = 0 ) const;
virtual QString asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const;
virtual QgsProcessingModelAlgorithm *create() const /Factory/;
void setName( const QString &name );
%Docstring
Sets the model ``name``.
.. seealso:: name()
%End
void setGroup( const QString &group );
%Docstring
Sets the model ``group``.
.. seealso:: group()
%End
QMap<QString, QgsProcessingModelAlgorithm::ChildAlgorithm> childAlgorithms() const;
%Docstring
Returns the map of child algorithms contained in the model. The keys
are the child algorithm ids (see QgsProcessingModelAlgorithm.ChildAlgorithm.childId()).
.. seealso:: childAlgorithm()
.. seealso:: setChildAlgorithms()
.. seealso:: addChildAlgorithm()
:rtype: QMap<str, QgsProcessingModelAlgorithm.ChildAlgorithm>
%End
void setChildAlgorithms( const QMap<QString, QgsProcessingModelAlgorithm::ChildAlgorithm> &childAlgorithms );
%Docstring
Sets the map of child algorithms contained in the model. The keys
are the child algorithm ids (see QgsProcessingModelAlgorithm.ChildAlgorithm.childId()).
All existing child algorithms will be replaced.
.. seealso:: childAlgorithms()
.. seealso:: childAlgorithm()
.. seealso:: setChildAlgorithm()
.. seealso:: addChildAlgorithm()
%End
void setChildAlgorithm( const QgsProcessingModelAlgorithm::ChildAlgorithm &algorithm );
%Docstring
Sets the child ``algorithm`` within the model. If a child algorithm already
exists in the model with the same child ID then that algorithm will be replaced.
.. seealso:: addChildAlgorithm()
.. seealso:: setChildAlgorithms()
%End
QString addChildAlgorithm( QgsProcessingModelAlgorithm::ChildAlgorithm &algorithm );
%Docstring
Adds a new child ``algorithm`` to the model. If a child algorithm already exists
in the model with the same child ID then ``algorithm`` will be assigned a new
autogenerated unique ID.
The assigned child ID will be returned.
.. seealso:: childAlgorithms()
.. seealso:: childAlgorithm()
.. seealso:: setChildAlgorithm()
.. seealso:: setChildAlgorithms()
:rtype: str
%End
QgsProcessingModelAlgorithm::ChildAlgorithm &childAlgorithm( const QString &id );
%Docstring
Returns the child algorithm with matching ``id``. If no child algorithm exists with
this ID a new algorithm will be added to the model and returned.
.. seealso:: addChildAlgorithm()
.. seealso:: childAlgorithms()
:rtype: QgsProcessingModelAlgorithm.ChildAlgorithm
%End
bool removeChildAlgorithm( const QString &id );
%Docstring
Attempts to remove the child algorithm with matching ``id``.
Returns true if the algorithm could be removed, or false
if the algorithm could not be removed (e.g. due to other
child algorithms depending on it).
.. seealso:: deactivateChildAlgorithm()
:rtype: bool
%End
void deactivateChildAlgorithm( const QString &id );
%Docstring
Deactivates the child algorithm with matching ``id``.
All other child algorithms which depend on the child
algorithm will also be deactivated.
.. seealso:: removeChildAlgorithm()
.. seealso:: activateChildAlgorithm()
%End
bool activateChildAlgorithm( const QString &id );
%Docstring
Attempts to activate the child algorithm with matching ``id``.
If any child algorithms on which the child depends are not active,
then the child will not be activated and false will be returned.
.. seealso:: deactivateChildAlgorithm()
:rtype: bool
%End
QSet< QString > dependentChildAlgorithms( const QString &childId ) const;
%Docstring
Returns a list of the child algorithm IDs depending on the child
algorithm with the specified ``childId``.
.. seealso:: dependsOnChildAlgorithms()
:rtype: set of str
%End
QSet< QString > dependsOnChildAlgorithms( const QString &childId ) const;
%Docstring
Returns a list of the child algorithm IDs on which the child
algorithm with the specified ``childId`` depends upon.
.. seealso:: dependentChildAlgorithms()
:rtype: set of str
%End
void addModelParameter( QgsProcessingParameterDefinition *definition /Transfer/, const QgsProcessingModelAlgorithm::ModelParameter &component );
%Docstring
Adds a new parameter to the model, with the specified ``definition`` and graphical ``component``.
Ownership of ``definition`` is transferred to the model.
.. seealso:: updateModelParameter()
.. seealso:: removeModelParameter()
%End
void updateModelParameter( QgsProcessingParameterDefinition *definition /Transfer/ );
%Docstring
Replaces the definition of an existing parameter (by parameter name) with a new ``definition``. Ownership of
``definition`` is transferred to the model, and any existing parameter is deleted.
.. seealso:: addModelParameter()
.. seealso:: removeModelParameter()
%End
void removeModelParameter( const QString &name );
%Docstring
Removes an existing model parameter by ``name``. The definition of the matching parameter
is deleted.
.. seealso:: addModelParameter()
.. seealso:: updateModelParameter()
%End
bool childAlgorithmsDependOnParameter( const QString &name ) const;
%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
QMap<QString, QgsProcessingModelAlgorithm::ModelParameter> parameterComponents() const;
%Docstring
Returns the map of parameter components used by the model. The keys
should match the algorithm's parameter names (see parameterDefinitions() ).
.. seealso:: setParameterComponent()
.. seealso:: parameterComponent()
:rtype: QMap<str, QgsProcessingModelAlgorithm.ModelParameter>
%End
void setParameterComponents( const QMap<QString, QgsProcessingModelAlgorithm::ModelParameter> &parameterComponents );
%Docstring
Sets the map of parameter components used by the model. The keys
should match the algorithm's parameter names (see parameterDefinitions() ).
All existing parameter components will be replaced.
.. seealso:: parameterComponents()
.. seealso:: setParameterComponent()
.. seealso:: parameterComponent()
%End
void setParameterComponent( const QgsProcessingModelAlgorithm::ModelParameter &component );
%Docstring
Sets a parameter ``component`` for the model. If a parameter component already
exists in the model with the same parameter name then that component will be replaced.
.. seealso:: parameterComponents()
.. seealso:: setParameterComponents()
.. seealso:: parameterComponent()
%End
QgsProcessingModelAlgorithm::ModelParameter &parameterComponent( const QString &name );
%Docstring
Returns the parameter component with matching ``name``. If no parameter component exists with
this name a new component will be added to the model and returned.
.. seealso:: parameterComponents()
.. seealso:: setParameterComponents()
.. seealso:: setParameterComponent()
:rtype: QgsProcessingModelAlgorithm.ModelParameter
%End
void updateDestinationParameters();
%Docstring
Updates the model's parameter definitions to include all relevant destination
parameters as required by child algorithm ModelOutputs.
Must be called whenever child algorithm ModelOutputs are altered.
%End
bool toFile( const QString &path ) const;
%Docstring
Writes the model to a file, at the specified ``path``.
.. seealso:: fromFile()
:rtype: bool
%End
bool fromFile( const QString &path );
%Docstring
Reads the model from a file, at the specified ``path``.
.. seealso:: toFile()
:rtype: bool
%End
QVariantMap &helpContent();
%Docstring
Returns the model's help contents (a free-form map of values describing the algorithm's
use and metadata).
.. seealso:: setHelpContent()
:rtype: QVariantMap
%End
void setHelpContent( const QVariantMap &contents );
%Docstring
Sets the model's help ``contents`` (a free-form map of values describing the algorithm's
use and metadata).
.. seealso:: helpContent()
%End
QString sourceFilePath() const;
%Docstring
Returns the source file path for the model, if available.
.. seealso:: setSourceFilePath()
:rtype: str
%End
void setSourceFilePath( const QString &path );
%Docstring
Sets the source file ``path`` for the model, if available.
.. seealso:: sourceFilePath()
%End
QString asPythonCode() const;
%Docstring
Attempts to convert the model to executable Python code.
:rtype: str
%End
QList< QgsProcessingModelAlgorithm::ChildParameterSource > availableSourcesForChild( const QString &childId, const QStringList &parameterTypes = QStringList(),
const QStringList &outputTypes = QStringList(), const QList< int > dataTypes = QList< int >() ) const;
%Docstring
Returns a list of possible sources which can be used for the parameters for a child
algorithm in the model. Returned sources are those which match either one of the
specified ``parameterTypes`` (see QgsProcessingParameterDefinition.type() ) or
on of the specified ``outputTypes`` (see QgsProcessingOutputDefinition.type() ).
If specified, an optional list of ``dataTypes`` can be used to filter the returned
sources to those with compatible data types for the parameter/outputs.
:rtype: list of QgsProcessingModelAlgorithm.ChildParameterSource
%End
class VariableDefinition
{
%Docstring
Definition of a expression context variable available during model execution.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingmodelalgorithm.h"
%End
public:
VariableDefinition( const QVariant &value = QVariant(), const QgsProcessingModelAlgorithm::ChildParameterSource &source = QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( QVariant() ), const QString &description = QString() );
%Docstring
Constructor for a new VariableDefinition with the specified ``value`` and original
parameter ``source``, and ``description``.
%End
QVariant value;
%Docstring
Value of variable
%End
QgsProcessingModelAlgorithm::ChildParameterSource source;
%Docstring
Original source of variable's value
%End
QString description;
%Docstring
Translated description of variable
%End
};
QMap< QString, QgsProcessingModelAlgorithm::VariableDefinition > variablesForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(),
const QVariantMap &results = QVariantMap() ) const;
%Docstring
Returns a map of variable name to variable definition for expression context variables which are available
for use by child algorithm during model execution.
The child algorithm ``childId`` and processing ``context``
are manadatory. If ``modelParameters`` and ``results`` are not specified, then only the variable names and sources
will be returned, but all variable values will be null. This can be used to determine in advance which variables
will be available for a specific child algorithm, e.g. for use in expression builder widgets.
In order to calculate the actual variable value, the input model ``modelParameters`` and already executed child
algorithm ``results`` must be passed.
.. seealso:: createExpressionContextScopeForChildAlgorithm()
:rtype: QMap< str, QgsProcessingModelAlgorithm.VariableDefinition >
%End
QgsExpressionContextScope *createExpressionContextScopeForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(),
const QVariantMap &results = QVariantMap() ) const /Factory/;
%Docstring
Creates a new expression context scope for a child algorithm within the model.
.. seealso:: variablesForChildAlgorithm()
:rtype: QgsExpressionContextScope
%End
protected:
virtual QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingmodelalgorithm.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -106,7 +106,7 @@ class QgsProcessingOutputVectorLayer : QgsProcessingOutputDefinition
%End
public:
QgsProcessingOutputVectorLayer( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny );
QgsProcessingOutputVectorLayer( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny );
%Docstring
Constructor for QgsProcessingOutputVectorLayer.
%End
@ -118,14 +118,14 @@ class QgsProcessingOutputVectorLayer : QgsProcessingOutputDefinition
%End
virtual QString type() const;
QgsProcessingParameterDefinition::LayerType dataType() const;
QgsProcessing::LayerType dataType() const;
%Docstring
Returns the layer type for the output layer.
.. seealso:: setDataType()
:rtype: QgsProcessingParameterDefinition.LayerType
:rtype: QgsProcessing.LayerType
%End
void setDataType( QgsProcessingParameterDefinition::LayerType type );
void setDataType( QgsProcessing::LayerType type );
%Docstring
Sets the layer ``type`` for the output layer.
.. seealso:: dataType()

View File

@ -181,14 +181,14 @@ class QgsProcessingParameterDefinition
sipType = sipType_QgsProcessingParameterFeatureSource;
else if ( sipCpp->type() == QgsProcessingParameterFeatureSink::typeName() )
sipType = sipType_QgsProcessingParameterFeatureSink;
else if ( sipCpp->type() == QgsProcessingParameterVectorOutput::typeName() )
sipType = sipType_QgsProcessingParameterVectorOutput;
else if ( sipCpp->type() == QgsProcessingParameterRasterOutput::typeName() )
sipType = sipType_QgsProcessingParameterRasterOutput;
else if ( sipCpp->type() == QgsProcessingParameterFileOutput::typeName() )
sipType = sipType_QgsProcessingParameterFileOutput;
else if ( sipCpp->type() == QgsProcessingParameterFolderOutput::typeName() )
sipType = sipType_QgsProcessingParameterFolderOutput;
else if ( sipCpp->type() == QgsProcessingParameterVectorDestination::typeName() )
sipType = sipType_QgsProcessingParameterVectorDestination;
else if ( sipCpp->type() == QgsProcessingParameterRasterDestination::typeName() )
sipType = sipType_QgsProcessingParameterRasterDestination;
else if ( sipCpp->type() == QgsProcessingParameterFileDestination::typeName() )
sipType = sipType_QgsProcessingParameterFileDestination;
else if ( sipCpp->type() == QgsProcessingParameterFolderDestination::typeName() )
sipType = sipType_QgsProcessingParameterFolderDestination;
%End
public:
@ -201,18 +201,6 @@ class QgsProcessingParameterDefinition
typedef QFlags<QgsProcessingParameterDefinition::Flag> Flags;
enum LayerType
{
TypeAny,
TypeVectorAny,
TypeVectorPoint,
TypeVectorLine,
TypeVectorPolygon,
TypeRaster,
TypeFile,
TypeTable,
};
QgsProcessingParameterDefinition( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
bool optional = false );
%Docstring
@ -472,6 +460,22 @@ class QgsProcessingParameters
:rtype: QgsProcessingFeatureSource
%End
static QString parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters,
QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = 0 );
%Docstring
Evaluates the parameter with matching ``definition`` to a source vector layer file path of compatible format.
If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the
``compatibleFormats`` argument, then the layer will first be exported to a compatible format
in a temporary location. The function will then return the path to that temporary file.
``compatibleFormats`` should consist entirely of lowercase file extensions, e.g. 'shp'.
The ``preferredFormat`` argument is used to specify to desired file extension to use when a temporary
layer export is required. This defaults to shapefiles, because shapefiles are the future (don't believe the geopackage hype!).
:rtype: str
%End
static QgsMapLayer *parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` to a map layer.
@ -492,9 +496,9 @@ class QgsProcessingParameters
:rtype: QgsRasterLayer
%End
static QString parameterAsRasterOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
static QString parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` to a raster output layer destination.
Evaluates the parameter with matching ``definition`` to a output layer destination.
:rtype: str
%End
@ -947,7 +951,7 @@ class QgsProcessingParameterMultipleLayers : QgsProcessingParameterDefinition
%End
public:
QgsProcessingParameterMultipleLayers( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType layerType = QgsProcessingParameterDefinition::TypeVectorAny,
QgsProcessingParameterMultipleLayers( const QString &name, const QString &description = QString(), QgsProcessing::LayerType layerType = QgsProcessing::TypeVectorAny,
const QVariant &defaultValue = QVariant(),
bool optional = false );
%Docstring
@ -967,14 +971,14 @@ class QgsProcessingParameterMultipleLayers : QgsProcessingParameterDefinition
virtual QString asScriptCode() const;
QgsProcessingParameterDefinition::LayerType layerType() const;
QgsProcessing::LayerType layerType() const;
%Docstring
Returns the layer type for layers acceptable by the parameter.
.. seealso:: setLayerType()
:rtype: QgsProcessingParameterDefinition.LayerType
:rtype: QgsProcessing.LayerType
%End
void setLayerType( QgsProcessingParameterDefinition::LayerType type );
void setLayerType( QgsProcessing::LayerType type );
%Docstring
Sets the layer ``type`` for layers acceptable by the parameter.
.. seealso:: layerType()
@ -1649,7 +1653,7 @@ class QgsProcessingParameterFeatureSink : QgsProcessingDestinationParameter
%End
public:
QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny, const QVariant &defaultValue = QVariant(),
QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(),
bool optional = false );
%Docstring
Constructor for QgsProcessingParameterFeatureSink.
@ -1672,11 +1676,11 @@ class QgsProcessingParameterFeatureSink : QgsProcessingDestinationParameter
virtual QString defaultFileExtension() const;
QgsProcessingParameterDefinition::LayerType dataType() const;
QgsProcessing::LayerType dataType() const;
%Docstring
Returns the layer type for sinks associated with the parameter.
.. seealso:: setDataType()
:rtype: QgsProcessingParameterDefinition.LayerType
:rtype: QgsProcessing.LayerType
%End
bool hasGeometry() const;
@ -1686,7 +1690,7 @@ class QgsProcessingParameterFeatureSink : QgsProcessingDestinationParameter
:rtype: bool
%End
void setDataType( QgsProcessingParameterDefinition::LayerType type );
void setDataType( QgsProcessing::LayerType type );
%Docstring
Sets the layer ``type`` for the sinks associated with the parameter.
.. seealso:: dataType()
@ -1708,10 +1712,15 @@ class QgsProcessingParameterFeatureSink : QgsProcessingDestinationParameter
};
class QgsProcessingParameterVectorOutput : QgsProcessingDestinationParameter
class QgsProcessingParameterVectorDestination : QgsProcessingDestinationParameter
{
%Docstring
A vector layer output parameter. Consider using the more flexible QgsProcessingParameterFeatureSink wherever
A vector layer destination parameter, for specifying the destination path for a vector layer
created by the algorithm.
.. note::
Consider using the more flexible QgsProcessingParameterFeatureSink wherever
possible.
.. versionadded:: 3.0
%End
@ -1721,10 +1730,10 @@ class QgsProcessingParameterVectorOutput : QgsProcessingDestinationParameter
%End
public:
QgsProcessingParameterVectorOutput( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny, const QVariant &defaultValue = QVariant(),
bool optional = false );
QgsProcessingParameterVectorDestination( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(),
bool optional = false );
%Docstring
Constructor for QgsProcessingParameterVectorOutput.
Constructor for QgsProcessingParameterVectorDestination.
%End
static QString typeName();
@ -1744,23 +1753,23 @@ class QgsProcessingParameterVectorOutput : QgsProcessingDestinationParameter
virtual QString defaultFileExtension() const;
QgsProcessingParameterDefinition::LayerType dataType() const;
QgsProcessing::LayerType dataType() const;
%Docstring
Returns the layer type for layers associated with the parameter.
Returns the layer type for this created vector layer.
.. seealso:: setDataType()
:rtype: QgsProcessingParameterDefinition.LayerType
:rtype: QgsProcessing.LayerType
%End
bool hasGeometry() const;
%Docstring
Returns true if the layer is likely to include geometries. In cases were presence of geometry
Returns true if the created layer is likely to include geometries. In cases were presence of geometry
cannot be reliably determined in advance, this method will default to returning true.
:rtype: bool
%End
void setDataType( QgsProcessingParameterDefinition::LayerType type );
void setDataType( QgsProcessing::LayerType type );
%Docstring
Sets the layer ``type`` for the layers associated with the parameter.
Sets the layer ``type`` for the created vector layer.
.. seealso:: dataType()
%End
@ -1769,19 +1778,20 @@ class QgsProcessingParameterVectorOutput : QgsProcessingDestinationParameter
virtual bool fromVariantMap( const QVariantMap &map );
static QgsProcessingParameterVectorOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
static QgsProcessingParameterVectorDestination *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.
:rtype: QgsProcessingParameterVectorOutput
:rtype: QgsProcessingParameterVectorDestination
%End
};
class QgsProcessingParameterRasterOutput : QgsProcessingDestinationParameter
class QgsProcessingParameterRasterDestination : QgsProcessingDestinationParameter
{
%Docstring
A raster layer output parameter.
A raster layer destination parameter, for specifying the destination path for a raster layer
created by the algorithm.
.. versionadded:: 3.0
%End
@ -1790,11 +1800,11 @@ class QgsProcessingParameterRasterOutput : QgsProcessingDestinationParameter
%End
public:
QgsProcessingParameterRasterOutput( const QString &name, const QString &description = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
QgsProcessingParameterRasterDestination( const QString &name, const QString &description = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
%Docstring
Constructor for QgsProcessingParameterRasterOutput.
Constructor for QgsProcessingParameterRasterDestination.
%End
static QString typeName();
@ -1812,17 +1822,18 @@ class QgsProcessingParameterRasterOutput : QgsProcessingDestinationParameter
virtual QString defaultFileExtension() const;
static QgsProcessingParameterRasterOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
static QgsProcessingParameterRasterDestination *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.
:rtype: QgsProcessingParameterRasterOutput
:rtype: QgsProcessingParameterRasterDestination
%End
};
class QgsProcessingParameterFileOutput : QgsProcessingDestinationParameter
class QgsProcessingParameterFileDestination : QgsProcessingDestinationParameter
{
%Docstring
A generic file based output parameter.
A generic file based destination parameter, for specifying the destination path for a file (non-map layer)
created by the algorithm.
.. versionadded:: 3.0
%End
@ -1831,12 +1842,12 @@ class QgsProcessingParameterFileOutput : QgsProcessingDestinationParameter
%End
public:
QgsProcessingParameterFileOutput( const QString &name, const QString &description = QString(),
const QString &fileFilter = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
QgsProcessingParameterFileDestination( const QString &name, const QString &description = QString(),
const QString &fileFilter = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
%Docstring
Constructor for QgsProcessingParameterFileOutput.
Constructor for QgsProcessingParameterFileDestination.
%End
static QString typeName();
@ -1856,14 +1867,14 @@ class QgsProcessingParameterFileOutput : QgsProcessingDestinationParameter
QString fileFilter() const;
%Docstring
Returns the file filter string for files compatible with this output.
Returns the file filter string for file destinations compatible with this parameter.
.. seealso:: setFileFilter()
:rtype: str
%End
void setFileFilter( const QString &filter );
%Docstring
Sets the file ``filter`` string for files compatible with this output.
Sets the file ``filter`` string for file destinations compatible with this parameter.
.. seealso:: fileFilter()
%End
@ -1872,18 +1883,20 @@ class QgsProcessingParameterFileOutput : QgsProcessingDestinationParameter
virtual bool fromVariantMap( const QVariantMap &map );
static QgsProcessingParameterFileOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
static QgsProcessingParameterFileDestination *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.
:rtype: QgsProcessingParameterFileOutput
:rtype: QgsProcessingParameterFileDestination
%End
};
class QgsProcessingParameterFolderOutput : QgsProcessingDestinationParameter
class QgsProcessingParameterFolderDestination : QgsProcessingDestinationParameter
{
%Docstring
A folder destination parameter, for specifying the destination path for a folder created
by the algorithm or used for creating new files within the algorithm.
A folder output parameter.
.. versionadded:: 3.0
%End
@ -1893,11 +1906,11 @@ class QgsProcessingParameterFolderOutput : QgsProcessingDestinationParameter
%End
public:
QgsProcessingParameterFolderOutput( const QString &name, const QString &description = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
QgsProcessingParameterFolderDestination( const QString &name, const QString &description = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
%Docstring
Constructor for QgsProcessingParameterFolderOutput.
Constructor for QgsProcessingParameterFolderDestination.
%End
static QString typeName();
@ -1913,10 +1926,10 @@ class QgsProcessingParameterFolderOutput : QgsProcessingDestinationParameter
virtual QString defaultFileExtension() const;
static QgsProcessingParameterFolderOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
static QgsProcessingParameterFolderDestination *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.
:rtype: QgsProcessingParameterFolderOutput
:rtype: QgsProcessingParameterFolderDestination
%End
};

View File

@ -158,6 +158,27 @@ class QgsProcessingUtils
:rtype: str
%End
static QString convertToCompatibleFormat( const QgsVectorLayer *layer,
bool selectedFeaturesOnly,
const QString &baseName,
const QStringList &compatibleFormats,
const QString &preferredFormat,
QgsProcessingContext &context,
QgsProcessingFeedback *feedback );
%Docstring
Converts a source vector ``layer`` to a file path to a vector layer of compatible format.
If the specified ``layer`` is not of the format listed in the
``compatibleFormats`` argument, then the layer will first be exported to a compatible format
in a temporary location using ``baseName``. The function will then return the path to that temporary file.
``compatibleFormats`` should consist entirely of lowercase file extensions, e.g. 'shp'.
The ``preferredFormat`` argument is used to specify to desired file extension to use when a temporary
layer export is required. This defaults to shapefiles.
:rtype: str
%End
};
class QgsProcessingFeatureSource : QgsFeatureSource

View File

@ -32,7 +32,7 @@ from qgis.PyQt.QtGui import QIcon
from qgis.analysis import QgsAspectFilter
from qgis.core import (QgsProcessingParameterRasterLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterOutput,
QgsProcessingParameterRasterDestination,
QgsProcessingOutputRasterLayer,
QgsFeatureSink)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
@ -65,7 +65,7 @@ class Aspect(QgisAlgorithm):
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
self.tr('Z factor'), QgsProcessingParameterNumber.Double,
1, False, 1, 999999.99))
self.addParameter(QgsProcessingParameterRasterOutput(self.OUTPUT, self.tr('Aspect')))
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Aspect')))
self.addOutput(QgsProcessingOutputRasterLayer(self.OUTPUT, self.tr('Aspect')))
def name(self):
@ -78,7 +78,7 @@ class Aspect(QgisAlgorithm):
inputFile = exportRasterLayer(self.parameterAsRasterLayer(parameters, self.INPUT, context))
zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)
outputFile = self.parameterAsRasterOutputLayer(parameters, self.OUTPUT, context)
outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
outputFormat = raster.formatShortNameFromFileName(outputFile)

View File

@ -34,7 +34,7 @@ from qgis.core import (QgsApplication,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterField,
QgsProcessingParameterFileOutput,
QgsProcessingParameterFileDestination,
QgsProcessingOutputHtml)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.tools import vector
@ -62,7 +62,7 @@ class BarPlot(QgisAlgorithm):
self.tr('Value field'),
None, self.INPUT, QgsProcessingParameterField.Numeric))
self.addParameter(QgsProcessingParameterFileOutput(self.OUTPUT, self.tr('Added'), self.tr('HTML files (*.html)')))
self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT, self.tr('Added'), self.tr('HTML files (*.html)')))
self.addOutput(QgsProcessingOutputHtml(self.OUTPUT, self.tr('Bar plot')))

View File

@ -39,7 +39,7 @@ from qgis.core import (QgsStatisticalSummary,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterField,
QgsProcessingParameterFileOutput,
QgsProcessingParameterFileDestination,
QgsProcessingOutputHtml,
QgsProcessingOutputNumber)
@ -95,7 +95,7 @@ class BasicStatisticsForField(QgisAlgorithm):
self.tr('Field to calculate statistics on'),
None, self.INPUT_LAYER, QgsProcessingParameterField.Any))
self.addParameter(QgsProcessingParameterFileOutput(self.OUTPUT_HTML_FILE, self.tr('Statistics'), self.tr('HTML files (*.html)'), None, True))
self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT_HTML_FILE, self.tr('Statistics'), self.tr('HTML files (*.html)'), None, True))
self.addOutput(QgsProcessingOutputHtml(self.OUTPUT_HTML_FILE, self.tr('Statistics')))
self.addOutput(QgsProcessingOutputNumber(self.COUNT, self.tr('Count')))

View File

@ -30,6 +30,7 @@ import os
from qgis.core import (QgsGeometry,
QgsWkbTypes,
QgsFeatureSink,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
@ -54,7 +55,7 @@ class Boundary(QgisAlgorithm):
def __init__(self):
super().__init__()
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorLine, QgsProcessingParameterDefinition.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER, self.tr('Input layer'), [QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_LAYER, self.tr('Boundary')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT_LAYER, self.tr("Boundaries")))

View File

@ -30,6 +30,7 @@ import os
from qgis.core import (QgsGeometry,
QgsWkbTypes,
QgsFeatureSink,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink,
@ -63,7 +64,7 @@ class BoundingBox(QgisAlgorithm):
super().__init__()
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER, self.tr('Input layer')))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_LAYER, self.tr('Bounds'), QgsProcessingParameterDefinition.TypeVectorPolygon))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_LAYER, self.tr('Bounds'), QgsProcessing.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT_LAYER, self.tr("Bounds")))
def name(self):

View File

@ -39,6 +39,7 @@ from qgis.core import (QgsSettings,
QgsWkbTypes,
QgsProcessingUtils,
QgsFields,
QgsProcessing,
QgsProcessingFeatureSource,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterEnum,
@ -81,15 +82,15 @@ class CheckValidity(QgisAlgorithm):
self.addParameter(QgsProcessingParameterEnum(self.METHOD,
self.tr('Method'), self.methods))
self.addParameter(QgsProcessingParameterFeatureSink(self.VALID_OUTPUT, self.tr('Valid output'), QgsProcessingParameterDefinition.TypeVectorAny, '', True))
self.addParameter(QgsProcessingParameterFeatureSink(self.VALID_OUTPUT, self.tr('Valid output'), QgsProcessing.TypeVectorAny, '', True))
self.addOutput(QgsProcessingOutputVectorLayer(self.VALID_OUTPUT, self.tr('Valid output')))
self.addOutput(QgsProcessingOutputNumber(self.VALID_COUNT, self.tr('Count of valid features')))
self.addParameter(QgsProcessingParameterFeatureSink(self.INVALID_OUTPUT, self.tr('Invalid output'), QgsProcessingParameterDefinition.TypeVectorAny, '', True))
self.addParameter(QgsProcessingParameterFeatureSink(self.INVALID_OUTPUT, self.tr('Invalid output'), QgsProcessing.TypeVectorAny, '', True))
self.addOutput(QgsProcessingOutputVectorLayer(self.INVALID_OUTPUT, self.tr('Invalid output')))
self.addOutput(QgsProcessingOutputNumber(self.INVALID_COUNT, self.tr('Count of invalid features')))
self.addParameter(QgsProcessingParameterFeatureSink(self.ERROR_OUTPUT, self.tr('Error output'), QgsProcessingParameterDefinition.TypeVectorAny, '', True))
self.addParameter(QgsProcessingParameterFeatureSink(self.ERROR_OUTPUT, self.tr('Error output'), QgsProcessing.TypeVectorAny, '', True))
self.addOutput(QgsProcessingOutputVectorLayer(self.ERROR_OUTPUT, self.tr('Error output')))
self.addOutput(QgsProcessingOutputNumber(self.ERROR_COUNT, self.tr('Count of errors')))

View File

@ -32,6 +32,7 @@ from qgis.core import (QgsFeatureRequest,
QgsFeatureSink,
QgsWkbTypes,
QgsApplication,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterVectorLayer,
@ -60,7 +61,7 @@ class ConcaveHull(QgisAlgorithm):
def __init__(self):
super().__init__()
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input point layer'), [QgsProcessingParameterDefinition.TypeVectorPoint]))
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input point layer'), [QgsProcessing.TypeVectorPoint]))
self.addParameter(QgsProcessingParameterNumber(self.ALPHA,
self.tr('Threshold (0-1, where 1 is equivalent with Convex Hull)'),
minValue=0, maxValue=1, defaultValue=0.3, type=QgsProcessingParameterNumber.Double))
@ -70,8 +71,8 @@ class ConcaveHull(QgisAlgorithm):
self.addParameter(QgsProcessingParameterBoolean(self.NO_MULTIGEOMETRY,
self.tr('Split multipart geometry into singleparts geometries'), defaultValue=False))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Concave hull'), type=QgsProcessingParameterDefinition.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Concave hull"), type=QgsProcessingParameterDefinition.TypeVectorPolygon))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Concave hull'), type=QgsProcessing.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Concave hull"), type=QgsProcessing.TypeVectorPolygon))
def name(self):
return 'concavehull'

View File

@ -38,6 +38,7 @@ from qgis.core import (QgsField,
QgsGeometry,
QgsPointXY,
QgsWkbTypes,
QgsProcessing,
QgsProcessingUtils,
QgsFields,
QgsProcessingParameterFeatureSource,
@ -67,9 +68,9 @@ class Delaunay(QgisAlgorithm):
def __init__(self):
super().__init__()
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPoint]))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Delaunay triangulation'), type=QgsProcessingParameterDefinition.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Delaunay triangulation"), type=QgsProcessingParameterDefinition.TypeVectorPolygon))
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorPoint]))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Delaunay triangulation'), type=QgsProcessing.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Delaunay triangulation"), type=QgsProcessing.TypeVectorPolygon))
def name(self):
return 'delaunaytriangulation'

View File

@ -26,6 +26,7 @@ __revision__ = '$Format:%H$'
from qgis.core import (QgsApplication,
QgsFeatureSink,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterNumber,
@ -50,13 +51,13 @@ class DeleteHoles(QgisAlgorithm):
def __init__(self):
super().__init__()
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPolygon]))
self.tr('Input layer'), [QgsProcessing.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterNumber(self.MIN_AREA,
self.tr('Remove holes with area less than'), QgsProcessingParameterNumber.Double,
0, True, 0.0, 10000000.0))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Cleaned'), QgsProcessingParameterDefinition.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Cleaned'), QgsProcessingParameterDefinition.TypeVectorPolygon))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Cleaned'), QgsProcessing.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Cleaned'), QgsProcessing.TypeVectorPolygon))
def name(self):
return 'deleteholes'

View File

@ -31,6 +31,7 @@ import os
from qgis.core import (QgsWkbTypes,
QgsFeatureSink,
QgsApplication,
QgsProcessing,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterNumber,
QgsProcessingParameterFeatureSink,
@ -55,7 +56,7 @@ class DensifyGeometries(QgisAlgorithm):
super().__init__()
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPolygon, QgsProcessingParameterDefinition.TypeVectorLine]))
self.tr('Input layer'), [QgsProcessing.TypeVectorPolygon, QgsProcessing.TypeVectorLine]))
self.addParameter(QgsProcessingParameterNumber(self.VERTICES,
self.tr('Vertices to add'), QgsProcessingParameterNumber.Integer,
1, False, 1, 10000000))

View File

@ -32,6 +32,7 @@ from math import sqrt
from qgis.core import (QgsWkbTypes,
QgsApplication,
QgsFeatureSink,
QgsProcessing,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterNumber,
QgsProcessingParameterFeatureSink,
@ -53,7 +54,7 @@ class DensifyGeometriesInterval(QgisAlgorithm):
super().__init__()
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPolygon, QgsProcessingParameterDefinition.TypeVectorLine]))
self.tr('Input layer'), [QgsProcessing.TypeVectorPolygon, QgsProcessing.TypeVectorLine]))
self.addParameter(QgsProcessingParameterNumber(self.INTERVAL,
self.tr('Interval between vertices to add'), QgsProcessingParameterNumber.Double,
1, False, 0, 10000000))

View File

@ -30,6 +30,7 @@ from qgis.core import (QgsFeatureRequest,
QgsFeatureSink,
QgsCoordinateReferenceSystem,
QgsApplication,
QgsProcessing,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink,
@ -51,7 +52,7 @@ class DropGeometry(QgisAlgorithm):
def __init__(self):
super().__init__()
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPoint, QgsProcessingParameterDefinition.TypeVectorLine, QgsProcessingParameterDefinition.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorPoint, QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Dropped geometry')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Dropped geometry")))

View File

@ -36,6 +36,7 @@ from qgis.core import (QgsField,
QgsGeometry,
QgsFeature,
QgsWkbTypes,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink,
@ -77,7 +78,7 @@ class ExtentFromLayer(QgisAlgorithm):
self.tr('Calculate extent for each feature separately'), False))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Extent')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Extent"), QgsProcessingParameterDefinition.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Extent"), QgsProcessing.TypeVectorPolygon))
def name(self):
return 'polygonfromlayerextent'

View File

@ -30,6 +30,7 @@ from qgis.core import (QgsWkbTypes,
QgsFeatureRequest,
QgsProcessingFeatureSource,
QgsGeometry,
QgsProcessing,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink,
@ -51,7 +52,7 @@ class FixGeometry(QgisAlgorithm):
def __init__(self):
super().__init__()
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorLine, QgsProcessingParameterDefinition.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Fixed geometries')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Fixed geometries")))

View File

@ -38,6 +38,7 @@ from qgis.core import (QgsRectangle,
QgsGeometry,
QgsPointXY,
QgsWkbTypes,
QgsProcessing,
QgsProcessingParameterEnum,
QgsProcessingParameterExtent,
QgsProcessingParameterNumber,
@ -100,7 +101,7 @@ class GridPolygon(QgisAlgorithm):
self.addParameter(QgsProcessingParameterCrs(self.CRS, 'Grid CRS', 'ProjectCrs'))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Grid')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Grid'), QgsProcessingParameterDefinition.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Grid'), QgsProcessing.TypeVectorPolygon))
def name(self):
return 'creategridpolygon'

View File

@ -33,6 +33,7 @@ from qgis.core import (QgsFields,
QgsField,
QgsFeatureRequest,
QgsFeatureSink,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterMultipleLayers,
QgsProcessingParameterDefinition,
@ -63,7 +64,7 @@ class Merge(QgisAlgorithm):
super().__init__()
self.addParameter(QgsProcessingParameterMultipleLayers(self.LAYERS,
self.tr('Layers to merge'),
QgsProcessingParameterDefinition.TypeVectorAny))
QgsProcessing.TypeVectorAny))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Merged')))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Merged')))

View File

@ -30,6 +30,7 @@ from qgis.core import (QgsApplication,
QgsPoint,
QgsFeatureRequest,
QgsGeometry,
QgsProcessing,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterFeatureSource,
@ -64,7 +65,7 @@ class PointsLayerFromTable(QgisAlgorithm):
def __init__(self):
super().__init__()
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), types=[QgsProcessingParameterField.TypeTable]))
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), types=[QgsProcessing.TypeTable]))
self.addParameter(QgsProcessingParameterField(self.XFIELD,
self.tr('X field'), parentLayerParameterName=self.INPUT, type=QgsProcessingParameterField.Any))
@ -77,8 +78,8 @@ class PointsLayerFromTable(QgisAlgorithm):
self.addParameter(QgsProcessingParameterCrs(self.TARGET_CRS,
self.tr('Target CRS'), defaultValue='EPSG:4326'))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Points from table'), type=QgsProcessingParameterDefinition.TypeVectorPoint))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Points from table'), type=QgsProcessingParameterDefinition.TypeVectorPoint))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Points from table'), type=QgsProcessing.TypeVectorPoint))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Points from table'), type=QgsProcessing.TypeVectorPoint))
def name(self):
return 'createpointslayerfromtable'

View File

@ -34,6 +34,7 @@ from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsRectangle, QgsFields, QgsFeatureSink, QgsField, QgsFeature, QgsWkbTypes,
QgsGeometry, QgsPointXY, QgsCoordinateReferenceSystem,
QgsProcessing,
QgsProcessingParameterExtent,
QgsProcessingParameterNumber,
QgsProcessingParameterBoolean,
@ -78,8 +79,8 @@ class RegularPoints(QgisAlgorithm):
self.addParameter(QgsProcessingParameterCrs(self.CRS,
self.tr('Output layer CRS'), 'ProjectCrs'))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Regular points'), QgsProcessingParameterDefinition.TypeVectorPoint))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Regular points'), QgsProcessingParameterDefinition.TypeVectorPoint))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Regular points'), QgsProcessing.TypeVectorPoint))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr('Regular points'), QgsProcessing.TypeVectorPoint))
def name(self):
return 'regularpoints'

View File

@ -28,6 +28,7 @@ __revision__ = '$Format:%H$'
from qgis.analysis import (QgsGeometrySnapper,
QgsInternalGeometrySnapper)
from qgis.core import (QgsFeatureSink,
QgsProcessing,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink,
@ -52,11 +53,11 @@ class SnapGeometriesToLayer(QgisAlgorithm):
def __init__(self):
super().__init__()
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPoint, QgsProcessingParameterDefinition.TypeVectorLine, QgsProcessingParameterDefinition.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorPoint, QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterFeatureSource(self.REFERENCE_LAYER, self.tr('Reference layer'),
[QgsProcessingParameterDefinition.TypeVectorPoint,
QgsProcessingParameterDefinition.TypeVectorLine,
QgsProcessingParameterDefinition.TypeVectorPolygon]))
[QgsProcessing.TypeVectorPoint,
QgsProcessing.TypeVectorLine,
QgsProcessing.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterNumber(self.TOLERANCE, self.tr('Tolerance (layer units)'), type=QgsProcessingParameterNumber.Double,
minValue=0.00000001, maxValue=9999999999, defaultValue=10.0))

View File

@ -32,7 +32,7 @@ from qgis.core import (QgsProcessingUtils,
QgsFeatureSink,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterField,
QgsProcessingParameterFolderOutput,
QgsProcessingParameterFolderDestination,
QgsProcessingOutputFolder,
QgsExpression,
QgsFeatureRequest)
@ -61,8 +61,8 @@ class VectorSplit(QgisAlgorithm):
self.addParameter(QgsProcessingParameterField(self.FIELD,
self.tr('Unique ID field'), None, self.INPUT))
self.addParameter(QgsProcessingParameterFolderOutput(self.OUTPUT,
self.tr('Output directory')))
self.addParameter(QgsProcessingParameterFolderDestination(self.OUTPUT,
self.tr('Output directory')))
self.addOutput(QgsProcessingOutputFolder(self.OUTPUT, self.tr('Output directory')))

View File

@ -36,6 +36,7 @@ from qgis.core import (QgsFeatureRequest,
QgsGeometry,
QgsPointXY,
QgsWkbTypes,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterDefinition,
@ -66,12 +67,12 @@ class VoronoiPolygons(QgisAlgorithm):
def __init__(self):
super().__init__()
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessingParameterDefinition.TypeVectorPoint]))
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorPoint]))
self.addParameter(QgsProcessingParameterNumber(self.BUFFER, self.tr('Buffer region'), type=QgsProcessingParameterNumber.Double,
minValue=0.0, maxValue=9999999999, defaultValue=0.0))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Voronoi polygons'), type=QgsProcessingParameterDefinition.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Voronoi polygons"), type=QgsProcessingParameterDefinition.TypeVectorPolygon))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Voronoi polygons'), type=QgsProcessing.TypeVectorPolygon))
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT, self.tr("Voronoi polygons"), type=QgsProcessing.TypeVectorPolygon))
def name(self):
return 'voronoipolygons'

View File

@ -32,6 +32,7 @@ from qgis.PyQt.QtGui import QIcon
from qgis.analysis import QgsZonalStatistics
from qgis.core import (QgsFeatureSink,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterDefinition,
QgsProcessingParameterVectorLayer,
@ -83,7 +84,7 @@ class ZonalStatistics(QgisAlgorithm):
minValue=1, maxValue=999, defaultValue=1))
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT_VECTOR,
self.tr('Vector layer containing zones'),
[QgsProcessingParameterDefinition.TypeVectorPolygon]))
[QgsProcessing.TypeVectorPolygon]))
self.addParameter(QgsProcessingParameterString(self.COLUMN_PREFIX,
self.tr('Output column prefix'), '_'))
keys = list(self.STATS.keys())
@ -93,7 +94,7 @@ class ZonalStatistics(QgisAlgorithm):
allowMultiple=True, defaultValue=[0, 1, 2]))
self.addOutput(QgsProcessingOutputVectorLayer(self.INPUT_VECTOR,
self.tr('Zonal statistics'),
QgsProcessingParameterDefinition.TypeVectorPolygon))
QgsProcessing.TypeVectorPolygon))
self.bandNumber = None
self.columnPrefix = None

View File

@ -42,10 +42,10 @@ from qgis.core import (QgsProject,
QgsProcessingOutputVectorLayer,
QgsProcessingAlgRunnerTask,
QgsProcessingOutputHtml,
QgsProcessingParameterVectorOutput,
QgsProcessingParameterVectorDestination,
QgsProcessingOutputLayerDefinition,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterRasterOutput,
QgsProcessingParameterRasterDestination,
QgsProcessingAlgorithm)
from qgis.gui import QgsMessageBar
from qgis.utils import iface
@ -119,7 +119,7 @@ class AlgorithmDialog(AlgorithmDialogBase):
else:
dest_project = None
if not param.flags() & QgsProcessingParameterDefinition.FlagHidden and \
isinstance(param, (QgsProcessingParameterRasterOutput, QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorOutput)):
isinstance(param, (QgsProcessingParameterRasterDestination, QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorDestination)):
if self.mainWidget.checkBoxes[param.name()].isChecked():
dest_project = QgsProject.instance()

View File

@ -34,7 +34,7 @@ from qgis.PyQt.QtGui import QCursor
from qgis.PyQt.QtCore import Qt
from qgis.core import (QgsProcessingParameterDefinition,
QgsProcessingParameterRasterOutput,
QgsProcessingParameterRasterDestination,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputLayerDefinition,
QgsProcessingOutputHtml,
@ -104,7 +104,7 @@ class BatchAlgorithmDialog(AlgorithmDialogBase):
widget = self.mainWidget.tblParameters.cellWidget(row, col)
text = widget.getValue()
if param.checkValueIsAcceptable(text, context):
if isinstance(out, (QgsProcessingParameterRasterOutput,
if isinstance(out, (QgsProcessingParameterRasterDestination,
QgsProcessingParameterFeatureSink)):
# load rasters and sinks on completion
parameters[out.name()] = QgsProcessingOutputLayerDefinition(text, context.project())

View File

@ -36,6 +36,7 @@ from qgis.PyQt.QtGui import QCursor
from qgis.core import (QgsMapLayer,
QgsSettings,
QgsProject,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterMultipleLayers,
QgsProcessingParameterRasterLayer,
@ -103,18 +104,18 @@ class BatchInputSelectionPanel(QWidget):
layers = []
if (isinstance(self.param, QgsProcessingParameterRasterLayer) or
(isinstance(self.param, QgsProcessingParameterMultipleLayers) and
self.param.layerType() == QgsProcessingParameterDefinition.TypeRaster)):
self.param.layerType() == QgsProcessing.TypeRaster)):
layers = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance())
elif isinstance(self.param, QgsProcessingParameterVectorLayer):
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())
else:
datatypes = [QgsProcessingParameterDefinition.TypeVectorAny]
datatypes = [QgsProcessing.TypeVectorAny]
if isinstance(self.param, QgsProcessingParameterFeatureSource):
datatypes = self.param.dataTypes()
elif isinstance(self.param, QgsProcessingParameterMultipleLayers):
datatypes = [self.param.layerType()]
if QgsProcessingParameterDefinition.TypeVectorAny not in datatypes:
if QgsProcessing.TypeVectorAny not in datatypes:
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), datatypes)
else:
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())

View File

@ -33,7 +33,7 @@ import re
from qgis.core import (QgsMapLayer,
QgsSettings,
QgsProcessingParameterFolderOutput,
QgsProcessingParameterFolderDestination,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterVectorLayer,
@ -73,7 +73,7 @@ class BatchOutputSelectionPanel(QWidget):
self.setLayout(self.horizontalLayout)
def showSelectionDialog(self):
if isinstance(self.output, QgsProcessingParameterFolderOutput):
if isinstance(self.output, QgsProcessingParameterFolderDestination):
self.selectDirectory()
return

View File

@ -41,7 +41,7 @@ from qgis.core import (QgsDataSourceUri,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputLayerDefinition,
QgsProcessingParameterDefinition,
QgsProcessingParameterFolderOutput)
QgsProcessingParameterFolderDestination)
from processing.core.ProcessingConfig import ProcessingConfig
from processing.tools.dataobjects import createContext
from processing.gui.PostgisTableSelector import PostgisTableSelector
@ -79,7 +79,7 @@ class DestinationSelectionPanel(BASE, WIDGET):
and alg.provider().supportsNonFileBasedOutput():
# use memory layers for temporary files if supported
self.leText.setPlaceholderText(self.SAVE_TO_TEMP_LAYER)
elif not isinstance(self.parameter, QgsProcessingParameterFolderOutput):
elif not isinstance(self.parameter, QgsProcessingParameterFolderDestination):
self.leText.setPlaceholderText(self.SAVE_TO_TEMP_FILE)
self.btnSelect.clicked.connect(self.selectOutput)
@ -94,7 +94,7 @@ class DestinationSelectionPanel(BASE, WIDGET):
self.use_temporary = False
def selectOutput(self):
if isinstance(self.parameter, QgsProcessingParameterFolderOutput):
if isinstance(self.parameter, QgsProcessingParameterFolderDestination):
self.selectDirectory()
else:
popupMenu = QMenu()
@ -275,7 +275,7 @@ class DestinationSelectionPanel(BASE, WIDGET):
if not key and self.parameter.flags() & QgsProcessingParameterDefinition.FlagOptional:
return None
if isinstance(self.parameter, QgsProcessingParameterFolderOutput):
if isinstance(self.parameter, QgsProcessingParameterFolderDestination):
return self.leText.text()
value = QgsProcessingOutputLayerDefinition(key)

View File

@ -36,7 +36,7 @@ from qgis.PyQt.QtWidgets import QDialog
from qgis.core import (QgsExpression,
QgsProcessingParameterNumber,
QgsProcessingOutputNumber,
QgsProcessingModelAlgorithm)
QgsProcessingModelChildParameterSource)
from qgis.gui import QgsExpressionBuilderDialog
from processing.tools.dataobjects import createExpressionContext, createContext
@ -92,26 +92,26 @@ class ModellerNumberInputPanel(BASE, WIDGET):
for param in self.modelParametersDialog.model.parameterDefinitions():
if isinstance(param, QgsProcessingParameterNumber):
if "@" + param.name() == value.strip():
return QgsProcessingModelAlgorithm.ChildParameterSource.fromModelParameter(param.name())
return QgsProcessingModelChildParameterSource.fromModelParameter(param.name())
for alg in list(self.modelParametersDialog.model.childAlgorithms().values()):
for out in alg.algorithm().outputDefinitions():
if isinstance(out, QgsProcessingOutputNumber) and "@%s_%s" % (alg.childId(), out.name()) == value.strip():
return QgsProcessingModelAlgorithm.ChildParameterSource.fromChildOutput(alg.childId(), out.outputName())
return QgsProcessingModelChildParameterSource.fromChildOutput(alg.childId(), out.outputName())
try:
return float(value.strip())
except:
return QgsProcessingModelAlgorithm.ChildParameterSource.fromExpression(self.leText.text())
return QgsProcessingModelChildParameterSource.fromExpression(self.leText.text())
def setValue(self, value):
if isinstance(value, QgsProcessingModelAlgorithm.ChildParameterSource):
if value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ModelParameter:
if isinstance(value, QgsProcessingModelChildParameterSource):
if value.source() == QgsProcessingModelChildParameterSource.ModelParameter:
self.leText.setText('@' + value.parameterName())
elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ChildOutput:
elif value.source() == QgsProcessingModelChildParameterSource.ChildOutput:
name = "%s_%s" % (value.outputChildId(), value.outputName())
self.leText.setText(name)
elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.Expression:
elif value.source() == QgsProcessingModelChildParameterSource.Expression:
self.leText.setText(value.expression())
else:
self.leText.setText(str(value.staticValue()))

View File

@ -26,10 +26,10 @@ __copyright__ = '(C) 2017, Nyall Dawson'
__revision__ = '$Format:%H$'
from qgis.core import (
QgsProcessingParameterDefinition,
QgsProcessingFeatureSourceDefinition,
QgsVectorFileWriter)
from qgis.core import (QgsProcessing,
QgsProcessingParameterDefinition,
QgsProcessingFeatureSourceDefinition,
QgsVectorFileWriter)
from qgis.PyQt.QtCore import QCoreApplication
from processing.tools import dataobjects
@ -47,19 +47,19 @@ def getFileFilter(param):
:return:
"""
if param.type() == 'multilayer':
if param.layerType() == QgsProcessingParameterDefinition.TypeRaster:
if param.layerType() == QgsProcessing.TypeRaster:
exts = dataobjects.getSupportedOutputRasterLayerExtensions()
elif param.layerType() == QgsProcessingParameterDefinition.TypeFile:
elif param.layerType() == QgsProcessing.TypeFile:
return tr('All files (*.*)', 'QgsProcessingParameterMultipleLayers')
else:
exts = QgsVectorFileWriter.supportedFormatExtensions()
for i in range(len(exts)):
exts[i] = tr('{0} files (*.{1})', 'QgsProcessingParameterMultipleLayers').format(exts[i].upper(), exts[i].lower())
return ';;'.join(exts)
elif param.type() in ('raster', 'rasterOut'):
elif param.type() in ('raster', 'rasterDestination'):
exts = dataobjects.getSupportedOutputRasterLayerExtensions()
for i in range(len(exts)):
exts[i] = tr('{0} files (*.{1})', 'QgsProcessingParameterRasterOutput').format(exts[i].upper(), exts[i].lower())
exts[i] = tr('{0} files (*.{1})', 'QgsProcessingParameterRasterDestination').format(exts[i].upper(), exts[i].lower())
return ';;'.join(exts)
elif param.type() == 'table':
exts = ['csv', 'dbf']

View File

@ -37,9 +37,9 @@ from qgis.core import (QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingOutputVectorLayer,
QgsProcessingOutputRasterLayer,
QgsProcessingParameterRasterOutput,
QgsProcessingParameterRasterDestination,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterVectorOutput)
QgsProcessingParameterVectorDestination)
from qgis.PyQt import uic
from qgis.PyQt.QtCore import QCoreApplication, Qt
from qgis.PyQt.QtWidgets import (QWidget, QHBoxLayout, QToolButton,
@ -158,7 +158,7 @@ class ParametersPanel(BASE, WIDGET):
widget = DestinationSelectionPanel(output, self.alg)
self.layoutMain.insertWidget(self.layoutMain.count() - 1, label)
self.layoutMain.insertWidget(self.layoutMain.count() - 1, widget)
if isinstance(output, (QgsProcessingParameterRasterOutput, QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorOutput)):
if isinstance(output, (QgsProcessingParameterRasterDestination, QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorDestination)):
check = QCheckBox()
check.setText(self.tr('Open output file after running algorithm'))
check.setChecked(True)

View File

@ -68,7 +68,7 @@ class ScriptEditorDialog(BASE, WIDGET):
self.restoreState(settings.value("/Processing/stateScriptEditor", QByteArray()))
self.restoreGeometry(settings.value("/Processing/geometryScriptEditor", QByteArray()))
iconSize = int(settings.value("iconsize", 24))
iconSize = int(settings.value("IconSize", 24))
self.toolBar.setIconSize(QSize(iconSize, iconSize))
self.actionOpenScript.setIcon(

View File

@ -45,6 +45,7 @@ from qgis.core import (
QgsSettings,
QgsProject,
QgsMapLayer,
QgsProcessing,
QgsProcessingUtils,
QgsProcessingParameterDefinition,
QgsProcessingParameterBoolean,
@ -176,7 +177,10 @@ class WidgetWrapper(QObject):
if combobox is None:
combobox = self.widget
if isinstance(value, list):
value = value[0]
if value:
value = value[0]
else:
value = None
values = [combobox.itemData(i) for i in range(combobox.count())]
try:
idx = values.index(value)
@ -517,20 +521,20 @@ class FixedTableWidgetWrapper(WidgetWrapper):
class MultipleInputWidgetWrapper(WidgetWrapper):
def _getOptions(self):
if self.param.layerType() == QgsProcessingParameterDefinition.TypeVectorAny:
if self.param.layerType() == QgsProcessing.TypeVectorAny:
options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFeatureSource, QgsProcessingOutputVectorLayer)
elif self.param.layerType() == QgsProcessingParameterDefinition.TypeVectorPoint:
elif self.param.layerType() == QgsProcessing.TypeVectorPoint:
options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFeatureSource, QgsProcessingOutputVectorLayer,
[QgsProcessingParameterDefinition.TypeVectorPoint, QgsProcessingParameterDefinition.TypeVectorAny])
elif self.param.layerType() == QgsProcessingParameterDefinition.TypeVectorLine:
[QgsProcessing.TypeVectorPoint, QgsProcessing.TypeVectorAny])
elif self.param.layerType() == QgsProcessing.TypeVectorLine:
options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFeatureSource, QgsProcessingOutputVectorLayer,
[QgsProcessingParameterDefinition.TypeVectorLine, QgsProcessingParameterDefinition.TypeVectorAny])
elif self.param.layerType() == QgsProcessingParameterDefinition.TypeVectorPolygon:
[QgsProcessing.TypeVectorLine, QgsProcessing.TypeVectorAny])
elif self.param.layerType() == QgsProcessing.TypeVectorPolygon:
options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFeatureSource, QgsProcessingOutputVectorLayer,
[QgsProcessingParameterDefinition.TypeVectorPolygon, QgsProcessingParameterDefinition.TypeVectorAny])
elif self.param.layerType() == QgsProcessingParameterDefinition.TypeRaster:
[QgsProcessing.TypeVectorPolygon, QgsProcessing.TypeVectorAny])
elif self.param.layerType() == QgsProcessing.TypeRaster:
options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterRasterLayer, QgsProcessingOutputRasterLayer)
elif self.param.layerType() == QgsProcessingParameterDefinition.TypeTable:
elif self.param.layerType() == QgsProcessing.TypeTable:
options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterVectorLayer, OutputTable)
else:
options = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFile, OutputFile)
@ -539,12 +543,12 @@ class MultipleInputWidgetWrapper(WidgetWrapper):
def createWidget(self):
if self.dialogType == DIALOG_STANDARD:
if self.param.layerType() == QgsProcessingParameterDefinition.TypeFile:
if self.param.layerType() == QgsProcessing.TypeFile:
return MultipleInputPanel(datatype=dataobjects.TYPE_FILE)
else:
if self.param.layerType() == QgsProcessingParameterDefinition.TypeRaster:
if self.param.layerType() == QgsProcessing.TypeRaster:
options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
elif self.param.layerType() in (QgsProcessingParameterDefinition.TypeVectorAny, QgsProcessingParameterDefinition.TypeTable):
elif self.param.layerType() in (QgsProcessing.TypeVectorAny, QgsProcessing.TypeTable):
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
else:
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()], False)
@ -559,10 +563,10 @@ class MultipleInputWidgetWrapper(WidgetWrapper):
return MultipleInputPanel(options)
def refresh(self):
if self.param.layerType() != QgsProcessingParameterDefinition.TypeFile:
if self.param.layerType() == QgsProcessingParameterDefinition.TypeRaster:
if self.param.layerType() != QgsProcessing.TypeFile:
if self.param.layerType() == QgsProcessing.TypeRaster:
options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
elif self.param.layerType() in (QgsProcessingParameterDefinition.TypeVectorAny, QgsProcessingParameterDefinition.TypeTable):
elif self.param.layerType() in (QgsProcessing.TypeVectorAny, QgsProcessing.TypeTable):
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
else:
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()], False)
@ -584,12 +588,12 @@ class MultipleInputWidgetWrapper(WidgetWrapper):
def value(self):
if self.dialogType == DIALOG_STANDARD:
if self.param.layerType() == QgsProcessingParameterDefinition.TypeFile:
if self.param.layerType() == QgsProcessing.TypeFile:
return self.param.setValue(self.widget.selectedoptions)
else:
if self.param.layerType() == QgsProcessingParameterDefinition.TypeRaster:
if self.param.layerType() == QgsProcessing.TypeRaster:
options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
elif self.param.layerType() in (QgsProcessingParameterDefinition.TypeVectorAny, QgsProcessingParameterDefinition.TypeTable):
elif self.param.layerType() in (QgsProcessing.TypeVectorAny, QgsProcessing.TypeTable):
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
else:
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()], False)
@ -599,7 +603,7 @@ class MultipleInputWidgetWrapper(WidgetWrapper):
else:
options = self._getOptions()
values = [options[i] for i in self.widget.selectedoptions]
if len(values) == 0 and not self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
if len(values) == 0 and not self.param.flags() & QgsProcessing.FlagOptional:
raise InvalidParameterValue()
return values
@ -784,13 +788,13 @@ class VectorWidgetWrapper(WidgetWrapper):
widget.setLayout(vl)
filters = QgsMapLayerProxyModel.Filters()
if QgsProcessingParameterDefinition.TypeVectorAny in self.param.dataTypes() or len(self.param.dataTypes()) == 0:
if QgsProcessing.TypeVectorAny in self.param.dataTypes() or len(self.param.dataTypes()) == 0:
filters = QgsMapLayerProxyModel.HasGeometry
if QgsProcessingParameterDefinition.TypeVectorPoint in self.param.dataTypes():
if QgsProcessing.TypeVectorPoint in self.param.dataTypes():
filters |= QgsMapLayerProxyModel.PointLayer
if QgsProcessingParameterDefinition.TypeVectorLine in self.param.dataTypes():
if QgsProcessing.TypeVectorLine in self.param.dataTypes():
filters |= QgsMapLayerProxyModel.LineLayer
if QgsProcessingParameterDefinition.TypeVectorPolygon in self.param.dataTypes():
if QgsProcessing.TypeVectorPolygon in self.param.dataTypes():
filters |= QgsMapLayerProxyModel.PolygonLayer
try:

View File

@ -46,7 +46,9 @@
***************************************************************************
"""
from qgis.core import QgsProcessingModelAlgorithm
from qgis.core import (QgsProcessingModelAlgorithm,
QgsProcessingModelChildAlgorithm,
QgsProcessingModelParameter)
from qgis.PyQt.QtCore import Qt, QPointF
from qgis.PyQt.QtWidgets import QGraphicsPathItem, QGraphicsItem
from qgis.PyQt.QtGui import QPen, QPainterPath, QPolygonF, QPainter
@ -80,14 +82,14 @@ class ModelerArrowItem(QGraphicsPathItem):
self.endPoints = []
controlPoints = []
endPt = self.endItem.getLinkPointForParameter(self.endIndex)
if isinstance(self.startItem.element, QgsProcessingModelAlgorithm.ModelParameter):
if isinstance(self.startItem.element, QgsProcessingModelParameter):
startPt = self.startItem.getLinkPointForParameter(self.startIndex)
else:
startPt = self.startItem.getLinkPointForOutput(self.startIndex)
if isinstance(self.endItem.element, QgsProcessingModelAlgorithm.ModelParameter):
if isinstance(self.endItem.element, QgsProcessingModelParameter):
endPt = self.endItem.getLinkPointForParameter(self.startIndex)
if isinstance(self.startItem.element, QgsProcessingModelAlgorithm.ChildAlgorithm):
if isinstance(self.startItem.element, QgsProcessingModelChildAlgorithm):
if self.startIndex != -1:
controlPoints.append(self.startItem.pos() + startPt)
controlPoints.append(self.startItem.pos() + startPt +

View File

@ -43,6 +43,7 @@ from qgis.core import (QgsApplication,
QgsMessageLog,
QgsProcessingUtils,
QgsProcessingModelAlgorithm,
QgsProcessingModelParameter,
QgsXmlUtils)
from qgis.gui import QgsMessageBar
from processing.gui.HelpEditionDialog import HelpEditionDialog
@ -217,7 +218,7 @@ class ModelerDialog(BASE, WIDGET):
ctrlEquals.activated.connect(self.zoomIn)
try:
iconSize = int(settings.value("iconsize", 24))
iconSize = int(settings.value("IconSize", 24))
except:
iconSize = 24
self.mToolbar.setIconSize(QSize(iconSize, iconSize))
@ -513,7 +514,7 @@ class ModelerDialog(BASE, WIDGET):
pos = self.getPositionForParameterItem()
if isinstance(pos, QPoint):
pos = QPointF(pos)
component = QgsProcessingModelAlgorithm.ModelParameter(dlg.param.name())
component = QgsProcessingModelParameter(dlg.param.name())
component.setDescription(dlg.param.name())
component.setPosition(pos)
self.model.addModelParameter(dlg.param, component)

View File

@ -34,6 +34,9 @@ from qgis.PyQt.QtGui import QFont, QFontMetricsF, QPen, QBrush, QColor, QPolygon
from qgis.PyQt.QtWidgets import QGraphicsItem, QMessageBox, QMenu
from qgis.PyQt.QtSvg import QSvgRenderer
from qgis.core import (QgsProcessingParameterDefinition,
QgsProcessingModelParameter,
QgsProcessingModelOutput,
QgsProcessingModelChildAlgorithm,
QgsProcessingModelAlgorithm)
from processing.modeler.ModelerParameterDefinitionDialog import ModelerParameterDefinitionDialog
from processing.modeler.ModelerParametersDialog import ModelerParametersDialog
@ -52,14 +55,14 @@ class ModelerGraphicItem(QGraphicsItem):
self.model = model
self.scene = scene
self.element = element
if isinstance(element, QgsProcessingModelAlgorithm.ModelParameter):
if isinstance(element, QgsProcessingModelParameter):
svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'input.svg'))
self.picture = QPicture()
painter = QPainter(self.picture)
svg.render(painter)
self.pixmap = None
self.text = self.model.parameterDefinition(element.parameterName()).description()
elif isinstance(element, QgsProcessingModelAlgorithm.ModelOutput):
elif isinstance(element, QgsProcessingModelOutput):
# Output name
svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'output.svg'))
self.picture = QPicture()
@ -76,7 +79,7 @@ class ModelerGraphicItem(QGraphicsItem):
self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True)
self.setZValue(1000)
if not isinstance(element, QgsProcessingModelAlgorithm.ModelOutput) and controls:
if not isinstance(element, QgsProcessingModelOutput) and controls:
svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'edit.svg'))
picture = QPicture()
painter = QPainter(picture)
@ -99,7 +102,7 @@ class ModelerGraphicItem(QGraphicsItem):
self.removeElement)
self.deleteButton.setParentItem(self)
if isinstance(element, QgsProcessingModelAlgorithm.ChildAlgorithm):
if isinstance(element, QgsProcessingModelChildAlgorithm):
alg = element.algorithm()
if [a for a in alg.parameterDefinitions() if not a.isDestination()]:
pt = self.getLinkPointForParameter(-1)
@ -143,9 +146,9 @@ class ModelerGraphicItem(QGraphicsItem):
font = QFont('Verdana', 8)
font.setPixelSize(12)
fm = QFontMetricsF(font)
unfolded = isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm) and not self.element.parametersCollapsed()
unfolded = isinstance(self.element, QgsProcessingModelChildAlgorithm) and not self.element.parametersCollapsed()
numParams = len([a for a in self.element.algorithm().parameterDefinitions() if not a.isDestination()]) if unfolded else 0
unfolded = isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm) and not self.element.outputsCollapsed()
unfolded = isinstance(self.element, QgsProcessingModelChildAlgorithm) and not self.element.outputsCollapsed()
numOutputs = len(self.element.algorithm().outputDefinitions()) if unfolded else 0
hUp = fm.height() * 1.2 * (numParams + 2)
@ -160,14 +163,14 @@ class ModelerGraphicItem(QGraphicsItem):
self.editElement()
def contextMenuEvent(self, event):
if isinstance(self.element, QgsProcessingModelAlgorithm.ModelOutput):
if isinstance(self.element, QgsProcessingModelOutput):
return
popupmenu = QMenu()
removeAction = popupmenu.addAction('Remove')
removeAction.triggered.connect(self.removeElement)
editAction = popupmenu.addAction('Edit')
editAction.triggered.connect(self.editElement)
if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm):
if isinstance(self.element, QgsProcessingModelChildAlgorithm):
if not self.element.isActive():
removeAction = popupmenu.addAction('Activate')
removeAction.triggered.connect(self.activateAlgorithm)
@ -189,7 +192,7 @@ class ModelerGraphicItem(QGraphicsItem):
'Activate them them before trying to activate it.')
def editElement(self):
if isinstance(self.element, QgsProcessingModelAlgorithm.ModelParameter):
if isinstance(self.element, QgsProcessingModelParameter):
dlg = ModelerParameterDefinitionDialog(self.model,
param=self.model.parameterDefinition(self.element.parameterName()))
dlg.exec_()
@ -200,7 +203,7 @@ class ModelerGraphicItem(QGraphicsItem):
self.model.addModelParameter(dlg.param, self.element)
self.text = dlg.param.description()
self.scene.dialog.repaintModel()
elif isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm):
elif isinstance(self.element, QgsProcessingModelChildAlgorithm):
dlg = None
try:
dlg = self.element.algorithm().getCustomModelerParametersDialog(self.model, self.element.childId())
@ -227,7 +230,7 @@ class ModelerGraphicItem(QGraphicsItem):
self.model.setChildAlgorithm(alg)
def removeElement(self):
if isinstance(self.element, QgsProcessingModelAlgorithm.ModelParameter):
if isinstance(self.element, QgsProcessingModelParameter):
if self.model.childAlgorithmsDependOnParameter(self.element.parameterName()):
QMessageBox.warning(None, 'Could not remove input',
'Algorithms depend on the selected input.\n'
@ -240,7 +243,7 @@ class ModelerGraphicItem(QGraphicsItem):
self.model.removeModelParameter(self.element.parameterName())
self.scene.dialog.haschanged = True
self.scene.dialog.repaintModel()
elif isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm):
elif isinstance(self.element, QgsProcessingModelChildAlgorithm):
if not self.model.removeChildAlgorithm(self.element.childId()):
QMessageBox.warning(None, 'Could not remove element',
'Other elements depend on the selected one.\n'
@ -270,11 +273,11 @@ class ModelerGraphicItem(QGraphicsItem):
ModelerGraphicItem.BOX_WIDTH + 2,
ModelerGraphicItem.BOX_HEIGHT + 2)
if isinstance(self.element, QgsProcessingModelAlgorithm.ModelParameter):
if isinstance(self.element, QgsProcessingModelParameter):
color = QColor(238, 242, 131)
stroke = QColor(234, 226, 118)
selected = QColor(116, 113, 68)
elif isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm):
elif isinstance(self.element, QgsProcessingModelChildAlgorithm):
color = QColor(255, 255, 255)
stroke = Qt.gray
selected = QColor(50, 50, 50)
@ -293,7 +296,7 @@ class ModelerGraphicItem(QGraphicsItem):
painter.setFont(font)
painter.setPen(QPen(Qt.black))
text = self.getAdjustedText(self.text)
if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm) and not self.element.isActive():
if isinstance(self.element, QgsProcessingModelChildAlgorithm) and not self.element.isActive():
painter.setPen(QPen(Qt.gray))
text = text + "\n(deactivated)"
fm = QFontMetricsF(font)
@ -302,7 +305,7 @@ class ModelerGraphicItem(QGraphicsItem):
pt = QPointF(-ModelerGraphicItem.BOX_WIDTH / 2 + 25, ModelerGraphicItem.BOX_HEIGHT / 2.0 - h + 1)
painter.drawText(pt, text)
painter.setPen(QPen(Qt.black))
if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm):
if isinstance(self.element, QgsProcessingModelChildAlgorithm):
h = -(fm.height() * 1.2)
h = h - ModelerGraphicItem.BOX_HEIGHT / 2.0 + 5
pt = QPointF(-ModelerGraphicItem.BOX_WIDTH / 2 + 25, h)
@ -337,16 +340,16 @@ class ModelerGraphicItem(QGraphicsItem):
def getLinkPointForParameter(self, paramIndex):
offsetX = 25
if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm) and self.element.parametersCollapsed():
if isinstance(self.element, QgsProcessingModelChildAlgorithm) and self.element.parametersCollapsed():
paramIndex = -1
offsetX = 17
if isinstance(self.element, QgsProcessingModelAlgorithm.ModelParameter):
if isinstance(self.element, QgsProcessingModelParameter):
paramIndex = -1
offsetX = 0
font = QFont('Verdana', 8)
font.setPixelSize(12)
fm = QFontMetricsF(font)
if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm):
if isinstance(self.element, QgsProcessingModelChildAlgorithm):
h = -(fm.height() * 1.2) * (paramIndex + 2) - fm.height() / 2.0 + 8
h = h - ModelerGraphicItem.BOX_HEIGHT / 2.0
else:
@ -354,7 +357,7 @@ class ModelerGraphicItem(QGraphicsItem):
return QPointF(-ModelerGraphicItem.BOX_WIDTH / 2 + offsetX, h)
def getLinkPointForOutput(self, outputIndex):
if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm) and self.element.algorithm().outputDefinitions():
if isinstance(self.element, QgsProcessingModelChildAlgorithm) and self.element.algorithm().outputDefinitions():
outputIndex = (outputIndex if not self.element.outputsCollapsed() else -1)
text = self.getAdjustedText(self.element.algorithm().outputDefinitions()[outputIndex].description())
font = QFont('Verdana', 8)
@ -377,11 +380,11 @@ class ModelerGraphicItem(QGraphicsItem):
self.element.setPosition(self.pos())
# also need to update the model's stored component's position
if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm):
if isinstance(self.element, QgsProcessingModelChildAlgorithm):
self.model.childAlgorithm(self.element.childId()).setPosition(self.pos())
elif isinstance(self.element, QgsProcessingModelAlgorithm.ModelParameter):
elif isinstance(self.element, QgsProcessingModelParameter):
self.model.parameterComponent(self.element.parameterName()).setPosition(self.pos())
elif isinstance(self.element, QgsProcessingModelAlgorithm.ModelOutput):
elif isinstance(self.element, QgsProcessingModelOutput):
self.model.childAlgorithm(self.element.childId()).modelOutput(self.element.name()).setPosition(self.pos())
return value

View File

@ -29,7 +29,8 @@ __revision__ = '$Format:%H$'
import math
from qgis.gui import QgsExpressionLineEdit, QgsProjectionSelectionWidget
from qgis.core import (QgsCoordinateReferenceSystem,
from qgis.core import (QgsSettings,
QgsCoordinateReferenceSystem,
QgsProcessingParameterDefinition,
QgsProcessingParameterBoolean,
QgsProcessingParameterCrs,
@ -48,7 +49,8 @@ from qgis.core import (QgsCoordinateReferenceSystem,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterField,
QgsProcessingParameterFeatureSource)
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtCore import (Qt,
QByteArray)
from qgis.PyQt.QtWidgets import (QDialog,
QVBoxLayout,
QLabel,
@ -62,18 +64,18 @@ from qgis.PyQt.QtWidgets import (QDialog,
class ModelerParameterDefinitionDialog(QDialog):
PARAMETER_NUMBER = 'Number'
PARAMETER_RASTER = 'Raster layer'
PARAMETER_TABLE = 'Table'
PARAMETER_VECTOR = 'Vector layer'
PARAMETER_RASTER = 'Raster Layer'
PARAMETER_TABLE = 'Vector Layer'
PARAMETER_VECTOR = 'Feature Source'
PARAMETER_STRING = 'String'
PARAMETER_EXPRESSION = 'Expression'
PARAMETER_BOOLEAN = 'Boolean'
PARAMETER_TABLE_FIELD = 'Table field'
PARAMETER_TABLE_FIELD = 'Layer Field'
PARAMETER_EXTENT = 'Extent'
PARAMETER_FILE = 'File'
PARAMETER_POINT = 'Point'
PARAMETER_CRS = 'CRS'
PARAMETER_MULTIPLE = 'Multiple input'
PARAMETER_MULTIPLE = 'Multiple Input'
paramTypes = [
PARAMETER_BOOLEAN,
@ -98,6 +100,13 @@ class ModelerParameterDefinitionDialog(QDialog):
QDialog.__init__(self)
self.setModal(True)
self.setupUi()
settings = QgsSettings()
self.restoreGeometry(settings.value("/Processing/modelParametersDefinitionDialogGeometry", QByteArray()))
def closeEvent(self, event):
settings = QgsSettings()
settings.setValue("/Processing/modelParametersDefinitionDialogGeometry", self.saveGeometry())
super(ModelerParameterDefinitionDialog, self).closeEvent(event)
def setupUi(self):
self.setWindowTitle(self.tr('Parameter definition'))

View File

@ -28,7 +28,10 @@ __revision__ = '$Format:%H$'
import webbrowser
from qgis.PyQt.QtCore import Qt, QUrl, QMetaObject
from qgis.PyQt.QtCore import (Qt,
QUrl,
QMetaObject,
QByteArray)
from qgis.PyQt.QtWidgets import (QDialog, QDialogButtonBox, QLabel, QLineEdit,
QFrame, QPushButton, QSizePolicy, QVBoxLayout,
QHBoxLayout, QWidget)
@ -37,14 +40,19 @@ from qgis.core import (QgsProcessingParameterDefinition,
QgsProcessingParameterPoint,
QgsProcessingParameterExtent,
QgsProcessingModelAlgorithm,
QgsProcessingModelOutput,
QgsProcessingModelChildAlgorithm,
QgsProcessingModelChildParameterSource,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterRasterOutput,
QgsProcessingParameterFileOutput,
QgsProcessingParameterFolderOutput,
QgsProcessingOutputDefinition)
QgsProcessingParameterRasterDestination,
QgsProcessingParameterFileDestination,
QgsProcessingParameterFolderDestination,
QgsProcessingOutputDefinition,
QgsSettings)
from qgis.gui import (QgsMessageBar,
QgsScrollArea)
QgsScrollArea,
QgsFilterLineEdit)
from processing.gui.wrappers import WidgetWrapperFactory
from processing.gui.wrappers import InvalidParameterValue
@ -69,6 +77,13 @@ class ModelerParametersDialog(QDialog):
self.childId = algName
self.setupUi()
self.params = None
settings = QgsSettings()
self.restoreGeometry(settings.value("/Processing/modelParametersDialogGeometry", QByteArray()))
def closeEvent(self, event):
settings = QgsSettings()
settings.setValue("/Processing/modelParametersDialogGeometry", self.saveGeometry())
super(ModelerParametersDialog, self).closeEvent(event)
def setupUi(self):
self.labels = {}
@ -150,10 +165,10 @@ class ModelerParametersDialog(QDialog):
for dest in self._alg.destinationParameterDefinitions():
if dest.flags() & QgsProcessingParameterDefinition.FlagHidden:
continue
if isinstance(dest, (QgsProcessingParameterRasterOutput, QgsProcessingParameterFeatureSink,
QgsProcessingParameterFileOutput, QgsProcessingParameterFolderOutput)):
if isinstance(dest, (QgsProcessingParameterRasterDestination, QgsProcessingParameterFeatureSink,
QgsProcessingParameterFileDestination, QgsProcessingParameterFolderDestination)):
label = QLabel(dest.description())
item = QLineEdit()
item = QgsFilterLineEdit()
if hasattr(item, 'setPlaceholderText'):
item.setPlaceholderText(ModelerParametersDialog.ENTER_NAME)
self.verticalLayout.addWidget(label)
@ -232,12 +247,12 @@ class ModelerParametersDialog(QDialog):
[o.typeName() for o in outTypes if issubclass(o, QgsProcessingOutputDefinition)], dataTypes)
def resolveValueDescription(self, value):
if isinstance(value, QgsProcessingModelAlgorithm.ChildParameterSource):
if value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.StaticValue:
if isinstance(value, QgsProcessingModelChildParameterSource):
if value.source() == QgsProcessingModelChildParameterSource.StaticValue:
return value.staticValue()
elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ModelParameter:
elif value.source() == QgsProcessingModelChildParameterSource.ModelParameter:
return self.model.parameterDefinition(value.parameterName()).description()
elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ChildOutput:
elif value.source() == QgsProcessingModelChildParameterSource.ChildOutput:
alg = self.model.childAlgorithm(value.outputChildId())
return self.tr("'{0}' from algorithm '{1}'").format(
alg.algorithm().outputDefinition(value.outputName()).description(), alg.description())
@ -251,14 +266,17 @@ class ModelerParametersDialog(QDialog):
for param in alg.algorithm().parameterDefinitions():
if param.isDestination() or param.flags() & QgsProcessingParameterDefinition.FlagHidden:
continue
value = None
if param.name() in alg.parameterSources():
value = alg.parameterSources()[param.name()]
if isinstance(value, list) and len(value) == 1:
value = value[0]
else:
elif isinstance(value, list) and len(value) == 0:
value = None
if value is None:
value = param.defaultValue()
if isinstance(value, QgsProcessingModelAlgorithm.ChildParameterSource) and value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.StaticValue:
if isinstance(value, QgsProcessingModelChildParameterSource) and value.source() == QgsProcessingModelChildParameterSource.StaticValue:
value = value.staticValue()
self.wrappers[param.name()].setValue(value)
@ -275,7 +293,7 @@ class ModelerParametersDialog(QDialog):
self.dependenciesPanel.setSelectedItems(selected)
def createAlgorithm(self):
alg = QgsProcessingModelAlgorithm.ChildAlgorithm(self._alg.id())
alg = QgsProcessingModelChildAlgorithm(self._alg.id())
if not self.childId:
alg.generateChildId(self.model)
else:
@ -286,7 +304,7 @@ class ModelerParametersDialog(QDialog):
continue
val = self.wrappers[param.name()].value()
if (isinstance(val,
QgsProcessingModelAlgorithm.ChildParameterSource) and val.source() == QgsProcessingModelAlgorithm.ChildParameterSource.StaticValue and not param.checkValueIsAcceptable(
QgsProcessingModelChildParameterSource) and val.source() == QgsProcessingModelChildParameterSource.StaticValue and not param.checkValueIsAcceptable(
val.staticValue())) \
or (val is None and not param.flags() & QgsProcessingParameterDefinition.FlagOptional):
self.bar.pushMessage("Error", "Wrong or missing value for parameter '%s'" % param.description(),
@ -294,19 +312,19 @@ class ModelerParametersDialog(QDialog):
return None
if val is None:
continue
elif isinstance(val, QgsProcessingModelAlgorithm.ChildParameterSource):
elif isinstance(val, QgsProcessingModelChildParameterSource):
alg.addParameterSources(param.name(), [val])
elif isinstance(val, list):
alg.addParameterSources(param.name(), val)
else:
alg.addParameterSources(param.name(), [QgsProcessingModelAlgorithm.ChildParameterSource.fromStaticValue(val)])
alg.addParameterSources(param.name(), [QgsProcessingModelChildParameterSource.fromStaticValue(val)])
outputs = {}
for dest in self._alg.destinationParameterDefinitions():
if not dest.flags() & QgsProcessingParameterDefinition.FlagHidden:
name = str(self.valueItems[dest.name()].text())
if name.strip() != '' and name != ModelerParametersDialog.ENTER_NAME:
output = QgsProcessingModelAlgorithm.ModelOutput(name, name)
output = QgsProcessingModelOutput(name, name)
output.setChildId(alg.childId())
output.setChildOutputName(dest.name())
outputs[name] = output

View File

@ -29,7 +29,7 @@ __revision__ = '$Format:%H$'
from qgis.PyQt.QtCore import QPointF, Qt
from qgis.PyQt.QtWidgets import QGraphicsItem, QGraphicsScene
from qgis.core import (QgsProcessingParameterDefinition,
QgsProcessingModelAlgorithm,
QgsProcessingModelChildParameterSource,
QgsExpression)
from processing.modeler.ModelerGraphicItem import ModelerGraphicItem
from processing.modeler.ModelerArrowItem import ModelerArrowItem
@ -69,17 +69,17 @@ class ModelerScene(QGraphicsScene):
if isinstance(value, list):
for v in value:
items.extend(self.getItemsFromParamValue(v, child_id, context))
elif isinstance(value, QgsProcessingModelAlgorithm.ChildParameterSource):
if value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ModelParameter:
elif isinstance(value, QgsProcessingModelChildParameterSource):
if value.source() == QgsProcessingModelChildParameterSource.ModelParameter:
items.append((self.paramItems[value.parameterName()], 0))
elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.ChildOutput:
elif value.source() == QgsProcessingModelChildParameterSource.ChildOutput:
outputs = self.model.childAlgorithm(value.outputChildId()).algorithm().outputDefinitions()
for i, out in enumerate(outputs):
if out.name() == value.outputName():
break
if value.outputChildId() in self.algItems:
items.append((self.algItems[value.outputChildId()], i))
elif value.source() == QgsProcessingModelAlgorithm.ChildParameterSource.Expression:
elif value.source() == QgsProcessingModelChildParameterSource.Expression:
variables = self.model.variablesForChildAlgorithm(child_id, context)
exp = QgsExpression(value.expression())
for v in exp.referencedVariables():

View File

@ -28,15 +28,12 @@ __revision__ = '$Format:%H$'
from qgis.testing import start_app, unittest
from qgis.core import (QgsProcessingModelAlgorithm,
QgsProcessingModelParameter,
QgsProcessingParameterString,
QgsProcessingParameterNumber,
QgsProcessingParameterField,
QgsProcessingParameterFile)
from processing.modeler.ModelerParametersDialog import (ModelerParametersDialog)
from processing.core.parameters import (ParameterFile,
ParameterNumber,
ParameterString,
ParameterTableField)
start_app()
@ -47,19 +44,19 @@ class ModelerTest(unittest.TestCase):
m = QgsProcessingModelAlgorithm()
string_param_1 = QgsProcessingModelAlgorithm.ModelParameter('string')
string_param_1 = QgsProcessingModelParameter('string')
m.addModelParameter(QgsProcessingParameterString('string'), string_param_1)
string_param_2 = QgsProcessingModelAlgorithm.ModelParameter('string2')
string_param_2 = QgsProcessingModelParameter('string2')
m.addModelParameter(QgsProcessingParameterString('string2'), string_param_2)
num_param = QgsProcessingModelAlgorithm.ModelParameter('number')
num_param = QgsProcessingModelParameter('number')
m.addModelParameter(QgsProcessingParameterNumber('number'), num_param)
table_field_param = QgsProcessingModelAlgorithm.ModelParameter('field')
table_field_param = QgsProcessingModelParameter('field')
m.addModelParameter(QgsProcessingParameterField('field'), table_field_param)
file_param = QgsProcessingModelAlgorithm.ModelParameter('file')
file_param = QgsProcessingModelParameter('file')
m.addModelParameter(QgsProcessingParameterFile('file'), file_param)
dlg = ModelerParametersDialog(m, m)

View File

@ -4,7 +4,7 @@
#inputs
##INPUT_LAYER=vector
##OUTPUT_LAYER=vectorOut
##OUTPUT_LAYER=vectorDestination
#outputs

View File

@ -4,7 +4,7 @@
#inputs
##INPUT_LAYER=vector
##OUTPUT_LAYER=vectorOut
##OUTPUT_LAYER=vectorDestination
#outputs

View File

@ -38,8 +38,8 @@ except ImportError:
from qgis.core import (QgsApplication,
QgsProcessingAlgorithm,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterVectorOutput,
QgsProcessingParameterRasterOutput,
QgsProcessingParameterVectorDestination,
QgsProcessingParameterRasterDestination,
QgsProcessingOutputLayerDefinition,
QgsProject)
from processing.core.Processing import Processing
@ -96,7 +96,7 @@ def runAndLoadResults(algOrName, parameters, feedback=None, context=None):
if not param.name() in parameters:
continue
if isinstance(param, (QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorOutput, QgsProcessingParameterRasterOutput)):
if isinstance(param, (QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorDestination, QgsProcessingParameterRasterDestination)):
p = parameters[param.name()]
if not isinstance(p, QgsProcessingOutputLayerDefinition):
parameters[param.name()] = QgsProcessingOutputLayerDefinition(p, QgsProject.instance())

View File

@ -96,12 +96,17 @@ SET(QGIS_CORE_SRCS
processing/qgsnativealgorithms.cpp
processing/qgsprocessingalgorithm.cpp
processing/qgsprocessingalgrunnertask.cpp
processing/qgsprocessingmodelalgorithm.cpp
processing/qgsprocessingoutputs.cpp
processing/qgsprocessingparameters.cpp
processing/qgsprocessingprovider.cpp
processing/qgsprocessingregistry.cpp
processing/qgsprocessingutils.cpp
processing/models/qgsprocessingmodelalgorithm.cpp
processing/models/qgsprocessingmodelchildalgorithm.cpp
processing/models/qgsprocessingmodelchildparametersource.cpp
processing/models/qgsprocessingmodelcomponent.cpp
processing/models/qgsprocessingmodelparameter.cpp
processing/models/qgsprocessingmodeloutput.cpp
providers/memory/qgsmemoryfeatureiterator.cpp
providers/memory/qgsmemoryprovider.cpp
@ -922,12 +927,18 @@ SET(QGIS_CORE_HDRS
metadata/qgslayermetadatavalidator.h
processing/qgsnativealgorithms.h
processing/qgsprocessing.h
processing/qgsprocessingalgorithm.h
processing/qgsprocessingcontext.h
processing/qgsprocessingmodelalgorithm.h
processing/qgsprocessingoutputs.h
processing/qgsprocessingparameters.h
processing/qgsprocessingutils.h
processing/models/qgsprocessingmodelalgorithm.h
processing/models/qgsprocessingmodelchildalgorithm.h
processing/models/qgsprocessingmodelchildparametersource.h
processing/models/qgsprocessingmodelcomponent.h
processing/models/qgsprocessingmodeloutput.h
processing/models/qgsprocessingmodelparameter.h
providers/memory/qgsmemoryfeatureiterator.h
providers/memory/qgsmemoryproviderutils.h
@ -1072,6 +1083,7 @@ INCLUDE_DIRECTORIES(
metadata
pal
processing
processing/models
providers
providers/memory
raster

View File

@ -26,288 +26,6 @@
///@cond NOT_STABLE
QgsProcessingModelAlgorithm::ChildAlgorithm::ChildAlgorithm( const QString &algorithmId )
: mAlgorithmId( algorithmId )
{
}
const QgsProcessingAlgorithm *QgsProcessingModelAlgorithm::ChildAlgorithm::algorithm() const
{
return QgsApplication::processingRegistry()->algorithmById( mAlgorithmId );
}
QString QgsProcessingModelAlgorithm::Component::description() const
{
return mDescription;
}
void QgsProcessingModelAlgorithm::Component::setDescription( const QString &description )
{
mDescription = description;
}
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources> QgsProcessingModelAlgorithm::ChildAlgorithm::parameterSources() const
{
return mParams;
}
void QgsProcessingModelAlgorithm::ChildAlgorithm::setParameterSources( const QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSources > &params )
{
mParams = params;
}
void QgsProcessingModelAlgorithm::ChildAlgorithm::addParameterSources( const QString &name, const ChildParameterSources &source )
{
mParams.insert( name, source );
}
bool QgsProcessingModelAlgorithm::ChildAlgorithm::isActive() const
{
return mActive;
}
void QgsProcessingModelAlgorithm::ChildAlgorithm::setActive( bool active )
{
mActive = active;
}
QPointF QgsProcessingModelAlgorithm::Component::position() const
{
return mPosition;
}
void QgsProcessingModelAlgorithm::Component::setPosition( const QPointF &position )
{
mPosition = position;
}
QgsProcessingModelAlgorithm::Component::Component( const QString &description )
: mDescription( description )
{}
void QgsProcessingModelAlgorithm::Component::saveCommonProperties( QVariantMap &map ) const
{
map.insert( QStringLiteral( "component_pos_x" ), mPosition.x() );
map.insert( QStringLiteral( "component_pos_y" ), mPosition.y() );
map.insert( QStringLiteral( "component_description" ), mDescription );
}
void QgsProcessingModelAlgorithm::Component::restoreCommonProperties( const QVariantMap &map )
{
QPointF pos;
pos.setX( map.value( QStringLiteral( "component_pos_x" ) ).toDouble() );
pos.setY( map.value( QStringLiteral( "component_pos_y" ) ).toDouble() );
mPosition = pos;
mDescription = map.value( QStringLiteral( "component_description" ) ).toString();
}
QStringList QgsProcessingModelAlgorithm::ChildAlgorithm::dependencies() const
{
return mDependencies;
}
void QgsProcessingModelAlgorithm::ChildAlgorithm::setDependencies( const QStringList &dependencies )
{
mDependencies = dependencies;
}
bool QgsProcessingModelAlgorithm::ChildAlgorithm::outputsCollapsed() const
{
return mOutputsCollapsed;
}
void QgsProcessingModelAlgorithm::ChildAlgorithm::setOutputsCollapsed( bool outputsCollapsed )
{
mOutputsCollapsed = outputsCollapsed;
}
QMap<QString, QgsProcessingModelAlgorithm::ModelOutput> QgsProcessingModelAlgorithm::ChildAlgorithm::modelOutputs() const
{
return mModelOutputs;
}
QgsProcessingModelAlgorithm::ModelOutput &QgsProcessingModelAlgorithm::ChildAlgorithm::modelOutput( const QString &name )
{
return mModelOutputs[ name ];
}
void QgsProcessingModelAlgorithm::ChildAlgorithm::setModelOutputs( const QMap<QString, QgsProcessingModelAlgorithm::ModelOutput> &modelOutputs )
{
mModelOutputs = modelOutputs;
QMap<QString, QgsProcessingModelAlgorithm::ModelOutput>::iterator outputIt = mModelOutputs.begin();
for ( ; outputIt != mModelOutputs.end(); ++outputIt )
{
// make sure values are consistent
outputIt->setName( outputIt.key() );
outputIt->setChildId( mId );
}
}
QVariant QgsProcessingModelAlgorithm::ChildAlgorithm::toVariant() const
{
QVariantMap map;
map.insert( QStringLiteral( "id" ), mId );
map.insert( QStringLiteral( "alg_id" ), mAlgorithmId );
map.insert( QStringLiteral( "active" ), mActive );
map.insert( QStringLiteral( "dependencies" ), mDependencies );
map.insert( QStringLiteral( "parameters_collapsed" ), mParametersCollapsed );
map.insert( QStringLiteral( "outputs_collapsed" ), mOutputsCollapsed );
saveCommonProperties( map );
QVariantMap paramMap;
QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSources >::const_iterator paramIt = mParams.constBegin();
for ( ; paramIt != mParams.constEnd(); ++paramIt )
{
QVariantList sources;
Q_FOREACH ( const ChildParameterSource &source, paramIt.value() )
{
sources << source.toVariant();
}
paramMap.insert( paramIt.key(), sources );
}
map.insert( "params", paramMap );
QVariantMap outputMap;
QMap< QString, QgsProcessingModelAlgorithm::ModelOutput >::const_iterator outputIt = mModelOutputs.constBegin();
for ( ; outputIt != mModelOutputs.constEnd(); ++outputIt )
{
outputMap.insert( outputIt.key(), outputIt.value().toVariant() );
}
map.insert( "outputs", outputMap );
return map;
}
bool QgsProcessingModelAlgorithm::ChildAlgorithm::loadVariant( const QVariant &child )
{
QVariantMap map = child.toMap();
mId = map.value( QStringLiteral( "id" ) ).toString();
mAlgorithmId = map.value( QStringLiteral( "alg_id" ) ).toString();
mActive = map.value( QStringLiteral( "active" ) ).toBool();
mDependencies = map.value( QStringLiteral( "dependencies" ) ).toStringList();
mParametersCollapsed = map.value( QStringLiteral( "parameters_collapsed" ) ).toBool();
mOutputsCollapsed = map.value( QStringLiteral( "outputs_collapsed" ) ).toBool();
restoreCommonProperties( map );
mParams.clear();
QVariantMap paramMap = map.value( QStringLiteral( "params" ) ).toMap();
QVariantMap::const_iterator paramIt = paramMap.constBegin();
for ( ; paramIt != paramMap.constEnd(); ++paramIt )
{
ChildParameterSources sources;
Q_FOREACH ( const QVariant &sourceVar, paramIt->toList() )
{
ChildParameterSource param;
if ( !param.loadVariant( sourceVar.toMap() ) )
return false;
sources << param;
}
mParams.insert( paramIt.key(), sources );
}
mModelOutputs.clear();
QVariantMap outputMap = map.value( QStringLiteral( "outputs" ) ).toMap();
QVariantMap::const_iterator outputIt = outputMap.constBegin();
for ( ; outputIt != outputMap.constEnd(); ++outputIt )
{
ModelOutput output;
if ( !output.loadVariant( outputIt.value().toMap() ) )
return false;
mModelOutputs.insert( outputIt.key(), output );
}
return true;
}
QString QgsProcessingModelAlgorithm::ChildAlgorithm::asPythonCode() const
{
QStringList lines;
if ( !algorithm() )
return QString();
QStringList paramParts;
QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSources >::const_iterator paramIt = mParams.constBegin();
for ( ; paramIt != mParams.constEnd(); ++paramIt )
{
QStringList sourceParts;
Q_FOREACH ( const ChildParameterSource &source, paramIt.value() )
{
QString part = source.asPythonCode();
if ( !part.isEmpty() )
sourceParts << QStringLiteral( "'%1':%2" ).arg( paramIt.key(), part );
}
if ( sourceParts.count() == 1 )
paramParts << sourceParts.at( 0 );
else
paramParts << QStringLiteral( "[%1]" ).arg( paramParts.join( ',' ) );
}
lines << QStringLiteral( "outputs['%1']=processing.run('%2', {%3}, context=context, feedback=feedback)" ).arg( mId, mAlgorithmId, paramParts.join( ',' ) );
QMap< QString, QgsProcessingModelAlgorithm::ModelOutput >::const_iterator outputIt = mModelOutputs.constBegin();
for ( ; outputIt != mModelOutputs.constEnd(); ++outputIt )
{
lines << QStringLiteral( "results['%1']=outputs['%2']['%3']" ).arg( outputIt.key(), mId, outputIt.value().childOutputName() );
}
return lines.join( '\n' );
}
bool QgsProcessingModelAlgorithm::ChildAlgorithm::parametersCollapsed() const
{
return mParametersCollapsed;
}
void QgsProcessingModelAlgorithm::ChildAlgorithm::setParametersCollapsed( bool parametersCollapsed )
{
mParametersCollapsed = parametersCollapsed;
}
QString QgsProcessingModelAlgorithm::ChildAlgorithm::childId() const
{
return mId;
}
void QgsProcessingModelAlgorithm::ChildAlgorithm::setChildId( const QString &id )
{
mId = id;
}
void QgsProcessingModelAlgorithm::ChildAlgorithm::generateChildId( const QgsProcessingModelAlgorithm &model )
{
int i = 1;
QString id;
while ( true )
{
id = QStringLiteral( "%1_%2" ).arg( mAlgorithmId ).arg( i );
if ( !model.childAlgorithms().contains( id ) )
break;
i++;
}
mId = id;
}
QString QgsProcessingModelAlgorithm::ChildAlgorithm::algorithmId() const
{
return mAlgorithmId;
}
void QgsProcessingModelAlgorithm::ChildAlgorithm::setAlgorithmId( const QString &algorithmId )
{
mAlgorithmId = algorithmId;
}
//
// QgsProcessingModelAlgorithm
//
QgsProcessingModelAlgorithm::QgsProcessingModelAlgorithm( const QString &name, const QString &group )
: QgsProcessingAlgorithm()
, mModelName( name.isEmpty() ? QObject::tr( "model" ) : name )
@ -351,7 +69,7 @@ QString QgsProcessingModelAlgorithm::helpUrl() const
return QgsProcessingUtils::formatHelpMapAsHtml( mHelpContent, this );
}
QVariantMap QgsProcessingModelAlgorithm::parametersForChildAlgorithm( const ChildAlgorithm &child, const QVariantMap &modelParameters, const QVariantMap &results, const QgsExpressionContext &expressionContext ) const
QVariantMap QgsProcessingModelAlgorithm::parametersForChildAlgorithm( const QgsProcessingModelChildAlgorithm &child, const QVariantMap &modelParameters, const QVariantMap &results, const QgsExpressionContext &expressionContext ) const
{
QVariantMap childParams;
Q_FOREACH ( const QgsProcessingParameterDefinition *def, child.algorithm()->parameterDefinitions() )
@ -364,29 +82,29 @@ QVariantMap QgsProcessingModelAlgorithm::parametersForChildAlgorithm( const Chil
if ( !child.parameterSources().contains( def->name() ) )
continue; // use default value
ChildParameterSources paramSources = child.parameterSources().value( def->name() );
QgsProcessingModelChildParameterSources paramSources = child.parameterSources().value( def->name() );
QVariantList paramParts;
Q_FOREACH ( const ChildParameterSource &source, paramSources )
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramSources )
{
switch ( source.source() )
{
case ChildParameterSource::StaticValue:
case QgsProcessingModelChildParameterSource::StaticValue:
paramParts << source.staticValue();
break;
case ChildParameterSource::ModelParameter:
case QgsProcessingModelChildParameterSource::ModelParameter:
paramParts << modelParameters.value( source.parameterName() );
break;
case ChildParameterSource::ChildOutput:
case QgsProcessingModelChildParameterSource::ChildOutput:
{
QVariantMap linkedChildResults = results.value( source.outputChildId() ).toMap();
paramParts << linkedChildResults.value( source.outputName() );
break;
}
case ChildParameterSource::Expression:
case QgsProcessingModelChildParameterSource::Expression:
{
QgsExpression exp( source.expression() );
paramParts << exp.evaluate( &expressionContext );
@ -406,8 +124,8 @@ QVariantMap QgsProcessingModelAlgorithm::parametersForChildAlgorithm( const Chil
// is destination linked to one of the final outputs from this model?
bool isFinalOutput = false;
QMap<QString, QgsProcessingModelAlgorithm::ModelOutput> outputs = child.modelOutputs();
QMap<QString, QgsProcessingModelAlgorithm::ModelOutput>::const_iterator outputIt = outputs.constBegin();
QMap<QString, QgsProcessingModelOutput> outputs = child.modelOutputs();
QMap<QString, QgsProcessingModelOutput>::const_iterator outputIt = outputs.constBegin();
for ( ; outputIt != outputs.constEnd(); ++outputIt )
{
if ( outputIt->childOutputName() == destParam->name() )
@ -454,20 +172,20 @@ QVariantMap QgsProcessingModelAlgorithm::parametersForChildAlgorithm( const Chil
bool QgsProcessingModelAlgorithm::childOutputIsRequired( const QString &childId, const QString &outputName ) const
{
// look through all child algs
QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt )
{
if ( childIt->childId() == childId || !childIt->isActive() )
continue;
// look through all sources for child
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources> candidateChildParams = childIt->parameterSources();
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources>::const_iterator childParamIt = candidateChildParams.constBegin();
QMap<QString, QgsProcessingModelChildParameterSources> candidateChildParams = childIt->parameterSources();
QMap<QString, QgsProcessingModelChildParameterSources>::const_iterator childParamIt = candidateChildParams.constBegin();
for ( ; childParamIt != candidateChildParams.constEnd(); ++childParamIt )
{
Q_FOREACH ( const ChildParameterSource &source, childParamIt.value() )
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, childParamIt.value() )
{
if ( source.source() == ChildParameterSource::ChildOutput
if ( source.source() == QgsProcessingModelChildParameterSource::ChildOutput
&& source.outputChildId() == childId
&& source.outputName() == outputName )
{
@ -482,7 +200,7 @@ bool QgsProcessingModelAlgorithm::childOutputIsRequired( const QString &childId,
QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
QSet< QString > toExecute;
QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt )
{
if ( childIt->isActive() && childIt->algorithm() )
@ -522,7 +240,7 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa
executedAlg = true;
feedback->pushDebugInfo( QObject::tr( "Prepare algorithm: %1" ).arg( childId ) );
const ChildAlgorithm &child = mChildAlgorithms[ childId ];
const QgsProcessingModelChildAlgorithm &child = mChildAlgorithms[ childId ];
QgsExpressionContext expContext = baseContext;
expContext << QgsExpressionContextUtils::processingAlgorithmScope( child.algorithm(), parameters, context )
@ -550,8 +268,8 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa
// look through child alg's outputs to determine whether any of these should be copied
// to the final model outputs
QMap<QString, QgsProcessingModelAlgorithm::ModelOutput> outputs = child.modelOutputs();
QMap<QString, QgsProcessingModelAlgorithm::ModelOutput>::const_iterator outputIt = outputs.constBegin();
QMap<QString, QgsProcessingModelOutput> outputs = child.modelOutputs();
QMap<QString, QgsProcessingModelOutput>::const_iterator outputIt = outputs.constBegin();
for ( ; outputIt != outputs.constEnd(); ++outputIt )
{
finalResults.insert( childId + ':' + outputIt->name(), results.value( outputIt->childOutputName() ) );
@ -582,7 +300,7 @@ QString QgsProcessingModelAlgorithm::asPythonCode() const
QStringList lines;
lines << QStringLiteral( "##%1=name" ).arg( name() );
QMap< QString, ModelParameter >::const_iterator paramIt = mParameterComponents.constBegin();
QMap< QString, QgsProcessingModelParameter >::const_iterator paramIt = mParameterComponents.constBegin();
for ( ; paramIt != mParameterComponents.constEnd(); ++paramIt )
{
QString name = paramIt.value().parameterName();
@ -600,15 +318,15 @@ QString QgsProcessingModelAlgorithm::asPythonCode() const
return n;
};
QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt )
{
if ( !childIt->isActive() || !childIt->algorithm() )
continue;
// look through all outputs for child
QMap<QString, QgsProcessingModelAlgorithm::ModelOutput> outputs = childIt->modelOutputs();
QMap<QString, QgsProcessingModelAlgorithm::ModelOutput>::const_iterator outputIt = outputs.constBegin();
QMap<QString, QgsProcessingModelOutput> outputs = childIt->modelOutputs();
QMap<QString, QgsProcessingModelOutput>::const_iterator outputIt = outputs.constBegin();
for ( ; outputIt != outputs.constEnd(); ++outputIt )
{
const QgsProcessingOutputDefinition *output = childIt->algorithm()->outputDefinition( outputIt->childOutputName() );
@ -651,7 +369,7 @@ QString QgsProcessingModelAlgorithm::asPythonCode() const
executedAlg = true;
const ChildAlgorithm &child = mChildAlgorithms[ childId ];
const QgsProcessingModelChildAlgorithm &child = mChildAlgorithms[ childId ];
lines << child.asPythonCode();
executed.insert( childId );
@ -674,30 +392,30 @@ QMap<QString, QgsProcessingModelAlgorithm::VariableDefinition> QgsProcessingMode
};
// "static"/single value sources
ChildParameterSources sources = availableSourcesForChild( childId, QStringList() << QgsProcessingParameterNumber::typeName()
<< QgsProcessingParameterBoolean::typeName()
<< QgsProcessingParameterExpression::typeName()
<< QgsProcessingParameterField::typeName()
<< QgsProcessingParameterString::typeName(),
QStringList() << QgsProcessingOutputNumber::typeName()
<< QgsProcessingOutputString::typeName() );
Q_FOREACH ( const ChildParameterSource &source, sources )
QgsProcessingModelChildParameterSources sources = availableSourcesForChild( childId, QStringList() << QgsProcessingParameterNumber::typeName()
<< QgsProcessingParameterBoolean::typeName()
<< QgsProcessingParameterExpression::typeName()
<< QgsProcessingParameterField::typeName()
<< QgsProcessingParameterString::typeName(),
QStringList() << QgsProcessingOutputNumber::typeName()
<< QgsProcessingOutputString::typeName() );
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, sources )
{
QString name;
QVariant value;
QString description;
switch ( source.source() )
{
case ChildParameterSource::ModelParameter:
case QgsProcessingModelChildParameterSource::ModelParameter:
{
name = source.parameterName();
value = modelParameters.value( source.parameterName() );
description = parameterDefinition( source.parameterName() )->description();
break;
}
case ChildParameterSource::ChildOutput:
case QgsProcessingModelChildParameterSource::ChildOutput:
{
const ChildAlgorithm &child = mChildAlgorithms.value( source.outputChildId() );
const QgsProcessingModelChildAlgorithm &child = mChildAlgorithms.value( source.outputChildId() );
name = QStringLiteral( "%1_%2" ).arg( child.description().isEmpty() ?
source.outputChildId() : child.description(), source.outputName() );
if ( const QgsProcessingAlgorithm *alg = child.algorithm() )
@ -709,8 +427,8 @@ QMap<QString, QgsProcessingModelAlgorithm::VariableDefinition> QgsProcessingMode
break;
}
case ChildParameterSource::Expression:
case ChildParameterSource::StaticValue:
case QgsProcessingModelChildParameterSource::Expression:
case QgsProcessingModelChildParameterSource::StaticValue:
continue;
};
variables.insert( safeName( name ), VariableDefinition( value, source, description ) );
@ -723,7 +441,7 @@ QMap<QString, QgsProcessingModelAlgorithm::VariableDefinition> QgsProcessingMode
QStringList() << QgsProcessingOutputVectorLayer::typeName()
<< QgsProcessingOutputRasterLayer::typeName() );
Q_FOREACH ( const ChildParameterSource &source, sources )
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, sources )
{
QString name;
QVariant value;
@ -731,16 +449,16 @@ QMap<QString, QgsProcessingModelAlgorithm::VariableDefinition> QgsProcessingMode
switch ( source.source() )
{
case ChildParameterSource::ModelParameter:
case QgsProcessingModelChildParameterSource::ModelParameter:
{
name = source.parameterName();
value = modelParameters.value( source.parameterName() );
description = parameterDefinition( source.parameterName() )->description();
break;
}
case ChildParameterSource::ChildOutput:
case QgsProcessingModelChildParameterSource::ChildOutput:
{
const ChildAlgorithm &child = mChildAlgorithms.value( source.outputChildId() );
const QgsProcessingModelChildAlgorithm &child = mChildAlgorithms.value( source.outputChildId() );
name = QStringLiteral( "%1_%2" ).arg( child.description().isEmpty() ?
source.outputChildId() : child.description(), source.outputName() );
value = results.value( source.outputChildId() ).toMap().value( source.outputName() );
@ -752,8 +470,8 @@ QMap<QString, QgsProcessingModelAlgorithm::VariableDefinition> QgsProcessingMode
break;
}
case ChildParameterSource::Expression:
case ChildParameterSource::StaticValue:
case QgsProcessingModelChildParameterSource::Expression:
case QgsProcessingModelChildParameterSource::StaticValue:
continue;
};
@ -772,7 +490,7 @@ QMap<QString, QgsProcessingModelAlgorithm::VariableDefinition> QgsProcessingMode
sources = availableSourcesForChild( childId, QStringList()
<< QgsProcessingParameterFeatureSource::typeName() );
Q_FOREACH ( const ChildParameterSource &source, sources )
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, sources )
{
QString name;
QVariant value;
@ -780,16 +498,16 @@ QMap<QString, QgsProcessingModelAlgorithm::VariableDefinition> QgsProcessingMode
switch ( source.source() )
{
case ChildParameterSource::ModelParameter:
case QgsProcessingModelChildParameterSource::ModelParameter:
{
name = source.parameterName();
value = modelParameters.value( source.parameterName() );
description = parameterDefinition( source.parameterName() )->description();
break;
}
case ChildParameterSource::ChildOutput:
case QgsProcessingModelChildParameterSource::ChildOutput:
{
const ChildAlgorithm &child = mChildAlgorithms.value( source.outputChildId() );
const QgsProcessingModelChildAlgorithm &child = mChildAlgorithms.value( source.outputChildId() );
name = QStringLiteral( "%1_%2" ).arg( child.description().isEmpty() ?
source.outputChildId() : child.description(), source.outputName() );
value = results.value( source.outputChildId() ).toMap().value( source.outputName() );
@ -801,8 +519,8 @@ QMap<QString, QgsProcessingModelAlgorithm::VariableDefinition> QgsProcessingMode
break;
}
case ChildParameterSource::Expression:
case ChildParameterSource::StaticValue:
case QgsProcessingModelChildParameterSource::Expression:
case QgsProcessingModelChildParameterSource::StaticValue:
continue;
};
@ -844,12 +562,12 @@ QgsExpressionContextScope *QgsProcessingModelAlgorithm::createExpressionContextS
return scope.release();
}
QgsProcessingModelAlgorithm::ChildParameterSources QgsProcessingModelAlgorithm::availableSourcesForChild( const QString &childId, const QStringList &parameterTypes, const QStringList &outputTypes, const QList<int> dataTypes ) const
QgsProcessingModelChildParameterSources QgsProcessingModelAlgorithm::availableSourcesForChild( const QString &childId, const QStringList &parameterTypes, const QStringList &outputTypes, const QList<int> dataTypes ) const
{
ChildParameterSources sources;
QgsProcessingModelChildParameterSources sources;
// first look through model parameters
QMap< QString, ModelParameter >::const_iterator paramIt = mParameterComponents.constBegin();
QMap< QString, QgsProcessingModelParameter >::const_iterator paramIt = mParameterComponents.constBegin();
for ( ; paramIt != mParameterComponents.constEnd(); ++paramIt )
{
const QgsProcessingParameterDefinition *def = parameterDefinition( paramIt->parameterName() );
@ -874,7 +592,7 @@ QgsProcessingModelAlgorithm::ChildParameterSources QgsProcessingModelAlgorithm::
bool ok = !sourceDef->dataTypes().isEmpty();
Q_FOREACH ( int type, sourceDef->dataTypes() )
{
if ( dataTypes.contains( type ) || type == QgsProcessingParameterDefinition::TypeAny )
if ( dataTypes.contains( type ) || type == QgsProcessing::TypeAny )
{
ok = true;
break;
@ -884,7 +602,7 @@ QgsProcessingModelAlgorithm::ChildParameterSources QgsProcessingModelAlgorithm::
continue;
}
}
sources << ChildParameterSource::fromModelParameter( paramIt->parameterName() );
sources << QgsProcessingModelChildParameterSource::fromModelParameter( paramIt->parameterName() );
}
}
@ -895,7 +613,7 @@ QgsProcessingModelAlgorithm::ChildParameterSources QgsProcessingModelAlgorithm::
dependents << childId;
}
QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt )
{
if ( dependents.contains( childIt->childId() ) )
@ -914,13 +632,13 @@ QgsProcessingModelAlgorithm::ChildParameterSources QgsProcessingModelAlgorithm::
if ( out->type() == QgsProcessingOutputVectorLayer::typeName() )
{
const QgsProcessingOutputVectorLayer *vectorOut = static_cast< const QgsProcessingOutputVectorLayer *>( out );
if ( !( dataTypes.contains( vectorOut->dataType() ) || vectorOut->dataType() == QgsProcessingParameterDefinition::TypeAny ) )
if ( !( dataTypes.contains( vectorOut->dataType() ) || vectorOut->dataType() == QgsProcessing::TypeAny ) )
{
continue;
}
}
}
sources << ChildParameterSource::fromChildOutput( childIt->childId(), out->name() );
sources << QgsProcessingModelChildParameterSource::fromChildOutput( childIt->childId(), out->name() );
}
}
}
@ -948,26 +666,26 @@ void QgsProcessingModelAlgorithm::setGroup( const QString &group )
mModelGroup = group;
}
QMap<QString, QgsProcessingModelAlgorithm::ChildAlgorithm> QgsProcessingModelAlgorithm::childAlgorithms() const
QMap<QString, QgsProcessingModelChildAlgorithm> QgsProcessingModelAlgorithm::childAlgorithms() const
{
return mChildAlgorithms;
}
void QgsProcessingModelAlgorithm::setParameterComponents( const QMap<QString, QgsProcessingModelAlgorithm::ModelParameter> &parameterComponents )
void QgsProcessingModelAlgorithm::setParameterComponents( const QMap<QString, QgsProcessingModelParameter> &parameterComponents )
{
mParameterComponents = parameterComponents;
}
void QgsProcessingModelAlgorithm::setParameterComponent( const QgsProcessingModelAlgorithm::ModelParameter &component )
void QgsProcessingModelAlgorithm::setParameterComponent( const QgsProcessingModelParameter &component )
{
mParameterComponents.insert( component.parameterName(), component );
}
QgsProcessingModelAlgorithm::ModelParameter &QgsProcessingModelAlgorithm::parameterComponent( const QString &name )
QgsProcessingModelParameter &QgsProcessingModelAlgorithm::parameterComponent( const QString &name )
{
if ( !mParameterComponents.contains( name ) )
{
QgsProcessingModelAlgorithm::ModelParameter &component = mParameterComponents[ name ];
QgsProcessingModelParameter &component = mParameterComponents[ name ];
component.setParameterName( name );
return component;
}
@ -992,11 +710,11 @@ void QgsProcessingModelAlgorithm::updateDestinationParameters()
mOutputs.clear();
// rebuild
QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt )
{
QMap<QString, QgsProcessingModelAlgorithm::ModelOutput> outputs = childIt->modelOutputs();
QMap<QString, QgsProcessingModelAlgorithm::ModelOutput>::const_iterator outputIt = outputs.constBegin();
QMap<QString, QgsProcessingModelOutput> outputs = childIt->modelOutputs();
QMap<QString, QgsProcessingModelOutput>::const_iterator outputIt = outputs.constBegin();
for ( ; outputIt != outputs.constEnd(); ++outputIt )
{
if ( !childIt->isActive() || !childIt->algorithm() )
@ -1032,7 +750,7 @@ QVariant QgsProcessingModelAlgorithm::toVariant() const
map.insert( QStringLiteral( "help" ), mHelpContent );
QVariantMap childMap;
QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt )
{
childMap.insert( childIt.key(), childIt.value().toVariant() );
@ -1040,7 +758,7 @@ QVariant QgsProcessingModelAlgorithm::toVariant() const
map.insert( "children", childMap );
QVariantMap paramMap;
QMap< QString, ModelParameter >::const_iterator paramIt = mParameterComponents.constBegin();
QMap< QString, QgsProcessingModelParameter >::const_iterator paramIt = mParameterComponents.constBegin();
for ( ; paramIt != mParameterComponents.constEnd(); ++paramIt )
{
paramMap.insert( paramIt.key(), paramIt.value().toVariant() );
@ -1070,7 +788,7 @@ bool QgsProcessingModelAlgorithm::loadVariant( const QVariant &model )
QVariantMap::const_iterator childIt = childMap.constBegin();
for ( ; childIt != childMap.constEnd(); ++childIt )
{
ChildAlgorithm child;
QgsProcessingModelChildAlgorithm child;
if ( !child.loadVariant( childIt.value() ) )
return false;
@ -1082,7 +800,7 @@ bool QgsProcessingModelAlgorithm::loadVariant( const QVariant &model )
QVariantMap::const_iterator paramIt = paramMap.constBegin();
for ( ; paramIt != paramMap.constEnd(); ++paramIt )
{
ModelParameter param;
QgsProcessingModelParameter param;
if ( !param.loadVariant( paramIt.value().toMap() ) )
return false;
@ -1141,19 +859,19 @@ bool QgsProcessingModelAlgorithm::fromFile( const QString &path )
return loadVariant( props );
}
void QgsProcessingModelAlgorithm::setChildAlgorithms( const QMap<QString, ChildAlgorithm> &childAlgorithms )
void QgsProcessingModelAlgorithm::setChildAlgorithms( const QMap<QString, QgsProcessingModelChildAlgorithm> &childAlgorithms )
{
mChildAlgorithms = childAlgorithms;
updateDestinationParameters();
}
void QgsProcessingModelAlgorithm::setChildAlgorithm( const QgsProcessingModelAlgorithm::ChildAlgorithm &algorithm )
void QgsProcessingModelAlgorithm::setChildAlgorithm( const QgsProcessingModelChildAlgorithm &algorithm )
{
mChildAlgorithms.insert( algorithm.childId(), algorithm );
updateDestinationParameters();
}
QString QgsProcessingModelAlgorithm::addChildAlgorithm( ChildAlgorithm &algorithm )
QString QgsProcessingModelAlgorithm::addChildAlgorithm( QgsProcessingModelChildAlgorithm &algorithm )
{
if ( algorithm.childId().isEmpty() || mChildAlgorithms.contains( algorithm.childId() ) )
algorithm.generateChildId( *this );
@ -1163,7 +881,7 @@ QString QgsProcessingModelAlgorithm::addChildAlgorithm( ChildAlgorithm &algorith
return algorithm.childId();
}
QgsProcessingModelAlgorithm::ChildAlgorithm &QgsProcessingModelAlgorithm::childAlgorithm( const QString &childId )
QgsProcessingModelChildAlgorithm &QgsProcessingModelAlgorithm::childAlgorithm( const QString &childId )
{
return mChildAlgorithms[ childId ];
}
@ -1200,7 +918,7 @@ bool QgsProcessingModelAlgorithm::activateChildAlgorithm( const QString &id )
return true;
}
void QgsProcessingModelAlgorithm::addModelParameter( QgsProcessingParameterDefinition *definition, const QgsProcessingModelAlgorithm::ModelParameter &component )
void QgsProcessingModelAlgorithm::addModelParameter( QgsProcessingParameterDefinition *definition, const QgsProcessingModelParameter &component )
{
addParameter( definition );
mParameterComponents.insert( definition->name(), component );
@ -1220,17 +938,17 @@ void QgsProcessingModelAlgorithm::removeModelParameter( const QString &name )
bool QgsProcessingModelAlgorithm::childAlgorithmsDependOnParameter( const QString &name ) const
{
QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt )
{
// check whether child requires this parameter
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources> childParams = childIt->parameterSources();
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources>::const_iterator paramIt = childParams.constBegin();
QMap<QString, QgsProcessingModelChildParameterSources> childParams = childIt->parameterSources();
QMap<QString, QgsProcessingModelChildParameterSources>::const_iterator paramIt = childParams.constBegin();
for ( ; paramIt != childParams.constEnd(); ++paramIt )
{
Q_FOREACH ( const ChildParameterSource &source, paramIt.value() )
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramIt.value() )
{
if ( source.source() == ChildParameterSource::ModelParameter
if ( source.source() == QgsProcessingModelChildParameterSource::ModelParameter
&& source.parameterName() == name )
{
return true;
@ -1254,14 +972,14 @@ bool QgsProcessingModelAlgorithm::otherParametersDependOnParameter( const QStrin
return false;
}
QMap<QString, QgsProcessingModelAlgorithm::ModelParameter> QgsProcessingModelAlgorithm::parameterComponents() const
QMap<QString, QgsProcessingModelParameter> QgsProcessingModelAlgorithm::parameterComponents() const
{
return mParameterComponents;
}
void QgsProcessingModelAlgorithm::dependentChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const
{
QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt )
{
if ( depends.contains( childIt->childId() ) )
@ -1276,13 +994,13 @@ void QgsProcessingModelAlgorithm::dependentChildAlgorithmsRecursive( const QStri
}
// check whether child requires any outputs from the target alg
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources> childParams = childIt->parameterSources();
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources>::const_iterator paramIt = childParams.constBegin();
QMap<QString, QgsProcessingModelChildParameterSources> childParams = childIt->parameterSources();
QMap<QString, QgsProcessingModelChildParameterSources>::const_iterator paramIt = childParams.constBegin();
for ( ; paramIt != childParams.constEnd(); ++paramIt )
{
Q_FOREACH ( const ChildParameterSource &source, paramIt.value() )
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramIt.value() )
{
if ( source.source() == ChildParameterSource::ChildOutput
if ( source.source() == QgsProcessingModelChildParameterSource::ChildOutput
&& source.outputChildId() == childId )
{
depends.insert( childIt->childId() );
@ -1313,7 +1031,7 @@ QSet<QString> QgsProcessingModelAlgorithm::dependentChildAlgorithms( const QStri
void QgsProcessingModelAlgorithm::dependsOnChildAlgorithmsRecursive( const QString &childId, QSet< QString > &depends ) const
{
ChildAlgorithm alg = mChildAlgorithms.value( childId );
QgsProcessingModelChildAlgorithm alg = mChildAlgorithms.value( childId );
// add direct dependencies
Q_FOREACH ( const QString &c, alg.dependencies() )
@ -1326,13 +1044,13 @@ void QgsProcessingModelAlgorithm::dependsOnChildAlgorithmsRecursive( const QStri
}
// check through parameter dependencies
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources> childParams = alg.parameterSources();
QMap<QString, QgsProcessingModelAlgorithm::ChildParameterSources>::const_iterator paramIt = childParams.constBegin();
QMap<QString, QgsProcessingModelChildParameterSources> childParams = alg.parameterSources();
QMap<QString, QgsProcessingModelChildParameterSources>::const_iterator paramIt = childParams.constBegin();
for ( ; paramIt != childParams.constEnd(); ++paramIt )
{
Q_FOREACH ( const ChildParameterSource &source, paramIt.value() )
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramIt.value() )
{
if ( source.source() == ChildParameterSource::ChildOutput && !depends.contains( source.outputChildId() ) )
if ( source.source() == QgsProcessingModelChildParameterSource::ChildOutput && !depends.contains( source.outputChildId() ) )
{
depends.insert( source.outputChildId() );
dependsOnChildAlgorithmsRecursive( source.outputChildId(), depends );
@ -1359,7 +1077,7 @@ QSet< QString > QgsProcessingModelAlgorithm::dependsOnChildAlgorithms( const QSt
bool QgsProcessingModelAlgorithm::canExecute( QString *errorMessage ) const
{
QMap< QString, ChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin();
for ( ; childIt != mChildAlgorithms.constEnd(); ++childIt )
{
if ( !childIt->algorithm() )
@ -1390,177 +1108,4 @@ QgsProcessingModelAlgorithm *QgsProcessingModelAlgorithm::create() const
return alg;
}
bool QgsProcessingModelAlgorithm::ChildParameterSource::operator==( const QgsProcessingModelAlgorithm::ChildParameterSource &other ) const
{
if ( mSource != other.mSource )
return false;
switch ( mSource )
{
case StaticValue:
return mStaticValue == other.mStaticValue;
case ChildOutput:
return mChildId == other.mChildId && mOutputName == other.mOutputName;
case ModelParameter:
return mParameterName == other.mParameterName;
case Expression:
return mExpression == other.mExpression;
}
return false;
}
QgsProcessingModelAlgorithm::ChildParameterSource QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( const QVariant &value )
{
ChildParameterSource src;
src.mSource = StaticValue;
src.mStaticValue = value;
return src;
}
QgsProcessingModelAlgorithm::ChildParameterSource QgsProcessingModelAlgorithm::ChildParameterSource::fromModelParameter( const QString &parameterName )
{
ChildParameterSource src;
src.mSource = ModelParameter;
src.mParameterName = parameterName;
return src;
}
QgsProcessingModelAlgorithm::ChildParameterSource QgsProcessingModelAlgorithm::ChildParameterSource::fromChildOutput( const QString &childId, const QString &outputName )
{
ChildParameterSource src;
src.mSource = ChildOutput;
src.mChildId = childId;
src.mOutputName = outputName;
return src;
}
QgsProcessingModelAlgorithm::ChildParameterSource QgsProcessingModelAlgorithm::ChildParameterSource::fromExpression( const QString &expression )
{
ChildParameterSource src;
src.mSource = Expression;
src.mExpression = expression;
return src;
}
QgsProcessingModelAlgorithm::ChildParameterSource::Source QgsProcessingModelAlgorithm::ChildParameterSource::source() const
{
return mSource;
}
QVariant QgsProcessingModelAlgorithm::ChildParameterSource::toVariant() const
{
QVariantMap map;
map.insert( QStringLiteral( "source" ), mSource );
switch ( mSource )
{
case ModelParameter:
map.insert( QStringLiteral( "parameter_name" ), mParameterName );
break;
case ChildOutput:
map.insert( QStringLiteral( "child_id" ), mChildId );
map.insert( QStringLiteral( "output_name" ), mOutputName );
break;
case StaticValue:
map.insert( QStringLiteral( "static_value" ), mStaticValue );
break;
case Expression:
map.insert( QStringLiteral( "expression" ), mExpression );
break;
}
return map;
}
bool QgsProcessingModelAlgorithm::ChildParameterSource::loadVariant( const QVariantMap &map )
{
mSource = static_cast< Source >( map.value( QStringLiteral( "source" ) ).toInt() );
switch ( mSource )
{
case ModelParameter:
mParameterName = map.value( QStringLiteral( "parameter_name" ) ).toString();
break;
case ChildOutput:
mChildId = map.value( QStringLiteral( "child_id" ) ).toString();
mOutputName = map.value( QStringLiteral( "output_name" ) ).toString();
break;
case StaticValue:
mStaticValue = map.value( QStringLiteral( "static_value" ) );
break;
case Expression:
mExpression = map.value( QStringLiteral( "expression" ) ).toString();
break;
}
return true;
}
QString QgsProcessingModelAlgorithm::ChildParameterSource::asPythonCode() const
{
switch ( mSource )
{
case ModelParameter:
return QStringLiteral( "parameters['%1']" ).arg( mParameterName );
case ChildOutput:
return QStringLiteral( "outputs['%1']['%2']" ).arg( mChildId, mOutputName );
case StaticValue:
return mStaticValue.toString();
case Expression:
return QStringLiteral( "QgsExpression('%1').evaluate()" ).arg( mExpression );
}
return QString();
}
QgsProcessingModelAlgorithm::ModelOutput::ModelOutput( const QString &name, const QString &description )
: QgsProcessingModelAlgorithm::Component( description )
, mName( name )
{}
QVariant QgsProcessingModelAlgorithm::ModelOutput::toVariant() const
{
QVariantMap map;
map.insert( QStringLiteral( "name" ), mName );
map.insert( QStringLiteral( "child_id" ), mChildId );
map.insert( QStringLiteral( "output_name" ), mOutputName );
saveCommonProperties( map );
return map;
}
bool QgsProcessingModelAlgorithm::ModelOutput::loadVariant( const QVariantMap &map )
{
mName = map.value( QStringLiteral( "name" ) ).toString();
mChildId = map.value( QStringLiteral( "child_id" ) ).toString();
mOutputName = map.value( QStringLiteral( "output_name" ) ).toString();
restoreCommonProperties( map );
return true;
}
QgsProcessingModelAlgorithm::ModelParameter::ModelParameter( const QString &parameterName )
: QgsProcessingModelAlgorithm::Component()
, mParameterName( parameterName )
{
}
QVariant QgsProcessingModelAlgorithm::ModelParameter::toVariant() const
{
QVariantMap map;
map.insert( QStringLiteral( "name" ), mParameterName );
saveCommonProperties( map );
return map;
}
bool QgsProcessingModelAlgorithm::ModelParameter::loadVariant( const QVariantMap &map )
{
mParameterName = map.value( QStringLiteral( "name" ) ).toString();
restoreCommonProperties( map );
return true;
}
///@endcond

View File

@ -0,0 +1,405 @@
/***************************************************************************
qgsprocessingmodelalgorithm.h
-----------------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSPROCESSINGMODELALGORITHM_H
#define QGSPROCESSINGMODELALGORITHM_H
#include "qgis_core.h"
#include "qgis.h"
#include "qgsprocessingmodelchildalgorithm.h"
#include "qgsprocessingalgorithm.h"
#include "qgsprocessingmodelparameter.h"
#include "qgsprocessingmodelchildparametersource.h"
///@cond NOT_STABLE
/**
* \class QgsProcessingModelAlgorithm
* \ingroup core
* Model based algorithm with processing.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
{
public:
/**
* Constructor for QgsProcessingModelAlgorithm.
*/
QgsProcessingModelAlgorithm( const QString &name = QString(), const QString &group = QString() );
QString name() const override;
QString displayName() const override;
QString group() const override;
QIcon icon() const override;
QString svgIconPath() const override;
QString shortHelpString() const override;
QString helpUrl() const override;
bool canExecute( QString *errorMessage SIP_OUT = nullptr ) const override;
QString asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const override;
QgsProcessingModelAlgorithm *create() const override SIP_FACTORY;
/**
* Sets the model \a name.
* \see name()
*/
void setName( const QString &name );
/**
* Sets the model \a group.
* \see group()
*/
void setGroup( const QString &group );
/**
* Returns the map of child algorithms contained in the model. The keys
* are the child algorithm ids (see QgsProcessingModelAlgorithm::ChildAlgorithm::childId()).
* \see childAlgorithm()
* \see setChildAlgorithms()
* \see addChildAlgorithm()
*/
QMap<QString, QgsProcessingModelChildAlgorithm> childAlgorithms() const;
/**
* Sets the map of child algorithms contained in the model. The keys
* are the child algorithm ids (see QgsProcessingModelAlgorithm::ChildAlgorithm::childId()).
* All existing child algorithms will be replaced.
* \see childAlgorithms()
* \see childAlgorithm()
* \see setChildAlgorithm()
* \see addChildAlgorithm()
*/
void setChildAlgorithms( const QMap<QString, QgsProcessingModelChildAlgorithm> &childAlgorithms );
/**
* Sets the child \a algorithm within the model. If a child algorithm already
* exists in the model with the same child ID then that algorithm will be replaced.
* \see addChildAlgorithm()
* \see setChildAlgorithms()
*/
void setChildAlgorithm( const QgsProcessingModelChildAlgorithm &algorithm );
/**
* Adds a new child \a algorithm to the model. If a child algorithm already exists
* in the model with the same child ID then \a algorithm will be assigned a new
* autogenerated unique ID.
* The assigned child ID will be returned.
* \see childAlgorithms()
* \see childAlgorithm()
* \see setChildAlgorithm()
* \see setChildAlgorithms()
*/
QString addChildAlgorithm( QgsProcessingModelChildAlgorithm &algorithm );
/**
* Returns the child algorithm with matching \a id. If no child algorithm exists with
* this ID a new algorithm will be added to the model and returned.
* \see addChildAlgorithm()
* \see childAlgorithms()
*/
QgsProcessingModelChildAlgorithm &childAlgorithm( const QString &id );
/**
* Attempts to remove the child algorithm with matching \a id.
* Returns true if the algorithm could be removed, or false
* if the algorithm could not be removed (e.g. due to other
* child algorithms depending on it).
* \see deactivateChildAlgorithm()
*/
bool removeChildAlgorithm( const QString &id );
/**
* Deactivates the child algorithm with matching \a id.
* All other child algorithms which depend on the child
* algorithm will also be deactivated.
* \see removeChildAlgorithm()
* \see activateChildAlgorithm()
*/
void deactivateChildAlgorithm( const QString &id );
/**
* Attempts to activate the child algorithm with matching \a id.
* If any child algorithms on which the child depends are not active,
* then the child will not be activated and false will be returned.
* \see deactivateChildAlgorithm()
*/
bool activateChildAlgorithm( const QString &id );
/**
* Returns a list of the child algorithm IDs depending on the child
* algorithm with the specified \a childId.
* \see dependsOnChildAlgorithms()
*/
QSet< QString > dependentChildAlgorithms( const QString &childId ) const;
/**
* Returns a list of the child algorithm IDs on which the child
* algorithm with the specified \a childId depends upon.
* \see dependentChildAlgorithms()
*/
QSet< QString > dependsOnChildAlgorithms( const QString &childId ) const;
/**
* Adds a new parameter to the model, with the specified \a definition and graphical \a component.
* Ownership of \a definition is transferred to the model.
* \see updateModelParameter()
* \see removeModelParameter()
*/
void addModelParameter( QgsProcessingParameterDefinition *definition SIP_TRANSFER, const QgsProcessingModelParameter &component );
/**
* Replaces the definition of an existing parameter (by parameter name) with a new \a definition. Ownership of
* \a definition is transferred to the model, and any existing parameter is deleted.
* \see addModelParameter()
* \see removeModelParameter()
*/
void updateModelParameter( QgsProcessingParameterDefinition *definition SIP_TRANSFER );
/**
* Removes an existing model parameter by \a name. The definition of the matching parameter
* is deleted.
* \see addModelParameter()
* \see updateModelParameter()
*/
void removeModelParameter( const QString &name );
/**
* 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() ).
* \see setParameterComponent()
* \see parameterComponent()
*/
QMap<QString, QgsProcessingModelParameter> parameterComponents() const;
/**
* Sets the map of parameter components used by the model. The keys
* should match the algorithm's parameter names (see parameterDefinitions() ).
* All existing parameter components will be replaced.
* \see parameterComponents()
* \see setParameterComponent()
* \see parameterComponent()
*/
void setParameterComponents( const QMap<QString, QgsProcessingModelParameter> &parameterComponents );
/**
* Sets a parameter \a component for the model. If a parameter component already
* exists in the model with the same parameter name then that component will be replaced.
* \see parameterComponents()
* \see setParameterComponents()
* \see parameterComponent()
*/
void setParameterComponent( const QgsProcessingModelParameter &component );
/**
* Returns the parameter component with matching \a name. If no parameter component exists with
* this name a new component will be added to the model and returned.
* \see parameterComponents()
* \see setParameterComponents()
* \see setParameterComponent()
*/
QgsProcessingModelParameter &parameterComponent( const QString &name );
/**
* Updates the model's parameter definitions to include all relevant destination
* parameters as required by child algorithm ModelOutputs.
* Must be called whenever child algorithm ModelOutputs are altered.
*/
void updateDestinationParameters();
/**
* Writes the model to a file, at the specified \a path.
* \see fromFile()
*/
bool toFile( const QString &path ) const;
/**
* Reads the model from a file, at the specified \a path.
* \see toFile()
*/
bool fromFile( const QString &path );
/**
* Returns the model's help contents (a free-form map of values describing the algorithm's
* use and metadata).
* \see setHelpContent()
*/
QVariantMap &helpContent() { return mHelpContent; }
/**
* Returns the model's help contents (a free-form map of values describing the algorithm's
* use and metadata).
* \see setHelpContent()
*/
SIP_SKIP QVariantMap helpContent() const;
/**
* Sets the model's help \a contents (a free-form map of values describing the algorithm's
* use and metadata).
* \see helpContent()
*/
void setHelpContent( const QVariantMap &contents );
/**
* Returns the source file path for the model, if available.
* \see setSourceFilePath()
*/
QString sourceFilePath() const;
/**
* Sets the source file \a path for the model, if available.
* \see sourceFilePath()
*/
void setSourceFilePath( const QString &path );
/**
* Attempts to convert the model to executable Python code.
*/
QString asPythonCode() const;
/**
* Returns a list of possible sources which can be used for the parameters for a child
* algorithm in the model. Returned sources are those which match either one of the
* specified \a parameterTypes (see QgsProcessingParameterDefinition::type() ) or
* on of the specified \a outputTypes (see QgsProcessingOutputDefinition::type() ).
* If specified, an optional list of \a dataTypes can be used to filter the returned
* sources to those with compatible data types for the parameter/outputs.
*/
QList< QgsProcessingModelChildParameterSource > availableSourcesForChild( const QString &childId, const QStringList &parameterTypes = QStringList(),
const QStringList &outputTypes = QStringList(), const QList< int > dataTypes = QList< int >() ) const;
/**
* Definition of a expression context variable available during model execution.
* \since QGIS 3.0
* \ingroup core
*/
class CORE_EXPORT VariableDefinition
{
public:
/**
* Constructor for a new VariableDefinition with the specified \a value and original
* parameter \a source, and \a description.
*/
VariableDefinition( const QVariant &value = QVariant(), const QgsProcessingModelChildParameterSource &source = QgsProcessingModelChildParameterSource::fromStaticValue( QVariant() ), const QString &description = QString() )
: value( value )
, source( source )
, description( description )
{}
//! Value of variable
QVariant value;
//! Original source of variable's value
QgsProcessingModelChildParameterSource source;
//! Translated description of variable
QString description;
};
/**
* Returns a map of variable name to variable definition for expression context variables which are available
* for use by child algorithm during model execution.
*
* The child algorithm \a childId and processing \a context
* are manadatory. If \a modelParameters and \a results are not specified, then only the variable names and sources
* will be returned, but all variable values will be null. This can be used to determine in advance which variables
* will be available for a specific child algorithm, e.g. for use in expression builder widgets.
*
* In order to calculate the actual variable value, the input model \a modelParameters and already executed child
* algorithm \a results must be passed.
* \see createExpressionContextScopeForChildAlgorithm()
*/
QMap< QString, QgsProcessingModelAlgorithm::VariableDefinition > variablesForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(),
const QVariantMap &results = QVariantMap() ) const;
/**
* Creates a new expression context scope for a child algorithm within the model.
* \see variablesForChildAlgorithm()
*/
QgsExpressionContextScope *createExpressionContextScopeForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(),
const QVariantMap &results = QVariantMap() ) const SIP_FACTORY;
protected:
QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
private:
QString mModelName;
QString mModelGroup;
QMap< QString, QgsProcessingModelChildAlgorithm > mChildAlgorithms;
//! Map of parameter name to model parameter component
QMap< QString, QgsProcessingModelParameter > mParameterComponents;
QVariantMap mHelpContent;
//! Model source file
QString mSourceFile;
QVariantMap mResults;
void dependsOnChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;
void dependentChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;
QVariantMap parametersForChildAlgorithm( const QgsProcessingModelChildAlgorithm &child, const QVariantMap &modelParameters, const QVariantMap &results, const QgsExpressionContext &expressionContext ) const;
/**
* Returns true if an output from a child algorithm is required elsewhere in
* the model.
*/
bool childOutputIsRequired( const QString &childId, const QString &outputName ) const;
/**
* Saves this model to a QVariantMap, wrapped in a QVariant.
* You can use QgsXmlUtils::writeVariant to save it to an XML document.
*
* \see loadVariant()
*/
QVariant toVariant() const;
/**
* Loads this model from a QVariantMap, wrapped in a QVariant.
* You can use QgsXmlUtils::readVariant to load it from an XML document.
*
* \see toVariant()
*/
bool loadVariant( const QVariant &model );
friend class TestQgsProcessing;
};
///@endcond
#endif // QGSPROCESSINGMODELALGORITHM_H

View File

@ -0,0 +1,181 @@
/***************************************************************************
qgsprocessingmodelchildalgorithm.cpp
------------------------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsprocessingmodelchildalgorithm.h"
#include "qgsapplication.h"
#include "qgsprocessingregistry.h"
#include "qgsprocessingmodelalgorithm.h"
///@cond NOT_STABLE
QgsProcessingModelChildAlgorithm::QgsProcessingModelChildAlgorithm( const QString &algorithmId )
: mAlgorithmId( algorithmId )
{
}
const QgsProcessingAlgorithm *QgsProcessingModelChildAlgorithm::algorithm() const
{
return QgsApplication::processingRegistry()->algorithmById( mAlgorithmId );
}
void QgsProcessingModelChildAlgorithm::setModelOutputs( const QMap<QString, QgsProcessingModelOutput> &modelOutputs )
{
mModelOutputs = modelOutputs;
QMap<QString, QgsProcessingModelOutput>::iterator outputIt = mModelOutputs.begin();
for ( ; outputIt != mModelOutputs.end(); ++outputIt )
{
// make sure values are consistent
outputIt->setName( outputIt.key() );
outputIt->setChildId( mId );
}
}
QVariant QgsProcessingModelChildAlgorithm::toVariant() const
{
QVariantMap map;
map.insert( QStringLiteral( "id" ), mId );
map.insert( QStringLiteral( "alg_id" ), mAlgorithmId );
map.insert( QStringLiteral( "active" ), mActive );
map.insert( QStringLiteral( "dependencies" ), mDependencies );
map.insert( QStringLiteral( "parameters_collapsed" ), mParametersCollapsed );
map.insert( QStringLiteral( "outputs_collapsed" ), mOutputsCollapsed );
saveCommonProperties( map );
QVariantMap paramMap;
QMap< QString, QgsProcessingModelChildParameterSources >::const_iterator paramIt = mParams.constBegin();
for ( ; paramIt != mParams.constEnd(); ++paramIt )
{
QVariantList sources;
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramIt.value() )
{
sources << source.toVariant();
}
paramMap.insert( paramIt.key(), sources );
}
map.insert( "params", paramMap );
QVariantMap outputMap;
QMap< QString, QgsProcessingModelOutput >::const_iterator outputIt = mModelOutputs.constBegin();
for ( ; outputIt != mModelOutputs.constEnd(); ++outputIt )
{
outputMap.insert( outputIt.key(), outputIt.value().toVariant() );
}
map.insert( "outputs", outputMap );
return map;
}
bool QgsProcessingModelChildAlgorithm::loadVariant( const QVariant &child )
{
QVariantMap map = child.toMap();
mId = map.value( QStringLiteral( "id" ) ).toString();
mAlgorithmId = map.value( QStringLiteral( "alg_id" ) ).toString();
mActive = map.value( QStringLiteral( "active" ) ).toBool();
mDependencies = map.value( QStringLiteral( "dependencies" ) ).toStringList();
mParametersCollapsed = map.value( QStringLiteral( "parameters_collapsed" ) ).toBool();
mOutputsCollapsed = map.value( QStringLiteral( "outputs_collapsed" ) ).toBool();
restoreCommonProperties( map );
mParams.clear();
QVariantMap paramMap = map.value( QStringLiteral( "params" ) ).toMap();
QVariantMap::const_iterator paramIt = paramMap.constBegin();
for ( ; paramIt != paramMap.constEnd(); ++paramIt )
{
QgsProcessingModelChildParameterSources sources;
Q_FOREACH ( const QVariant &sourceVar, paramIt->toList() )
{
QgsProcessingModelChildParameterSource param;
if ( !param.loadVariant( sourceVar.toMap() ) )
return false;
sources << param;
}
mParams.insert( paramIt.key(), sources );
}
mModelOutputs.clear();
QVariantMap outputMap = map.value( QStringLiteral( "outputs" ) ).toMap();
QVariantMap::const_iterator outputIt = outputMap.constBegin();
for ( ; outputIt != outputMap.constEnd(); ++outputIt )
{
QgsProcessingModelOutput output;
if ( !output.loadVariant( outputIt.value().toMap() ) )
return false;
mModelOutputs.insert( outputIt.key(), output );
}
return true;
}
QString QgsProcessingModelChildAlgorithm::asPythonCode() const
{
QStringList lines;
if ( !algorithm() )
return QString();
QStringList paramParts;
QMap< QString, QgsProcessingModelChildParameterSources >::const_iterator paramIt = mParams.constBegin();
for ( ; paramIt != mParams.constEnd(); ++paramIt )
{
QStringList sourceParts;
Q_FOREACH ( const QgsProcessingModelChildParameterSource &source, paramIt.value() )
{
QString part = source.asPythonCode();
if ( !part.isEmpty() )
sourceParts << QStringLiteral( "'%1':%2" ).arg( paramIt.key(), part );
}
if ( sourceParts.count() == 1 )
paramParts << sourceParts.at( 0 );
else
paramParts << QStringLiteral( "[%1]" ).arg( paramParts.join( ',' ) );
}
lines << QStringLiteral( "outputs['%1']=processing.run('%2', {%3}, context=context, feedback=feedback)" ).arg( mId, mAlgorithmId, paramParts.join( ',' ) );
QMap< QString, QgsProcessingModelOutput >::const_iterator outputIt = mModelOutputs.constBegin();
for ( ; outputIt != mModelOutputs.constEnd(); ++outputIt )
{
lines << QStringLiteral( "results['%1']=outputs['%2']['%3']" ).arg( outputIt.key(), mId, outputIt.value().childOutputName() );
}
return lines.join( '\n' );
}
void QgsProcessingModelChildAlgorithm::generateChildId( const QgsProcessingModelAlgorithm &model )
{
int i = 1;
QString id;
while ( true )
{
id = QStringLiteral( "%1_%2" ).arg( mAlgorithmId ).arg( i );
if ( !model.childAlgorithms().contains( id ) )
break;
i++;
}
mId = id;
}
///@endcond

View File

@ -0,0 +1,254 @@
/***************************************************************************
qgsprocessingmodelchildalgorithm.h
----------------------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSPROCESSINGMODELCHILDALGORITHM_H
#define QGSPROCESSINGMODELCHILDALGORITHM_H
#include "qgis_core.h"
#include "qgis.h"
#include "qgsprocessingmodelcomponent.h"
#include "qgsprocessingmodelchildparametersource.h"
#include "qgsprocessingmodeloutput.h"
class QgsProcessingModelAlgorithm;
class QgsProcessingAlgorithm;
///@cond NOT_STABLE
/**
* Child algorithm representing a single component of a QgsProcessingModelAlgorithm.
* \since QGIS 3.0
* \ingroup core
*/
class CORE_EXPORT QgsProcessingModelChildAlgorithm : public QgsProcessingModelComponent
{
public:
/**
* Constructor for QgsProcessingModelChildAlgorithm. The \a algorithmId parameter
* should be set to a QgsProcessingAlgorithm algorithm ID.
*/
QgsProcessingModelChildAlgorithm( const QString &algorithmId = QString() );
/**
* Returns the child algorithm's unique ID string, used the identify
* this child algorithm within its parent model.
* \see setChildId()
* \see generateChildId()
*/
QString childId() const { return mId; }
/**
* Sets the child algorithm's unique \a id string, used the identify
* this child algorithm within its parent model.
* \see childId()
* \see generateChildId()
*/
void setChildId( const QString &id ) { mId = id; }
/**
* Automatically generates a unique childId() for the algorithm,
* avoiding child IDs which are already present in \a model.
* \see childId()
* \see setChildId()
*/
void generateChildId( const QgsProcessingModelAlgorithm &model );
/**
* Returns the underlying child algorithm's ID.
* \see algorithm()
* \see setAlgorithmId()
*/
QString algorithmId() const { return mAlgorithmId; }
/**
* Sets the underlying child algorithm's ID. This
* should be set to an existing QgsProcessingAlgorithm algorithm ID.
* \see algorithm()
* \see algorithmId()
*/
void setAlgorithmId( const QString &algorithmId ) { mAlgorithmId = algorithmId; }
/**
* Returns the underlying child algorithm, or a nullptr
* if a matching algorithm is not available.
* \see algorithmId()
*/
const QgsProcessingAlgorithm *algorithm() const;
/**
* Returns a map of parameter sources. The keys are the child algorithm
* parameter names, the values are the sources for that parameter.
* \see setParameterSources()
* \see addParameterSources()
*/
QMap< QString, QList< QgsProcessingModelChildParameterSource > > parameterSources() const { return mParams; }
/**
* Sets the map of parameter \a sources. The keys are the child algorithm
* parameter names, the values are the sources for that parameter.
* \see parameterSources()
* \see addParameterSources()
*/
void setParameterSources( const QMap< QString, QList< QgsProcessingModelChildParameterSource > > &sources ) { mParams = sources; }
/**
* Adds a parameter source. The \a name argument should match
* one of the child algorithm's parameter names, and the \a sources
* argument is used to set the sources for that parameter.
*
* Any existing parameter sources with matching name will be replaced.
* \see parameterSources()
* \see setParameterSources()
*/
void addParameterSources( const QString &name, const QList< QgsProcessingModelChildParameterSource > &source ) { mParams.insert( name, source ); }
/**
* Returns true if the child algorithm is active.
* \see setActive()
*/
bool isActive() const { return mActive; }
/**
* Sets whether the child algorithm is active.
* \see isActive()
*/
void setActive( bool active ) { mActive = active; }
/**
* Returns the list of child algorithms from the parent model on which this
* algorithm is dependent. The returned list contains the id() of the
* dependent algorithms.
* \see setDependencies()
*/
QStringList dependencies() const { return mDependencies; }
/**
* Sets the list of child algorithms from the parent model on which this
* algorithm is dependent. The list should contain the id() of the
* dependent algorithms.
* \see dependencies()
*/
void setDependencies( const QStringList &dependencies ) { mDependencies = dependencies; }
/**
* Returns true if the list of parameters for this algorithm should be collapsed
* in the graphical modeller.
* \see setParametersCollapsed()
* \see outputsCollapsed()
*/
bool parametersCollapsed() const { return mParametersCollapsed; }
/**
* Sets whether the list of parameters for this algorithm should be collapsed
* in the graphical modeller.
* \see parametersCollapsed()
* \see setOutputsCollapsed()
*/
void setParametersCollapsed( bool collapsed ) { mParametersCollapsed = collapsed; }
/**
* Returns true if the list of outputs for this algorithm should be collapsed
* in the graphical modeller.
* \see setParametersCollapsed()
* \see parametersCollapsed()
*/
bool outputsCollapsed() const { return mOutputsCollapsed; }
/**
* Sets whether the list of outputs for this algorithm should be collapsed
* in the graphical modeller.
* \see outputsCollapsed()
* \see setParametersCollapsed()
*/
void setOutputsCollapsed( bool collapsed ) { mOutputsCollapsed = collapsed; }
/**
* Returns the map of final model outputs which are generated by this child algorithm.
* The keys are the output names from this child algorithm. Only outputs which are
* part of the final outputs from the model are included in this map.
* \see setModelOutputs()
* \see modelOutput()
*/
QMap<QString, QgsProcessingModelOutput> modelOutputs() const { return mModelOutputs; }
/**
* Returns the final model output with matching \a name. If no output
* exists with the name, a new one will be created and returned.
*
* If child model outputs are altered by this method, QgsProcessingModelAlgorithm::updateDestinationParameters()
* must be called on the parent model.
*
* \see modelOutputs()
* \see setModelOutputs()
*/
QgsProcessingModelOutput &modelOutput( const QString &name ) { return mModelOutputs[ name ]; }
/**
* Sets the map of final model \a outputs which are generated by this child algorithm.
* Only outputs which are part of the final outputs from the model should be included in this map.
*
* If child model outputs are altered by this method, QgsProcessingModelAlgorithm::updateDestinationParameters()
* must be called on the parent model.
*
* \see modelOutputs()
*/
void setModelOutputs( const QMap<QString, QgsProcessingModelOutput> &outputs );
/**
* Saves this child to a QVariant.
* \see loadVariant()
*/
QVariant toVariant() const;
/**
* Loads this child from a QVariant.
* \see toVariant()
*/
bool loadVariant( const QVariant &child );
/**
* Attempts to convert the child to executable Python code.
*/
QString asPythonCode() const;
private:
QString mId;
QString mAlgorithmId;
//! A map of parameter sources. Keys are algorithm parameter names.
QMap< QString, QgsProcessingModelChildParameterSources > mParams;
//! A map of ModelOutput for final model outputs generated by this child algorithm. Keys are output names from the child algorithm.
QMap< QString, QgsProcessingModelOutput > mModelOutputs;
bool mActive = true;
//! List of child algorithms from the parent model on which this algorithm is dependent
QStringList mDependencies;
//! Whether list of parameters should be collapsed in the graphical modeller
bool mParametersCollapsed = true;
//! Whether list of outputs should be collapsed in the graphical modeller
bool mOutputsCollapsed = true;
};
///@endcond
#endif // QGSPROCESSINGMODELCHILDALGORITHM_H

View File

@ -0,0 +1,149 @@
/***************************************************************************
qgsprocessingmodelchildparametersource.cpp
------------------------------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsprocessingmodelchildparametersource.h"
///@cond NOT_STABLE
bool QgsProcessingModelChildParameterSource::operator==( const QgsProcessingModelChildParameterSource &other ) const
{
if ( mSource != other.mSource )
return false;
switch ( mSource )
{
case StaticValue:
return mStaticValue == other.mStaticValue;
case ChildOutput:
return mChildId == other.mChildId && mOutputName == other.mOutputName;
case ModelParameter:
return mParameterName == other.mParameterName;
case Expression:
return mExpression == other.mExpression;
}
return false;
}
QgsProcessingModelChildParameterSource QgsProcessingModelChildParameterSource::fromStaticValue( const QVariant &value )
{
QgsProcessingModelChildParameterSource src;
src.mSource = StaticValue;
src.mStaticValue = value;
return src;
}
QgsProcessingModelChildParameterSource QgsProcessingModelChildParameterSource::fromModelParameter( const QString &parameterName )
{
QgsProcessingModelChildParameterSource src;
src.mSource = ModelParameter;
src.mParameterName = parameterName;
return src;
}
QgsProcessingModelChildParameterSource QgsProcessingModelChildParameterSource::fromChildOutput( const QString &childId, const QString &outputName )
{
QgsProcessingModelChildParameterSource src;
src.mSource = ChildOutput;
src.mChildId = childId;
src.mOutputName = outputName;
return src;
}
QgsProcessingModelChildParameterSource QgsProcessingModelChildParameterSource::fromExpression( const QString &expression )
{
QgsProcessingModelChildParameterSource src;
src.mSource = Expression;
src.mExpression = expression;
return src;
}
QgsProcessingModelChildParameterSource::Source QgsProcessingModelChildParameterSource::source() const
{
return mSource;
}
QVariant QgsProcessingModelChildParameterSource::toVariant() const
{
QVariantMap map;
map.insert( QStringLiteral( "source" ), mSource );
switch ( mSource )
{
case ModelParameter:
map.insert( QStringLiteral( "parameter_name" ), mParameterName );
break;
case ChildOutput:
map.insert( QStringLiteral( "child_id" ), mChildId );
map.insert( QStringLiteral( "output_name" ), mOutputName );
break;
case StaticValue:
map.insert( QStringLiteral( "static_value" ), mStaticValue );
break;
case Expression:
map.insert( QStringLiteral( "expression" ), mExpression );
break;
}
return map;
}
bool QgsProcessingModelChildParameterSource::loadVariant( const QVariantMap &map )
{
mSource = static_cast< Source >( map.value( QStringLiteral( "source" ) ).toInt() );
switch ( mSource )
{
case ModelParameter:
mParameterName = map.value( QStringLiteral( "parameter_name" ) ).toString();
break;
case ChildOutput:
mChildId = map.value( QStringLiteral( "child_id" ) ).toString();
mOutputName = map.value( QStringLiteral( "output_name" ) ).toString();
break;
case StaticValue:
mStaticValue = map.value( QStringLiteral( "static_value" ) );
break;
case Expression:
mExpression = map.value( QStringLiteral( "expression" ) ).toString();
break;
}
return true;
}
QString QgsProcessingModelChildParameterSource::asPythonCode() const
{
switch ( mSource )
{
case ModelParameter:
return QStringLiteral( "parameters['%1']" ).arg( mParameterName );
case ChildOutput:
return QStringLiteral( "outputs['%1']['%2']" ).arg( mChildId, mOutputName );
case StaticValue:
return mStaticValue.toString();
case Expression:
return QStringLiteral( "QgsExpression('%1').evaluate()" ).arg( mExpression );
}
return QString();
}
///@endcond

View File

@ -0,0 +1,198 @@
/***************************************************************************
qgsprocessingmodelchildparametersource.h
----------------------------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSPROCESSINGMODELCHILDPARAMETERSOURCE_H
#define QGSPROCESSINGMODELCHILDPARAMETERSOURCE_H
#include "qgis_core.h"
#include "qgis.h"
///@cond NOT_STABLE
/**
* Source for the value of a parameter for a child algorithm within a model.
* \since QGIS 3.0
* \ingroup core
*/
class CORE_EXPORT QgsProcessingModelChildParameterSource
{
public:
//! Possible parameter value sources
enum Source
{
ModelParameter, //!< Parameter value is taken from a parent model parameter
ChildOutput, //!< Parameter value is taken from an output generated by a child algorithm
StaticValue, //!< Parameter value is a static value
Expression, //!< Parameter value is taken from an expression, evaluated just before the algorithm runs
};
/**
* Constructor for QgsProcessingModelChildParameterSource. It is recommended that the static methods
* fromStaticValue(), fromModelParameter(), fromChildOutput() and fromExpression() are used instead.
*/
QgsProcessingModelChildParameterSource() = default;
bool operator==( const QgsProcessingModelChildParameterSource &other ) const;
bool operator!=( const QgsProcessingModelChildParameterSource &other ) const
{
return !operator==( other );
}
/**
* Returns a new QgsProcessingModelChildParameterSource which takes its value from a static \a value.
* \see fromModelParameter()
* \see fromChildOutput()
* \see fromExpression()
*/
static QgsProcessingModelChildParameterSource fromStaticValue( const QVariant &value );
/**
* Returns a new QgsProcessingModelChildParameterSource which takes its value from a parent model parameter.
* \see fromStaticValue()
* \see fromChildOutput()
* \see fromExpression()
*/
static QgsProcessingModelChildParameterSource fromModelParameter( const QString &parameterName );
/**
* Returns a new QgsProcessingModelChildParameterSource which takes its value from an output generated by a child algorithm.
* \see fromStaticValue()
* \see fromModelParameter()
* \see fromExpression()
*/
static QgsProcessingModelChildParameterSource fromChildOutput( const QString &childId, const QString &outputName );
/**
* Returns a new QgsProcessingModelChildParameterSource which takes its value from an expression. The expression
* is evaluated just before the child algorithm executes, and can use functions available
* in its expression context to include results calculated from the child algorithms already
* executed by the model.
* \see fromStaticValue()
* \see fromChildOutput()
* \see fromModelParameter()
*/
static QgsProcessingModelChildParameterSource fromExpression( const QString &expression );
/**
* Returns the parameter value's source.
*/
Source source() const;
/**
* Returns the source's static value. This is only used when the source() is StaticValue.
* \see setStaticValue()
*/
QVariant staticValue() const { return mStaticValue; }
/**
* Sets the source's static value. Calling this will also change the source() to StaticValue.
* \see staticValue()
*/
void setStaticValue( const QVariant &value ) { mStaticValue = value; mSource = StaticValue; }
/**
* Returns the source's model parameter name. This is only used when the source() is ModelParameter.
* \see setParameterName()
*/
QString parameterName() const { return mParameterName; }
/**
* Sets the source's model parameter \a name. Calling this will also change the source() to ModelParameter.
* \see parameterName()
*/
void setParameterName( const QString &name ) { mParameterName = name; mSource = ModelParameter; }
/**
* Returns the source's child algorithm ID from which the output value will be taken. This is only used when the source() is ChildOutput.
* \see setOutputChildId()
* \see outputName()
*/
QString outputChildId() const { return mChildId; }
/**
* Sets the source's child algorithm \a id from which the output value will be taken. Calling this will also change the source() to ChildOutput.
* \see parameterName()
* \see setOutputName()
*/
void setOutputChildId( const QString &id ) { mChildId = id; mSource = ChildOutput; }
/**
* Returns the source's child algorithm output name from which the output value will be taken. This is only used when the source() is ChildOutput.
* \see setOutputName()
* \see outputChildId()
*/
QString outputName() const { return mOutputName; }
/**
* Sets the source's child algorithm output \a name from which the output value will be taken. Calling this will also change the source() to ChildOutput.
* \see outputName()
* \see setOutputChildId()
*/
void setOutputName( const QString &name ) { mOutputName = name; mSource = ChildOutput; }
/**
* Returns the source's expression. This is only used when the source() is Expression.
* \see setExpression()
*/
QString expression() const { return mExpression; }
/**
* Sets the source's expression. Calling this will also change the source() to Expression.
* The expression is evaluated just before the child algorithm executes, and can use functions available
* in its expression context to include results calculated from the child algorithms already
* executed by the model.
* \see expression()
*/
void setExpression( const QString &expression ) { mExpression = expression; mSource = Expression; }
/**
* Saves this source to a QVariant.
* \see loadVariant()
*/
QVariant toVariant() const;
/**
* Loads this source from a QVariantMap.
* \see toVariant()
*/
bool loadVariant( const QVariantMap &map );
/**
* Attempts to convert the source to executable Python code.
*/
QString asPythonCode() const;
private:
Source mSource = StaticValue;
QVariant mStaticValue;
QString mParameterName;
QString mChildId;
QString mOutputName;
QString mExpression;
};
#ifndef SIP_RUN
//! List of child parameter sources
typedef QList< QgsProcessingModelChildParameterSource > QgsProcessingModelChildParameterSources;
#endif
///@endcond
#endif // QGSPROCESSINGMODELCHILDPARAMETERSOURCE_H

View File

@ -0,0 +1,62 @@
/***************************************************************************
qgsprocessingmodelcomponent.cpp
-------------------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsprocessingmodelcomponent.h"
///@cond NOT_STABLE
QgsProcessingModelComponent::QgsProcessingModelComponent( const QString &description )
: mDescription( description )
{}
QString QgsProcessingModelComponent::description() const
{
return mDescription;
}
void QgsProcessingModelComponent::setDescription( const QString &description )
{
mDescription = description;
}
QPointF QgsProcessingModelComponent::position() const
{
return mPosition;
}
void QgsProcessingModelComponent::setPosition( const QPointF &position )
{
mPosition = position;
}
void QgsProcessingModelComponent::saveCommonProperties( QVariantMap &map ) const
{
map.insert( QStringLiteral( "component_pos_x" ), mPosition.x() );
map.insert( QStringLiteral( "component_pos_y" ), mPosition.y() );
map.insert( QStringLiteral( "component_description" ), mDescription );
}
void QgsProcessingModelComponent::restoreCommonProperties( const QVariantMap &map )
{
QPointF pos;
pos.setX( map.value( QStringLiteral( "component_pos_x" ) ).toDouble() );
pos.setY( map.value( QStringLiteral( "component_pos_y" ) ).toDouble() );
mPosition = pos;
mDescription = map.value( QStringLiteral( "component_description" ) ).toString();
}
///@endcond

View File

@ -0,0 +1,94 @@
/***************************************************************************
qgsprocessingmodelcomponent.h
-----------------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSPROCESSINGMODELCOMPONENT_H
#define QGSPROCESSINGMODELCOMPONENT_H
#include "qgis_core.h"
#include "qgis.h"
#include <QPointF>
///@cond NOT_STABLE
/**
* Represents a component of a model algorithm.
* \since QGIS 3.0
* \ingroup core
*/
class CORE_EXPORT QgsProcessingModelComponent
{
public:
/**
* Returns the friendly description text for the component.
* \see setDescription()
*/
QString description() const;
/**
* Sets the friendly \a description text for the component.
* \see description()
*/
void setDescription( const QString &description );
/**
* Returns the position of the model component within the graphical modeler.
* \see setPosition()
*/
QPointF position() const;
/**
* Sets the \a position of the model component within the graphical modeler.
* \see position()
*/
void setPosition( const QPointF &position );
protected:
//! Only subclasses can be created
QgsProcessingModelComponent( const QString &description = QString() );
//! Copies are protected to avoid slicing
QgsProcessingModelComponent( const QgsProcessingModelComponent &other ) = default;
//! Copies are protected to avoid slicing
QgsProcessingModelComponent &operator=( const QgsProcessingModelComponent &other ) = default;
/**
* Saves the component properties to a QVariantMap.
* \see restoreCommonProperties()
*/
void saveCommonProperties( QVariantMap &map ) const;
/**
* Restores the component properties from a QVariantMap.
* \see saveCommonProperties()
*/
void restoreCommonProperties( const QVariantMap &map );
private:
//! Position of component within model
QPointF mPosition;
QString mDescription;
};
///@endcond
#endif // QGSPROCESSINGMODELCOMPONENT_H

View File

@ -0,0 +1,47 @@
/***************************************************************************
qgsprocessingmodeloutput.cpp
----------------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsprocessingmodeloutput.h"
///@cond NOT_STABLE
QgsProcessingModelOutput::QgsProcessingModelOutput( const QString &name, const QString &description )
: QgsProcessingModelComponent( description )
, mName( name )
{}
QVariant QgsProcessingModelOutput::toVariant() const
{
QVariantMap map;
map.insert( QStringLiteral( "name" ), mName );
map.insert( QStringLiteral( "child_id" ), mChildId );
map.insert( QStringLiteral( "output_name" ), mOutputName );
saveCommonProperties( map );
return map;
}
bool QgsProcessingModelOutput::loadVariant( const QVariantMap &map )
{
mName = map.value( QStringLiteral( "name" ) ).toString();
mChildId = map.value( QStringLiteral( "child_id" ) ).toString();
mOutputName = map.value( QStringLiteral( "output_name" ) ).toString();
restoreCommonProperties( map );
return true;
}
///@endcond

View File

@ -0,0 +1,98 @@
/***************************************************************************
qgsprocessingmodeloutput.h
--------------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSPROCESSINGMODELOUTPUT_H
#define QGSPROCESSINGMODELOUTPUT_H
#include "qgis_core.h"
#include "qgis.h"
#include "qgsprocessingmodelcomponent.h"
///@cond NOT_STABLE
/**
* Represents a final output created by the model.
* \since QGIS 3.0
* \ingroup core
*/
class CORE_EXPORT QgsProcessingModelOutput : public QgsProcessingModelComponent
{
public:
/**
* Constructor for QgsProcessingModelOutput with the specified \a name and \a description.
*/
QgsProcessingModelOutput( const QString &name = QString(), const QString &description = QString() );
/**
* Returns the model output name.
* \see setName()
*/
QString name() const { return mName; }
/**
* Sets the model output \a name.
* \see name()
*/
void setName( const QString &name ) { mName = name; }
/**
* Returns the child algorithm ID from which this output is generated.
* \see setChildId()
*/
QString childId() const { return mChildId; }
/**
* Sets the child algorithm \a id from which this output is generated.
* \see childId()
*/
void setChildId( const QString &id ) { mChildId = id; }
/**
* Returns the child algorithm output name from which this output is generated.
* \see setOutputName()
*/
QString childOutputName() const { return mOutputName; }
/**
* Sets the child algorithm output \a name from which this output is generated.
* \see outputName()
*/
void setChildOutputName( const QString &name ) { mOutputName = name; }
/**
* Saves this output to a QVariant.
* \see loadVariant()
*/
QVariant toVariant() const;
/**
* Loads this output from a QVariantMap.
* \see toVariant()
*/
bool loadVariant( const QVariantMap &map );
private:
QString mName;
QString mChildId;
QString mOutputName;
};
///@endcond
#endif // QGSPROCESSINGMODELOUTPUT_H

View File

@ -0,0 +1,44 @@
/***************************************************************************
qgsprocessingmodelparameter.cpp
------------------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsprocessingmodelparameter.h"
///@cond NOT_STABLE
QgsProcessingModelParameter::QgsProcessingModelParameter( const QString &parameterName )
: QgsProcessingModelComponent()
, mParameterName( parameterName )
{
}
QVariant QgsProcessingModelParameter::toVariant() const
{
QVariantMap map;
map.insert( QStringLiteral( "name" ), mParameterName );
saveCommonProperties( map );
return map;
}
bool QgsProcessingModelParameter::loadVariant( const QVariantMap &map )
{
mParameterName = map.value( QStringLiteral( "name" ) ).toString();
restoreCommonProperties( map );
return true;
}
///@endcond

View File

@ -0,0 +1,77 @@
/***************************************************************************
qgsprocessingmodelparameter.h
-----------------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSPROCESSINGMODELPARAMETER_H
#define QGSPROCESSINGMODELPARAMETER_H
#include "qgis_core.h"
#include "qgis.h"
#include "qgsprocessingmodelcomponent.h"
///@cond NOT_STABLE
/**
* Represents an input parameter used by the model.
* \since QGIS 3.0
* \ingroup core
*/
class CORE_EXPORT QgsProcessingModelParameter : public QgsProcessingModelComponent
{
public:
/**
* Constructor for QgsProcessingModelParameter. The parameter name should match one of the
* parameters from the parent model.
*/
QgsProcessingModelParameter( const QString &parameterName = QString() );
/**
* Returns the associated parameter name. The parameter name should match one of the
* parameters from the parent model.
* \see parameterName()
*/
QString parameterName() const { return mParameterName; }
/**
* Sets the associated parameter name. The parameter name should match one of the
* parameters from the parent model.
* \see parameterName()
*/
void setParameterName( const QString &name ) { mParameterName = name; }
/**
* Saves this parameter to a QVariant.
* \see loadVariant()
*/
QVariant toVariant() const;
/**
* Loads this parameter from a QVariantMap.
* \see toVariant()
*/
bool loadVariant( const QVariantMap &map );
private:
QString mParameterName;
};
///@endcond
#endif // QGSPROCESSINGMODELPARAMETER_H

View File

@ -74,8 +74,8 @@ void QgsNativeAlgorithms::loadAlgorithms()
QgsCentroidAlgorithm::QgsCentroidAlgorithm()
{
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Centroids" ), QgsProcessingParameterDefinition::TypeVectorPoint ) );
addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Centroids" ), QgsProcessingParameterDefinition::TypeVectorPoint ) );
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Centroids" ), QgsProcessing::TypeVectorPoint ) );
addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Centroids" ), QgsProcessing::TypeVectorPoint ) );
}
QString QgsCentroidAlgorithm::shortHelpString() const
@ -151,8 +151,8 @@ QgsBufferAlgorithm::QgsBufferAlgorithm()
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "MITRE_LIMIT" ), QObject::tr( "Miter limit" ), QgsProcessingParameterNumber::Double, 2, false, 1 ) );
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "DISSOLVE" ), QObject::tr( "Dissolve result" ), false ) );
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Buffered" ), QgsProcessingParameterDefinition::TypeVectorPolygon ) );
addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Buffered" ), QgsProcessingParameterDefinition::TypeVectorPoint ) );
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Buffered" ), QgsProcessing::TypeVectorPolygon ) );
addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Buffered" ), QgsProcessing::TypeVectorPoint ) );
}
QString QgsBufferAlgorithm::shortHelpString() const
@ -415,7 +415,7 @@ QVariantMap QgsDissolveAlgorithm::processAlgorithm( const QVariantMap &parameter
QgsClipAlgorithm::QgsClipAlgorithm()
{
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "OVERLAY" ), QObject::tr( "Clip layer" ), QList< int >() << QgsProcessingParameterDefinition::TypeVectorPolygon ) );
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "OVERLAY" ), QObject::tr( "Clip layer" ), QList< int >() << QgsProcessing::TypeVectorPolygon ) );
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Clipped" ) ) );
addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Clipped" ) ) );
@ -799,7 +799,7 @@ QgsExtractByExpressionAlgorithm::QgsExtractByExpressionAlgorithm()
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Matching features" ) ) );
addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Matching (expression)" ) ) );
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "FAIL_OUTPUT" ), QObject::tr( "Non-matching" ),
QgsProcessingParameterDefinition::TypeVectorAny, QVariant(), true ) );
QgsProcessing::TypeVectorAny, QVariant(), true ) );
addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "FAIL_OUTPUT" ), QObject::tr( "Non-matching (expression)" ) ) );
}
@ -930,7 +930,7 @@ QgsExtractByAttributeAlgorithm::QgsExtractByAttributeAlgorithm()
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Extracted (attribute)" ) ) );
addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Matching (attribute)" ) ) );
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "FAIL_OUTPUT" ), QObject::tr( "Extracted (non-matching)" ),
QgsProcessingParameterDefinition::TypeVectorAny, QVariant(), true ) );
QgsProcessing::TypeVectorAny, QVariant(), true ) );
addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "FAIL_OUTPUT" ), QObject::tr( "Non-matching (attribute)" ) ) );
}
@ -1035,8 +1035,7 @@ QVariantMap QgsExtractByAttributeAlgorithm::processAlgorithm( const QVariantMap
QgsExpression expression( expr );
if ( expression.hasParserError() )
{
// raise GeoAlgorithmExecutionException(expression.parserErrorString())
return QVariantMap();
throw QgsProcessingException( expression.parserErrorString() );
}
QgsExpressionContext expressionContext = createExpressionContext( parameters, context );

View File

@ -0,0 +1,61 @@
/***************************************************************************
qgsprocessing.h
---------------
begin : July 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSPROCESSING_H
#define QGSPROCESSING_H
#include "qgis_core.h"
#include "qgis.h"
#include "qgsprocessingparameters.h"
//
// Output definitions
//
/**
* \class QgsProcessing
* \ingroup core
*
* Contains enumerations and other constants for use in processing algorithms
* and parameters.
*
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessing
{
public:
//! Layer types enum
enum LayerType
{
TypeAny = -2, //!< Any layer
TypeVectorAny = -1, //!< Any vector layer with geometry
TypeVectorPoint = 0, //!< Vector point layers
TypeVectorLine = 1, //!< Vector line layers
TypeVectorPolygon = 2, //!< Vector polygon layers
TypeRaster = 3, //!< Raster layers
TypeFile = 4, //!< Files
TypeTable = 5, //!< Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink has no geometry.
};
};
#endif // QGSPROCESSING_H

View File

@ -503,6 +503,11 @@ QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVa
return QgsProcessingParameters::parameterAsSource( parameterDefinition( name ), parameters, context );
}
QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
{
return QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback );
}
QgsMapLayer *QgsProcessingAlgorithm::parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsLayer( parameterDefinition( name ), parameters, context );
@ -513,9 +518,9 @@ QgsRasterLayer *QgsProcessingAlgorithm::parameterAsRasterLayer( const QVariantMa
return QgsProcessingParameters::parameterAsRasterLayer( parameterDefinition( name ), parameters, context );
}
QString QgsProcessingAlgorithm::parameterAsRasterOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
QString QgsProcessingAlgorithm::parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsRasterOutputLayer( parameterDefinition( name ), parameters, context );
return QgsProcessingParameters::parameterAsOutputLayer( parameterDefinition( name ), parameters, context );
}
QString QgsProcessingAlgorithm::parameterAsFileOutput( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const

View File

@ -30,6 +30,7 @@
class QgsProcessingProvider;
class QgsProcessingFeedback;
class QgsFeatureSink;
class QgsProcessingFeedback;
/**
@ -485,7 +486,7 @@ class CORE_EXPORT QgsProcessingAlgorithm
const QgsFields &fields, QgsWkbTypes::Type geometryType = QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() ) const SIP_FACTORY;
/**
* Evaluates the parameter with matching \a definition to a feature source.
* Evaluates the parameter with matching \a name to a feature source.
*
* Sources will either be taken from \a context's active project, or loaded from external
* sources and stored temporarily in the \a context.
@ -494,6 +495,21 @@ class CORE_EXPORT QgsProcessingAlgorithm
*/
QgsProcessingFeatureSource *parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const SIP_FACTORY;
/**
* Evaluates the parameter with matching \a name to a source vector layer file path of compatible format.
*
* If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the
* \a compatibleFormats argument, then the layer will first be exported to a compatible format
* in a temporary location. The function will then return the path to that temporary file.
*
* \a compatibleFormats should consist entirely of lowercase file extensions, e.g. 'shp'.
*
* The \a preferredFormat argument is used to specify to desired file extension to use when a temporary
* layer export is required.
*/
QString parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name,
QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = nullptr );
/**
* Evaluates the parameter with matching \a name to a map layer.
*
@ -513,9 +529,9 @@ class CORE_EXPORT QgsProcessingAlgorithm
QgsRasterLayer *parameterAsRasterLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a raster output layer destination.
* Evaluates the parameter with matching \a name to a output layer destination.
*/
QString parameterAsRasterOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
QString parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
/**
* Evaluates the parameter with matching \a name to a file based output destination.

View File

@ -1,977 +0,0 @@
/***************************************************************************
qgsprocessingmodelalgorithm.h
-----------------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSPROCESSINGMODELALGORITHM_H
#define QGSPROCESSINGMODELALGORITHM_H
#include "qgis_core.h"
#include "qgis.h"
#include "qgsprocessingalgorithm.h"
#include "qgsprocessingcontext.h"
///@cond NOT_STABLE
/**
* \class QgsProcessingModelAlgorithm
* \ingroup core
* Model based algorithm with processing.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
{
public:
/**
* Source for the value of a parameter for a child algorithm within a model.
* \since QGIS 3.0
* \ingroup core
*/
class CORE_EXPORT ChildParameterSource
{
public:
//! Possible parameter value sources
enum Source
{
ModelParameter, //!< Parameter value is taken from a parent model parameter
ChildOutput, //!< Parameter value is taken from an output generated by a child algorithm
StaticValue, //!< Parameter value is a static value
Expression, //!< Parameter value is taken from an expression, evaluated just before the algorithm runs
};
/**
* Constructor for ChildParameterSource. It is recommended that the static methods
* fromStaticValue(), fromModelParameter(), fromChildOutput() and fromExpression() are used instead.
*/
ChildParameterSource() = default;
bool operator==( const QgsProcessingModelAlgorithm::ChildParameterSource &other ) const;
bool operator!=( const QgsProcessingModelAlgorithm::ChildParameterSource &other ) const
{
return !operator==( other );
}
/**
* Returns a new ChildParameterSource which takes its value from a static \a value.
* \see fromModelParameter()
* \see fromChildOutput()
* \see fromExpression()
*/
static QgsProcessingModelAlgorithm::ChildParameterSource fromStaticValue( const QVariant &value );
/**
* Returns a new ChildParameterSource which takes its value from a parent model parameter.
* \see fromStaticValue()
* \see fromChildOutput()
* \see fromExpression()
*/
static QgsProcessingModelAlgorithm::ChildParameterSource fromModelParameter( const QString &parameterName );
/**
* Returns a new ChildParameterSource which takes its value from an output generated by a child algorithm.
* \see fromStaticValue()
* \see fromModelParameter()
* \see fromExpression()
*/
static QgsProcessingModelAlgorithm::ChildParameterSource fromChildOutput( const QString &childId, const QString &outputName );
/**
* Returns a new ChildParameterSource which takes its value from an expression. The expression
* is evaluated just before the child algorithm executes, and can use functions available
* in its expression context to include results calculated from the child algorithms already
* executed by the model.
* \see fromStaticValue()
* \see fromChildOutput()
* \see fromModelParameter()
*/
static QgsProcessingModelAlgorithm::ChildParameterSource fromExpression( const QString &expression );
/**
* Returns the parameter value's source.
*/
Source source() const;
/**
* Returns the source's static value. This is only used when the source() is StaticValue.
* \see setStaticValue()
*/
QVariant staticValue() const { return mStaticValue; }
/**
* Sets the source's static value. Calling this will also change the source() to StaticValue.
* \see staticValue()
*/
void setStaticValue( const QVariant &value ) { mStaticValue = value; mSource = StaticValue; }
/**
* Returns the source's model parameter name. This is only used when the source() is ModelParameter.
* \see setParameterName()
*/
QString parameterName() const { return mParameterName; }
/**
* Sets the source's model parameter \a name. Calling this will also change the source() to ModelParameter.
* \see parameterName()
*/
void setParameterName( const QString &name ) { mParameterName = name; mSource = ModelParameter; }
/**
* Returns the source's child algorithm ID from which the output value will be taken. This is only used when the source() is ChildOutput.
* \see setOutputChildId()
* \see outputName()
*/
QString outputChildId() const { return mChildId; }
/**
* Sets the source's child algorithm \a id from which the output value will be taken. Calling this will also change the source() to ChildOutput.
* \see parameterName()
* \see setOutputName()
*/
void setOutputChildId( const QString &id ) { mChildId = id; mSource = ChildOutput; }
/**
* Returns the source's child algorithm output name from which the output value will be taken. This is only used when the source() is ChildOutput.
* \see setOutputName()
* \see outputChildId()
*/
QString outputName() const { return mOutputName; }
/**
* Sets the source's child algorithm output \a name from which the output value will be taken. Calling this will also change the source() to ChildOutput.
* \see outputName()
* \see setOutputChildId()
*/
void setOutputName( const QString &name ) { mOutputName = name; mSource = ChildOutput; }
/**
* Returns the source's expression. This is only used when the source() is Expression.
* \see setExpression()
*/
QString expression() const { return mExpression; }
/**
* Sets the source's expression. Calling this will also change the source() to Expression.
* The expression is evaluated just before the child algorithm executes, and can use functions available
* in its expression context to include results calculated from the child algorithms already
* executed by the model.
* \see expression()
*/
void setExpression( const QString &expression ) { mExpression = expression; mSource = Expression; }
/**
* Saves this source to a QVariant.
* \see loadVariant()
*/
QVariant toVariant() const;
/**
* Loads this source from a QVariantMap.
* \see toVariant()
*/
bool loadVariant( const QVariantMap &map );
/**
* Attempts to convert the source to executable Python code.
*/
QString asPythonCode() const;
private:
Source mSource = StaticValue;
QVariant mStaticValue;
QString mParameterName;
QString mChildId;
QString mOutputName;
QString mExpression;
};
#ifndef SIP_RUN
//! List of child parameter sources
typedef QList< QgsProcessingModelAlgorithm::ChildParameterSource > ChildParameterSources;
#endif
/**
* Represents a component of a model algorithm.
* \since QGIS 3.0
* \ingroup core
*/
class CORE_EXPORT Component
{
public:
/**
* Returns the friendly description text for the component.
* \see setDescription()
*/
QString description() const;
/**
* Sets the friendly \a description text for the component.
* \see description()
*/
void setDescription( const QString &description );
/**
* Returns the position of the model component within the graphical modeler.
* \see setPosition()
*/
QPointF position() const;
/**
* Sets the \a position of the model component within the graphical modeler.
* \see position()
*/
void setPosition( const QPointF &position );
protected:
//! Only subclasses can be created
Component( const QString &description = QString() );
//! Copies are protected to avoid slicing
Component( const QgsProcessingModelAlgorithm::Component &other ) = default;
//! Copies are protected to avoid slicing
Component &operator=( const QgsProcessingModelAlgorithm::Component &other ) = default;
/**
* Saves the component properties to a QVariantMap.
* \see restoreCommonProperties()
*/
void saveCommonProperties( QVariantMap &map ) const;
/**
* Restores the component properties from a QVariantMap.
* \see saveCommonProperties()
*/
void restoreCommonProperties( const QVariantMap &map );
private:
//! Position of component within model
QPointF mPosition;
QString mDescription;
};
/**
* Represents an input parameter used by the model.
* \since QGIS 3.0
* \ingroup core
*/
class CORE_EXPORT ModelParameter : public QgsProcessingModelAlgorithm::Component
{
public:
/**
* Constructor for ModelParameter. The parameter name should match one of the
* parameters from the parent model.
*/
ModelParameter( const QString &parameterName = QString() );
/**
* Returns the associated parameter name. The parameter name should match one of the
* parameters from the parent model.
* \see parameterName()
*/
QString parameterName() const { return mParameterName; }
/**
* Sets the associated parameter name. The parameter name should match one of the
* parameters from the parent model.
* \see parameterName()
*/
void setParameterName( const QString &name ) { mParameterName = name; }
/**
* Saves this parameter to a QVariant.
* \see loadVariant()
*/
QVariant toVariant() const;
/**
* Loads this parameter from a QVariantMap.
* \see toVariant()
*/
bool loadVariant( const QVariantMap &map );
private:
QString mParameterName;
};
/**
* Represents a final output created by the model.
* \since QGIS 3.0
* \ingroup core
*/
class CORE_EXPORT ModelOutput : public QgsProcessingModelAlgorithm::Component
{
public:
/**
* Constructor for ModelOutput with the specified \a name and \a description.
*/
ModelOutput( const QString &name = QString(), const QString &description = QString() );
/**
* Returns the model output name.
* \see setName()
*/
QString name() const { return mName; }
/**
* Sets the model output \a name.
* \see name()
*/
void setName( const QString &name ) { mName = name; }
/**
* Returns the child algorithm ID from which this output is generated.
* \see setChildId()
*/
QString childId() const { return mChildId; }
/**
* Sets the child algorithm \a id from which this output is generated.
* \see childId()
*/
void setChildId( const QString &id ) { mChildId = id; }
/**
* Returns the child algorithm output name from which this output is generated.
* \see setOutputName()
*/
QString childOutputName() const { return mOutputName; }
/**
* Sets the child algorithm output \a name from which this output is generated.
* \see outputName()
*/
void setChildOutputName( const QString &name ) { mOutputName = name; }
/**
* Saves this output to a QVariant.
* \see loadVariant()
*/
QVariant toVariant() const;
/**
* Loads this output from a QVariantMap.
* \see toVariant()
*/
bool loadVariant( const QVariantMap &map );
private:
QString mName;
QString mChildId;
QString mOutputName;
};
/**
* Child algorithm representing a single component of a QgsProcessingModelAlgorithm.
* \since QGIS 3.0
* \ingroup core
*/
class CORE_EXPORT ChildAlgorithm : public QgsProcessingModelAlgorithm::Component
{
public:
/**
* Constructor for ChildAlgorithm. The \a algorithmId parameter
* should be set to a QgsProcessingAlgorithm algorithm ID.
*/
ChildAlgorithm( const QString &algorithmId = QString() );
/**
* Returns the child algorithm's unique ID string, used the identify
* this child algorithm within its parent model.
* \see setChildId()
* \see generateChildId()
*/
QString childId() const;
/**
* Sets the child algorithm's unique \a id string, used the identify
* this child algorithm within its parent model.
* \see childId()
* \see generateChildId()
*/
void setChildId( const QString &id );
/**
* Automatically generates a unique childId() for the algorithm,
* avoiding child IDs which are already present in \a model.
* \see childId()
* \see setChildId()
*/
void generateChildId( const QgsProcessingModelAlgorithm &model );
/**
* Returns the underlying child algorithm's ID.
* \see algorithm()
* \see setAlgorithmId()
*/
QString algorithmId() const;
/**
* Sets the underlying child algorithm's ID. This
* should be set to an existing QgsProcessingAlgorithm algorithm ID.
* \see algorithm()
* \see algorithmId()
*/
void setAlgorithmId( const QString &algorithmId );
/**
* Returns the underlying child algorithm, or a nullptr
* if a matching algorithm is not available.
* \see algorithmId()
*/
const QgsProcessingAlgorithm *algorithm() const;
/**
* Returns a map of parameter sources. The keys are the child algorithm
* parameter names, the values are the sources for that parameter.
* \see setParameterSources()
* \see addParameterSources()
*/
QMap< QString, QList< QgsProcessingModelAlgorithm::ChildParameterSource > > parameterSources() const;
/**
* Sets the map of parameter \a sources. The keys are the child algorithm
* parameter names, the values are the sources for that parameter.
* \see parameterSources()
* \see addParameterSources()
*/
void setParameterSources( const QMap< QString, QList< QgsProcessingModelAlgorithm::ChildParameterSource > > &sources );
/**
* Adds a parameter source. The \a name argument should match
* one of the child algorithm's parameter names, and the \a sources
* argument is used to set the sources for that parameter.
*
* Any existing parameter sources with matching name will be replaced.
* \see parameterSources()
* \see setParameterSources()
*/
void addParameterSources( const QString &name, const QList< QgsProcessingModelAlgorithm::ChildParameterSource > &source );
/**
* Returns true if the child algorithm is active.
* \see setActive()
*/
bool isActive() const;
/**
* Sets whether the child algorithm is active.
* \see isActive()
*/
void setActive( bool active );
/**
* Returns the list of child algorithms from the parent model on which this
* algorithm is dependent. The returned list contains the id() of the
* dependent algorithms.
* \see setDependencies()
*/
QStringList dependencies() const;
/**
* Sets the list of child algorithms from the parent model on which this
* algorithm is dependent. The list should contain the id() of the
* dependent algorithms.
* \see dependencies()
*/
void setDependencies( const QStringList &dependencies );
/**
* Returns true if the list of parameters for this algorithm should be collapsed
* in the graphical modeller.
* \see setParametersCollapsed()
* \see outputsCollapsed()
*/
bool parametersCollapsed() const;
/**
* Sets whether the list of parameters for this algorithm should be collapsed
* in the graphical modeller.
* \see parametersCollapsed()
* \see setOutputsCollapsed()
*/
void setParametersCollapsed( bool collapsed );
/**
* Returns true if the list of outputs for this algorithm should be collapsed
* in the graphical modeller.
* \see setParametersCollapsed()
* \see parametersCollapsed()
*/
bool outputsCollapsed() const;
/**
* Sets whether the list of outputs for this algorithm should be collapsed
* in the graphical modeller.
* \see outputsCollapsed()
* \see setParametersCollapsed()
*/
void setOutputsCollapsed( bool collapsed );
/**
* Returns the map of final model outputs which are generated by this child algorithm.
* The keys are the output names from this child algorithm. Only outputs which are
* part of the final outputs from the model are included in this map.
* \see setModelOutputs()
* \see modelOutput()
*/
QMap<QString, QgsProcessingModelAlgorithm::ModelOutput> modelOutputs() const;
/**
* Returns the final model output with matching \a name. If no output
* exists with the name, a new one will be created and returned.
*
* If child model outputs are altered by this method, QgsProcessingModelAlgorithm::updateDestinationParameters()
* must be called on the parent model.
*
* \see modelOutputs()
* \see setModelOutputs()
*/
QgsProcessingModelAlgorithm::ModelOutput &modelOutput( const QString &name );
/**
* Sets the map of final model \a outputs which are generated by this child algorithm.
* Only outputs which are part of the final outputs from the model should be included in this map.
*
* If child model outputs are altered by this method, QgsProcessingModelAlgorithm::updateDestinationParameters()
* must be called on the parent model.
*
* \see modelOutputs()
*/
void setModelOutputs( const QMap<QString, QgsProcessingModelAlgorithm::ModelOutput> &outputs );
/**
* Saves this child to a QVariant.
* \see loadVariant()
*/
QVariant toVariant() const;
/**
* Loads this child from a QVariant.
* \see toVariant()
*/
bool loadVariant( const QVariant &child );
/**
* Attempts to convert the child to executable Python code.
*/
QString asPythonCode() const;
private:
QString mId;
QString mAlgorithmId;
//! A map of parameter sources. Keys are algorithm parameter names.
QMap< QString, QgsProcessingModelAlgorithm::ChildParameterSources > mParams;
//! A map of ModelOutput for final model outputs generated by this child algorithm. Keys are output names from the child algorithm.
QMap< QString, QgsProcessingModelAlgorithm::ModelOutput > mModelOutputs;
bool mActive = true;
//! List of child algorithms from the parent model on which this algorithm is dependent
QStringList mDependencies;
//! Whether list of parameters should be collapsed in the graphical modeller
bool mParametersCollapsed = true;
//! Whether list of outputs should be collapsed in the graphical modeller
bool mOutputsCollapsed = true;
};
/**
* Constructor for QgsProcessingModelAlgorithm.
*/
QgsProcessingModelAlgorithm( const QString &name = QString(), const QString &group = QString() );
QString name() const override;
QString displayName() const override;
QString group() const override;
QIcon icon() const override;
QString svgIconPath() const override;
QString shortHelpString() const override;
QString helpUrl() const override;
bool canExecute( QString *errorMessage SIP_OUT = nullptr ) const override;
QString asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const override;
QgsProcessingModelAlgorithm *create() const override SIP_FACTORY;
/**
* Sets the model \a name.
* \see name()
*/
void setName( const QString &name );
/**
* Sets the model \a group.
* \see group()
*/
void setGroup( const QString &group );
/**
* Returns the map of child algorithms contained in the model. The keys
* are the child algorithm ids (see QgsProcessingModelAlgorithm::ChildAlgorithm::childId()).
* \see childAlgorithm()
* \see setChildAlgorithms()
* \see addChildAlgorithm()
*/
QMap<QString, QgsProcessingModelAlgorithm::ChildAlgorithm> childAlgorithms() const;
/**
* Sets the map of child algorithms contained in the model. The keys
* are the child algorithm ids (see QgsProcessingModelAlgorithm::ChildAlgorithm::childId()).
* All existing child algorithms will be replaced.
* \see childAlgorithms()
* \see childAlgorithm()
* \see setChildAlgorithm()
* \see addChildAlgorithm()
*/
void setChildAlgorithms( const QMap<QString, QgsProcessingModelAlgorithm::ChildAlgorithm> &childAlgorithms );
/**
* Sets the child \a algorithm within the model. If a child algorithm already
* exists in the model with the same child ID then that algorithm will be replaced.
* \see addChildAlgorithm()
* \see setChildAlgorithms()
*/
void setChildAlgorithm( const QgsProcessingModelAlgorithm::ChildAlgorithm &algorithm );
/**
* Adds a new child \a algorithm to the model. If a child algorithm already exists
* in the model with the same child ID then \a algorithm will be assigned a new
* autogenerated unique ID.
* The assigned child ID will be returned.
* \see childAlgorithms()
* \see childAlgorithm()
* \see setChildAlgorithm()
* \see setChildAlgorithms()
*/
QString addChildAlgorithm( QgsProcessingModelAlgorithm::ChildAlgorithm &algorithm );
/**
* Returns the child algorithm with matching \a id. If no child algorithm exists with
* this ID a new algorithm will be added to the model and returned.
* \see addChildAlgorithm()
* \see childAlgorithms()
*/
QgsProcessingModelAlgorithm::ChildAlgorithm &childAlgorithm( const QString &id );
/**
* Attempts to remove the child algorithm with matching \a id.
* Returns true if the algorithm could be removed, or false
* if the algorithm could not be removed (e.g. due to other
* child algorithms depending on it).
* \see deactivateChildAlgorithm()
*/
bool removeChildAlgorithm( const QString &id );
/**
* Deactivates the child algorithm with matching \a id.
* All other child algorithms which depend on the child
* algorithm will also be deactivated.
* \see removeChildAlgorithm()
* \see activateChildAlgorithm()
*/
void deactivateChildAlgorithm( const QString &id );
/**
* Attempts to activate the child algorithm with matching \a id.
* If any child algorithms on which the child depends are not active,
* then the child will not be activated and false will be returned.
* \see deactivateChildAlgorithm()
*/
bool activateChildAlgorithm( const QString &id );
/**
* Returns a list of the child algorithm IDs depending on the child
* algorithm with the specified \a childId.
* \see dependsOnChildAlgorithms()
*/
QSet< QString > dependentChildAlgorithms( const QString &childId ) const;
/**
* Returns a list of the child algorithm IDs on which the child
* algorithm with the specified \a childId depends upon.
* \see dependentChildAlgorithms()
*/
QSet< QString > dependsOnChildAlgorithms( const QString &childId ) const;
/**
* Adds a new parameter to the model, with the specified \a definition and graphical \a component.
* Ownership of \a definition is transferred to the model.
* \see updateModelParameter()
* \see removeModelParameter()
*/
void addModelParameter( QgsProcessingParameterDefinition *definition SIP_TRANSFER, const QgsProcessingModelAlgorithm::ModelParameter &component );
/**
* Replaces the definition of an existing parameter (by parameter name) with a new \a definition. Ownership of
* \a definition is transferred to the model, and any existing parameter is deleted.
* \see addModelParameter()
* \see removeModelParameter()
*/
void updateModelParameter( QgsProcessingParameterDefinition *definition SIP_TRANSFER );
/**
* Removes an existing model parameter by \a name. The definition of the matching parameter
* is deleted.
* \see addModelParameter()
* \see updateModelParameter()
*/
void removeModelParameter( const QString &name );
/**
* 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() ).
* \see setParameterComponent()
* \see parameterComponent()
*/
QMap<QString, QgsProcessingModelAlgorithm::ModelParameter> parameterComponents() const;
/**
* Sets the map of parameter components used by the model. The keys
* should match the algorithm's parameter names (see parameterDefinitions() ).
* All existing parameter components will be replaced.
* \see parameterComponents()
* \see setParameterComponent()
* \see parameterComponent()
*/
void setParameterComponents( const QMap<QString, QgsProcessingModelAlgorithm::ModelParameter> &parameterComponents );
/**
* Sets a parameter \a component for the model. If a parameter component already
* exists in the model with the same parameter name then that component will be replaced.
* \see parameterComponents()
* \see setParameterComponents()
* \see parameterComponent()
*/
void setParameterComponent( const QgsProcessingModelAlgorithm::ModelParameter &component );
/**
* Returns the parameter component with matching \a name. If no parameter component exists with
* this name a new component will be added to the model and returned.
* \see parameterComponents()
* \see setParameterComponents()
* \see setParameterComponent()
*/
QgsProcessingModelAlgorithm::ModelParameter &parameterComponent( const QString &name );
/**
* Updates the model's parameter definitions to include all relevant destination
* parameters as required by child algorithm ModelOutputs.
* Must be called whenever child algorithm ModelOutputs are altered.
*/
void updateDestinationParameters();
/**
* Writes the model to a file, at the specified \a path.
* \see fromFile()
*/
bool toFile( const QString &path ) const;
/**
* Reads the model from a file, at the specified \a path.
* \see toFile()
*/
bool fromFile( const QString &path );
/**
* Returns the model's help contents (a free-form map of values describing the algorithm's
* use and metadata).
* \see setHelpContent()
*/
QVariantMap &helpContent() { return mHelpContent; }
/**
* Returns the model's help contents (a free-form map of values describing the algorithm's
* use and metadata).
* \see setHelpContent()
*/
SIP_SKIP QVariantMap helpContent() const;
/**
* Sets the model's help \a contents (a free-form map of values describing the algorithm's
* use and metadata).
* \see helpContent()
*/
void setHelpContent( const QVariantMap &contents );
/**
* Returns the source file path for the model, if available.
* \see setSourceFilePath()
*/
QString sourceFilePath() const;
/**
* Sets the source file \a path for the model, if available.
* \see sourceFilePath()
*/
void setSourceFilePath( const QString &path );
/**
* Attempts to convert the model to executable Python code.
*/
QString asPythonCode() const;
/**
* Returns a list of possible sources which can be used for the parameters for a child
* algorithm in the model. Returned sources are those which match either one of the
* specified \a parameterTypes (see QgsProcessingParameterDefinition::type() ) or
* on of the specified \a outputTypes (see QgsProcessingOutputDefinition::type() ).
* If specified, an optional list of \a dataTypes can be used to filter the returned
* sources to those with compatible data types for the parameter/outputs.
*/
QList< QgsProcessingModelAlgorithm::ChildParameterSource > availableSourcesForChild( const QString &childId, const QStringList &parameterTypes = QStringList(),
const QStringList &outputTypes = QStringList(), const QList< int > dataTypes = QList< int >() ) const;
/**
* Definition of a expression context variable available during model execution.
* \since QGIS 3.0
* \ingroup core
*/
class CORE_EXPORT VariableDefinition
{
public:
/**
* Constructor for a new VariableDefinition with the specified \a value and original
* parameter \a source, and \a description.
*/
VariableDefinition( const QVariant &value = QVariant(), const QgsProcessingModelAlgorithm::ChildParameterSource &source = QgsProcessingModelAlgorithm::ChildParameterSource::fromStaticValue( QVariant() ), const QString &description = QString() )
: value( value )
, source( source )
, description( description )
{}
//! Value of variable
QVariant value;
//! Original source of variable's value
QgsProcessingModelAlgorithm::ChildParameterSource source;
//! Translated description of variable
QString description;
};
/**
* Returns a map of variable name to variable definition for expression context variables which are available
* for use by child algorithm during model execution.
*
* The child algorithm \a childId and processing \a context
* are manadatory. If \a modelParameters and \a results are not specified, then only the variable names and sources
* will be returned, but all variable values will be null. This can be used to determine in advance which variables
* will be available for a specific child algorithm, e.g. for use in expression builder widgets.
*
* In order to calculate the actual variable value, the input model \a modelParameters and already executed child
* algorithm \a results must be passed.
* \see createExpressionContextScopeForChildAlgorithm()
*/
QMap< QString, QgsProcessingModelAlgorithm::VariableDefinition > variablesForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(),
const QVariantMap &results = QVariantMap() ) const;
/**
* Creates a new expression context scope for a child algorithm within the model.
* \see variablesForChildAlgorithm()
*/
QgsExpressionContextScope *createExpressionContextScopeForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(),
const QVariantMap &results = QVariantMap() ) const SIP_FACTORY;
protected:
QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
private:
QString mModelName;
QString mModelGroup;
QMap< QString, ChildAlgorithm > mChildAlgorithms;
//! Map of parameter name to model parameter component
QMap< QString, ModelParameter > mParameterComponents;
QVariantMap mHelpContent;
//! Model source file
QString mSourceFile;
QVariantMap mResults;
void dependsOnChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;
void dependentChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;
QVariantMap parametersForChildAlgorithm( const ChildAlgorithm &child, const QVariantMap &modelParameters, const QVariantMap &results, const QgsExpressionContext &expressionContext ) const;
/**
* Returns true if an output from a child algorithm is required elsewhere in
* the model.
*/
bool childOutputIsRequired( const QString &childId, const QString &outputName ) const;
/**
* Saves this model to a QVariantMap, wrapped in a QVariant.
* You can use QgsXmlUtils::writeVariant to save it to an XML document.
*
* \see loadVariant()
*/
QVariant toVariant() const;
/**
* Loads this model from a QVariantMap, wrapped in a QVariant.
* You can use QgsXmlUtils::readVariant to load it from an XML document.
*
* \see toVariant()
*/
bool loadVariant( const QVariant &model );
friend class TestQgsProcessing;
};
///@endcond
#endif // QGSPROCESSINGMODELALGORITHM_H

View File

@ -24,17 +24,17 @@ QgsProcessingOutputDefinition::QgsProcessingOutputDefinition( const QString &nam
}
QgsProcessingOutputVectorLayer::QgsProcessingOutputVectorLayer( const QString &name, const QString &description, QgsProcessingParameterDefinition::LayerType type )
QgsProcessingOutputVectorLayer::QgsProcessingOutputVectorLayer( const QString &name, const QString &description, QgsProcessing::LayerType type )
: QgsProcessingOutputDefinition( name, description )
, mDataType( type )
{}
QgsProcessingParameterDefinition::LayerType QgsProcessingOutputVectorLayer::dataType() const
QgsProcessing::LayerType QgsProcessingOutputVectorLayer::dataType() const
{
return mDataType;
}
void QgsProcessingOutputVectorLayer::setDataType( QgsProcessingParameterDefinition::LayerType type )
void QgsProcessingOutputVectorLayer::setDataType( QgsProcessing::LayerType type )
{
mDataType = type;
}

View File

@ -126,7 +126,7 @@ class CORE_EXPORT QgsProcessingOutputVectorLayer : public QgsProcessingOutputDef
/**
* Constructor for QgsProcessingOutputVectorLayer.
*/
QgsProcessingOutputVectorLayer( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny );
QgsProcessingOutputVectorLayer( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny );
/**
* Returns the type name for the output class.
@ -138,17 +138,17 @@ class CORE_EXPORT QgsProcessingOutputVectorLayer : public QgsProcessingOutputDef
* Returns the layer type for the output layer.
* \see setDataType()
*/
QgsProcessingParameterDefinition::LayerType dataType() const;
QgsProcessing::LayerType dataType() const;
/**
* Sets the layer \a type for the output layer.
* \see dataType()
*/
void setDataType( QgsProcessingParameterDefinition::LayerType type );
void setDataType( QgsProcessing::LayerType type );
private:
QgsProcessingParameterDefinition::LayerType mDataType = QgsProcessingParameterDefinition::TypeVectorAny;
QgsProcessing::LayerType mDataType = QgsProcessing::TypeVectorAny;
};
/**

View File

@ -21,6 +21,7 @@
#include "qgsvectorlayerfeatureiterator.h"
#include "qgsprocessingoutputs.h"
#include "qgssettings.h"
#include "qgsvectorfilewriter.h"
bool QgsProcessingParameters::isDynamic( const QVariantMap &parameters, const QString &name )
{
@ -327,6 +328,49 @@ QgsProcessingFeatureSource *QgsProcessingParameters::parameterAsSource( const Qg
}
}
QString QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
{
if ( !definition )
return QString();
QVariant val = parameters.value( definition->name() );
bool selectedFeaturesOnly = false;
if ( val.canConvert<QgsProcessingFeatureSourceDefinition>() )
{
// input is a QgsProcessingFeatureSourceDefinition - get extra properties from it
QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( val );
selectedFeaturesOnly = fromVar.selectedFeaturesOnly;
val = fromVar.source;
}
QString layerRef;
if ( val.canConvert<QgsProperty>() )
{
layerRef = val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );
}
else if ( !val.isValid() || val.toString().isEmpty() )
{
// fall back to default
layerRef = definition->defaultValue().toString();
}
else
{
layerRef = val.toString();
}
if ( layerRef.isEmpty() )
return QString();
QgsVectorLayer *vl = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( layerRef, context ) );
if ( !vl )
return QString();
return QgsProcessingUtils::convertToCompatibleFormat( vl, selectedFeaturesOnly, definition->name(),
compatibleFormats, preferredFormat, context, feedback );
}
QgsMapLayer *QgsProcessingParameters::parameterAsLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
{
if ( !definition )
@ -369,7 +413,7 @@ QgsRasterLayer *QgsProcessingParameters::parameterAsRasterLayer( const QgsProces
return qobject_cast< QgsRasterLayer *>( parameterAsLayer( definition, parameters, context ) );
}
QString QgsProcessingParameters::parameterAsRasterOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
{
QVariant val;
if ( definition )
@ -783,14 +827,14 @@ QgsProcessingParameterDefinition *QgsProcessingParameters::parameterFromVariantM
def.reset( new QgsProcessingParameterFeatureSource( name ) );
else if ( type == QgsProcessingParameterFeatureSink::typeName() )
def.reset( new QgsProcessingParameterFeatureSink( name ) );
else if ( type == QgsProcessingParameterVectorOutput::typeName() )
def.reset( new QgsProcessingParameterVectorOutput( name ) );
else if ( type == QgsProcessingParameterRasterOutput::typeName() )
def.reset( new QgsProcessingParameterRasterOutput( name ) );
else if ( type == QgsProcessingParameterFileOutput::typeName() )
def.reset( new QgsProcessingParameterFileOutput( name ) );
else if ( type == QgsProcessingParameterFolderOutput::typeName() )
def.reset( new QgsProcessingParameterFolderOutput( name ) );
else if ( type == QgsProcessingParameterVectorDestination::typeName() )
def.reset( new QgsProcessingParameterVectorDestination( name ) );
else if ( type == QgsProcessingParameterRasterDestination::typeName() )
def.reset( new QgsProcessingParameterRasterDestination( name ) );
else if ( type == QgsProcessingParameterFileDestination::typeName() )
def.reset( new QgsProcessingParameterFileDestination( name ) );
else if ( type == QgsProcessingParameterFolderDestination::typeName() )
def.reset( new QgsProcessingParameterFolderDestination( name ) );
if ( !def )
return nullptr;
@ -855,14 +899,14 @@ QgsProcessingParameterDefinition *QgsProcessingParameters::parameterFromScriptCo
return QgsProcessingParameterFeatureSource::fromScriptCode( name, description, isOptional, definition );
else if ( type == QStringLiteral( "sink" ) )
return QgsProcessingParameterFeatureSink::fromScriptCode( name, description, isOptional, definition );
else if ( type == QStringLiteral( "vectorout" ) )
return QgsProcessingParameterVectorOutput::fromScriptCode( name, description, isOptional, definition );
else if ( type == QStringLiteral( "rasterout" ) )
return QgsProcessingParameterRasterOutput::fromScriptCode( name, description, isOptional, definition );
else if ( type == QStringLiteral( "fileout" ) )
return QgsProcessingParameterFileOutput::fromScriptCode( name, description, isOptional, definition );
else if ( type == QStringLiteral( "folderout" ) )
return QgsProcessingParameterFolderOutput::fromScriptCode( name, description, isOptional, definition );
else if ( type == QStringLiteral( "vectordestination" ) )
return QgsProcessingParameterVectorDestination::fromScriptCode( name, description, isOptional, definition );
else if ( type == QStringLiteral( "rasterdestination" ) )
return QgsProcessingParameterRasterDestination::fromScriptCode( name, description, isOptional, definition );
else if ( type == QStringLiteral( "filedestination" ) )
return QgsProcessingParameterFileDestination::fromScriptCode( name, description, isOptional, definition );
else if ( type == QStringLiteral( "folderdestination" ) )
return QgsProcessingParameterFolderDestination::fromScriptCode( name, description, isOptional, definition );
return nullptr;
}
@ -1377,7 +1421,7 @@ QgsProcessingParameterMatrix *QgsProcessingParameterMatrix::fromScriptCode( cons
return new QgsProcessingParameterMatrix( name, description, 0, false, QStringList(), definition.isEmpty() ? QVariant() : definition, isOptional );
}
QgsProcessingParameterMultipleLayers::QgsProcessingParameterMultipleLayers( const QString &name, const QString &description, LayerType layerType, const QVariant &defaultValue, bool optional )
QgsProcessingParameterMultipleLayers::QgsProcessingParameterMultipleLayers( const QString &name, const QString &description, QgsProcessing::LayerType layerType, const QVariant &defaultValue, bool optional )
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
, mLayerType( layerType )
{
@ -1477,11 +1521,11 @@ QString QgsProcessingParameterMultipleLayers::asScriptCode() const
code += QStringLiteral( "optional " );
switch ( mLayerType )
{
case TypeRaster:
case QgsProcessing::TypeRaster:
code += QStringLiteral( "multiple raster" );
break;
case TypeFile:
case QgsProcessing::TypeFile:
code += QStringLiteral( "multiple file" );
break;
@ -1510,12 +1554,12 @@ QString QgsProcessingParameterMultipleLayers::asScriptCode() const
return code.trimmed();
}
QgsProcessingParameterDefinition::LayerType QgsProcessingParameterMultipleLayers::layerType() const
QgsProcessing::LayerType QgsProcessingParameterMultipleLayers::layerType() const
{
return mLayerType;
}
void QgsProcessingParameterMultipleLayers::setLayerType( LayerType type )
void QgsProcessingParameterMultipleLayers::setLayerType( QgsProcessing::LayerType type )
{
mLayerType = type;
}
@ -1542,7 +1586,7 @@ QVariantMap QgsProcessingParameterMultipleLayers::toVariantMap() const
bool QgsProcessingParameterMultipleLayers::fromVariantMap( const QVariantMap &map )
{
QgsProcessingParameterDefinition::fromVariantMap( map );
mLayerType = static_cast< LayerType >( map.value( QStringLiteral( "layer_type" ) ).toInt() );
mLayerType = static_cast< QgsProcessing::LayerType >( map.value( QStringLiteral( "layer_type" ) ).toInt() );
mMinimumNumberInputs = map.value( QStringLiteral( "min_inputs" ) ).toInt();
return true;
}
@ -1558,13 +1602,13 @@ QgsProcessingParameterMultipleLayers *QgsProcessingParameterMultipleLayers::from
type = m.captured( 1 ).toLower().trimmed();
defaultVal = m.captured( 2 );
}
LayerType layerType = TypeVectorAny;
QgsProcessing::LayerType layerType = QgsProcessing::TypeVectorAny;
if ( type == QStringLiteral( "vector" ) )
layerType = TypeVectorAny;
layerType = QgsProcessing::TypeVectorAny;
else if ( type == QStringLiteral( "raster" ) )
layerType = TypeRaster;
layerType = QgsProcessing::TypeRaster;
else if ( type == QStringLiteral( "file" ) )
layerType = TypeFile;
layerType = QgsProcessing::TypeFile;
return new QgsProcessingParameterMultipleLayers( name, description, layerType, defaultVal.isEmpty() ? QVariant() : defaultVal, isOptional );
}
@ -2432,15 +2476,15 @@ QString QgsProcessingParameterFeatureSource::asScriptCode() const
{
switch ( type )
{
case TypeVectorPoint:
case QgsProcessing::TypeVectorPoint:
code += QStringLiteral( "point " );
break;
case TypeVectorLine:
case QgsProcessing::TypeVectorLine:
code += QStringLiteral( "line " );
break;
case TypeVectorPolygon:
case QgsProcessing::TypeVectorPolygon:
code += QStringLiteral( "polygon " );
break;
@ -2493,19 +2537,19 @@ QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromSc
{
if ( def.startsWith( QStringLiteral( "point" ), Qt::CaseInsensitive ) )
{
types << QgsProcessingParameterDefinition::TypeVectorPoint;
types << QgsProcessing::TypeVectorPoint;
def = def.mid( 6 );
continue;
}
else if ( def.startsWith( QStringLiteral( "line" ), Qt::CaseInsensitive ) )
{
types << QgsProcessingParameterDefinition::TypeVectorLine;
types << QgsProcessing::TypeVectorLine;
def = def.mid( 5 );
continue;
}
else if ( def.startsWith( QStringLiteral( "polygon" ), Qt::CaseInsensitive ) )
{
types << QgsProcessingParameterDefinition::TypeVectorPolygon;
types << QgsProcessing::TypeVectorPolygon;
def = def.mid( 8 );
continue;
}
@ -2515,7 +2559,7 @@ QgsProcessingParameterFeatureSource *QgsProcessingParameterFeatureSource::fromSc
return new QgsProcessingParameterFeatureSource( name, description, types, def, isOptional );
}
QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, QgsProcessingParameterDefinition::LayerType type, const QVariant &defaultValue, bool optional )
QgsProcessingParameterFeatureSink::QgsProcessingParameterFeatureSink( const QString &name, const QString &description, QgsProcessing::LayerType type, const QVariant &defaultValue, bool optional )
: QgsProcessingDestinationParameter( name, description, defaultValue, optional )
, mDataType( type )
{
@ -2578,19 +2622,19 @@ QString QgsProcessingParameterFeatureSink::asScriptCode() const
switch ( mDataType )
{
case TypeVectorPoint:
case QgsProcessing::TypeVectorPoint:
code += QStringLiteral( "point " );
break;
case TypeVectorLine:
case QgsProcessing::TypeVectorLine:
code += QStringLiteral( "line " );
break;
case TypeVectorPolygon:
case QgsProcessing::TypeVectorPolygon:
code += QStringLiteral( "polygon " );
break;
case TypeTable:
case QgsProcessing::TypeTable:
code += QStringLiteral( "table " );
break;
@ -2620,7 +2664,7 @@ QString QgsProcessingParameterFeatureSink::defaultFileExtension() const
}
}
QgsProcessingParameterDefinition::LayerType QgsProcessingParameterFeatureSink::dataType() const
QgsProcessing::LayerType QgsProcessingParameterFeatureSink::dataType() const
{
return mDataType;
}
@ -2629,22 +2673,22 @@ bool QgsProcessingParameterFeatureSink::hasGeometry() const
{
switch ( mDataType )
{
case TypeAny:
case TypeVectorAny:
case TypeVectorPoint:
case TypeVectorLine:
case TypeVectorPolygon:
case TypeTable:
case QgsProcessing::TypeAny:
case QgsProcessing::TypeVectorAny:
case QgsProcessing::TypeVectorPoint:
case QgsProcessing::TypeVectorLine:
case QgsProcessing::TypeVectorPolygon:
case QgsProcessing::TypeTable:
return true;
case TypeRaster:
case TypeFile:
case QgsProcessing::TypeRaster:
case QgsProcessing::TypeFile:
return false;
}
return true;
}
void QgsProcessingParameterFeatureSink::setDataType( QgsProcessingParameterDefinition::LayerType type )
void QgsProcessingParameterFeatureSink::setDataType( QgsProcessing::LayerType type )
{
mDataType = type;
}
@ -2659,7 +2703,7 @@ QVariantMap QgsProcessingParameterFeatureSink::toVariantMap() const
bool QgsProcessingParameterFeatureSink::fromVariantMap( const QVariantMap &map )
{
QgsProcessingDestinationParameter::fromVariantMap( map );
mDataType = static_cast< QgsProcessingParameterDefinition::LayerType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
mDataType = static_cast< QgsProcessing::LayerType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
return true;
}
@ -2673,37 +2717,37 @@ QString QgsProcessingParameterFeatureSink::generateTemporaryDestination() const
QgsProcessingParameterFeatureSink *QgsProcessingParameterFeatureSink::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
{
QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny;
QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny;
QString def = definition;
if ( def.startsWith( QStringLiteral( "point" ), Qt::CaseInsensitive ) )
{
type = QgsProcessingParameterDefinition::TypeVectorPoint;
type = QgsProcessing::TypeVectorPoint;
def = def.mid( 6 );
}
else if ( def.startsWith( QStringLiteral( "line" ), Qt::CaseInsensitive ) )
{
type = QgsProcessingParameterDefinition::TypeVectorLine;
type = QgsProcessing::TypeVectorLine;
def = def.mid( 5 );
}
else if ( def.startsWith( QStringLiteral( "polygon" ), Qt::CaseInsensitive ) )
{
type = QgsProcessingParameterDefinition::TypeVectorPolygon;
type = QgsProcessing::TypeVectorPolygon;
def = def.mid( 8 );
}
else if ( def.startsWith( QStringLiteral( "table" ), Qt::CaseInsensitive ) )
{
type = QgsProcessingParameterDefinition::TypeTable;
type = QgsProcessing::TypeTable;
def = def.mid( 6 );
}
return new QgsProcessingParameterFeatureSink( name, description, type, definition, isOptional );
}
QgsProcessingParameterRasterOutput::QgsProcessingParameterRasterOutput( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
QgsProcessingParameterRasterDestination::QgsProcessingParameterRasterDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
: QgsProcessingDestinationParameter( name, description, defaultValue, optional )
{}
bool QgsProcessingParameterRasterOutput::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const
bool QgsProcessingParameterRasterDestination::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const
{
QVariant var = input;
if ( !var.isValid() )
@ -2729,7 +2773,7 @@ bool QgsProcessingParameterRasterOutput::checkValueIsAcceptable( const QVariant
return true;
}
QString QgsProcessingParameterRasterOutput::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
QString QgsProcessingParameterRasterDestination::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
@ -2750,31 +2794,31 @@ QString QgsProcessingParameterRasterOutput::valueAsPythonString( const QVariant
return value.toString().prepend( '\'' ).append( '\'' );
}
QgsProcessingOutputDefinition *QgsProcessingParameterRasterOutput::toOutputDefinition() const
QgsProcessingOutputDefinition *QgsProcessingParameterRasterDestination::toOutputDefinition() const
{
return new QgsProcessingOutputRasterLayer( name(), description() );
}
QString QgsProcessingParameterRasterOutput::defaultFileExtension() const
QString QgsProcessingParameterRasterDestination::defaultFileExtension() const
{
QgsSettings settings;
return settings.value( QStringLiteral( "Processing/DefaultOutputRasterLayerExt" ), QStringLiteral( "tif" ), QgsSettings::Core ).toString();
}
QgsProcessingParameterRasterOutput *QgsProcessingParameterRasterOutput::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
QgsProcessingParameterRasterDestination *QgsProcessingParameterRasterDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
{
return new QgsProcessingParameterRasterOutput( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
return new QgsProcessingParameterRasterDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
}
QgsProcessingParameterFileOutput::QgsProcessingParameterFileOutput( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional )
QgsProcessingParameterFileDestination::QgsProcessingParameterFileDestination( const QString &name, const QString &description, const QString &fileFilter, const QVariant &defaultValue, bool optional )
: QgsProcessingDestinationParameter( name, description, defaultValue, optional )
, mFileFilter( fileFilter.isEmpty() ? QObject::tr( "All files (*.*)" ) : fileFilter )
{
}
bool QgsProcessingParameterFileOutput::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const
bool QgsProcessingParameterFileDestination::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const
{
QVariant var = input;
if ( !var.isValid() )
@ -2802,7 +2846,7 @@ bool QgsProcessingParameterFileOutput::checkValueIsAcceptable( const QVariant &i
return true;
}
QString QgsProcessingParameterFileOutput::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
QString QgsProcessingParameterFileDestination::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
@ -2823,12 +2867,12 @@ QString QgsProcessingParameterFileOutput::valueAsPythonString( const QVariant &v
return value.toString().prepend( '\'' ).append( '\'' );
}
QgsProcessingOutputDefinition *QgsProcessingParameterFileOutput::toOutputDefinition() const
QgsProcessingOutputDefinition *QgsProcessingParameterFileDestination::toOutputDefinition() const
{
return nullptr;
}
QString QgsProcessingParameterFileOutput::defaultFileExtension() const
QString QgsProcessingParameterFileDestination::defaultFileExtension() const
{
if ( mFileFilter.isEmpty() || mFileFilter == QObject::tr( "All files (*.*)" ) )
return QStringLiteral( "file" );
@ -2842,24 +2886,24 @@ QString QgsProcessingParameterFileOutput::defaultFileExtension() const
return match.captured( 1 );
}
QString QgsProcessingParameterFileOutput::fileFilter() const
QString QgsProcessingParameterFileDestination::fileFilter() const
{
return mFileFilter;
}
void QgsProcessingParameterFileOutput::setFileFilter( const QString &fileFilter )
void QgsProcessingParameterFileDestination::setFileFilter( const QString &fileFilter )
{
mFileFilter = fileFilter;
}
QVariantMap QgsProcessingParameterFileOutput::toVariantMap() const
QVariantMap QgsProcessingParameterFileDestination::toVariantMap() const
{
QVariantMap map = QgsProcessingDestinationParameter::toVariantMap();
map.insert( QStringLiteral( "file_filter" ), mFileFilter );
return map;
}
bool QgsProcessingParameterFileOutput::fromVariantMap( const QVariantMap &map )
bool QgsProcessingParameterFileDestination::fromVariantMap( const QVariantMap &map )
{
QgsProcessingDestinationParameter::fromVariantMap( map );
mFileFilter = map.value( QStringLiteral( "file_filter" ) ).toString();
@ -2867,16 +2911,16 @@ bool QgsProcessingParameterFileOutput::fromVariantMap( const QVariantMap &map )
}
QgsProcessingParameterFileOutput *QgsProcessingParameterFileOutput::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
QgsProcessingParameterFileDestination *QgsProcessingParameterFileDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
{
return new QgsProcessingParameterFileOutput( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
return new QgsProcessingParameterFileDestination( name, description, QString(), definition.isEmpty() ? QVariant() : definition, isOptional );
}
QgsProcessingParameterFolderOutput::QgsProcessingParameterFolderOutput( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
QgsProcessingParameterFolderDestination::QgsProcessingParameterFolderDestination( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
: QgsProcessingDestinationParameter( name, description, defaultValue, optional )
{}
bool QgsProcessingParameterFolderOutput::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const
bool QgsProcessingParameterFolderDestination::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const
{
QVariant var = input;
if ( !var.isValid() )
@ -2896,19 +2940,19 @@ bool QgsProcessingParameterFolderOutput::checkValueIsAcceptable( const QVariant
return true;
}
QgsProcessingOutputDefinition *QgsProcessingParameterFolderOutput::toOutputDefinition() const
QgsProcessingOutputDefinition *QgsProcessingParameterFolderDestination::toOutputDefinition() const
{
return new QgsProcessingOutputFolder( name(), description() );
}
QString QgsProcessingParameterFolderOutput::defaultFileExtension() const
QString QgsProcessingParameterFolderDestination::defaultFileExtension() const
{
return QString();
}
QgsProcessingParameterFolderOutput *QgsProcessingParameterFolderOutput::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
QgsProcessingParameterFolderDestination *QgsProcessingParameterFolderDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
{
return new QgsProcessingParameterFolderOutput( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
return new QgsProcessingParameterFolderDestination( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
}
QgsProcessingDestinationParameter::QgsProcessingDestinationParameter( const QString &name, const QString &description, const QVariant &defaultValue, bool optional )
@ -2936,14 +2980,14 @@ QString QgsProcessingDestinationParameter::generateTemporaryDestination() const
return QgsProcessingUtils::generateTempFilename( name() + '.' + defaultFileExtension() );
}
QgsProcessingParameterVectorOutput::QgsProcessingParameterVectorOutput( const QString &name, const QString &description, QgsProcessingParameterDefinition::LayerType type, const QVariant &defaultValue, bool optional )
QgsProcessingParameterVectorDestination::QgsProcessingParameterVectorDestination( const QString &name, const QString &description, QgsProcessing::LayerType type, const QVariant &defaultValue, bool optional )
: QgsProcessingDestinationParameter( name, description, defaultValue, optional )
, mDataType( type )
{
}
bool QgsProcessingParameterVectorOutput::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const
bool QgsProcessingParameterVectorDestination::checkValueIsAcceptable( const QVariant &input, QgsProcessingContext * ) const
{
QVariant var = input;
if ( !var.isValid() )
@ -2969,7 +3013,7 @@ bool QgsProcessingParameterVectorOutput::checkValueIsAcceptable( const QVariant
return true;
}
QString QgsProcessingParameterVectorOutput::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
QString QgsProcessingParameterVectorDestination::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );
@ -2990,24 +3034,24 @@ QString QgsProcessingParameterVectorOutput::valueAsPythonString( const QVariant
return value.toString().prepend( '\'' ).append( '\'' );
}
QString QgsProcessingParameterVectorOutput::asScriptCode() const
QString QgsProcessingParameterVectorDestination::asScriptCode() const
{
QString code = QStringLiteral( "##%1=" ).arg( mName );
if ( mFlags & FlagOptional )
code += QStringLiteral( "optional " );
code += QStringLiteral( "vectorOut " );
code += QStringLiteral( "vectorDestination " );
switch ( mDataType )
{
case TypeVectorPoint:
case QgsProcessing::TypeVectorPoint:
code += QStringLiteral( "point " );
break;
case TypeVectorLine:
case QgsProcessing::TypeVectorLine:
code += QStringLiteral( "line " );
break;
case TypeVectorPolygon:
case QgsProcessing::TypeVectorPolygon:
code += QStringLiteral( "polygon " );
break;
@ -3019,12 +3063,12 @@ QString QgsProcessingParameterVectorOutput::asScriptCode() const
return code.trimmed();
}
QgsProcessingOutputDefinition *QgsProcessingParameterVectorOutput::toOutputDefinition() const
QgsProcessingOutputDefinition *QgsProcessingParameterVectorDestination::toOutputDefinition() const
{
return new QgsProcessingOutputVectorLayer( name(), description(), mDataType );
}
QString QgsProcessingParameterVectorOutput::defaultFileExtension() const
QString QgsProcessingParameterVectorDestination::defaultFileExtension() const
{
QgsSettings settings;
if ( hasGeometry() )
@ -3037,68 +3081,68 @@ QString QgsProcessingParameterVectorOutput::defaultFileExtension() const
}
}
QgsProcessingParameterDefinition::LayerType QgsProcessingParameterVectorOutput::dataType() const
QgsProcessing::LayerType QgsProcessingParameterVectorDestination::dataType() const
{
return mDataType;
}
bool QgsProcessingParameterVectorOutput::hasGeometry() const
bool QgsProcessingParameterVectorDestination::hasGeometry() const
{
switch ( mDataType )
{
case TypeAny:
case TypeVectorAny:
case TypeVectorPoint:
case TypeVectorLine:
case TypeVectorPolygon:
case TypeTable:
case QgsProcessing::TypeAny:
case QgsProcessing::TypeVectorAny:
case QgsProcessing::TypeVectorPoint:
case QgsProcessing::TypeVectorLine:
case QgsProcessing::TypeVectorPolygon:
case QgsProcessing::TypeTable:
return true;
case TypeRaster:
case TypeFile:
case QgsProcessing::TypeRaster:
case QgsProcessing::TypeFile:
return false;
}
return true;
}
void QgsProcessingParameterVectorOutput::setDataType( QgsProcessingParameterDefinition::LayerType type )
void QgsProcessingParameterVectorDestination::setDataType( QgsProcessing::LayerType type )
{
mDataType = type;
}
QVariantMap QgsProcessingParameterVectorOutput::toVariantMap() const
QVariantMap QgsProcessingParameterVectorDestination::toVariantMap() const
{
QVariantMap map = QgsProcessingDestinationParameter::toVariantMap();
map.insert( QStringLiteral( "data_type" ), mDataType );
return map;
}
bool QgsProcessingParameterVectorOutput::fromVariantMap( const QVariantMap &map )
bool QgsProcessingParameterVectorDestination::fromVariantMap( const QVariantMap &map )
{
QgsProcessingDestinationParameter::fromVariantMap( map );
mDataType = static_cast< QgsProcessingParameterDefinition::LayerType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
mDataType = static_cast< QgsProcessing::LayerType >( map.value( QStringLiteral( "data_type" ) ).toInt() );
return true;
}
QgsProcessingParameterVectorOutput *QgsProcessingParameterVectorOutput::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
QgsProcessingParameterVectorDestination *QgsProcessingParameterVectorDestination::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
{
QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny;
QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny;
QString def = definition;
if ( def.startsWith( QStringLiteral( "point" ), Qt::CaseInsensitive ) )
{
type = QgsProcessingParameterDefinition::TypeVectorPoint;
type = QgsProcessing::TypeVectorPoint;
def = def.mid( 6 );
}
else if ( def.startsWith( QStringLiteral( "line" ), Qt::CaseInsensitive ) )
{
type = QgsProcessingParameterDefinition::TypeVectorLine;
type = QgsProcessing::TypeVectorLine;
def = def.mid( 5 );
}
else if ( def.startsWith( QStringLiteral( "polygon" ), Qt::CaseInsensitive ) )
{
type = QgsProcessingParameterDefinition::TypeVectorPolygon;
type = QgsProcessing::TypeVectorPolygon;
def = def.mid( 8 );
}
return new QgsProcessingParameterVectorOutput( name, description, type, definition, isOptional );
return new QgsProcessingParameterVectorDestination( name, description, type, definition, isOptional );
}

View File

@ -20,6 +20,7 @@
#include "qgis_core.h"
#include "qgis.h"
#include "qgsprocessing.h"
#include "qgsproperty.h"
#include "qgscoordinatereferencesystem.h"
#include <QMap>
@ -32,6 +33,7 @@ class QgsFeatureSink;
class QgsFeatureSource;
class QgsProcessingFeatureSource;
class QgsProcessingOutputDefinition;
class QgsProcessingFeedback;
/**
* \class QgsProcessingFeatureSourceDefinition
@ -221,14 +223,14 @@ class CORE_EXPORT QgsProcessingParameterDefinition
sipType = sipType_QgsProcessingParameterFeatureSource;
else if ( sipCpp->type() == QgsProcessingParameterFeatureSink::typeName() )
sipType = sipType_QgsProcessingParameterFeatureSink;
else if ( sipCpp->type() == QgsProcessingParameterVectorOutput::typeName() )
sipType = sipType_QgsProcessingParameterVectorOutput;
else if ( sipCpp->type() == QgsProcessingParameterRasterOutput::typeName() )
sipType = sipType_QgsProcessingParameterRasterOutput;
else if ( sipCpp->type() == QgsProcessingParameterFileOutput::typeName() )
sipType = sipType_QgsProcessingParameterFileOutput;
else if ( sipCpp->type() == QgsProcessingParameterFolderOutput::typeName() )
sipType = sipType_QgsProcessingParameterFolderOutput;
else if ( sipCpp->type() == QgsProcessingParameterVectorDestination::typeName() )
sipType = sipType_QgsProcessingParameterVectorDestination;
else if ( sipCpp->type() == QgsProcessingParameterRasterDestination::typeName() )
sipType = sipType_QgsProcessingParameterRasterDestination;
else if ( sipCpp->type() == QgsProcessingParameterFileDestination::typeName() )
sipType = sipType_QgsProcessingParameterFileDestination;
else if ( sipCpp->type() == QgsProcessingParameterFolderDestination::typeName() )
sipType = sipType_QgsProcessingParameterFolderDestination;
SIP_END
#endif
@ -243,19 +245,6 @@ class CORE_EXPORT QgsProcessingParameterDefinition
};
Q_DECLARE_FLAGS( Flags, Flag )
//! Layer types enum
enum LayerType
{
TypeAny = -2, //!< Any layer
TypeVectorAny = -1, //!< Any vector layer with geometry
TypeVectorPoint = 0, //!< Vector point layers
TypeVectorLine = 1, //!< Vector line layers
TypeVectorPolygon = 2, //!< Vector polygon layers
TypeRaster = 3, //!< Raster layers
TypeFile = 4, //!< Files
TypeTable = 5, //!< Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink has no geometry.
};
/**
* Constructor for QgsProcessingParameterDefinition.
*/
@ -508,6 +497,21 @@ class CORE_EXPORT QgsProcessingParameters
*/
static QgsProcessingFeatureSource *parameterAsSource( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context ) SIP_FACTORY;
/**
* Evaluates the parameter with matching \a definition to a source vector layer file path of compatible format.
*
* If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the
* \a compatibleFormats argument, then the layer will first be exported to a compatible format
* in a temporary location. The function will then return the path to that temporary file.
*
* \a compatibleFormats should consist entirely of lowercase file extensions, e.g. 'shp'.
*
* The \a preferredFormat argument is used to specify to desired file extension to use when a temporary
* layer export is required. This defaults to shapefiles, because shapefiles are the future (don't believe the geopackage hype!).
*/
static QString parameterAsCompatibleSourceLayerPath( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters,
QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat = QString( "shp" ), QgsProcessingFeedback *feedback = nullptr );
/**
* Evaluates the parameter with matching \a definition to a map layer.
*
@ -527,9 +531,9 @@ class CORE_EXPORT QgsProcessingParameters
static QgsRasterLayer *parameterAsRasterLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a raster output layer destination.
* Evaluates the parameter with matching \a definition to a output layer destination.
*/
static QString parameterAsRasterOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
static QString parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
/**
* Evaluates the parameter with matching \a definition to a file based output destination.
@ -932,7 +936,7 @@ class CORE_EXPORT QgsProcessingParameterMultipleLayers : public QgsProcessingPar
/**
* Constructor for QgsProcessingParameterMultipleLayers.
*/
QgsProcessingParameterMultipleLayers( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType layerType = QgsProcessingParameterDefinition::TypeVectorAny,
QgsProcessingParameterMultipleLayers( const QString &name, const QString &description = QString(), QgsProcessing::LayerType layerType = QgsProcessing::TypeVectorAny,
const QVariant &defaultValue = QVariant(),
bool optional = false );
@ -949,13 +953,13 @@ class CORE_EXPORT QgsProcessingParameterMultipleLayers : public QgsProcessingPar
* Returns the layer type for layers acceptable by the parameter.
* \see setLayerType()
*/
QgsProcessingParameterDefinition::LayerType layerType() const;
QgsProcessing::LayerType layerType() const;
/**
* Sets the layer \a type for layers acceptable by the parameter.
* \see layerType()
*/
void setLayerType( QgsProcessingParameterDefinition::LayerType type );
void setLayerType( QgsProcessing::LayerType type );
/**
* Returns the minimum number of layers required for the parameter. If the return value is < 1
@ -981,7 +985,7 @@ class CORE_EXPORT QgsProcessingParameterMultipleLayers : public QgsProcessingPar
private:
LayerType mLayerType = TypeVectorAny;
QgsProcessing::LayerType mLayerType = QgsProcessing::TypeVectorAny;
int mMinimumNumberInputs = 0;
};
@ -1493,7 +1497,7 @@ class CORE_EXPORT QgsProcessingParameterFeatureSource : public QgsProcessingPara
private:
QList< int > mDataTypes = QList< int >() << QgsProcessingParameterDefinition::TypeVectorAny;
QList< int > mDataTypes = QList< int >() << QgsProcessing::TypeVectorAny;
};
@ -1573,7 +1577,7 @@ class CORE_EXPORT QgsProcessingParameterFeatureSink : public QgsProcessingDestin
/**
* Constructor for QgsProcessingParameterFeatureSink.
*/
QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny, const QVariant &defaultValue = QVariant(),
QgsProcessingParameterFeatureSink( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(),
bool optional = false );
/**
@ -1591,7 +1595,7 @@ class CORE_EXPORT QgsProcessingParameterFeatureSink : public QgsProcessingDestin
* Returns the layer type for sinks associated with the parameter.
* \see setDataType()
*/
QgsProcessingParameterDefinition::LayerType dataType() const;
QgsProcessing::LayerType dataType() const;
/**
* Returns true if sink is likely to include geometries. In cases were presence of geometry
@ -1603,7 +1607,7 @@ class CORE_EXPORT QgsProcessingParameterFeatureSink : public QgsProcessingDestin
* Sets the layer \a type for the sinks associated with the parameter.
* \see dataType()
*/
void setDataType( QgsProcessingParameterDefinition::LayerType type );
void setDataType( QgsProcessing::LayerType type );
QVariantMap toVariantMap() const override;
bool fromVariantMap( const QVariantMap &map ) override;
@ -1616,31 +1620,34 @@ class CORE_EXPORT QgsProcessingParameterFeatureSink : public QgsProcessingDestin
private:
QgsProcessingParameterDefinition::LayerType mDataType = QgsProcessingParameterDefinition::TypeVectorAny;
QgsProcessing::LayerType mDataType = QgsProcessing::TypeVectorAny;
};
/**
* \class QgsProcessingParameterVectorOutput
* \class QgsProcessingParameterVectorDestination
* \ingroup core
* A vector layer output parameter. Consider using the more flexible QgsProcessingParameterFeatureSink wherever
* A vector layer destination parameter, for specifying the destination path for a vector layer
* created by the algorithm.
*
* \note Consider using the more flexible QgsProcessingParameterFeatureSink wherever
* possible.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingParameterVectorOutput : public QgsProcessingDestinationParameter
class CORE_EXPORT QgsProcessingParameterVectorDestination : public QgsProcessingDestinationParameter
{
public:
/**
* Constructor for QgsProcessingParameterVectorOutput.
* Constructor for QgsProcessingParameterVectorDestination.
*/
QgsProcessingParameterVectorOutput( const QString &name, const QString &description = QString(), QgsProcessingParameterDefinition::LayerType type = QgsProcessingParameterDefinition::TypeVectorAny, const QVariant &defaultValue = QVariant(),
bool optional = false );
QgsProcessingParameterVectorDestination( const QString &name, const QString &description = QString(), QgsProcessing::LayerType type = QgsProcessing::TypeVectorAny, const QVariant &defaultValue = QVariant(),
bool optional = false );
/**
* Returns the type name for the parameter class.
*/
static QString typeName() { return QStringLiteral( "vectorOut" ); }
static QString typeName() { return QStringLiteral( "vectorDestination" ); }
QString type() const override { return typeName(); }
bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
@ -1649,22 +1656,22 @@ class CORE_EXPORT QgsProcessingParameterVectorOutput : public QgsProcessingDesti
QString defaultFileExtension() const override;
/**
* Returns the layer type for layers associated with the parameter.
* Returns the layer type for this created vector layer.
* \see setDataType()
*/
QgsProcessingParameterDefinition::LayerType dataType() const;
QgsProcessing::LayerType dataType() const;
/**
* Returns true if the layer is likely to include geometries. In cases were presence of geometry
* Returns true if the created layer is likely to include geometries. In cases were presence of geometry
* cannot be reliably determined in advance, this method will default to returning true.
*/
bool hasGeometry() const;
/**
* Sets the layer \a type for the layers associated with the parameter.
* Sets the layer \a type for the created vector layer.
* \see dataType()
*/
void setDataType( QgsProcessingParameterDefinition::LayerType type );
void setDataType( QgsProcessing::LayerType type );
QVariantMap toVariantMap() const override;
bool fromVariantMap( const QVariantMap &map ) override;
@ -1672,35 +1679,36 @@ class CORE_EXPORT QgsProcessingParameterVectorOutput : public QgsProcessingDesti
/**
* Creates a new parameter using the definition from a script code.
*/
static QgsProcessingParameterVectorOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
static QgsProcessingParameterVectorDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
private:
QgsProcessingParameterDefinition::LayerType mDataType = QgsProcessingParameterDefinition::TypeVectorAny;
QgsProcessing::LayerType mDataType = QgsProcessing::TypeVectorAny;
};
/**
* \class QgsProcessingParameterRasterOutput
* \class QgsProcessingParameterRasterDestination
* \ingroup core
* A raster layer output parameter.
* A raster layer destination parameter, for specifying the destination path for a raster layer
* created by the algorithm.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingParameterRasterOutput : public QgsProcessingDestinationParameter
class CORE_EXPORT QgsProcessingParameterRasterDestination : public QgsProcessingDestinationParameter
{
public:
/**
* Constructor for QgsProcessingParameterRasterOutput.
* Constructor for QgsProcessingParameterRasterDestination.
*/
QgsProcessingParameterRasterOutput( const QString &name, const QString &description = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
QgsProcessingParameterRasterDestination( const QString &name, const QString &description = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
/**
* Returns the type name for the parameter class.
*/
static QString typeName() { return QStringLiteral( "rasterOut" ); }
static QString typeName() { return QStringLiteral( "rasterDestination" ); }
QString type() const override { return typeName(); }
bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
@ -1710,31 +1718,32 @@ class CORE_EXPORT QgsProcessingParameterRasterOutput : public QgsProcessingDesti
/**
* Creates a new parameter using the definition from a script code.
*/
static QgsProcessingParameterRasterOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
static QgsProcessingParameterRasterDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
};
/**
* \class QgsProcessingParameterFileOutput
* \class QgsProcessingParameterFileDestination
* \ingroup core
* A generic file based output parameter.
* A generic file based destination parameter, for specifying the destination path for a file (non-map layer)
* created by the algorithm.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingParameterFileOutput : public QgsProcessingDestinationParameter
class CORE_EXPORT QgsProcessingParameterFileDestination : public QgsProcessingDestinationParameter
{
public:
/**
* Constructor for QgsProcessingParameterFileOutput.
* Constructor for QgsProcessingParameterFileDestination.
*/
QgsProcessingParameterFileOutput( const QString &name, const QString &description = QString(),
const QString &fileFilter = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
QgsProcessingParameterFileDestination( const QString &name, const QString &description = QString(),
const QString &fileFilter = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
/**
* Returns the type name for the parameter class.
*/
static QString typeName() { return QStringLiteral( "fileOut" ); }
static QString typeName() { return QStringLiteral( "fileDestination" ); }
QString type() const override { return typeName(); }
bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
@ -1742,13 +1751,13 @@ class CORE_EXPORT QgsProcessingParameterFileOutput : public QgsProcessingDestina
QString defaultFileExtension() const override;
/**
* Returns the file filter string for files compatible with this output.
* Returns the file filter string for file destinations compatible with this parameter.
* \see setFileFilter()
*/
QString fileFilter() const;
/**
* Sets the file \a filter string for files compatible with this output.
* Sets the file \a filter string for file destinations compatible with this parameter.
* \see fileFilter()
*/
void setFileFilter( const QString &filter );
@ -1759,7 +1768,7 @@ class CORE_EXPORT QgsProcessingParameterFileOutput : public QgsProcessingDestina
/**
* Creates a new parameter using the definition from a script code.
*/
static QgsProcessingParameterFileOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
static QgsProcessingParameterFileDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
private:
@ -1768,26 +1777,28 @@ class CORE_EXPORT QgsProcessingParameterFileOutput : public QgsProcessingDestina
};
/**
* \class QgsProcessingParameterFolderOutput
* \class QgsProcessingParameterFolderDestination
* \ingroup core
* A folder destination parameter, for specifying the destination path for a folder created
* by the algorithm or used for creating new files within the algorithm.
* A folder output parameter.
* \since QGIS 3.0
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingParameterFolderOutput : public QgsProcessingDestinationParameter
class CORE_EXPORT QgsProcessingParameterFolderDestination : public QgsProcessingDestinationParameter
{
public:
/**
* Constructor for QgsProcessingParameterFolderOutput.
* Constructor for QgsProcessingParameterFolderDestination.
*/
QgsProcessingParameterFolderOutput( const QString &name, const QString &description = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
QgsProcessingParameterFolderDestination( const QString &name, const QString &description = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false );
/**
* Returns the type name for the parameter class.
*/
static QString typeName() { return QStringLiteral( "folderOut" ); }
static QString typeName() { return QStringLiteral( "folderDestination" ); }
QString type() const override { return typeName(); }
bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
QgsProcessingOutputDefinition *toOutputDefinition() const override SIP_FACTORY;
@ -1796,7 +1807,7 @@ class CORE_EXPORT QgsProcessingParameterFolderOutput : public QgsProcessingDesti
/**
* Creates a new parameter using the definition from a script code.
*/
static QgsProcessingParameterFolderOutput *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
static QgsProcessingParameterFolderDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
};

View File

@ -461,6 +461,42 @@ QString QgsProcessingUtils::formatHelpMapAsHtml( const QVariantMap &map, const Q
return s;
}
QString QgsProcessingUtils::convertToCompatibleFormat( const QgsVectorLayer *vl, bool selectedFeaturesOnly, const QString &baseName, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
bool requiresTranslation = selectedFeaturesOnly;
if ( !selectedFeaturesOnly )
{
QFileInfo fi( vl->source() );
requiresTranslation = !compatibleFormats.contains( fi.suffix(), Qt::CaseInsensitive );
}
if ( requiresTranslation )
{
QString temp = QgsProcessingUtils::generateTempFilename( baseName + '.' + preferredFormat );
QgsVectorFileWriter writer( temp, context.defaultEncoding(),
vl->fields(), vl->wkbType(), vl->crs(), QgsVectorFileWriter::driverForExtension( preferredFormat ) );
QgsFeature f;
QgsFeatureIterator it;
if ( selectedFeaturesOnly )
it = vl->getSelectedFeatures();
else
it = vl->getFeatures();
while ( it.nextFeature( f ) )
{
if ( feedback->isCanceled() )
return QString();
writer.addFeature( f, QgsFeatureSink::FastInsert );
}
return temp;
}
else
{
return vl->source();
}
}
//
// QgsProcessingFeatureSource

View File

@ -28,6 +28,7 @@
class QgsProject;
class QgsProcessingContext;
class QgsMapLayerStore;
class QgsProcessingFeedback;
#include <QString>
#include <QVariant>
@ -189,6 +190,26 @@ class CORE_EXPORT QgsProcessingUtils
*/
static QString formatHelpMapAsHtml( const QVariantMap &map, const QgsProcessingAlgorithm *algorithm );
/**
* Converts a source vector \a layer to a file path to a vector layer of compatible format.
*
* If the specified \a layer is not of the format listed in the
* \a compatibleFormats argument, then the layer will first be exported to a compatible format
* in a temporary location using \a baseName. The function will then return the path to that temporary file.
*
* \a compatibleFormats should consist entirely of lowercase file extensions, e.g. 'shp'.
*
* The \a preferredFormat argument is used to specify to desired file extension to use when a temporary
* layer export is required. This defaults to shapefiles.
*/
static QString convertToCompatibleFormat( const QgsVectorLayer *layer,
bool selectedFeaturesOnly,
const QString &baseName,
const QStringList &compatibleFormats,
const QString &preferredFormat,
QgsProcessingContext &context,
QgsProcessingFeedback *feedback );
private:
static bool canUseLayer( const QgsRasterLayer *layer );

View File

@ -19,6 +19,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/core/layertree
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/processing
${CMAKE_SOURCE_DIR}/src/core/processing/models
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/scalebar
${CMAKE_SOURCE_DIR}/src/core/symbology-ng

File diff suppressed because it is too large Load Diff