summaryrefslogtreecommitdiffstats
path: root/scripts/templates
diff options
context:
space:
mode:
authorSandro S. Andrade <sandroandrade@kde.org>2013-10-07 19:57:57 -0300
committerSandro S. Andrade <sandroandrade@kde.org>2013-10-08 01:01:15 +0200
commitb453dca1261158461363076d3a312c22a51da3de (patch)
tree3d71d5cbf572d6d53aaa6740a9ba93524a86155d /scripts/templates
parent5e4a780b40543fa12d6d9607e3193fb111c5ab84 (diff)
Improve property metadata for XMI serialization
Change-Id: I5a5c4dd61312824c63f6eac73b7170376c2b6bdb Reviewed-by: Sandro S. Andrade <sandroandrade@kde.org>
Diffstat (limited to 'scripts/templates')
-rw-r--r--scripts/templates/common.tmpl35
-rw-r--r--scripts/templates/qclass.cpp26
-rw-r--r--scripts/templates/qclass.h1
3 files changed, 44 insertions, 18 deletions
diff --git a/scripts/templates/common.tmpl b/scripts/templates/common.tmpl
index ba4d8e63..75b1a0b7 100644
--- a/scripts/templates/common.tmpl
+++ b/scripts/templates/common.tmpl
@@ -100,8 +100,8 @@ ${attributeName}
[%- END -%]
[%- END -%]
[%- SET found = "false" -%]
+[%- SET className = class.findvalue("@name") -%]
[%- FOREACH attribute IN class.findnodes("ownedAttribute") -%]
- [%- SET className = class.findvalue("@name") -%]
[%- IF found == "false" %]
// Properties [${className}]
@@ -110,7 +110,7 @@ ${attributeName}
[%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%]
[%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 -%]
[%- SET qtType = QT_TYPE(namespace, attribute, "false") %]
- Q_PROPERTY(${qtType.trim} ${qtAttribute} READ ${PLURALFORM(qtAttribute, attribute)}[% IF attribute.findvalue("@isReadOnly") != "true" and !(attribute.findnodes("upperValue").findvalue("@value") == "*")%] WRITE set${qtAttribute.remove("^is").ucfirst.remove('_$')}[% END %][% IF attribute.findvalue("defaultValue/@xmi:type") != "" %] RESET unset${qtAttribute.remove("^is").ucfirst}[% END %][% IF attribute.findvalue("@isDerived") == "true" and attribute.findvalue("@isDerivedUnion") != "true" %] STORED false[% END %])
+ Q_PROPERTY(${qtType.trim} ${PLURALFORM(qtAttribute, attribute)} READ ${PLURALFORM(qtAttribute, attribute)}[% IF attribute.findvalue("@isReadOnly") != "true" and !(attribute.findnodes("upperValue").findvalue("@value") == "*")%] WRITE set${qtAttribute.remove("^is").ucfirst.remove('_$')}[% END %][% IF attribute.findvalue("defaultValue/@xmi:type") != "" %] RESET unset${qtAttribute.remove("^is").ucfirst}[% END %][% IF attribute.findvalue("@isDerived") == "true" and attribute.findvalue("@isDerivedUnion") != "true" %] STORED false[% END %])
[%- END %]
[%- END -%]
[%- MACRO GENERATE_ATTRIBUTES(class, visitedClasses, redefinedProperties) BLOCK -%]
@@ -123,8 +123,8 @@ ${attributeName}
[%- END -%]
[%- SET attributes = class.findnodes("ownedAttribute") -%]
[%- SET found = "false" -%]
+[%- SET className = class.findvalue("@name") -%]
[%- FOREACH attribute IN attributes -%]
- [%- SET className = class.findvalue("@name") -%]
[%- IF found == "false" %]
// Owned attributes [${className}]
@@ -153,8 +153,8 @@ ${attributeName}
[%- END -%]
[%- END -%]
[%- SET found = "false" -%]
-[%- FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%]
[%- SET className = class.findvalue("@name") -%]
+[%- FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%]
[%- IF found == "false" %]
// Operations [${className}]
@@ -182,8 +182,8 @@ ${parameter.findvalue("@name")}
[%- END -%]
[%- END -%]
[%- SET found = "false" -%]
-[%- FOREACH attribute IN class.findnodes("ownedAttribute") -%]
[%- SET className = class.findvalue("@name") -%]
+[%- FOREACH attribute IN class.findnodes("ownedAttribute") -%]
[%- IF found == "false" %]
// Slots for owned attributes [${className}]
@@ -225,8 +225,8 @@ ${parameter.findvalue("@name")}
[%- END -%]
[%- END -%]
[%- SET found = "false" -%]
+[%- SET className = class.findvalue("@name") -%]
[% FOREACH attribute = class.findnodes("ownedAttribute") -%]
- [%- SET className = class.findvalue("@name") -%]
[%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%]
[%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 -%]
[%- IF found == "false" -%]
@@ -267,8 +267,8 @@ ${parameter.findvalue("@name")}
[%- END -%]
[%- END -%]
[%- SET found = "false" -%]
-[% FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%]
[%- SET className = class.findvalue("@name") -%]
+[% FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%]
[%- IF found == "false" -%]
// OPERATIONS [${className}]
@@ -360,8 +360,8 @@ ${parameter.findvalue("@name")}
[%- END -%]
[%- END -%]
[%- SET found = "false" -%]
+[%- SET className = class.findvalue("@name") -%]
[% FOREACH attribute = class.findnodes("ownedAttribute") -%]
- [%- SET className = class.findvalue("@name") -%]
[%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%]
[%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 -%]
[%- IF found == "false" -%]
@@ -448,10 +448,10 @@ void Q${namespace}${originalClassName}Object::unset${qtAttribute.remove("^is").u
[%- GENERATE_CLONE(xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${parentName}\"]"), visitedClasses, redefinedProperties) -%]
[%- END -%]
[%- END -%]
+[%- SET className = class.findvalue("@name") -%]
[%- FOREACH attribute = class.findnodes("ownedAttribute[@isDerived=\"false\" or not(@isDerived)]") -%]
[%- SET qtType = QT_TYPE(namespace, attribute) -%]
[%- SET attributeName = attribute.findvalue("@name") -%]
- [%- SET className = class.findvalue("@name") -%]
[%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%]
[%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 -%]
[%- IF qtType.match("QList|QSet") %]
@@ -469,3 +469,20 @@ void Q${namespace}${originalClassName}Object::unset${qtAttribute.remove("^is").u
[%- END -%]
[%- END %]
[%- END -%]
+[%- MACRO SET_CLASS_FOR_PROPERTY(class, visitedClasses, redefinedProperties) BLOCK -%]
+[%- FOREACH parent IN class.findnodes("generalization") -%]
+ [%- SET parentName = parent.findvalue("@general") -%]
+ [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%]
+ [%- visitedClasses.push("${parentName}") -%]
+ [%- SET_CLASS_FOR_PROPERTY(xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${parentName}\"]"), visitedClasses, redefinedProperties) -%]
+ [%- END -%]
+[%- END -%]
+[%- SET className = class.findvalue("@name") -%]
+[%- FOREACH attribute = class.findnodes("ownedAttribute") -%]
+ [%- SET qtType = QT_TYPE(namespace, attribute) -%]
+ [%- SET attributeName = attribute.findvalue("@name") -%]
+ [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%]
+ [%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 %]
+ _classForProperty[QStringLiteral("${PLURALFORM(qtAttribute, attribute)}")] = QStringLiteral("Q${namespace}${className}");
+[%- END %]
+[%- END -%] \ No newline at end of file
diff --git a/scripts/templates/qclass.cpp b/scripts/templates/qclass.cpp
index dbbf63b5..629d8f95 100644
--- a/scripts/templates/qclass.cpp
+++ b/scripts/templates/qclass.cpp
@@ -121,6 +121,7 @@ Q${namespace}${className}::Q${namespace}${className}([%- IF class.findvalue("@is
if (createQObject)
_qObject = new Q${namespace}${className}Object(this);
[%- END %]
+ setClassForProperty();
setPropertyData();
}
@@ -403,22 +404,29 @@ ${parameter.findvalue("@name")}
}
[%- END %]
+void Q${namespace}${className}::setClassForProperty()
+{
+[%- visitedClasses = [] -%]
+[%- SET_CLASS_FOR_PROPERTY(class, visitedClasses, redefinedProperties) %]
+}
+
void Q${namespace}${className}::setPropertyData()
{
[%- FOREACH attribute = class.findnodes("ownedAttribute") -%]
+[%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%]
[%- SET association = attribute.findvalue("@association") -%]
[%- IF attribute.findvalue("@aggregation") == "composite" %]
- QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::AggregationRole] = QStringLiteral("composite");
+ QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${PLURALFORM(qtAttribute, attribute)}")][QtModeling::AggregationRole] = QStringLiteral("composite");
[%- ELSE %]
- QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::AggregationRole] = QStringLiteral("none");
+ QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${PLURALFORM(qtAttribute, attribute)}")][QtModeling::AggregationRole] = QStringLiteral("none");
[%- END %]
- QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::PropertyClassRole] = QStringLiteral("Q${namespace}${className}");
- QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::IsDerivedRole] = [% IF attribute.findvalue("@isDerived") == "true" %]true[% ELSE %]false[% END %];
- QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::IsDerivedUnionRole] = [% IF attribute.findvalue("@isDerivedUnion") == "true" %]true[% ELSE %]false[% END %];
- QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::DocumentationRole] = QStringLiteral("${attribute.findvalue("ownedComment/body/text()")}");
- QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::RedefinedPropertiesRole] = QStringLiteral("${attribute.findvalue("@redefinedProperty")}");
- QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::SubsettedPropertiesRole] = QStringLiteral("${attribute.findvalue("@subsettedProperty")}");
- QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::OppositeEndRole] = QStringLiteral("
+ QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${PLURALFORM(qtAttribute, attribute)}")][QtModeling::PropertyClassRole] = QStringLiteral("Q${namespace}${className}");
+ QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${PLURALFORM(qtAttribute, attribute)}")][QtModeling::IsDerivedRole] = [% IF attribute.findvalue("@isDerived") == "true" %]true[% ELSE %]false[% END %];
+ QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${PLURALFORM(qtAttribute, attribute)}")][QtModeling::IsDerivedUnionRole] = [% IF attribute.findvalue("@isDerivedUnion") == "true" %]true[% ELSE %]false[% END %];
+ QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${PLURALFORM(qtAttribute, attribute)}")][QtModeling::DocumentationRole] = QStringLiteral("${attribute.findvalue("ownedComment/body/text()")}");
+ QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${PLURALFORM(qtAttribute, attribute)}")][QtModeling::RedefinedPropertiesRole] = QStringLiteral("${attribute.findvalue("@redefinedProperty")}");
+ QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${PLURALFORM(qtAttribute, attribute)}")][QtModeling::SubsettedPropertiesRole] = QStringLiteral("${attribute.findvalue("@subsettedProperty")}");
+ QModelingObject::propertyDataHash[QStringLiteral("Q${namespace}${className}")][QStringLiteral("${PLURALFORM(qtAttribute, attribute)}")][QtModeling::OppositeEndRole] = QStringLiteral("
[%- IF association != "" -%]
[%- FOREACH memberEnd = xmi.findvalue("//packagedElement[@xmi:type=\"uml:Association\" and @name=\"${association}\"]/@memberEnd").split(' ') -%]
[%- NEXT IF memberEnd == className.replace('$', "-${attribute.findvalue(\"@name\")}") -%]
diff --git a/scripts/templates/qclass.h b/scripts/templates/qclass.h
index 93cab4f4..9e5d1b18 100644
--- a/scripts/templates/qclass.h
+++ b/scripts/templates/qclass.h
@@ -141,6 +141,7 @@ protected:
[% QT_TYPE(namespace, attribute) -%]_[%- PLURALFORM(QT_ATTRIBUTE(attribute), attribute) %];
[%- END %]
+ virtual void setClassForProperty();
virtual void setPropertyData();
};