Skip to content

Commit a7806d1

Browse files
authored
Merge pull request #3959 from nyalldawson/processing_port_feedback
[processing] Port feedback object to c++
2 parents 26a8a54 + 86e1138 commit a7806d1

303 files changed

Lines changed: 1024 additions & 836 deletions

File tree

Some content is hidden

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

‎doc/api_break.dox‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,11 @@ Processing {#qgis_api_break_3_0_Processing}
18311831

18321832
- Algorithm providers now subclass the c++ QgsProcessingProvider class, and must be adapted to the API for QgsProcessingProvider. Specifically,
18331833
getName() should be replaced with id(), getDescription() with name(), and getIcon with icon().
1834+
- Algorithm's processAlgorithm method now passes a QgsProcessingFeedback object instead of the loosely defined progress parameter. Algorithms will
1835+
need to update their use of the progress argument to utilise the QgsProcessingFeedback API.
1836+
- Similarly, Python processing scripts no longer have access to a progress variable for reporting their progress. Instead they have a feedback
1837+
object of type QgsProcessingFeedback, and will need to adapt their use of progress reporting to the QgsProcessingFeedback API.
1838+
- SilentProgress was removed. Use the base QgsProcessingFeedback class instead.
18341839

18351840

18361841
QGIS 2.4 {#qgis_api_break_2_4}

‎python/core/core.sip‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@
259259
%Include layertree/qgslayertreeregistrybridge.sip
260260
%Include layertree/qgslayertreeutils.sip
261261

262+
%Include processing/qgsprocessingfeedback.sip
262263
%Include processing/qgsprocessingprovider.sip
263264
%Include processing/qgsprocessingregistry.sip
264265

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* \class QgsProcessingFeedback
3+
* \ingroup core
4+
* Base class for providing feedback from a processing algorithm.
5+
*
6+
* This base class implementation silently ignores all feedback reported by algorithms.
7+
* Subclasses of QgsProcessingFeedback can be used to log this feedback or report
8+
* it to users via the GUI.
9+
* \note added in QGIS 3.0
10+
*/
11+
class QgsProcessingFeedback : public QgsFeedback
12+
{
13+
%TypeHeaderCode
14+
#include <qgsprocessingfeedback.h>
15+
%End
16+
17+
public:
18+
19+
/**
20+
* Sets the algorithm's progress. The progress
21+
* argument is limited to the range 0-100 and reflects the percentage
22+
* progress through the task.
23+
* @see setProgressText()
24+
*/
25+
virtual void setProgress( double progress );
26+
27+
/**
28+
* Sets a progress report text string. This can be used in conjunction with
29+
* setProgress() to provide detailed progress reports, such as "Transformed
30+
* 4 of 5 layers".
31+
* @see setProgress()
32+
*/
33+
virtual void setProgressText( const QString& text );
34+
35+
/**
36+
* Reports that the algorithm encountered an error which prevented it
37+
* from successfully executing.
38+
*/
39+
virtual void reportError( const QString& error );
40+
41+
/**
42+
* Pushes a general informational message from the algorithm. This can
43+
* be used to report feedback which is neither a status report or an
44+
* error, such as "Found 47 matching features".
45+
* @see pushCommandInfo()
46+
* @see pushDebugInfo()
47+
* @see pushConsoleInfo()
48+
*/
49+
virtual void pushInfo( const QString& info );
50+
51+
/**
52+
* Pushes an informational message containing a command from the algorithm.
53+
* This is usually used to report commands which are executed in an external
54+
* application or as subprocesses.
55+
* @see pushInfo()
56+
* @see pushDebugInfo()
57+
* @see pushConsoleInfo()
58+
*/
59+
virtual void pushCommandInfo( const QString& info );
60+
61+
/**
62+
* Pushes an informational message containing debugging helpers from
63+
* the algorithm.
64+
* @see pushInfo()
65+
* @see pushCommandInfo()
66+
* @see pushConsoleInfo()
67+
*/
68+
virtual void pushDebugInfo( const QString& info );
69+
70+
71+
/**
72+
* Pushes a console feedback message from the algorithm. This is used to
73+
* report the output from executing an external command or subprocess.
74+
* @see pushInfo()
75+
* @see pushDebugInfo()
76+
* @see pushCommandInfo()
77+
*/
78+
virtual void pushConsoleInfo( const QString& info );
79+
80+
};

‎python/plugins/processing/algs/exampleprovider/ExampleAlgorithm.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def defineCharacteristics(self):
7575
self.addOutput(OutputVector(self.OUTPUT_LAYER,
7676
self.tr('Output layer with selected features')))
7777

78-
def processAlgorithm(self, progress):
78+
def processAlgorithm(self, feedback):
7979
"""Here is where the processing itself takes place."""
8080

8181
# The first thing to do is retrieve the values of the parameters

‎python/plugins/processing/algs/gdal/GdalAlgorithm.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def getIcon(self):
5656
def getCustomParametersDialog(self):
5757
return GdalAlgorithmDialog(self)
5858

59-
def processAlgorithm(self, progress):
59+
def processAlgorithm(self, feedback):
6060
commands = self.getConsoleCommands()
6161
layers = dataobjects.getVectorLayers()
6262
supported = dataobjects.getSupportedOutputVectorLayerExtensions()
@@ -73,7 +73,7 @@ def processAlgorithm(self, progress):
7373
c = re.sub('["\']{}["\']'.format(fileName), "'" + exportedFileName + "'", c)
7474

7575
commands[i] = c
76-
GdalUtils.runGdal(commands, progress)
76+
GdalUtils.runGdal(commands, feedback)
7777

7878
def shortHelp(self):
7979
helpPath = GdalUtils.gdalHelpPath()

‎python/plugins/processing/algs/gdal/GdalUtils.py‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535
from osgeo import gdal
3636

3737
from qgis.PyQt.QtCore import QSettings
38-
from qgis.core import QgsApplication, QgsVectorFileWriter
38+
from qgis.core import (QgsApplication,
39+
QgsVectorFileWriter,
40+
QgsProcessingFeedback)
3941
from processing.core.ProcessingConfig import ProcessingConfig
4042
from processing.core.ProcessingLog import ProcessingLog
41-
from processing.core.SilentProgress import SilentProgress
4243
from processing.tools.system import isWindows, isMac
4344

4445
try:
@@ -55,9 +56,9 @@ class GdalUtils(object):
5556
supportedRasters = None
5657

5758
@staticmethod
58-
def runGdal(commands, progress=None):
59-
if progress is None:
60-
progress = SilentProgress()
59+
def runGdal(commands, feedback=None):
60+
if feedback is None:
61+
feedback = QgsProcessingFeedback()
6162
envval = os.getenv('PATH')
6263
# We need to give some extra hints to get things picked up on OS X
6364
isDarwin = False
@@ -79,9 +80,9 @@ def runGdal(commands, progress=None):
7980

8081
fused_command = ' '.join([str(c) for c in commands])
8182
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, fused_command)
82-
progress.setInfo('GDAL command:')
83-
progress.setCommand(fused_command)
84-
progress.setInfo('GDAL command output:')
83+
feedback.pushInfo('GDAL command:')
84+
feedback.pushCommandInfo(fused_command)
85+
feedback.pushInfo('GDAL command output:')
8586
success = False
8687
retry_count = 0
8788
while success == False:
@@ -97,7 +98,7 @@ def runGdal(commands, progress=None):
9798
universal_newlines=True,
9899
) as proc:
99100
for line in proc.stdout:
100-
progress.setConsoleInfo(line)
101+
feedback.pushConsoleInfo(line)
101102
loglines.append(line)
102103
success = True
103104
except IOError as e:

‎python/plugins/processing/algs/gdal/extractprojection.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def defineCharacteristics(self):
5757
def getConsoleCommands(self):
5858
return ["extractprojection"]
5959

60-
def processAlgorithm(self, progress):
60+
def processAlgorithm(self, feedback):
6161
rasterPath = self.getParameterValue(self.INPUT)
6262
createPrj = self.getParameterValue(self.PRJ_FILE)
6363

‎python/plugins/processing/algs/gdal/information.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def getConsoleCommands(self):
7373
arguments.append(self.getParameterValue(information.INPUT))
7474
return ['gdalinfo', GdalUtils.escapeAndJoin(arguments)]
7575

76-
def processAlgorithm(self, progress):
77-
GdalUtils.runGdal(self.getConsoleCommands(), progress)
76+
def processAlgorithm(self, feedback):
77+
GdalUtils.runGdal(self.getConsoleCommands(), feedback)
7878
output = self.getOutputValue(information.OUTPUT)
7979
with open(output, 'w') as f:
8080
f.write('<pre>')

‎python/plugins/processing/algs/gdal/ogr2ogrtabletopostgislist.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ def defineCharacteristics(self):
118118
self.addParameter(ParameterString(self.OPTIONS,
119119
self.tr('Additional creation options'), '', optional=True))
120120

121-
def processAlgorithm(self, progress):
121+
def processAlgorithm(self, feedback):
122122
self.processing = True
123-
GdalAlgorithm.processAlgorithm(self, progress)
123+
GdalAlgorithm.processAlgorithm(self, feedback)
124124
self.processing = False
125125

126126
def getConsoleCommands(self):

‎python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ def defineCharacteristics(self):
162162
self.addParameter(ParameterString(self.OPTIONS,
163163
self.tr('Additional creation options'), '', optional=True))
164164

165-
def processAlgorithm(self, progress):
165+
def processAlgorithm(self, feedback):
166166
self.processing = True
167-
GdalAlgorithm.processAlgorithm(self, progress)
167+
GdalAlgorithm.processAlgorithm(self, feedback)
168168
self.processing = False
169169

170170
def getConsoleCommands(self):

0 commit comments

Comments
 (0)