Skip to content
Permalink
Browse files

Merge pull request #4590 from nyalldawson/processing_pt3

Processing armaggeddon, pt 1
  • Loading branch information
nyalldawson committed Jun 5, 2017
2 parents 632a2be + 77072b1 commit 2b0af000fd40b7c08a65011a58f57a3d039b0ad2
Showing 394 changed files with 13,403 additions and 10,868 deletions.
@@ -8,6 +8,11 @@ ProcessingGrass7AlgorithmsImageryTest
ProcessingGrass7AlgorithmsRasterTest
PyQgsDBManagerGpkg

# temporary during processing refactoring
ProcessingParametersTest
ProcessingModelerTest
ProcessingGdalAlgorithmsTest

# layout tests are run on separate build
qgis_indentation
qgis_spelling
@@ -285,8 +285,10 @@
%Include metadata/qgslayermetadatavalidator.sip

%Include processing/qgsprocessingalgorithm.sip
%Include processing/qgsprocessingalgrunnertask.sip
%Include processing/qgsprocessingcontext.sip
%Include processing/qgsprocessingfeedback.sip
%Include processing/qgsprocessingoutputs.sip
%Include processing/qgsprocessingparameters.sip
%Include processing/qgsprocessingprovider.sip
%Include processing/qgsprocessingregistry.sip
@@ -10,6 +10,7 @@




class QgsProcessingAlgorithm
{
%Docstring
@@ -76,6 +77,32 @@ class QgsProcessingAlgorithm
:rtype: list of str
%End

virtual QString shortHelpString() const;
%Docstring
Returns a localised short helper string for the algorithm. This string should provide a basic description
about what the algorithm does and the parameters and outputs associated with it.
.. seealso:: helpString()
.. seealso:: helpUrl()
:rtype: str
%End

virtual QString helpString() const;
%Docstring
Returns a localised help string for the algorithm. Algorithm subclasses should implement either
helpString() or helpUrl().
.. seealso:: helpUrl()
.. seealso:: shortHelpString()
:rtype: str
%End

virtual QString helpUrl() const;
%Docstring
Returns a url pointing to the algorithm's help page.
.. seealso:: helpString()
.. seealso:: shortHelpString()
:rtype: str
%End

virtual QIcon icon() const;
%Docstring
Returns an icon for the algorithm.
@@ -104,19 +131,38 @@ class QgsProcessingAlgorithm
:rtype: Flags
%End

virtual bool canExecute( QString *errorMessage /Out/ = 0 ) const;
%Docstring
Returns true if the algorithm can execute. Algorithm subclasses can return false
here to indicate that they are not able to execute, e.g. as a result of unmet
external dependencies. If specified, the ``errorMessage`` argument will be filled
with a localised error message describing why the algorithm cannot execute.
:rtype: bool
%End

virtual bool checkParameterValues( const QVariantMap &parameters,
QgsProcessingContext &context, QString *message /Out/ = 0 ) const;
%Docstring
Checks the supplied ``parameter`` values to verify that they satisfy the requirements
of this algorithm in the supplied ``context``. The ``message`` parameter will be
filled with explanatory text if validation fails.
Overridden implementations should also check this base class implementation.
:return: true if parameters are acceptable for the algorithm.
:rtype: bool
%End

QgsProcessingProvider *provider() const;
%Docstring
Returns the provider to which this algorithm belongs.
:rtype: QgsProcessingProvider
%End

void setProvider( QgsProcessingProvider *provider );

QgsProcessingParameterDefinitions parameterDefinitions() const;
%Docstring
Returns an ordered list of parameter definitions utilized by the algorithm.
.. seealso:: addParameter()
.. seealso:: parameterDefinition()
.. seealso:: destinationParameterDefinitions()
:rtype: QgsProcessingParameterDefinitions
%End

@@ -128,33 +174,97 @@ class QgsProcessingAlgorithm
:rtype: QgsProcessingParameterDefinition
%End

virtual QVariantMap run( const QVariantMap &parameters,
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const;
int countVisibleParameters() const;
%Docstring
Runs the algorithm using the specified ``parameters``. Algorithms should implement
their custom processing logic here.
Returns the number of visible (non-hidden) parameters defined by this
algorithm.
:rtype: int
%End

QgsProcessingParameterDefinitions destinationParameterDefinitions() const;
%Docstring
Returns a list of destination parameters definitions utilized by the algorithm.
.. seealso:: QgsProcessingParameterDefinition.isDestination()
.. seealso:: parameterDefinitions()
:rtype: QgsProcessingParameterDefinitions
%End

QgsProcessingOutputDefinitions outputDefinitions() const;
%Docstring
Returns an ordered list of output definitions utilized by the algorithm.
.. seealso:: addOutput()
.. seealso:: outputDefinition()
:rtype: QgsProcessingOutputDefinitions
%End

const QgsProcessingOutputDefinition *outputDefinition( const QString &name ) const;
%Docstring
Returns a matching output by ``name``. Matching is done in a case-insensitive
manner.
.. seealso:: outputDefinitions()
:rtype: QgsProcessingOutputDefinition
%End

QVariantMap run( const QVariantMap &parameters,
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const;
%Docstring
Executes the algorithm using the specified ``parameters``.

The ``context`` argument specifies the context in which the algorithm is being run.

Algorithm progress should be reported using the supplied ``feedback`` object. Additionally,
well-behaved algorithms should periodically check ``feedback`` to determine whether the
algorithm should be canceled and exited early.
Algorithm progress should be reported using the supplied ``feedback`` object.

:return: A map of algorithm outputs. These may be output layer references, or calculated
values such as statistical calculations.
:rtype: QVariantMap
%End

virtual QWidget *createCustomParametersWidget( QWidget *parent = 0 ) const /Factory/;
%Docstring
If an algorithm subclass implements a custom parameters widget, a copy of this widget
should be constructed and returned by this method.
The base class implementation returns None, which indicates that an autogenerated
parameters widget should be used.
:rtype: QWidget
%End

protected:

bool addParameter( QgsProcessingParameterDefinition *parameterDefinition /Transfer/ );
%Docstring
Adds a parameter ``definition`` to the algorithm. Ownership of the definition is transferred to the algorithm.
Returns true if parameter could be successfully added, or false if the parameter could not be added (e.g.
as a result of a duplicate name).
.. seealso:: addOutput()
:rtype: bool
%End

bool addOutput( QgsProcessingOutputDefinition *outputDefinition /Transfer/ );
%Docstring
Adds an output ``definition`` to the algorithm. Ownership of the definition is transferred to the algorithm.
Returns true if the output could be successfully added, or false if the output could not be added (e.g.
as a result of a duplicate name).
.. seealso:: addParameter()
:rtype: bool
%End

virtual QVariantMap processAlgorithm( const QVariantMap &parameters,
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const = 0;
%Docstring
Runs the algorithm using the specified ``parameters``. Algorithms should implement
their custom processing logic here.

The ``context`` argument specifies the context in which the algorithm is being run.

Algorithm progress should be reported using the supplied ``feedback`` object. Additionally,
well-behaved algorithms should periodically check ``feedback`` to determine whether the
algorithm should be canceled and exited early.

:return: A map of algorithm outputs. These may be output layer references, or calculated
values such as statistical calculations.
:rtype: QVariantMap
%End

QString parameterAsString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a static string value.
@@ -197,6 +307,36 @@ class QgsProcessingAlgorithm
:rtype: bool
%End

QgsFeatureSink *parameterAsSink( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context,
const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs,
QString &destinationIdentifier /Out/ ) const /Factory/;
%Docstring
Evaluates the parameter with matching ``name`` to a feature sink.

Sinks will either be taken from ``context``'s active project, or created from external
providers and stored temporarily in the ``context``.

The ``fields``, ``geometryType`` and ``crs`` parameters dictate the properties
of the resulting feature sink.

The ``destinationIdentifier`` argument will be set to a string which can be used to retrieve the layer corresponding
to the sink, e.g. via calling QgsProcessingUtils.mapLayerFromString().

This function creates a new object and the caller takes responsibility for deleting the returned object.
:rtype: QgsFeatureSink
%End

QgsFeatureSource *parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const /Factory/;
%Docstring
Evaluates the parameter with matching ``definition`` 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``.

This function creates a new object and the caller takes responsibility for deleting the returned object.
:rtype: QgsFeatureSource
%End

QgsMapLayer *parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a map layer.
@@ -285,6 +425,8 @@ QFlags<QgsProcessingAlgorithm::Flag> operator|(QgsProcessingAlgorithm::Flag f1,





/************************************************************************
* This file has been generated automatically from *
* *
@@ -0,0 +1,50 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingalgrunnertask.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsProcessingAlgRunnerTask : QgsTask
{
%Docstring
QgsTask task which runs a QgsProcessingAlgorithm in a background task.
.. versionadded:: 3.0
%End

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

QgsProcessingAlgRunnerTask( const QgsProcessingAlgorithm *algorithm,
const QVariantMap &parameters,
QgsProcessingContext &context );
%Docstring
Constructor for QgsProcessingAlgRunnerTask. Takes an ``algorithm``, algorithm ``parameters``
and processing ``context``.
%End

virtual void cancel();

protected:

virtual bool run();
virtual void finished( bool result );

};



/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingalgrunnertask.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -27,7 +27,7 @@ class QgsProcessingContext

enum Flag
{
UseSelectionIfPresent,
// UseSelectionIfPresent,
};
typedef QFlags<QgsProcessingContext::Flag> Flags;

@@ -83,6 +83,49 @@ class QgsProcessingContext
:rtype: QgsMapLayerStore
%End

struct LayerDetails
{

LayerDetails( const QString &name, QgsProject *project );
%Docstring
Constructor for LayerDetails.
%End

QString name;
%Docstring
Friendly name for layer, to use when loading layer into project.
%End

QgsProject *project;
%Docstring
Destination project
%End

};

QMap< QString, QgsProcessingContext::LayerDetails > layersToLoadOnCompletion() const;
%Docstring
Returns a map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.
.. seealso:: setLayersToLoadOnCompletion()
.. seealso:: addLayerToLoadOnCompletion()
:rtype: QMap< str, QgsProcessingContext.LayerDetails >
%End

void setLayersToLoadOnCompletion( const QMap< QString, QgsProcessingContext::LayerDetails > &layers );
%Docstring
Sets the map of ``layers`` (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.
.. seealso:: addLayerToLoadOnCompletion()
.. seealso:: layersToLoadOnCompletion()
%End

void addLayerToLoadOnCompletion( const QString &layer, const QgsProcessingContext::LayerDetails &details );
%Docstring
Adds a ``layer`` to load (by ID or datasource) into the canvas upon completion of the algorithm or model.
The ``details`` parameter dictates the LayerDetails.
.. seealso:: setLayersToLoadOnCompletion()
.. seealso:: layersToLoadOnCompletion()
%End


QgsFeatureRequest::InvalidGeometryCheck invalidGeometryCheck() const;
%Docstring
@@ -137,6 +180,10 @@ class QgsProcessingContext
QgsProcessingContext( const QgsProcessingContext &other );
};





QFlags<QgsProcessingContext::Flag> operator|(QgsProcessingContext::Flag f1, QFlags<QgsProcessingContext::Flag> f2);


0 comments on commit 2b0af00

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