Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix batch panel uses layer ids when auto populating output names base…
…d on a layer parameter
  • Loading branch information
github-actions[bot] authored and nyalldawson committed Jul 5, 2020
1 parent 7da0f63 commit 66f72cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
16 changes: 14 additions & 2 deletions python/plugins/processing/gui/BatchOutputSelectionPanel.py
Expand Up @@ -33,6 +33,7 @@
QgsProcessingParameterMultipleLayers,
QgsProcessingParameterBoolean,
QgsProcessingParameterEnum,
QgsProject,
QgsProcessingParameterMatrix)
from qgis.PyQt.QtWidgets import QWidget, QPushButton, QLineEdit, QHBoxLayout, QSizePolicy, QFileDialog

Expand Down Expand Up @@ -108,8 +109,19 @@ def showSelectionDialog(self):
if isinstance(v, QgsMapLayer):
s = v.name()
else:
s = os.path.basename(v)
s = os.path.splitext(s)[0]
if v in QgsProject.instance().mapLayers():
layer = QgsProject.instance().mapLayer(v)
# value is a layer ID, but we'd prefer to show a layer name if it's unique in the project
if len([l for _, l in QgsProject.instance().mapLayers().items() if l.name().lower() == layer.name().lower()]) == 1:
s = layer.name()
else:
# otherwise fall back to layer id
s = v
else:
# else try to use file base name
# TODO: this is bad for database sources!!
s = os.path.basename(v)
s = os.path.splitext(s)[0]
elif isinstance(param, QgsProcessingParameterBoolean):
s = 'true' if v else 'false'
elif isinstance(param, QgsProcessingParameterEnum):
Expand Down
11 changes: 1 addition & 10 deletions python/plugins/processing/gui/BatchPanel.py
Expand Up @@ -304,14 +304,6 @@ def showLayerSelectionDialog(self):
dlg = MultipleInputDialog([layer.name() for layer in layers])
dlg.exec_()

def generate_layer_id(layer):
# prefer layer name if unique
if len([l for l in layers if l.name().lower() == layer.name().lower()]) == 1:
return layer.name()
else:
# otherwise fall back to layer id
return layer.id()

if not dlg.selectedoptions:
return

Expand All @@ -321,8 +313,7 @@ def generate_layer_id(layer):

first_row = self.panel.batchRowCount() if self.panel.batchRowCount() > 1 else 0
for row, selected_idx in enumerate(selected):
layer = layers[selected_idx]
value = generate_layer_id(layer)
value = layers[selected_idx].id()
self.setRowValue(first_row + row, value, context)

def calculateByExpression(self):
Expand Down

0 comments on commit 66f72cd

Please sign in to comment.