[Uml-devel] kdesdk/umbrello/umbrello

Brian Thomas thomas at mail630.gsfc.nasa.gov
Thu Apr 15 21:30:05 UTC 2004


CVS commit by thomas: 

bug fix: allow classes, interfaces, etc. to have unique name within the *package* rather than the entire hierarchy of umlobjects. Repeated names are ok IF they occur in separate packages


  M +36 -4     umldoc.cpp   1.138
  M +8 -0      umldoc.h   1.62
  M +4 -5      umllistviewitem.cpp   1.35


--- kdesdk/umbrello/umbrello/umldoc.cpp  #1.137:1.138
@@ -625,9 +625,25 @@ void UMLDoc::slotRemoveUMLObject(UMLObje
 bool UMLDoc::isUnique(QString name)
 {
-        UMLListViewItem *parentItem = (UMLListViewItem*)listView->currentItem();
+        UMLListViewItem *currentItem = (UMLListViewItem*)listView->currentItem();
+        UMLListViewItem *parentItem = 0;
+
+        // check for current item, if its a package, then we do a check on that  
+        // otherwise, if current item exists, find its parent and check if thats
+        // a package..
+        if(currentItem)
+        {
+                // its possible that the current item *is* a package, then just 
+                // do check now
+                if(currentItem->getType() == lvt_Package)
+                        return isUnique (name, (UMLPackage*) currentItem->getUMLObject());
+                parentItem = (UMLListViewItem*)currentItem->parent();
+        }
+
+        // item is in a package so do check only in that 
         if (parentItem != NULL && parentItem->getType() == lvt_Package) {
                 UMLPackage *parentPkg = (UMLPackage*)parentItem->getUMLObject();
-                return (parentPkg->findObject(name) == NULL);
+                return isUnique(name, parentPkg);
         }
+
         // Not currently in a package:
         // Check against all objects that _dont_ have a parent package.
@@ -638,4 +654,20 @@ bool UMLDoc::isUnique(QString name)
 }
 
+bool UMLDoc::isUnique(QString name, UMLPackage *package)
+{
+
+        // if a package, then only do check in that
+        if (package) 
+                return (package->findObject(name) == NULL);
+
+        // Not currently in a package:
+        // Check against all objects that _dont_ have a parent package.
+        for (UMLObject *obj = objectList.first(); obj; obj = objectList.next())
+                if (obj->getUMLPackage() == NULL && obj->getName() == name)
+                        return false;
+        return true;
+
+}
+
 UMLObject* UMLDoc::createUMLObject(const std::type_info &type)
 {
@@ -673,5 +705,5 @@ UMLObject* UMLDoc::createUMLObject(UMLOb
         int id;
         QString name;
-        if( !n.isEmpty() && isUnique(n) )
+        if( !n.isEmpty() && isUnique(n, parentPkg) )
         {
                 name = n;
@@ -689,5 +721,5 @@ UMLObject* UMLDoc::createUMLObject(UMLOb
                                 continue;
                         }
-                        if (! isUnique(name)) {
+                        if (! isUnique(name, parentPkg)) {
                                 KMessageBox::error(0, i18n("That name is already being used."), i18n("Not a Unique Name"));
                                 name = "";

--- kdesdk/umbrello/umbrello/umldoc.h  #1.61:1.62
@@ -209,4 +209,12 @@ public:
 
         /**
+         * Returns true if the given name is unique within its scope of given package.
+         *
+         * @param name          The name to check.
+         * @return      True if name is unique.
+         */
+        bool isUnique(QString name, UMLPackage *package); 
+
+        /**
          * Creates a @ref UMLObject of the given type.
          *

--- kdesdk/umbrello/umbrello/umllistviewitem.cpp  #1.34:1.35
@@ -300,12 +300,11 @@ void UMLListViewItem::okRename( int col 
                         object = m_pObject;
                         if( object ) {
-                                object = doc -> findUMLObject( newText );
-                                if( object && object == m_pObject )
-                                        object = 0;
-                                if( !object ) {
+                                if(doc->isUnique(newText))
+                                {
                                         m_pObject -> setName( newText );
                                         m_Label = newText;
                                         return;
-                                }
+                                } else
+                                        object = 0;
                         }
                         break;






More information about the umbrello-devel mailing list