Skip to content

Commit

Permalink
[processing] Fix exception when clicking alg with distance param in h…
Browse files Browse the repository at this point in the history
…istory dialog
  • Loading branch information
nyalldawson committed Jul 2, 2018
1 parent cb144b3 commit 1621402
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions python/plugins/processing/gui/NumberInputPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def __init__(self, param):
super(NumberInputPanel, self).__init__(None)
self.setupUi(self)

self.layer = None

self.spnValue.setExpressionsEnabled(True)

self.param = param
Expand Down Expand Up @@ -211,7 +213,8 @@ def __init__(self, param):

def setDynamicLayer(self, layer):
try:
self.btnDataDefined.setVectorLayer(self.getLayerFromValue(layer))
self.layer = self.getLayerFromValue(layer)
self.btnDataDefined.setVectorLayer(self.layer)
except:
pass

Expand All @@ -221,7 +224,14 @@ def getLayerFromValue(self, value):
value, ok = value.source.valueAsString(context.expressionContext())
if isinstance(value, str):
value = QgsProcessingUtils.mapLayerFromString(value, context)
return value
if value is None:
return None

# need to return layer with ownership - otherwise layer may be deleted when context
# goes out of scope
new_layer = context.takeResultLayer(value.id())
# if we got ownership, return that - otherwise just return the layer (which may be owned by the project)
return new_layer if new_layer is not None else value

def getValue(self):
if self.btnDataDefined is not None and self.btnDataDefined.isActive():
Expand Down

0 comments on commit 1621402

Please sign in to comment.