33
33
import functools
34
34
from qgis ._core import *
35
35
36
+
36
37
# Boolean evaluation of QgsGeometry
37
38
38
39
@@ -44,7 +45,8 @@ def _geometryNonZero(self):
44
45
QgsGeometry .__bool__ = _geometryNonZero
45
46
46
47
47
- def register_function (function , arg_count , group , usesgeometry = False , referenced_columns = [QgsFeatureRequest .ALL_ATTRIBUTES ], ** kwargs ):
48
+ def register_function (function , arg_count , group , usesgeometry = False ,
49
+ referenced_columns = [QgsFeatureRequest .ALL_ATTRIBUTES ], ** kwargs ):
48
50
"""
49
51
Register a Python function to be used as a expression function.
50
52
@@ -71,9 +73,11 @@ def myfunc(values, *args):
71
73
:param usesgeometry:
72
74
:return:
73
75
"""
76
+
74
77
class QgsPyExpressionFunction (QgsExpressionFunction ):
75
78
76
- def __init__ (self , func , name , args , group , helptext = '' , usesGeometry = True , referencedColumns = QgsFeatureRequest .ALL_ATTRIBUTES , expandargs = False ):
79
+ def __init__ (self , func , name , args , group , helptext = '' , usesGeometry = True ,
80
+ referencedColumns = QgsFeatureRequest .ALL_ATTRIBUTES , expandargs = False ):
77
81
QgsExpressionFunction .__init__ (self , name , args , group , helptext )
78
82
self .function = func
79
83
self .expandargs = expandargs
@@ -126,13 +130,16 @@ def referencedColumns(self, node):
126
130
if register and QgsExpression .isFunctionName (name ):
127
131
if not QgsExpression .unregisterFunction (name ):
128
132
msgtitle = QCoreApplication .translate ("UserExpressions" , "User expressions" )
129
- msg = QCoreApplication .translate ("UserExpressions" , "The user expression {0} already exists and could not be unregistered." ).format (name )
133
+ msg = QCoreApplication .translate ("UserExpressions" ,
134
+ "The user expression {0} already exists and could not be unregistered." ).format (
135
+ name )
130
136
QgsMessageLog .logMessage (msg + "\n " , msgtitle , QgsMessageLog .WARNING )
131
137
return None
132
138
133
139
function .__name__ = name
134
140
helptext = helptemplate .safe_substitute (name = name , doc = helptext )
135
- f = QgsPyExpressionFunction (function , name , arg_count , group , helptext , usesgeometry , referenced_columns , expandargs )
141
+ f = QgsPyExpressionFunction (function , name , arg_count , group , helptext , usesgeometry , referenced_columns ,
142
+ expandargs )
136
143
137
144
# This doesn't really make any sense here but does when used from a decorator context
138
145
# so it can stay.
@@ -163,6 +170,7 @@ def add(values, *args):
163
170
164
171
def wrapper (func ):
165
172
return register_function (func , args , group , ** kwargs )
173
+
166
174
return wrapper
167
175
168
176
@@ -174,6 +182,7 @@ def __init__(self, value):
174
182
def __str__ (self ):
175
183
return repr (self .value )
176
184
185
+
177
186
# Define a `with edit(layer)` statement
178
187
179
188
@@ -268,10 +277,16 @@ def calculation_finished(exception, value=None):
268
277
269
278
# add some __repr__ methods to processing classes
270
279
def processing_source_repr (self ):
271
- return "<QgsProcessingFeatureSourceDefinition {{'source':{}, 'selectedFeaturesOnly': {}}}>" .format (self .source .staticValue (), self .selectedFeaturesOnly )
280
+ return "<QgsProcessingFeatureSourceDefinition {{'source':{}, 'selectedFeaturesOnly': {}}}>" .format (
281
+ self .source .staticValue (), self .selectedFeaturesOnly )
282
+
283
+
272
284
QgsProcessingFeatureSourceDefinition .__repr__ = processing_source_repr
273
285
274
286
275
287
def processing_output_layer_repr (self ):
276
- return "<QgsProcessingOutputLayerDefinition {{'sink':{}, 'createOptions': {}}}>" .format (self .sink .staticValue (), self .createOptions )
288
+ return "<QgsProcessingOutputLayerDefinition {{'sink':{}, 'createOptions': {}}}>" .format (self .sink .staticValue (),
289
+ self .createOptions )
290
+
291
+
277
292
QgsProcessingOutputLayerDefinition .__repr__ = processing_output_layer_repr
0 commit comments