Пример #1
0
def default_type_value(symbol):
    """
    Find the default value for the type. Models are initialized as nullptr
    """
    prefix = Filters.classPrefix
    t = symbol.type
    if t.is_primitive:
        if t.is_int:
            return 'int(0)'
        if t.is_bool:
            return 'bool(false)'
        if t.is_string:
            return 'QString()'
        if t.is_real:
            return 'qreal(0.0)'
        if t.is_var:
            return 'QVariant()'
    elif t.is_void:
        return ''
    elif t.is_enum:
        module_name = t.reference.module.module_name
        value = next(iter(t.reference.members))
        return '{0}{1}Module::{2}'.format(prefix, upper_first(module_name), value)
    elif t.is_flag:
        module_name = t.reference.module.module_name
        return '{0}{1}Module::{2}()'.format(prefix, upper_first(module_name), flag_type(symbol))
    elif symbol.type.is_list:
        nested = Filters.returnType(symbol.type.nested)
        return 'QVariantList()'.format(nested)
    elif symbol.type.is_struct:
        return '{0}{1}()'.format(prefix, symbol.type.reference.name)
    elif symbol.type.is_model:
        return 'nullptr'
    jinja_error('default_type_value: Unknown parameter {0} of type {1}'.format(symbol, symbol.type))
Пример #2
0
 def defaultValue(symbol):
     prefix = Filters.classPrefix
     t = symbol.type  # type: qface.domain.TypeSymbol
     if t.is_enum:
         value = next(iter(t.reference.members))
         return '{0}{1}Enum::{2}'.format(prefix, symbol.type, value)
     return Filters.defaultValue(symbol)
Пример #3
0
 def signature(env, s, expand=False, filter=None):
     if not filter:
         filter = CustomFilters.returnType
     return Filters.signature(env, s, expand, filter)
Пример #4
0
 def parameters(env, s, filter=None, spaces=True):
     if not filter:
         filter = CustomFilters.parameterType
     return Filters.parameters(env, s, filter, spaces)
Пример #5
0
 def returnType(symbol):
     prefix = Filters.classPrefix
     if symbol.type.is_enum:
         return '{0}{1}Enum::{1}'.format(prefix, symbol.type)
     return Filters.returnType(symbol)
Пример #6
0
 def parameterType(symbol):
     prefix = Filters.classPrefix
     if symbol.type.is_enum:
         return '{0}{1}Enum::{1} {2}'.format(prefix, symbol.type, symbol)
     return Filters.parameterType(symbol)