Skip to content

Commit

Permalink
Astyle
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 11, 2017
1 parent 9239753 commit bc9b1b6
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions python/core/__init__.py
Expand Up @@ -33,6 +33,7 @@
import functools
from qgis._core import *


# Boolean evaluation of QgsGeometry


Expand All @@ -44,7 +45,8 @@ def _geometryNonZero(self):
QgsGeometry.__bool__ = _geometryNonZero


def register_function(function, arg_count, group, usesgeometry=False, referenced_columns=[QgsFeatureRequest.ALL_ATTRIBUTES], **kwargs):
def register_function(function, arg_count, group, usesgeometry=False,
referenced_columns=[QgsFeatureRequest.ALL_ATTRIBUTES], **kwargs):
"""
Register a Python function to be used as a expression function.
Expand All @@ -71,9 +73,11 @@ def myfunc(values, *args):
:param usesgeometry:
:return:
"""

class QgsPyExpressionFunction(QgsExpressionFunction):

def __init__(self, func, name, args, group, helptext='', usesGeometry=True, referencedColumns=QgsFeatureRequest.ALL_ATTRIBUTES, expandargs=False):
def __init__(self, func, name, args, group, helptext='', usesGeometry=True,
referencedColumns=QgsFeatureRequest.ALL_ATTRIBUTES, expandargs=False):
QgsExpressionFunction.__init__(self, name, args, group, helptext)
self.function = func
self.expandargs = expandargs
Expand Down Expand Up @@ -126,13 +130,16 @@ def referencedColumns(self, node):
if register and QgsExpression.isFunctionName(name):
if not QgsExpression.unregisterFunction(name):
msgtitle = QCoreApplication.translate("UserExpressions", "User expressions")
msg = QCoreApplication.translate("UserExpressions", "The user expression {0} already exists and could not be unregistered.").format(name)
msg = QCoreApplication.translate("UserExpressions",
"The user expression {0} already exists and could not be unregistered.").format(
name)
QgsMessageLog.logMessage(msg + "\n", msgtitle, QgsMessageLog.WARNING)
return None

function.__name__ = name
helptext = helptemplate.safe_substitute(name=name, doc=helptext)
f = QgsPyExpressionFunction(function, name, arg_count, group, helptext, usesgeometry, referenced_columns, expandargs)
f = QgsPyExpressionFunction(function, name, arg_count, group, helptext, usesgeometry, referenced_columns,
expandargs)

# This doesn't really make any sense here but does when used from a decorator context
# so it can stay.
Expand Down Expand Up @@ -163,6 +170,7 @@ def add(values, *args):

def wrapper(func):
return register_function(func, args, group, **kwargs)

return wrapper


Expand All @@ -174,6 +182,7 @@ def __init__(self, value):
def __str__(self):
return repr(self.value)


# Define a `with edit(layer)` statement


Expand Down Expand Up @@ -268,10 +277,16 @@ def calculation_finished(exception, value=None):

# add some __repr__ methods to processing classes
def processing_source_repr(self):
return "<QgsProcessingFeatureSourceDefinition {{'source':{}, 'selectedFeaturesOnly': {}}}>".format(self.source.staticValue(), self.selectedFeaturesOnly)
return "<QgsProcessingFeatureSourceDefinition {{'source':{}, 'selectedFeaturesOnly': {}}}>".format(
self.source.staticValue(), self.selectedFeaturesOnly)


QgsProcessingFeatureSourceDefinition.__repr__ = processing_source_repr


def processing_output_layer_repr(self):
return "<QgsProcessingOutputLayerDefinition {{'sink':{}, 'createOptions': {}}}>".format(self.sink.staticValue(), self.createOptions)
return "<QgsProcessingOutputLayerDefinition {{'sink':{}, 'createOptions': {}}}>".format(self.sink.staticValue(),
self.createOptions)


QgsProcessingOutputLayerDefinition.__repr__ = processing_output_layer_repr

0 comments on commit bc9b1b6

Please sign in to comment.