Skip to content

Commit

Permalink
[processing] populate batch interface with rows when multiple layers
Browse files Browse the repository at this point in the history
selected (#21859)
  • Loading branch information
alexbruy authored and nyalldawson committed May 1, 2019
1 parent cdaf2b9 commit 24510cb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
12 changes: 5 additions & 7 deletions python/plugins/processing/gui/BatchInputSelectionPanel.py
Expand Up @@ -87,13 +87,11 @@ def showPopupMenu(self):

if not (isinstance(self.param, QgsProcessingParameterMultipleLayers) and
self.param.layerType == dataobjects.TYPE_FILE):
selectLayerAction = QAction(
QCoreApplication.translate('BatchInputSelectionPanel', 'Select from Open Layers…'), self.pushButton)
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)

Expand Down Expand Up @@ -151,13 +149,13 @@ 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 = ''

Expand All @@ -166,7 +164,7 @@ def showFileSelectionDialog(self):
if ret:
files = list(ret)
settings.setValue('/Processing/LastInputPath',
os.path.dirname(str(files[0])))
os.path.dirname(files[0]))
for i, filename in enumerate(files):
files[i] = dataobjects.getRasterSublayer(filename, self.param)
if len(files) == 1:
Expand Down
20 changes: 17 additions & 3 deletions python/plugins/processing/gui/BatchPanel.py
Expand Up @@ -35,6 +35,11 @@
from qgis.core import (Qgis,
QgsApplication,
QgsSettings,
QgsProcessingParameterMapLayer,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterMeshLayer,
QgsProcessingParameterFile,
QgsProcessingParameterDefinition,
QgsProcessingModelAlgorithm)
from qgis.gui import (QgsProcessingParameterWidgetContext,
Expand All @@ -43,6 +48,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
Expand Down Expand Up @@ -289,9 +295,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():
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/ParameterGuiUtils.py
Expand Up @@ -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 24510cb

Please sign in to comment.