[Uml-devel] KDE/kdesdk/umbrello/umbrello

Oliver Kellogg okellogg at users.sourceforge.net
Sat Sep 16 13:51:22 UTC 2006


SVN commit 585190 by okellogg:

merge changes from branches/KDE/3.5 (r584893:585145)

 M  +2 -1      association.cpp  
 M  +5 -6      folder.cpp  
 M  +24 -28    model_utils.cpp  
 M  +39 -1     umldoc.cpp  
 M  +21 -0     umldoc.h  
 M  +1 -1      umllistviewitem.cpp  
 M  +2 -2      umlobject.cpp  


--- trunk/KDE/kdesdk/umbrello/umbrello/association.cpp #585189:585190
@@ -17,6 +17,7 @@
 #include <qregexp.h>
 // app includes
 #include "classifier.h"
+#include "folder.h"
 #include "uml.h"
 #include "umldoc.h"
 #include "umlrole.h"
@@ -553,7 +554,7 @@
     m_Name = "";
     m_bOldLoadMode = false;
     nrof_parent_widgets = -1;
-
+    m_pUMLPackage = UMLApp::app()->getDocument()->currentRoot();
     m_pRole[Uml::A] = new UMLRole (this, roleAObj, Uml::A);
     m_pRole[Uml::B] = new UMLRole (this, roleBObj, Uml::B);
 }
--- trunk/KDE/kdesdk/umbrello/umbrello/folder.cpp #585189:585190
@@ -202,12 +202,9 @@
 void UMLFolder::save(QDomDocument& qDoc, QDomElement& qElement) {
     UMLDoc *umldoc = UMLApp::app()->getDocument();
     QString elementName("UML:Package");
-    for (int i = 0; i < Uml::N_MODELTYPES; i++) {
-        if (this == umldoc->getRootFolder((Uml::Model_Type)i)) {
-            elementName = "UML:Model";
-            break;
-        }
-    }
+    const Uml::Model_Type mt = umldoc->rootFolderType(this);
+    if (mt != Uml::N_MODELTYPES)
+        elementName = "UML:Model";
     QDomElement folderElement = UMLObject::save(elementName, qDoc);
     saveContents(qDoc, folderElement);
     qElement.appendChild(folderElement);
@@ -392,6 +389,8 @@
             removeObject(pObject);
             delete pObject;
             totalSuccess = false;
+        } else {
+            addObject(pObject);
         }
     }
     return totalSuccess;
--- trunk/KDE/kdesdk/umbrello/umbrello/model_utils.cpp #585189:585190
@@ -347,11 +347,9 @@
                         while (pkg->getUMLPackage()) {  // wind back to root
                             pkg = pkg->getUMLPackage();
                         }
-                        for (int i = 0; i < Uml::N_MODELTYPES; i++) {
-                            Uml::Model_Type m = (Uml::Model_Type)i;
-                            if (pkg == umldoc->getRootFolder(m))
-                                return m;
-                        }
+                        const Uml::Model_Type m = umldoc->rootFolderType(pkg);
+                        if (m != Uml::N_MODELTYPES)
+                            return m;
                     }
                     mt = guessContainer(roleObj);
                     if (mt != Uml::mt_Logical)
@@ -830,30 +828,28 @@
             UMLDoc *umldoc = UMLApp::app()->getDocument();
             UMLFolder *f = static_cast<UMLFolder*>(o);
             do {
-                for (int i = 0; i < Uml::N_MODELTYPES; i++) {
-                    const Uml::Model_Type mt = (Uml::Model_Type)i;
-                    if (f == umldoc->getRootFolder(mt)) {
-                        switch (mt) {
-                            case Uml::mt_Logical:
-                                type = Uml::lvt_Logical_Folder;
-                                break;
-                            case Uml::mt_UseCase:
-                                type = Uml::lvt_UseCase_Folder;
-                                break;
-                            case Uml::mt_Component:
-                                type = Uml::lvt_Component_Folder;
-                                break;
-                            case Uml::mt_Deployment:
-                                type = Uml::lvt_Deployment_Folder;
-                                break;
-                            case Uml::mt_EntityRelationship:
-                                type = Uml::lvt_EntityRelationship_Folder;
-                                break;
-                            default:
-                                break;
-                        }
-                        return type;
+                const Uml::Model_Type mt = umldoc->rootFolderType(f);
+                if (mt != Uml::N_MODELTYPES) {
+                    switch (mt) {
+                        case Uml::mt_Logical:
+                            type = Uml::lvt_Logical_Folder;
+                            break;
+                        case Uml::mt_UseCase:
+                            type = Uml::lvt_UseCase_Folder;
+                            break;
+                        case Uml::mt_Component:
+                            type = Uml::lvt_Component_Folder;
+                            break;
+                        case Uml::mt_Deployment:
+                            type = Uml::lvt_Deployment_Folder;
+                            break;
+                        case Uml::mt_EntityRelationship:
+                            type = Uml::lvt_EntityRelationship_Folder;
+                            break;
+                        default:
+                            break;
                     }
+                    return type;
                 }
             } while ((f = static_cast<UMLFolder*>(f->getUMLPackage())) != NULL);
             kError() << "convert_OT_LVT(" << o->getName()
--- trunk/KDE/kdesdk/umbrello/umbrello/umldoc.cpp #585189:585190
@@ -94,6 +94,7 @@
     m_pAutoSaveTimer = 0;
     m_nViewID = Uml::id_None;
     m_pTabPopupMenu = 0;
+    m_pCurrentRoot = NULL;
 }
 
 void UMLDoc::init() {
@@ -111,6 +112,7 @@
     }
     m_datatypeRoot = new UMLFolder(m_datatypeFolderName);
     m_datatypeRoot->markPredefined();
+    m_datatypeRoot->setUMLPackage(m_root[Uml::mt_Logical]);
     m_root[Uml::mt_Logical]->addObject(m_datatypeRoot);
 
     // Connect signals.
@@ -291,6 +293,7 @@
         // Restore the datatype folder, it has been deleted above.
         m_datatypeRoot = new UMLFolder(m_datatypeFolderName);
         m_datatypeRoot->markPredefined();
+        m_datatypeRoot->setUMLPackage(m_root[Uml::mt_Logical]);
         m_root[Uml::mt_Logical]->addObject(m_datatypeRoot);
         listView->theDatatypeFolder()->setUMLObject(m_datatypeRoot);
         /* Remove any stereotypes.
@@ -1160,6 +1163,22 @@
     }
 }
 
+UMLFolder *UMLDoc::currentRoot() {
+    UMLView *currentView = UMLApp::app()->getCurrentView();
+    if (currentView == NULL) {
+        if (m_pCurrentRoot)
+            return m_pCurrentRoot;
+        kError() << "UMLDoc::currentRoot: currentView is NULL, assuming Logical View"
+            << endl;
+        return m_root[Uml::mt_Logical];
+    }
+    UMLFolder *f = currentView->getFolder();
+    while (f->getUMLPackage()) {
+        f = static_cast<UMLFolder*>(f->getUMLPackage());
+    }
+    return f;
+}
+
 void UMLDoc::removeUMLObject(UMLObject* umlobject) {
     UMLApp::app()->getDocWindow()->updateDocumentation(true);
     Object_Type type = umlobject->getBaseType();
@@ -1629,6 +1648,7 @@
         }
     } else {
         createDiagram(m_root[mt_Logical], Uml::dt_Class, false);
+        m_pCurrentRoot = m_root[mt_Logical];
     }
     emit sigResetStatusbarProgress();
     return true;
@@ -1692,6 +1712,13 @@
     emit sigWriteToStatusBar( i18n("Loading UML elements...") );
 
     bool bNativityIsDetermined = false;
+    const QString nativeRootName[Uml::N_MODELTYPES] = {
+        "Logical View",
+        "Use Case View",
+        "Component View",
+        "Deployment View",
+        "Entity Relationship Model"
+    };
     for (QDomNode node = element.firstChild(); !node.isNull();
             node = node.nextSibling()) {
         if (node.isComment())
@@ -1702,7 +1729,9 @@
             bool foundUmbrelloRootFolder = false;
             QString name = tempElement.attribute("name");
             for (int i = 0; i < Uml::N_MODELTYPES; i++) {
-                if (name == m_root[i]->getName()) {
+                if (name == m_root[i]->getName() ||
+                    name == nativeRootName[i]) {  // @todo checking for name creates i18n problem
+                    m_pCurrentRoot = m_root[i];
                     m_root[i]->loadFromXMI(tempElement);
                     foundUmbrelloRootFolder = true;
                     break;
@@ -2035,6 +2064,15 @@
     return m_root[mt];
 }
 
+Uml::Model_Type UMLDoc::rootFolderType(UMLObject *obj) {
+    for (int i = 0; i < Uml::N_MODELTYPES; i++) {
+        const Uml::Model_Type m = (Uml::Model_Type)i;
+        if (obj == m_root[m])
+            return m;
+    }
+    return Uml::N_MODELTYPES;
+}
+
 /** Read property of IDChangeLog* m_pChangeLog. */
 IDChangeLog* UMLDoc::getChangeLog() {
     return m_pChangeLog;
--- trunk/KDE/kdesdk/umbrello/umbrello/umldoc.h #585189:585190
@@ -620,6 +620,20 @@
     UMLFolder *getRootFolder(Uml::Model_Type mt);
 
     /**
+     * Return the corresponding Model_Type if the given object
+     * is one of the root folders.
+     * When the given object is not one of the root folders then
+     * return Uml::N_MODELTYPES.
+     */
+    Uml::Model_Type rootFolderType(UMLObject *obj);
+
+    /**
+     * Return the currently selected root folder.
+     * This will be an element from the m_root[] array.
+     */
+    UMLFolder *currentRoot();
+
+    /**
      * Read property of IDChangeLog* m_pChangeLog.
      *
      * @return  Pointer to the IDChangeLog object.
@@ -879,6 +893,13 @@
      */
     KMenu* m_pTabPopupMenu;
 
+    /**
+     * Auxiliary variable for currentRoot():
+     * m_pCurrentRoot is only used if UMLApp::app()->getCurrentView()
+     * returns NULL.
+     */
+    UMLFolder * m_pCurrentRoot;
+
 public slots:
 
     void slotRemoveUMLObject(UMLObject*o);
--- trunk/KDE/kdesdk/umbrello/umbrello/umllistviewitem.cpp #585189:585190
@@ -634,7 +634,7 @@
     UMLDoc *umldoc = s_pListView->getDocument();
     UMLFolder *extFolder = NULL;
     if (m_pObject == NULL) {
-        if (! Model_Utils::typeIsDiagram(m_Type))
+        if (! Model_Utils::typeIsDiagram(m_Type) && m_Type != Uml::lvt_View)
             kError() << "UMLListViewItem::saveToXMI(" << m_Label
                 << "): m_pObject is NULL" << endl;
         itemElement.setAttribute( "label", m_Label );
--- trunk/KDE/kdesdk/umbrello/umbrello/umlobject.cpp #585189:585190
@@ -754,8 +754,8 @@
             }
         } else if (m_pUMLPackage) {
             m_pUMLPackage->addObject(this);
-        } else {
-            kError() << "UMLObject::load(" << m_Name << "): m_pUMLPackage is not set"
+        } else if (umldoc->rootFolderType(this) == Uml::N_MODELTYPES) {
+            kError() << "UMLObject::loadFromXMI(" << m_Name << "): m_pUMLPackage is not set"
                 << endl;
         }
     }




More information about the umbrello-devel mailing list