Commit 1bfad17b authored by Joris Steyn's avatar Joris Steyn

Fix copy/paste between Umbrello instances

Clip4 now contains all the UMLObjects corresponding to the copied widgets.

Some related but obviously unused code removed. Involves a better fix than
c63e77ca for broken copy/paste of listview items.

BUG: 70926
BUG: 279788
BUG: 195803
CCBUG: 291749
CCBUG: 128068
parent 733671ce
......@@ -88,6 +88,13 @@ QMimeData* UMLClipboard::copy(bool fromView/*=false*/)
m_AssociationList = scene->selectedAssocs();
scene->copyAsImage(png);
// Clip4 needs UMLObjects because it's possible the UMLObject
// is no longer there when pasting this mime data. This happens for
// example when using cut-paste or pasting to another Umbrello
// instance.
foreach (WidgetBase* widget, m_WidgetList) {
m_ObjectList.append(widget->umlObject());
}
} else { //if the copy action is being performed from the ListView
UMLListViewItemList itemsSelected = listView->selectedItems();
if (itemsSelected.count() <= 0) {
......@@ -456,24 +463,6 @@ bool UMLClipboard::pasteClip2(const QMimeData* data)
}
}
UMLListView *listView = UMLApp::app()->listView();
listView->startUpdate();
foreach (UMLListViewItem* itemdata, itemdatalist) {
UMLListViewItem* item = listView->createItem(*itemdata, *idchanges);
if(!item) {
listView->endUpdate();
return false;
}
if(itemdata->childCount()) {
if(!pasteChildren(item, idchanges)) {
listView->endUpdate();
return false;
}
}
}
listView->endUpdate();
return result;
}
......@@ -499,18 +488,6 @@ bool UMLClipboard::pasteClip3(const QMimeData* data)
return false;
}
listView->startUpdate();
foreach (UMLListViewItem* itemdata, itemdatalist) {
UMLListViewItem* item = listView->createItem(*itemdata, *idchanges);
if(itemdata->childCount()) {
if(!pasteChildren(item, idchanges)) {
listView->endUpdate();
return false;
}
}
}
listView->endUpdate();
return result;
}
......@@ -604,24 +581,6 @@ bool UMLClipboard::pasteClip4(const QMimeData* data)
currentScene->activate();
currentScene->endPartialWidgetPaste();
/*
UMLListView *listView = UMLApp::app()->listView();
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();
}
......
......@@ -336,10 +336,6 @@ bool UMLDragData::decodeClip1(const QMimeData* mimeData, UMLObjectList& objects)
if(!doc->assignNewIDs(pObject)) {
return false;
}
UMLObject::ObjectType type = pObject->baseType();
QString newName = Model_Utils::uniqObjectName(type, pObject->umlPackage(),
pObject->name());
pObject->setName(newName);
/****************************************************************/
}
......@@ -600,9 +596,9 @@ bool UMLDragData::decodeClip3(const QMimeData* mimeData, UMLListViewItemList& um
/**
* For use when the user selects UML Objects from a
* Diagram. The Selected widegets and the relationships
* between only * selected widgets will be copied and
* also its respective ListView Items, * decodes Mime
* type = "application/x-uml-clip4
* between only selected widgets will be copied
*
* decodes Mime type = "application/x-uml-clip4"
*/
bool UMLDragData::decodeClip4(const QMimeData* mimeData, UMLObjectList& objects,
UMLWidgetList& widgets,
......@@ -647,16 +643,24 @@ bool UMLDragData::decodeClip4(const QMimeData* mimeData, UMLObjectList& objects,
//FIXME associations don't load
if (type == "UML:Association")
continue;
pObject = Object_Factory::makeObjectFromXMI(type);
UMLDoc* doc = UMLApp::app()->document();
Uml::ID::Type elmId = Uml::ID::fromString(element.attribute("xmi.id"));
pObject = doc->findObjectById(elmId);
if (!pObject) {
uWarning() << "Given wrong type of umlobject to create: " << type;
return false;
}
pObject = Object_Factory::makeObjectFromXMI(type);
if (!pObject) {
uWarning() << "Given wrong type of umlobject to create: " << type;
return false;
}
if (!pObject->loadFromXMI(element)) {
uWarning() << "Failed to load object from XMI.";
return false;
if (!pObject->loadFromXMI(element)) {
uWarning() << "Failed to load object from XMI.";
return false;
}
doc->signalUMLObjectCreated(pObject);
}
objects.append(pObject);
......
......@@ -1918,6 +1918,12 @@ bool UMLApp::editCutCopy(bool bFromView)
UMLClipboard clipboard;
QMimeData * clipdata = 0;
// If not from-view, list items are copied. This flag is
// used in UMLDragData to determine whether to assign new IDs
if (!bFromView) {
listView()->setStartedCopy(true);
}
if ((clipdata = clipboard.copy(bFromView)) != 0) {
QClipboard* clip = QApplication::clipboard();
clip->setMimeData(clipdata);//the global clipboard takes ownership of the clipdata memory
......
......@@ -1978,101 +1978,6 @@ UMLListViewItem* UMLListView::createDiagramItem(UMLView *view)
return item;
}
/**
* CHECK - This is perhaps redundant since the
* UMLListViewItemData => UMLListViewItem merge.
* Creates a new UMLListViewItem from a UMLListViewItem, if
* parent is null the ListView decides who is going to be the parent.
*/
UMLListViewItem* UMLListView::createItem(UMLListViewItem& Data, IDChangeLog& IDChanges,
UMLListViewItem* parent /*= 0*/)
{
UMLObject* pObject = 0;
UMLListViewItem* item = 0;
UMLListViewItem::ListViewType lvt = Data.type();
if (!parent) {
parent = determineParentItem(lvt);
if (!parent)
return 0;
}
switch (lvt) {
case UMLListViewItem::lvt_Actor:
case UMLListViewItem::lvt_UseCase:
case UMLListViewItem::lvt_Class:
case UMLListViewItem::lvt_Package:
case UMLListViewItem::lvt_Subsystem:
case UMLListViewItem::lvt_Component:
case UMLListViewItem::lvt_Node:
case UMLListViewItem::lvt_Artifact:
case UMLListViewItem::lvt_Interface:
case UMLListViewItem::lvt_Datatype:
case UMLListViewItem::lvt_Enum:
case UMLListViewItem::lvt_Entity:
case UMLListViewItem::lvt_Category:
case UMLListViewItem::lvt_Logical_Folder:
case UMLListViewItem::lvt_UseCase_Folder:
case UMLListViewItem::lvt_Component_Folder:
case UMLListViewItem::lvt_Deployment_Folder:
case UMLListViewItem::lvt_EntityRelationship_Folder:
/***
int newID = IDChanges.findNewID(Data.ID());
//if there is no ListViewItem associated with the new ID,
//it could exist an Item already asocciated if the user chose to reuse an uml object
if(!(item = findItem(newID))) {
pObject = m_doc->findObjectById(IDChanges.findNewID(Data.ID()));
item = new UMLListViewItem(parent, Data.text(0), lvt, pObject);
} ***/
pObject = m_doc->findObjectById(Data.ID());
item = new UMLListViewItem(parent, Data.text(0), lvt, pObject);
break;
case UMLListViewItem::lvt_Datatype_Folder:
item = new UMLListViewItem(parent, Data.text(0), lvt);
break;
case UMLListViewItem::lvt_Attribute:
case UMLListViewItem::lvt_EntityAttribute:
case UMLListViewItem::lvt_Operation:
case UMLListViewItem::lvt_Template:
case UMLListViewItem::lvt_EnumLiteral:
case UMLListViewItem::lvt_UniqueConstraint:
case UMLListViewItem::lvt_PrimaryKeyConstraint:
case UMLListViewItem::lvt_ForeignKeyConstraint:
case UMLListViewItem::lvt_CheckConstraint: {
UMLClassifier *pClass = static_cast<UMLClassifier*>(parent->umlObject());
Uml::ID::Type newID = IDChanges.findNewID(Data.ID());
pObject = pClass->findChildObjectById(newID);
if (pObject) {
item = new UMLListViewItem(parent, Data.text(0), lvt, pObject);
} else {
item = 0;
}
break;
}
case UMLListViewItem::lvt_UseCase_Diagram:
case UMLListViewItem::lvt_Sequence_Diagram:
case UMLListViewItem::lvt_Collaboration_Diagram:
case UMLListViewItem::lvt_Class_Diagram:
case UMLListViewItem::lvt_State_Diagram:
case UMLListViewItem::lvt_Activity_Diagram:
case UMLListViewItem::lvt_Component_Diagram:
case UMLListViewItem::lvt_Deployment_Diagram:
case UMLListViewItem::lvt_EntityRelationship_Diagram: {
Uml::ID::Type newID = IDChanges.findNewID(Data.ID());
UMLView* v = m_doc->findView(newID);
if (v == 0) {
return 0;
}
const UMLListViewItem::ListViewType lvt = Model_Utils::convert_DT_LVT(v->umlScene()->type());
item = new UMLListViewItem(parent, v->umlScene()->name(), lvt, newID);
}
break;
default:
uWarning() << "createItem() called on unknown type";
break;
}
return item;
}
/**
* Determine the parent ListViewItem given a ListViewType.
* This parent is used for creating new UMLListViewItems.
......@@ -2231,22 +2136,6 @@ void UMLListView::slotCutSuccessful()
}
}
/**
* TODO: still in use?
*/
void UMLListView::startUpdate()
{
setSortingEnabled(false);
}
/**
* TODO: still in use?
*/
void UMLListView::endUpdate()
{
setSortingEnabled(true);
}
/**
* Adds a new item to the tree of the given type under the given parent.
* Method will take care of signalling anyone needed on creation of new item.
......
......@@ -66,13 +66,8 @@ public:
UMLListViewItemList selectedItemsRoot();
int selectedItemsCount();
void startUpdate();
void endUpdate();
UMLListViewItem* createDiagramItem(UMLView *view);
UMLListViewItem* createItem(UMLListViewItem& Data, IDChangeLog& IDChanges,
UMLListViewItem* parent = 0);
bool createItem(UMLListViewItem *item);
UMLListViewItem* findFolderForDiagram(Uml::DiagramType::Enum dt);
......
......@@ -1066,9 +1066,8 @@ bool UMLObject::loadFromXMI(QDomElement & element)
m_BaseType != ot_Template && m_BaseType != ot_Stereotype &&
m_BaseType != ot_Role && m_BaseType != ot_UniqueConstraint &&
m_BaseType != ot_ForeignKeyConstraint) {
if (m_bInPaste) {
if (m_bInPaste || !m_pUMLPackage) {
m_pUMLPackage = Model_Utils::treeViewGetPackageFromCurrent();
this->setID(UniqueID::gen());
}
if (m_pUMLPackage) {
m_pUMLPackage->addObject(this);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment