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

Oliver Kellogg okellogg at users.sourceforge.net
Mon Dec 12 12:18:01 UTC 2005


SVN commit 487991 by okellogg:

apply commit 487831 from branches/KDE/3.5

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


--- trunk/KDE/kdesdk/umbrello/umbrello/dialogs/assocgenpage.cpp #487990:487991
@@ -17,6 +17,7 @@
 
 // qt includes
 #include <qlayout.h>
+#include <qcombobox.h>
 //Added by qt3to4:
 #include <QLabel>
 #include <QVBoxLayout>
@@ -38,7 +39,7 @@
 
     m_pAssociationWidget = assoc;
     m_pWidget = 0;
-    m_pTypeLE = 0;
+    m_pTypeCB = 0;
     m_pAssocNameLE = 0;
     m_pUmldoc = d;
 
@@ -82,17 +83,41 @@
     m_pDoc = new Q3MultiLineEdit(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(Q3MultiLineEdit::WidgetWidth);
+    nameLayout->addWidget(m_pTypeCB, 1, 1);
 
+    m_pDoc->setWordWrap(Q3MultiLineEdit::WidgetWidth);
+
 }
 
 
@@ -100,7 +125,9 @@
 
     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());
 
--- trunk/KDE/kdesdk/umbrello/umbrello/dialogs/assocgenpage.h #487990:487991
@@ -24,6 +24,7 @@
 #include <q3multilineedit.h>
 #include <qradiobutton.h>
 #include <qcheckbox.h>
+#include <q3valuelist.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,13 @@
     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 */
+    Q3ValueList<Uml::Association_Type> m_AssocTypes;
+    QStringList m_AssocTypeStrings;
     Q3MultiLineEdit * m_pDoc;
 
     AssociationWidget *m_pAssociationWidget;
--- trunk/KDE/kdesdk/umbrello/umbrello/umlview.cpp #487990:487991
@@ -809,6 +809,8 @@
     return 0;
 }
 
+
+
 AssociationWidget * UMLView::findAssocWidget( Uml::IDType id ) {
     AssociationWidget *obj;
     AssociationWidgetListIt it( m_AssociationList );
@@ -822,6 +824,21 @@
     return 0;
 }
 
+AssociationWidget * UMLView::findAssocWidget(UMLWidget *pWidgetA, UMLWidget *pWidgetB) {
+    static Q3ValueList<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;
@@ -2592,12 +2609,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")
@@ -2614,18 +2630,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
@@ -2641,6 +2659,7 @@
                     a->setActivated(true);
                     if (! addAssociation(a))
                         delete a;
+                   }
                 }
             }
         }
--- trunk/KDE/kdesdk/umbrello/umbrello/umlview.h #487990:487991
@@ -412,7 +412,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