Skip to content

Commit 8ceb6fc

Browse files
committedFeb 14, 2018
[processing] In batch dialog, use layer names for input layers
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.
1 parent 345088c commit 8ceb6fc

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed
 

‎python/plugins/processing/gui/BatchInputSelectionPanel.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,19 @@ def showLayerSelectionDialog(self):
120120

121121
dlg = MultipleInputDialog([layer.name() for layer in layers])
122122
dlg.exec_()
123+
124+
def generate_layer_id(layer):
125+
# prefer layer name if unique
126+
if len([l for l in layers if l.name().lower() == layer.name().lower()]) == 1:
127+
return layer.name()
128+
else:
129+
# otherwise fall back to layer id
130+
return layer.id()
131+
123132
if dlg.selectedoptions is not None:
124133
selected = dlg.selectedoptions
125134
if len(selected) == 1:
126-
self.setValue(layers[selected[0]].id())
135+
self.setValue(generate_layer_id(layers[selected[0]]))
127136
else:
128137
if isinstance(self.param, QgsProcessingParameterMultipleLayers):
129138
self.text.setText(';'.join(layers[idx].id() for idx in selected))
@@ -133,7 +142,7 @@ def showLayerSelectionDialog(self):
133142
self._panel().addRow()
134143
for i, layeridx in enumerate(selected):
135144
self._table().cellWidget(i + self.row,
136-
self.col).setValue(layers[layeridx].id())
145+
self.col).setValue(generate_layer_id(layers[layeridx]))
137146

138147
def showFileSelectionDialog(self):
139148
settings = QgsSettings()

0 commit comments

Comments
 (0)
Please sign in to comment.