Skip to content

Commit

Permalink
[processing] In batch dialog, use layer names for input layers
Browse files Browse the repository at this point in the history
if they are unique in the current project

Instead of always using the layer id, which is generally
gibberish and meaningless for users, instead prefer to use
the layer name as an input in the batch processing dialog. This
is done only if the name is unique within the current project's
loaded layers.

This change makes the dialog more user-friendly, but more importantly
it means that autofilling output values based on an input layer
parameter generates more meaningful automatic output file names.
  • Loading branch information
nyalldawson committed Feb 14, 2018
1 parent 345088c commit 8ceb6fc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions python/plugins/processing/gui/BatchInputSelectionPanel.py
Expand Up @@ -120,10 +120,19 @@ 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 dlg.selectedoptions is not None:
selected = dlg.selectedoptions
if len(selected) == 1:
self.setValue(layers[selected[0]].id())
self.setValue(generate_layer_id(layers[selected[0]]))
else:
if isinstance(self.param, QgsProcessingParameterMultipleLayers):
self.text.setText(';'.join(layers[idx].id() for idx in selected))
Expand All @@ -133,7 +142,7 @@ def showLayerSelectionDialog(self):
self._panel().addRow()
for i, layeridx in enumerate(selected):
self._table().cellWidget(i + self.row,
self.col).setValue(layers[layeridx].id())
self.col).setValue(generate_layer_id(layers[layeridx]))

def showFileSelectionDialog(self):
settings = QgsSettings()
Expand Down

0 comments on commit 8ceb6fc

Please sign in to comment.