diff options
author | Sandro S. Andrade <sandroandrade@kde.org> | 2013-08-29 22:02:11 -0300 |
---|---|---|
committer | Sandro S. Andrade <sandroandrade@kde.org> | 2013-08-30 03:05:54 +0200 |
commit | 5b9826151b9fe94aeca609c3f9c042ac8d95098b (patch) | |
tree | 1258efa26cfa37f70503f994180b9cdf00c20bdd /scripts | |
parent | 03a141b2de08aaaa12b69ae7422d524aaeb7e1b2 (diff) |
Add declaration of inherited properties and methods
Still lacks forward declaration of inherited types
Change-Id: Iee84221743fc9604720b5d68638871464ac16709
Reviewed-by: Sandro S. Andrade <sandroandrade@kde.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/templates/common.tmpl | 283 | ||||
-rw-r--r-- | scripts/templates/qclass.cpp | 151 | ||||
-rw-r--r-- | scripts/templates/qclass.h | 79 |
3 files changed, 297 insertions, 216 deletions
diff --git a/scripts/templates/common.tmpl b/scripts/templates/common.tmpl index d6d6ddff..bfe2c4c3 100644 --- a/scripts/templates/common.tmpl +++ b/scripts/templates/common.tmpl @@ -43,3 +43,286 @@ ${uml2qt_attribute.item(attributeName)} ${attributeName} [%- END -%] [%- END -%] +[%- MACRO GENERATE_QPROPERTIES(class, visitedClasses) BLOCK -%] +[%- FOREACH parent IN class.findnodes("generalization") -%] + [%- SET parentName = parent.findvalue("@general") -%] + [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] + [%- visitedClasses.push("${parentName}") -%] + [%- GENERATE_QPROPERTIES(xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${parentName}\"]"), visitedClasses) -%] + [%- END -%] +[%- END -%] +[%- FOREACH attribute IN class.findnodes("ownedAttribute") -%] + [%- IF loop.first %] + + // Properties [${class.findvalue("@name")}] + [%- END -%] + [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] + [%- SET qtType = QT_TYPE(namespace, attribute, "false") %] + Q_PROPERTY(${qtType.trim} ${qtAttribute} READ ${qtAttribute}) +[%- END %] +[%- END -%] +[%- MACRO GENERATE_ATTRIBUTES(class, visitedClasses) BLOCK -%] +[%- FOREACH parent IN class.findnodes("generalization") -%] + [%- SET parentName = parent.findvalue("@general") -%] + [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] + [%- visitedClasses.push("${parentName}") -%] + [%- GENERATE_ATTRIBUTES(xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${parentName}\"]"), visitedClasses) -%] + [%- END -%] +[%- END -%] +[%- SET attributes = class.findnodes("ownedAttribute") -%] +[%- FOREACH attribute IN attributes -%] + [%- IF loop.first %] + + // Owned attributes [${class.findvalue("@name")}] + [%- END -%] + [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] + [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] + [%- IF qtType.match("QList|QSet") %] + Q_INVOKABLE const ${qtType}${qtAttribute}() const; + [%- ELSIF qtType.match('\*$') %] + Q_INVOKABLE ${qtType}${qtAttribute}() const; + [%- ELSE %] + Q_INVOKABLE ${qtType}${qtAttribute}() const; + [%- END %] + [%- IF loop.last %] + [%- END %] +[%- END -%] +[%- END -%] +[%- MACRO GENERATE_OPERATIONS(class, visitedClasses) BLOCK -%] +[%- FOREACH parent IN class.findnodes("generalization") -%] + [%- SET parentName = parent.findvalue("@general") -%] + [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] + [%- visitedClasses.push("${parentName}") -%] + [%- GENERATE_OPERATIONS(xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${parentName}\"]"), visitedClasses) -%] + [%- END -%] +[%- END -%] +[%- FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%] +[%- IF loop.first %] + + // Operations [${class.findvalue("@name")}] +[%- END %] +[% SET operationName = operation.findvalue("@name") -%] + Q_INVOKABLE [% QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']"), "false") -%] +${operationName}( + [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] + [%- QT_TYPE(namespace, parameter, "false") -%] +${parameter.findvalue("@name")} + [%- IF !loop.last %], [% END -%] + [%- END -%] +)[% IF operation.findvalue("@isQuery") == "true" %] const[% END %]; +[%- END %] +[%- END -%] +[%- MACRO GENERATE_SLOTS(class, visitedClasses) BLOCK -%] +[%- FOREACH parent IN class.findnodes("generalization") -%] + [%- SET parentName = parent.findvalue("@general") -%] + [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] + [%- visitedClasses.push("${parentName}") -%] + [%- GENERATE_SLOTS(xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${parentName}\"]"), visitedClasses) -%] + [%- END -%] +[%- END -%] +[%- FOREACH attribute IN class.findnodes("ownedAttribute") -%] +[%- IF loop.first %] + // Slots for owned attributes [${class.findvalue("@name")}] +[%- END %] + [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] + [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] + [%- SET readOnly = attribute.findvalue("@isReadOnly") %] + [%- IF readOnly == "false" || readOnly == "" -%] + [%- SET attributeName = attribute.findvalue("@name").ucfirst -%] + [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" -%] + [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] + void add${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*').remove('^Q') %]${qtAttribute}); + void remove${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*').remove('^Q') %]${qtAttribute}); + [%- ELSE %] + void add${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "")}${qtAttribute}); + void remove${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "")}${qtAttribute}); + [%- END -%] + [%- ELSE -%] + [%- IF qtType.match('QList|QSet') %] + void set${attributeName.remove("^Is")}(${qtType.remove('^Q')}${qtAttribute}); + [%- ELSIF qtType.match('\*$') %] + void set${attributeName.remove("^Is")}(${qtType}${qtAttribute}); + [%- ELSE %] + void set${attributeName.remove("^Is")}(${qtType}${qtAttribute}); + [%- END -%] + [%- END -%] + [%- END %] +[%- IF loop.last %] +[% END %] +[%- END -%] +[%- END -%] +[%- MACRO GENERATE_CPP_ATTRIBUTES(class, visitedClasses) BLOCK -%] +[%- FOREACH parent IN class.findnodes("generalization") -%] + [%- SET parentName = parent.findvalue("@general") -%] + [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] + [%- visitedClasses.push("${parentName}") -%] + [%- GENERATE_CPP_ATTRIBUTES(xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${parentName}\"]"), visitedClasses) -%] + [%- END -%] +[%- END -%] +[% FOREACH attribute = class.findnodes("ownedAttribute") -%] + [%- IF loop.first -%] +// OWNED ATTRIBUTES [${class.findvalue("@name")}] +[% END -%] +[%- SET documentation = attribute.findvalue("ownedComment/body/text()") -%] +[%- IF documentation != "" %] +/*! + ${documentation} + */ +[%- END -%] + [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] + [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] + [%- SET derived = attribute.findvalue("@isDerived") -%] + [%- SET derivedUnion = attribute.findvalue("@isDerivedUnion") %] +[% IF qtType.match("QList|QSet") %]const [% END %]${qtType}Q${namespace}${className}::${qtAttribute}() const +{ + [%- IF qtType.match("QList|QSet") %] + [%- IF derived == "true" && (derivedUnion == "" || derivedUnion == "false") %] + ${qtType}r; + foreach (${qtType.remove("QList<").remove("QSet<").remove(">").trim.remove("^Q")}element, ${namespace}${className}::${qtAttribute}()) + r.[% IF qtType.match("QList") %]append[% ELSE %]insert[% END %](reinterpret_cast<${qtType.remove("QList<").remove("QSet<").remove(">").trim}>(element)); + return r; + [%- ELSE %] + return *(reinterpret_cast<const ${qtType.trim.remove(' \*$')} *>(&_${qtAttribute})); + [%- END -%] + [%- ELSIF qtType.match('\*$') %] + [%- IF derived == "true" && (derivedUnion == "" || derivedUnion == "false") %] + return reinterpret_cast<${qtType.trim}>(${namespace}${className}::${qtAttribute}()); + [%- ELSE %] + return reinterpret_cast<${qtType.trim}>(_${qtAttribute}); + [%- END -%] + [%- ELSE %] + [%- IF derived == "true" && (derivedUnion == "" || derivedUnion == "false") %] + return ${namespace}${className}::${qtAttribute}(); + [%- ELSE %] + return _${qtAttribute}; + [%- END -%] + [%- END %] +} + +[%- IF loop.last %] +[% END -%] +[%- END -%] +[%- END -%] +[%- MACRO GENERATE_CPP_OPERATIONS(class, visitedClasses) BLOCK -%] +[%- FOREACH parent IN class.findnodes("generalization") -%] + [%- SET parentName = parent.findvalue("@general") -%] + [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] + [%- visitedClasses.push("${parentName}") -%] + [%- GENERATE_CPP_OPERATIONS(xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${parentName}\"]"), visitedClasses) -%] + [%- END -%] +[%- END -%] +[% FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%] +[%- IF loop.first -%] +// OPERATIONS [${class.findvalue("@name")}] +[% END -%] +[% SET operationName = operation.findvalue("@name") -%] +[%- SET return = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']"), "false") %] +[%- SET documentation = operation.findvalue("ownedComment/body/text()") -%] +[%- IF documentation != "" %] +/*! + ${documentation} + */ +[%- END %] +[% return -%] +Q${namespace}${className}::${operationName}( + [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] + [%- QT_TYPE(namespace, parameter, "false") -%] +${parameter.findvalue("@name")} + [%- IF !loop.last %], [% END -%] + [%- END -%] +)[% IF operation.findvalue("@isQuery") == "true" %] const[% END %] +{ + [%- IF return.match('\*$') || !return.match("QList|QSet") %] + return [% IF return.match('\*$') %]reinterpret_cast<${return.trim}>([% END %]${namespace}${className}::${operationName}( + [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] +${parameter.findvalue("@name")} + [%- IF !loop.last %], [% END -%] + [%- END -%])[% IF return.match('\*$') %])[% END %]; + [%- ELSIF return.match('\*') %] + ${return}r; + foreach (${return.remove("QList<").remove("QSet<").remove(">").trim.remove("^Q")}element, ${namespace}${className}::${operationName}( + [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] +[%- qtType = QT_TYPE(namespace, parameter, "false") -%] +[%- IF qtType.match("QList|QSet") -%] +*(reinterpret_cast<${qtType.replace("<Q", "<")}*>(&${parameter.findvalue("@name")})) +[%- ELSE -%] +${parameter.findvalue("@name")} +[%- END -%] + [%- IF !loop.last %], [% END -%] + [%- END -%])) + r.[% IF return.match("QList") %]append[% ELSE %]insert[% END %](reinterpret_cast<${return.remove("QList<").remove("QSet<").remove(">").trim}>(element)); + return r; + [%- ELSE %] + return ${namespace}${className}::${operationName}( + [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] +${parameter.findvalue("@name")} + [%- IF !loop.last %], [% END -%] + [%- END -%]); + [%- END %] +} + +[%- IF loop.last %] +[% END -%] +[%- END -%] +[%- END -%] +[%- MACRO GENERATE_CPP_SLOTS(class, visitedClasses) BLOCK -%] +[%- FOREACH parent IN class.findnodes("generalization") -%] + [%- SET parentName = parent.findvalue("@general") -%] + [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] + [%- visitedClasses.push("${parentName}") -%] + [%- GENERATE_CPP_SLOTS(xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${parentName}\"]"), visitedClasses) -%] + [%- END -%] +[%- END -%] +[% FOREACH attribute = class.findnodes("ownedAttribute") -%] + [%- IF loop.first -%] +// SLOTS FOR OWNED ATTRIBUTES [${class.findvalue("@name")}] +[% END -%] + [%- SET readOnly = attribute.findvalue("@isReadOnly") %] + [%- IF readOnly == "false" || readOnly == "" -%] + [%- SET attributeName = attribute.findvalue("@name").ucfirst -%] + [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] + [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] + [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" -%] + [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] +void Q${namespace}${className}::add${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*').remove('^Q') %]${qtAttribute}) + [%- ELSE %] +void Q${namespace}${className}::add${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "")} ${qtAttribute}) + [%- END %] +{ + ${namespace}${className}::add${attributeName}(${qtAttribute}); +} + + [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] +void Q${namespace}${className}::remove${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*').remove('^Q') %]${qtAttribute}) + [%- ELSE %] +void Q${namespace}${className}::remove${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "")} ${qtAttribute}) + [%- END %] +{ + ${namespace}${className}::remove${attributeName}(${qtAttribute}); +} + + [%- ELSE -%] + [%- IF qtType.match('QList|QSet') %] +void Q${namespace}${className}::set${attributeName.remove("^Is")}(${qtType.remove('^Q')}${qtAttribute}) +{ + ${namespace}${className}::set${attributeName.remove("^Is")}(${qtAttribute}); +} + + [%- ELSIF qtType.match('\*$') %] +void Q${namespace}${className}::set${attributeName.remove("^Is")}(${qtType}${qtAttribute}) +{ + ${namespace}${className}::set${attributeName.remove("^Is")}(${qtAttribute}); +} + + [%- ELSE %] +void Q${namespace}${className}::set${attributeName.remove("^Is")}(${qtType}${qtAttribute}) +{ + ${namespace}${className}::set${attributeName.remove("^Is")}(${qtAttribute}); +} +[% END -%] + [%- END -%] + [%- END %] +[%- IF loop.last %] +[% END -%] +[%- END %] +[%- END -%]
\ No newline at end of file diff --git a/scripts/templates/qclass.cpp b/scripts/templates/qclass.cpp index d1b21d31..f02d6c79 100644 --- a/scripts/templates/qclass.cpp +++ b/scripts/templates/qclass.cpp @@ -68,150 +68,11 @@ Q${namespace}${className}::Q${namespace}${className}(QObject *parent) : { } -[% FOREACH attribute = class.findnodes("ownedAttribute") -%] - [%- IF loop.first -%] -// OWNED ATTRIBUTES -[% END -%] -[%- SET documentation = attribute.findvalue("ownedComment/body/text()") -%] -[%- IF documentation != "" %] -/*! - ${documentation} - */ -[%- END -%] - [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] - [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] - [%- SET derived = attribute.findvalue("@isDerived") -%] - [%- SET derivedUnion = attribute.findvalue("@isDerivedUnion") %] -[% IF qtType.match("QList|QSet") %]const [% END %]${qtType}Q${namespace}${className}::${qtAttribute}() const -{ - [%- IF qtType.match("QList|QSet") %] - [%- IF derived == "true" && (derivedUnion == "" || derivedUnion == "false") %] - ${qtType}r; - foreach (${qtType.remove("QList<").remove("QSet<").remove(">").trim.remove("^Q")}element, ${namespace}${className}::${qtAttribute}()) - r.[% IF qtType.match("QList") %]append[% ELSE %]insert[% END %](reinterpret_cast<${qtType.remove("QList<").remove("QSet<").remove(">").trim}>(element)); - return r; - [%- ELSE %] - return *(reinterpret_cast<const ${qtType.trim.remove(' \*$')} *>(&_${qtAttribute})); - [%- END -%] - [%- ELSIF qtType.match('\*$') %] - [%- IF derived == "true" && (derivedUnion == "" || derivedUnion == "false") %] - return reinterpret_cast<${qtType.trim}>(${namespace}${className}::${qtAttribute}()); - [%- ELSE %] - return reinterpret_cast<${qtType.trim}>(_${qtAttribute}); - [%- END -%] - [%- ELSE %] - [%- IF derived == "true" && (derivedUnion == "" || derivedUnion == "false") %] - return ${namespace}${className}::${qtAttribute}(); - [%- ELSE %] - return _${qtAttribute}; - [%- END -%] - [%- END %] -} - -[%- IF loop.last %] -[% END -%] -[%- END -%] -[% FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%] -[%- IF loop.first -%] -// OPERATIONS -[% END -%] -[% SET operationName = operation.findvalue("@name") -%] -[%- SET return = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']"), "false") %] -[%- SET documentation = operation.findvalue("ownedComment/body/text()") -%] -[%- IF documentation != "" %] -/*! - ${documentation} - */ -[%- END %] -[% return -%] -Q${namespace}${className}::${operationName}( - [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] - [%- QT_TYPE(namespace, parameter, "false") -%] -${parameter.findvalue("@name")} - [%- IF !loop.last %], [% END -%] - [%- END -%] -)[% IF operation.findvalue("@isQuery") == "true" %] const[% END %] -{ - [%- IF return.match('\*$') || !return.match("QList|QSet") %] - return [% IF return.match('\*$') %]reinterpret_cast<${return.trim}>([% END %]${namespace}${className}::${operationName}( - [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] -${parameter.findvalue("@name")} - [%- IF !loop.last %], [% END -%] - [%- END -%])[% IF return.match('\*$') %])[% END %]; - [%- ELSIF return.match('\*') %] - ${return}r; - foreach (${return.remove("QList<").remove("QSet<").remove(">").trim.remove("^Q")}element, ${namespace}${className}::${operationName}( - [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] -[%- qtType = QT_TYPE(namespace, parameter, "false") -%] -[%- IF qtType.match("QList|QSet") -%] -*(reinterpret_cast<${qtType.replace("<Q", "<")}*>(&${parameter.findvalue("@name")})) -[%- ELSE -%] -${parameter.findvalue("@name")} -[%- END -%] - [%- IF !loop.last %], [% END -%] - [%- END -%])) - r.[% IF return.match("QList") %]append[% ELSE %]insert[% END %](reinterpret_cast<${return.remove("QList<").remove("QSet<").remove(">").trim}>(element)); - return r; - [%- ELSE %] - return ${namespace}${className}::${operationName}( - [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] -${parameter.findvalue("@name")} - [%- IF !loop.last %], [% END -%] - [%- END -%]); - [%- END %] -} - -[%- IF loop.last %] -[% END -%] -[%- END -%] -[% FOREACH attribute = class.findnodes("ownedAttribute") -%] - [%- IF loop.first -%] -// SLOTS FOR OWNED ATTRIBUTES -[% END -%] - [%- SET readOnly = attribute.findvalue("@isReadOnly") %] - [%- IF readOnly == "false" || readOnly == "" -%] - [%- SET attributeName = attribute.findvalue("@name").ucfirst -%] - [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] - [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" -%] - [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] -void Q${namespace}${className}::add${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*').remove('^Q') %]${qtAttribute}) - [%- ELSE %] -void Q${namespace}${className}::add${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "")} ${qtAttribute}) - [%- END %] -{ - ${namespace}${className}::add${attributeName}(${qtAttribute}); -} - - [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] -void Q${namespace}${className}::remove${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*').remove('^Q') %]${qtAttribute}) - [%- ELSE %] -void Q${namespace}${className}::remove${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "")} ${qtAttribute}) - [%- END %] -{ - ${namespace}${className}::remove${attributeName}(${qtAttribute}); -} - - [%- ELSE -%] - [%- IF qtType.match('QList|QSet') %] -void Q${namespace}${className}::set${attributeName.remove("^Is")}(${qtType.remove('^Q')}${qtAttribute}) -{ - ${namespace}${className}::set${attributeName.remove("^Is")}(${qtAttribute}); -} - - [%- ELSIF qtType.match('\*$') %] -void Q${namespace}${className}::set${attributeName.remove("^Is")}(${qtType}${qtAttribute}) -{ - ${namespace}${className}::set${attributeName.remove("^Is")}(${qtAttribute}); -} - - [%- ELSE %] -void Q${namespace}${className}::set${attributeName.remove("^Is")}(${qtType}${qtAttribute}) -{ - ${namespace}${className}::set${attributeName.remove("^Is")}(${qtAttribute}); -} -[% END -%] - [%- END -%] - [%- END %] -[%- END %] +[%- visitedClasses = [] %] +[% GENERATE_CPP_ATTRIBUTES(class, visitedClasses) -%] +[%- visitedClasses = [] %] +[%- GENERATE_CPP_OPERATIONS(class, visitedClasses) -%] +[%- visitedClasses = [] %] +[%- GENERATE_CPP_SLOTS(class, visitedClasses) -%] QT_END_NAMESPACE diff --git a/scripts/templates/qclass.h b/scripts/templates/qclass.h index 65eeb195..81a8cbc1 100644 --- a/scripts/templates/qclass.h +++ b/scripts/templates/qclass.h @@ -74,82 +74,19 @@ class ${forward}; class Q_${namespace.upper}_EXPORT Q${namespace}${className} : public QObject, public ${namespace}${className} { Q_OBJECT -[%- SET attributes = class.findnodes("ownedAttribute") -%] -[%- FOREACH attribute IN attributes -%] - [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] - [%- SET qtType = QT_TYPE(namespace, attribute, "false") %] - [%- SET readOnly = attribute.findvalue("@isReadOnly") %] - [%- SET upperValue = attribute.findvalue("upperValue/@value") -%] - [%- SET attributeName = attribute.findvalue("@name").ucfirst %] - Q_PROPERTY(${qtType.trim} ${qtAttribute} READ ${qtAttribute}) -[%- END %] + [%- visitedClasses = [] -%] + [%- GENERATE_QPROPERTIES(class, visitedClasses) %] public: [% IF class.findvalue("@isAbstract") == "true" %]Q_DECL_HIDDEN [% ELSE %]Q_INVOKABLE [% END %]explicit Q${namespace}${className}(QObject *parent = 0); -[%- FOREACH attribute IN attributes -%] - [%- IF loop.first %] - - // Owned attributes - [%- END -%] - [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] - [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] - [%- IF qtType.match("QList|QSet") %] - Q_INVOKABLE const ${qtType}${qtAttribute}() const; - [%- ELSIF qtType.match('\*$') %] - Q_INVOKABLE ${qtType}${qtAttribute}() const; - [%- ELSE %] - Q_INVOKABLE ${qtType}${qtAttribute}() const; - [%- END %] - [%- IF loop.last %] - [%- END %] -[%- END -%] -[%- FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%] -[%- IF loop.first %] - - // Operations -[%- END %] -[% SET operationName = operation.findvalue("@name") -%] - Q_INVOKABLE [% QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']"), "false") -%] -${operationName}( - [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] - [%- QT_TYPE(namespace, parameter, "false") -%] -${parameter.findvalue("@name")} - [%- IF !loop.last %], [% END -%] - [%- END -%] -)[% IF operation.findvalue("@isQuery") == "true" %] const[% END %]; -[%- END %] -[%- FOREACH attribute IN attributes -%] - [%- IF loop.first %] +[%- visitedClasses = [] -%] +[%- GENERATE_ATTRIBUTES(class, visitedClasses) -%] +[%- visitedClasses = [] -%] +[%- GENERATE_OPERATIONS(class, visitedClasses) -%] +[%- visitedClasses = [] %] public Q_SLOTS: - // Slots for owned attributes - [%- END -%] - [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] - [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] - [%- SET readOnly = attribute.findvalue("@isReadOnly") %] - [%- IF readOnly == "false" || readOnly == "" -%] - [%- SET attributeName = attribute.findvalue("@name").ucfirst -%] - [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" -%] - [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] - void add${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*').remove('^Q') %]${qtAttribute}); - void remove${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*').remove('^Q') %]${qtAttribute}); - [%- ELSE %] - void add${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "")}${qtAttribute}); - void remove${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "")}${qtAttribute}); - [%- END -%] - [%- ELSE -%] - [%- IF qtType.match('QList|QSet') %] - void set${attributeName.remove("^Is")}(${qtType.remove('^Q')}${qtAttribute}); - [%- ELSIF qtType.match('\*$') %] - void set${attributeName.remove("^Is")}(${qtType}${qtAttribute}); - [%- ELSE %] - void set${attributeName.remove("^Is")}(${qtType}${qtAttribute}); - [%- END -%] - [%- END -%] - [%- END %] - [%- IF loop.last %] - [%- END %] -[%- END %] +[%- GENERATE_SLOTS(class, visitedClasses) -%] }; QT_END_NAMESPACE |