Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Just use standard QgsMessageLog functionality instead of a dedicated
method for processing
  • Loading branch information
nyalldawson committed Apr 26, 2017
1 parent 93c32e6 commit e9f13d1
Show file tree
Hide file tree
Showing 46 changed files with 141 additions and 185 deletions.
2 changes: 1 addition & 1 deletion doc/api_break.dox
Expand Up @@ -2229,7 +2229,7 @@ object of type QgsProcessingFeedback, and will need to adapt their use of progre
- SilentProgress was removed. Use the base QgsProcessingFeedback class instead.
- algList was removed. Use QgsApplication.processingRegistry() instead.
- Processing.algs was removed. QgsApplication.processingRegistry().algorithms() instead.
- ProcessingLog should not be used when reporting log messages from algorithms. Use QgsProcessingUtils.logMessage() instead.
- ProcessingLog should not be used when reporting log messages from algorithms. Use QgsMessageLog.logMessage() instead.

Triangulation {#qgis_api_break_3_0_Triangulation}
-------------
Expand Down
5 changes: 0 additions & 5 deletions python/core/processing/qgsprocessingutils.sip
Expand Up @@ -124,11 +124,6 @@ class QgsProcessingUtils
:rtype: list of QVariant
%End

static void logMessage( QgsMessageLog::MessageLevel level, const QString &message );
%Docstring
Logs a processing ``message`` of a specified ``level`` to the QGIS message log.
%End

};


Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/gdal/GdalUtils.py
Expand Up @@ -80,7 +80,7 @@ def runGdal(commands, feedback=None):
os.putenv('PATH', envval)

fused_command = ' '.join([str(c) for c in commands])
QgsProcessingUtils.logMessage(QgsMessageLog.INFO, fused_command)
QgsMessageLog.logMessage(fused_command, 'Processing', QgsMessageLog.INFO)
feedback.pushInfo('GDAL command:')
feedback.pushCommandInfo(fused_command)
feedback.pushInfo('GDAL command output:')
Expand Down Expand Up @@ -108,7 +108,7 @@ def runGdal(commands, feedback=None):
else:
raise IOError(e.message + u'\nTried 5 times without success. Last iteration stopped after reading {} line(s).\nLast line(s):\n{}'.format(len(loglines), u'\n'.join(loglines[-10:])))

QgsProcessingUtils.logMessage(QgsMessageLog.INFO, '\n'.join(loglines))
QgsMessageLog.logMessage('\n'.join(loglines), 'Processing', QgsMessageLog.INFO)
GdalUtils.consoleOutput = loglines

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/grass7/Grass7Algorithm.py
Expand Up @@ -189,7 +189,7 @@ def defineCharacteristicsFromFile(self):
"txt"))
line = lines.readline().strip('\n').strip()
except Exception as e:
QgsProcessingUtils.logMessage(QgsMessageLog.CRITICAL, self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(self.descriptionFile, line))
QgsMessageLog.logMessage(self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(self.descriptionFile, line), self.tr('Processing'), QgsMessageLog.CRITICAL)
raise e

self.addParameter(ParameterExtent(
Expand Down Expand Up @@ -299,7 +299,7 @@ def processAlgorithm(self, context, feedback):
feedback.pushCommandInfo(line)
loglines.append(line)
if ProcessingConfig.getSetting(Grass7Utils.GRASS_LOG_COMMANDS):
QgsProcessingUtils.logMessage(QgsMessageLog.INFO, loglines)
QgsMessageLog.logMessage(loglines, self.tr('Processing'), QgsMessageLog.INFO)

Grass7Utils.executeGrass7(self.commands, feedback, self.outputCommands)

Expand Down
Expand Up @@ -98,13 +98,10 @@ def createAlgsList(self):
if alg.name().strip() != '':
algs.append(alg)
else:
QgsProcessingUtils.logMessage(
QgsMessageLog.CRITICAL,
self.tr('Could not open GRASS GIS 7 algorithm: {0}').format(descriptionFile))
QgsMessageLog.logMessage(self.tr('Could not open GRASS GIS 7 algorithm: {0}').format(descriptionFile), self.tr('Processing'), QgsMessageLog.CRITICAL)
except Exception as e:
QgsProcessingUtils.logMessage(
QgsMessageLog.CRITICAL,
self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(descriptionFile, str(e)))
QgsMessageLog.logMessage(
self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(descriptionFile, str(e)), self.tr('Processing'), QgsMessageLog.CRITICAL)
algs.append(nviz7())
return algs

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/grass7/Grass7Utils.py
Expand Up @@ -335,7 +335,7 @@ def executeGrass7(commands, feedback, outputCommands=None):
feedback.pushConsoleInfo(line)

if ProcessingConfig.getSetting(Grass7Utils.GRASS_LOG_CONSOLE):
QgsProcessingUtils.logMessage(QgsMessageLog.INFO, loglines)
QgsMessageLog.logMessage('\n'.join(loglines), 'Processing', QgsMessageLog.INFO)

# GRASS session is used to hold the layers already exported or
# produced in GRASS between multiple calls to GRASS algorithms.
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/algs/qgis/Centroids.py
Expand Up @@ -81,8 +81,7 @@ def processAlgorithm(self, context, feedback):
if input_feature.geometry():
output_geometry = input_feature.geometry().centroid()
if not output_geometry:
QgsProcessingUtils.logMessage(QgsMessageLog.WARNING,
'Error calculating centroid for feature {}'.format(input_feature.id()))
QgsMessageLog.logMessage('Error calculating centroid for feature {}'.format(input_feature.id()), self.tr('Processing'), QgsMessageLog.WARNING)
output_feature.setGeometry(output_geometry)

writer.addFeature(output_feature)
Expand Down
7 changes: 3 additions & 4 deletions python/plugins/processing/algs/qgis/Clip.py
Expand Up @@ -141,10 +141,9 @@ def processAlgorithm(self, context, feedback):
out_feat.setAttributes(in_feat.attributes())
writer.addFeature(out_feat)
except:
QgsProcessingUtils.logMessage(QgsMessageLog.CRITICAL,
self.tr('Feature geometry error: One or more '
'output features ignored due to '
'invalid geometry.'))
QgsMessageLog.logMessage(self.tr('Feature geometry error: One or more '
'output features ignored due to '
'invalid geometry.'), self.tr('Processing'), QgsMessageLog.CRITICAL)
continue

if single_clip_feature:
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/algs/qgis/Difference.py
Expand Up @@ -102,8 +102,7 @@ def processAlgorithm(self, context, feedback):
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
except:
QgsProcessingUtils.logMessage(QgsMessageLog.WARNING,
self.tr('Feature geometry error: One or more output features ignored due to invalid geometry.'))
QgsMessageLog.logMessage(self.tr('Feature geometry error: One or more output features ignored due to invalid geometry.'), self.tr('Processing'), QgsMessageLog.WARNING)
continue

feedback.setProgress(int(current * total))
Expand Down
22 changes: 10 additions & 12 deletions python/plugins/processing/algs/qgis/Dissolve.py
Expand Up @@ -108,12 +108,11 @@ def processAlgorithm(self, context, feedback):
errors = tmpInGeom.validateGeometry()
if len(errors) != 0:
for error in errors:
QgsProcessingUtils.logMessage(QgsMessageLog.CRITICAL,
self.tr('ValidateGeometry()'
'error: One or more '
'input features have '
'invalid geometry: ') +
error.what())
QgsMessageLog.logMessage(self.tr('ValidateGeometry()'
'error: One or more '
'input features have '
'invalid geometry: ') +
error.what(), self.tr('Processing'), QgsMessageLog.CRITICAL)
continue

geom_queue.append(tmpInGeom)
Expand Down Expand Up @@ -151,12 +150,11 @@ def processAlgorithm(self, context, feedback):
errors = tmpInGeom.validateGeometry()
if len(errors) != 0:
for error in errors:
QgsProcessingUtils.logMessage(QgsMessageLog.CRITICAL,
self.tr('ValidateGeometry() '
'error: One or more input'
'features have invalid '
'geometry: ') +
error.what())
QgsMessageLog.logMessage(self.tr('ValidateGeometry() '
'error: One or more input'
'features have invalid '
'geometry: ') +
error.what(), self.tr('Processing'), QgsMessageLog.CRITICAL)

if index_attrs not in attribute_dict:
# keep attributes of first feature
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/EliminateSelection.py
Expand Up @@ -86,8 +86,8 @@ def processAlgorithm(self, context, feedback):
smallestArea = self.getParameterValue(self.MODE) == self.MODE_SMALLEST_AREA

if inLayer.selectedFeatureCount() == 0:
QgsProcessingUtils.logMessage(QgsMessageLog.WARNING,
self.tr('{0}: (No selection in input layer "{1}")').format(self.displayName(), self.getParameterValue(self.INPUT)))
QgsMessageLog.logMessage(self.tr('{0}: (No selection in input layer "{1}")').format(self.displayName(), self.getParameterValue(self.INPUT)),
self.tr('Processing'), QgsMessageLog.WARNING)

featToEliminate = []
selFeatIds = inLayer.selectedFeatureIds()
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/algs/qgis/FixGeometry.py
Expand Up @@ -88,8 +88,7 @@ def processAlgorithm(self, context, feedback):
if inputFeature.geometry():
outputGeometry = inputFeature.geometry().makeValid()
if not outputGeometry:
QgsProcessingUtils.logMessage(QgsMessageLog.WARNING,
'makeValid failed for feature {}'.format(inputFeature.id()))
QgsMessageLog.logMessage('makeValid failed for feature {}'.format(inputFeature.id()), self.tr('Processing'), QgsMessageLog.WARNING)

if outputGeometry.wkbType() == QgsWkbTypes.Unknown or QgsWkbTypes.flatType(outputGeometry.geometry().wkbType()) == QgsWkbTypes.GeometryCollection:
tmpGeometries = outputGeometry.asGeometryCollection()
Expand Down
12 changes: 4 additions & 8 deletions python/plugins/processing/algs/qgis/Gridify.py
Expand Up @@ -100,8 +100,7 @@ def processAlgorithm(self, context, feedback):
elif geomType == QgsWkbTypes.LineString:
points = self._gridify(geom.asPolyline(), hSpacing, vSpacing)
if len(points) < 2:
QgsProcessingUtils.logMessage(QgsMessageLog.INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
QgsMessageLog.logMessage(self.tr('Failed to gridify feature with FID {0}').format(f.id()), self.tr('Processing'), QgsMessageLog.INFO)
newGeom = None
else:
newGeom = QgsGeometry.fromPolyline(points)
Expand All @@ -112,8 +111,7 @@ def processAlgorithm(self, context, feedback):
if len(points) > 1:
polyline.append(points)
if len(polyline) <= 0:
QgsProcessingUtils.logMessage(QgsMessageLog.INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
QgsMessageLog.logMessage(self.tr('Failed to gridify feature with FID {0}').format(f.id()), self.tr('Processing'), QgsMessageLog.INFO)
newGeom = None
else:
newGeom = QgsGeometry.fromMultiPolyline(polyline)
Expand All @@ -125,8 +123,7 @@ def processAlgorithm(self, context, feedback):
if len(points) > 1:
polygon.append(points)
if len(polygon) <= 0:
QgsProcessingUtils.logMessage(QgsMessageLog.INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
QgsMessageLog.logMessage(self.tr('Failed to gridify feature with FID {0}').format(f.id()), self.tr('Processing'), QgsMessageLog.INFO)
newGeom = None
else:
newGeom = QgsGeometry.fromPolygon(polygon)
Expand All @@ -143,8 +140,7 @@ def processAlgorithm(self, context, feedback):
multipolygon.append(newPolygon)

if len(multipolygon) <= 0:
QgsProcessingUtils.logMessage(QgsMessageLog.INFO,
self.tr('Failed to gridify feature with FID {0}').format(f.id()))
QgsMessageLog.logMessage(self.tr('Failed to gridify feature with FID {0}').format(f.id()), self.tr('Processing'), QgsMessageLog.INFO)
newGeom = None
else:
newGeom = QgsGeometry.fromMultiPolygon(multipolygon)
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/algs/qgis/Heatmap.py
Expand Up @@ -176,8 +176,7 @@ def processAlgorithm(self, context, feedback):
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
for current, f in enumerate(features):
if kde.addFeature(f) != QgsKernelDensityEstimation.Success:
QgsProcessingUtils.logMessage(QgsMessageLog.CRITICAL,
self.tr('Error adding feature with ID {} to heatmap').format(f.id()))
QgsMessageLog.logMessage(self.tr('Error adding feature with ID {} to heatmap').format(f.id()), self.tr('Processing'), QgsMessageLog.CRITICAL)

feedback.setProgress(int(current * total))

Expand Down
10 changes: 4 additions & 6 deletions python/plugins/processing/algs/qgis/Intersection.py
Expand Up @@ -117,10 +117,9 @@ def processAlgorithm(self, context, feedback):
int_sym = geom.symDifference(tmpGeom)
int_geom = QgsGeometry(int_com.difference(int_sym))
if int_geom.isEmpty() or not int_geom.isGeosValid():
QgsProcessingUtils.logMessage(QgsMessageLog.CRITICAL,
self.tr('GEOS geoprocessing error: One or '
'more input features have invalid '
'geometry.'))
QgsMessageLog.logMessage(self.tr('GEOS geoprocessing error: One or '
'more input features have invalid '
'geometry.'), self.tr('Processing'), QgsMessageLog.CRITICAL)
try:
if int_geom.wkbType() in wkbTypeGroups[wkbTypeGroups[int_geom.wkbType()]]:
outFeat.setGeometry(int_geom)
Expand All @@ -130,8 +129,7 @@ def processAlgorithm(self, context, feedback):
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
except:
QgsProcessingUtils.logMessage(QgsMessageLog.INFO,
self.tr('Feature geometry error: One or more output features ignored due to invalid geometry.'))
QgsMessageLog.logMessage(self.tr('Feature geometry error: One or more output features ignored due to invalid geometry.'), self.tr('Processing'), QgsMessageLog.INFO)
continue

del writer
5 changes: 2 additions & 3 deletions python/plugins/processing/algs/qgis/RandomPointsAlongLines.py
Expand Up @@ -151,8 +151,7 @@ def processAlgorithm(self, context, feedback):
nIterations += 1

if nPoints < pointCount:
QgsProcessingUtils.logMessage(QgsMessageLog.INFO,
self.tr('Can not generate requested number of random points. '
'Maximum number of attempts exceeded.'))
QgsMessageLog.logMessage(self.tr('Can not generate requested number of random points. '
'Maximum number of attempts exceeded.'), self.tr('Processing'), QgsMessageLog.INFO)

del writer
5 changes: 2 additions & 3 deletions python/plugins/processing/algs/qgis/RandomPointsExtent.py
Expand Up @@ -131,8 +131,7 @@ def processAlgorithm(self, context, feedback):
nIterations += 1

if nPoints < pointCount:
QgsProcessingUtils.logMessage(QgsMessageLog.INFO,
self.tr('Can not generate requested number of random points. '
'Maximum number of attempts exceeded.'))
QgsMessageLog.logMessage(self.tr('Can not generate requested number of random points. '
'Maximum number of attempts exceeded.'), self.tr('Processing'), QgsMessageLog.INFO)

del writer
5 changes: 2 additions & 3 deletions python/plugins/processing/algs/qgis/RandomPointsLayer.py
Expand Up @@ -122,8 +122,7 @@ def processAlgorithm(self, context, feedback):
nIterations += 1

if nPoints < pointCount:
QgsProcessingUtils.logMessage(QgsMessageLog.INFO,
self.tr('Can not generate requested number of random points. '
'Maximum number of attempts exceeded.'))
QgsMessageLog.logMessage(self.tr('Can not generate requested number of random points. '
'Maximum number of attempts exceeded.'), self.tr('Processing'), QgsMessageLog.INFO)

del writer
Expand Up @@ -138,9 +138,8 @@ def processAlgorithm(self, context, feedback):
nIterations += 1

if nPoints < pointCount:
QgsProcessingUtils.logMessage(QgsMessageLog.INFO,
self.tr('Can not generate requested number of random '
'points. Maximum number of attempts exceeded.'))
QgsMessageLog.logMessage(self.tr('Can not generate requested number of random '
'points. Maximum number of attempts exceeded.'), self.tr('Processing'), QgsMessageLog.INFO)

feedback.setProgress(0)

Expand Down
Expand Up @@ -139,9 +139,8 @@ def processAlgorithm(self, context, feedback):
nIterations += 1

if nPoints < pointCount:
QgsProcessingUtils.logMessage(QgsMessageLog.INFO,
self.tr('Can not generate requested number of random '
'points. Maximum number of attempts exceeded.'))
QgsMessageLog.logMessage(self.tr('Can not generate requested number of random '
'points. Maximum number of attempts exceeded.'), self.tr('Processing'), QgsMessageLog.INFO)

feedback.setProgress(0)

Expand Down

0 comments on commit e9f13d1

Please sign in to comment.