/** 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; }
void SQLWriter::writeClass(UMLClassifier *c) { if(!c) { kDebug()<<"Cannot write class of NULL concept!" << endl; return; } const bool isClass = !c->isInterface(); QString classname = cleanName(c->getName()); //find an appropriate name for our file QString fileName = findFileName(c, ".sql"); if (fileName.isEmpty()) { emit codeGenerated(c, false); return; } QFile file; if( !openFile(file, fileName) ) { emit codeGenerated(c, false); return; } //Start generating the code!! QTextStream sql(&file); //try to find a heading file (license, coments, etc) QString str; str = getHeadingFile(".sql"); if(!str.isEmpty()) { str.replace(QRegExp("%filename%"),fileName); str.replace(QRegExp("%filepath%"),file.name()); sql<<str<<m_endl; } //Write class Documentation if there is somthing or if force option if(forceDoc() || !c->getDoc().isEmpty()) { sql << m_endl << "--" << m_endl; sql<<"-- TABLE: "<<classname<<m_endl; sql<<formatDoc(c->getDoc(),"-- "); sql << "-- " << m_endl << m_endl; } sql << "CREATE TABLE "<< classname << " ( " << m_endl; if (isClass) writeAttributes(c, sql); sql << m_endl << ");" << m_endl; QMap<UMLAssociation*,UMLAssociation*> constraintMap; // so we don't repeat constraint UMLAssociationList aggregations = c->getAggregations(); if( forceSections() || !aggregations.isEmpty() ) { for(UMLAssociation* a = aggregations.first(); a; a = aggregations.next()) { UMLObject *objA = a->getObject(Uml::A); UMLObject *objB = a->getObject(Uml::B); if (objA->getID() == c->getID() && objB->getID() != c->getID()) continue; constraintMap[a] = a; } } QMap<UMLAssociation*,UMLAssociation*>::Iterator itor = constraintMap.begin(); for (;itor != constraintMap.end();itor++) { UMLAssociation* a = itor.data(); sql << "ALTER TABLE "<< classname << " ADD CONSTRAINT " << a->getName() << " FOREIGN KEY (" << a->getRoleName(Uml::B) << ") REFERENCES " << a->getObject(Uml::A)->getName() << " (" << a->getRoleName(Uml::A) << ");" << m_endl; } file.close(); emit codeGenerated(c, true); }