Skip to content

Commit 24510cb

Browse files
alexbruynyalldawson
authored andcommitted
[processing] populate batch interface with rows when multiple layers
selected (#21859)
1 parent cdaf2b9 commit 24510cb

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

python/plugins/processing/gui/BatchInputSelectionPanel.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,11 @@ def showPopupMenu(self):
8787

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

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

@@ -151,13 +149,13 @@ def generate_layer_id(layer):
151149

152150
def showFileSelectionDialog(self):
153151
settings = QgsSettings()
154-
text = str(self.text.text())
152+
text = self.text.text()
155153
if os.path.isdir(text):
156154
path = text
157155
elif os.path.isdir(os.path.dirname(text)):
158156
path = os.path.dirname(text)
159157
elif settings.contains('/Processing/LastInputPath'):
160-
path = str(settings.value('/Processing/LastInputPath'))
158+
path = settings.value('/Processing/LastInputPath')
161159
else:
162160
path = ''
163161

@@ -166,7 +164,7 @@ def showFileSelectionDialog(self):
166164
if ret:
167165
files = list(ret)
168166
settings.setValue('/Processing/LastInputPath',
169-
os.path.dirname(str(files[0])))
167+
os.path.dirname(files[0]))
170168
for i, filename in enumerate(files):
171169
files[i] = dataobjects.getRasterSublayer(filename, self.param)
172170
if len(files) == 1:

python/plugins/processing/gui/BatchPanel.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
from qgis.core import (Qgis,
3636
QgsApplication,
3737
QgsSettings,
38+
QgsProcessingParameterMapLayer,
39+
QgsProcessingParameterRasterLayer,
40+
QgsProcessingParameterVectorLayer,
41+
QgsProcessingParameterMeshLayer,
42+
QgsProcessingParameterFile,
3843
QgsProcessingParameterDefinition,
3944
QgsProcessingModelAlgorithm)
4045
from qgis.gui import (QgsProcessingParameterWidgetContext,
@@ -43,6 +48,7 @@
4348

4449
from processing.gui.wrappers import WidgetWrapperFactory, WidgetWrapper
4550
from processing.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel
51+
from processing.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
4652

4753
from processing.tools import dataobjects
4854
from processing.tools.dataobjects import createContext
@@ -289,9 +295,17 @@ def addRow(self):
289295
if param.flags() & QgsProcessingParameterDefinition.FlagHidden or param.isDestination():
290296
continue
291297

292-
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent, row, column)
293-
wrappers[param.name()] = wrapper
294-
self.setCellWrapper(row, column, wrapper, context)
298+
if isinstance(param, (QgsProcessingParameterMapLayer, QgsProcessingParameterRasterLayer,
299+
QgsProcessingParameterVectorLayer, QgsProcessingParameterMeshLayer,
300+
QgsProcessingParameterFile)):
301+
self.tblParameters.setCellWidget(
302+
row, column, BatchInputSelectionPanel(
303+
param, row, column, self.parent))
304+
else:
305+
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent, row, column)
306+
wrappers[param.name()] = wrapper
307+
self.setCellWrapper(row, column, wrapper, context)
308+
295309
column += 1
296310

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

python/plugins/processing/gui/ParameterGuiUtils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def getFileFilter(param):
8585
return param.fileFilter() + ';;' + tr('All files (*.*)')
8686
elif param.type() == 'mesh':
8787
return tr('All files (*.*)')
88-
if param.defaultFileExtension():
88+
if hasattr(param, 'defaultFileExtension') and param.defaultFileExtension():
8989
return tr('Default extension') + ' (*.' + param.defaultFileExtension() + ')'
9090
else:
9191
return ''

0 commit comments

Comments
 (0)