summaryrefslogtreecommitdiffstats
path: root/scripts/templates
diff options
context:
space:
mode:
authorSandro S. Andrade <sandroandrade@kde.org>2013-09-04 07:26:59 -0300
committerSandro S. Andrade <sandroandrade@kde.org>2013-09-04 12:24:26 +0200
commitdf7fb2f660e151d0c5fbe62f90be9437ed190087 (patch)
treed001e89e61a00cd00e23b2b6a042bc55aed150d0 /scripts/templates
parentc9b9fb27ccfef6f23ce89eb7a54ed1ffa0bdd697 (diff)
Add clone() method in template files
Change-Id: I345f997a2002bb97d4d243e4b2286865728292d8 Reviewed-by: Sandro S. Andrade <sandroandrade@kde.org>
Diffstat (limited to 'scripts/templates')
-rw-r--r--scripts/templates/common.tmpl27
-rw-r--r--scripts/templates/qclass.cpp11
-rw-r--r--scripts/templates/qclass.h2
3 files changed, 39 insertions, 1 deletions
diff --git a/scripts/templates/common.tmpl b/scripts/templates/common.tmpl
index 96d7b63c..442825ee 100644
--- a/scripts/templates/common.tmpl
+++ b/scripts/templates/common.tmpl
@@ -394,4 +394,29 @@ void Q${namespace}${originalClassName}Object::set${attributeName.remove("^Is")}(
[%- IF forwardName != className -%][%- forwards.push("Q${namespace}${forwardName}") -%][%- END -%]
[%- END -%]
[%- END -%]
-[%- END -%] \ No newline at end of file
+[%- END -%]
+[%- MACRO GENERATE_CLONE(class, visitedClasses, redefinedProperties) BLOCK -%]
+[%- FOREACH parent IN class.findnodes("generalization") -%]
+ [%- SET parentName = parent.findvalue("@general") -%]
+ [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%]
+ [%- visitedClasses.push("${parentName}") -%]
+ [%- GENERATE_CLONE(xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${parentName}\"]"), visitedClasses, redefinedProperties) -%]
+ [%- END -%]
+[%- END -%]
+[%- 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") && qtType.match('\*') %]
+ foreach (${qtType.remove("QList<").remove("QSet<").remove(">").replace('\* ', '*')}element, ${attributeName}())
+ c->add${attributeName.ucfirst}(dynamic_cast<${qtType.remove("QList<").remove("QSet<").remove(">").replace('\* ', '*')}>(element->clone()));
+ [%- ELSIF qtType.match('\*') %]
+ if (${attributeName}())
+ c->set${attributeName.ucfirst}(dynamic_cast<${qtType.remove("QList<").remove("QSet<").remove(">").replace('\* ', '*')}>(${attributeName}()->clone()));
+ [%- ELSE %]
+ c->set${attributeName.ucfirst}(${attributeName}());
+ [%- END -%]
+[%- END %]
+[%- END -%]
diff --git a/scripts/templates/qclass.cpp b/scripts/templates/qclass.cpp
index 8e755719..70ca0bab 100644
--- a/scripts/templates/qclass.cpp
+++ b/scripts/templates/qclass.cpp
@@ -135,6 +135,17 @@ Q${namespace}${className}::~Q${namespace}${className}()
}
[%- END %]
}
+
+QModelingObject *Q${namespace}${className}::clone() const
+{
+ Q${namespace}${className} *c = new Q${namespace}${className};
+[%- visitedClasses = [] -%]
+[%- redefinedProperties = [] -%]
+[%- POPULATE_REDEFINED_PROPERTIES(class, visitedClasses, redefinedProperties) -%]
+[%- visitedClasses = [] -%]
+[%- GENERATE_CLONE(class, visitedClasses, redefinedProperties) %]
+ return c;
+}
[%- FOREACH attribute = class.findnodes("ownedAttribute") %]
[%- IF loop.first %]
diff --git a/scripts/templates/qclass.h b/scripts/templates/qclass.h
index 4e736811..1a29d7aa 100644
--- a/scripts/templates/qclass.h
+++ b/scripts/templates/qclass.h
@@ -97,6 +97,8 @@ public:
explicit Q${namespace}${className}(bool createQObject = true);
[%- END %]
virtual ~Q${namespace}${className}();
+
+ [% IF class.findvalue("@isAbstract") == "true" %]Q_DECL_HIDDEN [% END %]QModelingObject *clone() const;
[% FOREACH attribute = class.findnodes("ownedAttribute") -%]
[%- IF loop.first %]
// Owned attributes