/** 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; }
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; }
/** 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; }
/** * This is really an auxiliary method for loadFromMDL() but is kept in a * separate file to reflect that it is not coupled with the parser * (other than by the PetalNode.) * * @param root the root of the tree * @return true for success. */ bool petalTree2Uml(PetalNode *root) { if (root == NULL) { uError() << "petalTree2Uml: root is NULL"; return false; } if (root->name() != "Design") { uError() << "petalTree2Uml: expecting root name Design"; return false; } //*************************** import Logical View ******************************** PetalNode *root_category = root->findAttribute("root_category").node; if (root_category == NULL) { uError() << "petalTree2Uml: cannot find root_category"; return false; } if (root_category->name() != "Class_Category") { uError() << "petalTree2Uml: expecting root_category object Class_Category"; return false; } PetalNode *logical_models = root_category->findAttribute("logical_models").node; if (logical_models == NULL) { uError() << "petalTree2Uml: cannot find logical_models"; return false; } UMLDoc *umldoc = UMLApp::app()->document(); umldoc->setCurrentRoot(Uml::ModelType::Logical); Import_Utils::assignUniqueIdOnCreation(false); PetalNode::NameValueList atts = logical_models->attributes(); for (int i = 0; i < atts.count(); ++i) { umbrellify(atts[i].second.node); } // Shorthand for UMLApp::app()->listView() UMLListView *lv = UMLApp::app()->listView(); //*************************** import Use Case View ******************************** umldoc->setCurrentRoot(Uml::ModelType::UseCase); importView(root, "root_usecase_package", "logical_models", lv->theUseCaseView()); //*************************** import Component View ******************************* umldoc->setCurrentRoot(Uml::ModelType::Component); importView(root, "root_subsystem", "physical_models", lv->theComponentView()); //*************************** import Deployment View ****************************** umldoc->setCurrentRoot(Uml::ModelType::Deployment); importView(root, "process_structure", "ProcsNDevs", lv->theDeploymentView()); //*************************** wrap up ******************************** umldoc->setCurrentRoot(Uml::ModelType::Logical); Import_Utils::assignUniqueIdOnCreation(true); umldoc->resolveTypes(); return true; }
/** * Copy operation. * @param fromView flag if it is from view * @return the mime data */ QMimeData* UMLClipboard::copy(bool fromView/*=false*/) { //Clear previous copied data m_AssociationList.clear(); m_ItemList.clear(); m_ObjectList.clear(); m_ViewList.clear(); UMLDragData *data = 0; QPixmap* png = 0; UMLListView * listView = UMLApp::app()->listView(); if (fromView) { m_type = clip4; UMLScene *scene = UMLApp::app()->currentView()->umlScene(); scene->checkSelections(); m_WidgetList = scene->selectedWidgetsExt(); //if there is no selected widget then there is no copy action if (!m_WidgetList.count()) { return 0; } m_AssociationList = scene->selectedAssocs(); scene->copyAsImage(png); } else { //if the copy action is being performed from the ListView UMLListViewItemList itemsSelected = listView->selectedItems(); if (itemsSelected.count() <= 0) { return 0; } //Set What type of copy operation are we performing and //also fill m_ViewList with all the selected Diagrams setCopyType(itemsSelected); //if we are copying a diagram or part of a diagram, select the items //on the ListView that correspond to a UseCase, Actor or Concept //in the Diagram if (m_type == clip2) { //Fill the member lists with all the object and stuff to be copied //to the clipboard itemsSelected.clear(); //For each selected view select all the Actors, USe Cases and Concepts //widgets in the ListView foreach (UMLView* view, m_ViewList ) { UMLObjectList objects = view->umlScene()->umlObjects(); foreach (UMLObject* o, objects ) { UMLListViewItem *item = listView->findUMLObject(o); if (item) { listView->setCurrentItem(item); } } }
/** * Returns true if the UMLListViewItem of the given ID is a parent of * this UMLListViewItem. */ bool UMLListViewItem::isOwnParent(Uml::ID::Type listViewItemID) { UMLListView* listView = static_cast<UMLListView*>(treeWidget()); QTreeWidgetItem *lvi = static_cast<QTreeWidgetItem*>(listView->findItem(listViewItemID)); if (lvi == 0) { uError() << "ListView->findItem(" << Uml::ID::toString(listViewItemID) << ") returns NULL"; return true; } for (QTreeWidgetItem *self = static_cast<QTreeWidgetItem*>(this); self; self = self->parent()) { if (lvi == self) return true; } return false; }
/** * Loads a "listitem" tag, this is only used by the clipboard currently. */ bool UMLListViewItem::loadFromXMI(QDomElement& qElement) { QString id = qElement.attribute(QLatin1String("id"), QLatin1String("-1")); QString type = qElement.attribute(QLatin1String("type"), QLatin1String("-1")); QString label = qElement.attribute(QLatin1String("label")); QString open = qElement.attribute(QLatin1String("open"), QLatin1String("1")); if (!label.isEmpty()) setText(label); else if (id == QLatin1String("-1")) { uError() << "Item of type " << type << " has neither ID nor label"; return false; } m_id = Uml::ID::fromString(id); if (m_id != Uml::ID::None) { UMLListView* listView = static_cast<UMLListView*>(treeWidget()); m_object = listView->document()->findObjectById(m_id); } m_type = (ListViewType)(type.toInt()); if (m_object) updateObject(); setOpen((bool)open.toInt()); return true; }
/** If clipboard has mime type application/x-uml-clip1, Pastes the data from the clipboard into the current Doc */ bool UMLClipboard::pasteClip1(QMimeSource* data) { UMLObjectList objects; if (! UMLDrag::decodeClip1(data, objects)) { return false; } UMLListView *lv = UMLApp::app()->getListView(); if ( !lv->startedCopy() ) return true; lv->setStartedCopy(false); /* If we get here we are pasting after a Copy and need to // paste possible children. UMLListViewItem* itemdata = 0; UMLListViewItemListIt it(itemdatalist); while ( (itemdata=it.current()) != 0 ) { if(itemdata -> childCount()) { if(!pasteChildren(itemdata, idchanges)) { return false; } } ++it; } */ return true; }
/** * This slot is called to finish item editing */ void UMLListViewItem::slotEditFinished(const QString &newText) { m_label = text(0); DEBUG(DBG_LVI) << this << "text=" << newText; UMLListView* listView = static_cast<UMLListView*>(treeWidget()); UMLDoc* doc = listView->document(); if (newText == m_label) { return; } if (newText.isEmpty()) { cancelRenameWithMsg(); return; } switch (m_type) { case lvt_UseCase: case lvt_Actor: case lvt_Class: case lvt_Package: case lvt_UseCase_Folder: case lvt_Logical_Folder: case lvt_Component_Folder: case lvt_Deployment_Folder: case lvt_EntityRelationship_Folder: case lvt_Interface: case lvt_Datatype: case lvt_Enum: case lvt_EnumLiteral: case lvt_Subsystem: case lvt_Component: case lvt_Port: case lvt_Node: case lvt_Category: if (m_object == 0 || !doc->isUnique(newText)) { cancelRenameWithMsg(); return; } UMLApp::app()->executeCommand(new Uml::CmdRenameUMLObject(m_object, newText)); doc->setModified(true); m_label = newText; break; case lvt_Operation: { if (m_object == 0) { cancelRenameWithMsg(); return; } UMLOperation *op = static_cast<UMLOperation*>(m_object); UMLClassifier *parent = static_cast<UMLClassifier *>(op->parent()); Model_Utils::OpDescriptor od; Model_Utils::Parse_Status st = Model_Utils::parseOperation(newText, od, parent); if (st == Model_Utils::PS_OK) { // TODO: Check that no operation with the exact same profile exists. UMLApp::app()->executeCommand(new Uml::CmdRenameUMLObject(op, od.m_name)); op->setType(od.m_pReturnType); UMLAttributeList parmList = op->getParmList(); const int newParmListCount = parmList.count(); if (newParmListCount > od.m_args.count()) { // Remove parameters at end of of list that no longer exist. for (int i = od.m_args.count(); i < newParmListCount; i++) { UMLAttribute *a = parmList.at(i); op->removeParm(a, false); } } Model_Utils::NameAndType_ListIt lit = od.m_args.begin(); for (int i = 0; lit != od.m_args.end(); ++lit, ++i) { const Model_Utils::NameAndType& nm_tp = *lit; UMLAttribute *a; if (i < newParmListCount) { a = parmList.at(i); } else { a = new UMLAttribute(op); a->setID(UniqueID::gen()); } UMLApp::app()->executeCommand(new Uml::CmdRenameUMLObject(a, nm_tp.m_name)); a->setType(nm_tp.m_type); a->setParmKind(nm_tp.m_direction); a->setInitialValue(nm_tp.m_initialValue); if (i >= newParmListCount) { op->addParm(a); } } m_label = op->toString(Uml::SignatureType::SigNoVis); } else { KMessageBox::error(0, Model_Utils::psText(st), i18n("Rename canceled")); } setText(m_label); break; } case lvt_Attribute: case lvt_EntityAttribute: { if (m_object == 0) { cancelRenameWithMsg(); return; } UMLClassifier *parent = static_cast<UMLClassifier*>(m_object->parent()); Model_Utils::NameAndType nt; Uml::Visibility::Enum vis; Model_Utils::Parse_Status st; st = Model_Utils::parseAttribute(newText, nt, parent, &vis); if (st == Model_Utils::PS_OK) { UMLObject *exists = parent->findChildObject(newText); if (exists) { cancelRenameWithMsg(); return; } UMLApp::app()->executeCommand(new Uml::CmdRenameUMLObject(m_object, nt.m_name)); UMLAttribute *pAtt = static_cast<UMLAttribute*>(m_object); pAtt->setType(nt.m_type); pAtt->setVisibility(vis); pAtt->setParmKind(nt.m_direction); pAtt->setInitialValue(nt.m_initialValue); m_label = pAtt->toString(Uml::SignatureType::SigNoVis); } else { KMessageBox::error(0, Model_Utils::psText(st), i18n("Rename canceled")); } setText(m_label); break; } case lvt_PrimaryKeyConstraint: case lvt_UniqueConstraint: case lvt_ForeignKeyConstraint: case lvt_CheckConstraint: { if (m_object == 0) { cancelRenameWithMsg(); return; } UMLEntity *parent = static_cast<UMLEntity*>(m_object->parent()); QString name; Model_Utils::Parse_Status st; st = Model_Utils::parseConstraint(newText, name, parent); if (st == Model_Utils::PS_OK) { UMLObject *exists = parent->findChildObject(name); if (exists) { cancelRenameWithMsg(); return; } UMLApp::app()->executeCommand(new Uml::CmdRenameUMLObject(m_object, name)); UMLEntityConstraint* uec = static_cast<UMLEntityConstraint*>(m_object); m_label = uec->toString(Uml::SignatureType::SigNoVis); } else { KMessageBox::error(0, Model_Utils::psText(st), i18n("Rename canceled")); } setText(m_label); break; } case lvt_Template: { if (m_object == 0) { cancelRenameWithMsg(); return; } UMLClassifier *parent = static_cast<UMLClassifier*>(m_object->parent()); Model_Utils::NameAndType nt; Model_Utils::Parse_Status st = Model_Utils::parseTemplate(newText, nt, parent); if (st == Model_Utils::PS_OK) { UMLObject *exists = parent->findChildObject(newText); if (exists) { cancelRenameWithMsg(); return; } UMLApp::app()->executeCommand(new Uml::CmdRenameUMLObject(m_object, nt.m_name)); UMLTemplate *tmpl = static_cast<UMLTemplate*>(m_object); tmpl->setType(nt.m_type); m_label = tmpl->toString(Uml::SignatureType::SigNoVis); } else { KMessageBox::error(0, Model_Utils::psText(st), i18n("Rename canceled")); } setText(m_label); break; } case lvt_UseCase_Diagram: case lvt_Class_Diagram: case lvt_Sequence_Diagram: case lvt_Collaboration_Diagram: case lvt_State_Diagram: case lvt_Activity_Diagram: case lvt_Component_Diagram: case lvt_Deployment_Diagram: { UMLView *view = doc->findView(ID()); if (view == 0) { cancelRenameWithMsg(); return; } UMLView *anotherView = doc->findView(view->umlScene()->type(), newText); if (anotherView && anotherView->umlScene()->ID() == ID()) { anotherView = 0; } if (anotherView) { cancelRenameWithMsg(); return; } view->umlScene()->setName(newText); setText(newText); doc->signalDiagramRenamed(view); break; } default: KMessageBox::error(0, i18n("Renaming an item of listview type %1 is not yet implemented.", m_type), i18n("Function Not Implemented")); setText(m_label); break; } doc->setModified(true); }
/** 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; }
QMimeSource* UMLClipboard::copy(bool fromView/*=false*/) { //Clear previous copied data m_AssociationList.clear(); m_ItemList.clear(); m_ObjectList.clear(); m_ViewList.clear(); UMLDrag *data = 0; QPixmap* png = 0; UMLListView * listView = UMLApp::app()->getListView(); UMLListViewItemList selectedItems; selectedItems.setAutoDelete(false); if(fromView) { m_type = clip4; UMLView *view = UMLApp::app()->getCurrentView(); view->checkSelections(); if(!view->getSelectedWidgets(m_WidgetList)) { return 0; } //if there is no selected widget then there is no copy action if(!m_WidgetList.count()) { return 0; } m_AssociationList = view->getSelectedAssocs(); view->copyAsImage(png); } else { //if the copy action is being performed from the ListView if(!listView->getSelectedItems(selectedItems)) { return 0; } //Set What type of copy operation are we performing and //also fill m_ViewList with all the selected Diagrams setCopyType(selectedItems); //if we are copying a diagram or part of a diagram, select the items //on the ListView that correspond to a UseCase, Actor or Concept //in the Diagram if(m_type == clip2) { //Fill the member lists with all the object and stuff to be copied //to the clipboard selectedItems.clear(); //For each selected view select all the Actors, USe Cases and Concepts //widgets in the ListView for (UMLViewListIt vit(m_ViewList); vit.current(); ++vit) { UMLObjectList objects = vit.current()->getUMLObjects(); for (UMLObjectListIt oit(objects); oit.current(); ++oit) { UMLObject *o = oit.current(); UMLListViewItem *item = listView->findUMLObject(o); if(item) { listView->setSelected(item, true); } } } if(!listView->getSelectedItems(selectedItems)) { return 0; } } if(!fillSelectionLists(selectedItems)) { return 0; } } int i =0; switch(m_type) { case clip1: data = new UMLDrag(m_ObjectList); break; case clip2: data = new UMLDrag(m_ObjectList, m_ItemList, m_ViewList); break; case clip3: data = new UMLDrag(m_ItemList); break; case clip4: if(png) { UMLView *view = UMLApp::app()->getCurrentView(); data = new UMLDrag(m_ObjectList, m_WidgetList, m_AssociationList, *png, view->getType()); } else { return 0; } break; case clip5: data = new UMLDrag(m_ObjectList, i); // The int i is used to differentiate // which UMLDrag constructor gets called. break; } return (QMimeSource*)data; }