[Uml-devel] [Bug 130172] Association role labels are duplicated

Oliver Kellogg okellogg at users.sourceforge.net
Thu Jun 7 18:21:26 UTC 2007


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=130172         




------- Additional Comments From okellogg users sourceforge net  2007-06-07 20:21 -------
SVN commit 672632 by okellogg:

findAssocWidget(UMLWidget*,UMLWidget*): Add a further arg, the role B name.
This fixes association label duplications when adding multiple attributes
of the same type at a classifier, when both that classifier and the
attribute type classifier are present on a class diagram.
CCBUG:130172


 M  +21 -23    umlview.cpp  
 M  +12 -3     umlview.h  


--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umlview.cpp #672631:672632
 @ -764,17 +764,24  @
     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 * UMLView::findAssocWidget(UMLWidget *pWidgetA,
+                                             UMLWidget *pWidgetB, const QString& roleNameB) {
+    AssociationWidget *assoc;
+    AssociationWidgetListIt it(m_AssociationList);
+    while ((assoc = it.current()) != 0) {
+        ++it;
+        const Association_Type testType = assoc->getAssocType();
+        if (testType != Uml::at_Association &&
+            testType != Uml::at_UniAssociation &&
+            testType != Uml::at_Composition &&
+            testType != Uml::at_Aggregation)
+            continue;
+        if (pWidgetA->getID() == assoc->getWidgetID(A) &&
+            pWidgetB->getID() == assoc->getWidgetID(B) &&
+            assoc->getRoleName(Uml::B) == roleNameB)
+            return assoc;
     }
-    AssociationWidget* retval = NULL;
-    for (uint i=0; i < assocTypes.size(); ++i) {
-        retval = findAssocWidget(assocTypes[i], pWidgetA, pWidgetB);
-        if (retval != NULL) return retval;
-    }
-    return retval;
+    return 0;
 }
 
 
 @ -790,15 +797,6  @
         if (pWidgetA->getID() == assoc->getWidgetID(A) &&
                 pWidgetB->getID() == assoc->getWidgetID(B))
             return assoc;
-        // Allow for the swapped roles of generalization/realization assocwidgets.
-        // When the swapped roles bug is fixed, this code can disappear.
-        if (pWidgetA->getID() == assoc->getWidgetID(B) &&
-                pWidgetB->getID() == assoc->getWidgetID(A)) {
-            kDebug() << "UMLView::findAssocWidget: found assoctype " << at
-                      << "with swapped roles (A: " << pWidgetA->getName()
-                      << ", B: " << pWidgetB->getName() << ")" << endl;
-            return assoc;
-        }
     }
     return 0;
 }
 @ -2147,7 +2145,7  @
     UMLAttributeList attrList = klass->getAttributeList();
     for (UMLAttributeListIt ait(attrList); ait.current(); ++ait) {
         UMLAttribute *attr = ait.current();
-        createAutoAttributeAssociation(attr->getType(), attr,widget);
+        createAutoAttributeAssociation(attr->getType(), attr, widget);
         /*
          * The following code from attachment 19935 of http://bugs.kde.org/140669
          * creates Aggregation/Composition to the template parameters.
 @ -2174,8 +2172,8  @
     AssociationWidget *aw = NULL;
     // if the attribute type has a widget representation on this view
     if (w) {
-        aw = findAssocWidget(widget, w) ;
-        if ( ( aw == NULL || aw->getRoleName(Uml::B) != attr->getName() ) &&
+        aw = findAssocWidget(widget, w, attr->getName());
+        if ( aw == NULL &&
                // if the current diagram type permits compositions
                AssocRules::allowAssociation(assocType, widget, w, false) ) {
             // Create a composition AssocWidget, or, if the attribute type is
 @ -2206,7 +2204,7  @
             UMLWidget *w = c ? findWidget( c->getID() ) : 0;
             // if the referenced type has a widget representation on this view
             if (w) {
-                aw = findAssocWidget(widget, w);
+                aw = findAssocWidget(widget, w, attr->getName());
                 if (aw == NULL &&
                     // if the current diagram type permits aggregations
                     AssocRules::allowAssociation(at_Aggregation, widget, w, false)) {
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umlview.h #672631:672632
 @ -399,10 +399,19  @
                                         UMLWidget *pWidgetA, UMLWidget *pWidgetB);
 
     /**
-     * calls findAssocWidget on three possible types:
-     * Uml::at_Aggregation << Uml::at_Composition << Uml::at_Containment
+     * Finds an association widget with the given widgets and the given role B name.
+     * Considers the following association types:
+     *  at_Association, at_UniAssociation, at_Composition, at_Aggregation
+     * This is used for seeking an attribute association.
+     *
+     *  param pWidgetA  Pointer to the UMLWidget of role A.
+     *  param pWidgetB  Pointer to the UMLWidget of role B.
+     *  param roleNameB Name at the B side of the association (the attribute name)
+     *
+     *  return Returns the widget found, returns 0 if no widget found.
      */
-    AssociationWidget * findAssocWidget(UMLWidget *pWidgetA, UMLWidget *pWidgetB);
+    AssociationWidget * findAssocWidget(UMLWidget *pWidgetA,
+                                        UMLWidget *pWidgetB, const QString& roleNameB);
 
     /**
      * Remove a widget from view.




More information about the umbrello-devel mailing list