Beispiel #1
0
def handle_function(node, mapLib):
    fnIndex = node.fnIndex()
    func = QgsExpression.Functions()[fnIndex]
    args = node.args().list()
    retFunc = (func.name())
    retArgs = []
    for arg in args:
        retArgs.append(walkExpression(arg, mapLib))
    retArgs = ",".join(retArgs)
    return "fnc_%s([%s], context)" % (retFunc, retArgs)
def handle_function(node, mapLib):
    fnIndex = node.fnIndex()
    func = QgsExpression.Functions()[fnIndex]
    retArgs = []
    retFunc = (func.name().replace("$", "_"))
    args = node.args()
    if args is not None:
        args = args.list()
        for arg in args:
            retArgs.append(walkExpression(arg, mapLib))
        retArgs = ",".join(retArgs)
    return "fnc_%s([%s], context)" % (retFunc, retArgs)
Beispiel #3
0
    def get_function(self, function_name):
        """Get an expression function which is already loaded in qgis.

        :param function_name: Name of the function.
        :type function_name: str

        :return: The function.
        :rtype: QgsExpressionFunction

        .. versionadded:: 4.3
        """
        for func in QgsExpression.Functions():
            if func.name() == function_name:
                return func
        return None
Beispiel #4
0
def handleFunction(node, layer):
    fnIndex = node.fnIndex()
    func = QgsExpression.Functions()[fnIndex].name()
    if func == "$geometry":
        return ["PropertyName", "geom"]
    elif func in functions:        
        elems = [functions[func]]
        args = node.args()
        if args is not None:
            args = args.list()
            for arg in args:
                elems.append(walkExpression(arg, layer))
        return elems
    else:
        raise UnsupportedExpressionException("Unsupported function in expression: '%s'" % func)    
Beispiel #5
0
def gen_func_stubs():
    """
    Generate function stubs for QGIS functions.
    """
    funcs = QgsExpression.Functions()
    functions = []
    temp = """function %s(values, context) {
    return false;
};
"""
    for func in funcs:
        name = func.name()
        if name.startswith("$"):
            continue
        newfunc = temp % ("fnc_" + name)
        functions.append(newfunc)
    return "\n".join(functions)
Beispiel #6
0
def registerFunctions():

    toms_list = QgsExpression.Functions()

    for func in functions:
        QgsMessageLog.logMessage("Considering function {}".format(func.name()),
                                 tag="TOMs panel")
        try:
            if func in toms_list:
                QgsExpression.unregisterFunction(func.name())
                #del toms_list[func.name()]
        except AttributeError:
            #qgis.toms_functions = dict()
            pass

        if QgsExpression.registerFunction(func):
            QgsMessageLog.logMessage(
                "Registered expression function {}".format(func.name()),
                tag="TOMs panel")
            #qgis.toms_functions[func.name()] = func
    """for title in qgis.toms_functions:
Beispiel #7
0
    QSpinBox,
    QStyledItemDelegate,
)

from qgis.core import QgsExpression

from processing.algs.qgis.ui.FieldsMappingPanel import (
    ExpressionDelegate,
    FieldsMappingModel,
    FieldsMappingPanel,
    FieldsMappingWidgetWrapper,
    FieldTypeDelegate,
)

AGGREGATES = ['first_value']
for function in QgsExpression.Functions():
    if function.name()[0] == '_':
        continue
    if function.isDeprecated():
        continue
    # if ( func->isContextual() ):
    if "Aggregates" in function.groups():
        if function.name() in ('aggregate', 'relation_aggregate'):
            continue
        AGGREGATES.append(function.name())
AGGREGATES = sorted(AGGREGATES)


class AggregatesModel(FieldsMappingModel):
    def configure(self):
        self.columns = [{