[% USE xmi = XML.XPath("$xmi") -%] [% SET class = xmi.findnodes("//packagedElement[(@xmi:type='uml:Class' or @xmi:type='uml:Stereotype') and @name='$className']") -%] [% SET uml2qt_type = { "Boolean" = "bool", "Integer" = "int", "UnlimitedNatural" = "QString", "String" = "QString", "Real" = "double" }; -%] [%- MACRO QT_TYPE(namespace, attribute, external) BLOCK -%] [%- SET localNamespace = namespace -%] [%- SET multiplicity = attribute.findnodes("upperValue").findvalue("@value") -%] [%- SET isUnique = attribute.findvalue("@isUnique") -%] [%- SET isOrdered = attribute.findvalue("@isOrdered") -%] [%- IF multiplicity == "*" %][% IF (isUnique == "true" || isUnique == "") && (isOrdered == "false" || isOrdered == "") %]QSet[% ELSE %]QList[% END %]<[% END -%] [%- SET attributeType = attribute.findvalue("@type") -%] [%- IF attributeType == "" -%][%- SET attributeType = attribute.findnodes("type").findvalue("@xmi:idref") -%][%- END -%] [%- IF attributeType == "" -%][%- SET attributeType = attribute.findnodes("type").findvalue("@href") -%][%- END -%] [%- IF attributeType.split('#').first.split('/').last != attributeType and !attributeType.match('PrimitiveTypes\.xmi') -%] [%- SET localNamespace = attributeType.split('#').first.split('/').last.split('\.').first.lower.ucfirst -%] [%- SET attributeType = attributeType.split('#').last -%] [%- END -%] [%- IF !attributeType.match('PrimitiveTypes\.xmi') -%] [%- IF xmi.findnodes("//packagedElement[@xmi:type='uml:Enumeration' and @name='$attributeType']").findvalue("@name") != "" -%] Qt${localNamespace}::${attributeType} [%- ELSE -%] [%- IF attributeType != "" -%] [% IF external == "false" %]QObject *[% ELSE %]Q${localNamespace}${attributeType} *[% END %] [%- ELSE %] [% END -%] [%- END -%] [%- ELSE -%] ${uml2qt_type.item(attributeType.split('#').last)}[%- IF multiplicity != "*" %] [% END -%] [%- END -%] [%- IF multiplicity == "*" %]> [% END -%] [%- END -%] [% SET uml2qt_attribute = { "namespace" = "namespace_", "interface" = "interface_", "class" = "class_", "default" = "default_", "template" = "template_", "slot" = "slot_", "delete" = "delete_", "event" = "event_" }; -%] [%- MACRO QT_ATTRIBUTE(attribute) BLOCK -%] [%- SET attributeName = attribute.findvalue("@name") -%] [%- IF uml2qt_attribute.item(attributeName) != "" -%] ${uml2qt_attribute.item(attributeName)} [%- ELSE -%] ${attributeName} [%- END -%] [%- END -%] [%- MACRO POPULATE_REDEFINED_PROPERTIES(class, visitedClasses, redefinedProperties) BLOCK -%] [%- FOREACH parent IN class.findnodes("generalization") -%] [%- SET parentName = parent.findvalue("@general") -%] [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] [%- visitedClasses.push("${parentName}") -%] [%- POPULATE_REDEFINED_PROPERTIES(xmi.findnodes("//packagedElement[(@xmi:type=\"uml:Class\" or @xmi:type=\"uml:Stereotype\") and @name=\"${parentName}\"]"), visitedClasses, redefinedProperties) -%] [%- END -%] [%- END -%] [%- FOREACH attribute IN class.findnodes("ownedAttribute[@redefinedProperty]") -%] [%- FOREACH redefinedProperty IN attribute.findvalue("@redefinedProperty").split(' ') -%] [%- redefinedProperties.push("${redefinedProperty}") -%] [%- END -%] [%- END -%] [%- END -%] [%- MACRO POPULATE_REDEFINED_OPERATIONS(class, visitedClasses, redefinedOperations) BLOCK -%] [%- FOREACH parent IN class.findnodes("generalization") -%] [%- SET parentName = parent.findvalue("@general") -%] [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] [%- visitedClasses.push("${parentName}") -%] [%- POPULATE_REDEFINED_OPERATIONS(xmi.findnodes("//packagedElement[(@xmi:type=\"uml:Class\" or @xmi:type=\"uml:Stereotype\") and @name=\"${parentName}\"]"), visitedClasses, redefinedOperations) -%] [%- END -%] [%- END -%] [%- FOREACH operation IN class.findnodes("ownedOperation[@redefinedOperation]") -%] [%- FOREACH redefinedOperation IN operation.findvalue("@redefinedOperation").split(' ') -%] [%- redefinedOperations.push("${redefinedOperation}") -%] [%- 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") -%] [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] [%- visitedClasses.push("${parentName}") -%] [%- GENERATE_QPROPERTIES(xmi.findnodes("//packagedElement[(@xmi:type=\"uml:Class\" or @xmi:type=\"uml:Stereotype\") and @name=\"${parentName}\"]"), visitedClasses, redefinedProperties) -%] [%- END -%] [%- END -%] [%- SET found = "false" -%] [%- SET className = class.findvalue("@name") -%] [%- FOREACH attribute IN class.findnodes("ownedAttribute") -%] [%- IF found == "false" %] // Properties [${className}] [%- SET found = "true" -%] [%- END -%] [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] [%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 -%] [%- SET qtType = QT_TYPE(namespace, attribute, "false") %] 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 %] NOTIFY ${PLURALFORM(qtAttribute, attribute).remove('_$')}Changed[% 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 -%] [%- FOREACH parent IN class.findnodes("generalization") -%] [%- SET parentName = parent.findvalue("@general") -%] [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] [%- visitedClasses.push("${parentName}") -%] [%- GENERATE_ATTRIBUTES(xmi.findnodes("//packagedElement[(@xmi:type=\"uml:Class\" or @xmi:type=\"uml:Stereotype\") and @name=\"${parentName}\"]"), visitedClasses, redefinedProperties) -%] [%- END -%] [%- END -%] [%- SET attributes = class.findnodes("ownedAttribute") -%] [%- SET found = "false" -%] [%- SET className = class.findvalue("@name") -%] [%- FOREACH attribute IN attributes -%] [%- SET derived = attribute.findvalue("@isDerived") -%] [%- SET derivedUnion = attribute.findvalue("@isDerivedUnion") -%] [%- IF found == "false" %] // Owned attributes [${className}] [%- SET found = "true" -%] [%- END -%] [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] [%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 -%] [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] [%- IF qtType.match("QList|QSet") %] [% IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]Q_TODO [% END %]Q_INVOKABLE const ${qtType}${PLURALFORM(qtAttribute, attribute)}() const; [%- ELSIF qtType.match('\*$') %] [% IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]Q_TODO [% END %]Q_INVOKABLE ${qtType}${qtAttribute}() const; [%- ELSE %] [% IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]Q_TODO [% END %]Q_INVOKABLE ${qtType}${qtAttribute}() const; [%- END %] [%- IF loop.last %] [%- END %] [%- END -%] [%- END -%] [%- MACRO GENERATE_OPERATIONS(class, visitedClasses, redefinedOperations) BLOCK -%] [%- FOREACH parent IN class.findnodes("generalization") -%] [%- SET parentName = parent.findvalue("@general") -%] [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] [%- visitedClasses.push("${parentName}") -%] [%- GENERATE_OPERATIONS(xmi.findnodes("//packagedElement[(@xmi:type=\"uml:Class\" or @xmi:type=\"uml:Stereotype\") and @name=\"${parentName}\"]"), visitedClasses, redefinedOperations) -%] [%- END -%] [%- END -%] [%- SET found = "false" -%] [%- SET className = class.findvalue("@name") -%] [%- FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%] [%- IF found == "false" %] // Operations [${className}] [%- SET found = "true" -%] [%- END %] [%- SET operationName = operation.findvalue("@name") -%] [%- NEXT IF redefinedOperations.grep("^${className}-${operationName}$").size > 0 -%] [%- SET qtType = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']"), "false") -%] Q_TODO Q_INVOKABLE [%- IF qtType != " " -%]${qtType}[%- ELSE -%]void [%- END -%] [%- IF uml2qt_attribute.item(operationName) != "" -%]${uml2qt_attribute.item(operationName)}[%- ELSE -%]${operationName}[%- END -%]( [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] [%- QT_TYPE(namespace, parameter, "false") -%] [%- SET parameterName = parameter.findvalue("@name") -%] [%- IF uml2qt_attribute.item(parameterName) != "" -%]${uml2qt_attribute.item(parameterName)}[%- ELSE -%]${parameterName}[%- END -%] [%- IF !loop.last %], [% END -%] [%- END -%] )[% IF operation.findvalue("@isQuery") == "true" %] const[% END %]; [%- END %] [%- END -%] [%- MACRO GENERATE_SLOTS(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_SLOTS(xmi.findnodes("//packagedElement[(@xmi:type=\"uml:Class\" or @xmi:type=\"uml:Stereotype\") and @name=\"${parentName}\"]"), visitedClasses, redefinedProperties) -%] [%- END -%] [%- END -%] [%- SET found = "false" -%] [%- SET className = class.findvalue("@name") -%] [%- FOREACH attribute IN class.findnodes("ownedAttribute") -%] [%- IF found == "false" %] // Slots for owned attributes [${className}] [%- SET found = "true" -%] [%- END %] [%- SET qtAttribute = QT_ATTRIBUTE(attribute) %] [%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 -%] [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] [%- SET readOnly = attribute.findvalue("@isReadOnly") -%] [%- SET attributeName = attribute.findvalue("@name").ucfirst -%] [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" -%] [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] void [%- IF readOnly == "true" -%]Q_DECL_HIDDEN [% END %]add${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*') %]${qtAttribute}); void [%- IF readOnly == "true" -%]Q_DECL_HIDDEN [% END %]remove${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*') %]${qtAttribute}); [%- ELSE %] void [%- IF readOnly == "true" -%]Q_DECL_HIDDEN [% END %]add${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "")}${qtAttribute}); void [%- IF readOnly == "true" -%]Q_DECL_HIDDEN [% END %]remove${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "")}${qtAttribute}); [%- END -%] [%- ELSE -%] [%- IF qtType.match('QList|QSet') %] void [%- IF readOnly == "true" -%]Q_DECL_HIDDEN [% END %]set${attributeName}(${qtType}${qtAttribute}); [%- ELSIF qtType.match('\*$') %] void [%- IF readOnly == "true" -%]Q_DECL_HIDDEN [% END %]set${attributeName}(${qtType}${qtAttribute} = 0); [%- ELSE %] void [%- IF readOnly == "true" -%]Q_DECL_HIDDEN [% END %]set${attributeName.remove("^Is")}(${qtType}${qtAttribute}); [%- END -%] [%- END -%] [%- IF attribute.findvalue("defaultValue/@xmi:type") != "" %] void unset${qtAttribute.remove("^is").ucfirst}(); [%- END -%] [%- END %] [%- END -%] [%- MACRO GENERATE_CPP_ATTRIBUTES(originalClassName, 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_CPP_ATTRIBUTES(originalClassName, xmi.findnodes("//packagedElement[(@xmi:type=\"uml:Class\" or @xmi:type=\"uml:Stereotype\") and @name=\"${parentName}\"]"), visitedClasses, redefinedProperties) -%] [%- END -%] [%- END -%] [%- SET found = "false" -%] [%- SET className = class.findvalue("@name") -%] [% FOREACH attribute = class.findnodes("ownedAttribute") -%] [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] [%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 -%] [%- IF found == "false" -%] // OWNED ATTRIBUTES [${className}] [% 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") %] [%- 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, qmodelingelementproperty_cast(this)->${PLURALFORM(qtAttribute, attribute)}()) [% IF qtType.match("QList") %]list[% ELSE %]set[% END %].[% IF qtType.match("QList") %]append[% ELSE %]insert[% END %](element->asQModelingObject()); return [% IF qtType.match("QList") %]list[% ELSE %]set[% END %]; [%- ELSIF qtType.match('\*$') %] if (!qmodelingelementproperty_cast(this)->${PLURALFORM(qtAttribute, attribute)}()) return 0; else return qmodelingelementproperty_cast(this)->${PLURALFORM(qtAttribute, attribute)}()->asQModelingObject(); [%- ELSE %] return qmodelingelementproperty_cast(this)->${PLURALFORM(qtAttribute, attribute)}(); [%- END %] } [% END -%] [%- END -%] [%- MACRO GENERATE_CPP_OPERATIONS(originalClassName, class, visitedClasses, redefinedOperations) BLOCK -%] [%- FOREACH parent IN class.findnodes("generalization") -%] [%- SET parentName = parent.findvalue("@general") -%] [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] [%- visitedClasses.push("${parentName}") -%] [%- GENERATE_CPP_OPERATIONS(originalClassName, xmi.findnodes("//packagedElement[(@xmi:type=\"uml:Class\" or @xmi:type=\"uml:Stereotype\") and @name=\"${parentName}\"]"), visitedClasses, redefinedOperations) -%] [%- END -%] [%- END -%] [%- SET found = "false" -%] [%- SET className = class.findvalue("@name") -%] [% FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%] [%- IF found == "false" -%] // OPERATIONS [${className}] [% SET found = "true" -%] [% END -%] [% SET operationName = operation.findvalue("@name") -%] [%- IF uml2qt_attribute.item(operationName) != "" -%][% SET operationName = uml2qt_attribute.item(operationName) -%][%- END -%] [%- NEXT IF redefinedOperations.grep("^${className}-${operationName}$").size > 0 -%] [%- SET return = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']"), "false") %] [%- SET originalReturn = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']"), "true") %] [%- IF return != " " %]${return}[%- ELSE %]void [%- END -%] Q${namespace}${originalClassName}Object::${operationName}( [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] [%- QT_TYPE(namespace, parameter, "false") -%] [%- SET parameterName = parameter.findvalue("@name") -%] [%- IF uml2qt_attribute.item(parameterName) != "" -%][%- SET parameterName = uml2qt_attribute.item(parameterName) -%][%- END -%] ${parameterName} [%- IF !loop.last %], [% END -%] [%- END -%] )[% IF operation.findvalue("@isQuery") == "true" %] const[% END %] { [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] [%- IF QT_TYPE(namespace, parameter, "true").match("QList|QSet") %] ${QT_TYPE(namespace, parameter, "true")}${parameter.findvalue("@name")}Converted; foreach (QObject *object, ${parameter.findvalue("@name")}) ${parameter.findvalue("@name")}Converted.[% IF QT_TYPE(namespace, parameter, "true").match("QList") %]append[% ELSE %]insert[% END %](qmodelingelementproperty_cast<${QT_TYPE(namespace, parameter, "true").remove("QList<").remove("QSet<").remove(">").trim}>(object)); [%- END -%] [%- END -%] [%- IF return.match("QList|QSet") && return.match('\*') %] ${return}[% IF qtType.match("QList") %]list[% ELSE %]set[% END %]; foreach (${originalReturn.remove("QList<").remove("QSet<").remove(">").trim}element, qmodelingelementproperty_cast(this)->${operationName}( [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] [%- SET parameterName = parameter.findvalue("@name") -%] [%- IF uml2qt_attribute.item(parameterName) != "" -%][%- SET parameterName = uml2qt_attribute.item(parameterName) -%][%- END -%] [%- qtType = QT_TYPE(namespace, parameter, "true") -%] [%- IF qtType.match('QList|QSet') -%] ${parameterName}Converted [%- ELSIF qtType.match('\*$') -%] qmodelingelementproperty_cast<${qtType.remove("QList<").remove("QSet<").remove(">")}>(${parameter.findvalue("@name")}) [%- ELSE -%] ${parameterName} [%- END -%] [%- IF !loop.last %], [% END -%] [%- END -%])) [% IF qtType.match("QList") %]list[% ELSE %]set[% END %].[% IF return.match("QList") %]append[% ELSE %]insert[% END %](element->asQModelingObject()); return [% IF qtType.match("QList") %]list[% ELSE %]set[% END %]; [%- ELSIF !return.match("QList|QSet") && return.match('\*$') %] if (!qmodelingelementproperty_cast(this)->${operationName}( [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] [%- SET parameterName = parameter.findvalue("@name") -%] [%- IF uml2qt_attribute.item(parameterName) != "" -%][%- SET parameterName = uml2qt_attribute.item(parameterName) -%][%- END -%] [%- qtType = QT_TYPE(namespace, parameter, "true") -%] [%- IF qtType.match('\*$') -%] [%- SET parameterName = parameter.findvalue("@name") -%] [%- IF uml2qt_attribute.item(parameterName) != "" -%][%- SET parameterName = uml2qt_attribute.item(parameterName) -%][%- END -%] qmodelingelementproperty_cast<${qtType.remove("QList<").remove("QSet<").remove(">")}>(${parameterName}) [%- ELSE -%] ${parameterName}[%- IF QT_TYPE(namespace, parameter, "true").match("QList|QSet") %]Converted[%- END -%] [%- END -%] [%- IF !loop.last %], [% END -%] [%- END -%])) return 0; else return qmodelingelementproperty_cast(this)->${operationName}( [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] [%- SET parameterName = parameter.findvalue("@name") -%] [%- IF uml2qt_attribute.item(parameterName) != "" -%][%- SET parameterName = uml2qt_attribute.item(parameterName) -%][%- END -%] [%- qtType = QT_TYPE(namespace, parameter, "true") -%] [%- IF qtType.match('\*$') -%] qmodelingelementproperty_cast<${qtType.remove("QList<").remove("QSet<").remove(">")}>(${parameterName}) [%- ELSE -%] ${parameterName}[%- IF QT_TYPE(namespace, parameter, "true").match("QList|QSet") %]Converted[%- END -%] [%- END -%] [%- IF !loop.last %], [% END -%] [%- END -%])->asQModelingObject(); [%- ELSE %] return qmodelingelementproperty_cast(this)->${operationName}( [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] [%- SET parameterName = parameter.findvalue("@name") -%] [%- IF uml2qt_attribute.item(parameterName) != "" -%][%- SET parameterName = uml2qt_attribute.item(parameterName) -%][%- END -%] [%- qtType = QT_TYPE(namespace, parameter, "true") -%] [%- IF qtType.match('\*$') -%] qmodelingelementproperty_cast<${qtType.remove("QList<").remove("QSet<").remove(">")}>(${parameterName}) [%- ELSE -%] ${parameterName} [%- END -%] [%- IF !loop.last %], [% END -%] [%- END -%]); [%- END %] } [% END -%] [%- END -%] [%- MACRO GENERATE_CPP_SLOTS(originalClassName, 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_CPP_SLOTS(originalClassName, xmi.findnodes("//packagedElement[(@xmi:type=\"uml:Class\" or @xmi:type=\"uml:Stereotype\") and @name=\"${parentName}\"]"), visitedClasses, redefinedProperties) -%] [%- END -%] [%- END -%] [%- SET found = "false" -%] [%- SET className = class.findvalue("@name") -%] [% FOREACH attribute = class.findnodes("ownedAttribute") -%] [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] [%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 -%] [%- IF found == "false" -%] // SLOTS FOR OWNED ATTRIBUTES [${className}] [%- SET found = "true" -%] [% END -%] [%- SET attributeName = attribute.findvalue("@name").ucfirst -%] [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] [%- SET originalQtType = QT_TYPE(namespace, attribute, "true") -%] [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" -%] [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] void Q${namespace}${originalClassName}Object::add${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*') %]${qtAttribute}) [%- ELSE %] void Q${namespace}${originalClassName}Object::add${attributeName}(${originalQtType.remove("QSet<").remove("QList<").replace(">", "")} ${qtAttribute}) [%- END %] { [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] qmodelingelementproperty_cast(this)->add${attributeName}(qmodelingelementproperty_cast<${originalQtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*')}>(${qtAttribute})); [%- ELSE %] qmodelingelementproperty_cast(this)->add${attributeName}(${qtAttribute}); [%- END %] emit ${PLURALFORM(qtAttribute, attribute).remove('_$')}Changed(this->${PLURALFORM(qtAttribute, attribute)}()); } [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] void Q${namespace}${originalClassName}Object::remove${attributeName}([% qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*') %]${qtAttribute}) [%- ELSE %] void Q${namespace}${originalClassName}Object::remove${attributeName}(${originalQtType.remove("QSet<").remove("QList<").replace(">", "")} ${qtAttribute}) [%- END %] { [%- IF qtType.remove("QSet<").remove("QList<").match('\*') %] qmodelingelementproperty_cast(this)->remove${attributeName}(qmodelingelementproperty_cast<${originalQtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*')}>(${qtAttribute})); [%- ELSE %] qmodelingelementproperty_cast(this)->remove${attributeName}(${qtAttribute}); [%- END %] emit ${PLURALFORM(qtAttribute, attribute).remove('_$')}Changed(this->${PLURALFORM(qtAttribute, attribute)}()); } [%- ELSIF qtType.match('\*$') %] void Q${namespace}${originalClassName}Object::set${attributeName}(${qtType}${qtAttribute}) { qmodelingelementproperty_cast(this)->set${attributeName}(qmodelingelementproperty_cast<${originalQtType}>(${qtAttribute})); [%- IF attributeName.upper != attributeName %] emit ${attributeName.lcfirst}Changed(this->${qtAttribute}()); [%- ELSE %] emit ${attributeName}Changed(this->${attributeName}()); [%- END %] } [%- ELSE %] void Q${namespace}${originalClassName}Object::set${attributeName.remove("^Is")}(${qtType}${qtAttribute}) { qmodelingelementproperty_cast(this)->set${attributeName.remove("^Is")}(${qtAttribute}); [%- IF attributeName.upper != attributeName %] emit ${attributeName.lcfirst}Changed(this->${qtAttribute}()); [%- ELSE %] emit ${attributeName}Changed(this->${attributeName}()); [%- END %] } [%- END -%] [%- IF attribute.findvalue("defaultValue/@xmi:type") != "" %] void Q${namespace}${originalClassName}Object::unset${qtAttribute.remove("^is").ucfirst}() { Q_D(QModelingObject); [% 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('\*$') -%] [%- IF defaultType == "uml:LiteralBoolean" -%] [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%] [%- IF defaultValue != "" %] set${qtAttribute.remove("^is").ucfirst}(${defaultValue}); [%- ELSE -%] set${qtAttribute.remove("^is").ucfirst}(false); [%- END -%] [%- ELSIF defaultType == "uml:InstanceValue" -%] [%- SET defaultInstance = attribute.findvalue("defaultValue/@instance") -%] set${qtAttribute.remove("^is").ucfirst}(Qt${namespace}::${defaultInstance.split("-").0}${defaultInstance.split("-").1.ucfirst}); [%- ELSIF defaultType == "uml:LiteralInteger" -%] [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%] [%- IF defaultValue != "" -%] set${qtAttribute.remove("^is").ucfirst}(${defaultValue}); [%- ELSE -%] set${qtAttribute.remove("^is").ucfirst}(0); [%- END -%] [%- ELSIF defaultType == "uml:LiteralUnlimitedNatural" -%] [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%] [%- IF defaultValue != "" -%] set${qtAttribute.remove("^is").ucfirst}(QStringLiteral("${defaultValue}")); [%- ELSE -%] set${qtAttribute.remove("^is").ucfirst}(QStringLiteral("")); [%- END -%] [%- ELSIF type.match('\*$') -%] set${qtAttribute.remove("^is").ucfirst}(0); [%- END -%] [%- ELSIF xmi.findvalue("//packagedElement[@xmi:id=\"${type}\"]/xmi:type") == "uml:Enumeration" -%] set${qtAttribute.remove("^is").ucfirst}(Qt${namespace}::${type}None); [%- END %] d->modifiedResettableProperties.removeAll(QStringLiteral("${attributeName.lcfirst}")); } [%- END -%] [%- IF loop.last %] [% END -%] [%- END %] [%- END -%] [%- MACRO GENERATE_FWD_DECLARATIONS(class, visitedClasses, forwards, useNamespace, superclasses, recursive) BLOCK -%] [%- IF recursive != "false" -%] [%- FOREACH parent IN class.findnodes("generalization") -%] [%- SET parentName = parent.findvalue("@general") -%] [%- IF visitedClasses.grep("^${parentName}$").size == 0 -%] [%- visitedClasses.push("${parentName}") -%] [%- GENERATE_FWD_DECLARATIONS(xmi.findnodes("//packagedElement[(@xmi:type=\"uml:Class\" or @xmi:type=\"uml:Stereotype\") and @name=\"${parentName}\"]"), visitedClasses, forwards, useNamespace, superclasses, recursive) -%] [%- END -%] [%- END -%] [%- END -%] [%- FOREACH forward = class.findnodes("ownedAttribute[@type] | ownedOperation/ownedParameter[@type] | ownedAttribute/type | ownedOperation/ownedParameter/type") -%] [%- SET forwardName = forward.findvalue('@type') -%] [%- IF forwardName == "" -%][%- SET forwardName = forward.findvalue('@xmi:idref') -%][%- END -%] [%- IF forwardName == "" -%][%- SET forwardName = forward.findvalue('@href') -%][%- END -%] [%- NEXT IF forwardName.match('PrimitiveTypes') -%] [%- SET localNamespace = namespace -%] [%- IF forwardName.split('#').first.split('/').last != forwardName -%] [%- SET localNamespace = forwardName.split('#').first.split('/').last.split('\.').first.lower.ucfirst -%] [%- SET forwardName = forwardName.split('#').last -%] [%- END -%] [%- IF xmi.findnodes("//packagedElement[@xmi:type='uml:Enumeration' and @name='$forwardName']").findvalue("@name") != "" -%] [%- useNamespace.push("true") -%] [%- ELSE -%] [%- IF forwardName != className && superclasses.grep("^${localNamespace}${forwardName}\$").size == 0 -%][%- forwards.push("Qt${localNamespace}/Q${localNamespace}${forwardName}") -%][%- END -%] [%- END -%] [%- END -%] [%- 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\" or @xmi:type=\"uml:Stereotype\") 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 qtAttribute = QT_ATTRIBUTE(attribute) -%] [%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 -%] [%- NEXT IF attribute.findvalue("@aggregation") != "composite" && qtType.match('\*') -%] [%- IF qtType.match("QList|QSet") %] 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 %] c->add${attributeName.ucfirst}(element); [%- END -%] [%- ELSIF qtType.match('\*') %] if (${qtAttribute}()) c->set${attributeName.ucfirst}(dynamic_cast<${qtType.remove("QList<").remove("QSet<").remove(">").replace('\* ', '*')}>(${qtAttribute}()->clone())); [%- ELSE %] c->set${attributeName.ucfirst.remove("^Is")}(${qtAttribute}()); [%- END -%] [%- END %] [%- END -%] [%- MACRO SET_GROUP_PROPERTIES(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_GROUP_PROPERTIES(xmi.findnodes("//packagedElement[(@xmi:type=\"uml:Class\" or @xmi:type=\"uml:Stereotype\") and @name=\"${parentName}\"]"), visitedClasses, redefinedProperties) -%] [%- END -%] [%- END -%] [%- SET className = class.findvalue("@name") %] d->propertyGroups << QStringLiteral("Q${namespace}${className}"); [%- 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 %] d->groupProperties.insert(QStringLiteral("Q${namespace}${className}"), new QMetaProperty(metaObject->property(metaObject->indexOfProperty("${PLURALFORM(qtAttribute, attribute)}")))); [%- END %] [%- END -%] [%- MACRO SET_PROPERTY_DATA(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_PROPERTY_DATA(xmi.findnodes("//packagedElement[(@xmi:type=\"uml:Class\" or @xmi:type=\"uml:Stereotype\") and @name=\"${parentName}\"]"), visitedClasses, redefinedProperties) -%] [%- END -%] [%- END -%] [%- SET className = class.findvalue("@name") %] [%- FOREACH attribute = class.findnodes("ownedAttribute") -%] [%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%] [%- SET association = attribute.findvalue("@association") -%] [%- IF attribute.findvalue("@aggregation") == "composite" %] Q_DECLARE_METAPROPERTY_INFO(Q${namespace}${className}, ${PLURALFORM(qtAttribute, attribute)}, AggregationRole, QStringLiteral("composite")); [%- ELSE %] Q_DECLARE_METAPROPERTY_INFO(Q${namespace}${className}, ${PLURALFORM(qtAttribute, attribute)}, AggregationRole, QStringLiteral("none")); [%- END %] Q_DECLARE_METAPROPERTY_INFO(Q${namespace}${className}, ${PLURALFORM(qtAttribute, attribute)}, PropertyClassRole, QStringLiteral("Q${namespace}${className}")); Q_DECLARE_METAPROPERTY_INFO(Q${namespace}${className}, ${PLURALFORM(qtAttribute, attribute)}, PropertyTypeRole, QStringLiteral("${QT_TYPE(namespace, attribute, "true").trim}")); Q_DECLARE_METAPROPERTY_INFO(Q${namespace}${className}, ${PLURALFORM(qtAttribute, attribute)}, IsDerivedRole, [% IF attribute.findvalue("@isDerived") == "true" %]true[% ELSE %]false[% END %]); Q_DECLARE_METAPROPERTY_INFO(Q${namespace}${className}, ${PLURALFORM(qtAttribute, attribute)}, IsDerivedUnionRole, [% IF attribute.findvalue("@isDerivedUnion") == "true" %]true[% ELSE %]false[% END %]); Q_DECLARE_METAPROPERTY_INFO(Q${namespace}${className}, ${PLURALFORM(qtAttribute, attribute)}, DocumentationRole, QStringLiteral("${attribute.findvalue("ownedComment/body/text()")}")); Q_DECLARE_METAPROPERTY_INFO(Q${namespace}${className}, ${PLURALFORM(qtAttribute, attribute)}, RedefinedPropertiesRole, QStringLiteral("${attribute.findvalue("@redefinedProperty")}")); Q_DECLARE_METAPROPERTY_INFO(Q${namespace}${className}, ${PLURALFORM(qtAttribute, attribute)}, SubsettedPropertiesRole, QStringLiteral("${attribute.findvalue("@subsettedProperty")}")); Q_DECLARE_METAPROPERTY_INFO(Q${namespace}${className}, ${PLURALFORM(qtAttribute, attribute)}, OppositeEndRole, QStringLiteral(" [%- IF association != "" -%] [%- FOREACH memberEnd = xmi.findvalue("//packagedElement[(@xmi:type=\"uml:Association\" or @xmi:type=\"uml:Extension\") and @name=\"${association}\"]/@memberEnd").split(' ') -%] [%- NEXT IF memberEnd == className.replace('$', "-${attribute.findvalue(\"@name\")}") -%] [%- SET oppositeProperty = xmi.findnodes("//packagedElement[(@xmi:type=\"uml:Class\" or @xmi:type=\"uml:Stereotype\") and @name=\"${memberEnd.split('-').0}\"]/ownedAttribute[@name=\"${memberEnd.split('-').1}\"]") -%] [%- IF oppositeProperty.findvalue("@name") != "" -%]${oppositeProperty.findvalue("@xmi:id")}[%- END -%] [%- END -%] [%- END -%] ")); [%- END %] [%- END -%] [%- MACRO GENERATE_SIGNALS(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_SIGNALS(xmi.findnodes("//packagedElement[(@xmi:type=\"uml:Class\" or @xmi:type=\"uml:Stereotype\") and @name=\"${parentName}\"]"), visitedClasses, redefinedProperties) -%] [%- END -%] [%- END -%] [%- SET found = "false" -%] [%- SET className = class.findvalue("@name") -%] [%- FOREACH attribute IN class.findnodes("ownedAttribute") -%] [%- IF found == "false" %] // Signals for owned attributes [${className}] [%- SET found = "true" -%] [%- END %] [%- SET qtAttribute = QT_ATTRIBUTE(attribute) %] [%- NEXT IF redefinedProperties.grep("^${className}-${qtAttribute}$").size > 0 -%] [%- SET qtType = QT_TYPE(namespace, attribute, "false") -%] [%- SET readOnly = attribute.findvalue("@isReadOnly") -%] [%- SET attributeName = attribute.findvalue("@name").ucfirst %] void ${PLURALFORM(qtAttribute, attribute).remove('_$')}Changed(${qtType}${PLURALFORM(qtAttribute, attribute)}); [%- END %] [%- END -%]