QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
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"
29
31
37class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm
38{
39 Q_GADGET
40
41 public:
42
46 QgsProcessingModelAlgorithm( const QString &name = QString(), const QString &group = QString(), const QString &groupId = QString() );
47
48 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override; //#spellok
49
50 QString name() const override;
51 QString displayName() const override;
52 QString group() const override;
53 QString groupId() const override;
54 QIcon icon() const override;
55 QString svgIconPath() const override;
56 QString shortHelpString() const override;
57 QString shortDescription() const override;
58 QString helpUrl() 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
227 void changeParameterName( const QString &oldName, const QString &newName );
228
234 bool childAlgorithmsDependOnParameter( const QString &name ) const;
235
242 bool otherParametersDependOnParameter( const QString &name ) const;
243
250 QMap<QString, QgsProcessingModelParameter> parameterComponents() const;
251
260 void setParameterComponents( const QMap<QString, QgsProcessingModelParameter> &parameterComponents );
261
269 void setParameterComponent( const QgsProcessingModelParameter &component );
270
278 QgsProcessingModelParameter &parameterComponent( const QString &name );
279
286 QList< QgsProcessingModelParameter > orderedParameters() const;
287
297 void setParameterOrder( const QStringList &order );
298
305 QList< QgsProcessingModelOutput > orderedOutputs() const;
306
316 void setOutputOrder( const QStringList &order );
317
324 QString outputGroup() const;
325
332 void setOutputGroup( const QString &group );
333
339 void updateDestinationParameters();
340
349 void addGroupBox( const QgsProcessingModelGroupBox &groupBox );
350
357 QList< QgsProcessingModelGroupBox > groupBoxes() const;
358
366 void removeGroupBox( const QString &uuid );
367
372 bool toFile( const QString &path ) const;
373
378 bool fromFile( const QString &path );
379
387 QVariant toVariant() const;
388
396 bool loadVariant( const QVariant &variant );
397
403 QVariantMap &helpContent() { return mHelpContent; }
404
410 SIP_SKIP QVariantMap helpContent() const;
411
417 void setHelpContent( const QVariantMap &contents );
418
423 QString sourceFilePath() const;
424
429 void setSourceFilePath( const QString &path );
430
439 bool modelNameMatchesFilePath() const;
440
448 QStringList asPythonCode( QgsProcessing::PythonOutputType outputType, int indentSize ) const;
449
458 QList< QgsProcessingModelChildParameterSource > availableSourcesForChild( const QString &childId, const QStringList &parameterTypes = QStringList(),
459 const QStringList &outputTypes = QStringList(), const QList< int > &dataTypes = QList< int >() ) const;
460
465 class CORE_EXPORT VariableDefinition
466 {
467 public:
468
473 VariableDefinition( const QVariant &value = QVariant(), const QgsProcessingModelChildParameterSource &source = QgsProcessingModelChildParameterSource::fromStaticValue( QVariant() ), const QString &description = QString() )
474 : value( value )
475 , source( source )
476 , description( description )
477 {}
478
480 QVariant value;
481
483 QgsProcessingModelChildParameterSource source;
484
486 QString description;
487 };
488
502 QMap< QString, QgsProcessingModelAlgorithm::VariableDefinition > variablesForChildAlgorithm( const QString &childId, QgsProcessingContext *context = nullptr, const QVariantMap &modelParameters = QVariantMap(),
503 const QVariantMap &results = QVariantMap() ) const;
504
509 QgsExpressionContextScope *createExpressionContextScopeForChildAlgorithm( const QString &childId, QgsProcessingContext &context, const QVariantMap &modelParameters = QVariantMap(),
510 const QVariantMap &results = QVariantMap() ) const SIP_FACTORY;
511
521 QVariantMap variables() const;
522
532 void setVariables( const QVariantMap &variables );
533
545 QVariantMap designerParameterValues() const;
546
558 void setDesignerParameterValues( const QVariantMap &values ) { mDesignerParameterValues = values; }
559
565 const QgsProcessingParameterDefinition *modelParameterFromChildIdAndOutputName( const QString &childId, const QString &childOutputName ) const;
566
574 static QString safeName( const QString &name, bool capitalize = false );
575
576#ifndef SIP_RUN
577
579 enum class InternalVersion
580 {
581 Version1,
582 Version2,
583 };
584 Q_ENUM( InternalVersion )
585
586#endif
587
588 protected:
589
591
592 QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override SIP_THROW( QgsProcessingException );
593
594 private:
595
596 InternalVersion mInternalVersion = InternalVersion::Version2;
597
598 QString mModelName;
599 QString mModelGroup;
600 QString mModelGroupId;
601
602 QMap< QString, QgsProcessingModelChildAlgorithm > mChildAlgorithms;
603
605 QMap< QString, QgsProcessingModelParameter > mParameterComponents;
606
607 QVariantMap mHelpContent;
608
610 QString mSourceFile;
611
612 QVariantMap mResults;
613
614 QVariantMap mVariables;
615
616 QVariantMap mDesignerParameterValues;
617
618 QMap< QString, QgsProcessingModelGroupBox > mGroupBoxes;
619
620 QStringList mParameterOrder;
621 QStringList mOutputOrder;
622 QString mOutputGroup;
623
624 void dependsOnChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends ) const;
625 void dependentChildAlgorithmsRecursive( const QString &childId, QSet<QString> &depends, const QString &branch ) const;
626
627 QVariantMap parametersForChildAlgorithm( const QgsProcessingModelChildAlgorithm &child, const QVariantMap &modelParameters, const QVariantMap &results, const QgsExpressionContext &expressionContext, QString &error, const QgsProcessingContext *context = nullptr ) const;
628
633 bool childOutputIsRequired( const QString &childId, const QString &outputName ) const;
634
644 static bool vectorOutputIsCompatibleType( const QList<int> &acceptableDataTypes, Qgis::ProcessingSourceType outputType );
645
649 void reattachAlgorithms() const;
650
651 friend class TestQgsProcessingModelAlgorithm;
652};
653
655
656#endif // QGSPROCESSINGMODELALGORITHM_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
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 QgsProcessingAlgorithm * createInstance() const =0
Creates a new instance of the algorithm class.
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 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 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.
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.
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
#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
#define SIP_THROW(name,...)
Definition qgis_sip.h:203