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

Alan Ezust alan.ezust at gmail.com
Mon Dec 12 00:09:00 UTC 2005


SVN commit 487831 by alanezust:

Bug 109963 -
now it is possible to change properties of associations between 
aggregation and composition, even for auto-generated assocations.



 M  +36 -9     dialogs/assocgenpage.cpp  
 M  +12 -1     dialogs/assocgenpage.h  
 M  +28 -9     umlview.cpp  
 M  +7 -0      umlview.h  


--- branches/KDE/3.5/kdesdk/umbrello/umbrello/dialogs/assocgenpage.cpp #487830:487831
@@ -17,6 +17,7 @@
 
 // qt includes
 #include <qlayout.h>
+#include <qcombobox.h>
 
 // kde includes
 #include <klocale.h>
@@ -33,7 +34,7 @@
 
     m_pAssociationWidget = assoc;
     m_pWidget = 0;
-    m_pTypeLE = 0;
+    m_pTypeCB = 0;
     m_pAssocNameLE = 0;
     m_pUmldoc = d;
 
@@ -77,25 +78,51 @@
     m_pDoc = new QMultiLineEdit(docGB);
     docLayout -> addWidget(m_pDoc);
     m_pDoc-> setText(m_pAssociationWidget-> getDoc());
+    Uml::Association_Type currentType =  m_pAssociationWidget->getAssocType();
+    QString currentTypeAsString = UMLAssociation::typeAsString(currentType);
+    QLabel *pTypeL = new QLabel(i18n("Type:"), nameGB);
+    nameLayout->addWidget(pTypeL, 1, 0);
 
-    // Association Type
-    QLabel *pTypeL = NULL;
-    Dialog_Utils::makeLabeledEditField( nameGB, nameLayout, 1,
-                                    pTypeL, i18n("Type:"),
-                                    m_pTypeLE,
-                                    UMLAssociation::typeAsString(m_pAssociationWidget->getAssocType()) );
-    m_pTypeLE->setEnabled(false);
+    /* Here is a list of all the supported choices for changing
+       association types */
+    m_AssocTypes.clear();
+    m_AssocTypes <<  Uml::at_Aggregation
+        << Uml::at_Composition << Uml::at_Containment;
 
+    bool found=false;
+    m_AssocTypeStrings.clear();
+    for (int i=0; i<m_AssocTypes.size(); ++i) {
+        if (m_AssocTypes[i] == currentType) found=true;
+        QString typeStr = UMLAssociation::typeAsString(m_AssocTypes[i]);
+        m_AssocTypeStrings << typeStr;
+    }
+    
+    if (!found) {
+        m_AssocTypes.clear();
+        m_AssocTypes << currentType;
+        m_AssocTypeStrings.clear();
+        m_AssocTypeStrings << currentTypeAsString;
+    }
+    
+    m_pTypeCB = new QComboBox(nameGB);
+    pTypeL->setBuddy(m_pTypeCB);
+    m_pTypeCB->insertStringList(m_AssocTypeStrings);
+    m_pTypeCB->setCurrentText(currentTypeAsString);
     m_pDoc->setWordWrap(QMultiLineEdit::WidgetWidth);
+    nameLayout->addWidget(m_pTypeCB, 1, 1);
+    
 
 }
 
 
 void AssocGenPage::updateObject() {
 
+
     if(m_pAssociationWidget) {
         QString name = m_pAssocNameLE -> text();
-
+        int comboBoxItem = m_pTypeCB->currentItem();
+        Uml::Association_Type newType = m_AssocTypes[comboBoxItem];
+        m_pAssociationWidget->setAssocType(newType);
         m_pAssociationWidget->setName(m_pAssocNameLE->text());
         m_pAssociationWidget->setDoc(m_pDoc->text());
 
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/dialogs/assocgenpage.h #487830:487831
@@ -24,6 +24,7 @@
 #include <qmultilineedit.h>
 #include <qradiobutton.h>
 #include <qcheckbox.h>
+#include <qvaluelist.h>
 
 //my class includes
 #include "../umlobject.h"
@@ -31,6 +32,9 @@
 #include "../umldoc.h"
 #include "../associationwidget.h"
 
+class QComboBox;
+
+
 /**
  * Displays properties of a UMLObject in a dialog box.  This is not usually directly
  * called.  The class @ref AssocPropDlg will set this up for you.
@@ -64,7 +68,14 @@
     void updateObject();
 
 private:
-    QLineEdit * m_pAssocNameLE, *m_pTypeLE;
+    QLineEdit * m_pAssocNameLE;
+    QComboBox *m_pTypeCB;
+
+    /* Choices for the QComboBox, and we store ints and strings
+       so we can translate both ways */
+    QValueList<Uml::Association_Type> m_AssocTypes;
+    QStringList m_AssocTypeStrings;
+        
     QMultiLineEdit * m_pDoc;
 
     AssociationWidget *m_pAssociationWidget;
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umlview.cpp #487830:487831
@@ -801,6 +801,8 @@
     return 0;
 }
 
+
+
 AssociationWidget * UMLView::findAssocWidget( Uml::IDType id ) {
     AssociationWidget *obj;
     AssociationWidgetListIt it( m_AssociationList );
@@ -814,6 +816,21 @@
     return 0;
 }
 
+AssociationWidget * UMLView::findAssocWidget(UMLWidget *pWidgetA, UMLWidget *pWidgetB) {
+    static QValueList<Association_Type> assocTypes;
+    if (assocTypes.isEmpty()) {
+        assocTypes << Uml::at_Aggregation
+        << Uml::at_Composition << Uml::at_Containment;
+    }
+    AssociationWidget* retval = NULL;
+    for (int i=0; i<assocTypes.size(); ++i) {
+        retval = findAssocWidget(assocTypes[i], pWidgetA, pWidgetB);
+        if (retval != NULL) return retval;
+    }
+    return retval;
+}
+
+
 AssociationWidget * UMLView::findAssocWidget(Association_Type at,
         UMLWidget *pWidgetA, UMLWidget *pWidgetB) {
     AssociationWidget *assoc;
@@ -2586,12 +2603,11 @@
         UMLWidget *w = findWidget( attrType->getID() );
         AssociationWidget *aw = NULL;
         // if the attribute type has a widget representation on this view
-        if (w &&
-                // if the AssocWidget does not already exist then
-                ((aw = findAssocWidget(assocType, widget, w)) == NULL ||
-                 aw->getRoleName(Uml::B) != attr->getName()) &&
-                // if the current diagram type permits compositions
-                AssocRules::allowAssociation(assocType, widget, w, false)) {
+        if (w) {
+           aw = findAssocWidget(widget, w) ;
+           if ( ( aw == NULL || aw->getRoleName(Uml::B) != attr->getName() ) &&
+              // if the current diagram type permits compositions
+                AssocRules::allowAssociation(assocType, widget, w, false) ) {
             // Create a composition AssocWidget, or, if the attribute type is
             // stereotyped <<CORBAInterface>>, create a UniAssociation widget.
             if (attrType->getStereotype() == "CORBAInterface")
@@ -2608,18 +2624,20 @@
             a->setActivated(true);
             if (! addAssociation(a))
                 delete a;
+           }
         }
         // if the attribute type is a UMLDatatype then
         if (attrType->getBaseType() == ot_Datatype) {
             UMLDatatype *dt = static_cast<UMLDatatype*>(attrType);
             // if the UMLDatatype is a reference (pointer) type
             if (dt->isReference()) {
+                Uml::Association_Type assocType = Uml::at_Composition;
                 UMLClassifier *c = dt->originType();
                 UMLWidget *w = c ? findWidget( c->getID() ) : 0;
                 // if the referenced type has a widget representation on this view
-                if (w &&
-                        // if the AssocWidget does not already exist then
-                        findAssocWidget(at_Aggregation, widget, w) == NULL &&
+                if (w) {
+                   aw = findAssocWidget(widget, w);
+                   if (aw == NULL &&
                         // if the current diagram type permits aggregations
                         AssocRules::allowAssociation(at_Aggregation, widget, w, false)) {
                     // create an aggregation AssocWidget from the ClassifierWidget
@@ -2635,6 +2653,7 @@
                     a->setActivated(true);
                     if (! addAssociation(a))
                         delete a;
+                   }
                 }
             }
         }
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umlview.h #487830:487831
@@ -403,7 +403,14 @@
      */
     AssociationWidget * findAssocWidget(Uml::Association_Type at,
                                         UMLWidget *pWidgetA, UMLWidget *pWidgetB);
+
+
     /**
+        calls findAssocWidget on three possible types:
+        Uml::at_Aggregation << Uml::at_Composition << Uml::at_Containment
+        */
+    AssociationWidget * findAssocWidget(UMLWidget *pWidgetA, UMLWidget *pWidgetB);
+    /**
      * Remove a widget from view.
      *
      * @param o  The widget to remove.




More information about the umbrello-devel mailing list