[Uml-devel] branches/work/soc-umbrello/umbrello

Andi Fischer andi.fischer at hispeed.ch
Fri Sep 25 22:14:36 UTC 2009


SVN commit 1028112 by fischer:

Removing some dependencies.

 M  +1 -7      dialogs/classgenpage.cpp  
 M  +7 -9      listpopupmenu.cpp  
 M  +78 -0     model_utils.cpp  
 M  +4 -9      model_utils.h  
 M  +1 -8      toolbarstateassociation.cpp  
 M  +9 -1      umlnamespace.h  
 M  +1 -12     umlobject.cpp  
 M  +8 -23     umlviewimageexportermodel.cpp  


--- branches/work/soc-umbrello/umbrello/dialogs/classgenpage.cpp #1028111:1028112
@@ -22,8 +22,6 @@
 #include "umlscene.h"
 #include "stereotype.h"
 #include "umlpackagelist.h"
-#include "umllistviewitem.h"
-#include "umllistview.h"
 #include "model_utils.h"
 #include "package.h"
 #include "folder.h"
@@ -433,11 +431,7 @@
             }
 
             // adjust list view items
-            UMLListView *lv = UMLApp::app()->getListView();
-            UMLListViewItem *newLVParent = lv->findUMLObject(newPackage);
-            lv->moveObject(m_pObject->getID(),
-                           Model_Utils::convert_OT_LVT(m_pObject),
-                           newLVParent);
+            Model_Utils::treeViewMoveObjectTo(newPackage, m_pObject);
         }
 
         if ( m_pAbstractCB ) {
--- branches/work/soc-umbrello/umbrello/listpopupmenu.cpp #1028111:1028112
@@ -19,8 +19,6 @@
 // app includes
 #include "widgetbase.h"
 #include "umldoc.h"
-#include "umllistview.h"
-#include "umllistviewitem.h"
 #include "classifierwidget.h"
 #include "classifier.h"
 #include "floatingtextwidget.h"
@@ -898,23 +896,23 @@
         // in the General Settings.
         return;
     }
-    UMLListView *listView = UMLApp::app()->getListView();
-    UMLListViewItem *current = static_cast<UMLListViewItem*>(listView->currentItem());
-    UMLObject *o = current->getUMLObject();
+    UMLObject *o = Model_Utils::treeViewGetCurrentObject();
     if (o == NULL) {
-        uError() << current->getText() << " getUMLObject()  returns NULL";
+        uError() << " Model_Utils::treeViewGetCurrentObject() returns NULL";
         return;
     }
     UMLFolder *f = dynamic_cast<UMLFolder*>(o);
     if (f == NULL) {
-        uError() << "current->getUMLObject (" << o->getName() << ") is not a Folder";
+        uError() << o->getName() << " is not a Folder";
         return;
     }
     QString submodelFile = f->getFolderFile();
-    if (submodelFile.isEmpty())
+    if (submodelFile.isEmpty()) {
         insert(mt_Externalize_Folder);
-    else
+    }
+    else {
         insert(mt_Internalize_Folder);
+    }
 }
 
 /**
--- branches/work/soc-umbrello/umbrello/model_utils.cpp #1028111:1028112
@@ -310,6 +310,84 @@
 }
 
 /**
+ * Move an object to a new container in the tree view.
+ * @param container   the new container for the object
+ * @param object      the to be moved object
+ */
+void treeViewMoveObjectTo(UMLObject* container, UMLObject* object)
+{
+    UMLListView *listView = UMLApp::app()->getListView();
+    UMLListViewItem *newParent = listView->findUMLObject(container);
+    listView->moveObject(object->getID(),
+                   Model_Utils::convert_OT_LVT(object),
+                   newParent);
+}
+
+/**
+ * Return the current UMLObject from the tree view.
+ * @return   the UML object of the current item
+ */
+UMLObject* treeViewGetCurrentObject()
+{
+    UMLListView *listView = UMLApp::app()->getListView();
+    UMLListViewItem *current = static_cast<UMLListViewItem*>(listView->currentItem());
+    return current->getUMLObject();
+}
+
+/**
+ * Return the UMLPackage if the current item
+ * in the tree view is a package.
+ * @return   the package or NULL
+ */
+UMLPackage* treeViewGetPackageFromCurrent()
+{
+    UMLListView *listView = UMLApp::app()->getListView();
+    UMLListViewItem *parentItem = (UMLListViewItem*)listView->currentItem();
+    if (parentItem) {
+        Uml::ListView_Type lvt = parentItem->getType();
+        if (Model_Utils::typeIsContainer(lvt) ||
+            lvt == Uml::lvt_Class ||
+            lvt == Uml::lvt_Interface) {
+            UMLObject *o = parentItem->getUMLObject();
+            return static_cast<UMLPackage*>(o);
+        }
+    }
+    return NULL;
+}
+
+/**
+ * Build the diagram name from the tree view.
+ * @param id   the id of the diaram
+ * @return     the constructed diagram name
+ */
+QString treeViewBuildDiagramName(Uml::IDType id)
+{
+    UMLListView *listView = UMLApp::app()->getListView();
+    UMLListViewItem* listViewItem = listView->findItem(id);
+
+    if (listViewItem) {
+        // skip the name of the first item because it's the View
+        listViewItem = static_cast<UMLListViewItem*>(listViewItem->parent());
+        
+        // Relies on the tree structure of the UMLListView. There are a base "Views" folder
+        // and five children, one for each view type (Logical, use case, components, deployment
+        // and entity relationship)
+        QString name;
+        while (listView->rootView(listViewItem->getType()) == NULL) {
+            name.insert(0, listViewItem->getText() + '/');
+            listViewItem = static_cast<UMLListViewItem*>(listViewItem->parent());
+            if (listViewItem == NULL)
+                break;
+        }
+        return name;
+    }
+    else {
+        uWarning() << "diagram not found - returning empty name!";
+        return QString();
+    }
+}
+
+/**
  * Returns a name for the new object, appended with a number
  * if the default name is taken e.g. new_actor, new_actor_1
  * etc.
--- branches/work/soc-umbrello/umbrello/model_utils.h #1028111:1028112
@@ -24,7 +24,6 @@
 class UMLClassifier;
 class UMLPackage;
 class UMLEntity;
-class UMLForeignKeyConstraint;
 
 /**
  * General purpose model utilities.
@@ -45,6 +44,10 @@
 void treeViewAddViews(const UMLViewList& viewList);
 void treeViewChangeIcon(UMLObject* object, Icon_Utils::Icon_Type to);
 void treeViewSetCurrentItem(UMLObject* object);
+void treeViewMoveObjectTo(UMLObject* container, UMLObject* object);
+UMLObject*  treeViewGetCurrentObject();
+UMLPackage* treeViewGetPackageFromCurrent();
+QString treeViewBuildDiagramName(Uml::IDType id);
 
 QString uniqObjectName(Uml::Object_Type type,
                        UMLPackage *parentPkg,
@@ -120,14 +123,6 @@
 
 QString updateDeleteActionToString( UMLForeignKeyConstraint::UpdateDeleteAction uda );
 
-/**
- * In a Q_OBJECT class define any enum as Q_ENUMS.
- * With the above the following macro returns the name of a given enum.
- * This can be used in debug output.
- * TODO: convert it to a function.
- */
-#define ENUM_NAME(o,e,v) (o::staticMetaObject.enumerator(o::staticMetaObject.indexOfEnumerator(#e)).valueToKey((v)))
-
 }
 
 #endif
--- branches/work/soc-umbrello/umbrello/toolbarstateassociation.cpp #1028111:1028112
@@ -26,7 +26,6 @@
 #include "uml.h"
 #include "umlobject.h"
 #include "umlscene.h"
-#include "umllistview.h"
 #include "umldoc.h"
 #include "umlwidget.h"
 
@@ -62,7 +61,6 @@
 void ToolBarStateAssociation::init()
 {
     ToolBarStatePool::init();
-
     cleanAssociation();
 }
 
@@ -73,7 +71,6 @@
 void ToolBarStateAssociation::cleanBeforeChange()
 {
     ToolBarStatePool::cleanBeforeChange();
-
     cleanAssociation();
 }
 
@@ -237,14 +234,10 @@
         AssociationWidget *temp = new AssociationWidget(widgetA, type, widgetB);
         addAssociationInViewAndDoc(temp);
         if (type == at_Containment) {
-            UMLListView *lv = UMLApp::app()->getListView();
             UMLObject *newContainer = widgetA->umlObject();
             UMLObject *objToBeMoved = widgetB->umlObject();
             if (newContainer && objToBeMoved) {
-                UMLListViewItem *newLVParent = lv->findUMLObject(newContainer);
-                lv->moveObject(objToBeMoved->getID(),
-                               Model_Utils::convert_OT_LVT(objToBeMoved),
-                               newLVParent);
+                Model_Utils::treeViewMoveObjectTo(newContainer, objToBeMoved);
             }
         }
         UMLApp::app()->getDocument()->setModified();
--- branches/work/soc-umbrello/umbrello/umlnamespace.h #1028111:1028112
@@ -4,7 +4,7 @@
  *   the Free Software Foundation; either version 2 of the License, or     *
  *   (at your option) any later version.                                   *
  *                                                                         *
- *   copyright (C) 2002-2008                                               *
+ *   copyright (C) 2002-2009                                               *
  *   Umbrello UML Modeller Authors <uml-devel at uml.sf.net>                  *
  ***************************************************************************/
 
@@ -352,4 +352,12 @@
 
 #define uIgnoreZeroPointer(a) if (!a) { uDebug() << "zero pointer detected" << __FILE__ << __LINE__; continue; }
 
+/**
+ * In a Q_OBJECT class define any enum as Q_ENUMS.
+ * With the above the following macro returns the name of a given enum.
+ * This can be used in debug output.
+ * TODO: convert it to a function.
+ */
+#define ENUM_NAME(o,e,v) (o::staticMetaObject.enumerator(o::staticMetaObject.indexOfEnumerator(#e)).valueToKey((v)))
+
 #endif
--- branches/work/soc-umbrello/umbrello/umlobject.cpp #1028111:1028112
@@ -1030,18 +1030,7 @@
             m_BaseType != Uml::ot_Role && m_BaseType != Uml::ot_UniqueConstraint &&
             m_BaseType != Uml::ot_ForeignKeyConstraint) {
         if (m_bInPaste) {
-            m_pUMLPackage = NULL;  // forget any old parent
-            UMLListView *listView = UMLApp::app()->getListView();
-            UMLListViewItem *parentItem = (UMLListViewItem*)listView->currentItem();
-            if (parentItem) {
-                Uml::ListView_Type lvt = parentItem->getType();
-                if (Model_Utils::typeIsContainer(lvt) ||
-                        lvt == Uml::lvt_Class ||
-                        lvt == Uml::lvt_Interface) {
-                    UMLObject *o = parentItem->getUMLObject();
-                    m_pUMLPackage = static_cast<UMLPackage*>(o);
-                }
-            }
+            m_pUMLPackage = Model_Utils::treeViewGetPackageFromCurrent();
         }
         if (m_pUMLPackage) {
             m_pUMLPackage->addObject(this);
--- branches/work/soc-umbrello/umbrello/umlviewimageexportermodel.cpp #1028111:1028112
@@ -33,11 +33,10 @@
 #include <kio/netaccess.h>
 
 // application specific includes
+#include "model_utils.h"
 #include "uml.h"
 #include "umldoc.h"
 #include "umlview.h"
-#include "umllistview.h"
-#include "umllistviewitem.h"
 #include "umlscene.h"
 
 static QStringList supportedImageTypesList;
@@ -260,29 +259,15 @@
  */
 QString UMLViewImageExporterModel::getDiagramFileName(UMLView *view, const QString &imageType, bool useFolders /* = false */) const
 {
-    // [PORT]
-    QString name = view->umlScene()->getName() + '.' + imageType.toLower();
-
-    if (!useFolders) {
-        return name;
+    UMLScene* scene = view->umlScene();
+    if (useFolders) {
+        qApp->processEvents();  //:TODO: still needed ???
+        return Model_Utils::treeViewBuildDiagramName(scene->getID());
     }
-
-    qApp->processEvents();
-    UMLListView *listView = UMLApp::app()->getListView();
-    UMLListViewItem* listViewItem = listView->findItem(view->umlScene()->getID());
-    // skip the name of the first item because it's the View
-    listViewItem = static_cast<UMLListViewItem*>(listViewItem->parent());
-
-    // Relies on the tree structure of the UMLListView. There are a base "Views" folder
-    // and five children, one for each view type (Logical, use case, components, deployment
-    // and entity relationship)
-    while (listView->rootView(listViewItem->getType()) == NULL) {
-        name.insert(0, listViewItem->getText() + '/');
-        listViewItem = static_cast<UMLListViewItem*>(listViewItem->parent());
-        if (listViewItem == NULL)
-            break;
+    else {
+        // [PORT]
+        return scene->getName() + '.' + imageType.toLower();;
     }
-    return name;
 }
 
 /**




More information about the umbrello-devel mailing list