/** * Reimplemented from UMLWidget::saveToXMI to save * classifierwidget data either to 'interfacewidget' or 'classwidget' * XMI element. */ void ClassifierWidget::saveToXMI(QDomDocument & qDoc, QDomElement & qElement) { QDomElement conceptElement; UMLClassifier *umlc = classifier(); QString tagName = umlc->isInterface() ? "interfacewidget" : "classwidget"; conceptElement = qDoc.createElement(tagName); UMLWidget::saveToXMI( qDoc, conceptElement ); conceptElement.setAttribute("showoperations", visualProperty(ShowOperations)); conceptElement.setAttribute("showpubliconly", visualProperty(ShowPublicOnly)); conceptElement.setAttribute("showopsigs", m_operationSignature); conceptElement.setAttribute("showpackage", visualProperty(ShowPackage)); conceptElement.setAttribute("showscope", visualProperty(ShowVisibility)); if (! umlc->isInterface()) { conceptElement.setAttribute("showattributes", visualProperty(ShowAttributes)); conceptElement.setAttribute("showattsigs", m_attributeSignature); } if (umlc->isInterface() || umlc->isAbstract()) { conceptElement.setAttribute("drawascircle", visualProperty(DrawAsCircle)); } qElement.appendChild(conceptElement); }
void CSharpWriter::writeOverridesRecursive(UMLClassifierList *superclasses, QTextStream &cs) { // oplist for implemented abstract operations UMLOperationList opabstract; opabstract.setAutoDelete(false); UMLClassifier *obj; for (obj = superclasses->first(); obj; obj = superclasses->next()) { if (!obj->isInterface() && obj->hasAbstractOps()) { // collect abstract ops UMLOperationList opl(obj->getOpList()); for (UMLOperation *op = opl.first(); op ; op = opl.next()) { if (op->getAbstract()) { opabstract.append(op); } } // write abstract implementations cs << m_endl << m_container_indent << m_indentation << "#region " << obj->getName() << " members" << m_endl << m_endl; writeOperations(opabstract,cs,false,true,true); cs << m_container_indent << m_indentation << "#endregion" << m_endl << m_endl; opabstract.clear(); } // Recurse to parent superclasses UMLClassifierList superRecursive = obj->getSuperClasses(); UMLClassifierList *superRecursivePtr =& superRecursive; if (superRecursivePtr->count() > 0) { writeOverridesRecursive(superRecursivePtr, cs); } } }
/** * Event handler for hover leave events. */ void ClassifierWidget::hoverLeaveEvent(UMLSceneHoverEvent * event) { Q_UNUSED(event); if (!visualProperty(DrawAsCircle)) { UMLClassifier* umlC = classifier(); if (umlC && !umlC->isInterface()) { m_attributeExpanderBox->setVisible(false); } m_operationExpanderBox->setVisible(false); } }
// these exist for abstract classes only (which become xs:group nodes) QStringList XMLSchemaWriter::findAttributeGroups (UMLClassifier *c) { // we need to look for any class we inherit from. IF these // have attributes, then we need to notice QStringList list; UMLClassifierList superclasses = c->findSuperClassConcepts(); // list of what inherits from us for(UMLClassifier *classifier = superclasses.first(); classifier; classifier = superclasses.next()) { if(classifier->getAbstract()) { // only classes have attributes.. if (!classifier->isInterface()) { UMLAttributeList attribs = c->getAttributeList(); if (attribs.count() > 0) list.append(getElementName(classifier)+"AttribGroupType"); } } } return list; }
void CSharpWriter::writeClass(UMLClassifier *c) { if (!c) { kDebug()<<"Cannot write class of NULL concept!" << endl; return; } QString classname = cleanName(c->getName()); //find an appropriate name for our file QString fileName = findFileName(c, ".cs"); if (fileName.isEmpty()) { emit codeGenerated(c, false); return; } QFile filecs; if (!openFile(filecs, fileName)) { emit codeGenerated(c, false); return; } QTextStream cs(&filecs); ////////////////////////////// //Start generating the code!! ///////////////////////////// //try to find a heading file (license, coments, etc) QString str; str = getHeadingFile(".cs"); if (!str.isEmpty()) { str.replace(QRegExp("%filename%"),fileName); str.replace(QRegExp("%filepath%"),filecs.name()); cs<<str<<m_endl; } UMLDoc *umldoc = UMLApp::app()->getDocument(); UMLFolder *logicalView = umldoc->getRootFolder(Uml::mt_Logical); // write generic includes cs << "using System;" << m_endl; cs << "using System.Text;" << m_endl; cs << "using System.Collections;" << m_endl; cs << "using System.Collections.Generic;" << m_endl << m_endl; //write includes and namespace UMLPackage *container = c->getUMLPackage(); if (container == logicalView) container = NULL; UMLPackageList includes; findObjectsRelated(c, includes); m_seenIncludes.clear(); //m_seenIncludes.append(logicalView); if (includes.count()) { UMLPackage *p; for (UMLPackageListIt it(includes); (p = it.current()) != NULL; ++it) { UMLClassifier *cl = dynamic_cast<UMLClassifier*>(p); if (cl) p = cl->getUMLPackage(); if (p != logicalView && m_seenIncludes.findRef(p) == -1 && p != container) { cs << "using " << p->getFullyQualifiedName(".") << ";" << m_endl; m_seenIncludes.append(p); } } cs << m_endl; } m_container_indent = ""; if (container) { cs << "namespace " << container->getFullyQualifiedName(".") << m_endl; cs << "{" << m_endl << m_endl; m_container_indent = m_indentation; m_seenIncludes.append(container); } //Write class Documentation if there is somthing or if force option if (forceDoc() || !c->getDoc().isEmpty()) { cs << m_container_indent << "/// <summary>" << m_endl; cs << formatDoc(c->getDoc(), m_container_indent + "/// " ); cs << m_container_indent << "/// </summary>" << m_endl ; } UMLClassifierList superclasses = c->getSuperClasses(); UMLAssociationList aggregations = c->getAggregations(); UMLAssociationList compositions = c->getCompositions(); UMLAssociationList realizations = c->getRealizations(); bool isInterface = c->isInterface(); m_unnamedRoles = 1; cs << m_container_indent << "public "; //check if it is an interface or regular class if (isInterface) { cs << "interface " << classname; } else { //check if class is abstract and / or has abstract methods if (c->getAbstract() || c->hasAbstractOps()) cs << "abstract "; cs << "class " << classname << (superclasses.count() > 0 ? " : ":""); // write baseclass, ignore interfaces, write error on multiple inheritance if (superclasses.count() > 0) { UMLClassifier *obj; int supers = 0; for (obj = superclasses.first(); obj; obj = superclasses.next()) { if (!obj->isInterface()) { if (supers > 0) { cs << " // AND "; } cs << cleanName(obj->getName()); supers++; } } if (supers > 1) { cs << m_endl << "//WARNING: C# does not support multiple inheritance but there is more than 1 superclass defined in your UML model!" << m_endl; } } //check for realizations UMLAssociationList realizations = c->getRealizations(); UMLAssociation *a; if (!realizations.isEmpty()) { for (a = realizations.first(); a; a = realizations.next()) { UMLClassifier *real = (UMLClassifier*)a->getObject(Uml::B); if(real != c) { // write list of realizations cs << ", " << real->getName(); } } } } cs << m_endl << m_container_indent << '{' << m_endl; //associations if (forceSections() || !aggregations.isEmpty()) { cs << m_endl << m_container_indent << m_indentation << "#region Aggregations" << m_endl << m_endl; writeAssociatedAttributes(aggregations, c, cs); cs << m_endl << m_container_indent << m_indentation << "#endregion" << m_endl; } //compositions if (forceSections() || !compositions.isEmpty()) { cs << m_endl << m_container_indent << m_indentation << "#region Compositions" << m_endl << m_endl; writeAssociatedAttributes(compositions, c, cs); cs << m_endl << m_container_indent << m_indentation << "#endregion" << m_endl; } //attributes // FIXME: C# allows Properties in interface! if (!isInterface) writeAttributes(c, cs); //operations writeOperations(c, cs); //finish file cs << m_endl << m_container_indent << "}" << m_endl << m_endl; // close class if (container) { cs << "} // end of namespace " << container->getFullyQualifiedName(".") << m_endl << m_endl; } //close files and notfiy we are done filecs.close(); emit codeGenerated(c, true); }