/** * 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); } } }
/** Adds the children of a UMLListViewItem to m_ItemList */ bool UMLClipboard::insertItemChildren(UMLListViewItem * Item, UMLListViewItemList& SelectedItems) { if(Item->childCount()) { UMLListViewItem * child = (UMLListViewItem*)Item->firstChild(); int type; while(child) { m_ItemList.append(child); type = child->getType(); if(type == Uml::lvt_Actor || type == Uml::lvt_UseCase || type == Uml::lvt_Class) { m_ObjectList.append(child->getUMLObject()); } // If the child is selected, remove it from the list of selected items // otherwise it will be inserted twice in m_ObjectList. if(child->isSelected()) { SelectedItems.remove(SelectedItems.find(child) ); } insertItemChildren(child, SelectedItems); child = (UMLListViewItem*)child->nextSibling(); } } return true; }
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; }