Remove qgsfunction from qgis.utils.

Import from qgis.core so we don't break API
This commit is contained in:
Nathan Woodrow 2014-11-29 23:21:38 +10:00
parent e14b7e4868
commit 7942325fd7

View File

@ -29,7 +29,7 @@ QGIS utilities module
""" """
from PyQt4.QtCore import QCoreApplication, QLocale from PyQt4.QtCore import QCoreApplication, QLocale
from qgis.core import QGis, QgsExpression, QgsMessageLog from qgis.core import QGis, QgsExpression, QgsMessageLog, qgsfunction
from string import Template from string import Template
import sys import sys
import traceback import traceback
@ -412,62 +412,6 @@ def closeProjectMacro():
mod.closeProject() mod.closeProject()
def qgsfunction(args, group, **kwargs):
"""
Decorator function used to define a user expression function.
Custom functions should take (values, feature, parent) as args,
they can also shortcut naming feature and parent args by using *args
if they are not needed in the function.
Functions should return a value compatible with QVariant
Eval errors can be raised using parent.setEvalErrorString()
Functions must be unregistered when no longer needed using
QgsExpression.unregisterFunction
Example:
@qgsfunction(2, 'test'):
def add(values, feature, parent):
pass
Will create and register a function in QgsExpression called 'add' in the
'test' group that takes two arguments.
or not using feature and parent:
@qgsfunction(2, 'test'):
def add(values, *args):
pass
"""
helptemplate = Template("""<h3>$name function</h3><br>$doc""")
class QgsExpressionFunction(QgsExpression.Function):
def __init__(self, name, args, group, helptext='', usesgeometry=False):
QgsExpression.Function.__init__(self, name, args, group, helptext, usesgeometry)
def func(self, values, feature, parent):
pass
def wrapper(func):
name = kwargs.get('name', func.__name__)
usesgeometry = kwargs.get('usesgeometry', False)
help = func.__doc__ or ''
help = help.strip()
if args == 0 and not name[0] == '$':
name = '${0}'.format(name)
func.__name__ = name
help = helptemplate.safe_substitute(name=name, doc=help)
f = QgsExpressionFunction(name, args, group, help, usesgeometry)
f.func = func
register = kwargs.get('register', True)
if register:
QgsExpression.registerFunction(f)
return f
return wrapper
####################### #######################
# SERVER PLUGINS # SERVER PLUGINS
# #