void CSharpWriter::writeAssociatedAttributes(UMLAssociationList &associated, UMLClassifier *c, QTextStream &cs) { UMLAssociation *a; for (a = associated.first(); a ; a = associated.next()) { if (c != a->getObject(Uml::A)) // we need to be at the A side continue; UMLObject *o = a->getObject(Uml::B); if (o == NULL) { kError() << "composition role B object is NULL" << endl; continue; } // Take name and documentaton from Role, take type name from the referenced object QString roleName = cleanName(a->getRoleName(Uml::B)); QString typeName = cleanName(o->getName()); if (roleName.isEmpty()) { roleName = QString("UnnamedRoleB_%1").arg(m_unnamedRoles++); } QString roleDoc = a->getRoleDoc(Uml::B); //FIXME:is this simple condition enough? if (a->getMulti(Uml::B).isEmpty() || a->getMulti(Uml::B) == "1") { // normal attribute writeAttribute(roleDoc, a->getVisibility(Uml::B), false, typeName, roleName, "", ( a->getVisibility(Uml::B) != Uml::Visibility::Private), cs); } else { // array roleDoc += "\n(Array of " + typeName + ')'; writeAttribute(roleDoc, a->getVisibility(Uml::B), false, "ArrayList", roleName, "", ( a->getVisibility(Uml::B) != Uml::Visibility::Private), cs); } } }
bool UMLClipboard::pasteChildren(UMLListViewItem *parent, IDChangeLog *chgLog) { if (!parent) { kWarning() << "Paste Children Error, parent missing" << endl; return false; } UMLDoc *doc = UMLApp::app()->getDocument(); UMLListView *listView = UMLApp::app()->getListView(); UMLListViewItem *childItem = static_cast<UMLListViewItem*>(parent->firstChild()); while (childItem) { Uml::IDType oldID = childItem->getID(); Uml::IDType newID = chgLog->findNewID(oldID); UMLListViewItem *shouldNotExist = listView->findItem(newID); if (shouldNotExist) { kError() << "UMLClipboard::pasteChildren: new list view item " << ID2STR(newID) << " already exists (internal error)" << endl; childItem = static_cast<UMLListViewItem*>(childItem->nextSibling()); continue; } UMLObject *newObj = doc->findObjectById(newID); if (newObj) { kDebug() << "UMLClipboard::pasteChildren: adjusting lvitem(" << ID2STR(oldID) << ") to new UMLObject(" << ID2STR(newID) << ")" << endl; childItem->setUMLObject(newObj); childItem->setText(newObj->getName()); } else { kDebug() << "UMLClipboard::pasteChildren: no UMLObject found for lvitem " << ID2STR(newID) << endl; } childItem = static_cast<UMLListViewItem*>(childItem->nextSibling()); } return true; }
QString UMLAttribute::toString(Uml::Signature_Type sig) { QString s; if(sig == Uml::st_ShowSig || sig == Uml::st_NoSig) { s = m_Vis.toString(true) + ' '; } if(sig == Uml::st_ShowSig || sig == Uml::st_SigNoVis) { // Determine whether the type name needs to be scoped. UMLObject *owningObject = static_cast<UMLObject*>(parent()); if (owningObject->getBaseType() == Uml::ot_Operation) { // The immediate parent() is the UMLOperation but we want // the UMLClassifier: owningObject = static_cast<UMLObject*>(owningObject->parent()); } UMLClassifier *ownParent = dynamic_cast<UMLClassifier*>(owningObject); if (ownParent == NULL) { kError() << "UMLAttribute::toString: parent " << owningObject->getName() << " is not a UMLClassifier" << endl; return ""; } QString typeName; UMLClassifier *type = UMLClassifierListItem::getType(); if (type) { UMLPackage *typeScope = type->getUMLPackage(); if (typeScope != ownParent && typeScope != ownParent->getUMLPackage()) typeName = type->getFullyQualifiedName(); else typeName = type->getName(); } // The default direction, "in", is not mentioned. // Perhaps we should include a pd_Unspecified in // Uml::Parameter_Direction to have better control over this. if (m_ParmKind == Uml::pd_InOut) s += "inout "; else if (m_ParmKind == Uml::pd_Out) s += "out "; // Construct the attribute text. QString string = s + getName() + " : " + typeName; if(m_InitialValue.length() > 0) string += " = " + m_InitialValue; return string; } return s + getName(); }
void UMLScene::changeUMLObjectName() { QList< QGraphicsItem * > selectedUMLObjectList( this->selectedItems() ); QListIterator< QGraphicsItem * > umlObjectIter( selectedUMLObjectList ); while( umlObjectIter.hasNext() ) { UMLObject * umlObject = dynamic_cast< UMLObject * >( umlObjectIter.next() ); if ( !umlObject ) { QMessageBox::critical( this->views().first(), "Error", "Can not rename non UML object. Try to rename correct UML object."); return; } QString name = QInputDialog::getText( this->views().first(), QObject::tr( "Change object name" ), QObject::tr( "Enter a name" ), QLineEdit::Normal, umlObject->getName() ); umlObject->setName( name ); } }
QString UMLAttribute::getFullyQualifiedName( const QString& separator, bool includeRoot /* = false */) const { UMLOperation *op = NULL; UMLObject *owningObject = static_cast<UMLObject*>(parent()); if (owningObject->getBaseType() == Uml::ot_Operation) { op = static_cast<UMLOperation*>(owningObject); owningObject = static_cast<UMLObject*>(owningObject->parent()); } UMLClassifier *ownParent = dynamic_cast<UMLClassifier*>(owningObject); if (ownParent == NULL) { kError() << "UMLAttribute::getFullyQualifiedName(" << m_Name << "): parent " << owningObject->getName() << " is not a UMLClassifier" << endl; return ""; } QString tempSeparator = separator; if (tempSeparator.isEmpty()) tempSeparator = UMLApp::app()->activeLanguageScopeSeparator(); QString fqn = ownParent->getFullyQualifiedName(tempSeparator, includeRoot); if (op) fqn.append(tempSeparator + op->getName()); fqn.append(tempSeparator + m_Name); return fqn; }
/** If clipboard has mime type application/x-uml-clip5, Pastes the data from the clipboard into the current Doc */ bool UMLClipboard::pasteClip5(QMimeSource* data) { UMLDoc *doc = UMLApp::app()->getDocument(); UMLListView *listView = UMLApp::app()->getListView(); UMLListViewItem* lvitem = dynamic_cast<UMLListViewItem *>( listView->currentItem() ); if (!lvitem || (lvitem->getType() != Uml::lvt_Class && lvitem->getType() != Uml::lvt_Interface)) { return false; } UMLClassifier *parent = dynamic_cast<UMLClassifier *>(lvitem->getUMLObject()); if (parent == NULL) { kError() << "UMLClipboard::pasteClip5: parent is not a UMLClassifier" << endl; return false; } UMLObjectList objects; objects.setAutoDelete(false); IDChangeLog* idchanges = 0; bool result = UMLDrag::decodeClip5(data, objects, parent); if(!result) { return false; } UMLObject *obj = 0; doc->setModified(true); idchanges = doc->getChangeLog(); // Assume success if at least one child object could be pasted if (objects.count()) result = false; for (UMLObjectListIt it(objects); (obj = it.current()) != NULL; ++it) { obj->setID(doc->assignNewID(obj->getID())); switch(obj->getBaseType()) { case Uml::ot_Attribute : { UMLObject *exist = parent->findChildObject(obj->getName(), Uml::ot_Attribute); if (exist) { QString newName = parent->uniqChildName(Uml::ot_Attribute, obj->getName()); obj->setName(newName); } UMLAttribute *att = static_cast<UMLAttribute*>(obj); if (parent->addAttribute(att, idchanges)) { result = true; } else { kError() << "UMLClipboard::pasteClip5: " << parent->getName() << "->addAttribute(" << att->getName() << ") failed" << endl; } break; } case Uml::ot_Operation : { UMLOperation *op = static_cast<UMLOperation*>(obj); UMLOperation *exist = parent->checkOperationSignature(op->getName(), op->getParmList()); if (exist) { QString newName = parent->uniqChildName(Uml::ot_Operation, obj->getName()); op->setName(newName); } if (parent->addOperation(op, idchanges)) { result = true; } else { kError() << "UMLClipboard::pasteClip5: " << parent->getName() << "->addOperation(" << op->getName() << ") failed" << endl; } break; } default : kWarning() << "pasting unknown children type in clip type 5" << endl; return false; } } return result; }