[Uml-devel] kdesdk/umbrello

Oliver Kellogg okellogg at users.sourceforge.net
Sun Oct 3 13:03:06 UTC 2004


CVS commit by okellogg: 

Fix bug 82342: Create datatype if pointer, else create class.


  M +3 -3      ChangeLog   1.37
  M +26 -35    umbrello/dialogs/umlattributedialog.cpp   1.21


--- kdesdk/umbrello/ChangeLog  #1.36:1.37
@@ -8,7 +8,7 @@
 
 * Bugs fixed / wishes implemented (see http://bugs.kde.org)
-62321 80405 80559 85377 86083 86952 86958 87111 87537 87995
-88152 88245 88415 88954 89334 89553 89579 89582 89699 89903
-90102 
+62321       80405 80559 82342 85377 86083 86952 86958 87111
+87537 87995 88152 88245 88415 88954 89334 89553 89579 89582
+89699 89903 90102 
 
 

--- kdesdk/umbrello/umbrello/dialogs/umlattributedialog.cpp  #1.20:1.21
@@ -140,33 +140,6 @@ void UMLAttributeDialog::slotNameChanged
 
 bool UMLAttributeDialog::apply() {
-        UMLClassifier * pConcept = dynamic_cast<UMLClassifier *>( m_pAttribute->parent() );
-
-        if ( m_pPublicRB->isChecked() ) {
-                m_pAttribute->setScope(Uml::Public);
-        } else if ( m_pPrivateRB -> isChecked() ) {
-                m_pAttribute->setScope(Uml::Private);
-        } else {
-                m_pAttribute->setScope(Uml::Protected);
-        }
-
-        QString typeName = m_pTypeCB->currentText();
-        UMLDoc * pDoc = UMLApp::app()->getDocument();
-        UMLClassifierList namesList( pDoc->getConcepts() );
-        UMLClassifier* obj = NULL;
-        for (obj=namesList.first(); obj!=0; obj=namesList.next()) {
-                if (typeName == obj->getName()) {
-                        m_pAttribute->setType( obj );
-                        break;
-                }
-        }
-        if (obj == NULL) {
-                // Nothing found: set type name directly. Bad.
-                kdDebug() << "UMLAttributeDialog::apply: " << typeName << " not found."
-                          << endl;
-                m_pAttribute->setTypeName( typeName );
-        }
-        m_pAttribute->setInitialValue( m_pInitialLE->text() );
         QString name = m_pNameLE->text();
-        if( name.length() == 0 ) {
+        if (name.isEmpty()) {
                 KMessageBox::error(this, i18n("You have entered an invalid attribute name."),
                                    i18n("Attribute Name Invalid"), false);
@@ -174,7 +147,5 @@ bool UMLAttributeDialog::apply() {
                 return false;
         }
-
-        m_pAttribute->setStereotype( m_pStereoTypeLE->text() );
-
+        UMLClassifier * pConcept = dynamic_cast<UMLClassifier *>( m_pAttribute->parent() );
         UMLObjectList list= pConcept->findChildObject(Uml::ot_Attribute, name);
         if( list.count() != 0 && list.findRef( m_pAttribute ) ) {
@@ -185,10 +156,30 @@ bool UMLAttributeDialog::apply() {
         }
         m_pAttribute->setName(name);
+        if ( m_pPublicRB->isChecked() ) {
+                m_pAttribute->setScope(Uml::Public);
+        } else if ( m_pPrivateRB -> isChecked() ) {
+                m_pAttribute->setScope(Uml::Private);
+        } else {
+                m_pAttribute->setScope(Uml::Protected);
+        }
+        m_pAttribute->setInitialValue( m_pInitialLE->text() );
+        m_pAttribute->setStereotype( m_pStereoTypeLE->text() );
         m_pAttribute->setStatic( m_pStaticCB->isChecked() );
 
-        UMLDoc *umldoc = UMLApp::app()->getDocument();
-        if (umldoc->findUMLObject(typeName) == NULL)
-                umldoc->createDatatype( m_pTypeCB->currentText() );
-
+        QString typeName = m_pTypeCB->currentText();
+        UMLDoc * pDoc = UMLApp::app()->getDocument();
+        UMLObject *obj = pDoc->findUMLObject(typeName);
+        UMLClassifier *classifier = dynamic_cast<UMLClassifier*>(obj);
+        if (classifier == NULL) {
+                // If it's obviously a pointer type (C++) then create a datatype.
+                // Else we don't know what it is so as a compromise create a class.
+                Uml::Object_Type ot = (typeName.contains('*') ? Uml::ot_Datatype
+                                                              : Uml::ot_Class);
+                obj = pDoc->createUMLObject(ot, typeName);
+                if (obj == NULL)
+                        return false;
+                classifier = static_cast<UMLClassifier*>(obj);
+        }
+        m_pAttribute->setType( classifier );
         return true;
 }






More information about the umbrello-devel mailing list