Skip to content
Permalink
Browse files

[processing] Ensure parameters linked to layer parameters

(e.g. field choices) are correctly updated when a layer
is selected which doesn't belong to the project
  • Loading branch information
nyalldawson committed May 21, 2018
1 parent 4ec9e00 commit c5ff6b9c99493f9b77fcc4bce3eb9c1198f7a6a0
Showing with 25 additions and 9 deletions.
  1. +25 −9 python/plugins/processing/gui/wrappers.py
@@ -901,6 +901,7 @@ def selectFile(self):
self.combo.setCurrentIndex(self.combo.findText(filename))
else:
self.combo.setEditText(filename)
self.widgetValueHasChanged.emit(self)

def setValue(self, value):
if value is None or value == NULL:
@@ -918,6 +919,7 @@ def setValue(self, value):
self.widget.setText(value)
else:
self.setComboValue(value, combobox=self.combo)
self.widgetValueHasChanged.emit(self)

def value(self):
if self.dialogType == DIALOG_STANDARD:
@@ -962,6 +964,7 @@ def selectFile(self):
self.combo.setCurrentIndex(self.combo.findText(filename))
else:
self.combo.setEditText(filename)
self.widgetValueHasChanged.emit(self)


class EnumWidgetWrapper(WidgetWrapper):
@@ -1136,6 +1139,7 @@ def selectFile(self):
self.combo.setCurrentIndex(self.combo.findText(filename))
else:
self.combo.setEditText(filename)
self.widgetValueHasChanged.emit(self)

def setValue(self, value):
if value is None or value == NULL:
@@ -1153,6 +1157,7 @@ def setValue(self, value):
self.widget.setValue(value)
else:
self.setComboValue(value, combobox=self.combo)
self.widgetValueHasChanged.emit(self)

def value(self):
if self.dialogType == DIALOG_STANDARD:
@@ -1280,6 +1285,10 @@ def validator(v):

class ExpressionWidgetWrapper(WidgetWrapper):

def __init__(self, param, dialog, row=0, col=0, **kwargs):
super().__init__(param, dialog, row, col, **kwargs)
self.context = dataobjects.createContext()

def createWidget(self):
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
if self.param.parentLayerParameterName():
@@ -1312,11 +1321,10 @@ def parentLayerChanged(self, wrapper):
self.setLayer(wrapper.value())

def setLayer(self, layer):
context = dataobjects.createContext()
if isinstance(layer, QgsProcessingFeatureSourceDefinition):
layer, ok = layer.source.valueAsString(context.expressionContext())
layer, ok = layer.source.valueAsString(self.context.expressionContext())
if isinstance(layer, str):
layer = QgsProcessingUtils.mapLayerFromString(layer, context)
layer = QgsProcessingUtils.mapLayerFromString(layer, self.context)
self.widget.setLayer(layer)

def setValue(self, value):
@@ -1433,6 +1441,7 @@ def selectFile(self):
self.combo.setCurrentIndex(self.combo.findText(filename))
else:
self.combo.setEditText(filename)
self.widgetValueHasChanged.emit(self)

def setValue(self, value):
if value is None or value == NULL:
@@ -1450,6 +1459,7 @@ def setValue(self, value):
return self.widget.setText(value)
else:
self.setComboValue(value, combobox=self.combo)
self.widgetValueHasChanged.emit(self)

def value(self):
if self.dialogType == DIALOG_STANDARD:
@@ -1473,6 +1483,10 @@ def validator(v):
class TableFieldWidgetWrapper(WidgetWrapper):
NOT_SET = '[Not set]'

def __init__(self, param, dialog, row=0, col=0, **kwargs):
super().__init__(param, dialog, row, col, **kwargs)
self.context = dataobjects.createContext()

def createWidget(self):
self._layer = None

@@ -1516,11 +1530,10 @@ def parentValueChanged(self, wrapper):
self.setLayer(wrapper.value())

def setLayer(self, layer):
context = dataobjects.createContext()
if isinstance(layer, QgsProcessingFeatureSourceDefinition):
layer, ok = layer.source.valueAsString(context.expressionContext())
layer, ok = layer.source.valueAsString(self.context.expressionContext())
if isinstance(layer, str):
layer = QgsProcessingUtils.mapLayerFromString(layer, context)
layer = QgsProcessingUtils.mapLayerFromString(layer, self.context)
self._layer = layer
self.refreshItems()

@@ -1595,6 +1608,10 @@ def validator(v):
class BandWidgetWrapper(WidgetWrapper):
NOT_SET = '[Not set]'

def __init__(self, param, dialog, row=0, col=0, **kwargs):
super().__init__(param, dialog, row, col, **kwargs)
self.context = dataobjects.createContext()

def createWidget(self):
self._layer = None

@@ -1626,11 +1643,10 @@ def parentValueChanged(self, wrapper):
self.setLayer(wrapper.value())

def setLayer(self, layer):
context = dataobjects.createContext()
if isinstance(layer, QgsProcessingParameterRasterLayer):
layer, ok = layer.source.valueAsString(context.expressionContext())
layer, ok = layer.source.valueAsString(self.context.expressionContext())
if isinstance(layer, str):
layer = QgsProcessingUtils.mapLayerFromString(layer, context)
layer = QgsProcessingUtils.mapLayerFromString(layer, self.context)
self._layer = layer
self.refreshItems()

0 comments on commit c5ff6b9

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