00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "umldrag.h"
00014
00015
00016 #include <qdom.h>
00017 #include <kdebug.h>
00018
00019
00020 #include "idchangelog.h"
00021 #include "../uml.h"
00022 #include "../umldoc.h"
00023 #include "../umlview.h"
00024 #include "../umlobject.h"
00025 #include "../folder.h"
00026 #include "../classifier.h"
00027 #include "../umlwidget.h"
00028 #include "../umllistview.h"
00029 #include "../umllistviewitem.h"
00030 #include "../associationwidget.h"
00031 #include "../object_factory.h"
00032 #include "../model_utils.h"
00033
00034 #define nfmt 4
00035 class UMLDragPrivate {
00036 public:
00037 QCString fmt[nfmt];
00038 QCString subtype;
00039 QByteArray enc[nfmt];
00040
00041 UMLDragPrivate() {
00042 setSubType("clip1", 0);
00043 }
00044
00045 void setType(const QCString& st, int index) {
00046 if (index < nfmt) {
00047 fmt[index] = st.lower();
00048 }
00049 }
00050
00051 void setSubType(const QCString& st, int index) {
00052 if (index < nfmt) {
00053 subtype = st.lower();
00054 fmt[index] = "application/x-uml-";
00055 fmt[index].append(subtype);
00056 }
00057 }
00058
00059 const char* format(int i) const {
00060 if(i < nfmt) {
00061 return fmt[i];
00062 }
00063 return 0;
00064 }
00065 };
00066
00067 UMLDrag::UMLDrag(UMLObjectList& objects, QWidget* dragSource , const char* name )
00068 : QDragObject(dragSource, name) {
00069 data = new UMLDragPrivate;
00070 setUMLDataClip1(objects);
00071 }
00072
00073 UMLDrag::UMLDrag(UMLObjectList& objects, UMLListViewItemList& umlListViewItems, UMLViewList& diagrams,
00074 QWidget* dragSource , const char* name ): QDragObject(dragSource, name) {
00075 data = new UMLDragPrivate;
00076 setUMLDataClip2(objects, umlListViewItems, diagrams);
00077 }
00078
00079 UMLDrag::UMLDrag(UMLListViewItemList& umlListViewItems, QWidget* dragSource ,
00080 const char* name ): QDragObject(dragSource, name) {
00081 data = new UMLDragPrivate;
00082 setUMLDataClip3(umlListViewItems);
00083 }
00084
00085 UMLDrag::UMLDrag(UMLObjectList& objects,
00086 UMLWidgetList& widgets, AssociationWidgetList& associationDatas,
00087 QPixmap& pngImage, Uml::Diagram_Type dType, QWidget * dragSource ,
00088 const char * name ): QDragObject(dragSource, name) {
00089 data = new UMLDragPrivate;
00090 setUMLDataClip4(objects, widgets, associationDatas, pngImage, dType);
00091 }
00092
00093 UMLDrag::UMLDrag(UMLObjectList& objects, int,
00094 QWidget* , const char* ) {
00095 data = new UMLDragPrivate;
00096 setUMLDataClip5(objects);
00097 }
00098
00099 UMLDrag::UMLDrag(QWidget* dragSource , const char * name ): QDragObject(dragSource, name) {
00100 data = new UMLDragPrivate;
00101 }
00102
00103 UMLDrag::~UMLDrag() {
00104 delete data;
00105 }
00106
00107 void UMLDrag::setSubType(const QCString& string, int index) {
00108 data->setSubType(string, index);
00109 }
00110
00111 void UMLDrag::setEncodedData(const QByteArray& encodedData, int index) {
00112 data->enc[index] = encodedData.copy();
00113 }
00114
00115 QByteArray UMLDrag::encodedData(const char* dataName) const {
00116 QString str(dataName);
00117 for (int i = 0; i < 4; i++) {
00118 if ( !qstricmp(dataName,data->fmt[i]) ) {
00119 return data->enc[i];
00120 }
00121 }
00122 return QByteArray();
00123 }
00124
00125 const char* UMLDrag::format(int index) const {
00126 char* result = (char*)data->format(index);
00127 return result;
00128 }
00129
00130 void UMLDrag::setUMLDataClip1(UMLObjectList& objects) {
00131 setSubType("clip1", 0);
00132
00133 QDomDocument domDoc;
00134 QDomElement xmiclip = domDoc.createElement("xmiclip");
00135 domDoc.appendChild(xmiclip);
00136 QDomElement objectsTag = domDoc.createElement("umlobjects");
00137 xmiclip.appendChild(objectsTag);
00138
00139 UMLObjectListIt object_it(objects);
00140 UMLObject* obj = 0;
00141 while ( (obj=object_it.current()) != 0 ) {
00142 ++object_it;
00143 obj->saveToXMI(domDoc, objectsTag);
00144 }
00145
00146 QDomElement itemsTag = domDoc.createElement("umllistviewitems");
00147 xmiclip.appendChild(itemsTag);
00148
00149 setEncodedData(domDoc.toString().utf8(), 0);
00150 }
00151
00152 void UMLDrag::setUMLDataClip2(UMLObjectList& objects, UMLListViewItemList& umlListViewItems,
00153 UMLViewList& diagrams) {
00154 setSubType("clip2", 0);
00155
00156 QDomDocument domDoc;
00157 QDomElement xmiclip = domDoc.createElement("xmiclip");
00158 domDoc.appendChild(xmiclip);
00159 QDomElement objectsTag = domDoc.createElement("umlobjects");
00160 xmiclip.appendChild(objectsTag);
00161
00162 UMLObjectListIt object_it(objects);
00163 UMLObject* obj = 0;
00164 while ( (obj=object_it.current()) != 0 ) {
00165 ++object_it;
00166 obj->saveToXMI(domDoc, objectsTag);
00167 }
00168
00169 QDomElement viewsTag = domDoc.createElement("umlviews");
00170 xmiclip.appendChild(viewsTag);
00171
00172 UMLViewListIt diagram_it(diagrams);
00173 UMLView* view = 0;
00174 while ( (view=diagram_it.current()) != 0 ) {
00175 ++diagram_it;
00176 view->saveToXMI(domDoc, viewsTag);
00177 }
00178
00179 QDomElement itemsTag = domDoc.createElement("umllistviewitems");
00180 xmiclip.appendChild(itemsTag);
00181
00182 UMLListViewItemListIt item_it2(umlListViewItems);
00183 UMLListViewItem* item = 0;
00184 while ( (item=item_it2.current()) != 0 ) {
00185 ++item_it2;
00186 item->saveToXMI(domDoc, itemsTag);
00187 }
00188 setEncodedData(domDoc.toString().utf8(), 0);
00189 }
00190
00191 void UMLDrag::setUMLDataClip3(UMLListViewItemList& umlListViewItems) {
00192 setSubType("clip3", 0);
00193
00194 QDomDocument domDoc;
00195 QDomElement xmiclip = domDoc.createElement("xmiclip");
00196 domDoc.appendChild(xmiclip);
00197
00198 QDomElement itemsTag = domDoc.createElement("umllistviewitems");
00199 xmiclip.appendChild(itemsTag);
00200
00201 UMLListViewItemListIt item_it2(umlListViewItems);
00202 UMLListViewItem* item = 0;
00203 while ( (item=item_it2.current()) != 0 ) {
00204 ++item_it2;
00205 item->saveToXMI(domDoc, itemsTag);
00206 }
00207 setEncodedData(domDoc.toString().utf8(), 0);
00208 }
00209
00210 void UMLDrag::setUMLDataClip4(UMLObjectList& objects, UMLWidgetList& widgets, AssociationWidgetList& associations,
00211 QPixmap& pngImage, Uml::Diagram_Type dType ) {
00212 setSubType("clip4", 0);
00213
00214 QDomDocument domDoc;
00215 QDomElement xmiclip = domDoc.createElement("xmiclip");
00216 xmiclip.setAttribute("diagramtype", dType);
00217 domDoc.appendChild(xmiclip);
00218 QDomElement objectsTag = domDoc.createElement("umlobjects");
00219 xmiclip.appendChild(objectsTag);
00220
00221 UMLObjectListIt object_it(objects);
00222 UMLObject* obj = 0;
00223 while ( (obj=object_it.current()) != 0 ) {
00224 ++object_it;
00225 obj->saveToXMI(domDoc, objectsTag);
00226 }
00227
00228 QDomElement widgetsTag = domDoc.createElement("widgets");
00229 xmiclip.appendChild(widgetsTag);
00230
00231 UMLWidgetListIt widget_it(widgets);
00232 UMLWidget* widget = 0;
00233 while ( (widget=widget_it.current()) != 0 ) {
00234 ++widget_it;
00235 widget->saveToXMI(domDoc, widgetsTag);
00236 }
00237
00238 QDomElement associationWidgetsTag = domDoc.createElement("associations");
00239 xmiclip.appendChild(associationWidgetsTag);
00240
00241 AssociationWidgetListIt associations_it(associations);
00242 AssociationWidget* association;
00243 while ( (association=associations_it.current()) != 0 ) {
00244 ++associations_it;
00245 association->saveToXMI(domDoc, associationWidgetsTag);
00246 }
00247
00248 QDomElement itemsTag = domDoc.createElement("umllistviewitems");
00249 xmiclip.appendChild(itemsTag);
00250
00251 setEncodedData(domDoc.toString().utf8(), 0);
00252
00253 data->setType("image/PNG", 1);
00254 long l_size = (pngImage.convertToImage()).numBytes();
00255 QByteArray clipdata;
00256 clipdata.resize(l_size);
00257 QDataStream clipstream(clipdata, IO_WriteOnly);
00258 clipstream << pngImage;
00259 setEncodedData(clipdata, 1);
00260 }
00261
00262 void UMLDrag::setUMLDataClip5(UMLObjectList& objects) {
00263 setSubType("clip5", 0);
00264
00265 QDomDocument domDoc;
00266 QDomElement xmiclip = domDoc.createElement("xmiclip");
00267 domDoc.appendChild(xmiclip);
00268 QDomElement objectsTag = domDoc.createElement("umlobjects");
00269 xmiclip.appendChild(objectsTag);
00270
00271 UMLObjectListIt object_it(objects);
00272 UMLObject* obj = 0;
00273 while ( (obj=object_it.current()) != 0 ) {
00274 ++object_it;
00275 obj->saveToXMI(domDoc, objectsTag);
00276 }
00277
00278 QDomElement itemsTag = domDoc.createElement("umllistviewitems");
00279 xmiclip.appendChild(itemsTag);
00280
00281 setEncodedData(domDoc.toString().utf8(), 0);
00282 }
00283
00284 bool UMLDrag::decodeClip1(const QMimeSource* mimeSource, UMLObjectList& objects) {
00285 UMLDoc* doc = UMLApp::app()->getDocument();
00286 if ( !mimeSource->provides("application/x-uml-clip1") ) {
00287 return false;
00288 }
00289 QByteArray payload = mimeSource->encodedData("application/x-uml-clip1");
00290 if ( !payload.size() ) {
00291 return false;
00292 }
00293 QString xmiClip = QString::fromUtf8(payload);
00294
00295 QString error;
00296 int line;
00297 QDomDocument domDoc;
00298 if( !domDoc.setContent(xmiClip, false, &error, &line) ) {
00299 kWarning() << "Can't set content:" << error << " Line:" << line << endl;
00300 return false;
00301 }
00302 QDomNode xmiClipNode = domDoc.firstChild();
00303 QDomElement root = xmiClipNode.toElement();
00304 if ( root.isNull() ) {
00305 return false;
00306 }
00307
00308 if ( root.tagName() != "xmiclip" ) {
00309 return false;
00310 }
00311
00312 UMLListView *listView = UMLApp::app()->getListView();
00313
00314
00315 QDomNode objectsNode = xmiClipNode.firstChild();
00316 QDomNode objectElement = objectsNode.firstChild();
00317 QDomElement element = objectElement.toElement();
00318 if ( element.isNull() ) {
00319 return false;
00320 }
00321 UMLObject* pObject = 0;
00322 while ( !element.isNull() ) {
00323 pObject = 0;
00324 QString type = element.tagName();
00325 if (type == "UML:Association") {
00326 objectElement = objectElement.nextSibling();
00327 element = objectElement.toElement();
00328 continue;
00329 }
00330 pObject = Object_Factory::makeObjectFromXMI(type);
00331
00332 if( !pObject ) {
00333 kWarning() << "UMLDrag::decodeClip1: Given wrong type of umlobject to create: "
00334 << type << endl;
00335 return false;
00336 }
00337 pObject->setInPaste( true );
00338 if( !pObject->loadFromXMI( element ) ) {
00339 kWarning() << "UMLDrag::decodeClip1: failed to load object of type "
00340 << type << " from XMI" << endl;
00341 delete pObject;
00342 return false;
00343 }
00344 pObject->setInPaste( false );
00345 if (listView->startedCopy()) {
00346
00347
00348
00349
00350
00351
00352
00353 if(!doc->assignNewIDs(pObject)) {
00354 return false;
00355 }
00356 Uml::Object_Type type = pObject->getBaseType();
00357 QString newName = Model_Utils::uniqObjectName(type, pObject->getUMLPackage(),
00358 pObject->getName());
00359 pObject->setName(newName);
00360
00361 }
00362
00363 pObject->resolveRef();
00364
00365 objects.append(pObject);
00366 objectElement = objectElement.nextSibling();
00367 element = objectElement.toElement();
00368 }
00369
00370 return true;
00371 }
00372
00373 bool UMLDrag::decodeClip2(const QMimeSource* mimeSource, UMLObjectList& objects,
00374 UMLListViewItemList& umlListViewItems, UMLViewList& diagrams) {
00375
00376 if ( !mimeSource->provides("application/x-uml-clip2") ) {
00377 return false;
00378 }
00379 QByteArray payload = mimeSource->encodedData("application/x-uml-clip2");
00380 if ( !payload.size() ) {
00381 return false;
00382 }
00383 QString xmiClip = QString::fromUtf8(payload);
00384
00385 QString error;
00386 int line;
00387 QDomDocument domDoc;
00388 if( !domDoc.setContent(xmiClip, false, &error, &line) ) {
00389 kWarning() << "Can't set content:" << error << " Line:" << line << endl;
00390 return false;
00391 }
00392 QDomNode xmiClipNode = domDoc.firstChild();
00393 QDomElement root = xmiClipNode.toElement();
00394 if ( root.isNull() ) {
00395 return false;
00396 }
00397
00398 if ( root.tagName() != "xmiclip" ) {
00399 return false;
00400 }
00401
00402
00403 QDomNode objectsNode = xmiClipNode.firstChild();
00404 QDomNode objectElement = objectsNode.firstChild();
00405 QDomElement element = objectElement.toElement();
00406 if ( element.isNull() ) {
00407 return false;
00408 }
00409 UMLObject* pObject = 0;
00410 while ( !element.isNull() ) {
00411 pObject = 0;
00412 QString type = element.tagName();
00413 if (type != "UML:Association") {
00414 pObject = Object_Factory::makeObjectFromXMI(type);
00415
00416 if( !pObject ) {
00417 kWarning() << "Given wrong type of umlobject to create:" << type << endl;
00418 return false;
00419 }
00420 if( !pObject->loadFromXMI(element) ) {
00421 kWarning() << "failed to load object from XMI" << endl;
00422 return false;
00423 }
00424 objects.append(pObject);
00425 }
00426 objectElement = objectElement.nextSibling();
00427 element = objectElement.toElement();
00428 }
00429
00430
00431 QDomNode umlviewsNode = objectsNode.nextSibling();
00432 QDomNode diagramNode = umlviewsNode.firstChild();
00433 QDomElement diagramElement = diagramNode.toElement();
00434 if ( diagramElement.isNull() ) {
00435 kWarning() << "no diagrams in XMI clip" << endl;
00436 return false;
00437 }
00438 UMLListView *listView = UMLApp::app()->getListView();
00439 while ( !diagramElement.isNull() ) {
00440 QString type = diagramElement.attribute("type", "0");
00441 Uml::Diagram_Type dt = (Uml::Diagram_Type)type.toInt();
00442 UMLListViewItem *parent = listView->findFolderForDiagram(dt);
00443 if (parent == NULL)
00444 return false;
00445 UMLObject *po = parent->getUMLObject();
00446 if (po == NULL || po->getBaseType() != Uml::ot_Folder) {
00447 kError() << "UMLDrag::decodeClip2: bad parent for view" << endl;
00448 return false;
00449 }
00450 UMLFolder *f = static_cast<UMLFolder*>(po);
00451 UMLView* view = new UMLView(f);
00452 view->loadFromXMI(diagramElement);
00453 diagrams.append(view);
00454 diagramNode = diagramNode.nextSibling();
00455 diagramElement = diagramNode.toElement();
00456 }
00457
00458
00459 QDomNode listItemNode = umlviewsNode.nextSibling();
00460 QDomNode listItems = listItemNode.firstChild();
00461 QDomElement listItemElement = listItems.toElement();
00462 if ( listItemElement.isNull() ) {
00463 kWarning() << "no listitems in XMI clip" << endl;
00464 return false;
00465 }
00466 UMLListViewItem *currentItem = (UMLListViewItem*)listView->currentItem();
00467 while ( !listItemElement.isNull() ) {
00468 UMLListViewItem* itemData;
00469 if (currentItem)
00470 itemData = new UMLListViewItem( currentItem );
00471 else
00472 itemData = new UMLListViewItem( listView );
00473 if ( itemData->loadFromXMI(listItemElement) )
00474 umlListViewItems.append(itemData);
00475 else
00476 delete itemData;
00477 listItems = listItems.nextSibling();
00478 listItemElement = listItems.toElement();
00479 }
00480 return true;
00481 }
00482
00483 bool UMLDrag::getClip3TypeAndID(const QMimeSource* mimeSource,
00484 LvTypeAndID_List& typeAndIdList)
00485 {
00486 if ( !mimeSource->provides("application/x-uml-clip3") ) {
00487 return false;
00488 }
00489 QByteArray payload = mimeSource->encodedData("application/x-uml-clip3");
00490 if ( !payload.size() ) {
00491 return false;
00492 }
00493 QTextStream clipdata(payload, IO_ReadOnly);
00494 QString xmiClip = QString::fromUtf8(payload);
00495
00496 QString error;
00497 int line;
00498 QDomDocument domDoc;
00499 if( !domDoc.setContent(xmiClip, false, &error, &line) ) {
00500 kWarning() << "getClip3Type: Can't set content:" << error << " Line:" << line << endl;
00501 return false;
00502 }
00503 QDomNode xmiClipNode = domDoc.firstChild();
00504 QDomElement root = xmiClipNode.toElement();
00505 if ( root.isNull() ) {
00506 return false;
00507 }
00508
00509 if (root.tagName() != "xmiclip") {
00510 return false;
00511 }
00512
00513 QDomNode listItemNode = xmiClipNode.firstChild();
00514 QDomNode listItems = listItemNode.firstChild();
00515 QDomElement listItemElement = listItems.toElement();
00516 if ( listItemElement.isNull() ) {
00517 kWarning() << "getClip3Type: no listitems in XMI clip" << endl;
00518 return false;
00519 }
00520 while ( !listItemElement.isNull() ) {
00521 QString typeStr = listItemElement.attribute( "type", "-1" );
00522 if (typeStr == "-1") {
00523 kDebug() << "getClip3Type: bad type" << endl;
00524 return false;
00525 }
00526 QString idStr = listItemElement.attribute( "id", "-1" );
00527 if (idStr == "-1") {
00528 kDebug() << "getClip3Type: bad id" << endl;
00529 return false;
00530 }
00531 LvTypeAndID * pData = new LvTypeAndID;
00532 pData->type = (Uml::ListView_Type)(typeStr.toInt());
00533 pData->id = STR2ID(idStr);
00534 typeAndIdList.append(pData);
00535 listItems = listItems.nextSibling();
00536 listItemElement = listItems.toElement();
00537 }
00538 return true;
00539 }
00540
00541 bool UMLDrag::decodeClip3(const QMimeSource* mimeSource, UMLListViewItemList& umlListViewItems,
00542 const UMLListView* parentListView){
00543 if ( !mimeSource->provides("application/x-uml-clip3") ) {
00544 return false;
00545 }
00546 QByteArray payload = mimeSource->encodedData("application/x-uml-clip3");
00547 if ( !payload.size() ) {
00548 return false;
00549 }
00550 QTextStream clipdata(payload, IO_ReadOnly);
00551 QString xmiClip = QString::fromUtf8(payload);
00552
00553 QString error;
00554 int line;
00555 QDomDocument domDoc;
00556 if( !domDoc.setContent(xmiClip, false, &error, &line) ) {
00557 kWarning() << "Can't set content:" << error << " Line:" << line << endl;
00558 return false;
00559 }
00560 QDomNode xmiClipNode = domDoc.firstChild();
00561 QDomElement root = xmiClipNode.toElement();
00562 if ( root.isNull() ) {
00563 return false;
00564 }
00565
00566 if (root.tagName() != "xmiclip") {
00567 return false;
00568 }
00569
00570
00571 QDomNode listItemNode = xmiClipNode.firstChild();
00572 QDomNode listItems = listItemNode.firstChild();
00573 QDomElement listItemElement = listItems.toElement();
00574 if ( listItemElement.isNull() ) {
00575 kWarning() << "no listitems in XMI clip" << endl;
00576 return false;
00577 }
00578 while ( !listItemElement.isNull() ) {
00579
00580
00581 QString type = listItemElement.attribute( "type", "-1" );
00582 if (type == "-1") {
00583 kDebug() << "Pech gehabt" << endl;
00584 continue;
00585 }
00586 Uml::ListView_Type t = (Uml::ListView_Type)(type.toInt());
00587 UMLListViewItem* parent = parentListView->determineParentItem(t);
00588 UMLListViewItem* itemData = new UMLListViewItem(parent);
00589 if ( itemData->loadFromXMI(listItemElement) )
00590 umlListViewItems.append(itemData);
00591 else
00592 delete itemData;
00593 listItems = listItems.nextSibling();
00594 listItemElement = listItems.toElement();
00595 }
00596 return true;
00597 }
00598
00599 bool UMLDrag::decodeClip4(const QMimeSource* mimeSource, UMLObjectList& objects,
00600 UMLWidgetList& widgets,
00601 AssociationWidgetList& associations, Uml::Diagram_Type & dType) {
00602 UMLDoc* doc = UMLApp::app()->getDocument();
00603 if ( !mimeSource->provides("application/x-uml-clip4") ) {
00604 return false;
00605 }
00606 QByteArray payload = mimeSource->encodedData("application/x-uml-clip4");
00607 if ( !payload.size() ) {
00608 return false;
00609 }
00610
00611 QString xmiClip = QString::fromUtf8(payload);
00612
00613 QString error;
00614 int line;
00615 QDomDocument domDoc;
00616 if( !domDoc.setContent(xmiClip, false, &error, &line) ) {
00617 kWarning() << "Can't set content:" << error << " Line:" << line << endl;
00618 return false;
00619 }
00620 QDomNode xmiClipNode = domDoc.firstChild();
00621 QDomElement root = xmiClipNode.toElement();
00622 if ( root.isNull() ) {
00623 return false;
00624 }
00625
00626 if ( root.tagName() != "xmiclip" ) {
00627 return false;
00628 }
00629
00630 dType = (Uml::Diagram_Type)(root.attribute("diagramtype", "0").toInt());
00631
00632
00633 QDomNode objectsNode = xmiClipNode.firstChild();
00634 QDomNode objectElement = objectsNode.firstChild();
00635 QDomElement element = objectElement.toElement();
00636 while ( !element.isNull() ) {
00637 UMLObject* pObject = 0;
00638 QString type = element.tagName();
00639
00640 if (type == "UML:Association")
00641 continue;
00642 pObject = Object_Factory::makeObjectFromXMI(type);
00643
00644 if ( !pObject ) {
00645 kWarning() << "Given wrong type of umlobject to create: " << type << endl;
00646 return false;
00647 }
00648
00649 if ( !pObject->loadFromXMI( element ) ) {
00650 kWarning() << "failed to load object from XMI" << endl;
00651 return false;
00652 }
00653
00654 objects.append(pObject);
00655 objectElement = objectElement.nextSibling();
00656 element = objectElement.toElement();
00657 }
00658
00659
00660 QDomNode widgetsNode = objectsNode.nextSibling();
00661 QDomNode widgetNode = widgetsNode.firstChild();
00662 QDomElement widgetElement = widgetNode.toElement();
00663 if ( widgetElement.isNull() ) {
00664 kWarning() << "no widgets in XMI clip" << endl;
00665 return false;
00666 }
00667
00668 UMLView *view = UMLApp::app()->getCurrentView();
00669 while ( !widgetElement.isNull() ) {
00670
00671 UMLWidget* widget = view->loadWidgetFromXMI(widgetElement);
00672 if (widget)
00673 widgets.append(widget);
00674
00675 widgetNode = widgetNode.nextSibling();
00676 widgetElement = widgetNode.toElement();
00677 }
00678
00679
00680 QDomNode associationWidgetsNode = widgetsNode.nextSibling();
00681 QDomNode associationWidgetNode = associationWidgetsNode.firstChild();
00682 QDomElement associationWidgetElement = associationWidgetNode.toElement();
00683 while ( !associationWidgetElement.isNull() ) {
00684 AssociationWidget* associationWidget = new AssociationWidget(view);
00685 if (associationWidget->loadFromXMI(associationWidgetElement, widgets))
00686 associations.append(associationWidget);
00687 else {
00688
00689 delete associationWidget;
00690 }
00691 associationWidgetNode = associationWidgetNode.nextSibling();
00692 associationWidgetElement = associationWidgetNode.toElement();
00693 }
00694
00695 return true;
00696 }
00697
00698 bool UMLDrag::decodeClip5(const QMimeSource* mimeSource, UMLObjectList& objects,
00699 UMLClassifier* newParent) {
00700 if ( !mimeSource->provides("application/x-uml-clip5") ) {
00701 return false;
00702 }
00703 QByteArray payload = mimeSource->encodedData("application/x-uml-clip5");
00704 if ( !payload.size() ) {
00705 return false;
00706 }
00707 QString xmiClip = QString::fromUtf8(payload);
00708
00709 QString error;
00710 int line;
00711 QDomDocument domDoc;
00712 if( !domDoc.setContent(xmiClip, false, &error, &line) ) {
00713 kWarning() << "Can't set content:" << error << " Line:" << line << endl;
00714 return false;
00715 }
00716 QDomNode xmiClipNode = domDoc.firstChild();
00717 QDomElement root = xmiClipNode.toElement();
00718 if ( root.isNull() ) {
00719 return false;
00720 }
00721
00722 if (root.tagName() != "xmiclip") {
00723 return false;
00724 }
00725
00726
00727 QDomNode objectsNode = xmiClipNode.firstChild();
00728 QDomNode objectElement = objectsNode.firstChild();
00729 QDomElement element = objectElement.toElement();
00730 if ( element.isNull() ) {
00731 return false;
00732 }
00733 while ( !element.isNull() ) {
00734 QString type = element.tagName();
00735 UMLClassifierListItem *pObject = newParent->makeChildObject(type);
00736 if( !pObject ) {
00737 kWarning() << "Given wrong type of umlobject to create:" << type << endl;
00738 return false;
00739 }
00740 if( !pObject->loadFromXMI( element ) ) {
00741 kWarning() << "failed to load object from XMI" << endl;
00742 return false;
00743 }
00744 pObject->resolveRef();
00745 objects.append(pObject);
00746 objectElement = objectElement.nextSibling();
00747 element = objectElement.toElement();
00748 }
00749
00750 return true;
00751 }
00752
00753 int UMLDrag::getCodingType(const QMimeSource* mimeSource) {
00754 int result = 0;
00755 if (mimeSource->provides("application/x-uml-clip1") ) {
00756 result = 1;
00757 }
00758 if (mimeSource->provides("application/x-uml-clip2") ) {
00759 result = 2;
00760 }
00761 if (mimeSource->provides("application/x-uml-clip3") ) {
00762 result = 3;
00763 }
00764 if (mimeSource->provides("application/x-uml-clip4") ) {
00765 result = 4;
00766 }
00767 if (mimeSource->provides("application/x-uml-clip5") ) {
00768 result = 5;
00769 }
00770
00771 return result;
00772 }
00773
00774 #include "umldrag.moc"