[processing] Fix optional layer parameters are filled by default

Refs #17471

Not a full fix for 17471 - that requires handling of optional
numeric values too
This commit is contained in:
Nyall Dawson 2017-12-01 17:03:48 +10:00
parent 0fcbeb7867
commit 8303b94685

View File

@ -708,8 +708,6 @@ class MapLayerWidgetWrapper(WidgetWrapper):
layout.addWidget(btn)
widget.setLayout(layout)
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
self.combo.setAllowEmptyLayer(True)
if ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF):
self.combo.setShowCrs(True)
@ -720,6 +718,10 @@ class MapLayerWidgetWrapper(WidgetWrapper):
except:
pass
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
self.combo.setAllowEmptyLayer(True)
self.combo.setLayer(None)
self.combo.currentIndexChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
self.combo.currentTextChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
return widget
@ -907,8 +909,6 @@ class FeatureSourceWidgetWrapper(WidgetWrapper):
except:
pass
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
self.combo.setAllowEmptyLayer(True)
if ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF):
self.combo.setShowCrs(True)
@ -916,6 +916,10 @@ class FeatureSourceWidgetWrapper(WidgetWrapper):
self.combo.setFilters(filters)
self.combo.setExcludedProviders(['grass'])
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
self.combo.setAllowEmptyLayer(True)
self.combo.setLayer(None)
self.combo.layerChanged.connect(self.layerChanged)
return widget
@ -1179,8 +1183,6 @@ class VectorLayerWidgetWrapper(WidgetWrapper):
if ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF):
self.combo.setShowCrs(True)
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
self.combo.setAllowEmptyLayer(True)
filters = QgsMapLayerProxyModel.Filters()
if QgsProcessing.TypeVectorAnyGeometry in self.param.dataTypes() or len(self.param.dataTypes()) == 0:
@ -1201,6 +1203,10 @@ class VectorLayerWidgetWrapper(WidgetWrapper):
except:
pass
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
self.combo.setAllowEmptyLayer(True)
self.combo.setLayer(None)
self.combo.currentIndexChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
self.combo.currentTextChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
return widget