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

Gopala Krishna A krishna.ggk at gmail.com
Fri Jun 19 22:58:44 UTC 2009


SVN commit 984097 by gopala:

* Created OpenArrow, ClosedArrow and CrowFeet symbols for AssociationLine.
* AssociationLine::setupSymbols() was implemented to set appropriate symbol
  based on associaton type. This means, symbols for AssociationLine is now
  set on creation.


 M  +80 -6     newlinepath.cpp  
 M  +4 -1      newlinepath.h  
 M  +11 -3     widgets/newassociationwidget.cpp  
 M  +2 -0      widgets/newassociationwidget.h  


--- branches/work/soc-umbrello/umbrello/newlinepath.cpp #984096:984097
@@ -33,6 +33,14 @@
             PointPair(QPointF(0, 10), QPointF(0, 10))
         },
         {
+            QRectF(-6, 0, 12, 10), QPainterPath(), QLineF(0, 0, 0, 10),
+            PointPair(QPointF(0, 0), QPointF(0, 10))
+        },
+        {
+            QRectF(-6, 0, 12, 10), QPainterPath(), QLineF(0, 0, 0, 10),
+            PointPair(QPointF(0, 10), QPointF(0, 10))
+        },
+        {
             QRectF(-5, -10, 10, 20), QPainterPath(), QLineF(0, -10, 0, 10),
             PointPair(QPointF(0, -10), QPointF(0, 10))
         },
@@ -50,15 +58,44 @@
     /// @internal A convenience method to setup shapes of all symbols.
     void Symbol::setupSymbolTable()
     {
-        SymbolProperty &arrow = symbolTable[Arrow];
-        if (arrow.shape.isEmpty()) {
-            QRectF rect = arrow.boundRect;
+        SymbolProperty &openArrow = symbolTable[OpenArrow];
+        if (openArrow.shape.isEmpty()) {
+            QRectF rect = openArrow.boundRect;
             // Defines a 'V' shape arrow fitting in the bound rect.
-            arrow.shape.moveTo(rect.topLeft());
-            arrow.shape.lineTo(rect.center().x(), rect.bottom());
-            arrow.shape.lineTo(rect.topRight());
+            openArrow.shape.moveTo(rect.topLeft());
+            openArrow.shape.lineTo(rect.center().x(), rect.bottom());
+            openArrow.shape.lineTo(rect.topRight());
         }
 
+        SymbolProperty &closedArrow = symbolTable[ClosedArrow];
+        if (closedArrow.shape.isEmpty()) {
+            QRectF rect = closedArrow.boundRect;
+            // Defines a 'V' shape arrow fitting in the bound rect.
+            closedArrow.shape.moveTo(rect.topLeft());
+            closedArrow.shape.lineTo(rect.center().x(), rect.bottom());
+            closedArrow.shape.lineTo(rect.topRight());
+            closedArrow.shape.lineTo(rect.topLeft());
+        }
+
+        SymbolProperty &crowFeet = symbolTable[CrowFeet];
+        if (crowFeet.shape.isEmpty()) {
+            QRectF rect = crowFeet.boundRect;
+            // Defines a crowFeet fitting in the bound rect.
+            QPointF topMid(rect.center().x(), rect.top());
+
+            // left leg
+            crowFeet.shape.moveTo(rect.bottomLeft());
+            crowFeet.shape.lineTo(topMid);
+
+            // middle leg
+            crowFeet.shape.moveTo(rect.center().x(), rect.bottom());
+            crowFeet.shape.lineTo(topMid);
+
+            // left leg
+            crowFeet.shape.moveTo(rect.bottomRight());
+            crowFeet.shape.lineTo(topMid);
+        }
+
         SymbolProperty &diamond = symbolTable[Diamond];
         if (diamond.shape.isEmpty()) {
             QRectF rect = diamond.boundRect;
@@ -1019,5 +1056,42 @@
         calculateEndPoints();
     }
 
+    /**
+     * This method creates appropriate symbols based on type of
+     * m_associationWidget.
+     */
+    void AssociationLine::setupSymbols()
+    {
+        switch( m_associationWidget->associationType() ) {
+            case Uml::at_State:
+            case Uml::at_Activity:
+            case Uml::at_Exception:
+            case Uml::at_UniAssociation:
+            case Uml::at_Dependency:
+                setEndSymbol(Symbol::OpenArrow);
+                break;
+
+            case Uml::at_Relationship:
+                setEndSymbol(Symbol::CrowFeet);
+                break;
+
+            case Uml::at_Generalization:
+            case Uml::at_Realization:
+                setEndSymbol(Symbol::ClosedArrow);
+                break;
+
+            case Uml::at_Composition:
+            case Uml::at_Aggregation:
+                setStartSymbol(Symbol::Diamond);
+                break;
+
+            case Uml::at_Containment:
+                setStartSymbol(Symbol::Circle);
+                break;
+            default:
+                break;
+        }
+    }
+
 }
 
--- branches/work/soc-umbrello/umbrello/newlinepath.h #984096:984097
@@ -45,7 +45,9 @@
          */
         enum SymbolType {
             None = -1,
-            Arrow,
+            OpenArrow,
+            ClosedArrow,
+            CrowFeet,
             Diamond,
             Subset,
             Circle,
@@ -171,6 +173,7 @@
         void calculateEndPoints();
         void calculateInitialEndPoints();
 
+        void setupSymbols();
 
     private:
         /// These points represents the association line.
--- branches/work/soc-umbrello/umbrello/widgets/newassociationwidget.cpp #984096:984097
@@ -45,7 +45,8 @@
 
     AssociationWidget::AssociationWidget(UMLWidget *widgetA, Uml::Association_Type type,
                                          UMLWidget *widgetB, UMLObject *umlObj) :
-        WidgetBase(umlObj)
+        WidgetBase(umlObj),
+        m_associationType(type)
     {
         m_associationLine = new New::AssociationLine(this);
         m_nameWidget = 0;
@@ -76,6 +77,7 @@
         }
         // TODO: Probably move this calculation to slotInit.
         m_associationLine->calculateInitialEndPoints();
+        m_associationLine->setupSymbols();
 
         Q_ASSERT(widgetA->umlScene() == widgetB->umlScene());
 
@@ -491,12 +493,18 @@
 
     Uml::Association_Type AssociationWidget::associationType() const
     {
-        return static_cast<UMLAssociation*>(umlObject())->getAssocType();
+        if (umlObject()) {
+            return static_cast<UMLAssociation*>(umlObject())->getAssocType();
+        }
+        return m_associationType;
     }
 
     void AssociationWidget::setAssociationType(Uml::Association_Type type)
     {
-        static_cast<UMLAssociation*>(umlObject())->setAssocType(type);
+        m_associationType = type;
+        if (umlObject()) {
+            static_cast<UMLAssociation*>(umlObject())->setAssocType(type);
+        }
     }
 
     bool AssociationWidget::isCollaboration() const
--- branches/work/soc-umbrello/umbrello/widgets/newassociationwidget.h #984096:984097
@@ -151,6 +151,8 @@
         New::AssociationLine *m_associationLine;
         WidgetRole m_widgetRole[2];
         FloatingTextWidget *m_nameWidget;
+
+        Uml::Association_Type m_associationType;
     };
 }
 




More information about the umbrello-devel mailing list