[processing] populate batch interface with rows when multiple layers

selected (fix #21859)
This commit is contained in:
Alexander Bruy 2019-04-17 18:57:54 +03:00 committed by Nyall Dawson
parent 7279269eaf
commit f8890d8f04
3 changed files with 22 additions and 16 deletions

View File

@ -56,9 +56,10 @@ class BatchInputSelectionPanel(QWidget):
def __init__(self, param, row, col, dialog): def __init__(self, param, row, col, dialog):
super(BatchInputSelectionPanel, self).__init__(None) super(BatchInputSelectionPanel, self).__init__(None)
self.param = param self.param = param
self.dialog = dialog
self.row = row self.row = row
self.col = col self.col = col
self.dialog = dialog
self.horizontalLayout = QHBoxLayout(self) self.horizontalLayout = QHBoxLayout(self)
self.horizontalLayout.setSpacing(0) self.horizontalLayout.setSpacing(0)
self.horizontalLayout.setMargin(0) self.horizontalLayout.setMargin(0)
@ -67,8 +68,7 @@ class BatchInputSelectionPanel(QWidget):
self.text.setMinimumWidth(300) self.text.setMinimumWidth(300)
self.setValue('') self.setValue('')
self.text.editingFinished.connect(self.textEditingFinished) self.text.editingFinished.connect(self.textEditingFinished)
self.text.setSizePolicy(QSizePolicy.Expanding, self.text.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
QSizePolicy.Expanding)
self.horizontalLayout.addWidget(self.text) self.horizontalLayout.addWidget(self.text)
self.pushButton = QPushButton() self.pushButton = QPushButton()
self.pushButton.setText('') self.pushButton.setText('')
@ -86,14 +86,12 @@ class BatchInputSelectionPanel(QWidget):
popupmenu = QMenu() popupmenu = QMenu()
if not (isinstance(self.param, QgsProcessingParameterMultipleLayers) and if not (isinstance(self.param, QgsProcessingParameterMultipleLayers) and
self.param.layerType == dataobjects.TYPE_FILE): self.param.layerType() == QgsProcessing.TypeFile):
selectLayerAction = QAction( selectLayerAction = QAction(self.tr('Select from Open Layers…'), self.pushButton)
QCoreApplication.translate('BatchInputSelectionPanel', 'Select from Open Layers…'), self.pushButton)
selectLayerAction.triggered.connect(self.showLayerSelectionDialog) selectLayerAction.triggered.connect(self.showLayerSelectionDialog)
popupmenu.addAction(selectLayerAction) popupmenu.addAction(selectLayerAction)
selectFileAction = QAction( selectFileAction = QAction(self.tr('Select from File System…'), self.pushButton)
QCoreApplication.translate('BatchInputSelectionPanel', 'Select from File System…'), self.pushButton)
selectFileAction.triggered.connect(self.showFileSelectionDialog) selectFileAction.triggered.connect(self.showFileSelectionDialog)
popupmenu.addAction(selectFileAction) popupmenu.addAction(selectFileAction)
@ -151,13 +149,13 @@ class BatchInputSelectionPanel(QWidget):
def showFileSelectionDialog(self): def showFileSelectionDialog(self):
settings = QgsSettings() settings = QgsSettings()
text = str(self.text.text()) text = self.text.text()
if os.path.isdir(text): if os.path.isdir(text):
path = text path = text
elif os.path.isdir(os.path.dirname(text)): elif os.path.isdir(os.path.dirname(text)):
path = os.path.dirname(text) path = os.path.dirname(text)
elif settings.contains('/Processing/LastInputPath'): elif settings.contains('/Processing/LastInputPath'):
path = str(settings.value('/Processing/LastInputPath')) path = settings.value('/Processing/LastInputPath')
else: else:
path = '' path = ''
@ -165,8 +163,7 @@ class BatchInputSelectionPanel(QWidget):
getFileFilter(self.param)) getFileFilter(self.param))
if ret: if ret:
files = list(ret) files = list(ret)
settings.setValue('/Processing/LastInputPath', settings.setValue('/Processing/LastInputPath', os.path.dirname(files[0]))
os.path.dirname(str(files[0])))
for i, filename in enumerate(files): for i, filename in enumerate(files):
files[i] = dataobjects.getRasterSublayer(filename, self.param) files[i] = dataobjects.getRasterSublayer(filename, self.param)
if len(files) == 1: if len(files) == 1:

View File

@ -79,6 +79,7 @@ from qgis.utils import iface
from processing.gui.wrappers import WidgetWrapperFactory, WidgetWrapper from processing.gui.wrappers import WidgetWrapperFactory, WidgetWrapper
from processing.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel from processing.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel
from processing.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
from processing.tools import dataobjects from processing.tools import dataobjects
from processing.tools.dataobjects import createContext from processing.tools.dataobjects import createContext
@ -528,9 +529,17 @@ class BatchPanel(BASE, WIDGET):
if param.flags() & QgsProcessingParameterDefinition.FlagHidden or param.isDestination(): if param.flags() & QgsProcessingParameterDefinition.FlagHidden or param.isDestination():
continue continue
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) wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent, row, column)
wrappers[param.name()] = wrapper wrappers[param.name()] = wrapper
self.setCellWrapper(row, column, wrapper, context) self.setCellWrapper(row, column, wrapper, context)
column += 1 column += 1
for out in self.alg.destinationParameterDefinitions(): for out in self.alg.destinationParameterDefinitions():

View File

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