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

Sharan Rao sharanrao at gmail.com
Tue Jun 19 04:01:56 UTC 2007


SVN commit 677387 by sharan:

*automatically create an association widget on adding a foreign key constraint
*xmi representation for Unique constraints

still todo
*xmi representation for foreign key constraints ( any suggestins ? , simple representaions lead to lots of forward 
reference problems)
*listpopup menu entries




 M  +10 -4     associationwidget.cpp  
 M  +6 -4      associationwidget.h  
 M  +19 -0     entity.cpp  
 M  +1 -1      foreignkeyconstraint.cpp  
 M  +3 -0      umllistview.cpp  
 M  +2 -1      umlobject.cpp  
 M  +97 -5     umlview.cpp  
 M  +9 -0      umlview.h  
 M  +8 -2      umlwidget.cpp  
 M  +49 -4     uniqueconstraint.cpp  


--- trunk/KDE/kdesdk/umbrello/umbrello/associationwidget.cpp #677386:677387
@@ -3214,17 +3214,21 @@
     if (ot == Uml::ot_Attribute) {
         UMLClassifier *klass = static_cast<UMLClassifier*>(obj->parent());
         connect(klass, SIGNAL(attributeRemoved(UMLClassifierListItem*)),
-                this, SLOT(slotAttributeRemoved(UMLClassifierListItem*)));
+                this, SLOT(slotClassifierListItemRemoved(UMLClassifierListItem*)));
     } else if (ot == Uml::ot_EntityAttribute) {
         UMLEntity *ent = static_cast<UMLEntity*>(obj->parent());
         connect(ent, SIGNAL(entityAttributeRemoved(UMLClassifierListItem*)),
-                this, SLOT(slotAttributeRemoved(UMLClassifierListItem*)));
+                this, SLOT(slotClassifierListItemRemoved(UMLClassifierListItem*)));
+    } else if (ot == Uml::ot_ForeignKeyConstraint) {
+        UMLEntity* ent = static_cast<UMLEntity*>(obj->parent());
+        connect(ent, SIGNAL(entityConstraintRemoved(UMLClassifierListItem*)),
+                this, SLOT(slotClassifierListItemRemoved(UMLClassifierListItem*)));
     }
 }
 
-void AssociationWidget::slotAttributeRemoved(UMLClassifierListItem* obj) {
+void AssociationWidget::slotClassifierListItemRemoved(UMLClassifierListItem* obj) {
     if (obj != m_pObject)
-        kDebug() << "AssociationWidget::slotAttributeRemoved:(obj=" << obj
+        kDebug() << "AssociationWidget::slotClassifierListItemRemoved:(obj=" << obj
                   << "): m_pObject=" << m_pObject << endl;
     m_pObject = NULL;
     m_pView->removeAssoc(this);
@@ -3684,4 +3688,6 @@
     return loadFromXMI( qElement, m_pView->getWidgetList(), &messages );
 }
 
+
+
 #include "associationwidget.moc"
--- trunk/KDE/kdesdk/umbrello/umbrello/associationwidget.h #677386:677387
@@ -1030,13 +1030,15 @@
     void slotClearAllSelected();
 
     /**
-     * Connected to UMLClassifier::attributeRemoved() in case this
-     * AssociationWidget is linked to a classifer's attribute type.
+     * Connected to UMLClassifier::attributeRemoved() or UMLEntity::constraintRemoved()
+     * in case this AssociationWidget is linked to a clasifier list item
+     * ( an attribute or a foreign key constraint )
      *
-     * @param obj               The UMLAttribute removed.
+     * @param obj               The UMLClassifierListItem removed.
      */
-    void slotAttributeRemoved(UMLClassifierListItem* obj);
+    void slotClassifierListItemRemoved(UMLClassifierListItem* obj);
 
+
     /**
      * Synchronize this widget from the UMLAssociation.
      */
--- trunk/KDE/kdesdk/umbrello/umbrello/entity.cpp #677386:677387
@@ -286,6 +286,12 @@
          (pEntityAttribute = it.current()) != NULL; ++it) {
         pEntityAttribute->saveToXMI(qDoc, entityElement);
     }
+
+    UMLClassifierListItemList entityConstraints = getFilteredList(Uml::ot_EntityConstraint);
+    foreach(UMLClassifierListItem* cli, entityConstraints) {
+        cli->saveToXMI(qDoc,entityElement);
+    }
+
     qElement.appendChild(entityElement);
 }
 
@@ -304,6 +310,19 @@
                 return false;
             }
             m_List.append(pEntityAttribute);
+        } else if ( Uml::tagEq( tag, "UniqueConstraint" ) ) {
+            UMLUniqueConstraint* pUniqueConstraint = new UMLUniqueConstraint(this);
+            if ( !pUniqueConstraint->loadFromXMI(tempElement) ) {
+                return false;
+            }
+            addConstraint( pUniqueConstraint );
+        } else if ( Uml::tagEq( tag,"ForeignKeyConstraint" ) ) {
+            UMLForeignKeyConstraint* pForeignKeyConstraint = new UMLForeignKeyConstraint(this);
+            if ( !pForeignKeyConstraint->loadFromXMI(tempElement) ) {
+                return false;
+            }
+
+            addConstraint( pForeignKeyConstraint );
         } else if (tag == "stereotype") {
             kDebug() << "UMLEntity::load(" << m_Name
             << "): losing old-format stereotype." << endl;
--- trunk/KDE/kdesdk/umbrello/umbrello/foreignkeyconstraint.cpp #677386:677387
@@ -90,7 +90,7 @@
             if ( first ) {
                 first = false;
             } else
-                s += ' , ';
+                s += ',';
             s += key->getName();
         }
         s += ')';
--- trunk/KDE/kdesdk/umbrello/umbrello/umllistview.cpp #677386:677387
@@ -2526,6 +2526,9 @@
         case Uml::lvt_Template:
         case Uml::lvt_Operation:
         case Uml::lvt_EnumLiteral:
+        case Uml::lvt_UniqueConstraint:
+        case Uml::lvt_PrimaryKeyConstraint:
+        case Uml::lvt_ForeignKeyConstraint:
             item = findItem(nID);
             if (item == NULL) {
                 kDebug() << pfx << "item " << ID2STR(nID) << " (of type "
--- trunk/KDE/kdesdk/umbrello/umbrello/umlobject.cpp #677386:677387
@@ -719,7 +719,8 @@
     if (m_BaseType != Uml::ot_Operation && m_BaseType != Uml::ot_Attribute &&
             m_BaseType != Uml::ot_EnumLiteral && m_BaseType != Uml::ot_EntityAttribute &&
             m_BaseType != Uml::ot_Template && m_BaseType != Uml::ot_Stereotype &&
-            m_BaseType != Uml::ot_Role) {
+            m_BaseType != Uml::ot_Role && m_BaseType !=Uml::ot_UniqueConstraint &&
+            m_BaseType != Uml::ot_ForeignKeyConstraint ) {
         if (m_bInPaste) {
             m_pUMLPackage = NULL;  // forget any old parent
             UMLListView *listView = UMLApp::app()->getListView();
--- trunk/KDE/kdesdk/umbrello/umbrello/umlview.cpp #677386:677387
@@ -105,6 +105,8 @@
 #include "umlwidget.h"
 #include "toolbarstatefactory.h"
 #include "cmds.h"
+#include "entity.h"
+#include "foreignkeyconstraint.h"
 
 // control the manual DoubleBuffering of QCanvas
 // with a define, so that this memory X11 effect can
@@ -520,8 +522,12 @@
         // widget might saturate some latent attribute assocs.
         for (UMLWidgetListIt it(m_WidgetList); it.current(); ++it) {
             UMLWidget *w = it.current();
-            if (w != newWidget)
+            if (w != newWidget) {
                 createAutoAttributeAssociations(w);
+
+                if ( o->getBaseType() == ot_Entity )
+                  createAutoConstraintAssociations(w);
+            }
         }
         break;
     default:
@@ -828,7 +834,8 @@
         if (testType != Uml::at_Association &&
             testType != Uml::at_UniAssociation &&
             testType != Uml::at_Composition &&
-            testType != Uml::at_Aggregation)
+            testType != Uml::at_Aggregation &&
+            testType != Uml::at_Relationship)
             continue;
         if (pWidgetA->getID() == assoc->getWidgetID(A) &&
             pWidgetB->getID() == assoc->getWidgetID(B) &&
@@ -2046,9 +2053,9 @@
     if (widget == NULL ||
         (m_Type != Uml::dt_Class &&
          m_Type != Uml::dt_Component &&
-         m_Type != Uml::dt_Deployment &&
-         m_Type != Uml::dt_EntityRelationship))
-        return;
+         m_Type != Uml::dt_Deployment
+         && m_Type != Uml::dt_EntityRelationship))
+         return;
     // Recipe:
     // If this widget has an underlying UMLCanvasObject then
     //   for each of the UMLCanvasObject's UMLAssociations
@@ -2161,7 +2168,13 @@
         if (! addAssociation(assocwidget))
             delete assocwidget;
     }
+
     createAutoAttributeAssociations(widget);
+
+    if ( m_Type == Uml::dt_EntityRelationship ) {
+        createAutoConstraintAssociations(widget);
+    }
+
     // if this object is capable of containing nested objects then
     Uml::Object_Type t = umlObj->getBaseType();
     if (t == ot_Package || t == ot_Class || t == ot_Interface || t == ot_Component) {
@@ -2342,6 +2355,85 @@
     }
 }
 
+void UMLView::createAutoConstraintAssociations(UMLWidget *widget) {
+    if (widget == NULL || m_Type != Uml::dt_EntityRelationship)
+        return;
+
+    // Pseudocode:
+    //   if the underlying model object is really a UMLEntity then
+    //     for each of the UMLEntity's UMLForeignKeyConstraint's
+    //       if the attribute type has a widget representation on this view then
+    //         if the AssocWidget does not already exist then
+    //           if the current diagram type permits relationships then
+    //             create a relationship AssocWidget
+    //           end if
+    //         end if
+    //       end if
+
+    UMLObject *tmpUmlObj = widget->getUMLObject();
+    if (tmpUmlObj == NULL)
+        return;
+    // check if the underlying model object is really a UMLEntity
+    UMLCanvasObject *umlObj = dynamic_cast<UMLCanvasObject*>(tmpUmlObj);
+    if (umlObj == NULL)
+        return;
+     // finished checking whether this widget has a UMLCanvas Object
+
+    if (tmpUmlObj->getBaseType() != Uml::ot_Entity)
+        return;
+    UMLEntity *entity = static_cast<UMLEntity*>(tmpUmlObj);
+
+    // for each of the UMLEntity's UMLForeignKeyConstraints
+    UMLClassifierListItemList constrList = entity->getFilteredList(Uml::ot_ForeignKeyConstraint);
+
+    for (UMLClassifierListItemListIt ect(constrList); ect.current(); ++ect) {
+        UMLEntityConstraint *eConstr = static_cast<UMLEntityConstraint*>( ect.current() );
+
+        UMLForeignKeyConstraint* fkc = static_cast<UMLForeignKeyConstraint*>(eConstr);
+        if( fkc == NULL ){
+            return;
+        }
+
+        UMLEntity* refEntity = fkc->getReferencedEntity();
+        if( refEntity == NULL ){
+            return;
+        }
+
+        createAutoConstraintAssociation(refEntity , fkc , widget);
+
+    }
+}
+
+void UMLView::createAutoConstraintAssociation(UMLEntity* refEntity, UMLForeignKeyConstraint* fkConstraint, UMLWidget* widget){
+
+    if (refEntity == NULL) {
+         return;
+    }
+
+    Uml::Association_Type assocType = Uml::at_Relationship;
+    UMLWidget *w = findWidget( refEntity->getID() );
+    AssociationWidget *aw = NULL;
+
+    if (w) {
+        aw = findAssocWidget(widget, w, fkConstraint->getName());
+        if ( aw == NULL &&
+               // if the current diagram type permits relationships
+               AssocRules::allowAssociation(assocType, widget, w, false) ) {
+
+            AssociationWidget *a = new AssociationWidget (this, widget, assocType, w);
+            a->setUMLObject(fkConstraint);
+            a->calculateEndingPoints();
+            //a->setVisibility(attr->getVisibility(), B);
+            a->setRoleName(fkConstraint->getName(), B);
+            a->setActivated(true);
+            if (! addAssociation(a))
+                delete a;
+        }
+    }
+
+}
+
+
 void UMLView::findMaxBoundingRectangle(const FloatingTextWidget* ft, int& px, int& py, int& qx, int& qy)
 {
     if (ft == NULL || !ft->isVisible())
--- trunk/KDE/kdesdk/umbrello/umbrello/umlview.h #677386:677387
@@ -47,6 +47,8 @@
 class UMLCanvasObject;
 class UMLClassifier;
 class UMLViewImageExporter;
+class UMLForeignKeyConstraint;
+class UMLEntity;
 
 class KPrinter;
 class ToolBarState;
@@ -731,6 +733,9 @@
      */
     void createAutoAttributeAssociations(UMLWidget *widget);
 
+    void createAutoConstraintAssociations(UMLWidget* widget);
+
+
     /**
      * Refreshes containment association, i.e. removes possible old
      * containment and adds new containment association if applicable.
@@ -1199,6 +1204,10 @@
                                         UMLAttribute *attr,
                                         UMLWidget *widget);
 
+    void createAutoConstraintAssociation(UMLEntity* refEntity, 
+                                         UMLForeignKeyConstraint* fkConstraint, 
+                                         UMLWidget* widget);
+
 public slots:
 
     void zoomIn();
--- trunk/KDE/kdesdk/umbrello/umbrello/umlwidget.cpp #677386:677387
@@ -182,9 +182,15 @@
 {
     updateComponentSize();
     adjustAssocs( getX(), getY() ); //adjust assoc lines.
-    if (m_Type == Uml::wt_Class) {
-        m_pView->createAutoAttributeAssociations(this);
+    switch( m_Type ) {
+        case Uml::wt_Class:
+            m_pView->createAutoAttributeAssociations( this );
+            break;
+        case Uml::wt_Entity:
+            m_pView->createAutoConstraintAssociations( this );
+            break;
     }
+
     if(isVisible())
         update();
 }
--- trunk/KDE/kdesdk/umbrello/umbrello/uniqueconstraint.cpp #677386:677387
@@ -78,7 +78,6 @@
 
 QString UMLUniqueConstraint::toString(Uml::Signature_Type sig ) {
      QString s;
-    //FIXME
 
     if(sig == Uml::st_ShowSig || sig == Uml::st_ShowSig || sig == Uml::st_SigNoVis) {
         s = getName() + ':';
@@ -94,7 +93,7 @@
             if ( first ) {
                first = false;
             } else
-                s += ' , ';
+                s += ',';
             s += att->getName();
         }
         s +=  ')' ;
@@ -111,7 +110,20 @@
 }
 
 void UMLUniqueConstraint::saveToXMI( QDomDocument & qDoc, QDomElement & qElement ) {
-    kDebug()<< k_funcinfo <<"Nothing implemented yet";
+    QDomElement uniqueConstraintElement = UMLObject::save("UML:UniqueConstraint", qDoc);
+
+    UMLEntity* parentEnt = static_cast<UMLEntity*>( parent() );
+    if ( parentEnt->isPrimaryKey( this ) ) {
+        uniqueConstraintElement.setAttribute( "isPrimary", "1" );
+    } else {
+        uniqueConstraintElement.setAttribute( "isPrimary", "0" );
+    }
+
+    foreach( UMLEntityAttribute* att, m_EntityAttributeList ) {
+        att->saveToXMI(qDoc,uniqueConstraintElement);
+    }
+
+    qElement.appendChild( uniqueConstraintElement );
 }
 
 bool UMLUniqueConstraint::showPropertiesDialog(QWidget* parent) {
@@ -120,7 +132,40 @@
 }
 
 bool UMLUniqueConstraint::load( QDomElement & element ) {
-    kDebug()<< k_funcinfo <<"Nothing implemented yet"<<endl;
+
+    int isPrimary = element.attribute( "isPrimary", "0" ).toInt();
+    UMLEntity* parentEnt = static_cast<UMLEntity*>(parent());
+
+    if ( isPrimary == 1 ) {
+        parentEnt->setAsPrimaryKey(this);
+    }
+
+    QDomNode node = element.firstChild();
+    while ( !node.isNull() ) {
+        if (node.isComment()) {
+            node = node.nextSibling();
+            continue;
+        }
+        QDomElement tempElement = node.toElement();
+        QString tag = tempElement.tagName();
+        if (Uml::tagEq(tag, "EntityAttribute")) {
+
+            QString attName = tempElement.attribute("name","" );
+            UMLObject* obj = parentEnt->findChildObject( attName );
+
+            UMLEntityAttribute* entAtt = static_cast<UMLEntityAttribute*>(obj);
+            if ( entAtt == NULL )
+                continue;
+
+            m_EntityAttributeList.append(entAtt);
+
+        } else {
+            kWarning() << "unknown child type in UMLUniqueConstraint::load" << endl;
+        }
+
+        node = node.nextSibling();
+    }
+
     return true;
 }
 




More information about the umbrello-devel mailing list