18 #ifndef QGSPROCESSINGMODELALGORITHM_H
19 #define QGSPROCESSINGMODELALGORITHM_H
21 #include "qgis_core.h"
45 QgsProcessingModelAlgorithm(
const QString &name = QString(),
const QString &group = QString(),
const QString &groupId = QString() );
47 void initAlgorithm(
const QVariantMap &configuration = QVariantMap() )
override;
49 QString
name()
const override;
51 QString
group()
const override;
52 QString
groupId()
const override;
53 QIcon
icon()
const override;
57 QString
helpUrl()
const override;
58 Flags
flags()
const override;
68 void setName(
const QString &name );
74 void setGroup(
const QString &group );
83 bool validate( QStringList &issues
SIP_OUT )
const;
92 QMap<QString, QgsProcessingModelChildAlgorithm> childAlgorithms()
const;
103 void setChildAlgorithms(
const QMap<QString, QgsProcessingModelChildAlgorithm> &childAlgorithms );
111 void setChildAlgorithm(
const QgsProcessingModelChildAlgorithm &
algorithm );
123 QString addChildAlgorithm( QgsProcessingModelChildAlgorithm &
algorithm );
131 QgsProcessingModelChildAlgorithm &childAlgorithm(
const QString &
id );
140 bool removeChildAlgorithm(
const QString &
id );
149 void deactivateChildAlgorithm(
const QString &
id );
157 bool activateChildAlgorithm(
const QString &
id );
169 QSet< QString > dependentChildAlgorithms(
const QString &childId,
const QString &conditionalBranch = QString() )
const;
176 QSet< QString > dependsOnChildAlgorithms(
const QString &childId )
const;
183 QList< QgsProcessingModelChildDependency > availableDependenciesForChildAlgorithm(
const QString &childId )
const;
194 bool validateChildAlgorithm(
const QString &childId, QStringList &issues
SIP_OUT )
const;
218 void removeModelParameter(
const QString &name );
225 bool childAlgorithmsDependOnParameter(
const QString &name )
const;
233 bool otherParametersDependOnParameter(
const QString &name )
const;
241 QMap<QString, QgsProcessingModelParameter> parameterComponents()
const;
251 void setParameterComponents(
const QMap<QString, QgsProcessingModelParameter> ¶meterComponents );
260 void setParameterComponent(
const QgsProcessingModelParameter &component );
269 QgsProcessingModelParameter ¶meterComponent(
const QString &name );
277 QList< QgsProcessingModelParameter > orderedParameters()
const;
288 void setParameterOrder(
const QStringList &order );
295 void updateDestinationParameters();
305 void addGroupBox(
const QgsProcessingModelGroupBox &groupBox );
313 QList< QgsProcessingModelGroupBox > groupBoxes()
const;
322 void removeGroupBox(
const QString &uuid );
328 bool toFile(
const QString &path )
const;
334 bool fromFile(
const QString &path );
343 QVariant toVariant()
const;
352 bool loadVariant(
const QVariant &variant );
359 QVariantMap &helpContent() {
return mHelpContent; }
366 SIP_SKIP QVariantMap helpContent()
const;
373 void setHelpContent(
const QVariantMap &contents );
379 QString sourceFilePath()
const;
385 void setSourceFilePath(
const QString &path );
395 bool modelNameMatchesFilePath()
const;
414 QList< QgsProcessingModelChildParameterSource > availableSourcesForChild(
const QString &childId,
const QStringList ¶meterTypes = QStringList(),
415 const QStringList &outputTypes = QStringList(),
const QList< int > &dataTypes = QList< int >() )
const;
422 class CORE_EXPORT VariableDefinition
430 VariableDefinition(
const QVariant &value = QVariant(),
const QgsProcessingModelChildParameterSource &source = QgsProcessingModelChildParameterSource::fromStaticValue( QVariant() ),
const QString &description = QString() )
433 , description( description )
440 QgsProcessingModelChildParameterSource source;
459 QMap< QString, QgsProcessingModelAlgorithm::VariableDefinition > variablesForChildAlgorithm(
const QString &childId,
QgsProcessingContext &context,
const QVariantMap &modelParameters = QVariantMap(),
460 const QVariantMap &results = QVariantMap() )
const;
467 const QVariantMap &results = QVariantMap() ) const
SIP_FACTORY;
478 QVariantMap variables() const;
489 void setVariables( const QVariantMap &variables );
502 QVariantMap designerParameterValues() const;
515 void setDesignerParameterValues( const QVariantMap &values ) { mDesignerParameterValues = values; }
527 QString mModelGroupId;
529 QMap< QString, QgsProcessingModelChildAlgorithm > mChildAlgorithms;
532 QMap< QString, QgsProcessingModelParameter > mParameterComponents;
534 QVariantMap mHelpContent;
539 QVariantMap mResults;
541 QVariantMap mVariables;
543 QVariantMap mDesignerParameterValues;
545 QMap< QString, QgsProcessingModelGroupBox > mGroupBoxes;
547 QStringList mParameterOrder;
549 void dependsOnChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;
550 void dependentChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends, const QString &branch ) const;
552 QVariantMap parametersForChildAlgorithm( const QgsProcessingModelChildAlgorithm &child, const QVariantMap &modelParameters, const QVariantMap &results, const
QgsExpressionContext &expressionContext, QString &error ) const;
558 bool childOutputIsRequired( const QString &childId, const QString &outputName ) const;
569 static
bool vectorOutputIsCompatibleType( const QList<
int> &acceptableDataTypes,
QgsProcessing::SourceType outputType );
574 void reattachAlgorithms() const;
576 friend class TestQgsProcessingModelAlgorithm;
Single scope for storing variables and functions for use within a QgsExpressionContext.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Abstract base class for processing algorithms.
virtual QString group() const
Returns the name of the group this algorithm belongs to.
virtual QString groupId() const
Returns the unique ID of the group this algorithm belongs to.
virtual QString helpUrl() const
Returns a url pointing to the algorithm's help page.
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
virtual QIcon icon() const
Returns an icon for the algorithm.
virtual QString shortHelpString() const
Returns a localised short helper string for the algorithm.
virtual QString shortDescription() const
Returns an optional translated short description of the algorithm.
friend class QgsProcessingModelAlgorithm
virtual QString displayName() const =0
Returns the translated algorithm name, which should be used for any user-visible display of the algor...
virtual QgsExpressionContext createExpressionContext(const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeatureSource *source=nullptr) const
Creates an expression context relating to the algorithm.
virtual QgsProcessingAlgorithm * createInstance() const =0
Creates a new instance of the algorithm class.
virtual QString svgIconPath() const
Returns a path to an SVG version of the algorithm's icon.
virtual void initAlgorithm(const QVariantMap &configuration=QVariantMap())=0
Initializes the algorithm using the specified configuration.
virtual QString asPythonCommand(const QVariantMap ¶meters, QgsProcessingContext &context) const
Returns a Python command string which can be executed to run the algorithm using the specified parame...
virtual bool canExecute(QString *errorMessage=nullptr) const
Returns true if the algorithm can execute.
virtual QString name() const =0
Returns the algorithm name, used for identifying the algorithm.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource,...
Base class for providing feedback from a processing algorithm.
Base class for the definition of processing parameters.
Contains enumerations and other constants for use in processing algorithms and parameters.
PythonOutputType
Available Python output types.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call