Skip to content
Permalink
Browse files

[processing] correctly set output styles for models

fixes #20573
  • Loading branch information
volaya committed Jan 23, 2019
1 parent f204452 commit eb47288fac06692748c7017f6f125a1fc66e9561
@@ -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)
@@ -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

@@ -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
@@ -37,7 +37,9 @@
QgsMapLayer,
QgsWkbTypes,
QgsMessageLog,
QgsProviderRegistry)
QgsProviderRegistry,
QgsExpressionContext,
QgsExpressionContextScope)

from processing.core.ProcessingConfig import ProcessingConfig
from processing.gui.RenderingStyles import RenderingStyles
@@ -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()
@@ -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)

0 comments on commit eb47288

Please sign in to comment.
You can’t perform that action at this time.