Skip to content

Commit 979af2b

Browse files
alexbruynyalldawson
authored andcommitted
[processing] populate batch interface with rows when multiple layers
selected (fix #21859)
1 parent ef52134 commit 979af2b

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

python/plugins/processing/gui/BatchInputSelectionPanel.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,11 @@ def showPopupMenu(self):
8686

8787
if not (isinstance(self.param, QgsProcessingParameterMultipleLayers) and
8888
self.param.layerType == dataobjects.TYPE_FILE):
89-
selectLayerAction = QAction(
90-
QCoreApplication.translate('BatchInputSelectionPanel', 'Select from Open Layers…'), self.pushButton)
89+
selectLayerAction = QAction(self.tr('Select from Open Layers…'), self.pushButton)
9190
selectLayerAction.triggered.connect(self.showLayerSelectionDialog)
9291
popupmenu.addAction(selectLayerAction)
9392

94-
selectFileAction = QAction(
95-
QCoreApplication.translate('BatchInputSelectionPanel', 'Select from File System…'), self.pushButton)
93+
selectFileAction = QAction(self.tr('Select from File System…'), self.pushButton)
9694
selectFileAction.triggered.connect(self.showFileSelectionDialog)
9795
popupmenu.addAction(selectFileAction)
9896

@@ -146,13 +144,13 @@ def generate_layer_id(layer):
146144

147145
def showFileSelectionDialog(self):
148146
settings = QgsSettings()
149-
text = str(self.text.text())
147+
text = self.text.text()
150148
if os.path.isdir(text):
151149
path = text
152150
elif os.path.isdir(os.path.dirname(text)):
153151
path = os.path.dirname(text)
154152
elif settings.contains('/Processing/LastInputPath'):
155-
path = str(settings.value('/Processing/LastInputPath'))
153+
path = settings.value('/Processing/LastInputPath')
156154
else:
157155
path = ''
158156

@@ -161,7 +159,7 @@ def showFileSelectionDialog(self):
161159
if ret:
162160
files = list(ret)
163161
settings.setValue('/Processing/LastInputPath',
164-
os.path.dirname(str(files[0])))
162+
os.path.dirname(files[0]))
165163
for i, filename in enumerate(files):
166164
files[i] = dataobjects.getRasterSublayer(filename, self.param)
167165
if len(files) == 1:

python/plugins/processing/gui/BatchPanel.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
QgsApplication,
3737
QgsSettings,
3838
QgsProperty,
39+
QgsProcessingParameterMapLayer,
40+
QgsProcessingParameterRasterLayer,
41+
QgsProcessingParameterVectorLayer,
42+
QgsProcessingParameterFile,
3943
QgsProcessingFeatureSourceDefinition,
4044
QgsCoordinateReferenceSystem,
4145
QgsProcessingParameterDefinition,
@@ -46,6 +50,7 @@
4650

4751
from processing.gui.wrappers import WidgetWrapperFactory, WidgetWrapper
4852
from processing.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel
53+
from processing.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
4954

5055
from processing.tools import dataobjects
5156
from processing.tools.dataobjects import createContext
@@ -292,9 +297,16 @@ def addRow(self):
292297
if param.flags() & QgsProcessingParameterDefinition.FlagHidden or param.isDestination():
293298
continue
294299

295-
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent, row, column)
296-
wrappers[param.name()] = wrapper
297-
self.setCellWrapper(row, column, wrapper, context)
300+
if isinstance(param, (QgsProcessingParameterMapLayer, QgsProcessingParameterRasterLayer,
301+
QgsProcessingParameterVectorLayer, QgsProcessingParameterFile)):
302+
self.tblParameters.setCellWidget(
303+
row, column, BatchInputSelectionPanel(
304+
param, row, column, self.parent))
305+
else:
306+
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent, row, column)
307+
wrappers[param.name()] = wrapper
308+
self.setCellWrapper(row, column, wrapper, context)
309+
298310
column += 1
299311

300312
for out in self.alg.destinationParameterDefinitions():

python/plugins/processing/gui/ParameterGuiUtils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def getFileFilter(param):
8484
elif param.type() == 'fileDestination':
8585
return param.fileFilter() + ';;' + tr('All files (*.*)')
8686

87-
if param.defaultFileExtension():
87+
if hasattr(param, 'defaultFileExtension') and param.defaultFileExtension():
8888
return tr('Default extension') + ' (*.' + param.defaultFileExtension() + ')'
8989
else:
9090
return ''

0 commit comments

Comments
 (0)