Skip to content

Commit

Permalink
[processing] Fix some exceptions in batch dialog after refactoring
Browse files Browse the repository at this point in the history
Fixes #19779, #19786
  • Loading branch information
nyalldawson committed Sep 8, 2018
1 parent 32ee716 commit 1c5250b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions python/plugins/processing/gui/BatchPanel.py
Expand Up @@ -135,6 +135,7 @@ def initWidgets(self):
self.tblParameters.horizontalHeader().setStretchLastSection(True)

def load(self):
context = dataobjects.createContext()
settings = QgsSettings()
last_path = settings.value("/Processing/LastBatchPath", QDir.homePath())
filename, selected_filter = QFileDialog.getOpenFileName(self,
Expand Down Expand Up @@ -164,7 +165,7 @@ def load(self):
if param.name() in params:
value = eval(params[param.name()])
wrapper = self.wrappers[row][column]
wrapper.setValue(value)
wrapper.setParameterValue(value, context)
column += 1

for out in self.alg.destinationParameterDefinitions():
Expand Down Expand Up @@ -195,12 +196,24 @@ def save(self):
if param.isDestination():
continue
wrapper = self.wrappers[row][col]
if not param.checkValueIsAcceptable(wrapper.value(), context):

# For compatibility with 3.x API, we need to check whether the wrapper is
# the deprecated WidgetWrapper class. If not, it's the newer
# QgsAbstractProcessingParameterWidgetWrapper class
# TODO QGIS 4.0 - remove
if issubclass(wrapper.__class__, WidgetWrapper):
widget = wrapper.widget
else:
widget = wrapper.wrappedWidget()

value = wrapper.parameterValue()

if not param.checkValueIsAcceptable(value, context):
self.parent.messageBar().pushMessage("", self.tr('Wrong or missing parameter value: {0} (row {1})').format(
param.description(), row + 1),
level=Qgis.Warning, duration=5)
return
algParams[param.name()] = param.valueAsPythonString(wrapper.value(), context)
algParams[param.name()] = param.valueAsPythonString(value, context)
col += 1
for out in alg.destinationParameterDefinitions():
if out.flags() & QgsProcessingParameterDefinition.FlagHidden:
Expand Down Expand Up @@ -289,13 +302,15 @@ def removeRows(self):
self.tblParameters.setRowCount(self.tblParameters.rowCount() - 1)

def fillParameterValues(self, column):
context = dataobjects.createContext()

wrapper = self.wrappers[0][column]
if wrapper is None:
# e.g. double clicking on a destination header
return

for row in range(1, self.tblParameters.rowCount()):
self.wrappers[row][column].setValue(wrapper.value())
self.wrappers[row][column].setParameterValue(wrapper.value(), context)

def toggleAdvancedMode(self, checked):
for column, param in enumerate(self.alg.parameterDefinitions()):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/wrappers.py
Expand Up @@ -1286,7 +1286,7 @@ def setValue(self, value):
self.setComboValue(value)

def value(self):
if self.dialogType in DIALOG_STANDARD:
if self.dialogType == DIALOG_STANDARD:
if self.parameterDefinition().multiLine():
text = self.widget.toPlainText()
else:
Expand Down

0 comments on commit 1c5250b

Please sign in to comment.