32 #include <QDomDocument>
34 #include <QTextStream>
42 setUMLDataClip1(objects);
54 setUMLDataClip2(objects, umlListViewItems, diagrams);
64 setUMLDataClip3(umlListViewItems);
79 setUMLDataClip4(objects, widgets, associationDatas, pngImage, dType);
91 setUMLDataClip5(objects);
116 QDomElement xmiclip = domDoc.createElement(
"xmiclip");
117 domDoc.appendChild(xmiclip);
118 QDomElement objectsTag = domDoc.createElement(
"umlobjects");
119 xmiclip.appendChild(objectsTag);
123 while (object_it.hasNext()) {
124 obj = object_it.next();
128 QDomElement itemsTag = domDoc.createElement(
"umllistviewitems");
129 xmiclip.appendChild(itemsTag);
131 setData(
"application/x-uml-clip1", domDoc.toString().toUtf8());
142 QDomElement xmiclip = domDoc.createElement(
"xmiclip");
143 domDoc.appendChild(xmiclip);
144 QDomElement objectsTag = domDoc.createElement(
"umlobjects");
145 xmiclip.appendChild(objectsTag);
149 while (object_it.hasNext()) {
150 obj = object_it.next();
154 QDomElement viewsTag = domDoc.createElement(
"umlviews");
155 xmiclip.appendChild(viewsTag);
157 foreach(
UMLView* view, diagrams) {
161 QDomElement itemsTag = domDoc.createElement(
"umllistviewitems");
162 xmiclip.appendChild(itemsTag);
168 setData(
"application/x-uml-clip2", domDoc.toString().toUtf8());
178 QDomElement xmiclip = domDoc.createElement(
"xmiclip");
179 domDoc.appendChild(xmiclip);
181 QDomElement itemsTag = domDoc.createElement(
"umllistviewitems");
182 xmiclip.appendChild(itemsTag);
188 setData(
"application/x-uml-clip3", domDoc.toString().toUtf8());
201 QDomElement xmiclip = domDoc.createElement(
"xmiclip");
202 xmiclip.setAttribute(
"diagramtype", dType);
203 domDoc.appendChild(xmiclip);
204 QDomElement objectsTag = domDoc.createElement(
"umlobjects");
205 xmiclip.appendChild(objectsTag);
211 QDomElement widgetsTag = domDoc.createElement(
"widgets");
212 xmiclip.appendChild(widgetsTag);
218 QDomElement associationWidgetsTag = domDoc.createElement(
"associations");
219 xmiclip.appendChild(associationWidgetsTag);
222 association->
saveToXMI(domDoc, associationWidgetsTag);
225 QDomElement itemsTag = domDoc.createElement(
"umllistviewitems");
226 xmiclip.appendChild(itemsTag);
228 setData(
"application/x-uml-clip4", domDoc.toString().toUtf8());
230 QImage img = pngImage.toImage();
231 int l_size = img.numBytes();
233 clipdata.resize(l_size);
234 QDataStream clipstream(&clipdata, QIODevice::WriteOnly);
237 setImageData(clipdata);
247 QDomElement xmiclip = domDoc.createElement(
"xmiclip");
248 domDoc.appendChild(xmiclip);
249 QDomElement objectsTag = domDoc.createElement(
"umlobjects");
250 xmiclip.appendChild(objectsTag);
256 QDomElement itemsTag = domDoc.createElement(
"umllistviewitems");
257 xmiclip.appendChild(itemsTag);
259 setData(
"application/x-uml-clip5", domDoc.toString().toUtf8());
271 if (!mimeData->hasFormat(
"application/x-uml-clip1")) {
274 QByteArray payload = mimeData->data(
"application/x-uml-clip1");
275 if (!payload.size()) {
278 QString xmiClip = QString::fromUtf8(payload);
283 if(!domDoc.setContent(xmiClip,
false, &error, &line)) {
284 uWarning() <<
"Can not set content:" << error <<
" Line:" << line;
287 QDomNode xmiClipNode = domDoc.firstChild();
288 QDomElement root = xmiClipNode.toElement();
293 if (root.tagName() !=
"xmiclip") {
300 QDomNode objectsNode = xmiClipNode.firstChild();
301 QDomNode objectElement = objectsNode.firstChild();
302 QDomElement element = objectElement.toElement();
303 if (element.isNull()) {
307 while (!element.isNull()) {
309 QString type = element.tagName();
310 if (type ==
"UML:Association") {
311 objectElement = objectElement.nextSibling();
312 element = objectElement.toElement();
318 uWarning() <<
"Given wrong type of umlobject to create: " << type;
323 uWarning() <<
"Failed to load object of type " << type <<
" from XMI";
344 objects.append(pObject);
345 objectElement = objectElement.nextSibling();
346 element = objectElement.toElement();
360 if (!mimeData->hasFormat(
"application/x-uml-clip2")) {
363 QByteArray payload = mimeData->data(
"application/x-uml-clip2");
364 if (!payload.size()) {
367 QString xmiClip = QString::fromUtf8(payload);
372 if(!domDoc.setContent(xmiClip,
false, &error, &line)) {
373 uWarning() <<
"Can not set content:" << error <<
" Line:" << line;
376 QDomNode xmiClipNode = domDoc.firstChild();
377 QDomElement root = xmiClipNode.toElement();
382 if (root.tagName() !=
"xmiclip") {
387 QDomNode objectsNode = xmiClipNode.firstChild();
388 QDomNode objectElement = objectsNode.firstChild();
389 QDomElement element = objectElement.toElement();
390 if (element.isNull()) {
394 while (!element.isNull()) {
396 QString type = element.tagName();
397 if (type !=
"UML:Association") {
401 uWarning() <<
"Given wrong type of umlobject to create:" << type;
405 uWarning() <<
"Failed to load object from XMI.";
408 objects.append(pObject);
410 objectElement = objectElement.nextSibling();
411 element = objectElement.toElement();
415 QDomNode umlviewsNode = objectsNode.nextSibling();
416 QDomNode diagramNode = umlviewsNode.firstChild();
417 QDomElement diagramElement = diagramNode.toElement();
418 if (diagramElement.isNull()) {
419 uWarning() <<
"No diagrams in XMI clip.";
423 while (!diagramElement.isNull()) {
424 QString type = diagramElement.attribute(
"type",
"0");
431 uError() <<
"Bad parent for view.";
437 diagrams.append(view);
438 diagramNode = diagramNode.nextSibling();
439 diagramElement = diagramNode.toElement();
443 QDomNode listItemNode = umlviewsNode.nextSibling();
444 QDomNode listItems = listItemNode.firstChild();
445 QDomElement listItemElement = listItems.toElement();
446 if (listItemElement.isNull()) {
447 uWarning() <<
"No listitems in XMI clip.";
451 while (!listItemElement.isNull()) {
458 umlListViewItems.append(itemData);
461 listItems = listItems.nextSibling();
462 listItemElement = listItems.toElement();
477 if (!mimeData->hasFormat(
"application/x-uml-clip3")) {
480 QByteArray payload = mimeData->data(
"application/x-uml-clip3");
481 if (!payload.size()) {
484 QTextStream clipdata(payload, QIODevice::ReadOnly);
485 QString xmiClip = QString::fromUtf8(payload);
490 if(!domDoc.setContent(xmiClip,
false, &error, &line)) {
491 uWarning() <<
"getClip3Type: Can not set content:" << error <<
" Line:" << line;
494 QDomNode xmiClipNode = domDoc.firstChild();
495 QDomElement root = xmiClipNode.toElement();
500 if (root.tagName() !=
"xmiclip") {
504 QDomNode listItemNode = xmiClipNode.firstChild();
505 QDomNode listItems = listItemNode.firstChild();
506 QDomElement listItemElement = listItems.toElement();
507 if (listItemElement.isNull()) {
508 uWarning() <<
"getClip3Type: No listitems in XMI clip.";
511 while (!listItemElement.isNull()) {
512 QString typeStr = listItemElement.attribute(
"type",
"-1");
513 if (typeStr ==
"-1") {
514 uDebug() <<
"getClip3Type: bad type.";
517 QString idStr = listItemElement.attribute(
"id",
"-1");
519 uDebug() <<
"getClip3Type: bad id";
525 typeAndIdList.append(pData);
526 listItems = listItems.nextSibling();
527 listItemElement = listItems.toElement();
540 if (!mimeData->hasFormat(
"application/x-uml-clip3")) {
543 QByteArray payload = mimeData->data(
"application/x-uml-clip3");
544 if (!payload.size()) {
547 QTextStream clipdata(payload, QIODevice::ReadOnly);
548 QString xmiClip = QString::fromUtf8(payload);
553 if(!domDoc.setContent(xmiClip,
false, &error, &line)) {
554 uWarning() <<
"Can not set content:" << error <<
" Line:" << line;
557 QDomNode xmiClipNode = domDoc.firstChild();
558 QDomElement root = xmiClipNode.toElement();
563 if (root.tagName() !=
"xmiclip") {
568 QDomNode listItemNode = xmiClipNode.firstChild();
569 QDomNode listItems = listItemNode.firstChild();
570 QDomElement listItemElement = listItems.toElement();
571 if (listItemElement.isNull()) {
572 uWarning() <<
"no listitems in XMI clip";
575 while (!listItemElement.isNull()) {
578 QString type = listItemElement.attribute(
"type",
"-1");
580 uDebug() <<
"Type not found.";
587 umlListViewItems.append(itemData);
590 listItems = listItems.nextSibling();
591 listItemElement = listItems.toElement();
607 if (!mimeData->hasFormat(
"application/x-uml-clip4")) {
610 QByteArray payload = mimeData->data(
"application/x-uml-clip4");
611 if (!payload.size()) {
615 QString xmiClip = QString::fromUtf8(payload);
620 if(!domDoc.setContent(xmiClip,
false, &error, &line)) {
621 uWarning() <<
"Can not set content:" << error <<
" Line:" << line;
624 QDomNode xmiClipNode = domDoc.firstChild();
625 QDomElement root = xmiClipNode.toElement();
630 if (root.tagName() !=
"xmiclip") {
637 QDomNode objectsNode = xmiClipNode.firstChild();
638 QDomNode objectElement = objectsNode.firstChild();
639 QDomElement element = objectElement.toElement();
640 while (!element.isNull()) {
642 QString type = element.tagName();
651 uWarning() <<
"Given wrong type of umlobject to create: " << type;
655 if (!pObject->loadFromXMI(element)) {
656 uWarning() <<
"Failed to load object from XMI.";
663 objects.append(pObject);
664 objectElement = objectElement.nextSibling();
665 element = objectElement.toElement();
669 QDomNode widgetsNode = objectsNode.nextSibling();
670 QDomNode widgetNode = widgetsNode.firstChild();
671 QDomElement widgetElement = widgetNode.toElement();
672 if (widgetElement.isNull()) {
673 uWarning() <<
"No widgets in XMI clip.";
679 while (!widgetElement.isNull()) {
683 widgets.append(widget);
685 widgetNode = widgetNode.nextSibling();
686 widgetElement = widgetNode.toElement();
690 QDomNode associationWidgetsNode = widgetsNode.nextSibling();
691 QDomNode associationWidgetNode = associationWidgetsNode.firstChild();
692 QDomElement associationWidgetElement = associationWidgetNode.toElement();
693 while (!associationWidgetElement.isNull()) {
695 if (associationWidget->
loadFromXMI(associationWidgetElement, widgets, 0))
696 associations.append(associationWidget);
698 delete associationWidget;
700 associationWidgetNode = associationWidgetNode.nextSibling();
701 associationWidgetElement = associationWidgetNode.toElement();
715 if (!mimeData->hasFormat(
"application/x-uml-clip5")) {
718 QByteArray payload = mimeData->data(
"application/x-uml-clip5");
719 if (!payload.size()) {
722 QString xmiClip = QString::fromUtf8(payload);
727 if(!domDoc.setContent(xmiClip,
false, &error, &line)) {
728 uWarning() <<
"Can not set content:" << error <<
" Line:" << line;
731 QDomNode xmiClipNode = domDoc.firstChild();
732 QDomElement root = xmiClipNode.toElement();
737 if (root.tagName() !=
"xmiclip") {
742 QDomNode objectsNode = xmiClipNode.firstChild();
743 QDomNode objectElement = objectsNode.firstChild();
744 QDomElement element = objectElement.toElement();
745 if (element.isNull()) {
748 while (!element.isNull()) {
749 QString type = element.tagName();
752 uWarning() <<
"Given wrong type of umlobject to create:" << type;
756 uWarning() <<
"Failed to load object from XMI.";
760 objects.append(pObject);
761 objectElement = objectElement.nextSibling();
762 element = objectElement.toElement();
774 if (mimeData->hasFormat(
"application/x-uml-clip1")) {
777 if (mimeData->hasFormat(
"application/x-uml-clip2")) {
780 if (mimeData->hasFormat(
"application/x-uml-clip3")) {
783 if (mimeData->hasFormat(
"application/x-uml-clip4")) {
786 if (mimeData->hasFormat(
"application/x-uml-clip5")) {
792 #include "umldragdata.moc"
Items used by the class UMLListView.
static bool decodeClip1(const QMimeData *mimeData, UMLObjectList &objects)
For use when the user selects only UML Objects from the ListView but no diagrams to be copied...
QListIterator< UMLObject * > UMLObjectListIt
void saveToXMI(QDomDocument &qDoc, QDomElement &qElement)
Saves the listview item to a "listitem" tag.
This class defines the non-graphical information required for a UML Classifier (ie a class or interfa...
virtual bool loadFromXMI(QDomElement &element)
This method loads the generic parts of the XMI common to most model classes.
Classifiers (classes, interfaces) have lists of operations, attributes, templates and others...
UMLListView * listView() const
Returns a pointer to the list view.
UMLView * currentView() const
Get the current view.
UMLView instances represent diagrams.
static UMLApp * app()
Get the last created instance of this class.
UMLListViewItem * findFolderForDiagram(Uml::DiagramType::Enum dt)
Find the parent folder for a diagram.
virtual bool loadFromXMI(QDomElement &qElement)
Loads the "diagram" tag.
QList< UMLView * > UMLViewList
static bool decodeClip2(const QMimeData *mimeData, UMLObjectList &objects, UMLListViewItemList ¨ListViewItems, UMLViewList &diagrams)
For use when the user selects UML Object and Diagrams from the ListView to be copied, decodes Mime type = "application/x-uml-clip2.
UMLListViewItem * determineParentItem(UMLObject *object) const
Determine the parent ListViewItem given an UMLObject.
UMLDoc * document() const
Returns a pointer to the current document connected to the KMainWindow instance.
static bool getClip3TypeAndID(const QMimeData *mimeData, LvTypeAndID_List &typeAndIdList)
Return just the LvTypeAndID of a Clip3.
This class is the non-graphical version of UMLWidget.
This is one of the main classes used in this program.
virtual bool resolveRef()
Resolve referenced objects (if any.) Needs to be called after all UML objects are loaded from file...
bool assignNewIDs(UMLObject *obj)
Assigns an already created UMLObject a new ID.
UMLDragData(UMLObjectList &Objects, QWidget *dragSource=0)
Constructor.
~UMLDragData()
Deconstructor.
static int getCodingType(const QMimeData *mimeData)
Converts application/x-uml-clip[1-5] clip type to an integer.
static bool decodeClip3(const QMimeData *mimeData, UMLListViewItemList ¨ListViewItems, const UMLListView *parentListView=0)
For use when the user selects UMLObjects from the ListView to be copied, decodes Mime * type = "appli...
This class manages the UMLObjects and UMLViews of a Folder.
bool startedCopy() const
Return the variable m_bStartedCopy.
ObjectType baseType() const
Returns the type of the object.
UMLObject * findObjectById(Uml::ID::Type id)
Used to find a reference to a UMLObject by its ID.
virtual void saveToXMI(QDomDocument &qDoc, QDomElement &qElement)
Creates the "diagram" tag and fills it with the contents of the diagram.
Enum fromInt(int item)
Convert an integer item into DiagramType representation.
UMLScene * umlScene() const
Getter for the scene.
UMLListViewItem::ListViewType type
virtual void saveToXMI(QDomDocument &qDoc, QDomElement &qElement)=0
This sub-class adds copyInto and clone to the QList base class.
UMLObject * makeObjectFromXMI(const QString &xmiTag, const QString &stereoID)
Make a new UMLObject according to the given XMI tag.
static bool decodeClip4(const QMimeData *mimeData, UMLObjectList &objects, UMLWidgetList &widgets, AssociationWidgetList &associations, Uml::DiagramType::Enum &dType)
For use when the user selects UML Objects from a Diagram.
void setInPaste(bool bInPaste=true)
virtual UMLClassifierListItem * makeChildObject(const QString &xmiTag)
utility functions to allow easy determination of what classifiers are "owned" by the current one via ...
bool loadFromXMI(QDomElement &qElement)
Loads a "listitem" tag, this is only used by the clipboard currently.
ID::Type fromString(const QString &id)
static bool decodeClip5(const QMimeData *mimeData, UMLObjectList &objects, UMLClassifier *newParent)
For use when the user selects only Attributes and/or Operations from the ListView * copied...
QList< UMLListViewItem * > UMLListViewItemList
UMLWidget * loadWidgetFromXMI(QDomElement &widgetElement)
Loads a "widget" element from XMI, used by loadFromXMI() and the clipboard.
UMLScene instances represent diagrams.
void signalUMLObjectCreated(UMLObject *o)
Signal that a UMLObject has been created.
UMLDoc provides a document object for a document-view model.