diff options
author | Sandro S. Andrade <sandroandrade@kde.org> | 2013-10-06 11:31:46 -0300 |
---|---|---|
committer | Sandro S. Andrade <sandroandrade@kde.org> | 2013-10-06 16:28:28 +0200 |
commit | 3031fe1254052bdeffec90ca76e2f3649a971ae7 (patch) | |
tree | 1c53eeec8c4be183f600a8f17c7e156efa779ea1 /scripts/templates | |
parent | e07d31eda9cc77f50fb6dbae8905384219171332 (diff) |
Use plural form for multi-valued UML metamodel properties
Change-Id: Ia8ab1c48d0fb552aca0ae729507c18b63d4c448e
Reviewed-by: Sandro S. Andrade <sandroandrade@kde.org>
Diffstat (limited to 'scripts/templates')
-rw-r--r-- | scripts/templates/common.tmpl | 41 | ||||
-rw-r--r-- | scripts/templates/module.pro | 2 | ||||
-rw-r--r-- | scripts/templates/qclass.cpp | 29 | ||||
-rw-r--r-- | scripts/templates/qclass.h | 4 |
4 files changed, 49 insertions, 27 deletions
diff --git a/scripts/templates/common.tmpl b/scripts/templates/common.tmpl index 22bad677..fc94026b 100644 --- a/scripts/templates/common.tmpl +++ b/scripts/templates/common.tmpl @@ -71,6 +71,26 @@ ${attributeName} [%- END -%] [%- END -%] [%- END -%] +[%- MACRO PLURALFORM(attributeName, attribute) BLOCK -%] +[%- SET return = attributeName -%] +[%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" && + !((attributeName.match('^to')) && attributeName.substr(3, 1) == attributeName.substr(3, 1).upper) && + attributeName != 'provided' && + attributeName != 'required' && + attributeName != 'endData' && + attributeName != 'conveyed' && + attributeName != 'covered' && + attributeName != 'coveredBy' && + attributeName != 'conformance' && + attributeName != 'referred' && + attributeName != 'represented' -%] +[%- SET return = return.replace('_$', '').replace('y$', 'ie').replace('ss$', 'sse').replace('ex$', 'ice').replace('x$', 'ce').replace('$', 's') -%] +[%- IF attributeName.match('_$') and !return.match('_$') -%][%- SET return = return.replace('$', '_') -%][%- END -%] +${return} +[%- ELSE -%] +${attributeName} +[%- END -%] +[%- END -%] [%- MACRO GENERATE_QPROPERTIES(class, visitedClasses, redefinedProperties) BLOCK -%] [%- FOREACH parent IN class.findnodes("generalization") -%] [%- SET parentName = parent.findvalue("@general") -%] @@ -90,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 ${qtAttribute}[% 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} ${qtAttribute} READ ${PLURALFORM(qtAttribute, attribute)}[% 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 -%] @@ -114,7 +134,7 @@ ${attributeName} [%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 -%] [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] [%- IF qtType.match("QList|QSet") %] - Q_INVOKABLE const ${qtType}${qtAttribute}() const; + Q_INVOKABLE const ${qtType}${PLURALFORM(qtAttribute, attribute)}() const; [%- ELSIF qtType.match('\*$') %] Q_INVOKABLE ${qtType}${qtAttribute}() const; [%- ELSE %] @@ -212,33 +232,32 @@ ${parameter.findvalue("@name")} [%- IF found == "false" -%] // OWNED ATTRIBUTES [${className}] -[%- SET found = "true" -%] +[% SET found = "true" -%] [% 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}Object::${qtAttribute}() const + [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] +[% IF qtType.match("QList|QSet") %]const [% END %]${qtType}Q${namespace}${originalClassName}Object::${PLURALFORM(qtAttribute, attribute)}() const { [%- IF qtType.match("QList|QSet") && !qtType.match("QString") %] ${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}()) + foreach (Q${originalQtType.remove("QList<").remove("QSet<").remove(">").trim.remove("^Q")}element, qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->${PLURALFORM(qtAttribute, attribute)}()) [% 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 (!qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->${qtAttribute}()) + if (!qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->${PLURALFORM(qtAttribute, attribute)}()) return 0; else - return qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->${qtAttribute}()->asQObject(); + return qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->${PLURALFORM(qtAttribute, attribute)}()->asQObject(); [%- ELSE %] - return qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->${qtAttribute}(); + return qmodelingobjectproperty_cast<Q${namespace}${originalClassName} *>(this)->${PLURALFORM(qtAttribute, attribute)}(); [%- END %] } -[%- IF loop.last %] [% END -%] [%- END -%] -[%- END -%] [%- MACRO GENERATE_CPP_OPERATIONS(originalClassName, class, visitedClasses, redefinedOperations) BLOCK -%] [%- FOREACH parent IN class.findnodes("generalization") -%] [%- SET parentName = parent.findvalue("@general") -%] @@ -436,7 +455,7 @@ void Q${namespace}${originalClassName}Object::unset${qtAttribute.remove("^is").u [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] [%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 -%] [%- IF qtType.match("QList|QSet") %] - foreach (${qtType.remove("QList<").remove("QSet<").remove(">").replace('\* ', '*')}element, ${qtAttribute}()) + foreach (${qtType.remove("QList<").remove("QSet<").remove(">").replace('\* ', '*')}element, ${PLURALFORM(qtAttribute, attribute)}()) [%- IF qtType.match('\*') %] c->add${attributeName.ucfirst}(dynamic_cast<${qtType.remove("QList<").remove("QSet<").remove(">").replace('\* ', '*')}>(element->clone())); [%- ELSE %] diff --git a/scripts/templates/module.pro b/scripts/templates/module.pro index 4b39de97..eae886f1 100644 --- a/scripts/templates/module.pro +++ b/scripts/templates/module.pro @@ -1,7 +1,7 @@ load(qt_build_config) TARGET = Qt${namespace} -QT = core +QT = core modeling QMAKE_DOCS = [%- GET '$$PWD' -%]/doc/qt${namespace.lower}.qdocconf diff --git a/scripts/templates/qclass.cpp b/scripts/templates/qclass.cpp index 19935695..0f33637b 100644 --- a/scripts/templates/qclass.cpp +++ b/scripts/templates/qclass.cpp @@ -59,6 +59,7 @@ [%- IF loop.last %] [% END -%] [%- END -%] + /*! \class Q${namespace}${className} @@ -162,12 +163,12 @@ QModelingObject *Q${namespace}${className}::clone() const ${documentation} */ [%- END %] -[% IF qtType.match("QList|QSet") %]const [% END %]${qtType}Q${namespace}${className}::${qtAttribute}() const +[% IF qtType.match("QList|QSet") %]const [% END %]${qtType}Q${namespace}${className}::${PLURALFORM(qtAttribute, attribute)}() 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 %])"); + qWarning("${namespace}${className}::${PLURALFORM(qtAttribute, attribute)}(): to be implemented (this is a derived [% IF association != "" %]association end[% ELSE %]property[% END %])"); [%- IF qtType.match('\*$') %] return 0; @@ -175,7 +176,7 @@ QModelingObject *Q${namespace}${className}::clone() const return ${qtType.trim}(); [%- END %] [%- ELSE %] - return _${qtAttribute}; + return _${PLURALFORM(qtAttribute, attribute)}; [%- END %] } [%- SET attributeName = attribute.findvalue("@name").ucfirst %] @@ -186,14 +187,14 @@ void Q${namespace}${className}::add${attributeName}(${qtType.remove("QSet<").rem // 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 %])"); + qWarning("${namespace}${className}::add${attributeName}(): 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 (!_${PLURALFORM(qtAttribute, attribute)}.contains(${qtAttribute})) { + _${PLURALFORM(qtAttribute, attribute)}.[% IF qtType.match("QList") %]append[% ELSE %]insert[% END %](${qtAttribute}); [%- IF qtType.match('\*') %] if (${qtAttribute} && ${qtAttribute}->asQObject() && this->asQObject()) QObject::connect(${qtAttribute}->asQObject(), SIGNAL(destroyed(QObject*)), this->asQObject(), SLOT(remove${attributeName}(QObject *))); @@ -247,14 +248,14 @@ void Q${namespace}${className}::remove${attributeName}(${qtType.remove("QSet<"). // 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 %])"); + qWarning("${namespace}${className}::remove${attributeName}(): 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 (_${PLURALFORM(qtAttribute, attribute)}.contains(${qtAttribute})) { + _${PLURALFORM(qtAttribute, attribute)}.[% IF qtType.match("QList") %]removeAll[% ELSE %]remove[% END %](${qtAttribute}); [%- IF attribute.findvalue("@aggregation") == "composite" %] if (${qtAttribute}->asQObject()) ${qtAttribute}->asQObject()->setParent(0); @@ -306,12 +307,12 @@ void Q${namespace}${className}::set${attributeName.remove("^Is")}([% IF !qtType. // 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 %])"); + qWarning("${namespace}${className}::set${attributeName.remove("^Is")}(): 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}) { + if (_${PLURALFORM(qtAttribute, attribute)} != ${qtAttribute}) { [%- END %] [%- found = "false" -%] [%- FOREACH subsettedPropertyName = attribute.findvalue("@subsettedProperty").split(" ") -%] @@ -322,7 +323,7 @@ void Q${namespace}${className}::set${attributeName.remove("^Is")}([% IF !qtType. [%- 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 %]); + [% IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]// [% END %]remove${subsettedPropertyName.split('-').1.ucfirst}([%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]/* <derived-code> */[% ELSE %]_${PLURALFORM(qtAttribute, attribute)}[% END %]); [%- END -%] [%- END %] [%- END %] @@ -331,7 +332,7 @@ void Q${namespace}${className}::set${attributeName.remove("^Is")}([% IF !qtType. [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %] // <derived-code> [%- ELSE %] - _${qtAttribute} = ${qtAttribute}; + _${PLURALFORM(qtAttribute, attribute)} = ${qtAttribute}; [%- IF attribute.findvalue("defaultValue/@xmi:type") != "" %] _modifiedResettableProperties << QStringLiteral("${attributeName.lcfirst}"); [%- END %] @@ -411,6 +412,8 @@ void Q${namespace}${className}::setPropertyData() [%- ELSE %] QModelingObject::propertyDataHash[QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::AggregationRole] = QStringLiteral("none"); [%- END %] + QModelingObject::propertyDataHash[QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::PropertyClassRole] = QStringLiteral("Q${namespace}${className}"); + QModelingObject::propertyDataHash[QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::IsDerivedRole] = [% IF attribute.findvalue("@isDerived") == "true" %]true[% ELSE %]false[% END %]; QModelingObject::propertyDataHash[QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::IsDerivedUnionRole] = [% IF attribute.findvalue("@isDerivedUnion") == "true" %]true[% ELSE %]false[% END %]; QModelingObject::propertyDataHash[QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::DocumentationRole] = QStringLiteral("${attribute.findvalue("ownedComment/body/text()")}"); QModelingObject::propertyDataHash[QStringLiteral("${attribute.findvalue("@name")}")][QtModeling::RedefinedPropertiesRole] = QStringLiteral("${attribute.findvalue("@redefinedProperty")}"); diff --git a/scripts/templates/qclass.h b/scripts/templates/qclass.h index c4a1d9c7..93cab4f4 100644 --- a/scripts/templates/qclass.h +++ b/scripts/templates/qclass.h @@ -106,7 +106,7 @@ public: [%- 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; + [% IF qtType.match("QList|QSet") %]const [% END %]${qtType}${PLURALFORM(qtAttribute, attribute)}() 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}); @@ -138,7 +138,7 @@ protected: 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) %]; + [% QT_TYPE(namespace, attribute) -%]_[%- PLURALFORM(QT_ATTRIBUTE(attribute), attribute) %]; [%- END %] virtual void setPropertyData(); |