aboutsummaryrefslogtreecommitdiffstats
path: root/qface/helper/qtcpp.py
diff options
context:
space:
mode:
authorJuergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com>2017-06-27 11:36:55 +0200
committerJuergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com>2017-06-27 11:39:12 +0200
commit2ad559682c5a836636ccf581efcccdf2a49cdc27 (patch)
treed0115d4b000a6fcb09987c4d3ec6fcb66ce0a8c3 /qface/helper/qtcpp.py
parenta5681713980177e99cae74a3904d57fef593997f (diff)
Added some helpers for qtcpp for signatures, parameters passing.
Diffstat (limited to 'qface/helper/qtcpp.py')
-rw-r--r--qface/helper/qtcpp.py45
1 files changed, 41 insertions, 4 deletions
diff --git a/qface/helper/qtcpp.py b/qface/helper/qtcpp.py
index 7e8f3ca..c42f554 100644
--- a/qface/helper/qtcpp.py
+++ b/qface/helper/qtcpp.py
@@ -1,7 +1,8 @@
"""
Provides helper functionality specificially for Qt C++/QML code generators
"""
-
+import qface.idl.domain as domain
+from jinja2 import environmentfilter
def upper_first(s):
s = str(s)
@@ -23,13 +24,13 @@ class Filters(object):
t = symbol.type # type: qface.domain.TypeSymbol
if t.is_primitive:
if t.is_int:
- return '0'
+ return 'int(0)'
if t.is_bool:
- return 'false'
+ return 'bool(false)'
if t.is_string:
return 'QString()'
if t.is_real:
- return '0.0'
+ return 'qreal(0.0)'
if t.is_variant:
return 'QVariant()'
elif t.is_void:
@@ -122,3 +123,39 @@ class Filters(object):
id = '::'.join(symbol.module.name_parts)
return 'using namespace {0}'.format(id)
+ @staticmethod
+ def signalName(s):
+ if isinstance(s, domain.Property):
+ return '{0}Changed'.format(s)
+ return s
+
+ @staticmethod
+ @environmentfilter
+ def parameters(env, s, filter=None, spaces=True):
+ if not filter:
+ filter = Filters.parameterType
+ else:
+ filter = env.filters[filter]
+ args = []
+ indent = ', '
+ if not spaces:
+ indent = ','
+ if isinstance(s, domain.Operation):
+ args = s.parameters
+ elif isinstance(s, domain.Signal):
+ args = s.parameters
+ elif isinstance(s, domain.Property):
+ args = [s]
+ return indent.join([filter(a) for a in args])
+
+ @staticmethod
+ def signature(s):
+ if isinstance(s, domain.Operation):
+ args = s.parameters
+ elif isinstance(s, domain.Signal):
+ args = s.parameters
+ elif isinstance(s, domain.Property):
+ args = [s.type] # for <property>Changed(<type>)
+ else:
+ args = []
+ return ','.join([Filters.returnType(a) for a in args])