Skip to content
Permalink
Browse files

[FEATURE][processing] In batch mode, allow population of file/layer

input columns by searching for files matching a specified pattern

With optional recursive search!
  • Loading branch information
nyalldawson committed Apr 26, 2019
1 parent 3f4c3d0 commit e6e39173b2b94fb7387b0c8bb1748fd87e4f5e05
@@ -78,7 +78,7 @@ def runAlgorithm(self):
load_layers = self.mainWidget().checkLoadLayersOnCompletion.isChecked()
project = QgsProject.instance() if load_layers else None

for row in range(len(self.mainWidget().batchRowCount())):
for row in range(self.mainWidget().batchRowCount()):
col = 0
parameters = {}
for param in self.algorithm().parameterDefinitions():
@@ -49,14 +49,21 @@
from qgis.core import (Qgis,
QgsApplication,
QgsSettings,
QgsProperty,
QgsProperty, # NOQA - must be here for saved file evaluation
QgsProject,
QgsProcessingFeatureSourceDefinition,
QgsCoordinateReferenceSystem,
QgsProcessingFeatureSourceDefinition, # NOQA - must be here for saved file evaluation
QgsCoordinateReferenceSystem, # NOQA - must be here for saved file evaluation
QgsProcessingParameterDefinition,
QgsProcessingModelAlgorithm)
QgsProcessingModelAlgorithm,
QgsProcessingParameterFile,
QgsProcessingParameterMapLayer,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterMeshLayer,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterFeatureSource)
from qgis.gui import (QgsProcessingParameterWidgetContext,
QgsProcessingContextGenerator)
QgsProcessingContextGenerator,
QgsFindFilesByPatternDialog)
from qgis.utils import iface

from processing.gui.wrappers import WidgetWrapperFactory, WidgetWrapper
@@ -103,9 +110,20 @@ def createMenu(self):
fill_down_action = QAction(self.tr('Fill Down'), self.menu)
fill_down_action.triggered.connect(self.fillDown)
fill_down_action.setToolTip(self.tr('Copy the first value down to all other rows'))

self.menu.addAction(fill_down_action)

if isinstance(self.parameterDefinition, (QgsProcessingParameterFile,
QgsProcessingParameterMapLayer,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterMeshLayer,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterFeatureSource)):
find_by_pattern_action = QAction(QCoreApplication.translate('BatchPanel', 'Add Files by Pattern…'),
self.menu)
find_by_pattern_action.triggered.connect(self.addFilesByPattern)
find_by_pattern_action.setToolTip(self.tr('Adds files by a file pattern match'))
self.menu.addAction(find_by_pattern_action)

def fillDown(self):
"""
Copy the top value down
@@ -127,13 +145,30 @@ def setRowValue(self, row, value, context):
"""
Sets the value for a row, in the current column
"""
if self.panel.batchRowCount() <= row:
self.panel.addRow()

wrapper = self.panel.wrappers[row][self.column]
if wrapper is None:
# e.g. destination header
self.panel.tblParameters.cellWidget(row + 1, self.column).setValue(str(value))
else:
wrapper.setParameterValue(value, context)

def addFilesByPattern(self):
"""
Populates the dialog using a file pattern match
"""
dlg = QgsFindFilesByPatternDialog()
dlg.setWindowTitle(self.tr("Add Files by Pattern"))
if dlg.exec_():
files = dlg.files()
context = dataobjects.createContext()

first_row = self.panel.batchRowCount() if self.panel.batchRowCount() > 1 else 0
for row, file in enumerate(files):
self.setRowValue(first_row + row, file, context)


class BatchPanel(BASE, WIDGET):

0 comments on commit e6e3917

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