QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
Classes | Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
QgsProcessingAlgorithm Class Referenceabstract

Abstract base class for processing algorithms. More...

#include <qgsprocessingalgorithm.h>

Inheritance diagram for QgsProcessingAlgorithm:
Inheritance graph
[legend]

Classes

struct  VectorProperties
 Properties of a vector source or sink used in an algorithm. More...
 

Public Types

enum  Flag {
  FlagHideFromToolbox = 1 << 1 , FlagHideFromModeler = 1 << 2 , FlagSupportsBatch = 1 << 3 , FlagCanCancel = 1 << 4 ,
  FlagRequiresMatchingCrs = 1 << 5 , FlagNoThreading = 1 << 6 , FlagDisplayNameIsLiteral = 1 << 7 , FlagSupportsInPlaceEdits = 1 << 8 ,
  FlagKnownIssues = 1 << 9 , FlagCustomException = 1 << 10 , FlagPruneModelBranchesBasedOnAlgorithmResults = 1 << 11 , FlagSkipGenericModelLogging = 1 << 12 ,
  FlagNotAvailableInStandaloneTool = 1 << 13 , FlagRequiresProject = 1 << 14 , FlagDeprecated = FlagHideFromToolbox | FlagHideFromModeler
}
 Flags indicating how and when an algorithm operates and should be exposed to users. More...
 
enum  PropertyAvailability { NotAvailable , Available }
 Property availability, used for QgsProcessingAlgorithm::VectorProperties in order to determine if properties are available or not. More...
 

Public Member Functions

 QgsProcessingAlgorithm ()=default
 Constructor for QgsProcessingAlgorithm. More...
 
 QgsProcessingAlgorithm (const QgsProcessingAlgorithm &other)=delete
 Algorithms cannot be copied - create() should be used instead. More...
 
virtual ~QgsProcessingAlgorithm ()
 
virtual QString asPythonCommand (const QVariantMap &parameters, QgsProcessingContext &context) const
 Returns a Python command string which can be executed to run the algorithm using the specified parameters. More...
 
virtual bool canExecute (QString *errorMessage=nullptr) const
 Returns true if the algorithm can execute. More...
 
virtual bool checkParameterValues (const QVariantMap &parameters, QgsProcessingContext &context, QString *message=nullptr) const
 Checks the supplied parameter values to verify that they satisfy the requirements of this algorithm in the supplied context. More...
 
int countVisibleParameters () const
 Returns the number of visible (non-hidden) parameters defined by this algorithm. More...
 
QgsProcessingAlgorithmcreate (const QVariantMap &configuration=QVariantMap()) const SIP_THROW(QgsProcessingException)
 Creates a copy of the algorithm, ready for execution. More...
 
virtual QWidget * createCustomParametersWidget (QWidget *parent=nullptr) const
 If an algorithm subclass implements a custom parameters widget, a copy of this widget should be constructed and returned by this method. More...
 
virtual QgsExpressionContext createExpressionContext (const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeatureSource *source=nullptr) const
 Creates an expression context relating to the algorithm. More...
 
QgsProcessingParameterDefinitions destinationParameterDefinitions () const
 Returns a list of destination parameters definitions utilized by the algorithm. More...
 
virtual QString displayName () const =0
 Returns the translated algorithm name, which should be used for any user-visible display of the algorithm name. More...
 
virtual Flags flags () const
 Returns the flags indicating how and when the algorithm operates and should be exposed to users. More...
 
virtual QString group () const
 Returns the name of the group this algorithm belongs to. More...
 
virtual QString groupId () const
 Returns the unique ID of the group this algorithm belongs to. More...
 
bool hasHtmlOutputs () const
 Returns true if this algorithm generates HTML outputs. More...
 
virtual Q_DECL_DEPRECATED QString helpString () const
 Returns a localised help string for the algorithm. More...
 
virtual QString helpUrl () const
 Returns a url pointing to the algorithm's help page. More...
 
virtual QIcon icon () const
 Returns an icon for the algorithm. More...
 
QString id () const
 Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and the algorithms unique name (e.g. More...
 
virtual QString name () const =0
 Returns the algorithm name, used for identifying the algorithm. More...
 
QgsProcessingAlgorithmoperator= (const QgsProcessingAlgorithm &other)=delete
 Algorithms cannot be copied- create() should be used instead. More...
 
const QgsProcessingOutputDefinitionoutputDefinition (const QString &name) const
 Returns a matching output by name. More...
 
QgsProcessingOutputDefinitions outputDefinitions () const
 Returns an ordered list of output definitions utilized by the algorithm. More...
 
const QgsProcessingParameterDefinitionparameterDefinition (const QString &name) const
 Returns a matching parameter by name. More...
 
QgsProcessingParameterDefinitions parameterDefinitions () const
 Returns an ordered list of parameter definitions utilized by the algorithm. More...
 
QVariantMap postProcess (QgsProcessingContext &context, QgsProcessingFeedback *feedback)
 Should be called in the main thread following the completion of runPrepared(). More...
 
bool prepare (const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
 Prepares the algorithm for execution. More...
 
virtual QVariantMap preprocessParameters (const QVariantMap &parameters)
 Pre-processes a set of parameters, allowing the algorithm to clean their values. More...
 
QgsProcessingProviderprovider () const
 Returns the provider to which this algorithm belongs. More...
 
QVariantMap run (const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok=nullptr, const QVariantMap &configuration=QVariantMap(), bool catchExceptions=true) const SIP_THROW(QgsProcessingException)
 Executes the algorithm using the specified parameters. More...
 
QVariantMap runPrepared (const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
 Runs the algorithm, which has been prepared by an earlier call to prepare(). More...
 
void setProvider (QgsProcessingProvider *provider)
 Associates this algorithm with its provider. More...
 
virtual QString shortDescription () const
 Returns an optional translated short description of the algorithm. More...
 
virtual QString shortHelpString () const
 Returns a localised short helper string for the algorithm. More...
 
virtual QgsProcessingAlgorithm::VectorProperties sinkProperties (const QString &sink, const QVariantMap &parameters, QgsProcessingContext &context, const QMap< QString, QgsProcessingAlgorithm::VectorProperties > &sourceProperties) const
 Returns the vector properties which will be used for the sink with matching name. More...
 
virtual QString svgIconPath () const
 Returns a path to an SVG version of the algorithm's icon. More...
 
virtual QStringList tags () const
 Returns a list of tags which relate to the algorithm, and are used to assist users in searching for suitable algorithms. More...
 
virtual bool validateInputCrs (const QVariantMap &parameters, QgsProcessingContext &context) const
 Checks whether the coordinate reference systems for the specified set of parameters are valid for the algorithm. More...
 

Protected Member Functions

bool addOutput (QgsProcessingOutputDefinition *outputDefinition)
 Adds an output definition to the algorithm. More...
 
bool addParameter (QgsProcessingParameterDefinition *parameterDefinition, bool createOutput=true)
 Adds a parameter definition to the algorithm. More...
 
virtual QgsProcessingAlgorithmcreateInstance () const =0
 Creates a new instance of the algorithm class. More...
 
virtual void initAlgorithm (const QVariantMap &configuration=QVariantMap())=0
 Initializes the algorithm using the specified configuration. More...
 
QgsAnnotationLayerparameterAsAnnotationLayer (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to an annotation layer. More...
 
bool parameterAsBool (const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a static boolean value. More...
 
bool parameterAsBoolean (const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a static boolean value. More...
 
QColor parameterAsColor (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
 Evaluates the parameter with matching name to a color, or returns an invalid color if the parameter was not set. More...
 
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 name to a source vector layer file path of compatible format. More...
 
QString parameterAsCompatibleSourceLayerPathAndLayerName (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr, QString *layerName=nullptr)
 Evaluates the parameter with matching name to a source vector layer file path and layer name of compatible format. More...
 
QString parameterAsConnectionName (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
 Evaluates the parameter with matching name to a connection name string. More...
 
QgsCoordinateReferenceSystem parameterAsCrs (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a coordinate reference system. More...
 
QString parameterAsDatabaseTableName (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
 Evaluates the parameter with matching name to a database table name string. More...
 
QDateTime parameterAsDateTime (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
 Evaluates the parameter with matching name to a DateTime, or returns an invalid date time if the parameter was not set. More...
 
double parameterAsDouble (const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a static double value. More...
 
int parameterAsEnum (const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a enum value. More...
 
QList< int > parameterAsEnums (const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
 Evaluates the parameter with matching name to list of enum values. More...
 
QString parameterAsEnumString (const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a static enum string. More...
 
QStringList parameterAsEnumStrings (const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
 Evaluates the parameter with matching name to list of static enum strings. More...
 
QString parameterAsExpression (const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
 Evaluates the parameter with matching name to an expression. More...
 
QgsRectangle parameterAsExtent (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
 Evaluates the parameter with matching name to a rectangular extent. More...
 
QgsCoordinateReferenceSystem parameterAsExtentCrs (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
 Returns the coordinate reference system associated with an extent parameter value. More...
 
QgsGeometry parameterAsExtentGeometry (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
 Evaluates the parameter with matching name to a rectangular extent, and returns a geometry covering this extent. More...
 
QStringList parameterAsFields (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a list of fields. More...
 
QString parameterAsFile (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a file/folder name. More...
 
QStringList parameterAsFileList (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a list of files (for QgsProcessingParameterMultipleLayers in QgsProcessing:TypeFile mode). More...
 
QString parameterAsFileOutput (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a file based output destination. More...
 
QgsGeometry parameterAsGeometry (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
 Evaluates the parameter with matching name to a geometry. More...
 
QgsCoordinateReferenceSystem parameterAsGeometryCrs (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
 Returns the coordinate reference system associated with a geometry parameter value. More...
 
int parameterAsInt (const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a static integer value. More...
 
QList< int > parameterAsInts (const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a list of integer values. More...
 
QgsMapLayerparameterAsLayer (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a map layer. More...
 
QList< QgsMapLayer * > parameterAsLayerList (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a list of map layers. More...
 
QgsPrintLayoutparameterAsLayout (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
 Evaluates the parameter with matching name to a print layout. More...
 
QgsLayoutItemparameterAsLayoutItem (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsPrintLayout *layout)
 Evaluates the parameter with matching name to a print layout item, taken from the specified layout. More...
 
QVariantList parameterAsMatrix (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a matrix/table of values. More...
 
QgsMeshLayerparameterAsMeshLayer (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a mesh layer. More...
 
QString parameterAsOutputLayer (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a output layer destination. More...
 
QgsPointXY parameterAsPoint (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
 Evaluates the parameter with matching name to a point. More...
 
QgsPointCloudLayerparameterAsPointCloudLayer (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a point cloud layer. More...
 
QgsCoordinateReferenceSystem parameterAsPointCrs (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
 Returns the coordinate reference system associated with an point parameter value. More...
 
QList< double > parameterAsRange (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a range of values. More...
 
QgsRasterLayerparameterAsRasterLayer (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a raster layer. More...
 
QString parameterAsSchema (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
 Evaluates the parameter with matching name to a database schema name string. More...
 
QgsFeatureSinkparameterAsSink (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QString &destinationIdentifier, const QgsFields &fields, QgsWkbTypes::Type geometryType=QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem(), QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList()) const SIP_THROW(QgsProcessingException)
 Evaluates the parameter with matching name to a feature sink. More...
 
QgsProcessingFeatureSourceparameterAsSource (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a feature source. More...
 
QString parameterAsString (const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a static string value. More...
 
QgsVectorLayerparameterAsVectorLayer (const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
 Evaluates the parameter with matching name to a vector layer. More...
 
virtual QVariantMap postProcessAlgorithm (QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
 Allows the algorithm to perform any required cleanup tasks. More...
 
virtual bool prepareAlgorithm (const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
 Prepares the algorithm to run using the specified parameters. More...
 
virtual QVariantMap processAlgorithm (const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)=0
 Runs the algorithm using the specified parameters. More...
 
void removeParameter (const QString &name)
 Removes the parameter with matching name from the algorithm, and deletes any existing definition. More...
 
virtual bool supportInPlaceEdit (const QgsMapLayer *layer) const
 Checks whether this algorithm supports in-place editing on the given layer Default implementation returns false. More...
 

Static Protected Member Functions

static QString invalidRasterError (const QVariantMap &parameters, const QString &name)
 Returns a user-friendly string to use as an error when a raster layer input could not be loaded. More...
 
static QString invalidSinkError (const QVariantMap &parameters, const QString &name)
 Returns a user-friendly string to use as an error when a sink parameter could not be created. More...
 
static QString invalidSourceError (const QVariantMap &parameters, const QString &name)
 Returns a user-friendly string to use as an error when a source parameter could not be loaded. More...
 
static QString writeFeatureError (QgsFeatureSink *sink, const QVariantMap &parameters, const QString &name)
 Returns a user-friendly string to use as an error when a feature cannot be written into a sink. More...
 

Friends

class QgsProcessingModelAlgorithm
 
class QgsProcessingProvider
 
class QgsProcessingToolboxProxyModel
 
class TestQgsProcessing
 

Detailed Description

Abstract base class for processing algorithms.

Since
QGIS 3.0

Definition at line 52 of file qgsprocessingalgorithm.h.

Member Enumeration Documentation

◆ Flag

Flags indicating how and when an algorithm operates and should be exposed to users.

Enumerator
FlagHideFromToolbox 

Algorithm should be hidden from the toolbox.

FlagHideFromModeler 

Algorithm should be hidden from the modeler.

FlagSupportsBatch 

Algorithm supports batch mode.

FlagCanCancel 

Algorithm can be canceled.

FlagRequiresMatchingCrs 

Algorithm requires that all input layers have matching coordinate reference systems.

FlagNoThreading 

Algorithm is not thread safe and cannot be run in a background thread, e.g. for algorithms which manipulate the current project, layer selections, or with external dependencies which are not thread-safe.

FlagDisplayNameIsLiteral 

Algorithm's display name is a static literal string, and should not be translated or automatically formatted. For use with algorithms named after commands, e.g. GRASS 'v.in.ogr'.

FlagSupportsInPlaceEdits 

Algorithm supports in-place editing.

FlagKnownIssues 

Algorithm has known issues.

FlagCustomException 

Algorithm raises custom exception notices, don't use the standard ones.

FlagPruneModelBranchesBasedOnAlgorithmResults 

Algorithm results will cause remaining model branches to be pruned based on the results of running the algorithm.

FlagSkipGenericModelLogging 

When running as part of a model, the generic algorithm setup and results logging should be skipped.

FlagNotAvailableInStandaloneTool 

Algorithm should not be available from the standalone "qgis_process" tool. Used to flag algorithms which make no sense outside of the QGIS application, such as "select by..." style algorithms.

FlagRequiresProject 

The algorithm requires that a valid QgsProject is available from the processing context in order to execute.

FlagDeprecated 

Algorithm is deprecated.

Definition at line 69 of file qgsprocessingalgorithm.h.

◆ PropertyAvailability

Property availability, used for QgsProcessingAlgorithm::VectorProperties in order to determine if properties are available or not.

Enumerator
NotAvailable 

Properties are not available.

Available 

Properties are available.

Definition at line 325 of file qgsprocessingalgorithm.h.

Constructor & Destructor Documentation

◆ QgsProcessingAlgorithm() [1/2]

QgsProcessingAlgorithm::QgsProcessingAlgorithm ( )
default

Constructor for QgsProcessingAlgorithm.

initAlgorithm() should be called after creating an algorithm to ensure it can correctly configure its parameterDefinitions() and outputDefinitions(). Alternatively, calling create() will return a pre-initialized copy of the algorithm.

◆ ~QgsProcessingAlgorithm()

QgsProcessingAlgorithm::~QgsProcessingAlgorithm ( )
virtual

Definition at line 35 of file qgsprocessingalgorithm.cpp.

◆ QgsProcessingAlgorithm() [2/2]

QgsProcessingAlgorithm::QgsProcessingAlgorithm ( const QgsProcessingAlgorithm other)
delete

Algorithms cannot be copied - create() should be used instead.

Member Function Documentation

◆ addOutput()

bool QgsProcessingAlgorithm::addOutput ( QgsProcessingOutputDefinition outputDefinition)
protected

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).

This should usually be called from a subclass' initAlgorithm() implementation.

Note that in some cases output creation can be automatically performed when calling addParameter(). See the notes in addParameter() for a description of when this occurs.

See also
addParameter()
initAlgorithm()

Definition at line 357 of file qgsprocessingalgorithm.cpp.

◆ addParameter()

bool QgsProcessingAlgorithm::addParameter ( QgsProcessingParameterDefinition parameterDefinition,
bool  createOutput = true 
)
protected

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).

This should usually be called from a subclass' initAlgorithm() implementation.

If the createOutput argument is true, then a corresponding output definition will also be created (and added to the algorithm) where appropriate. E.g. when adding a QgsProcessingParameterVectorDestination and createOutput is true, then a QgsProcessingOutputVectorLayer output will be created and added to the algorithm. There is no need to call addOutput() to manually add a corresponding output for this vector. If createOutput is false then this automatic output creation will not occur.

See also
initAlgorithm()
addOutput()

Definition at line 309 of file qgsprocessingalgorithm.cpp.

◆ asPythonCommand()

QString QgsProcessingAlgorithm::asPythonCommand ( const QVariantMap &  parameters,
QgsProcessingContext context 
) const
virtual

Returns a Python command string which can be executed to run the algorithm using the specified parameters.

Algorithms which cannot be run from a Python command should return an empty string.

Definition at line 289 of file qgsprocessingalgorithm.cpp.

◆ canExecute()

bool QgsProcessingAlgorithm::canExecute ( QString *  errorMessage = nullptr) const
virtual

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.

Definition at line 94 of file qgsprocessingalgorithm.cpp.

◆ checkParameterValues()

bool QgsProcessingAlgorithm::checkParameterValues ( const QVariantMap &  parameters,
QgsProcessingContext context,
QString *  message = nullptr 
) const
virtual

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.

Returns
true if parameters are acceptable for the algorithm.

Definition at line 99 of file qgsprocessingalgorithm.cpp.

◆ countVisibleParameters()

int QgsProcessingAlgorithm::countVisibleParameters ( ) const

Returns the number of visible (non-hidden) parameters defined by this algorithm.

Definition at line 402 of file qgsprocessingalgorithm.cpp.

◆ create()

QgsProcessingAlgorithm * QgsProcessingAlgorithm::create ( const QVariantMap &  configuration = QVariantMap()) const

Creates a copy of the algorithm, ready for execution.

This method returns a new, preinitialized copy of the algorithm, ready for executing.

The configuration argument allows passing of a map of configuration settings to the algorithm, allowing it to dynamically adjust its initialized parameters and outputs according to this configuration. This is generally used only for algorithms in a model, allowing them to adjust their behavior at run time according to some user configuration.

Raises a QgsProcessingException if a new algorithm instance could not be created, e.g. if there is an issue with the subclass' createInstance() method.

See also
initAlgorithm()

Definition at line 41 of file qgsprocessingalgorithm.cpp.

◆ createCustomParametersWidget()

QWidget * QgsProcessingAlgorithm::createCustomParametersWidget ( QWidget *  parent = nullptr) const
virtual

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 nullptr, which indicates that an autogenerated parameters widget should be used.

Definition at line 152 of file qgsprocessingalgorithm.cpp.

◆ createExpressionContext()

QgsExpressionContext QgsProcessingAlgorithm::createExpressionContext ( const QVariantMap &  parameters,
QgsProcessingContext context,
QgsProcessingFeatureSource source = nullptr 
) const
virtual

Creates an expression context relating to the algorithm.

This can be called by algorithms to create a new expression context ready for evaluating expressions within the algorithm. Optionally, a source can be specified which will be used to populate the context if it implements the QgsExpressionContextGenerator interface.

Definition at line 157 of file qgsprocessingalgorithm.cpp.

◆ createInstance()

virtual QgsProcessingAlgorithm* QgsProcessingAlgorithm::createInstance ( ) const
protectedpure virtual

Creates a new instance of the algorithm class.

This method should return a 'pristine' instance of the algorithm class.

◆ destinationParameterDefinitions()

QgsProcessingParameterDefinitions QgsProcessingAlgorithm::destinationParameterDefinitions ( ) const

Returns a list of destination parameters definitions utilized by the algorithm.

See also
QgsProcessingParameterDefinition::isDestination()
parameterDefinitions()

Definition at line 413 of file qgsprocessingalgorithm.cpp.

◆ displayName()

virtual QString QgsProcessingAlgorithm::displayName ( ) const
pure virtual

Returns the translated algorithm name, which should be used for any user-visible display of the algorithm name.

Algorithm display names should be short, e.g. ideally no more than 3 or 4 words. The name should use sentence case (e.g. "Raster layer statistics", not "Raster Layer Statistics").

See also
name()
shortDescription()

◆ flags()

QgsProcessingAlgorithm::Flags QgsProcessingAlgorithm::flags ( ) const
virtual

Returns the flags indicating how and when the algorithm operates and should be exposed to users.

Default flags are FlagSupportsBatch and FlagCanCancel.

Reimplemented in QgsProcessingFeatureBasedAlgorithm.

Definition at line 89 of file qgsprocessingalgorithm.cpp.

◆ group()

virtual QString QgsProcessingAlgorithm::group ( ) const
inlinevirtual

Returns the name of the group this algorithm belongs to.

This string should be localised.

See also
groupId()
tags()

Reimplemented in QgsBatchGeocodeAlgorithm.

Definition at line 225 of file qgsprocessingalgorithm.h.

◆ groupId()

virtual QString QgsProcessingAlgorithm::groupId ( ) const
inlinevirtual

Returns the unique ID of the group this algorithm belongs to.

This string should be fixed for the algorithm, and must not be localised. The group id should be unique within each provider. Group id should contain lowercase alphanumeric characters only and no spaces or other formatting characters.

See also
group()

Reimplemented in QgsBatchGeocodeAlgorithm.

Definition at line 234 of file qgsprocessingalgorithm.h.

◆ hasHtmlOutputs()

bool QgsProcessingAlgorithm::hasHtmlOutputs ( ) const

Returns true if this algorithm generates HTML outputs.

Definition at line 434 of file qgsprocessingalgorithm.cpp.

◆ helpString()

QString QgsProcessingAlgorithm::helpString ( ) const
virtual

Returns a localised help string for the algorithm.

Algorithm subclasses should implement either helpString() or helpUrl().

See also
helpUrl()
shortHelpString()
Deprecated:
Unused, will be removed in QGIS 4.0

Definition at line 69 of file qgsprocessingalgorithm.cpp.

◆ helpUrl()

QString QgsProcessingAlgorithm::helpUrl ( ) const
virtual

Returns a url pointing to the algorithm's help page.

See also
helpString()
shortHelpString()

Definition at line 74 of file qgsprocessingalgorithm.cpp.

◆ icon()

QIcon QgsProcessingAlgorithm::icon ( ) const
virtual

Returns an icon for the algorithm.

See also
svgIconPath()

Definition at line 79 of file qgsprocessingalgorithm.cpp.

◆ id()

QString QgsProcessingAlgorithm::id ( ) const

Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and the algorithms unique name (e.g.

"qgis:mergelayers" ).

See also
name()
provider()

Definition at line 51 of file qgsprocessingalgorithm.cpp.

◆ initAlgorithm()

virtual void QgsProcessingAlgorithm::initAlgorithm ( const QVariantMap &  configuration = QVariantMap())
protectedpure virtual

Initializes the algorithm using the specified configuration.

This should be called directly after creating algorithms and before retrieving any parameterDefinitions() or outputDefinitions().

Subclasses should use their implementations to add all required input parameter and output definitions (which can be dynamically adjusted according to configuration).

Dynamic configuration can be used by algorithms which alter their behavior when used inside processing models. For instance, a "feature router" type algorithm which sends input features to one of any number of outputs sinks based on some preconfigured filter parameters can use the init method to create these outputs based on the specified configuration.

See also
addParameter()
addOutput()

Implemented in QgsProcessingFeatureBasedAlgorithm.

◆ invalidRasterError()

QString QgsProcessingAlgorithm::invalidRasterError ( const QVariantMap &  parameters,
const QString &  name 
)
staticprotected

Returns a user-friendly string to use as an error when a raster layer input could not be loaded.

The parameters argument should give the algorithms parameter map, and the name should correspond to the invalid source parameter name.

See also
invalidSourceError()
invalidSinkError()
Since
QGIS 3.2

Definition at line 841 of file qgsprocessingalgorithm.cpp.

◆ invalidSinkError()

QString QgsProcessingAlgorithm::invalidSinkError ( const QVariantMap &  parameters,
const QString &  name 
)
staticprotected

Returns a user-friendly string to use as an error when a sink parameter could not be created.

The parameters argument should give the algorithms parameter map, and the name should correspond to the invalid source parameter name.

See also
invalidSourceError()
invalidRasterError()
Since
QGIS 3.2

Definition at line 863 of file qgsprocessingalgorithm.cpp.

◆ invalidSourceError()

QString QgsProcessingAlgorithm::invalidSourceError ( const QVariantMap &  parameters,
const QString &  name 
)
staticprotected

Returns a user-friendly string to use as an error when a source parameter could not be loaded.

The parameters argument should give the algorithms parameter map, and the name should correspond to the invalid source parameter name.

See also
invalidRasterError()
invalidSinkError()
Since
QGIS 3.2

Definition at line 809 of file qgsprocessingalgorithm.cpp.

◆ name()

virtual QString QgsProcessingAlgorithm::name ( ) const
pure virtual

Returns the algorithm name, used for identifying the algorithm.

This string should be fixed for the algorithm, and must not be localised. The name should be unique within each provider. Names should contain lowercase alphanumeric characters only and no spaces or other formatting characters.

See also
displayName()
group()
tags()

◆ operator=()

QgsProcessingAlgorithm& QgsProcessingAlgorithm::operator= ( const QgsProcessingAlgorithm other)
delete

Algorithms cannot be copied- create() should be used instead.

◆ outputDefinition()

const QgsProcessingOutputDefinition * QgsProcessingAlgorithm::outputDefinition ( const QString &  name) const

Returns a matching output by name.

Matching is done in a case-insensitive manner.

See also
outputDefinitions()

Definition at line 424 of file qgsprocessingalgorithm.cpp.

◆ outputDefinitions()

QgsProcessingOutputDefinitions QgsProcessingAlgorithm::outputDefinitions ( ) const
inline

Returns an ordered list of output definitions utilized by the algorithm.

See also
addOutput()
outputDefinition()

Definition at line 307 of file qgsprocessingalgorithm.h.

◆ parameterAsAnnotationLayer()

QgsAnnotationLayer * QgsProcessingAlgorithm::parameterAsAnnotationLayer ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to an annotation layer.

Annotation layers will be taken from context's active project. Callers do not need to handle deletion of the returned layer.

Warning
Working with annotation layers is generally not thread safe (unless the layers are from a QgsProject loaded directly in a background thread). Ensure your algorithm returns the QgsProcessingAlgorithm::FlagNoThreading flag or only accesses annotation layers from a prepareAlgorithm() or postProcessAlgorithm() step.
Since
QGIS 3.22

Definition at line 804 of file qgsprocessingalgorithm.cpp.

◆ parameterAsBool()

bool QgsProcessingAlgorithm::parameterAsBool ( const QVariantMap &  parameters,
const QString &  name,
const QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a static boolean value.

Definition at line 631 of file qgsprocessingalgorithm.cpp.

◆ parameterAsBoolean()

bool QgsProcessingAlgorithm::parameterAsBoolean ( const QVariantMap &  parameters,
const QString &  name,
const QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a static boolean value.

Since
QGIS 3.8

Definition at line 636 of file qgsprocessingalgorithm.cpp.

◆ parameterAsColor()

QColor QgsProcessingAlgorithm::parameterAsColor ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
)
protected

Evaluates the parameter with matching name to a color, or returns an invalid color if the parameter was not set.

Since
QGIS 3.10

Definition at line 774 of file qgsprocessingalgorithm.cpp.

◆ parameterAsCompatibleSourceLayerPath()

QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPath ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context,
const QStringList &  compatibleFormats,
const QString &  preferredFormat = QString( "shp" ),
QgsProcessingFeedback feedback = nullptr 
)
protected

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.

When an algorithm is capable of handling multi-layer input files (such as Geopackage), it is preferable to use parameterAsCompatibleSourceLayerPathAndLayerName() which may avoid conversion in more situations.

Definition at line 654 of file qgsprocessingalgorithm.cpp.

◆ parameterAsCompatibleSourceLayerPathAndLayerName()

QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPathAndLayerName ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context,
const QStringList &  compatibleFormats,
const QString &  preferredFormat = QString( "shp" ),
QgsProcessingFeedback feedback = nullptr,
QString *  layerName = nullptr 
)
protected

Evaluates the parameter with matching name to a source vector layer file path and layer name 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!).

This method should be preferred over parameterAsCompatibleSourceLayerPath() when an algorithm is able to correctly handle files with multiple layers. Unlike parameterAsCompatibleSourceLayerPath(), it will not force a conversion in this case and will return the target layer name in the layerName argument.

Parameters
parametersinput parameter value map
namename of target parameter
contextprocessing context
compatibleFormatsa list of lowercase file extensions compatible with the algorithm
preferredFormatpreferred format extension to use if conversion if required
feedbackfeedback object
layerNamewill be set to the target layer name for multi-layer sources (e.g. Geopackage)
Returns
path to source layer, or nearly converted compatible layer
See also
parameterAsCompatibleSourceLayerPath()
Since
QGIS 3.10

Definition at line 659 of file qgsprocessingalgorithm.cpp.

◆ parameterAsConnectionName()

QString QgsProcessingAlgorithm::parameterAsConnectionName ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
)
protected

Evaluates the parameter with matching name to a connection name string.

Since
QGIS 3.14

Definition at line 779 of file qgsprocessingalgorithm.cpp.

◆ parameterAsCrs()

QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsCrs ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a coordinate reference system.

Definition at line 694 of file qgsprocessingalgorithm.cpp.

◆ parameterAsDatabaseTableName()

QString QgsProcessingAlgorithm::parameterAsDatabaseTableName ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
)
protected

Evaluates the parameter with matching name to a database table name string.

Since
QGIS 3.14

Definition at line 794 of file qgsprocessingalgorithm.cpp.

◆ parameterAsDateTime()

QDateTime QgsProcessingAlgorithm::parameterAsDateTime ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
)
protected

Evaluates the parameter with matching name to a DateTime, or returns an invalid date time if the parameter was not set.

Since
QGIS 3.14

Definition at line 784 of file qgsprocessingalgorithm.cpp.

◆ parameterAsDouble()

double QgsProcessingAlgorithm::parameterAsDouble ( const QVariantMap &  parameters,
const QString &  name,
const QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a static double value.

Definition at line 596 of file qgsprocessingalgorithm.cpp.

◆ parameterAsEnum()

int QgsProcessingAlgorithm::parameterAsEnum ( const QVariantMap &  parameters,
const QString &  name,
const QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a enum value.

Definition at line 611 of file qgsprocessingalgorithm.cpp.

◆ parameterAsEnums()

QList< int > QgsProcessingAlgorithm::parameterAsEnums ( const QVariantMap &  parameters,
const QString &  name,
const QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to list of enum values.

Definition at line 616 of file qgsprocessingalgorithm.cpp.

◆ parameterAsEnumString()

QString QgsProcessingAlgorithm::parameterAsEnumString ( const QVariantMap &  parameters,
const QString &  name,
const QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a static enum string.

Since
QGIS 3.18

Definition at line 621 of file qgsprocessingalgorithm.cpp.

◆ parameterAsEnumStrings()

QStringList QgsProcessingAlgorithm::parameterAsEnumStrings ( const QVariantMap &  parameters,
const QString &  name,
const QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to list of static enum strings.

Since
QGIS 3.18

Definition at line 626 of file qgsprocessingalgorithm.cpp.

◆ parameterAsExpression()

QString QgsProcessingAlgorithm::parameterAsExpression ( const QVariantMap &  parameters,
const QString &  name,
const QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to an expression.

Definition at line 591 of file qgsprocessingalgorithm.cpp.

◆ parameterAsExtent()

QgsRectangle QgsProcessingAlgorithm::parameterAsExtent ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context,
const QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem() 
) const
protected

Evaluates the parameter with matching name to a rectangular extent.

If crs is set, and the original coordinate reference system of the parameter can be determined, then the extent will be automatically reprojected so that it is in the specified crs. In this case the extent of the reproject rectangle will be returned.

See also
parameterAsExtentGeometry()

Definition at line 704 of file qgsprocessingalgorithm.cpp.

◆ parameterAsExtentCrs()

QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsExtentCrs ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
)
protected

Returns the coordinate reference system associated with an extent parameter value.

See also
parameterAsExtent()

Definition at line 699 of file qgsprocessingalgorithm.cpp.

◆ parameterAsExtentGeometry()

QgsGeometry QgsProcessingAlgorithm::parameterAsExtentGeometry ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context,
const QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem() 
)
protected

Evaluates the parameter with matching name to a rectangular extent, and returns a geometry covering this extent.

If crs is set, and the original coordinate reference system of the parameter can be determined, then the extent will be automatically reprojected so that it is in the specified crs. Unlike parameterAsExtent(), the reprojected rectangle returned by this function will no longer be a rectangle itself (i.e. this method returns the geometry of the actual reprojected rectangle, while parameterAsExtent() returns just the extent of the reprojected rectangle).

See also
parameterAsExtent()

Definition at line 709 of file qgsprocessingalgorithm.cpp.

◆ parameterAsFields()

QStringList QgsProcessingAlgorithm::parameterAsFields ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a list of fields.

Definition at line 759 of file qgsprocessingalgorithm.cpp.

◆ parameterAsFile()

QString QgsProcessingAlgorithm::parameterAsFile ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a file/folder name.

Definition at line 734 of file qgsprocessingalgorithm.cpp.

◆ parameterAsFileList()

QStringList QgsProcessingAlgorithm::parameterAsFileList ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a list of files (for QgsProcessingParameterMultipleLayers in QgsProcessing:TypeFile mode).

Since
QGIS 3.10

Definition at line 749 of file qgsprocessingalgorithm.cpp.

◆ parameterAsFileOutput()

QString QgsProcessingAlgorithm::parameterAsFileOutput ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a file based output destination.

Definition at line 684 of file qgsprocessingalgorithm.cpp.

◆ parameterAsGeometry()

QgsGeometry QgsProcessingAlgorithm::parameterAsGeometry ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context,
const QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem() 
) const
protected

Evaluates the parameter with matching name to a geometry.

If crs is set then the geometry will be automatically reprojected so that it is in the specified crs.

See also
parameterAsGeometryCrs()

Definition at line 724 of file qgsprocessingalgorithm.cpp.

◆ parameterAsGeometryCrs()

QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsGeometryCrs ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
)
protected

Returns the coordinate reference system associated with a geometry parameter value.

See also
parameterAsGeometry()

Definition at line 729 of file qgsprocessingalgorithm.cpp.

◆ parameterAsInt()

int QgsProcessingAlgorithm::parameterAsInt ( const QVariantMap &  parameters,
const QString &  name,
const QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a static integer value.

Definition at line 601 of file qgsprocessingalgorithm.cpp.

◆ parameterAsInts()

QList< int > QgsProcessingAlgorithm::parameterAsInts ( const QVariantMap &  parameters,
const QString &  name,
const QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a list of integer values.

Since
QGIS 3.4

Definition at line 606 of file qgsprocessingalgorithm.cpp.

◆ parameterAsLayer()

QgsMapLayer * QgsProcessingAlgorithm::parameterAsLayer ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a map layer.

Layers will either be taken from context's active project, or loaded from external sources and stored temporarily in the context. In either case, callers do not need to handle deletion of the returned layer.

Definition at line 664 of file qgsprocessingalgorithm.cpp.

◆ parameterAsLayerList()

QList< QgsMapLayer * > QgsProcessingAlgorithm::parameterAsLayerList ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a list of map layers.

Definition at line 744 of file qgsprocessingalgorithm.cpp.

◆ parameterAsLayout()

QgsPrintLayout * QgsProcessingAlgorithm::parameterAsLayout ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
)
protected

Evaluates the parameter with matching name to a print layout.

Warning
This method is not safe to run in a background thread, so it must either be used within a prepareAlgorithm implementation (which runs in the main thread), or the algorithm must return the FlagNoThreading flag.
Since
QGIS 3.8

Definition at line 764 of file qgsprocessingalgorithm.cpp.

◆ parameterAsLayoutItem()

QgsLayoutItem * QgsProcessingAlgorithm::parameterAsLayoutItem ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context,
QgsPrintLayout layout 
)
protected

Evaluates the parameter with matching name to a print layout item, taken from the specified layout.

Warning
This method is not safe to run in a background thread, so it must either be used within a prepareAlgorithm implementation (which runs in the main thread), or the algorithm must return the FlagNoThreading flag.
Since
QGIS 3.8

Definition at line 769 of file qgsprocessingalgorithm.cpp.

◆ parameterAsMatrix()

QVariantList QgsProcessingAlgorithm::parameterAsMatrix ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a matrix/table of values.

Tables are collapsed to a 1 dimensional list.

Definition at line 739 of file qgsprocessingalgorithm.cpp.

◆ parameterAsMeshLayer()

QgsMeshLayer * QgsProcessingAlgorithm::parameterAsMeshLayer ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a mesh layer.

Layers will either be taken from context's active project, or loaded from external sources and stored temporarily in the context. In either case, callers do not need to handle deletion of the returned layer.

Since
QGIS 3.6

Definition at line 674 of file qgsprocessingalgorithm.cpp.

◆ parameterAsOutputLayer()

QString QgsProcessingAlgorithm::parameterAsOutputLayer ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a output layer destination.

Definition at line 679 of file qgsprocessingalgorithm.cpp.

◆ parameterAsPoint()

QgsPointXY QgsProcessingAlgorithm::parameterAsPoint ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context,
const QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem() 
) const
protected

Evaluates the parameter with matching name to a point.

If crs is set then the point will be automatically reprojected so that it is in the specified crs.

See also
parameterAsPointCrs()

Definition at line 714 of file qgsprocessingalgorithm.cpp.

◆ parameterAsPointCloudLayer()

QgsPointCloudLayer * QgsProcessingAlgorithm::parameterAsPointCloudLayer ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a point cloud layer.

Layers will either be taken from context's active project, or loaded from external sources and stored temporarily in the context. In either case, callers do not need to handle deletion of the returned layer.

Since
QGIS 3.22

Definition at line 799 of file qgsprocessingalgorithm.cpp.

◆ parameterAsPointCrs()

QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsPointCrs ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
)
protected

Returns the coordinate reference system associated with an point parameter value.

See also
parameterAsPoint()

Definition at line 719 of file qgsprocessingalgorithm.cpp.

◆ parameterAsRange()

QList< double > QgsProcessingAlgorithm::parameterAsRange ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a range of values.

Definition at line 754 of file qgsprocessingalgorithm.cpp.

◆ parameterAsRasterLayer()

QgsRasterLayer * QgsProcessingAlgorithm::parameterAsRasterLayer ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a raster layer.

Layers will either be taken from context's active project, or loaded from external sources and stored temporarily in the context. In either case, callers do not need to handle deletion of the returned layer.

Definition at line 669 of file qgsprocessingalgorithm.cpp.

◆ parameterAsSchema()

QString QgsProcessingAlgorithm::parameterAsSchema ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
)
protected

Evaluates the parameter with matching name to a database schema name string.

Since
QGIS 3.14

Definition at line 789 of file qgsprocessingalgorithm.cpp.

◆ parameterAsSink()

QgsFeatureSink * QgsProcessingAlgorithm::parameterAsSink ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context,
QString &  destinationIdentifier,
const QgsFields fields,
QgsWkbTypes::Type  geometryType = QgsWkbTypes::NoGeometry,
const QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem(),
QgsFeatureSink::SinkFlags  sinkFlags = QgsFeatureSink::SinkFlags(),
const QVariantMap &  createOptions = QVariantMap(),
const QStringList &  datasourceOptions = QStringList(),
const QStringList &  layerOptions = QStringList() 
) const
protected

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().

The createOptions argument is used to pass on creation options such as layer name.

The datasourceOptions and layerOptions arguments is used to pass on GDAL-specific format driver options.

This function creates a new object and the caller takes responsibility for deleting the returned object.

Exceptions
QgsProcessingException

Definition at line 641 of file qgsprocessingalgorithm.cpp.

◆ parameterAsSource()

QgsProcessingFeatureSource * QgsProcessingAlgorithm::parameterAsSource ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

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.

This function creates a new object and the caller takes responsibility for deleting the returned object.

Definition at line 649 of file qgsprocessingalgorithm.cpp.

◆ parameterAsString()

QString QgsProcessingAlgorithm::parameterAsString ( const QVariantMap &  parameters,
const QString &  name,
const QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a static string value.

Definition at line 586 of file qgsprocessingalgorithm.cpp.

◆ parameterAsVectorLayer()

QgsVectorLayer * QgsProcessingAlgorithm::parameterAsVectorLayer ( const QVariantMap &  parameters,
const QString &  name,
QgsProcessingContext context 
) const
protected

Evaluates the parameter with matching name to a vector layer.

Layers will either be taken from context's active project, or loaded from external sources and stored temporarily in the context. In either case, callers do not need to handle deletion of the returned layer.

Definition at line 689 of file qgsprocessingalgorithm.cpp.

◆ parameterDefinition()

const QgsProcessingParameterDefinition * QgsProcessingAlgorithm::parameterDefinition ( const QString &  name) const

Returns a matching parameter by name.

Matching is done in a case-insensitive manner, but exact case matches will be preferred.

See also
parameterDefinitions()

Definition at line 384 of file qgsprocessingalgorithm.cpp.

◆ parameterDefinitions()

QgsProcessingParameterDefinitions QgsProcessingAlgorithm::parameterDefinitions ( ) const
inline

Returns an ordered list of parameter definitions utilized by the algorithm.

See also
addParameter()
parameterDefinition()
destinationParameterDefinitions()

Definition at line 280 of file qgsprocessingalgorithm.h.

◆ postProcess()

QVariantMap QgsProcessingAlgorithm::postProcess ( QgsProcessingContext context,
QgsProcessingFeedback feedback 
)

Should be called in the main thread following the completion of runPrepared().

This method allows the algorithm to perform any required cleanup tasks. The returned variant map includes the results evaluated by the algorithm.

Note
This method modifies the algorithm instance, so it is not safe to call on algorithms directly retrieved from QgsProcessingRegistry and QgsProcessingProvider. Instead, a copy of the algorithm should be created with clone() and prepare()/runPrepared() called on the copy.

Definition at line 557 of file qgsprocessingalgorithm.cpp.

◆ postProcessAlgorithm()

QVariantMap QgsProcessingAlgorithm::postProcessAlgorithm ( QgsProcessingContext context,
QgsProcessingFeedback feedback 
)
protectedvirtual

Allows the algorithm to perform any required cleanup tasks.

The returned variant map includes the results evaluated by the algorithm. These may be output layer references, or calculated values such as statistical calculations.

The context argument specifies the context in which the algorithm was run.

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

postProcessAlgorithm should be used to handle any thread-sensitive cleanup which is required by the algorithm. It will always be called from the same thread that context has thread affinity with. While this will generally be the main thread, it is not guaranteed. For instance, algorithms which are run as a step in a larger model or as a subcomponent of a script-based algorithm will call postProcessAlgorithm from the same thread as that model/script it being executed in.

postProcessAlgorithm will not be called if the prepareAlgorithm() step failed (returned false), or if an exception was raised by the processAlgorithm() step.

Returns
A map of algorithm outputs. These may be output layer references, or calculated values such as statistical calculations. Implementations which return a non-empty map will override any results returned by processAlgorithm().
See also
prepareAlgorithm()
processAlgorithm()

Definition at line 379 of file qgsprocessingalgorithm.cpp.

◆ prepare()

bool QgsProcessingAlgorithm::prepare ( const QVariantMap &  parameters,
QgsProcessingContext context,
QgsProcessingFeedback feedback 
)

Prepares the algorithm for execution.

This must be run in the main thread, and allows the algorithm to pre-evaluate input parameters in a thread-safe manner. This must be called before calling runPrepared() (which is safe to do in any thread).

See also
runPrepared()
postProcess()
Note
This method modifies the algorithm instance, so it is not safe to call on algorithms directly retrieved from QgsProcessingRegistry and QgsProcessingProvider. Instead, a copy of the algorithm should be created with clone() and prepare()/runPrepared() called on the copy.

Definition at line 484 of file qgsprocessingalgorithm.cpp.

◆ prepareAlgorithm()

bool QgsProcessingAlgorithm::prepareAlgorithm ( const QVariantMap &  parameters,
QgsProcessingContext context,
QgsProcessingFeedback feedback 
)
protectedvirtual

Prepares the algorithm to run using the specified parameters.

Algorithms should implement their logic for evaluating parameter values here. The evaluated parameter results should be stored in member variables ready for a call to processAlgorithm().

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

prepareAlgorithm should be used to handle any thread-sensitive preparation which is required by the algorithm. It will always be called from the same thread that context has thread affinity with. While this will generally be the main thread, it is not guaranteed. For instance, algorithms which are run as a step in a larger model or as a subcomponent of a script-based algorithm will call prepareAlgorithm from the same thread as that model/script it being executed in.

Note that the processAlgorithm step uses a temporary context with affinity for the thread in which the algorithm is executed, making it safe for processAlgorithm implementations to load sources and sinks without issue. Implementing prepareAlgorithm is only required if special thread safe handling is required by the algorithm.

Algorithm preparation 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.

If the preparation was successful algorithms must return true. If a false value is returned this indicates that the preparation could not be completed, and the algorithm execution will be canceled.

Returns
true if preparation was successful.
See also
processAlgorithm()
postProcessAlgorithm()

Reimplemented in QgsBatchGeocodeAlgorithm.

Definition at line 374 of file qgsprocessingalgorithm.cpp.

◆ preprocessParameters()

QVariantMap QgsProcessingAlgorithm::preprocessParameters ( const QVariantMap &  parameters)
virtual

Pre-processes a set of parameters, allowing the algorithm to clean their values.

This method is automatically called after users enter parameters, e.g. via the algorithm dialog. This method should NOT be called manually by algorithms.

Definition at line 124 of file qgsprocessingalgorithm.cpp.

◆ processAlgorithm()

virtual QVariantMap QgsProcessingAlgorithm::processAlgorithm ( const QVariantMap &  parameters,
QgsProcessingContext context,
QgsProcessingFeedback feedback 
)
protectedpure virtual

Runs the algorithm using the specified parameters.

Algorithms should implement their custom processing logic here.

The context argument gives a temporary context with thread affinity matching the thread in which the algorithm is being run. This is a cut-back copy of the context passed to the prepareAlgorithm() and postProcessAlgorithm() steps, but it is generally safe for most algorithms to utilize this context for loading layers and creating sinks. Any loaded layers or sinks created within this temporary context will be transferred back to the main execution context upon successful completion of the processAlgorithm() step.

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.

This method will not be called if the prepareAlgorithm() step failed (returned false).

Implementations of processAlgorithm can throw the QgsProcessingException exception to indicate that a fatal error occurred within the execution.

Returns
A map of algorithm outputs. These may be output layer references, or calculated values such as statistical calculations. Unless the algorithm subclass overrides the postProcessAlgorithm() step this returned map will be used as the output for the algorithm.
See also
prepareAlgorithm()
postProcessAlgorithm()

Implemented in QgsProcessingFeatureBasedAlgorithm.

◆ provider()

QgsProcessingProvider * QgsProcessingAlgorithm::provider ( ) const

Returns the provider to which this algorithm belongs.

Definition at line 129 of file qgsprocessingalgorithm.cpp.

◆ removeParameter()

void QgsProcessingAlgorithm::removeParameter ( const QString &  name)
protected

Removes the parameter with matching name from the algorithm, and deletes any existing definition.

Definition at line 339 of file qgsprocessingalgorithm.cpp.

◆ run()

QVariantMap QgsProcessingAlgorithm::run ( const QVariantMap &  parameters,
QgsProcessingContext context,
QgsProcessingFeedback feedback,
bool *  ok = nullptr,
const QVariantMap &  configuration = QVariantMap(),
bool  catchExceptions = true 
) const

Executes the algorithm using the specified parameters.

This method internally creates a copy of the algorithm before running it, so it is safe to call on algorithms directly retrieved from QgsProcessingRegistry and QgsProcessingProvider.

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

Algorithm progress should be reported using the supplied feedback object.

If specified, ok will be set to true if algorithm was successfully run.

If catchExceptions is set to false, then QgsProcessingException raised during the algorithm run will not be automatically caught and will be raised instead.

Returns
A map of algorithm outputs. These may be output layer references, or calculated values such as statistical calculations.
Note
this method can only be called from the main thread. Use prepare(), runPrepared() and postProcess() if you need to run algorithms from a background thread, or use the QgsProcessingAlgRunnerTask class.

Definition at line 449 of file qgsprocessingalgorithm.cpp.

◆ runPrepared()

QVariantMap QgsProcessingAlgorithm::runPrepared ( const QVariantMap &  parameters,
QgsProcessingContext context,
QgsProcessingFeedback feedback 
)

Runs the algorithm, which has been prepared by an earlier call to prepare().

This method is safe to call from any thread. Returns true if the algorithm was successfully executed. After runPrepared() has finished, the postProcess() method should be called from the main thread to allow the algorithm to perform any required cleanup tasks and return its final result.

See also
prepare()
postProcess()
Note
This method modifies the algorithm instance, so it is not safe to call on algorithms directly retrieved from QgsProcessingRegistry and QgsProcessingProvider. Instead, a copy of the algorithm should be created with clone() and prepare()/runPrepared() called on the copy.

Definition at line 501 of file qgsprocessingalgorithm.cpp.

◆ setProvider()

void QgsProcessingAlgorithm::setProvider ( QgsProcessingProvider provider)

Associates this algorithm with its provider.

No transfer of ownership is involved.

Definition at line 134 of file qgsprocessingalgorithm.cpp.

◆ shortDescription()

QString QgsProcessingAlgorithm::shortDescription ( ) const
virtual

Returns an optional translated short description of the algorithm.

This should be at most a single sentence, e.g. "Converts 2D features to 3D by sampling a DEM raster."

Since
QGIS 3.2

Definition at line 59 of file qgsprocessingalgorithm.cpp.

◆ shortHelpString()

QString QgsProcessingAlgorithm::shortHelpString ( ) const
virtual

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.

See also
helpString()
helpUrl()

Definition at line 64 of file qgsprocessingalgorithm.cpp.

◆ sinkProperties()

QgsProcessingAlgorithm::VectorProperties QgsProcessingAlgorithm::sinkProperties ( const QString &  sink,
const QVariantMap &  parameters,
QgsProcessingContext context,
const QMap< QString, QgsProcessingAlgorithm::VectorProperties > &  sourceProperties 
) const
virtual

Returns the vector properties which will be used for the sink with matching name.

The parameters argument specifies the values of all parameters which would be used to generate the sink. These can be used alongside the provided context in order to pre-evaluate inputs when required in order to determine the sink's properties.

The sourceProperties map will contain the vector properties of the various sources used as inputs to the algorithm. These will only be available in certain circumstances (e.g. when the algorithm is used within a model), so implementations will need to be adaptable to circumstances when either sourceParameters is empty or parameters is empty, and use whatever information is passed in order to make a best guess determination of the output properties.

Since
QGIS 3.14

Reimplemented in QgsProcessingFeatureBasedAlgorithm.

Definition at line 444 of file qgsprocessingalgorithm.cpp.

◆ supportInPlaceEdit()

bool QgsProcessingAlgorithm::supportInPlaceEdit ( const QgsMapLayer layer) const
protectedvirtual

Checks whether this algorithm supports in-place editing on the given layer Default implementation returns false.

Returns
true if the algorithm supports in-place editing
Since
QGIS 3.4

Reimplemented in QgsProcessingFeatureBasedAlgorithm, and QgsBatchGeocodeAlgorithm.

Definition at line 900 of file qgsprocessingalgorithm.cpp.

◆ svgIconPath()

QString QgsProcessingAlgorithm::svgIconPath ( ) const
virtual

Returns a path to an SVG version of the algorithm's icon.

See also
icon()

Definition at line 84 of file qgsprocessingalgorithm.cpp.

◆ tags()

virtual QStringList QgsProcessingAlgorithm::tags ( ) const
inlinevirtual

Returns a list of tags which relate to the algorithm, and are used to assist users in searching for suitable algorithms.

These tags should be localised.

Reimplemented in QgsBatchGeocodeAlgorithm.

Definition at line 181 of file qgsprocessingalgorithm.h.

◆ validateInputCrs()

bool QgsProcessingAlgorithm::validateInputCrs ( const QVariantMap &  parameters,
QgsProcessingContext context 
) const
virtual

Checks whether the coordinate reference systems for the specified set of parameters are valid for the algorithm.

For instance, the base implementation performs checks to ensure that all input CRS are equal Returns true if parameters have passed the CRS check.

Definition at line 181 of file qgsprocessingalgorithm.cpp.

◆ writeFeatureError()

QString QgsProcessingAlgorithm::writeFeatureError ( QgsFeatureSink sink,
const QVariantMap &  parameters,
const QString &  name 
)
staticprotected

Returns a user-friendly string to use as an error when a feature cannot be written into a sink.

The sink argument is the sink into which the feature cannot be written.

The parameters argument should give the algorithms parameter map, and the name should correspond to the sink parameter name.

Since
QGIS 3.22

Definition at line 890 of file qgsprocessingalgorithm.cpp.

Friends And Related Function Documentation

◆ QgsProcessingModelAlgorithm

friend class QgsProcessingModelAlgorithm
friend

Definition at line 1085 of file qgsprocessingalgorithm.h.

◆ QgsProcessingProvider

friend class QgsProcessingProvider
friend

Definition at line 1083 of file qgsprocessingalgorithm.h.

◆ QgsProcessingToolboxProxyModel

friend class QgsProcessingToolboxProxyModel
friend

Definition at line 1086 of file qgsprocessingalgorithm.h.

◆ TestQgsProcessing

friend class TestQgsProcessing
friend

Definition at line 1084 of file qgsprocessingalgorithm.h.


The documentation for this class was generated from the following files: