Autolayout::Graph * Autolayout::AutolayouterAdapter::setGraph( UMLView * view ) { if (! view) return 0; Autolayout::Graph * g=getGraph(); if (g&&g->empty()) { UMLWidgetList list = view->getWidgetList(); UMLWidget* widget; for ( widget = list.first(); widget; widget= list.next() ) { if (widget->getBaseType() == Uml::wt_Class) { g->addNode(widget->getID().c_str(),widget->getWidth(), widget->getHeight()); } } AssociationWidgetList as_list=view->getAssociationList(); AssociationWidget* assoc; AssociationWidgetListIt it(as_list); while ( (assoc = it.current()) != 0 ) { ++it; addRelationship(assoc); } } return g; }
bool UMLWidget::operator==(const UMLWidget& other) { if( this == &other ) return true; if(m_Type != other.m_Type) { return false; } if (getID() != other.getID()) return false; /* Testing the associations is already an exaggeration, no? The type and ID should uniquely identify an UMLWidget. */ if (m_Assocs.count() != other.m_Assocs.count()) { return false; } // if(getBaseType() != wt_Text) // DON'T do this for floatingtext widgets, an infinite loop will result // { AssociationWidgetListIt assoc_it( m_Assocs ); AssociationWidgetListIt assoc_it2( other.m_Assocs ); AssociationWidget * assoc = 0, *assoc2 = 0; while ( ((assoc=assoc_it.current()) != 0) && ((assoc2=assoc_it2.current()) != 0)) { ++assoc_it; ++assoc_it2; if(!(*assoc == *assoc2)) { return false; } } // } return true; // NOTE: In the comparison tests we are going to do, we don't need these values. // They will actually stop things functioning correctly so if you change these, be aware of that. /* if(m_bUseFillColour != other.m_bUseFillColour) return false; if(m_nId != other.m_nId) return false; if( m_Font != other.m_Font ) return false; if(m_nX != other.m_nX) return false; if(m_nY != other.m_nY) return false; */ }
void Autolayout::AutolayouterAdapter::updateView( UMLView* view ) { if (! view) return ; UMLWidgetList list = view->getWidgetList(); UMLWidget* widget; Graph *g=getGraph(); if (! view||!g) return ; for ( widget = list.first(); widget; widget= list.next() ) if (widget->getBaseType() == Uml::wt_Class) { Node* n =g->getNode(widget->getID().c_str()); //printf("old values widgets %s x,y:%d,%d\n",widget->getID().c_str(),widget->getX(),widget->getY()); //int x_old=widget->getX(); //int x_calc=n.getX(); //int x_calc2=30 +n.getX()-widget->getWidth()/2; widget->setX(getCanvas()->getBaseX() +n->getX()-widget->getWidth()/2); //int x=widget->getX(); widget->setY(getCanvas()->getMaxY()/2-(n->getY()+(widget->getHeight()/2))); widget->updateWidget(); } }
/** 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; }