Commit a5e3fc46 authored by Joris Steyn's avatar Joris Steyn

Include object packages in clip

BUG: 327888
parent 584f826f
......@@ -91,11 +91,7 @@ QMimeData* UMLClipboard::copy(bool fromView/*=false*/)
// 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) {
if (widget->umlObject() != 0) {
m_ObjectList.append(widget->umlObject());
}
}
fillObjectListForWidgets(m_WidgetList);
foreach (WidgetBase* widget, m_AssociationList) {
if (widget->umlObject() != 0) {
......@@ -118,12 +114,7 @@ QMimeData* UMLClipboard::copy(bool fromView/*=false*/)
// in the Diagram
if (m_type == clip2) {
foreach (UMLView* view, m_ViewList) {
UMLWidgetList widgets = view->umlScene()->widgetList();
foreach (UMLWidget* widget, widgets) {
if (widget->umlObject() != 0) {
m_ObjectList.append(widget->umlObject());
}
}
fillObjectListForWidgets(view->umlScene()->widgetList());
AssociationWidgetList associations = view->umlScene()->associationList();
foreach (AssociationWidget* association, associations) {
......@@ -216,6 +207,41 @@ bool UMLClipboard::paste(const QMimeData* data)
return result;
}
/**
* Fills object list based on a selection of widgets
*
* @param UMLWidgetList& widgets
*/
void UMLClipboard::fillObjectListForWidgets(UMLWidgetList& widgets)
{
// The order of the packages in the clip matters. So we collect
// the packages and add them from the root package to the deeper levels
UMLObjectList packages;
foreach (UMLWidget* widget, widgets) {
UMLObject* widgetObject = widget->umlObject();
if (widgetObject != 0) {
packages.clear();
UMLPackage* package = widgetObject->umlPackage();
while (package != 0) {
packages.prepend(package);
package = package->umlPackage();
}
foreach (UMLObject* package, packages) {
if (!m_ObjectList.contains(package)) {
m_ObjectList.append(package);
}
}
if (!m_ObjectList.contains(widgetObject)) {
m_ObjectList.append(widgetObject);
}
}
}
}
/**
* Fills the member lists with all the objects and other
* stuff to be copied to the clipboard.
......@@ -362,17 +388,7 @@ bool UMLClipboard::insertItemChildren(UMLListViewItem * item, UMLListViewItemLis
bool UMLClipboard::pasteClip1(const QMimeData* data)
{
UMLObjectList objects;
if (! UMLDragData::decodeClip1(data, objects)) {
return false;
}
UMLDoc* doc = UMLApp::app()->document();
foreach (UMLObject* object, objects) {
doc->assignNewIDs(object);
object->resolveRef();
}
return true;
return UMLDragData::decodeClip1(data, objects);
}
/**
......@@ -387,8 +403,7 @@ bool UMLClipboard::pasteClip2(const QMimeData* data)
UMLObjectList objects;
UMLViewList views;
bool result = UMLDragData::decodeClip2(data, objects, views);
if(!result) {
if (!UMLDragData::decodeClip2(data, objects, views)) {
return false;
}
......@@ -398,7 +413,7 @@ bool UMLClipboard::pasteClip2(const QMimeData* data)
}
}
return result;
return true;
}
/**
......@@ -426,12 +441,7 @@ bool UMLClipboard::pasteClip3(const QMimeData* data)
}
UMLListView *listView = UMLApp::app()->listView();
bool result = UMLDragData::decodeClip3(data, itemdatalist, listView);
if(!result) {
return false;
}
return result;
return UMLDragData::decodeClip3(data, itemdatalist, listView);
}
/**
......
......@@ -72,6 +72,8 @@ private:
private:
void fillObjectListForWidgets(UMLWidgetList& widgets);
bool fillSelectionLists(UMLListViewItemList& selectedItems);
void setCopyType(UMLListViewItemList& selectedItems);
......
......@@ -27,6 +27,7 @@
#include "associationwidget.h"
#include "object_factory.h"
#include "model_utils.h"
#include "cmds.h"
// qt includes
#include <QDomDocument>
......@@ -660,51 +661,51 @@ bool UMLDragData::decodeObjects(QDomNode& objectsNode, UMLObjectList& objects, b
uWarning() << "Given wrong type of umlobject to create: " << type;
return false;
}
pObject->setInPaste(true);
// Note: element should not be used after calling loadFromXMI() because
// it can point to an arbitrary child node
Uml::ID::Type oldParentId = Uml::ID::fromString(
element.attribute("namespace", "-1")
);
if(!pObject->loadFromXMI(element)) {
uWarning() << "Failed to load object of type " << type << " from XMI";
delete pObject;
return false;
}
pObject->setInPaste(false);
// Determine the parent package of the pasted object
UMLPackage* newParent = 0;
if (oldParentId != Uml::ID::None) {
Uml::ID::Type newParentId = doc->changeLog()->findNewID(oldParentId);
if (newParentId != Uml::ID::None) {
// Find the newly pasted package
newParent = static_cast<UMLPackage*>(doc->findObjectById(newParentId));
} else {
// Package is not in this clip, determine the parent based
// on the selected tree view item
newParent = Model_Utils::treeViewGetPackageFromCurrent();
if (newParentId == Uml::ID::None) {
// Fallback to parent ID before paste (folder was not pasted in
// this paste operation)
newParentId = oldParentId;
}
newParent = static_cast<UMLPackage*>(doc->findObjectById(newParentId));
}
if (newParent != 0) {
UMLPackage* oldParent = pObject->umlPackage();
if (oldParent != 0) {
oldParent->removeObject(pObject);
}
if (newParent == 0) {
// Package is not in this clip, determine the parent based
// on the selected tree view item
newParent = Model_Utils::treeViewGetPackageFromCurrent();
}
pObject->setUMLPackage(newParent);
pObject->setUMLPackage(newParent);
newParent->addObject(pObject);
// Note: element should not be used after calling loadFromXMI() because
// it can point to an arbitrary child node
if(!pObject->loadFromXMI(element)) {
uWarning() << "Failed to load object of type " << type << " from XMI";
delete pObject;
return false;
}
// only signal creation of the object did not exist before the paste
if (!objectExists) {
doc->signalUMLObjectCreated(pObject);
// Assign a new ID if the object already existed before this paste,
// this happens when pasting on listview items in the same document.
if (objectExists) {
pObject->setID(
doc->assignNewID(pObject->id())
);
}
UMLApp::app()->executeCommand(new Uml::CmdCreateUMLObject(pObject));
objects.append(pObject);
objectElement = objectElement.nextSibling();
element = objectElement.toElement();
......
......@@ -185,10 +185,15 @@ UMLObject* createUMLObject(UMLObject::ObjectType type, const QString &n,
return o;
}
}
bool ok = false;
QString name = Model_Utils::uniqObjectName(type, parentPkg, n);
bool bValidNameEntered = false;
do {
QString name = Model_Utils::uniqObjectName(type, parentPkg, n);
if (name == n) {
bValidNameEntered = true;
}
bool ok = false;
while (bValidNameEntered == false) {
name = KInputDialog::getText(i18nc("UMLObject name", "Name"), i18n("Enter name:"), name, &ok, (QWidget*)UMLApp::app());
if (!ok) {
return 0;
......@@ -210,7 +215,8 @@ UMLObject* createUMLObject(UMLObject::ObjectType type, const QString &n,
continue;
}
bValidNameEntered = true;
} while (bValidNameEntered == false);
}
UMLObject *o = createNewUMLObject(type, name, parentPkg);
return o;
}
......
......@@ -2067,6 +2067,11 @@ void UMLListView::addNewItem(UMLListViewItem *parentItem, UMLListViewItem::ListV
QString name = Model_Utils::uniqObjectName(objectType, package);
UMLObject* object = Object_Factory::createUMLObject(objectType, name, package);
if (object == 0) {
// creation was cancelled by the user
return;
}
if (type == UMLListViewItem::lvt_Subsystem) {
object->setStereotype("subsystem");
} else if (Model_Utils::typeIsFolder(type)) {
......
......@@ -103,7 +103,6 @@ void UMLObject::init()
m_Doc.clear();
m_bAbstract = false;
m_bStatic = false;
m_bInPaste = false;
m_bCreationWasSignalled = false;
m_pSecondary = 0;
}
......@@ -323,11 +322,6 @@ void UMLObject::setAbstract(bool bAbstract)
emitModified();
}
void UMLObject::setInPaste(bool bInPaste /* =true */)
{
m_bInPaste = bInPaste;
}
/**
* Returns true if this UMLObject has classifier scope,
* otherwise false (the default).
......@@ -1066,15 +1060,6 @@ 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) {
// Todo: refactor outside of loadFromXmi()
//
// Determine parent of new object:
// * if m_bInPaste=true, object was pasted in the tree view -> get package from current
// * if there's no package and we're not loading a XMI file, object was
// pasted from another instance of umbrello -> get package from current
if (m_bInPaste || (!m_pUMLPackage && !umldoc->loading())) {
m_pUMLPackage = Model_Utils::treeViewGetPackageFromCurrent();
}
if (m_pUMLPackage) {
m_pUMLPackage->addObject(this);
} else if (umldoc->rootFolderType(this) == Uml::ModelType::N_MODELTYPES) {
......
......@@ -128,8 +128,6 @@ public:
void setAbstract(bool bAbstract);
bool isAbstract() const;
void setInPaste(bool bInPaste = true);
// FIXME: merge with showPropertiesDialog()
virtual bool showPropertiesPagedDialog(int page = 0, bool assoc = false);
......
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