Skip to content
Permalink
Browse files

[processing] populate batch interface with rows when multiple layers

selected (fix #21859)
  • Loading branch information
alexbruy authored and nyalldawson committed Apr 17, 2019
1 parent 7279269 commit f8890d8f047cd2bb934eaad83e1057814927adb5
@@ -56,9 +56,10 @@ class BatchInputSelectionPanel(QWidget):
def __init__(self, param, row, col, dialog):
super(BatchInputSelectionPanel, self).__init__(None)
self.param = param
self.dialog = dialog
self.row = row
self.col = col
self.dialog = dialog

self.horizontalLayout = QHBoxLayout(self)
self.horizontalLayout.setSpacing(0)
self.horizontalLayout.setMargin(0)
@@ -67,8 +68,7 @@ def __init__(self, param, row, col, dialog):
self.text.setMinimumWidth(300)
self.setValue('')
self.text.editingFinished.connect(self.textEditingFinished)
self.text.setSizePolicy(QSizePolicy.Expanding,
QSizePolicy.Expanding)
self.text.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.horizontalLayout.addWidget(self.text)
self.pushButton = QPushButton()
self.pushButton.setText('…')
@@ -86,14 +86,12 @@ def showPopupMenu(self):
popupmenu = QMenu()

if not (isinstance(self.param, QgsProcessingParameterMultipleLayers) and
self.param.layerType == dataobjects.TYPE_FILE):
selectLayerAction = QAction(
QCoreApplication.translate('BatchInputSelectionPanel', 'Select from Open Layers…'), self.pushButton)
self.param.layerType() == QgsProcessing.TypeFile):
selectLayerAction = QAction(self.tr('Select from Open Layers…'), self.pushButton)
selectLayerAction.triggered.connect(self.showLayerSelectionDialog)
popupmenu.addAction(selectLayerAction)

selectFileAction = QAction(
QCoreApplication.translate('BatchInputSelectionPanel', 'Select from File System…'), self.pushButton)
selectFileAction = QAction(self.tr('Select from File System…'), self.pushButton)
selectFileAction.triggered.connect(self.showFileSelectionDialog)
popupmenu.addAction(selectFileAction)

@@ -151,22 +149,21 @@ def generate_layer_id(layer):

def showFileSelectionDialog(self):
settings = QgsSettings()
text = str(self.text.text())
text = self.text.text()
if os.path.isdir(text):
path = text
elif os.path.isdir(os.path.dirname(text)):
path = os.path.dirname(text)
elif settings.contains('/Processing/LastInputPath'):
path = str(settings.value('/Processing/LastInputPath'))
path = settings.value('/Processing/LastInputPath')
else:
path = ''

ret, selected_filter = QFileDialog.getOpenFileNames(self, self.tr('Select Files'), path,
getFileFilter(self.param))
if ret:
files = list(ret)
settings.setValue('/Processing/LastInputPath',
os.path.dirname(str(files[0])))
settings.setValue('/Processing/LastInputPath', os.path.dirname(files[0]))
for i, filename in enumerate(files):
files[i] = dataobjects.getRasterSublayer(filename, self.param)
if len(files) == 1:
@@ -79,6 +79,7 @@

from processing.gui.wrappers import WidgetWrapperFactory, WidgetWrapper
from processing.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel
from processing.gui.BatchInputSelectionPanel import BatchInputSelectionPanel

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

wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent, row, column)
wrappers[param.name()] = wrapper
self.setCellWrapper(row, column, wrapper, context)
if isinstance(param, (QgsProcessingParameterMapLayer, QgsProcessingParameterRasterLayer,
QgsProcessingParameterVectorLayer, QgsProcessingParameterMeshLayer,
QgsProcessingParameterFile)):
self.tblParameters.setCellWidget(
row, column, BatchInputSelectionPanel(
param, row, column, self.parent))
else:
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent, row, column)
wrappers[param.name()] = wrapper
self.setCellWrapper(row, column, wrapper, context)

column += 1

for out in self.alg.destinationParameterDefinitions():
@@ -85,7 +85,7 @@ def getFileFilter(param):
return param.fileFilter() + ';;' + tr('All files (*.*)')
elif param.type() == 'mesh':
return tr('All files (*.*)')
if param.defaultFileExtension():
if hasattr(param, 'defaultFileExtension') and param.defaultFileExtension():
return tr('Default extension') + ' (*.' + param.defaultFileExtension() + ')'
else:
return ''

0 comments on commit f8890d8

Please sign in to comment.
You can’t perform that action at this time.