[Uml-devel] branches/work/soc-umbrello/umbrello/widgets

Gopala Krishna A krishna.ggk at gmail.com
Fri Apr 3 06:34:00 UTC 2009


SVN commit 948466 by gopala:

Started porting of AssociationWidget again. Implemented isEqual method in lines
with operator= for NewAssociationWidget.



 M  +59 -0     newassociationwidget.cpp  
 M  +22 -0     newassociationwidget.h  


--- branches/work/soc-umbrello/umbrello/widgets/newassociationwidget.cpp #948465:948466
@@ -14,6 +14,7 @@
 #include "association.h"
 #include "floatingtextwidget.h"
 #include "newlinepath.h"
+#include "objectwidget.h"
 #include "umlscene.h"
 #include "umlwidget.h"
 
@@ -23,6 +24,9 @@
     {
         multiplicityWidget = changeabilityWidget = roleWidget = 0;
         umlWidget = 0;
+        region = New::Left;
+        visibility = Uml::Visibility::Public;
+        changeability = Uml::chg_Changeable;
     }
 
     WidgetRole::~WidgetRole()
@@ -70,6 +74,61 @@
         delete m_associationLine;
     }
 
+    UMLAssociation* AssociationWidget::association() const
+    {
+        if (!umlObject()) return 0;
+        Q_ASSERT(umlObject()->getBaseType() == Uml::ot_Association);
+        return static_cast<UMLAssociation*>(umlObject());
+    }
+
+    bool AssociationWidget::isEqual(New::AssociationWidget *other) const
+    {
+        if( this == other )
+            return true;
+
+        // if no model representation exists, then the widgets are not equal
+        if ( !association() || !other->association() )
+            return false;
+        else if (association() != other->association()) {
+            return false;
+        }
+
+        if (associationType() != other->associationType())
+            return false;
+
+        UMLWidget *aWid = widgetForRole(Uml::A);
+        UMLWidget *bWid = widgetForRole(Uml::B);
+
+        UMLWidget *oaWid = other->widgetForRole(Uml::A);
+        UMLWidget *obWid = other->widgetForRole(Uml::B);
+
+        if (aWid->id() != oaWid->id() || bWid->id() != obWid->id())
+            return false;
+
+        if (aWid->baseType() == Uml::wt_Object && oaWid->baseType() == Uml::wt_Object) {
+            ObjectWidget *a = static_cast<ObjectWidget*>(aWid);
+            ObjectWidget *oa = static_cast<ObjectWidget*>(oaWid);
+            if (a->localID() != oa->localID()) {
+                return false;
+            }
+        }
+
+        if (bWid->baseType() == Uml::wt_Object && obWid->baseType() == Uml::wt_Object) {
+            ObjectWidget *b = static_cast<ObjectWidget*>(bWid);
+            ObjectWidget *ob = static_cast<ObjectWidget*>(obWid);
+            if (b->localID() != ob->localID()) {
+                return false;
+            }
+        }
+
+        // Two objects in a collaboration can have multiple messages between each other.
+        // Here we depend on the messages having names, and the names must be different.
+        // That is the reason why collaboration messages have strange initial names like
+        // "m29997" or similar.
+        return (name() == other->name());
+
+    }
+
     UMLWidget* AssociationWidget::widgetForRole(Uml::Role_Type role) const
     {
         return m_widgetRole[role].umlWidget;
--- branches/work/soc-umbrello/umbrello/widgets/newassociationwidget.h #948465:948466
@@ -15,12 +15,24 @@
 #include "widgetbase.h"
 
 class FloatingTextWidget;
+class UMLAssociation;
 class UMLWidget;
 
 namespace New
 {
     class AssociationLine;
 
+    enum Region {
+        Left,
+        TopLeft,
+        Top,
+        TopRight,
+        Right,
+        BottomRight,
+        Bottom,
+        BottomLeft
+    };
+
     struct WidgetRole
     {
         FloatingTextWidget *multiplicityWidget;
@@ -29,6 +41,13 @@
 
         UMLWidget *umlWidget;
 
+        New::Region region;
+
+        // The following are used only in case of absence of UMLObject
+        Uml::Visibility visibility;
+        Uml::Changeability_Type changeability;
+        QString roleDocumentation;
+
         WidgetRole();
         ~WidgetRole();
     };
@@ -41,6 +60,9 @@
                           UMLWidget *widgetB, UMLObject *obj = 0);
         virtual ~AssociationWidget();
 
+        UMLAssociation* association() const;
+        bool isEqual(New::AssociationWidget *other) const;
+
         QString multiplicity(Uml::Role_Type role) const;
         void setMultiplicity(const QString& text, Uml::Role_Type role);
 




More information about the umbrello-devel mailing list