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

Oliver Kellogg okellogg at users.sourceforge.net
Thu Jun 7 10:10:33 UTC 2007


SVN commit 672510 by okellogg:

UMLAttribute(parent,name,id,s,type,iv): Change "type" arg to UMLObject*.
UMLClassifier::createAttribute(): Add more parameters to avoid calling separate
 setters which result in futile modified() signals.


 M  +6 -10     attribute.cpp  
 M  +1 -1      attribute.h  
 M  +8 -7      classifier.cpp  
 M  +7 -1      classifier.h  
 M  +3 -2      entity.cpp  
 M  +4 -3      entity.h  
 M  +1 -1      entityattribute.cpp  
 M  +1 -1      entityattribute.h  
 M  +13 -14    umllistview.cpp  


--- branches/KDE/3.5/kdesdk/umbrello/umbrello/attribute.cpp #672509:672510
@@ -26,22 +26,18 @@
 UMLAttribute::UMLAttribute( const UMLObject *parent,
                             const QString& name, Uml::IDType id,
                             Uml::Visibility s,
-                            const QString& type, const QString& iv )
+                            UMLObject *type, const QString& iv )
         : UMLClassifierListItem(parent, name, id) {
     m_InitialValue = iv;
     m_BaseType = Uml::ot_Attribute;
     m_Vis = s;
     m_ParmKind = Uml::pd_In;
-    if (!type.isEmpty()) {
-        UMLDoc *pDoc = UMLApp::app()->getDocument();
-        m_pSecondary = pDoc->findUMLObject(type);
-        if (m_pSecondary == NULL) {
-            if (type.contains( QRegExp("[\\*\\&]") ))
-                m_pSecondary = Object_Factory::createUMLObject(Uml::ot_Datatype, type);
-            else
-                m_pSecondary = Object_Factory::createUMLObject(Uml::ot_Class, type);
-        }
+    /* CHECK: Do we need this:
+    if (type == NULL) {
+        type = Object_Factory::createUMLObject(Uml::ot_Datatype, "undef");
     }
+     */
+    m_pSecondary = type;
 }
 
 UMLAttribute::UMLAttribute(const UMLObject *parent) : UMLClassifierListItem(parent) {
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/attribute.h #672509:672510
@@ -40,7 +40,7 @@
     UMLAttribute(const UMLObject *parent, const QString& name,
                  Uml::IDType id = Uml::id_None,
                  Uml::Visibility s = Uml::Visibility::Private,
-                 const QString& type = "int", const QString& iv = 0);
+                 UMLObject *type = 0, const QString& iv = 0);
 
     /**
      * Sets up an attribute.
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/classifier.cpp #672509:672510
@@ -182,10 +182,9 @@
     if (params) {
         for (Model_Utils::NameAndType_ListIt it = params->begin(); it != params->end(); ++it ) {
             const Model_Utils::NameAndType &nt = *it;
-            UMLAttribute *par = new UMLAttribute(op, nt.m_name);
-            par->setType(nt.m_type);
+            UMLAttribute *par = new UMLAttribute(op, nt.m_name, Uml::id_None, Uml::Visibility::Private,
+                                                 nt.m_type, nt.m_initialValue);
             par->setParmKind(nt.m_direction);
-            par->setInitialValue(nt.m_initialValue);
             op->addParm(par);
         }
     }
@@ -496,7 +495,10 @@
     return false; //shutup compiler warning
 }
 
-UMLAttribute* UMLClassifier::createAttribute(const QString &name /*=null*/) {
+UMLAttribute* UMLClassifier::createAttribute(const QString &name /*=null*/,
+                                             UMLObject *type,
+                                             Uml::Visibility vis,
+                                             const QString &init) {
     Uml::IDType id = UniqueID::gen();
     QString currentName;
     if (name.isNull())  {
@@ -504,9 +506,7 @@
     } else {
         currentName = name;
     }
-    const Settings::OptionState optionState = Settings::getOptionState();
-    Uml::Visibility scope = optionState.classState.defaultAttributeScope;
-    UMLAttribute* newAttribute = new UMLAttribute(this, currentName, id, scope);
+    UMLAttribute* newAttribute = new UMLAttribute(this, currentName, id, vis, type, init);
 
     int button = QDialog::Accepted;
     bool goodName = false;
@@ -528,6 +528,7 @@
     }
 
     if (button != QDialog::Accepted) {
+        delete newAttribute;
         return NULL;
     }
 
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/classifier.h #672509:672510
@@ -78,9 +78,15 @@
      * Creates an attribute for the class.
      *
      * @param name  An optional name, used by when creating through UMLListView
+     * @param type  An optional type, used by when creating through UMLListView
+     * @param vis   An optional visibility, used by when creating through UMLListView
+     * @param init  An optional initial value, used by when creating through UMLListView
      * @return  The UMLAttribute created
      */
-    virtual UMLAttribute* createAttribute(const QString &name = QString::null);
+    virtual UMLAttribute* createAttribute(const QString &name = QString::null,
+                                          UMLObject *type = 0,
+                                          Uml::Visibility vis = Uml::Visibility::Private,
+                                          const QString &init = QString::null);
 
     /**
      * Adds an attribute to the class.
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/entity.cpp #672509:672510
@@ -52,7 +52,7 @@
     m_BaseType = Uml::ot_Entity;
 }
 
-UMLAttribute* UMLEntity::createAttribute(const QString &name /*=null*/) {
+UMLAttribute* UMLEntity::createAttribute(const QString &name /*=null*/, UMLObject *type /*=NULL*/) {
     Uml::IDType id = UniqueID::gen();
     QString currentName;
     if (name.isNull())  {
@@ -62,7 +62,7 @@
     }
     const Settings::OptionState optionState = Settings::getOptionState();
     Uml::Visibility scope = optionState.classState.defaultAttributeScope;
-    UMLEntityAttribute* newAttribute = new UMLEntityAttribute(this, currentName, id, scope);
+    UMLEntityAttribute* newAttribute = new UMLEntityAttribute(this, currentName, id, scope, type);
 
     int button = QDialog::Accepted;
     bool goodName = false;
@@ -84,6 +84,7 @@
     }
 
     if (button != QDialog::Accepted) {
+        delete newAttribute;
         return NULL;
     }
 
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/entity.h #672509:672510
@@ -5,7 +5,7 @@
  *   the Free Software Foundation; either version 2 of the License, or     *
  *   (at your option) any later version.                                   *
  *                                                                         *
- *   copyright (C) 2003-2006                                               *
+ *   copyright (C) 2003-2007                                               *
  *   Umbrello UML Modeller Authors <uml-devel at uml.sf.net>                  *
  ***************************************************************************/
 
@@ -62,11 +62,12 @@
      * Creates an entity attribute for the parent concept.
      * Reimplementation of method from UMLClassifier.
      *
-     * @param o The parent concept
      * @param name  An optional name, used by when creating through UMLListView
+     * @param type  An optional type, used by when creating through UMLListView
      * @return  The UMLEntityAttribute created
      */
-    UMLAttribute* createAttribute(const QString &name = QString::null);
+    UMLAttribute* createAttribute(const QString &name = QString::null,
+                                  UMLObject *type = 0);
 
     /**
          * Adds an entityAttribute to the entity.
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/entityattribute.cpp #672509:672510
@@ -23,7 +23,7 @@
 
 UMLEntityAttribute::UMLEntityAttribute( const UMLObject *parent, const QString& name,
                                         Uml::IDType id, Uml::Visibility s,
-                                        const QString& type, const QString& iv )
+                                        UMLObject *type, const QString& iv )
         : UMLAttribute(parent, name, id, s, type, iv) {
     init();
     if (m_pSecondary) {
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/entityattribute.h #672509:672510
@@ -39,7 +39,7 @@
     UMLEntityAttribute(const UMLObject* parent, const QString& name,
                        Uml::IDType id = Uml::id_None,
                        Uml::Visibility s = Uml::Visibility::Private,
-                       const QString& type = "int", const QString& iv = 0);
+                       UMLObject *type = 0, const QString& iv = 0);
 
     /**
      * Sets up an entityattribute.
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umllistview.cpp #672509:672510
@@ -1409,11 +1409,10 @@
                         << att->getName() << ") returns NULL" << endl;
                 } else {
                     const QString& nm = att->getName();
-                    UMLAttribute *newAtt = newParentClassifier->createAttribute(nm);
-                    newAtt->setType(att->getType());
-                    newAtt->setVisibility(att->getVisibility());
-                    newAtt->setInitialValue(att->getInitialValue());
-
+                    UMLAttribute *newAtt = newParentClassifier->createAttribute(nm,
+                                                                                att->getType(),
+                                                                                att->getVisibility(),
+                                                                                att->getInitialValue());
                     newItem->setUMLObject(newAtt);
                     newParent->addClassifierListItem( newAtt, newItem );
 
@@ -1442,11 +1441,13 @@
                     UMLAttributeList parmList = op->getParmList();
                     for (UMLAttributeListIt plit(parmList); plit.current(); ++plit) {
                         UMLAttribute *parm = plit.current();
-                        UMLAttribute *newParm = new UMLAttribute(newParentClassifier, parm->getName());
-                        newParm->setVisibility(parm->getVisibility());
-                        newParm->setType(parm->getType());
+                        UMLAttribute *newParm = new UMLAttribute(newParentClassifier,
+                                                                 parm->getName(),
+                                                                 Uml::id_None,
+                                                                 parm->getVisibility(),
+                                                                 parm->getType(),
+                                                                 parm->getInitialValue());
                         newParm->setParmKind(parm->getParmKind());
-                        newParm->setInitialValue(parm->getInitialValue());
                         newOp->addParm(newParm);
                     }
                     newItem->setUMLObject(newOp);
@@ -2099,12 +2100,9 @@
             m_bCreatingChildObject = false;
             return false;
         }
-        newObject = owningClass->createAttribute(nt.m_name);
+        newObject = owningClass->createAttribute(nt.m_name, nt.m_type, vis, nt.m_initialValue);
         UMLAttribute *att = static_cast<UMLAttribute*>(newObject);
-        att->setType(nt.m_type);
-        att->setVisibility(vis);
         att->setParmKind(nt.m_direction);
-        att->setInitialValue(nt.m_initialValue);
         text = att->toString(Uml::st_SigNoVis);
     } else if ( type == Uml::ot_Operation ) {
         UMLClassifier *owningClassifier = static_cast<UMLClassifier*>(parent);
@@ -2152,7 +2150,8 @@
 
     m_bCreatingChildObject = false;
 
-    //m_doc->setModified();
+    if (! m_doc->loading())
+        m_doc->setModified();
     return true;
 }
 




More information about the umbrello-devel mailing list