Skip to content
Permalink
Browse files

[processing] Use outputi database layer name instead of file name when

'use filename as layer name' is checked

Avoids raw uri layer names for database type destinations
  • Loading branch information
nyalldawson committed Oct 23, 2018
1 parent a093dd7 commit e5f52f98c2e341f59c1bffe3634858485c6f94f3
Showing with 25 additions and 3 deletions.
  1. +25 −3 python/plugins/processing/gui/Postprocessing.py
@@ -36,18 +36,41 @@
QgsProcessingUtils,
QgsMapLayer,
QgsWkbTypes,
QgsMessageLog)
QgsMessageLog,
QgsProviderRegistry)

from processing.core.ProcessingConfig import ProcessingConfig
from processing.gui.RenderingStyles import RenderingStyles


def set_layer_name(layer, context_layer_details):
"""
Sets the name for the given layer, either using the layer's file name
(or database layer name), or the name specified by the parameter definition.
"""
use_filename_as_layer_name = ProcessingConfig.getSetting(ProcessingConfig.USE_FILENAME_AS_LAYER_NAME)

if use_filename_as_layer_name or not context_layer_details.name:
source_parts = QgsProviderRegistry.instance().decodeUri(layer.dataProvider().name(), layer.source())
layer_name = source_parts.get('layerName', '')
# if source layer name exists, use that -- else use
if layer_name:
layer.setName(layer_name)
else:
path = source_parts.get('path', '')
if path:
layer.setName(os.path.splitext(os.path.basename(path))[0])
else:
layer.setName(context_layer_details.name)


def handleAlgorithmResults(alg, context, feedback=None, showResults=True):
wrongLayers = []
if feedback is None:
feedback = QgsProcessingFeedback()
feedback.setProgressText(QCoreApplication.translate('Postprocessing', 'Loading resulting layers'))
i = 0

for l, details in context.layersToLoadOnCompletion().items():
if feedback.isCanceled():
return False
@@ -59,8 +82,7 @@ def handleAlgorithmResults(alg, context, feedback=None, showResults=True):
try:
layer = QgsProcessingUtils.mapLayerFromString(l, context, typeHint=details.layerTypeHint)
if layer is not None:
if not ProcessingConfig.getSetting(ProcessingConfig.USE_FILENAME_AS_LAYER_NAME):
layer.setName(details.name)
set_layer_name(layer, details)

style = None
if details.outputName:

0 comments on commit e5f52f9

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