Skip to content
Permalink
Browse files

[processing] Make batch process faster (#38989)

  • Loading branch information
nirvn committed Sep 24, 2020
1 parent c1702db commit 931136879c15afab96cc4fd179e541e157cd6b1d
Showing with 39 additions and 20 deletions.
  1. +39 −20 python/plugins/processing/gui/BatchPanel.py
@@ -224,8 +224,11 @@ def addFilesByPattern(self):
context = dataobjects.createContext()

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

def showFileSelectionDialog(self):
settings = QgsSettings()
@@ -246,8 +249,11 @@ def showFileSelectionDialog(self):
context = dataobjects.createContext()

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

def showDirectorySelectionDialog(self):
settings = QgsSettings()
@@ -283,8 +289,11 @@ def showDirectorySelectionDialog(self):
context = dataobjects.createContext()

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

def showLayerSelectionDialog(self):
layers = []
@@ -382,9 +391,13 @@ def populateByExpression(self, adding=False):
res = [res]

first_row = self.panel.batchRowCount() if self.panel.batchRowCount() > 1 else 0
self.panel.addRow(len(res))
self.panel.tblParameters.setUpdatesEnabled(False)
for row, value in enumerate(res):
self.setRowValue(row + first_row, value, context)
self.panel.tblParameters.setUpdatesEnabled(True)
else:
self.panel.tblParameters.setUpdatesEnabled(False)
for row in range(self.panel.batchRowCount()):
params, ok = self.panel.parametersForRow(row, warnOnInvalid=False)

@@ -406,6 +419,7 @@ def populateByExpression(self, adding=False):
exp = QgsExpression(dlg.expressionText())
value = exp.evaluate(expression_context)
self.setRowValue(row, value, context)
self.panel.tblParameters.setUpdatesEnabled(True)


class BatchPanel(QgsPanelWidget, WIDGET):
@@ -655,34 +669,39 @@ def addFillRow(self):
param_definition = self.alg.parameterDefinition(self.column_to_parameter_definition[col])
self.tblParameters.setCellWidget(0, col, BatchPanelFillWidget(param_definition, col, self))

def addRow(self):
self.wrappers.append([None] * self.tblParameters.columnCount())
self.tblParameters.setRowCount(self.tblParameters.rowCount() + 1)
def addRow(self, nb=1):
self.tblParameters.setUpdatesEnabled(False)
self.tblParameters.setRowCount(self.tblParameters.rowCount() + nb)

context = dataobjects.createContext()

wrappers = {}
row = self.tblParameters.rowCount() - 1
for param in self.alg.parameterDefinitions():
if param.isDestination():
continue
row = self.tblParameters.rowCount() - nb
while row < self.tblParameters.rowCount():
self.wrappers.append([None] * self.tblParameters.columnCount())
for param in self.alg.parameterDefinitions():
if param.isDestination():
continue

column = self.parameter_to_column[param.name()]
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent, row, column)
wrappers[param.name()] = wrapper
self.setCellWrapper(row, column, wrapper, context)
column = self.parameter_to_column[param.name()]
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent, row, column)
wrappers[param.name()] = wrapper
self.setCellWrapper(row, column, wrapper, context)

for out in self.alg.destinationParameterDefinitions():
if out.flags() & QgsProcessingParameterDefinition.FlagHidden:
continue
for out in self.alg.destinationParameterDefinitions():
if out.flags() & QgsProcessingParameterDefinition.FlagHidden:
continue

column = self.parameter_to_column[out.name()]
self.tblParameters.setCellWidget(
row, column, BatchOutputSelectionPanel(
out, self.alg, row, column, self))

column = self.parameter_to_column[out.name()]
self.tblParameters.setCellWidget(
row, column, BatchOutputSelectionPanel(
out, self.alg, row, column, self))
for wrapper in list(wrappers.values()):
wrapper.postInitialize(list(wrappers.values()))
row += 1

for wrapper in list(wrappers.values()):
wrapper.postInitialize(list(wrappers.values()))
self.tblParameters.setUpdatesEnabled(True)

def removeRows(self):
rows = set()

0 comments on commit 9311368

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