summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSandro S. Andrade <sandroandrade@kde.org>2013-08-25 16:07:06 -0300
committerSandro S. Andrade <sandroandrade@kde.org>2013-08-25 21:06:07 +0200
commit1c770ad764a39ce0ad40913c1c4bd72bd43710a9 (patch)
treee6f7789ee1b007e081c7f45e385135b6e8e37bd2 /scripts
parentea1a2ed03ac0880ef969e01598016de0581fbd41 (diff)
Add handling of derived properties in artifact generation from xmi
Change-Id: I3764f41fd6a727f1a09daed9fc82c9fedf8ba5af Reviewed-by: Sandro S. Andrade <sandroandrade@kde.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/templates/class.cpp91
-rw-r--r--scripts/templates/class.h8
-rw-r--r--scripts/templates/class_p.h2
-rw-r--r--scripts/templates/module.pri16
4 files changed, 88 insertions, 29 deletions
diff --git a/scripts/templates/class.cpp b/scripts/templates/class.cpp
index 001f9bf1..622ba55f 100644
--- a/scripts/templates/class.cpp
+++ b/scripts/templates/class.cpp
@@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE
Q${namespace}${className}Private::Q${namespace}${className}Private()
[%- SET found = "false" -%]
-[%- FOREACH attribute = class.findnodes("ownedAttribute") -%]
+[%- 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('\*$') -%]
@@ -127,40 +127,98 @@ Q${namespace}${className}::Q${namespace}${className}(bool create_d_ptr) :
[%- FOREACH attribute = class.findnodes("ownedAttribute") %]
[%- IF loop.first %]
-// Owned attributes
+// OWNED ATTRIBUTES
[%- END %]
+[%- SET documentation = attribute.findvalue("ownedComment/body/text()") -%]
+[%- IF documentation != "" %]
/*!
- ${attribute.findvalue("ownedComment/body/text()")}
+ ${documentation}
*/
+[%- END %]
[% QT_TYPE(namespace, attribute) -%]
-Q${namespace}${className}::[% QT_ATTRIBUTE(attribute) %]() const
+[%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%]
+[%- SET readOnly = attribute.findvalue("@isReadOnly") -%]
+[%- SET derived = attribute.findvalue("@isDerived") -%]
+[%- SET derivedUnion = attribute.findvalue("@isDerivedUnion") -%]
+[%- SET association = attribute.findvalue("@association") -%]
+Q${namespace}${className}::${qtAttribute}() const
{
- [%- SET qtType = QT_TYPE(namespace, attribute).trim -%]
- [%- IF qtType.match('\*$') %]
+ // 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("Q${namespace}${className}::${qtAttribute}(): to be implemented (this is a derived [% IF association != "" %]association end[% ELSE %]property[% END %])");
+
+ [%- IF QT_TYPE(namespace, attribute).match('\*$') %]
return 0;
[%- ELSE %]
- return [% QT_TYPE(namespace, attribute).trim -%]();
+ return ${QT_TYPE(namespace, attribute).trim}();
+ [%- END %]
+ [%- ELSE %]
+ QM_D(const Q${namespace}${className});
+ return d->${qtAttribute};
[%- END %]
}
[%- SET attributeName = attribute.findvalue("@name").ucfirst %]
[%- IF attribute.findvalue("@isReadOnly") != "true" -%]
[%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" %]
-void Q${namespace}${className}::add${attributeName}([% QT_TYPE(namespace, attribute) %][% QT_ATTRIBUTE(attribute) %])
+void Q${namespace}${className}::add${attributeName}(${QT_TYPE(namespace, attribute).remove("QSet<").remove("QList<").replace("> ", " ").replace('\* $', '*')}${qtAttribute})
{
- Q_UNUSED([% QT_ATTRIBUTE(attribute) %]);
+ // 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("Q${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 %]
+ QM_D(Q${namespace}${className});
+ if (!d->${qtAttribute}.contains(${qtAttribute})) {
+ d->${qtAttribute}.[% IF QT_TYPE(namespace, attribute).match("QList") %]append[% ELSE %]insert[% END %](${qtAttribute});
+ }
+ [%- END %]
}
-void Q${namespace}${className}::remove${attributeName}([% QT_TYPE(namespace, attribute) %][% QT_ATTRIBUTE(attribute) %])
+void Q${namespace}${className}::remove${attributeName}(${QT_TYPE(namespace, attribute).remove("QSet<").remove("QList<").replace("> ", " ").replace('\* $', '*')}${qtAttribute})
{
- Q_UNUSED([% QT_ATTRIBUTE(attribute) %]);
+ // 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("Q${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 %]
+ QM_D(Q${namespace}${className});
+ if (d->${qtAttribute}.contains(${qtAttribute})) {
+ d->${qtAttribute}.[% IF QT_TYPE(namespace, attribute).match("QList") %]removeAll[% ELSE %]remove[% END %](${qtAttribute});
+ }
+ [%- END %]
}
[%- ELSE %]
-void Q${namespace}${className}::set${attributeName.remove("^Is")}([% QT_TYPE(namespace, attribute) %][% QT_ATTRIBUTE(attribute) %])
+void Q${namespace}${className}::set${attributeName.remove("^Is")}(${QT_TYPE(namespace, attribute)}${qtAttribute})
{
- Q_UNUSED([% QT_ATTRIBUTE(attribute) %]);
+ // 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("Q${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 %]
+ QM_D(Q${namespace}${className});
+ if (d->${qtAttribute} != ${qtAttribute}) {
+ d->${qtAttribute} = ${qtAttribute};
+ }
+ [%- END %]
}
[%- END %]
[%- END %]
@@ -168,15 +226,18 @@ void Q${namespace}${className}::set${attributeName.remove("^Is")}([% QT_TYPE(nam
[%- FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%]
[%- IF loop.first %]
-// Operations
+// OPERATIONS
[%- END %]
[%- SET operationName = operation.findvalue("@name") -%]
[%- SET returnType = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']")) %]
+[%- SET documentation = operation.findvalue("ownedComment/body/text()") -%]
+[%- IF documentation != "" %]
/*!
- ${operation.findvalue("ownedComment/body/text()")}
+ ${documentation}
*/
+[%- END %]
${returnType}Q${namespace}${className}::${operationName}(
[%- SET parameters = operation.findnodes("ownedParameter[@direction!='return']") -%]
[%- FOREACH parameter = parameters -%]
diff --git a/scripts/templates/class.h b/scripts/templates/class.h
index 4315ad97..23242b12 100644
--- a/scripts/templates/class.h
+++ b/scripts/templates/class.h
@@ -74,9 +74,7 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Qt${namespace})
-[%- FOREACH forward = forwards.unique.sort -%]
-[%- IF loop.first %]
-[% END %]
+[% FOREACH forward = forwards.unique.sort %]
class ${forward};
[%- IF loop.last %]
[% END %]
@@ -104,8 +102,8 @@ public:
[%- SET attributeName = attribute.findvalue("@name").ucfirst -%]
[%- IF attribute.findvalue("@isReadOnly") != "true" -%]
[%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" %]
- void add${attributeName}([% QT_TYPE(namespace, attribute) %][% QT_ATTRIBUTE(attribute) %]);
- void remove${attributeName}([% QT_TYPE(namespace, attribute) %][% QT_ATTRIBUTE(attribute) %]);
+ void add${attributeName}([% QT_TYPE(namespace, attribute).remove("QSet<").remove("QList<").replace("> ", " ").replace('\* $', '*') %][% QT_ATTRIBUTE(attribute) %]);
+ void remove${attributeName}([% QT_TYPE(namespace, attribute).remove("QSet<").remove("QList<").replace("> ", " ").replace('\* $', '*') %][% QT_ATTRIBUTE(attribute) %]);
[%- ELSE %]
void set${attributeName.remove("^Is")}([% QT_TYPE(namespace, attribute) %][% QT_ATTRIBUTE(attribute) %]);
[%- END %]
diff --git a/scripts/templates/class_p.h b/scripts/templates/class_p.h
index ec2a5015..31e6eb30 100644
--- a/scripts/templates/class_p.h
+++ b/scripts/templates/class_p.h
@@ -73,7 +73,7 @@ public QModelingObjectPrivate
public:
Q${namespace}${className}Private();
-[%- FOREACH attribute = class.findnodes("ownedAttribute") %]
+[%- FOREACH attribute = class.findnodes("ownedAttribute[(@isDerived=\"false\" or not(@isDerived)) or (@isDerivedUnion and @isDerivedUnion=\"true\")]") %]
[% QT_TYPE(namespace, attribute) -%][%- QT_ATTRIBUTE(attribute) %];
[%- END %]
};
diff --git a/scripts/templates/module.pri b/scripts/templates/module.pri
index 50405690..0dd4307a 100644
--- a/scripts/templates/module.pri
+++ b/scripts/templates/module.pri
@@ -1,21 +1,21 @@
[% USE xmi = XML.XPath("$xmi") -%]
-PUBLIC_HEADERS += \
+PUBLIC_HEADERS += \
qt${namespace.lower}global.h \
qt${namespace.lower}namespace.h
[%- FOREACH class = xmi.findnodes('//packagedElement[@xmi:type=\'uml:Class\']') -%]
-\
- q${namespace.lower}${class.findvalue('@name').lower}.h
+ \
+ q${namespace.lower}${class.findvalue('@name').lower}.h
[%- END %]
-PRIVATE_HEADERS +=
+PRIVATE_HEADERS +=
[%- FOREACH class = xmi.findnodes('//packagedElement[@xmi:type=\'uml:Class\']') -%]
-\
- q${namespace.lower}${class.findvalue('@name').lower}_p.h
+ \
+ q${namespace.lower}${class.findvalue('@name').lower}_p.h
[%- END %]
SOURCES += \
qt${namespace.lower}namespace.cpp
[%- FOREACH class = xmi.findnodes('//packagedElement[@xmi:type=\'uml:Class\']') -%]
-\
- q${namespace.lower}${class.findvalue('@name').lower}.cpp
+ \
+ q${namespace.lower}${class.findvalue('@name').lower}.cpp
[%- END %]