summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSandro S. Andrade <sandroandrade@kde.org>2013-08-27 12:01:42 -0300
committerSandro S. Andrade <sandroandrade@kde.org>2013-08-27 17:12:52 +0200
commit53b5fa7c58cc496b34679f51e6fcedfaa5f5d448 (patch)
treea131696409baa9a6a14294c5d22e4c9cb7eab7cd /scripts
parentbc5342512ed3605bbd1953eaf395fe137ca239f0 (diff)
Fix return value for QList/QSet properties
Add initialization of QObject properties from XMI-declared default values Change-Id: I1a5c097463aa492b121991cf6e569b38222cfdda Reviewed-by: Sandro S. Andrade <sandroandrade@kde.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/templates/class.cpp19
-rw-r--r--scripts/templates/class.h13
2 files changed, 18 insertions, 14 deletions
diff --git a/scripts/templates/class.cpp b/scripts/templates/class.cpp
index 496f61df..e1609a13 100644
--- a/scripts/templates/class.cpp
+++ b/scripts/templates/class.cpp
@@ -110,6 +110,8 @@ Q${namespace}${className}::Q${namespace}${className}()
[%- END %]
{
[%- FOREACH attribute = class.findnodes("ownedAttribute") -%]
+ [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%]
+ [%- SET defaultInstance = attribute.findvalue("defaultValue/@instance") -%]
[%- SET type = QT_TYPE(namespace, attribute) -%]
[%- SET derived = attribute.findvalue("@isDerived") -%]
[%- SET derivedUnion = attribute.findvalue("@isDerivedUnion") %]
@@ -117,10 +119,10 @@ Q${namespace}${className}::Q${namespace}${className}()
[%- IF type.match("QList|QSet") -%][% IF derived == "true" && (derivedUnion == "" || derivedUnion == "false") %]${type.trim}()[% ELSE %]&_[% QT_ATTRIBUTE(attribute) %][% END %]
[%- ELSIF type.match('\*$') -%](${type})(0)
[%- ELSIF type == "QString " -%]QString()
-[%- ELSIF type.match("::") -%]${type.trim}None
-[%- ELSIF type.match("int") -%](int)(0)
+[%- ELSIF type.match("::") -%][% IF defaultInstance != "" %]Qt${namespace}::${defaultInstance.split("-").0}${defaultInstance.split("-").1.ucfirst}[% ELSE %]${type.trim}None[% END -%]
+[%- ELSIF type.match("int") -%](int)([% IF defaultValue != "" %]${defaultValue}[% ELSE %]0[% END %])
[%- ELSIF type.match("double") -%](double)(0.0)
-[%- ELSIF type.match("bool") -%]false
+[%- ELSIF type.match("bool") -%][% IF defaultValue != "" %]${defaultValue}[% ELSE %]false[% END -%]
[%- END -%]
));
[%- END %]
@@ -136,13 +138,14 @@ Q${namespace}${className}::Q${namespace}${className}()
/*!
${documentation}
*/
-[%- END %]
-[% QT_TYPE(namespace, attribute) -%]
+[%- 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 association = attribute.findvalue("@association") %]
+[% IF qtType.match("QList|QSet") %]const [% END %][% QT_TYPE(namespace, attribute) -%]
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 %]
@@ -150,10 +153,10 @@ Q${namespace}${className}::${qtAttribute}() const
[%- 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('\*$') %]
+ [%- IF qtType.match('\*$') %]
return 0;
[%- ELSE %]
- return ${QT_TYPE(namespace, attribute).trim}();
+ return ${qtType.trim}();
[%- END %]
[%- ELSE %]
return _${qtAttribute};
diff --git a/scripts/templates/class.h b/scripts/templates/class.h
index a8a1cc7c..e692d35b 100644
--- a/scripts/templates/class.h
+++ b/scripts/templates/class.h
@@ -95,15 +95,16 @@ public:
[%- IF loop.first %]
// Owned attributes
- [%- END %]
- [% QT_TYPE(namespace, attribute) -%]
- [%- QT_ATTRIBUTE(attribute) -%]() const;
+ [%- END -%]
+ [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%]
+ [%- 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 attribute.findvalue("@isReadOnly") == "true" -%]Q_DECL_HIDDEN [% END %]void add${attributeName}([% QT_TYPE(namespace, attribute).remove("QSet<").remove("QList<").replace("> ", " ").replace('\* $', '*') %][% QT_ATTRIBUTE(attribute) %]);
- [% IF attribute.findvalue("@isReadOnly") == "true" -%]Q_DECL_HIDDEN [% END %]void remove${attributeName}([% QT_TYPE(namespace, attribute).remove("QSet<").remove("QList<").replace("> ", " ").replace('\* $', '*') %][% QT_ATTRIBUTE(attribute) %]);
+ [% IF attribute.findvalue("@isReadOnly") == "true" -%]Q_DECL_HIDDEN [% END %]void add${attributeName}([% qtType.remove("QSet<").remove("QList<").replace("> ", " ").replace('\* $', '*') %]${qtAttribute});
+ [% IF attribute.findvalue("@isReadOnly") == "true" -%]Q_DECL_HIDDEN [% END %]void remove${attributeName}([% qtType.remove("QSet<").remove("QList<").replace("> ", " ").replace('\* $', '*') %]${qtAttribute});
[%- ELSE %]
- [% IF attribute.findvalue("@isReadOnly") == "true" -%]Q_DECL_HIDDEN [% END %]void set${attributeName.remove("^Is")}([% QT_TYPE(namespace, attribute) %][% QT_ATTRIBUTE(attribute) %]);
+ [% IF attribute.findvalue("@isReadOnly") == "true" -%]Q_DECL_HIDDEN [% END %]void set${attributeName.remove("^Is")}(${qtType}${qtAttribute});
[%- END %]
[%- IF loop.last %]
[%- END %]