[Uml-devel] kdesdk/umbrello/umbrello

Oliver Kellogg okellogg at users.sourceforge.net
Sat May 1 07:25:01 UTC 2004


CVS commit by okellogg: 

insertAttribute(name): Return existing UMLAttribute if an attribute of the
 given name already exists.


  M +8 -1      class.cpp   1.32
  M +8 -3      class.h   1.26


--- kdesdk/umbrello/umbrello/class.cpp  #1.31:1.32
@@ -34,6 +34,13 @@ UMLClass::~UMLClass() {
 }
 ////////////////////////////////////////////////////////////////////////////////////////////////////
-UMLAttribute* UMLClass::addAttribute(QString name, int id) {
+UMLAttribute* UMLClass::addAttribute(QString name, int id /* = -1 */) {
+        UMLClassifierListItem *obj = NULL;
+        for (obj = m_AttsList.first(); obj; obj = m_AttsList.next()) {
+                if (obj->getBaseType() == ot_Attribute && obj->getName() == name)
+                        return static_cast<UMLAttribute*>(obj);
+        }
         UMLDoc *umldoc = UMLApp::app()->getDocument();
+        if (id == -1)
+                id = umldoc->getUniqueID();
         Uml::Scope scope = umldoc->getOptionState().classState.defaultAttributeScope;
         UMLAttribute *a = new UMLAttribute(this, name, id, "int", scope);

--- kdesdk/umbrello/umbrello/class.h  #1.25:1.26
@@ -65,10 +65,15 @@ public:
         /**
          * Adds an attribute to the class.
+         * If an attribute of the given name already exists, then
+         * returns the existing attribute instead of creating a new one.
          *
          * @param name          The name of the attribute.
-         * @param id            The id of the attribute.
-         * @return      Pointer to the UMLAttribute created.
+         * @param id            The id of the attribute (optional.)
+         *                      If not given, and the attribute name
+         *                      does not already exist, then the method
+         *                      will internally assign a new ID.
+         * @return      Pointer to the UMLAttribute created or found.
          */
-        UMLAttribute* addAttribute(QString name, int id);
+        UMLAttribute* addAttribute(QString name, int id = -1);
 
         /**






More information about the umbrello-devel mailing list