diff options
author | Sandro S. Andrade <sandroandrade@kde.org> | 2013-09-02 22:02:41 -0300 |
---|---|---|
committer | Sandro S. Andrade <sandroandrade@kde.org> | 2013-09-03 03:04:37 +0200 |
commit | a143fe8c5451493b128b4c6f0750f02b58af8666 (patch) | |
tree | 4b74787f6ece9256db04dc65002cae749f6936b3 /scripts/templates | |
parent | 2bfe659e4d30b449747585e18eeb84bfc5d73f43 (diff) |
Add initial version of new UML metamodel implementation
Change-Id: Ic29a04dc49fac075d9c736237573b7f4e3da85ef
Reviewed-by: Sandro S. Andrade <sandroandrade@kde.org>
Diffstat (limited to 'scripts/templates')
-rw-r--r-- | scripts/templates/class.cpp | 327 | ||||
-rw-r--r-- | scripts/templates/class_p.h | 130 | ||||
-rw-r--r-- | scripts/templates/common.tmpl | 185 | ||||
-rw-r--r-- | scripts/templates/module.pri | 9 | ||||
-rw-r--r-- | scripts/templates/module.pro | 2 | ||||
-rw-r--r-- | scripts/templates/qclass.cpp | 361 | ||||
-rw-r--r-- | scripts/templates/qclass.h | 110 | ||||
-rw-r--r-- | scripts/templates/qobjectclass.cpp | 85 | ||||
-rw-r--r-- | scripts/templates/qobjectclass_p.h | 94 |
9 files changed, 693 insertions, 610 deletions
diff --git a/scripts/templates/class.cpp b/scripts/templates/class.cpp deleted file mode 100644 index b3717b11..00000000 --- a/scripts/templates/class.cpp +++ /dev/null @@ -1,327 +0,0 @@ -[%- PROCESS common.tmpl -%] -/**************************************************************************** -** -** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt${namespace} module of the Qt Toolkit. -** -** \$QT_BEGIN_LICENSE:LGPL\$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** \$QT_END_LICENSE\$ -** -****************************************************************************/ -#include "${namespace.lower}${className.lower}_p.h" -[%- superclasses = [] -%] -[%- SET generalization = class.findnodes("generalization") -%] -[%- FOREACH superclass IN generalization -%] -[%- superclasses.push("${namespace}${superclass.findvalue('@general')}") -%] -[%- END -%] -[%- forwards = [] -%] -[%- FOREACH forward = class.findnodes("ownedAttribute[@type] | ownedOperation/ownedParameter[@type]") -%] -[%- SET forwardName = forward.findvalue('@type') -%] -[%- IF xmi.findnodes("//packagedElement[@xmi:type='uml:Enumeration' and @name='$forwardName']").findvalue("@name") == "" -%] -[%- IF forwardName != className && superclasses.grep("^${namespace}${forwardName}\$").size == 0 -%][%- forwards.push("${namespace}${forwardName}") -%][%- END -%] -[%- END -%] -[%- END -%] -[%- FOREACH forward = forwards.unique.sort -%] -[%- IF loop.first %] -[% END %] -#include "private/${forward.lower}_p.h" -[%- END %] - -${namespace}${className}::${namespace}${className}() -[%- SET found = "false" -%] -[%- FOREACH attribute = class.findnodes("ownedAttribute[(@isDerived=\"false\" or not(@isDerived)) or (@isDerivedUnion and @isDerivedUnion=\"true\")]") -%] - [%- SET defaultType = attribute.findvalue("defaultValue/@xmi:type") -%] - [%- SET type = QT_TYPE(namespace, attribute) -%] - [%- IF defaultType == "uml:LiteralBoolean" || defaultType == "uml:InstanceValue" || defaultType == "uml:LiteralInteger" || defaultType == "uml:LiteralUnlimitedNatural" || type.match('\*$') -%] - [%- IF found == "false" %] : -[% SET found = "true" -%] - [%- ELSE %], -[% END -%] - [%- IF defaultType == "uml:LiteralBoolean" -%] - [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%] - [%- IF defaultValue != "" -%] - _[% QT_ATTRIBUTE(attribute) %](${defaultValue}) - [%- ELSE -%] - _[% QT_ATTRIBUTE(attribute) %](false) - [%- END -%] - [%- ELSIF defaultType == "uml:InstanceValue" -%] - [%- SET defaultInstance = attribute.findvalue("defaultValue/@instance") -%] - _[% QT_ATTRIBUTE(attribute) %](Qt${namespace}::${defaultInstance.split("-").0}${defaultInstance.split("-").1.ucfirst}) - [%- ELSIF defaultType == "uml:LiteralInteger" -%] - [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%] - [%- IF defaultValue != "" -%] - _[% QT_ATTRIBUTE(attribute) %](${defaultValue}) - [%- ELSE -%] - _[% QT_ATTRIBUTE(attribute) %](0) - [%- END -%] - [%- ELSIF defaultType == "uml:LiteralUnlimitedNatural" -%] - [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%] - [%- IF defaultValue != "" -%] - _[% QT_ATTRIBUTE(attribute) %](${defaultValue}) - [%- ELSE -%] - _[% QT_ATTRIBUTE(attribute) %](0) - [%- END -%] - [%- ELSIF type.match('\*$') -%] - _[% QT_ATTRIBUTE(attribute) %](0) - [%- END -%] - [%- END -%] -[%- END %] -{ -} -[%- FOREACH attribute = class.findnodes("ownedAttribute") %] -[%- IF loop.first %] - -// OWNED ATTRIBUTES -[%- END %] - -[%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] -[%- SET qtType = QT_TYPE(namespace, attribute) -%] -[%- SET readOnly = attribute.findvalue("@isReadOnly") -%] -[%- SET derived = attribute.findvalue("@isDerived") -%] -[%- SET derivedUnion = attribute.findvalue("@isDerivedUnion") -%] -[%- SET association = attribute.findvalue("@association") %] -[% IF qtType.match("QList|QSet") %]const [% END %][% QT_TYPE(namespace, attribute) -%] -${namespace}${className}::${qtAttribute}() const -{ - // This is a [% IF readOnly == "" || readOnly == "false" %]read-write[% ELSE %]read-only[% END %][% IF derived == "true" %] derived[% END %][% IF derivedUnion == "true" %] union[% END %] [% IF association != "" %]association end[% ELSE %]property[% END %] - - [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %] - qWarning("${namespace}${className}::${qtAttribute}(): to be implemented (this is a derived [% IF association != "" %]association end[% ELSE %]property[% END %])"); - - [%- IF qtType.match('\*$') %] - return 0; - [%- ELSE %] - return ${qtType.trim}(); - [%- END %] - [%- ELSE %] - return _${qtAttribute}; - [%- END %] -} - [%- SET attributeName = attribute.findvalue("@name").ucfirst %] - [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" %] - -void ${namespace}${className}::add${attributeName}(${QT_TYPE(namespace, attribute).remove("QSet<").remove("QList<").replace("> ", " ").replace('\* $', '*')}${qtAttribute}) -{ - // This is a [% IF readOnly == "" || readOnly == "false" %]read-write[% ELSE %]read-only[% END %][% IF derived == "true" %] derived[% END %][% IF derivedUnion == "true" %] union[% END %] [% IF association != "" %]association end[% ELSE %]property[% END %] - - [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %] - qWarning("${namespace}${className}::${qtAttribute}(): to be implemented (this is a derived [% IF association != "" %]association end[% ELSE %]property[% END %])"); - Q_UNUSED(${qtAttribute}); - - if (false /* <derivedexclusion-criteria> */) { - // <derived-code> - [%- ELSE %] - if (!_${qtAttribute}.contains(${qtAttribute})) { - _${qtAttribute}.[% IF QT_TYPE(namespace, attribute).match("QList") %]append[% ELSE %]insert[% END %](${qtAttribute}); - [%- END %] - [%- found = "false" -%] - [%- FOREACH subsettedPropertyName = attribute.findvalue("@subsettedProperty").split(" ") -%] - [%- SET subsettedProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${subsettedPropertyName.split('-').0}\"]/ownedAttribute[@name=\"${subsettedPropertyName.split('-').1}\"]") -%] - [%- IF subsettedProperty.findvalue("@name") != "" -%] - [%- IF found == "false" %] - - // Adjust subsetted properties - [%- found = "true" -%] - [%- END -%] - [%- IF subsettedProperty.findvalue("upperValue/@value") == "*" %] - add${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute}); - [%- ELSE %] - set${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute}); - [%- END -%] - [%- END %] - [%- END %] - [%- IF association != "" -%] - [%- found = "false" -%] - [%- FOREACH memberEnd = xmi.findvalue("//packagedElement[@xmi:type=\"uml:Association\" and @name=\"${association}\"]/@memberEnd").split(' ') -%] - [%- NEXT IF memberEnd.split('-').0 == className -%] - [%- SET oppositeProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${memberEnd.split('-').0}\"]/ownedAttribute[@name=\"${memberEnd.split('-').1}\"]") -%] - [%- IF oppositeProperty.findvalue("@name") != "" -%] - [%- IF found == "false" %] - - // Adjust opposite properties - [%- found = "true" -%] - [%- END %] - if (${qtAttribute}) { - [%- IF oppositeProperty.findvalue("upperValue/@value") == "*" %] - ${qtAttribute}->add${memberEnd.split('-').1.ucfirst}(this); - [%- ELSE %] - ${qtAttribute}->set${memberEnd.split('-').1.ucfirst}(this); - [%- END %] - } - [%- END %] - [%- END %] - [%- END %] - } -} - -void ${namespace}${className}::remove${attributeName}(${QT_TYPE(namespace, attribute).remove("QSet<").remove("QList<").replace("> ", " ").replace('\* $', '*')}${qtAttribute}) -{ - // This is a [% IF readOnly == "" || readOnly == "false" %]read-write[% ELSE %]read-only[% END %][% IF derived == "true" %] derived[% END %][% IF derivedUnion == "true" %] union[% END %] [% IF association != "" %]association end[% ELSE %]property[% END %] - - [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %] - qWarning("${namespace}${className}::${qtAttribute}(): to be implemented (this is a derived [% IF association != "" %]association end[% ELSE %]property[% END %])"); - Q_UNUSED(${qtAttribute}); - - if (false /* <derivedexclusion-criteria> */) { - // <derived-code> - [%- ELSE %] - if (_${qtAttribute}.contains(${qtAttribute})) { - _${qtAttribute}.[% IF QT_TYPE(namespace, attribute).match("QList") %]removeAll[% ELSE %]remove[% END %](${qtAttribute}); - [%- END %] - [%- found = "false" -%] - [%- FOREACH subsettedPropertyName = attribute.findvalue("@subsettedProperty").split(" ") -%] - [%- SET subsettedProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${subsettedPropertyName.split('-').0}\"]/ownedAttribute[@name=\"${subsettedPropertyName.split('-').1}\"]") -%] - [%- IF subsettedProperty.findvalue("@name") != "" -%] - [%- IF found == "false" %] - - // Adjust subsetted properties - [%- found = "true" -%] - [%- END -%] - [%- IF subsettedProperty.findvalue("upperValue/@value") == "*" %] - remove${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute}); - [%- ELSE %] - set${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute}); - [%- END -%] - [%- END %] - [%- END %] - [%- IF association != "" -%] - [%- found = "false" -%] - [%- FOREACH memberEnd = xmi.findvalue("//packagedElement[@xmi:type=\"uml:Association\" and @name=\"${association}\"]/@memberEnd").split(' ') -%] - [%- NEXT IF memberEnd.split('-').0 == className -%] - [%- SET oppositeProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${memberEnd.split('-').0}\"]/ownedAttribute[@name=\"${memberEnd.split('-').1}\"]") -%] - [%- IF oppositeProperty.findvalue("@name") != "" -%] - [%- IF found == "false" %] - - // Adjust opposite properties - [%- found = "true" -%] - [%- END %] - if (${qtAttribute}) { - [%- IF oppositeProperty.findvalue("upperValue/@value") == "*" %] - ${qtAttribute}->remove${memberEnd.split('-').1.ucfirst}(this); - [%- ELSE %] - ${qtAttribute}->set${memberEnd.split('-').1.ucfirst}(0); - [%- END %] - } - [%- END %] - [%- END %] - [%- END %] - } -} - [%- ELSE %] - -void ${namespace}${className}::set${attributeName.remove("^Is")}(${QT_TYPE(namespace, attribute)}${qtAttribute}) -{ - // This is a [% IF readOnly == "" || readOnly == "false" %]read-write[% ELSE %]read-only[% END %][% IF derived == "true" %] derived[% END %][% IF derivedUnion == "true" %] union[% END %] [% IF association != "" %]association end[% ELSE %]property[% END %] - - [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %] - qWarning("${namespace}${className}::${qtAttribute}(): to be implemented (this is a derived [% IF association != "" %]association end[% ELSE %]property[% END %])"); - Q_UNUSED(${qtAttribute}); - - if (false /* <derivedexclusion-criteria> */) { - [%- ELSE %] - if (_${qtAttribute} != ${qtAttribute}) { - [%- END %] - [%- found = "false" -%] - [%- FOREACH subsettedPropertyName = attribute.findvalue("@subsettedProperty").split(" ") -%] - [%- SET subsettedProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${subsettedPropertyName.split('-').0}\"]/ownedAttribute[@name=\"${subsettedPropertyName.split('-').1}\"]") -%] - [%- IF subsettedProperty.findvalue("@name") != "" -%] - [%- IF found == "false" %] - // Adjust subsetted properties - [%- found = "true" -%] - [%- END -%] - [%- IF subsettedProperty.findvalue("upperValue/@value") == "*" %] - [% IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]// [% END %]remove${subsettedPropertyName.split('-').1.ucfirst}([%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]/* <derived-code> */[% ELSE %]_${qtAttribute}[% END %]); - [%- END -%] - [%- END %] - [%- END %] -[%- IF found == "true" %] -[% END %] - [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %] - // <derived-code> - [%- ELSE %] - _${qtAttribute} = ${qtAttribute}; - [%- END %] - [%- found = "false" -%] - [%- FOREACH subsettedPropertyName = attribute.findvalue("@subsettedProperty").split(" ") -%] - [%- SET subsettedProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${subsettedPropertyName.split('-').0}\"]/ownedAttribute[@name=\"${subsettedPropertyName.split('-').1}\"]") -%] - [%- IF subsettedProperty.findvalue("@name") != "" -%] - [%- IF found == "false" %] - - // Adjust subsetted properties - [%- found = "true" -%] - [%- END -%] - [%- IF subsettedProperty.findvalue("upperValue/@value") == "*" %] - if (${qtAttribute}) { - add${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute}); - } - [%- ELSE %] - set${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute}); - [%- END -%] - [%- END %] - [%- END %] - } -} - [%- END %] -[%- END %] -[%- FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%] -[%- IF loop.first %] - -// OPERATIONS -[%- END %] -[%- SET operationName = operation.findvalue("@name") -%] - -[%- SET returnType = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']")) %] - -${returnType}${namespace}${className}::${operationName}( - [% SET parameters = operation.findnodes("ownedParameter[@direction!='return']") -%] - [%- FOREACH parameter = parameters -%] - [%- QT_TYPE(namespace, parameter) -%] -${parameter.findvalue("@name")} - [%- IF !loop.last %], [% END -%] - [%- END -%] -)[% IF operation.findvalue("@isQuery") == "true" %] const[% END %] -{ - qWarning("${namespace}${className}::${operationName}(): to be implemented (operation)"); - - [%- FOREACH parameter = parameters %] - Q_UNUSED(${parameter.findvalue("@name")}); - [%- END %] - [%- IF returnType.match('\*$') %] - return 0; - [%- ELSE %] - return ${returnType}(); - [%- END %] -} -[%- END %] - diff --git a/scripts/templates/class_p.h b/scripts/templates/class_p.h deleted file mode 100644 index 7ec0ec53..00000000 --- a/scripts/templates/class_p.h +++ /dev/null @@ -1,130 +0,0 @@ -[%- PROCESS common.tmpl -%] -/**************************************************************************** -** -** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt${namespace} module of the Qt Toolkit. -** -** \$QT_BEGIN_LICENSE:LGPL\$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** \$QT_END_LICENSE\$ -** -****************************************************************************/ -#ifndef ${namespace.upper}${className.upper}_H -#define ${namespace.upper}${className.upper}_H - -#include <Qt${namespace}/Qt${namespace}Global> -[% superclasses = [] -%] -[%- SET generalization = class.findnodes("generalization") -%] -[%- FOREACH superclass IN generalization -%] -[% SET superclassName = superclass.findvalue("@general") %] -#include "private/${namespace.lower}${superclassName.lower}_p.h" -[%- superclasses.push("${namespace}${superclassName}") -%] -[%- IF loop.last %] -[% END -%] -[%- END -%] - -#include <QtCore/QSet> -#include <QtCore/QList> -#include <QtCore/QString> - -[%- SET useNamespace = 'false' -%] -[%- forwards = [] -%] -[%- FOREACH forward = class.findnodes("ownedAttribute[@type] | ownedOperation/ownedParameter[@type]") -%] -[%- SET forwardName = forward.findvalue('@type') -%] -[%- IF xmi.findnodes("//packagedElement[@xmi:type='uml:Enumeration' and @name='$forwardName']").findvalue("@name") != "" -%] - [%- SET useNamespace = 'true' -%] -[%- ELSE -%] -[%- IF forwardName != className && superclasses.grep("^${namespace}${forwardName}\$").size == 0 -%][%- forwards.push("${namespace}${forwardName}") -%][%- END -%] -[%- END -%] -[%- END -%] -[%- IF useNamespace == 'true' %] -#include <Qt${namespace}/Qt${namespace}Namespace> -[% END -%] -[%- FOREACH forward = forwards.unique.sort %] -class ${forward}; -[%- IF loop.last %] -[% END %] -[%- END -%] - -class Q_${namespace.upper}_EXPORT ${namespace}${className} -[%- FOREACH superclass IN generalization -%] -[%- IF loop.first -%] : [%- END -%] -public ${namespace}${superclass.findvalue("@general")} -[%- IF !loop.last %], [% END -%] -[%- END %] -{ -public: - Q_DECL_HIDDEN explicit ${namespace}${className}(); -[%- FOREACH attribute = class.findnodes("ownedAttribute") -%] - [%- IF loop.first %] - - // Owned attributes - [%- END -%] - [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] - [%- SET readOnly = attribute.findvalue("@isReadOnly") -%] - [%- SET qtType = QT_TYPE(namespace, attribute) %] - [% IF qtType.match("QList|QSet") %]const [% END %]${qtType}${qtAttribute}() const; - [%- SET attributeName = attribute.findvalue("@name").ucfirst -%] - [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" %] - [% IF readOnly == "true" %]Q_DECL_HIDDEN [% END %]void add${attributeName}([% qtType.remove("QSet<").remove("QList<").replace("> ", " ").replace('\* $', '*') %]${qtAttribute}); - [% IF readOnly == "true" %]Q_DECL_HIDDEN [% END %]void remove${attributeName}([% qtType.remove("QSet<").remove("QList<").replace("> ", " ").replace('\* $', '*') %]${qtAttribute}); - [%- ELSE %] - [% IF readOnly == "true" %]Q_DECL_HIDDEN [% END %]void set${attributeName.remove("^Is")}(${qtType}${qtAttribute}); - [%- 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") -%] - [% QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']")) -%] -${operationName}( - [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] - [%- QT_TYPE(namespace, parameter) -%] -${parameter.findvalue("@name")} - [%- IF !loop.last %], [% END -%] - [%- END -%] -)[% IF operation.findvalue("@isQuery") == "true" %] const[% END %]; -[%- END %] - -protected: -[%- FOREACH attribute = class.findnodes("ownedAttribute[(@isDerived=\"false\" or not(@isDerived)) or (@isDerivedUnion and @isDerivedUnion=\"true\")]") %] - [% QT_TYPE(namespace, attribute) -%]_[%- QT_ATTRIBUTE(attribute) %]; -[%- END %] -}; - -#endif // ${namespace.upper}${className.upper}_H - diff --git a/scripts/templates/common.tmpl b/scripts/templates/common.tmpl index a218b92a..96d7b63c 100644 --- a/scripts/templates/common.tmpl +++ b/scripts/templates/common.tmpl @@ -8,7 +8,7 @@ "Real" = "double" }; -%] -[%- MACRO QT_TYPE(namespace, attribute, internal) BLOCK -%] +[%- MACRO QT_TYPE(namespace, attribute, external) BLOCK -%] [%- SET multiplicity = attribute.findnodes("upperValue").findvalue("@value") -%] [%- SET isUnique = attribute.findvalue("@isUnique") -%] [%- SET isOrdered = attribute.findvalue("@isOrdered") -%] @@ -18,7 +18,7 @@ [%- IF xmi.findnodes("//packagedElement[@xmi:type='uml:Enumeration' and @name='$attributeType']").findvalue("@name") != "" -%] Qt${namespace}::${attributeType} [%- ELSE -%] -[% IF internal == "false" %]Q[% END %]${namespace}${attributeType} * +[% IF external == "false" %]QObject *[% ELSE %]Q${namespace}${attributeType} *[% END %] [%- END -%] [%- ELSE -%] ${uml2qt_type.item(attribute.findnodes("type").findvalue("@href").split("#").last)}[%- IF multiplicity != "*" %] [% END -%] @@ -173,26 +173,24 @@ ${parameter.findvalue("@name")} [%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 -%] [%- 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 -%] + [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] + void [%- IF readOnly == "true" -%]Q_DECL_HIDDEN [% END %]add${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*') %]${qtAttribute}); + void [%- IF readOnly == "true" -%]Q_DECL_HIDDEN [% END %]remove${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*') %]${qtAttribute}); + [%- ELSE %] + void [%- IF readOnly == "true" -%]Q_DECL_HIDDEN [% END %]add${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "")}${qtAttribute}); + void [%- IF readOnly == "true" -%]Q_DECL_HIDDEN [% END %]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}); + [%- IF qtType.match('QList|QSet') %] + void [%- IF readOnly == "true" -%]Q_DECL_HIDDEN [% END %]set${attributeName}(${qtType}${qtAttribute}); + [%- ELSIF qtType.match('\*$') %] + void [%- IF readOnly == "true" -%]Q_DECL_HIDDEN [% END %]set${attributeName}(${qtType}${qtAttribute} = 0); + [%- ELSE %] + void [%- IF readOnly == "true" -%]Q_DECL_HIDDEN [% END %]set${attributeName.remove("^Is")}(${qtType}${qtAttribute}); + [%- END -%] [%- END -%] - [%- END -%] - [%- END %] [%- END %] [%- END -%] [%- MACRO GENERATE_CPP_ATTRIBUTES(originalClassName, class, visitedClasses, redefinedProperties) BLOCK -%] @@ -213,38 +211,21 @@ ${parameter.findvalue("@name")} [%- SET found = "true" -%] [% END -%] -[%- SET documentation = attribute.findvalue("ownedComment/body/text()") -%] -[%- IF documentation != "" %] -/*! - ${documentation} - */ -[%- END -%] [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] + [%- SET originalQtType = QT_TYPE(namespace, attribute, "true") -%] [%- SET derived = attribute.findvalue("@isDerived") -%] [%- SET derivedUnion = attribute.findvalue("@isDerivedUnion") %] -[% IF qtType.match("QList|QSet") %]const [% END %]${qtType}Q${namespace}${originalClassName}::${qtAttribute}() const +[% IF qtType.match("QList|QSet") %]const [% END %]${qtType}Q${namespace}${originalClassName}Object::${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 -%] + ${qtType}[% IF qtType.match("QList") %]list[% ELSE %]set[% END %]; + foreach (Q${originalQtType.remove("QList<").remove("QSet<").remove(">").trim.remove("^Q")}element, qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->${qtAttribute}()) + [% IF qtType.match("QList") %]list[% ELSE %]set[% END %].[% IF qtType.match("QList") %]append[% ELSE %]insert[% END %](element->asQObject()); + return [% IF qtType.match("QList") %]list[% ELSE %]set[% 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 -%] + return qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->${qtAttribute}()->asQObject(); [%- ELSE %] - [%- IF derived == "true" && (derivedUnion == "" || derivedUnion == "false") %] - return ${namespace}${className}::${qtAttribute}(); - [%- ELSE %] - return _${qtAttribute}; - [%- END -%] + return qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->${qtAttribute}(); [%- END %] } @@ -271,14 +252,9 @@ ${parameter.findvalue("@name")} [% SET operationName = operation.findvalue("@name") -%] [%- NEXT IF redefinedOperations.grep("^${className}-${operationName}$").size > 0 -%] [%- SET return = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']"), "false") %] -[%- SET documentation = operation.findvalue("ownedComment/body/text()") -%] -[%- IF documentation != "" %] -/*! - ${documentation} - */ -[%- END %] +[%- SET originalReturn = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']"), "true") %] [% return -%] -Q${namespace}${originalClassName}::${operationName}( +Q${namespace}${originalClassName}Object::${operationName}( [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] [%- QT_TYPE(namespace, parameter, "false") -%] ${parameter.findvalue("@name")} @@ -286,32 +262,51 @@ ${parameter.findvalue("@name")} [%- 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']") -%] + [%- IF QT_TYPE(namespace, parameter, "true").match("QList|QSet") %] + ${QT_TYPE(namespace, parameter, "true")}${parameter.findvalue("@name")}Converted; + foreach (QObject *object, ${parameter.findvalue("@name")}) + ${parameter.findvalue("@name")}Converted.[% IF QT_TYPE(namespace, parameter, "true").match("QList") %]append[% ELSE %]insert[% END %](qmodelingobjectproperty_cast<${QT_TYPE(namespace, parameter, "true").remove("QList<").remove("QSet<").remove(">").trim}>(object)); + [%- END -%] + [%- END -%] + [%- IF return.match("QList|QSet") && return.match('\*') %] + ${return}[% IF qtType.match("QList") %]list[% ELSE %]set[% END %]; + foreach (${originalReturn.remove("QList<").remove("QSet<").remove(">").trim}element, qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->${operationName}( + [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] + [%- qtType = QT_TYPE(namespace, parameter, "true") -%] + [%- IF qtType.match('QList|QSet') -%] +${parameter.findvalue("@name")}Converted + [%- ELSIF qtType.match('\*$') -%] +qmodelingobjectproperty_cast<${qtType.remove("QList<").remove("QSet<").remove(">")}>(${parameter.findvalue("@name")}) + [%- ELSE -%] ${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 -%] + [%- END -%] + [%- IF !loop.last %], [% END -%] + [%- END -%])) + [% IF qtType.match("QList") %]list[% ELSE %]set[% END %].[% IF return.match("QList") %]append[% ELSE %]insert[% END %](element->asQObject()); + return [% IF qtType.match("QList") %]list[% ELSE %]set[% END %]; + [%- ELSIF !return.match("QList|QSet") && return.match('\*$') %] + return qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->${operationName}( + [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] + [%- qtType = QT_TYPE(namespace, parameter, "true") -%] + [%- IF qtType.match('\*$') -%] +qmodelingobjectproperty_cast<${qtType.remove("QList<").remove("QSet<").remove(">")}>(${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; + [%- END -%] + [%- IF !loop.last %], [% END -%] + [%- END -%])->asQObject(); [%- ELSE %] - return ${namespace}${className}::${operationName}( - [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] + return qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->${operationName}( + [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] + [%- qtType = QT_TYPE(namespace, parameter, "true") -%] + [%- IF qtType.match('\*$') -%] +qmodelingobjectproperty_cast<${qtType.remove("QList<").remove("QSet<").remove(">")}>(${parameter.findvalue("@name")}) + [%- ELSE -%] ${parameter.findvalue("@name")} - [%- IF !loop.last %], [% END -%] - [%- END -%]); + [%- END -%] + [%- IF !loop.last %], [% END -%] + [%- END -%]); [%- END %] } @@ -337,50 +332,48 @@ ${parameter.findvalue("@name")} [%- SET found = "true" -%] [% END -%] - [%- SET readOnly = attribute.findvalue("@isReadOnly") %] - [%- IF readOnly == "false" || readOnly == "" -%] [%- SET attributeName = attribute.findvalue("@name").ucfirst -%] [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] + [%- SET originalQtType = QT_TYPE(namespace, attribute, "true") -%] [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" -%] - [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] -void Q${namespace}${originalClassName}::add${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*').remove('^Q') %]${qtAttribute}) - [%- ELSE %] -void Q${namespace}${originalClassName}::add${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "")} ${qtAttribute}) - [%- END %] + [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] +void Q${namespace}${originalClassName}Object::add${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*') %]${qtAttribute}) + [%- ELSE %] +void Q${namespace}${originalClassName}Object::add${attributeName}(${originalQtType.remove("QSet<").remove("QList<").replace(">", "")} ${qtAttribute}) + [%- END %] { - ${namespace}${className}::add${attributeName}(${qtAttribute}); + [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] + qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->add${attributeName}(qmodelingobjectproperty_cast<${originalQtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*')}>(${qtAttribute})); + [%- ELSE %] + qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->add${attributeName}(${qtAttribute}); + [%- END %] } [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] -void Q${namespace}${originalClassName}::remove${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*').remove('^Q') %]${qtAttribute}) +void Q${namespace}${originalClassName}Object::remove${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*') %]${qtAttribute}) [%- ELSE %] -void Q${namespace}${originalClassName}::remove${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "")} ${qtAttribute}) +void Q${namespace}${originalClassName}Object::remove${attributeName}(${originalQtType.remove("QSet<").remove("QList<").replace(">", "")} ${qtAttribute}) [%- END %] { - ${namespace}${className}::remove${attributeName}(${qtAttribute}); -} - - [%- ELSE -%] - [%- IF qtType.match('QList|QSet') %] -void Q${namespace}${originalClassName}::set${attributeName.remove("^Is")}(${qtType.remove('^Q')}${qtAttribute}) -{ - ${namespace}${className}::set${attributeName.remove("^Is")}(${qtAttribute}); + [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] + qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->remove${attributeName}(qmodelingobjectproperty_cast<${originalQtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*')}>(${qtAttribute})); + [%- ELSE %] + qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->remove${attributeName}(${qtAttribute}); + [%- END %] } [%- ELSIF qtType.match('\*$') %] -void Q${namespace}${originalClassName}::set${attributeName.remove("^Is")}(${qtType}${qtAttribute}) +void Q${namespace}${originalClassName}Object::set${attributeName}(${qtType}${qtAttribute}) { - ${namespace}${className}::set${attributeName.remove("^Is")}(${qtAttribute}); + qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->set${attributeName}(qmodelingobjectproperty_cast<${originalQtType}>(${qtAttribute})); } [%- ELSE %] -void Q${namespace}${originalClassName}::set${attributeName.remove("^Is")}(${qtType}${qtAttribute}) +void Q${namespace}${originalClassName}Object::set${attributeName.remove("^Is")}(${qtType}${qtAttribute}) { - ${namespace}${className}::set${attributeName.remove("^Is")}(${qtAttribute}); + qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->set${attributeName.remove("^Is")}(${qtAttribute}); } -[% END -%] - [%- END -%] - [%- END %] + [% END -%] [%- IF loop.last %] [% END -%] [%- END %] diff --git a/scripts/templates/module.pri b/scripts/templates/module.pri index 88876e4b..12fe0903 100644 --- a/scripts/templates/module.pri +++ b/scripts/templates/module.pri @@ -9,14 +9,19 @@ HEADERS += \ PRIVATE_HEADERS += [%- FOREACH class = xmi.findnodes('//packagedElement[@xmi:type=\'uml:Class\']') -%] +[%- IF class.findvalue("@isAbstract") != "true" -%] \ - internal/${namespace.lower}${class.findvalue('@name').lower}_p.h + qobjects/q${namespace.lower}${class.findvalue('@name').lower}object_p.h +[%- END -%] [%- END %] SOURCES += \ qt${namespace.lower}namespace.cpp [%- FOREACH class = xmi.findnodes('//packagedElement[@xmi:type=\'uml:Class\']') -%] +[%- IF class.findvalue("@isAbstract") != "true" -%] + \ + qobjects/q${namespace.lower}${class.findvalue('@name').lower}object.cpp +[%- END -%] \ - internal/${namespace.lower}${class.findvalue('@name').lower}.cpp \ q${namespace.lower}${class.findvalue('@name').lower}.cpp [%- END %] diff --git a/scripts/templates/module.pro b/scripts/templates/module.pro index eea9495e..4b39de97 100644 --- a/scripts/templates/module.pro +++ b/scripts/templates/module.pro @@ -8,3 +8,5 @@ QMAKE_DOCS = [%- GET '$$PWD' -%]/doc/qt${namespace.lower}.qdocconf load(qt_module) include(${namespace.lower}.pri) + +HEADERS += [%- GET '$$PUBLIC_HEADERS' -%] [% GET '$$PRIVATE_HEADERS' -%] diff --git a/scripts/templates/qclass.cpp b/scripts/templates/qclass.cpp index 183c9e1f..cce4513c 100644 --- a/scripts/templates/qclass.cpp +++ b/scripts/templates/qclass.cpp @@ -40,43 +40,354 @@ ** ****************************************************************************/ #include "q${namespace.lower}${className.lower}.h" +[%- IF class.findvalue("@isAbstract") != "true" %] -[% SET useNamespace = 'false' -%] +#include "private/q${namespace.lower}${className.lower}object_p.h" +[%- END -%] + +[%- superclasses = [] -%] +[%- SET generalization = class.findnodes("generalization") -%] +[%- FOREACH superclass IN generalization -%] +[%- superclasses.push("${namespace}${superclass.findvalue('@general')}") -%] +[%- END -%] [%- forwards = [] -%] -[%- visitedClasses = [] -%] -[%- GENERATE_FWD_DECLARATIONS(class, visitedClasses, forwards, useNamespace) -%] -[%- FOREACH forward = forwards.unique.sort -%] -#include <Qt${namespace}/${forward}> -[% IF loop.last %] -[% END -%] +[%- FOREACH forward = class.findnodes("ownedAttribute[@type] | ownedOperation/ownedParameter[@type]") -%] +[%- SET forwardName = forward.findvalue('@type') -%] +[%- IF xmi.findnodes("//packagedElement[@xmi:type='uml:Enumeration' and @name='$forwardName']").findvalue("@name") == "" -%] +[%- IF forwardName != className && superclasses.grep("^${namespace}${forwardName}\$").size == 0 -%][%- forwards.push("${namespace}${forwardName}") -%][%- END -%] +[%- END -%] [%- END -%] -QT_BEGIN_NAMESPACE +[%- FOREACH forward = forwards.unique.sort -%] +[%- IF loop.first %] +[% END %] +#include <Qt${namespace}/Q$${forward}> +[%- END %] /*! - \class ${namespace}${className} + \class Q${namespace}${className} \inmodule Qt${namespace} \brief ${class.findvalue("ownedComment/body/text()")} */ +Q${namespace}${className}::Q${namespace}${className}([%- IF class.findvalue("@isAbstract") != "true" %]bool createQObject[% END %]) +[%- SET found = "false" -%] +[%- FOREACH superclass IN generalization -%] +[%- SET superclassName = superclass.findvalue('@general') -%] +[%- IF xmi.findvalue("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${superclassName}\"]/@isAbstract") != "true" -%] + [%- IF found == "false" %] : +[% SET found = "true" -%] + [%- ELSE %], +[% END -%] + Q${namespace}${superclassName}(false) +[%- END -%] +[%- END -%] +[%- FOREACH attribute = class.findnodes("ownedAttribute[(@isDerived=\"false\" or not(@isDerived)) or (@isDerivedUnion and @isDerivedUnion=\"true\")]") -%] + [%- SET defaultType = attribute.findvalue("defaultValue/@xmi:type") -%] + [%- SET type = QT_TYPE(namespace, attribute) -%] + [%- IF defaultType == "uml:LiteralBoolean" || defaultType == "uml:InstanceValue" || defaultType == "uml:LiteralInteger" || defaultType == "uml:LiteralUnlimitedNatural" || type.match('\*$') -%] + [%- IF found == "false" %] : +[% SET found = "true" -%] + [%- ELSE %], +[% END -%] + [%- IF defaultType == "uml:LiteralBoolean" -%] + [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%] + [%- IF defaultValue != "" -%] + _[% QT_ATTRIBUTE(attribute) %](${defaultValue}) + [%- ELSE -%] + _[% QT_ATTRIBUTE(attribute) %](false) + [%- END -%] + [%- ELSIF defaultType == "uml:InstanceValue" -%] + [%- SET defaultInstance = attribute.findvalue("defaultValue/@instance") -%] + _[% QT_ATTRIBUTE(attribute) %](Qt${namespace}::${defaultInstance.split("-").0}${defaultInstance.split("-").1.ucfirst}) + [%- ELSIF defaultType == "uml:LiteralInteger" -%] + [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%] + [%- IF defaultValue != "" -%] + _[% QT_ATTRIBUTE(attribute) %](${defaultValue}) + [%- ELSE -%] + _[% QT_ATTRIBUTE(attribute) %](0) + [%- END -%] + [%- ELSIF defaultType == "uml:LiteralUnlimitedNatural" -%] + [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%] + [%- IF defaultValue != "" -%] + _[% QT_ATTRIBUTE(attribute) %](${defaultValue}) + [%- ELSE -%] + _[% QT_ATTRIBUTE(attribute) %](0) + [%- END -%] + [%- ELSIF type.match('\*$') -%] + _[% QT_ATTRIBUTE(attribute) %](0) + [%- END -%] + [%- END -%] +[%- END %] +{ +[%- IF class.findvalue("@isAbstract") != "true" %] + if (createQObject) + _qObject = new Q${namespace}${className}Object(this); +[%- END %] +} + +Q${namespace}${className}::~Q${namespace}${className}() +{ +[%- IF class.findvalue("@isAbstract") != "true" %] + if (!deletingFromQObject) { + _qObject->setProperty("deletingFromModelingObject", true); + delete _qObject; + } +[%- END %] +} +[%- FOREACH attribute = class.findnodes("ownedAttribute") %] +[%- IF loop.first %] + +// OWNED ATTRIBUTES +[%- END %] + +[%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] +[%- SET qtType = QT_TYPE(namespace, attribute) -%] +[%- SET readOnly = attribute.findvalue("@isReadOnly") -%] +[%- SET derived = attribute.findvalue("@isDerived") -%] +[%- SET derivedUnion = attribute.findvalue("@isDerivedUnion") -%] +[%- SET association = attribute.findvalue("@association") -%] +[%- SET documentation = attribute.findvalue("ownedComment/body/text()") -%] +[%- IF documentation != "" %] +/*! + ${documentation} + */ +[%- END %] +[% IF qtType.match("QList|QSet") %]const [% END %]${qtType} +Q${namespace}${className}::${qtAttribute}() const +{ + // This is a [% IF readOnly == "" || readOnly == "false" %]read-write[% ELSE %]read-only[% END %][% IF derived == "true" %] derived[% END %][% IF derivedUnion == "true" %] union[% END %] [% IF association != "" %]association end[% ELSE %]property[% END %] + + [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %] + qWarning("${namespace}${className}::${qtAttribute}(): to be implemented (this is a derived [% IF association != "" %]association end[% ELSE %]property[% END %])"); + + [%- IF qtType.match('\*$') %] + return 0; + [%- ELSE %] + return ${qtType.trim}(); + [%- END %] + [%- ELSE %] + return _${qtAttribute}; + [%- END %] +} + [%- SET attributeName = attribute.findvalue("@name").ucfirst %] + [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" %] -Q${namespace}${className}::Q${namespace}${className}(QObject *parent) : - QObject(parent) +void Q${namespace}${className}::add${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*')}${qtAttribute}) { + // This is a [% IF readOnly == "" || readOnly == "false" %]read-write[% ELSE %]read-only[% END %][% IF derived == "true" %] derived[% END %][% IF derivedUnion == "true" %] union[% END %] [% IF association != "" %]association end[% ELSE %]property[% END %] + + [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %] + qWarning("${namespace}${className}::${qtAttribute}(): to be implemented (this is a derived [% IF association != "" %]association end[% ELSE %]property[% END %])"); + Q_UNUSED(${qtAttribute}); + + if (false /* <derivedexclusion-criteria> */) { + // <derived-code> + [%- ELSE %] + if (!_${qtAttribute}.contains(${qtAttribute})) { + _${qtAttribute}.[% IF qtType.match("QList") %]append[% ELSE %]insert[% END %](${qtAttribute}); + [%- IF qtType.match('\*') %] + if (${qtAttribute}->asQObject() && this->asQObject()) + QObject::connect(${qtAttribute}->asQObject(), SIGNAL(destroyed(QObject*)), this->asQObject(), SLOT(remove${attributeName}(QObject *))); + [%- IF attribute.findvalue("@aggregation") == "composite" %] + ${qtAttribute}->asQObject()->setParent(this->asQObject()); + [%- END -%] + [%- END %] + [%- END %] + [%- found = "false" -%] + [%- FOREACH subsettedPropertyName = attribute.findvalue("@subsettedProperty").split(" ") -%] + [%- SET subsettedProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${subsettedPropertyName.split('-').0}\"]/ownedAttribute[@name=\"${subsettedPropertyName.split('-').1}\"]") -%] + [%- IF subsettedProperty.findvalue("@name") != "" -%] + [%- IF found == "false" %] + + // Adjust subsetted properties + [%- found = "true" -%] + [%- END -%] + [%- IF subsettedProperty.findvalue("upperValue/@value") == "*" %] + add${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute}); + [%- ELSE %] + set${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute}); + [%- END -%] + [%- END %] + [%- END %] + [%- IF association != "" -%] + [%- found = "false" -%] + [%- FOREACH memberEnd = xmi.findvalue("//packagedElement[@xmi:type=\"uml:Association\" and @name=\"${association}\"]/@memberEnd").split(' ') -%] + [%- NEXT IF memberEnd.split('-').0 == className -%] + [%- SET oppositeProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${memberEnd.split('-').0}\"]/ownedAttribute[@name=\"${memberEnd.split('-').1}\"]") -%] + [%- IF oppositeProperty.findvalue("@name") != "" -%] + [%- IF found == "false" %] + + // Adjust opposite properties + [%- found = "true" -%] + [%- END %] + if (${qtAttribute}) { + [%- IF oppositeProperty.findvalue("upperValue/@value") == "*" %] + ${qtAttribute}->add${memberEnd.split('-').1.ucfirst}(this); + [%- ELSE %] + ${qtAttribute}->set${memberEnd.split('-').1.ucfirst}(this); + [%- END %] + } + [%- END %] + [%- END %] + [%- END %] + } +} + +void Q${namespace}${className}::remove${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*')}${qtAttribute}) +{ + // This is a [% IF readOnly == "" || readOnly == "false" %]read-write[% ELSE %]read-only[% END %][% IF derived == "true" %] derived[% END %][% IF derivedUnion == "true" %] union[% END %] [% IF association != "" %]association end[% ELSE %]property[% END %] + + [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %] + qWarning("${namespace}${className}::${qtAttribute}(): to be implemented (this is a derived [% IF association != "" %]association end[% ELSE %]property[% END %])"); + Q_UNUSED(${qtAttribute}); + + if (false /* <derivedexclusion-criteria> */) { + // <derived-code> + [%- ELSE %] + if (_${qtAttribute}.contains(${qtAttribute})) { + _${qtAttribute}.[% IF qtType.match("QList") %]removeAll[% ELSE %]remove[% END %](${qtAttribute}); + [%- IF attribute.findvalue("@aggregation") == "composite" %] + if (${qtAttribute}->asQObject()) + ${qtAttribute}->asQObject()->setParent(0); + [%- END -%] + [%- END %] + [%- found = "false" -%] + [%- FOREACH subsettedPropertyName = attribute.findvalue("@subsettedProperty").split(" ") -%] + [%- SET subsettedProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${subsettedPropertyName.split('-').0}\"]/ownedAttribute[@name=\"${subsettedPropertyName.split('-').1}\"]") -%] + [%- IF subsettedProperty.findvalue("@name") != "" -%] + [%- IF found == "false" %] + + // Adjust subsetted properties + [%- found = "true" -%] + [%- END -%] + [%- IF subsettedProperty.findvalue("upperValue/@value") == "*" %] + remove${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute}); + [%- ELSE %] + set${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute}); + [%- END -%] + [%- END %] + [%- END %] + [%- IF association != "" -%] + [%- found = "false" -%] + [%- FOREACH memberEnd = xmi.findvalue("//packagedElement[@xmi:type=\"uml:Association\" and @name=\"${association}\"]/@memberEnd").split(' ') -%] + [%- NEXT IF memberEnd.split('-').0 == className -%] + [%- SET oppositeProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${memberEnd.split('-').0}\"]/ownedAttribute[@name=\"${memberEnd.split('-').1}\"]") -%] + [%- IF oppositeProperty.findvalue("@name") != "" -%] + [%- IF found == "false" %] + + // Adjust opposite properties + [%- found = "true" -%] + [%- END %] + if (${qtAttribute}) { + [%- IF oppositeProperty.findvalue("upperValue/@value") == "*" %] + ${qtAttribute}->remove${memberEnd.split('-').1.ucfirst}(this); + [%- ELSE %] + ${qtAttribute}->set${memberEnd.split('-').1.ucfirst}(0); + [%- END %] + } + [%- END %] + [%- END %] + [%- END %] + } +} + [%- ELSE %] + +void Q${namespace}${className}::set${attributeName.remove("^Is")}([% IF !qtType.match('\*$') %]${qtType.trim} [% ELSE %]${qtType}[% END %]${qtAttribute}) +{ + // This is a [% IF readOnly == "" || readOnly == "false" %]read-write[% ELSE %]read-only[% END %][% IF derived == "true" %] derived[% END %][% IF derivedUnion == "true" %] union[% END %] [% IF association != "" %]association end[% ELSE %]property[% END %] + + [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %] + qWarning("${namespace}${className}::${qtAttribute}(): to be implemented (this is a derived [% IF association != "" %]association end[% ELSE %]property[% END %])"); + Q_UNUSED(${qtAttribute}); + + if (false /* <derivedexclusion-criteria> */) { + [%- ELSE %] + if (_${qtAttribute} != ${qtAttribute}) { + [%- END %] + [%- found = "false" -%] + [%- FOREACH subsettedPropertyName = attribute.findvalue("@subsettedProperty").split(" ") -%] + [%- SET subsettedProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${subsettedPropertyName.split('-').0}\"]/ownedAttribute[@name=\"${subsettedPropertyName.split('-').1}\"]") -%] + [%- IF subsettedProperty.findvalue("@name") != "" -%] + [%- IF found == "false" %] + // Adjust subsetted properties + [%- found = "true" -%] + [%- END -%] + [%- IF subsettedProperty.findvalue("upperValue/@value") == "*" %] + [% IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]// [% END %]remove${subsettedPropertyName.split('-').1.ucfirst}([%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]/* <derived-code> */[% ELSE %]_${qtAttribute}[% END %]); + [%- END -%] + [%- END %] + [%- END %] +[%- IF found == "true" %] +[% END %] + [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %] + // <derived-code> + [%- ELSE %] + _${qtAttribute} = ${qtAttribute}; + [%- IF qtType.match('\*') %] + if (${qtAttribute}->asQObject() && this->asQObject()) + QObject::connect(${qtAttribute}->asQObject(), SIGNAL(destroyed()), this->asQObject(), SLOT(set${attributeName}())); + [%- IF attribute.findvalue("@aggregation") == "composite" %] + ${qtAttribute}->asQObject()->setParent(this->asQObject()); + [%- END -%] + [%- END %] + [%- END %] + [%- found = "false" -%] + [%- FOREACH subsettedPropertyName = attribute.findvalue("@subsettedProperty").split(" ") -%] + [%- SET subsettedProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${subsettedPropertyName.split('-').0}\"]/ownedAttribute[@name=\"${subsettedPropertyName.split('-').1}\"]") -%] + [%- IF subsettedProperty.findvalue("@name") != "" -%] + [%- IF found == "false" %] + + // Adjust subsetted properties + [%- found = "true" -%] + [%- END -%] + [%- IF subsettedProperty.findvalue("upperValue/@value") == "*" %] + if (${qtAttribute}) { + add${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute}); + } + [%- ELSE %] + set${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute}); + [%- END -%] + [%- END %] + [%- END %] + } } + [%- END %] +[%- END %] +[%- FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%] +[%- IF loop.first %] + +// OPERATIONS +[%- END %] +[%- SET operationName = operation.findvalue("@name") -%] -[%- SET originalClassName = class.findvalue("@name") -%] -[%- visitedClasses = [] -%] -[%- redefinedProperties = [] -%] -[%- POPULATE_REDEFINED_PROPERTIES(class, visitedClasses, redefinedProperties) -%] -[%- visitedClasses = [] %] -[% GENERATE_CPP_ATTRIBUTES(originalClassName, class, visitedClasses, redefinedProperties) -%] -[%- visitedClasses = [] -%] -[%- redefinedOperations = [] -%] -[%- POPULATE_REDEFINED_OPERATIONS(class, visitedClasses, redefinedOperations) -%] -[%- visitedClasses = [] %] -[%- GENERATE_CPP_OPERATIONS(originalClassName, class, visitedClasses, redefinedOperations) -%] -[%- visitedClasses = [] %] -[%- GENERATE_CPP_SLOTS(originalClassName, class, visitedClasses, redefinedProperties) -%] -QT_END_NAMESPACE +[%- SET returnType = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']")) %] + +[%- SET documentation = operation.findvalue("ownedComment/body/text()") -%] +[%- IF documentation != "" %] +/*! + ${documentation} + */ +[%- END %] +${returnType}Q${namespace}${className}::${operationName}( + [%- SET parameters = operation.findnodes("ownedParameter[@direction!='return']") -%] + [%- FOREACH parameter = parameters -%] + [%- QT_TYPE(namespace, parameter) -%] +${parameter.findvalue("@name")} + [%- IF !loop.last %], [% END -%] + [%- END -%] +)[% IF operation.findvalue("@isQuery") == "true" %] const[% END %] +{ + qWarning("${namespace}${className}::${operationName}(): to be implemented (operation)"); + + [%- FOREACH parameter = parameters %] + Q_UNUSED(${parameter.findvalue("@name")}); + [%- END %] + [%- IF returnType.match('\*$') %] + return 0; + [%- ELSE %] + return ${returnType}(); + [%- END %] +} +[%- END %] diff --git a/scripts/templates/qclass.h b/scripts/templates/qclass.h index b40f6ceb..4e736811 100644 --- a/scripts/templates/qclass.h +++ b/scripts/templates/qclass.h @@ -44,55 +44,105 @@ #include <Qt${namespace}/Qt${namespace}Global> -#include <QtCore/QObject> -#include "private/${namespace.lower}${className.lower}_p.h" +[% superclasses = [] -%] +[%- SET generalization = class.findnodes("generalization") -%] +[%- FOREACH superclass IN generalization -%] +[%- SET superclassName = superclass.findvalue("@general") -%] +#include <Qt${namespace}/Q${namespace}${superclassName}> +[% superclasses.push("${namespace}${superclassName}") -%] +[%- IF loop.last %] +[% END -%] +[%- END -%] +[%- IF superclasses.size == 0 -%] +#include <QtModeling/QModelingObject> -[%- useNamespace = [] -%] +[% END -%] +[%- SET useNamespace = 'false' -%] [%- forwards = [] -%] -[%- visitedClasses = [] -%] -[%- GENERATE_FWD_DECLARATIONS(class, visitedClasses, forwards, useNamespace) -%] -[%- IF useNamespace.size > 0 %] +[%- FOREACH forward = class.findnodes("ownedAttribute[@type] | ownedOperation/ownedParameter[@type]") -%] +[%- SET forwardName = forward.findvalue('@type') -%] +[%- IF xmi.findnodes("//packagedElement[@xmi:type='uml:Enumeration' and @name='$forwardName']").findvalue("@name") != "" -%] + [%- SET useNamespace = 'true' -%] +[%- ELSE -%] +[%- IF forwardName != className && superclasses.grep("^${namespace}${forwardName}\$").size == 0 -%][%- forwards.push("${namespace}${forwardName}") -%][%- END -%] +[%- END -%] +[%- END -%] +[%- IF useNamespace == 'true' %] #include <Qt${namespace}/Qt${namespace}Namespace> -[% END %] +[% END -%] + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(Qt${namespace}) -[% FOREACH forward = forwards.unique.sort %] -class ${forward}; + +[%- FOREACH forward = forwards.unique.sort %] +class Q${forward}; [%- IF loop.last %] [% END %] [%- END -%] -class Q_${namespace.upper}_EXPORT Q${namespace}${className} : public QObject, public ${namespace}${className} +class Q_${namespace.upper}_EXPORT Q${namespace}${className} : +[%- FOREACH superclass IN generalization -%] +public Q${namespace}${superclass.findvalue("@general")} +[%- IF !loop.last %], [% END -%] +[%- END -%] +[%- IF superclasses.size == 0 -%] +public QModelingObject +[%- END %] { - Q_OBJECT - [%- visitedClasses = [] -%] - [%- redefinedProperties = [] -%] - [%- POPULATE_REDEFINED_PROPERTIES(class, visitedClasses, redefinedProperties) -%] - [%- visitedClasses = [] -%] - [%- GENERATE_QPROPERTIES(class, visitedClasses, redefinedProperties) %] - public: - [% IF class.findvalue("@isAbstract") == "true" %]Q_DECL_HIDDEN [% ELSE %]Q_INVOKABLE [% END %]explicit Q${namespace}${className}(QObject *parent = 0); -[%- visitedClasses = [] -%] -[%- GENERATE_ATTRIBUTES(class, visitedClasses, redefinedProperties) -%] -[%- visitedClasses = [] -%] -[%- redefinedOperations = [] -%] -[%- POPULATE_REDEFINED_OPERATIONS(class, visitedClasses, redefinedOperations) -%] -[%- visitedClasses = [] -%] -[%- GENERATE_OPERATIONS(class, visitedClasses, redefinedOperations) -%] -[%- visitedClasses = [] %] +[%- IF class.findvalue("@isAbstract") != "true" %] + explicit Q${namespace}${className}(bool createQObject = true); +[%- END %] + virtual ~Q${namespace}${className}(); +[% FOREACH attribute = class.findnodes("ownedAttribute") -%] + [%- IF loop.first %] + // Owned attributes + [%- END -%] + [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] + [%- SET readOnly = attribute.findvalue("@isReadOnly") -%] + [%- SET qtType = QT_TYPE(namespace, attribute) %] + [% IF qtType.match("QList|QSet") %]const [% END %]${qtType}${qtAttribute}() const; + [%- SET attributeName = attribute.findvalue("@name").ucfirst -%] + [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" %] + [% IF readOnly == "true" %]Q_DECL_HIDDEN [% END %]void add${attributeName}([% qtType.remove("QSet<").remove("QList<").replace("> ", " ").replace('\* $', '*') %]${qtAttribute}); + [% IF readOnly == "true" %]Q_DECL_HIDDEN [% END %]void remove${attributeName}([% qtType.remove("QSet<").remove("QList<").replace("> ", " ").replace('\* $', '*') %]${qtAttribute}); + [%- ELSE %] + [% IF readOnly == "true" %]Q_DECL_HIDDEN [% END %]void set${attributeName.remove("^Is")}(${qtType}${qtAttribute}); + [%- 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") -%] + [% QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']")) -%] +${operationName}( + [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] + [%- QT_TYPE(namespace, parameter) -%] +${parameter.findvalue("@name")} + [%- IF !loop.last %], [% END -%] + [%- END -%] +)[% IF operation.findvalue("@isQuery") == "true" %] const[% END %]; +[%- END %] -public Q_SLOTS:[%- GENERATE_SLOTS(class, visitedClasses, redefinedProperties) %] +protected: +[%- IF class.findvalue("@isAbstract") == "true" %] + explicit Q${namespace}${className}(); +[% END -%] +[%- FOREACH attribute = class.findnodes("ownedAttribute[(@isDerived=\"false\" or not(@isDerived)) or (@isDerivedUnion and @isDerivedUnion=\"true\")]") %] + [% QT_TYPE(namespace, attribute) -%]_[%- QT_ATTRIBUTE(attribute) %]; +[%- END %] }; QT_END_NAMESPACE -Q_DECLARE_METATYPE(Q${namespace}${className} *) -Q_DECLARE_METATYPE(QList<Q${namespace}${className} *> *) -Q_DECLARE_METATYPE(QSet<Q${namespace}${className} *> *) +Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(Q${namespace}${className}) *) QT_END_HEADER diff --git a/scripts/templates/qobjectclass.cpp b/scripts/templates/qobjectclass.cpp new file mode 100644 index 00000000..a18284c6 --- /dev/null +++ b/scripts/templates/qobjectclass.cpp @@ -0,0 +1,85 @@ +[%- PROCESS common.tmpl -%] +/**************************************************************************** +** +** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt${namespace} module of the Qt Toolkit. +** +** \$QT_BEGIN_LICENSE:LGPL\$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** \$QT_END_LICENSE\$ +** +****************************************************************************/ +#include "q${namespace.lower}${className.lower}object_p.h" + +#include <Qt${namespace}/Q${namespace}${className}> +[% SET useNamespace = 'false' -%] +[%- forwards = [] -%] +[%- visitedClasses = [] -%] +[%- GENERATE_FWD_DECLARATIONS(class, visitedClasses, forwards, useNamespace) -%] +[%- FOREACH forward = forwards.unique.sort -%] +#include <Qt${namespace}/${forward}> +[% IF loop.last %] +[% END -%] +[%- END -%] +QT_BEGIN_NAMESPACE + +Q${namespace}${className}Object::Q${namespace}${className}Object(Q${namespace}${className} *qModelingObject) +{ + setProperty("modelingObject", QVariant::fromValue(qModelingObject)); +} + +[%- IF class.findvalue("@isAbstract") != "true" %] +Q${namespace}${className}Object::~Q${namespace}${className}Object() +{ + if (!property("deletingFromModelingObject").isValid()) { + qmodelingobjectproperty_cast<Q${namespace}${className} *>(this)->deletingFromQObject = true; + delete qmodelingobjectproperty_cast<QUmlComment *>(this); + } +} + +[%- END %] +[%- SET originalClassName = class.findvalue("@name") -%] +[%- visitedClasses = [] -%] +[%- redefinedProperties = [] -%] +[%- POPULATE_REDEFINED_PROPERTIES(class, visitedClasses, redefinedProperties) -%] +[%- visitedClasses = [] %] +[% GENERATE_CPP_ATTRIBUTES(originalClassName, class, visitedClasses, redefinedProperties) -%] +[%- visitedClasses = [] -%] +[%- redefinedOperations = [] -%] +[%- POPULATE_REDEFINED_OPERATIONS(class, visitedClasses, redefinedOperations) -%] +[%- visitedClasses = [] %] +[%- GENERATE_CPP_OPERATIONS(originalClassName, class, visitedClasses, redefinedOperations) -%] +[%- visitedClasses = [] %] +[%- GENERATE_CPP_SLOTS(originalClassName, class, visitedClasses, redefinedProperties) -%] +QT_END_NAMESPACE + diff --git a/scripts/templates/qobjectclass_p.h b/scripts/templates/qobjectclass_p.h new file mode 100644 index 00000000..e41ac90f --- /dev/null +++ b/scripts/templates/qobjectclass_p.h @@ -0,0 +1,94 @@ +[%- PROCESS common.tmpl -%] +/**************************************************************************** +** +** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt${namespace} module of the Qt Toolkit. +** +** \$QT_BEGIN_LICENSE:LGPL\$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** \$QT_END_LICENSE\$ +** +****************************************************************************/ +#ifndef Q${namespace.upper}${className.upper}OBJECT_H +#define Q${namespace.upper}${className.upper}OBJECT_H + +#include <Qt${namespace}/Qt${namespace}Global> + +#include <QtCore/QObject> +[% useNamespace = [] -%] +[%- forwards = [] -%] +[%- visitedClasses = [] -%] +[%- GENERATE_FWD_DECLARATIONS(class, visitedClasses, forwards, useNamespace) -%] +[%- IF useNamespace.size > 0 %] +#include <Qt${namespace}/Qt${namespace}Namespace> +[% END -%] + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Qt${namespace}) + +class Q${namespace}${className}; +class Q_${namespace.upper}_EXPORT Q${namespace}${className}Object : public QObject +{ + Q_OBJECT + [%- visitedClasses = [] -%] + [%- redefinedProperties = [] -%] + [%- POPULATE_REDEFINED_PROPERTIES(class, visitedClasses, redefinedProperties) -%] + [%- visitedClasses = [] -%] + [%- GENERATE_QPROPERTIES(class, visitedClasses, redefinedProperties) %] + +public: + [% IF class.findvalue("@isAbstract") == "true" %]Q_DECL_HIDDEN [% ELSE %]Q_INVOKABLE [% END %]explicit Q${namespace}${className}Object(Q${namespace}${className} *qModelingObject); + [%- IF class.findvalue("@isAbstract") != "true" %] + virtual ~Q${namespace}${className}Object(); + [%- END %] +[%- visitedClasses = [] -%] +[%- GENERATE_ATTRIBUTES(class, visitedClasses, redefinedProperties) -%] +[%- visitedClasses = [] -%] +[%- redefinedOperations = [] -%] +[%- POPULATE_REDEFINED_OPERATIONS(class, visitedClasses, redefinedOperations) -%] +[%- visitedClasses = [] -%] +[%- GENERATE_OPERATIONS(class, visitedClasses, redefinedOperations) -%] +[%- visitedClasses = [] %] + +public Q_SLOTS:[%- GENERATE_SLOTS(class, visitedClasses, redefinedProperties) %] +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // Q${namespace.upper}${className.upper}OBJECT_H + |