mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-08 00:06:51 -05:00
Expose "context" to expression functions
This commit is contained in:
parent
028c64e884
commit
5f7a2912f6
@ -84,12 +84,17 @@ def register_function(function, arg_count, group, usesgeometry=False, referenced
|
|||||||
feature = None
|
feature = None
|
||||||
if context:
|
if context:
|
||||||
feature = context.feature()
|
feature = context.feature()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self.expandargs:
|
if self.expandargs:
|
||||||
values.append(feature)
|
values.append(feature)
|
||||||
values.append(parent)
|
values.append(parent)
|
||||||
|
if inspect.getargspec(self.function).args[-1] == 'context':
|
||||||
|
values.append(context)
|
||||||
return self.function(*values)
|
return self.function(*values)
|
||||||
else:
|
else:
|
||||||
|
if inspect.getargspec(self.function).args[-1] == 'context':
|
||||||
|
self.function(values, feature, parent, context)
|
||||||
return self.function(values, feature, parent)
|
return self.function(values, feature, parent)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
parent.setEvalErrorString(str(ex))
|
parent.setEvalErrorString(str(ex))
|
||||||
@ -113,6 +118,8 @@ def register_function(function, arg_count, group, usesgeometry=False, referenced
|
|||||||
args = inspect.getargspec(function).args
|
args = inspect.getargspec(function).args
|
||||||
number = len(args)
|
number = len(args)
|
||||||
arg_count = number - 2
|
arg_count = number - 2
|
||||||
|
if args[-1] == 'context':
|
||||||
|
arg_count -= 1
|
||||||
expandargs = True
|
expandargs = True
|
||||||
|
|
||||||
register = kwargs.get('register', True)
|
register = kwargs.get('register', True)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user