/** If clipboard has mime type application/x-uml-clip3, Pastes the data from the clipboard into the current Doc */ bool UMLClipboard::pasteClip3(QMimeSource* data) { UMLDoc *doc = UMLApp::app()->getDocument(); UMLListViewItemList itemdatalist; UMLListViewItem* item = 0; UMLListViewItem* itemdata = 0; IDChangeLog* idchanges = doc->getChangeLog(); if(!idchanges) { return false; } UMLListView *listView = UMLApp::app()->getListView(); bool result = UMLDrag::decodeClip3(data, itemdatalist, listView); if(!result) { return false; } UMLListViewItemListIt it(itemdatalist); while ( (itemdata=it.current()) != 0 ) { item = listView->createItem(*itemdata, *idchanges); if(itemdata -> childCount()) { if(!pasteChildren(item, idchanges)) { return false; } } ++it; } return result; }
/** If clipboard has mime type application/x-uml-clip2, Pastes the data from the clipboard into the current Doc */ bool UMLClipboard::pasteClip2(QMimeSource* data) { UMLDoc *doc = UMLApp::app()->getDocument(); UMLListViewItemList itemdatalist; UMLObjectList objects; objects.setAutoDelete(false); UMLViewList views; IDChangeLog* idchanges = 0; bool result = UMLDrag::decodeClip2(data, objects, itemdatalist, views); if(!result) { return false; } UMLObject *obj = 0; UMLObjectListIt object_it(objects); idchanges = doc->getChangeLog(); if(!idchanges) { return false; } while ( (obj=object_it.current()) != 0 ) { ++object_it; if(!doc->assignNewIDs(obj)) { kDebug()<<"UMLClipboard: error adding umlobject"<<endl; return false; } } UMLView * pView = 0; UMLViewListIt view_it( views ); while ( ( pView =view_it.current()) != 0 ) { ++view_it; if( !doc->addUMLView( pView ) ) { return false; } } UMLListView *listView = UMLApp::app()->getListView(); UMLListViewItem* item = 0; UMLListViewItem* itemdata = 0; UMLListViewItemListIt it(itemdatalist); while ( (itemdata=it.current()) != 0 ) { item = listView->createItem(*itemdata, *idchanges); if(!item) { return false; } if(itemdata -> childCount()) { if(!pasteChildren(item, idchanges)) { return false; } } ++it; } return result; }
/** 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; }
/** If clipboard has mime type application/x-uml-clip4, Pastes the data from the clipboard into the current Doc */ bool UMLClipboard::pasteClip4(QMimeSource* data) { UMLDoc *doc = UMLApp::app()->getDocument(); UMLObjectList objects; objects.setAutoDelete(false); UMLWidgetList widgets; widgets.setAutoDelete(false); AssociationWidgetList assocs; assocs.setAutoDelete(false); IDChangeLog* idchanges = 0; Uml::Diagram_Type diagramType; if( !UMLDrag::decodeClip4(data, objects, widgets, assocs, diagramType) ) { return false; } if( diagramType != UMLApp::app()->getCurrentView()->getType() ) { if( !checkPasteWidgets(widgets) ) { assocs.setAutoDelete(true); assocs.clear(); return false; } } UMLObjectListIt object_it(objects); idchanges = doc->getChangeLog(); if(!idchanges) { return false; } //make sure the file we are pasting into has the objects //we need if there are widgets to be pasted UMLObject* obj = 0; while ( (obj=object_it.current()) != 0 ) { ++object_it; if(!doc->assignNewIDs(obj)) { return false; } } //now add any widget we are want to paste bool objectAlreadyExists = false; UMLView *currentView = UMLApp::app()->getCurrentView(); currentView->beginPartialWidgetPaste(); UMLWidget* widget =0; UMLWidgetListIt widget_it(widgets); while ( (widget=widget_it.current()) != 0 ) { ++widget_it; Uml::IDType oldId = widget->getID(); Uml::IDType newId = idchanges->findNewID(oldId); if (currentView->findWidget(newId)) { kError() << "UMLClipboard::pasteClip4: widget (oldID=" << ID2STR(oldId) << ", newID=" << ID2STR(newId) << ") already exists in target view." << endl; widgets.remove(widget); delete widget; objectAlreadyExists = true; } else if (! currentView->addWidget(widget, true)) { currentView->endPartialWidgetPaste(); return false; } } //now paste the associations AssociationWidget* assoc; AssociationWidgetListIt assoc_it(assocs); while ( (assoc=assoc_it.current()) != 0 ) { ++assoc_it; if (!currentView->addAssociation(assoc, true)) { currentView->endPartialWidgetPaste(); return false; } } //Activate all the pasted associations and widgets currentView->activate(); currentView->endPartialWidgetPaste(); /* UMLListView *listView = UMLApp::app()->getListView(); UMLListViewItem* item = 0; UMLListViewItem* itemdata = 0; UMLListViewItemListIt it(itemdatalist); while ( (itemdata=it.current()) != 0 ) { item = listView->createItem(*itemdata, *idchanges); if(!item) { return false; } if(itemdata -> childCount()) { if(!pasteChildren(item, idchanges)) { return false; } } ++it; }*/ if (objectAlreadyExists) { pasteItemAlreadyExists(); } return true; }