Skip to content

Commit

Permalink
[processing] correctly set output styles for models
Browse files Browse the repository at this point in the history
fixes #20573
  • Loading branch information
volaya committed Jan 23, 2019
1 parent f204452 commit eb47288
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
Expand Up @@ -256,7 +256,8 @@ def accept(self):
handleAlgorithmResults(self.alg,
context,
self.feedback,
not keepOpen)
not keepOpen,
parameters)
self._wasExecuted = self.executed or self._wasExecuted
if not keepOpen:
QDialog.reject(self)
Expand Down
5 changes: 2 additions & 3 deletions python/plugins/processing/gui/AlgorithmDialog.py
Expand Up @@ -301,9 +301,8 @@ def finish(self, successful, result, context, feedback):
for out in self.algorithm().outputDefinitions():
if isinstance(out, QgsProcessingOutputHtml) and out.name() in result and result[out.name()]:
resultsList.addResult(icon=self.algorithm().icon(), name=out.description(), timestamp=time.localtime(),
result=result[out.name()])

if not handleAlgorithmResults(self.algorithm(), context, feedback, not keepOpen):
result=result[out.name()])
if not handleAlgorithmResults(self.algorithm(), context, feedback, not keepOpen, result):
self.resetGui()
return

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/BatchAlgorithmDialog.py
Expand Up @@ -168,7 +168,7 @@ def runAlgorithm(self):
else:
break

handleAlgorithmResults(self.algorithm(), context, multi_feedback, False)
handleAlgorithmResults(self.algorithm(), context, multi_feedback, False, parameters)

feedback.pushInfo(self.tr('Batch execution completed in {0:0.2f} seconds'.format(time.time() - start_time)))
task = None
Expand Down
29 changes: 23 additions & 6 deletions python/plugins/processing/gui/Postprocessing.py
Expand Up @@ -37,7 +37,9 @@
QgsMapLayer,
QgsWkbTypes,
QgsMessageLog,
QgsProviderRegistry)
QgsProviderRegistry,
QgsExpressionContext,
QgsExpressionContextScope)

from processing.core.ProcessingConfig import ProcessingConfig
from processing.gui.RenderingStyles import RenderingStyles
Expand Down Expand Up @@ -67,7 +69,7 @@ def set_layer_name(layer, context_layer_details):
layer.setName(context_layer_details.name)


def handleAlgorithmResults(alg, context, feedback=None, showResults=True):
def handleAlgorithmResults(alg, context, feedback=None, showResults=True, parameters={}):
wrongLayers = []
if feedback is None:
feedback = QgsProcessingFeedback()
Expand All @@ -81,15 +83,30 @@ def handleAlgorithmResults(alg, context, feedback=None, showResults=True):
if len(context.layersToLoadOnCompletion()) > 2:
# only show progress feedback if we're loading a bunch of layers
feedback.setProgress(100 * i / float(len(context.layersToLoadOnCompletion())))

try:
layer = QgsProcessingUtils.mapLayerFromString(l, context, typeHint=details.layerTypeHint)
if layer is not None:
set_layer_name(layer, details)

style = None
if details.outputName:
style = RenderingStyles.getStyle(alg.id(), details.outputName)
'''If running a model, the execution will arrive here when an algorithm that is part of
that model is executed. We check if its output is a final otuput of the model, and
adapt the output name accordingly'''
outputName = details.outputName
expcontext = QgsExpressionContext()
scope = QgsExpressionContextScope()
expcontext.appendScope(scope)
for out in alg.outputDefinitions():
outValue = parameters[out.name()]
if hasattr(outValue, "sink"):
outValue = outValue.sink.valueAsString(expcontext)[0]
else:
outValue = str(outValue)
if outValue == l:
outputName = out.name()
break
style = None
if outputName:
style = RenderingStyles.getStyle(alg.id(), outputName)
if style is None:
if layer.type() == QgsMapLayer.RasterLayer:
style = ProcessingConfig.getSetting(ProcessingConfig.RASTER_STYLE)
Expand Down

0 comments on commit eb47288

Please sign in to comment.