Skip to content
Permalink
Browse files

Astyle

  • Loading branch information
nyalldawson committed Jun 11, 2017
1 parent 9239753 commit bc9b1b64f9b76ce9b19ce26c8f10cce142369011
Showing with 21 additions and 6 deletions.
  1. +21 −6 python/core/__init__.py
@@ -33,6 +33,7 @@
import functools
from qgis._core import *


# Boolean evaluation of QgsGeometry


@@ -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.
@@ -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
@@ -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.
@@ -163,6 +170,7 @@ def add(values, *args):

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

return wrapper


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


# Define a `with edit(layer)` statement


@@ -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.
You can’t perform that action at this time.