Skip to content

Commit 0b737ff

Browse files
authoredJul 12, 2017
Merge pull request #4840 from nyalldawson/processing_next
[processing] Simplify output creation
2 parents 18b52b2 + 91d6ac9 commit 0b737ff

Some content is hidden

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

46 files changed

+112
-221
lines changed
 

‎python/core/processing/qgsprocessingalgorithm.sip

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,21 @@ class QgsProcessingAlgorithm
392392
.. seealso:: addOutput()
393393
%End
394394

395-
bool addParameter( QgsProcessingParameterDefinition *parameterDefinition /Transfer/ );
395+
bool addParameter( QgsProcessingParameterDefinition *parameterDefinition /Transfer/, bool createOutput = true );
396396
%Docstring
397397
Adds a parameter ``definition`` to the algorithm. Ownership of the definition is transferred to the algorithm.
398398
Returns true if parameter could be successfully added, or false if the parameter could not be added (e.g.
399399
as a result of a duplicate name).
400400

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

403+
If the ``createOutput`` argument is true, then a corresponding output definition will also be created
404+
(and added to the algorithm) where appropriate. E.g. when adding a QgsProcessingParameterVectorDestination
405+
and ``createOutput`` is true, then a QgsProcessingOutputVectorLayer output will be created and
406+
added to the algorithm. There is no need to call addOutput() to manually add a corresponding output
407+
for this vector. If ``createOutput`` is false then this automatic output creation will not
408+
occur.
409+
403410
.. seealso:: initAlgorithm()
404411
.. seealso:: addOutput()
405412
:rtype: bool
@@ -419,6 +426,9 @@ class QgsProcessingAlgorithm
419426

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

429+
Note that in some cases output creation can be automatically performed when calling addParameter().
430+
See the notes in addParameter() for a description of when this occurs.
431+
422432
.. seealso:: addParameter()
423433
.. seealso:: initAlgorithm()
424434
:rtype: bool

‎python/plugins/processing/algs/qgis/AddTableField.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,12 @@
2727

2828
from qgis.PyQt.QtCore import QVariant
2929
from qgis.core import (QgsField,
30-
QgsFeature,
3130
QgsFeatureSink,
32-
QgsApplication,
33-
QgsProcessingUtils,
3431
QgsProcessingParameterFeatureSource,
3532
QgsProcessingParameterString,
3633
QgsProcessingParameterNumber,
3734
QgsProcessingParameterEnum,
38-
QgsProcessingParameterFeatureSink,
39-
QgsProcessingOutputVectorLayer)
35+
QgsProcessingParameterFeatureSink)
4036
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
4137

4238

@@ -73,7 +69,6 @@ def initAlgorithm(self, config=None):
7369
self.addParameter(QgsProcessingParameterNumber(self.FIELD_PRECISION,
7470
self.tr('Field precision'), QgsProcessingParameterNumber.Integer, 0, False, 0, 10))
7571
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT_LAYER, self.tr('Added')))
76-
self.addOutput(QgsProcessingOutputVectorLayer(self.OUTPUT_LAYER, self.tr('Added')))
7772

7873
def name(self):
7974
return 'addfieldtoattributestable'

0 commit comments

Comments
 (0)
Please sign in to comment.