QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
qgsprocessingmodelalgorithm.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprocessingmodelalgorithm.h
3  -----------------------------
4  begin : June 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSPROCESSINGMODELALGORITHM_H
19 #define QGSPROCESSINGMODELALGORITHM_H
20 
21 #include "qgis_core.h"
22 #include "qgis.h"
24 #include "qgsprocessingalgorithm.h"
29 
31 
38 class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
39 {
40  public:
41 
45  QgsProcessingModelAlgorithm( const QString &name = QString(), const QString &group = QString(), const QString &groupId = QString() );
46 
47  void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override; //#spellok
48 
49  QString name() const override;
50  QString displayName() const override;
51  QString group() const override;
52  QString groupId() const override;
53  QIcon icon() const override;
54  QString svgIconPath() const override;
55  QString shortHelpString() const override;
56  QString shortDescription() const override;
57  QString helpUrl() const override;
58  Flags flags() const override;
59 
60  bool canExecute( QString *errorMessage SIP_OUT = nullptr ) const override;
61  QString asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const override;
62  QgsExpressionContext createExpressionContext( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeatureSource *source = nullptr ) const override;
63 
68  void setName( const QString &name );
69 
74  void setGroup( const QString &group );
75 
83  bool validate( QStringList &issues SIP_OUT ) const;
84 
92  QMap<QString, QgsProcessingModelChildAlgorithm> childAlgorithms() const;
93 
103  void setChildAlgorithms( const QMap<QString, QgsProcessingModelChildAlgorithm> &childAlgorithms );
104 
111  void setChildAlgorithm( const QgsProcessingModelChildAlgorithm &algorithm );
112 
123  QString addChildAlgorithm( QgsProcessingModelChildAlgorithm &algorithm );
124 
131  QgsProcessingModelChildAlgorithm &childAlgorithm( const QString &id );
132 
140  bool removeChildAlgorithm( const QString &id );
141 
149  void deactivateChildAlgorithm( const QString &id );
150 
157  bool activateChildAlgorithm( const QString &id );
158 
169  QSet< QString > dependentChildAlgorithms( const QString &childId, const QString &conditionalBranch = QString() ) const;
170 
176  QSet< QString > dependsOnChildAlgorithms( const QString &childId ) const;
177 
183  QList< QgsProcessingModelChildDependency > availableDependenciesForChildAlgorithm( const QString &childId ) const;
184 
194  bool validateChildAlgorithm( const QString &childId, QStringList &issues SIP_OUT ) const;
195 
202  void addModelParameter( QgsProcessingParameterDefinition *definition SIP_TRANSFER, const QgsProcessingModelParameter &component );
203 
210  void updateModelParameter( QgsProcessingParameterDefinition *definition SIP_TRANSFER );
211 
218  void removeModelParameter( const QString &name );
219 
225  bool childAlgorithmsDependOnParameter( const QString &name ) const;
226 
233  bool otherParametersDependOnParameter( const QString &name ) const;
234 
241  QMap<QString, QgsProcessingModelParameter> parameterComponents() const;
242 
251  void setParameterComponents( const QMap<QString, QgsProcessingModelParameter> &parameterComponents );
252 
260  void setParameterComponent( const QgsProcessingModelParameter &component );
261 
269  QgsProcessingModelParameter &parameterComponent( const QString &name );
270 
277  QList< QgsProcessingModelParameter > orderedParameters() const;
278 
288  void setParameterOrder( const QStringList &order );
289 
295  void updateDestinationParameters();
296 
305  void addGroupBox( const QgsProcessingModelGroupBox &groupBox );
306 
313  QList< QgsProcessingModelGroupBox > groupBoxes() const;
314 
322  void removeGroupBox( const QString &uuid );
323 
328  bool toFile( const QString &path ) const;
329 
334  bool fromFile( const QString &path );
335 
343  QVariant toVariant() const;
344 
352  bool loadVariant( const QVariant &variant );
353 
359  QVariantMap &helpContent() { return mHelpContent; }
360 
366  SIP_SKIP QVariantMap helpContent() const;
367 
373  void setHelpContent( const QVariantMap &contents );
374 
379  QString sourceFilePath() const;
380 
385  void setSourceFilePath( const QString &path );
386 
394  QStringList asPythonCode( QgsProcessing::PythonOutputType outputType, int indentSize ) const;
395 
404  QList< QgsProcessingModelChildParameterSource > availableSourcesForChild( const QString &childId, const QStringList &parameterTypes = QStringList(),
405  const QStringList &outputTypes = QStringList(), const QList< int > &dataTypes = QList< int >() ) const;
406 
412  class CORE_EXPORT VariableDefinition
413  {
414  public:
415 
420  VariableDefinition( const QVariant &value = QVariant(), const QgsProcessingModelChildParameterSource &source = QgsProcessingModelChildParameterSource::fromStaticValue( QVariant() ), const QString &description = QString() )
421  : value( value )
422  , source( source )
423  , description( description )
424  {}
425 
427  QVariant value;
428 
430  QgsProcessingModelChildParameterSource source;
431 
433  QString description;
434  };
435 
449  QMap< QString, QgsProcessingModelAlgorithm::VariableDefinition > variablesForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(),
450  const QVariantMap &results = QVariantMap() ) const;
451 
456  QgsExpressionContextScope *createExpressionContextScopeForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(),
457  const QVariantMap &results = QVariantMap() ) const SIP_FACTORY;
458 
468  QVariantMap variables() const;
469 
479  void setVariables( const QVariantMap &variables );
480 
492  QVariantMap designerParameterValues() const;
493 
505  void setDesignerParameterValues( const QVariantMap &values ) { mDesignerParameterValues = values; }
506 
507  protected:
508 
510 
511  QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override SIP_THROW( QgsProcessingException );
512 
513  private:
514 
515  QString mModelName;
516  QString mModelGroup;
517  QString mModelGroupId;
518 
519  QMap< QString, QgsProcessingModelChildAlgorithm > mChildAlgorithms;
520 
522  QMap< QString, QgsProcessingModelParameter > mParameterComponents;
523 
524  QVariantMap mHelpContent;
525 
527  QString mSourceFile;
528 
529  QVariantMap mResults;
530 
531  QVariantMap mVariables;
532 
533  QVariantMap mDesignerParameterValues;
534 
535  QMap< QString, QgsProcessingModelGroupBox > mGroupBoxes;
536 
537  QStringList mParameterOrder;
538 
539  void dependsOnChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;
540  void dependentChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends, const QString &branch ) const;
541 
542  QVariantMap parametersForChildAlgorithm( const QgsProcessingModelChildAlgorithm &child, const QVariantMap &modelParameters, const QVariantMap &results, const QgsExpressionContext &expressionContext ) const;
543 
548  bool childOutputIsRequired( const QString &childId, const QString &outputName ) const;
549 
559  static bool vectorOutputIsCompatibleType( const QList<int> &acceptableDataTypes, QgsProcessing::SourceType outputType );
560 
564  void reattachAlgorithms() const;
565 
566  friend class TestQgsProcessing;
567 };
568 
570 
571 #endif // QGSPROCESSINGMODELALGORITHM_H
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.
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 &parameters, 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 &parameters, 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.
Definition: qgsexception.h:83
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.
Definition: qgsprocessing.h:40
PythonOutputType
Available Python output types.
Definition: qgsprocessing.h:63
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
#define SIP_THROW(name)
Definition: qgis_sip.h:189
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76