Skip to content

Commit f8890d8

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

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

python/plugins/processing/gui/BatchInputSelectionPanel.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ class BatchInputSelectionPanel(QWidget):
5656
def __init__(self, param, row, col, dialog):
5757
super(BatchInputSelectionPanel, self).__init__(None)
5858
self.param = param
59-
self.dialog = dialog
6059
self.row = row
6160
self.col = col
61+
self.dialog = dialog
62+
6263
self.horizontalLayout = QHBoxLayout(self)
6364
self.horizontalLayout.setSpacing(0)
6465
self.horizontalLayout.setMargin(0)
@@ -67,8 +68,7 @@ def __init__(self, param, row, col, dialog):
6768
self.text.setMinimumWidth(300)
6869
self.setValue('')
6970
self.text.editingFinished.connect(self.textEditingFinished)
70-
self.text.setSizePolicy(QSizePolicy.Expanding,
71-
QSizePolicy.Expanding)
71+
self.text.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
7272
self.horizontalLayout.addWidget(self.text)
7373
self.pushButton = QPushButton()
7474
self.pushButton.setText('…')
@@ -86,14 +86,12 @@ def showPopupMenu(self):
8686
popupmenu = QMenu()
8787

8888
if not (isinstance(self.param, QgsProcessingParameterMultipleLayers) and
89-
self.param.layerType == dataobjects.TYPE_FILE):
90-
selectLayerAction = QAction(
91-
QCoreApplication.translate('BatchInputSelectionPanel', 'Select from Open Layers…'), self.pushButton)
89+
self.param.layerType() == QgsProcessing.TypeFile):
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,22 +149,21 @@ 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

164162
ret, selected_filter = QFileDialog.getOpenFileNames(self, self.tr('Select Files'), path,
165163
getFileFilter(self.param))
166164
if ret:
167165
files = list(ret)
168-
settings.setValue('/Processing/LastInputPath',
169-
os.path.dirname(str(files[0])))
166+
settings.setValue('/Processing/LastInputPath', os.path.dirname(files[0]))
170167
for i, filename in enumerate(files):
171168
files[i] = dataobjects.getRasterSublayer(filename, self.param)
172169
if len(files) == 1:

python/plugins/processing/gui/BatchPanel.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979

8080
from processing.gui.wrappers import WidgetWrapperFactory, WidgetWrapper
8181
from processing.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel
82+
from processing.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
8283

8384
from processing.tools import dataobjects
8485
from processing.tools.dataobjects import createContext
@@ -528,9 +529,17 @@ def addRow(self):
528529
if param.flags() & QgsProcessingParameterDefinition.FlagHidden or param.isDestination():
529530
continue
530531

531-
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent, row, column)
532-
wrappers[param.name()] = wrapper
533-
self.setCellWrapper(row, column, wrapper, context)
532+
if isinstance(param, (QgsProcessingParameterMapLayer, QgsProcessingParameterRasterLayer,
533+
QgsProcessingParameterVectorLayer, QgsProcessingParameterMeshLayer,
534+
QgsProcessingParameterFile)):
535+
self.tblParameters.setCellWidget(
536+
row, column, BatchInputSelectionPanel(
537+
param, row, column, self.parent))
538+
else:
539+
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent, row, column)
540+
wrappers[param.name()] = wrapper
541+
self.setCellWrapper(row, column, wrapper, context)
542+
534543
column += 1
535544

536545
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
@@ -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)