Skip to content

Commit 46dc2f6

Browse files
committed
[processing] Avoid losing static, user-entered parameter values
in model child algorithms Prior to this change if you edited an algorithm in a model and tried to enter a preset string for certain parameter types, this string would get silently discarded on closing the dialog. E.g. with a dissolve algorithm it was not possible to have a fixed field name within the model to dissolve by. This was caused by WidgetWrapper.comboValue returning the customData for these manually entered values in the parameters combo box, yet manually entered values never have custom data. To work around this we only return the custom data if its set for the selected item - otherwise we return the text unchanged. In order to handle the "[not set]" options, a new static custom data value of WidgetWrapper.NOT_SET_OPTION is added to that comboValue can detect this and return the appropriate None value.
1 parent 12fcfac commit 46dc2f6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

python/plugins/processing/gui/wrappers.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ def getExtendedLayerName(layer):
140140
class WidgetWrapper(QObject):
141141
widgetValueHasChanged = pyqtSignal(object)
142142

143+
NOT_SET_OPTION = '~~~~!!!!NOT SET!!!!~~~~~~~'
144+
143145
def __init__(self, param, dialog, row=0, col=0, **kwargs):
144146
QObject.__init__(self)
145147
self.param = param
@@ -160,7 +162,12 @@ def comboValue(self, validator=None, combobox=None):
160162
if validator is not None and not validator(v):
161163
raise InvalidParameterValue()
162164
return v
163-
return combobox.currentData()
165+
if combobox.currentData() == self.NOT_SET_OPTION:
166+
return None
167+
elif combobox.currentData() is not None:
168+
return combobox.currentData()
169+
else:
170+
return combobox.currentText()
164171

165172
def createWidget(self, **kwargs):
166173
pass
@@ -1303,7 +1310,7 @@ def createWidget(self):
13031310
tables = self.dialog.getAvailableValuesOfType((QgsProcessingParameterVectorLayer, QgsProcessingParameterString),
13041311
(QgsProcessingOutputVectorLayer, QgsProcessingOutputMapLayer, QgsProcessingOutputFile, QgsProcessingOutputString))
13051312
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
1306-
self.combo.addItem(self.NOT_SELECTED, None)
1313+
self.combo.addItem(self.NOT_SELECTED, self.NOT_SET_OPTION)
13071314
for table in tables:
13081315
self.combo.addItem(self.dialog.resolveValueDescription(table), table)
13091316

@@ -1395,7 +1402,7 @@ def createWidget(self):
13951402
fields = self.dialog.getAvailableValuesOfType([QgsProcessingParameterField, QgsProcessingParameterString],
13961403
[QgsProcessingOutputString])
13971404
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
1398-
widget.addItem(self.NOT_SET, None)
1405+
widget.addItem(self.NOT_SET, self.NOT_SET_OPTION)
13991406
for f in fields:
14001407
widget.addItem(self.dialog.resolveValueDescription(f), f)
14011408
widget.setToolTip(
@@ -1508,7 +1515,7 @@ def createWidget(self):
15081515
fields = self.dialog.getAvailableValuesOfType([QgsProcessingParameterBand, QgsProcessingParameterNumber],
15091516
[QgsProcessingOutputNumber])
15101517
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
1511-
widget.addItem(self.NOT_SET, None)
1518+
widget.addItem(self.NOT_SET, self.NOT_SET_OPTION)
15121519
for f in fields:
15131520
widget.addItem(self.dialog.resolveValueDescription(f), f)
15141521
return widget

0 commit comments

Comments
 (0)