Skip to content

Commit

Permalink
[processing] Ensure parameters linked to layer parameters
Browse files Browse the repository at this point in the history
(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 c5ff6b9
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions python/plugins/processing/gui/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit c5ff6b9

Please sign in to comment.