Skip to content

Commit 72f95e6

Browse files
authored
Merge pull request #4682 from nyalldawson/processing_pt3
Processing rebuilding...
2 parents 2b0af00 + 1d2e54d commit 72f95e6

File tree

181 files changed

+1546
-628
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+1546
-628
lines changed

python/core/processing/qgsprocessingalgorithm.sip

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class QgsProcessingAlgorithm
2828
FlagHideFromToolbox,
2929
FlagHideFromModeler,
3030
FlagSupportsBatch,
31+
FlagCanCancel,
3132
FlagDeprecated,
3233
};
3334
typedef QFlags<QgsProcessingAlgorithm::Flag> Flags;
@@ -128,6 +129,7 @@ class QgsProcessingAlgorithm
128129
virtual Flags flags() const;
129130
%Docstring
130131
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
132+
Default flags are FlagSupportsBatch and FlagCanCancel.
131133
:rtype: Flags
132134
%End
133135

@@ -205,6 +207,12 @@ class QgsProcessingAlgorithm
205207
:rtype: QgsProcessingOutputDefinition
206208
%End
207209

210+
bool hasHtmlOutputs() const;
211+
%Docstring
212+
Returns true if this algorithm generates HTML outputs.
213+
:rtype: bool
214+
%End
215+
208216
QVariantMap run( const QVariantMap &parameters,
209217
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const;
210218
%Docstring
@@ -228,6 +236,15 @@ class QgsProcessingAlgorithm
228236
:rtype: QWidget
229237
%End
230238

239+
QgsExpressionContext createExpressionContext( const QVariantMap &parameters,
240+
QgsProcessingContext &context ) const;
241+
%Docstring
242+
Creates an expression context relating to the algorithm. This can be called by algorithms
243+
to create a new expression context ready for evaluating expressions within the algorithm.
244+
:rtype: QgsExpressionContext
245+
%End
246+
247+
231248
protected:
232249

233250
bool addParameter( QgsProcessingParameterDefinition *parameterDefinition /Transfer/ );
@@ -357,6 +374,18 @@ class QgsProcessingAlgorithm
357374
:rtype: QgsRasterLayer
358375
%End
359376

377+
QString parameterAsRasterOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
378+
%Docstring
379+
Evaluates the parameter with matching ``name`` to a raster output layer destination.
380+
:rtype: str
381+
%End
382+
383+
QString parameterAsFileOutput( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
384+
%Docstring
385+
Evaluates the parameter with matching ``name`` to a file based output destination.
386+
:rtype: str
387+
%End
388+
360389
QgsVectorLayer *parameterAsVectorLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
361390
%Docstring
362391
Evaluates the parameter with matching ``name`` to a vector layer.

python/core/processing/qgsprocessingoutputs.sip

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class QgsProcessingOutputDefinition
3030
%ConvertToSubClassCode
3131
if ( sipCpp->type() == "outputVector" )
3232
sipType = sipType_QgsProcessingOutputVectorLayer;
33+
else if ( sipCpp->type() == "outputRaster" )
34+
sipType = sipType_QgsProcessingOutputRasterLayer;
35+
else if ( sipCpp->type() == "outputHtml" )
36+
sipType = sipType_QgsProcessingOutputHtml;
3337
%End
3438
public:
3539

@@ -118,6 +122,45 @@ class QgsProcessingOutputVectorLayer : QgsProcessingOutputDefinition
118122

119123
};
120124

125+
class QgsProcessingOutputRasterLayer : QgsProcessingOutputDefinition
126+
{
127+
%Docstring
128+
A raster layer output for processing algorithms.
129+
.. versionadded:: 3.0
130+
%End
131+
132+
%TypeHeaderCode
133+
#include "qgsprocessingoutputs.h"
134+
%End
135+
public:
136+
137+
QgsProcessingOutputRasterLayer( const QString &name, const QString &description = QString() );
138+
%Docstring
139+
Constructor for QgsProcessingOutputRasterLayer.
140+
%End
141+
142+
virtual QString type() const;
143+
};
144+
145+
class QgsProcessingOutputHtml : QgsProcessingOutputDefinition
146+
{
147+
%Docstring
148+
A HTML file output for processing algorithms.
149+
.. versionadded:: 3.0
150+
%End
151+
152+
%TypeHeaderCode
153+
#include "qgsprocessingoutputs.h"
154+
%End
155+
public:
156+
157+
QgsProcessingOutputHtml( const QString &name, const QString &description = QString() );
158+
%Docstring
159+
Constructor for QgsProcessingOutputHtml.
160+
%End
161+
162+
virtual QString type() const;
163+
};
121164

122165

123166

python/core/processing/qgsprocessingparameters.sip

Lines changed: 99 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ Allows direct construction of QVariants.
5656

5757

5858

59-
class QgsProcessingFeatureSinkDefinition
59+
class QgsProcessingOutputLayerDefinition
6060
{
6161
%Docstring
6262

63-
Encapsulates settings relating to a feature sink input to a processing algorithm.
63+
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
6464

6565
.. versionadded:: 3.0
6666
%End
@@ -70,35 +70,35 @@ class QgsProcessingFeatureSinkDefinition
7070
%End
7171
public:
7272

73-
QgsProcessingFeatureSinkDefinition( const QString &sink = QString(), QgsProject *destinationProject = 0 );
73+
QgsProcessingOutputLayerDefinition( const QString &sink = QString(), QgsProject *destinationProject = 0 );
7474
%Docstring
75-
Constructor for QgsProcessingFeatureSinkDefinition, accepting a static string sink.
75+
Constructor for QgsProcessingOutputLayerDefinition, accepting a static sink/layer string.
7676
The ``destinationProject`` parameter can be set to a QgsProject instance in which
77-
to automatically load the resulting sink after completing processing.
77+
to automatically load the resulting sink/layer after completing processing.
7878
%End
7979

80-
QgsProcessingFeatureSinkDefinition( const QgsProperty &sink, QgsProject *destinationProject = 0 );
80+
QgsProcessingOutputLayerDefinition( const QgsProperty &sink, QgsProject *destinationProject = 0 );
8181
%Docstring
82-
Constructor for QgsProcessingFeatureSinkDefinition, accepting a QgsProperty sink.
82+
Constructor for QgsProcessingOutputLayerDefinition, accepting a QgsProperty sink/layer.
8383
The ``destinationProject`` parameter can be set to a QgsProject instance in which
84-
to automatically load the resulting sink after completing processing.
84+
to automatically load the resulting sink/layer after completing processing.
8585
%End
8686

8787
QgsProperty sink;
8888
%Docstring
89-
Sink definition. Usually a static property set to the destination file name for the sink's layer.
89+
Sink/layer definition. Usually a static property set to the destination file name for the sink's layer.
9090
%End
9191

9292
QgsProject *destinationProject;
9393
%Docstring
9494
Destination project. Can be set to a QgsProject instance in which
95-
to automatically load the resulting sink after completing processing.
95+
to automatically load the resulting sink/layer after completing processing.
9696
The default behavior is not to load the result into any project (None).
9797
%End
9898

9999
QVariantMap createOptions;
100100
%Docstring
101-
Map of optional sink creation options, which
101+
Map of optional sink/layer creation options, which
102102
are passed to the underlying provider when creating new layers. Known options also
103103
include 'fileEncoding', which is used to specify a file encoding to use for created
104104
files.
@@ -171,6 +171,10 @@ class QgsProcessingParameterDefinition
171171
sipType = sipType_QgsProcessingParameterFeatureSource;
172172
else if ( sipCpp->type() == "sink" )
173173
sipType = sipType_QgsProcessingParameterFeatureSink;
174+
else if ( sipCpp->type() == "rasterOut" )
175+
sipType = sipType_QgsProcessingParameterRasterOutput;
176+
else if ( sipCpp->type() == "fileOut" )
177+
sipType = sipType_QgsProcessingParameterFileOutput;
174178
%End
175179
public:
176180

@@ -419,6 +423,18 @@ class QgsProcessingParameters
419423
:rtype: QgsRasterLayer
420424
%End
421425

426+
static QString parameterAsRasterOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
427+
%Docstring
428+
Evaluates the parameter with matching ``definition`` to a raster output layer destination.
429+
:rtype: str
430+
%End
431+
432+
static QString parameterAsFileOutput( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
433+
%Docstring
434+
Evaluates the parameter with matching ``definition`` to a file based output destination.
435+
:rtype: str
436+
%End
437+
422438
static QgsVectorLayer *parameterAsVectorLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
423439
%Docstring
424440
Evaluates the parameter with matching ``definition`` to a vector layer.
@@ -1206,6 +1222,13 @@ class QgsProcessingParameterFeatureSink : QgsProcessingParameterDefinition
12061222
:rtype: QgsProcessingParameterDefinition.LayerType
12071223
%End
12081224

1225+
bool hasGeometry() const;
1226+
%Docstring
1227+
Returns true if sink is likely to include geometries. In cases were presence of geometry
1228+
cannot be reliably determined in advance, this method will default to returning true.
1229+
:rtype: bool
1230+
%End
1231+
12091232
void setDataType( QgsProcessingParameterDefinition::LayerType type );
12101233
%Docstring
12111234
Sets the layer ``type`` for the sinks associated with the parameter.
@@ -1214,6 +1237,71 @@ class QgsProcessingParameterFeatureSink : QgsProcessingParameterDefinition
12141237

12151238
};
12161239

1240+
class QgsProcessingParameterRasterOutput : QgsProcessingParameterDefinition
1241+
{
1242+
%Docstring
1243+
A raster layer output parameter.
1244+
.. versionadded:: 3.0
1245+
%End
1246+
1247+
%TypeHeaderCode
1248+
#include "qgsprocessingparameters.h"
1249+
%End
1250+
public:
1251+
1252+
QgsProcessingParameterRasterOutput( const QString &name, const QString &description = QString(),
1253+
const QVariant &defaultValue = QVariant(),
1254+
bool optional = false );
1255+
%Docstring
1256+
Constructor for QgsProcessingParameterRasterOutput.
1257+
%End
1258+
1259+
virtual QString type() const;
1260+
virtual bool isDestination() const;
1261+
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;
1262+
1263+
};
1264+
1265+
class QgsProcessingParameterFileOutput : QgsProcessingParameterDefinition
1266+
{
1267+
%Docstring
1268+
A generic file based output parameter.
1269+
.. versionadded:: 3.0
1270+
%End
1271+
1272+
%TypeHeaderCode
1273+
#include "qgsprocessingparameters.h"
1274+
%End
1275+
public:
1276+
1277+
QgsProcessingParameterFileOutput( const QString &name, const QString &description = QString(),
1278+
const QString &fileFilter = QString(),
1279+
const QVariant &defaultValue = QVariant(),
1280+
bool optional = false );
1281+
%Docstring
1282+
Constructor for QgsProcessingParameterFileOutput.
1283+
%End
1284+
1285+
virtual QString type() const;
1286+
virtual bool isDestination() const;
1287+
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;
1288+
1289+
1290+
QString fileFilter() const;
1291+
%Docstring
1292+
Returns the file filter string for files compatible with this output.
1293+
.. seealso:: setFileFilter()
1294+
:rtype: str
1295+
%End
1296+
1297+
void setFileFilter( const QString &filter );
1298+
%Docstring
1299+
Sets the file ``filter`` string for files compatible with this output.
1300+
.. seealso:: fileFilter()
1301+
%End
1302+
1303+
};
1304+
12171305

12181306

12191307
/************************************************************************

python/core/qgsexpressioncontext.sip

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,14 @@ class QgsExpressionContextUtils
866866
:rtype: QgsExpressionContext
867867
%End
868868

869+
static QgsExpressionContextScope *processingAlgorithmScope( const QgsProcessingAlgorithm *algorithm, const QVariantMap &parameters, QgsProcessingContext &context ) /Factory/;
870+
%Docstring
871+
Creates a new scope which contains variables and functions relating to a processing ``algorithm``,
872+
when used with the specified ``parameters`` and ``context``.
873+
For instance, algorithm name and parameter functions.
874+
:rtype: QgsExpressionContextScope
875+
%End
876+
869877
static void registerContextFunctions();
870878
%Docstring
871879
Registers all known core functions provided by QgsExpressionContextScope objects.

0 commit comments

Comments
 (0)