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

Gopala Krishna A krishna.ggk at gmail.com
Wed Jul 8 13:06:25 UTC 2009


SVN commit 993310 by gopala:

* Ported few more methods of AssociationWidget to New::AssociationWidget.
* Documented methods in widget_utils.cpp



 M  +5 -0      association.h  
 M  +136 -4    widgets/newassociationwidget.cpp  
 M  +6 -0      widgets/newassociationwidget.h  
 M  +9 -0      widgets/widget_utils.cpp  


--- branches/work/soc-umbrello/umbrello/association.h #993309:993310
@@ -17,6 +17,10 @@
 #include "umlobject.h"
 
 class UMLRole;
+namespace New
+{
+    class AssociationWidget;
+} // namespace New
 
 /**
  * This class contains the non-graphic representation of an association.
@@ -32,6 +36,7 @@
 {
     Q_OBJECT
     friend class AssociationWidget;
+    friend class New::AssociationWidget;
 public:
 
     UMLAssociation(Uml::Association_Type type, UMLObject *roleA, UMLObject *roleB);
--- branches/work/soc-umbrello/umbrello/widgets/newassociationwidget.cpp #993309:993310
@@ -16,6 +16,7 @@
 #include "associationspacemanager.h"
 #include "attribute.h"
 #include "classifier.h"
+#include "entity.h"
 #include "floatingtextwidget.h"
 #include "newlinepath.h"
 #include "objectwidget.h"
@@ -50,7 +51,9 @@
         m_associationLine = new New::AssociationLine(this);
         m_nameWidget = 0;
 
-        if (!umlObj && UMLAssociation::assocTypeHasUMLRepresentation(type)) {
+        if (umlObj) {
+            setUMLObject(umlObj);
+        } else if (UMLAssociation::assocTypeHasUMLRepresentation(type)) {
             UMLObject *objectA = widgetA->umlObject();
             UMLObject *objectB = widgetB->umlObject();
 
@@ -268,8 +271,9 @@
 
     UMLAssociation* AssociationWidget::association() const
     {
-        if (!umlObject()) return 0;
-        Q_ASSERT(umlObject()->getBaseType() == Uml::ot_Association);
+        if (!umlObject() || umlObject()->getBaseType() != Uml::ot_Association) {
+            return 0;
+        }
         return static_cast<UMLAssociation*>(umlObject());
     }
 
@@ -501,9 +505,10 @@
     void AssociationWidget::setAssociationType(Uml::Association_Type type)
     {
         m_associationType = type;
-        if (umlObject()) {
+        if (umlObject() && umlObject()->getBaseType() == Uml::ot_Association) {
             static_cast<UMLAssociation*>(umlObject())->setAssocType(type);
         }
+
     }
 
     bool AssociationWidget::isCollaboration() const
@@ -522,6 +527,32 @@
         return m_associationLine->shape();
     }
 
+    /**
+     * Reimplemented to handle updation of underlying UMLObject
+     * @note syncToModel() is deprecated as I see no point in setting the object's variable
+     * value to itself. Probably the intention was to emit the various changed signals indirectly,
+     * which infact can be done directly.
+     */
+    void AssociationWidget::slotUMLObjectDataChanged()
+    {
+        UMLObject *obj = umlObject();
+        if (!obj) {
+            WidgetBase::slotUMLObjectDataChanged();
+            return;
+        }
+        const Uml::Object_Type ot = obj->getBaseType();
+        if (ot == Uml::ot_Operation) {
+            if (m_nameWidget) {
+                m_nameWidget->setMessageText();
+            }
+        } else if (ot == Uml::ot_Attribute) {
+            UMLAttribute *attr = static_cast<UMLAttribute*>(obj);
+            setVisibility(attr->getVisibility(), Uml::B);
+            setRoleName(attr->getName(), Uml::B);
+        }
+        WidgetBase::slotUMLObjectDataChanged();
+    }
+
     void AssociationWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem* opt, QWidget *)
     {
         m_associationLine->paint(painter, opt);
@@ -586,6 +617,107 @@
         m_associationLine->hoverLeaveEvent(event);
     }
 
+    /**
+     * Reimplemented to do more checks and changes while setting a new UMLObject.
+     * The old UMLObject's connectivity is removed in @ref umlObjectChanged method, which is
+     * invoked by WidgetBase::setUMLObject.
+     */
+    void AssociationWidget::setUMLObject(UMLObject *obj)
+    {
+        if (obj == umlObject()) {
+            return;
+        }
+        if (!obj) {
+            WidgetBase::setUMLObject(0);
+            return;
+        }
+
+        const Uml::Object_Type ot = obj->getBaseType();
+        if (ot == Uml::ot_Association) {
+
+            UMLAssociation *assoc = static_cast<UMLAssociation*>(obj);
+            if (assoc->nrof_parent_widgets < 0) {
+                assoc->nrof_parent_widgets = 0;
+            }
+            assoc->nrof_parent_widgets++;
+
+        } else if (ot == Uml::ot_Operation) {
+
+            // Nothing special to do.
+
+        } else if (ot == Uml::ot_Attribute) {
+
+            UMLClassifier *klass = static_cast<UMLClassifier*>(obj->parent());
+            connect(klass, SIGNAL(attributeRemoved(UMLClassifierListItem*)),
+                    this, SLOT(slotClassifierListItemRemoved(UMLClassifierListItem*)));
+            // attributeChanged is emitted along with modified signal. So its not
+            // necessary to handle attributeChanged signal.
+
+        } else if (ot == Uml::ot_EntityAttribute) {
+
+            UMLEntity *ent = static_cast<UMLEntity*>(obj->parent());
+            connect(ent, SIGNAL(entityAttributeRemoved(UMLClassifierListItem*)),
+                    this, SLOT(slotClassifierListItemRemoved(UMLClassifierListItem*)));
+
+        } else if (ot == Uml::ot_ForeignKeyConstraint) {
+
+            UMLEntity *ent = static_cast<UMLEntity*>(obj->parent());
+            connect(ent, SIGNAL(entityAttributeRemoved(UMLClassifierListItem*)),
+                    this, SLOT(slotClassifierListItemRemoved(UMLClassifierListItem*)));
+
+        } else {
+
+            uError() << "UMLAssociation constructor: cannot associate UMLObject of type " << ot;
+
+        }
+
+        WidgetBase::setUMLObject(obj);
+    }
+
+    /**
+     * Reimplemented to cleanup connectivity with the old UMLObject.
+     */ 
+    void AssociationWidget::umlObjectChanged(UMLObject *old)
+    {
+        if (!old) {
+            return;
+        }
+
+        const Uml::Object_Type ot = old->getBaseType();
+        if (ot == Uml::ot_Association) {
+
+            UMLAssociation *oldAssoc = static_cast<UMLAssociation*>(old);
+            oldAssoc->nrof_parent_widgets--;
+            // TODO: Discussion on ownership of UMLAssociation
+            if (oldAssoc->nrof_parent_widgets == 0) {
+                // TODO: Delete oldAssoc or not ? Depends on cut/copy implementation
+            }
+
+        } else if (ot == Uml::ot_Attribute) {
+
+            UMLClassifier *klass = static_cast<UMLClassifier*>(old->parent());
+            disconnect(klass, SIGNAL(attributeRemoved(UMLClassifierListItem*)),
+                    this, SLOT(slotClassifierListItemRemoved(UMLClassifierListItem*)));
+
+        } else if (ot == Uml::ot_EntityAttribute) {
+
+            UMLEntity *ent = static_cast<UMLEntity*>(old->parent());
+            disconnect(ent, SIGNAL(entityAttributeRemoved(UMLClassifierListItem*)),
+                    this, SLOT(slotClassifierListItemRemoved(UMLClassifierListItem*)));
+
+        } else if (ot == Uml::ot_ForeignKeyConstraint) {
+
+            UMLEntity *ent = static_cast<UMLEntity*>(old->parent());
+            disconnect(ent, SIGNAL(entityConstraintRemoved(UMLClassifierListItem*)),
+                    this, SLOT(slotClassifierListItemRemoved(UMLClassifierListItem*)));
+
+        } else {
+            uError() << "Had a wrong association of type " << ot;
+        }
+
+        WidgetBase::umlObjectChanged(old);
+    }
+
     void AssociationWidget::setFloatingText(Uml::Text_Role tr, const QString& text, FloatingTextWidget* &ft)
     {
         if (! FloatingTextWidget::isTextValid(text)) {
--- branches/work/soc-umbrello/umbrello/widgets/newassociationwidget.h #993309:993310
@@ -114,6 +114,9 @@
         virtual QPainterPath shape() const;
         virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem* opt, QWidget*);
 
+    protected Q_SLOTS:
+        virtual void slotUMLObjectDataChanged();
+
     protected:
         virtual void updateGeometry();
         virtual QVariant itemChange(GraphicsItemChange change, const QVariant& value);
@@ -128,6 +131,9 @@
         virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
         virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
 
+        virtual void setUMLObject(UMLObject *obj);
+        virtual void umlObjectChanged(UMLObject *old);
+
     private:
         void setFloatingText(Uml::Text_Role tr, const QString& text,
                 FloatingTextWidget* &ft);
--- branches/work/soc-umbrello/umbrello/widgets/widget_utils.cpp #993309:993310
@@ -179,6 +179,15 @@
         }
     }
 
+    /**
+     * Draws a rounded rect rounded at specified corners.
+     *
+     * @param painter The painter with which this round rect should be drawn.
+     * @param rect    The rectangle to be drawn.
+     * @param xRadius The x radius of rounded corner.
+     * @param yRadius The y radius of rounded corner.
+     * @param corners The corners to be rounded.
+     */
     void drawRoundedRect(QPainter *painter, const QRectF& rect, qreal xRadius,
             qreal yRadius, Uml::Corners corners)
     {




More information about the umbrello-devel mailing list