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

Sharan Rao sharanrao at gmail.com
Tue Jan 15 12:36:10 UTC 2008


SVN commit 761842 by sharan:

Add support for copy/pasting Templates, Enum Literals and Entity Attributes ( can also be read as: fixed bug where copy pasting for the mentioned things didn't work ;) )


 M  +1 -1      attribute.h  
 M  +1 -1      classifier.h  
 M  +70 -3     clipboard/umlclipboard.cpp  
 M  +1 -1      clipboard/umlclipboard.h  
 M  +13 -4     entity.cpp  
 M  +13 -2     entity.h  
 M  +1 -1      entityattribute.h  
 M  +9 -0      enum.cpp  
 M  +10 -0     enum.h  
 M  +1 -1      enumliteral.h  
 M  +12 -0     model_utils.cpp  
 M  +5 -0      model_utils.h  


--- trunk/KDE/kdesdk/umbrello/umbrello/attribute.h #761841:761842
@@ -115,7 +115,7 @@
     /**
      * Creates the <UML:Attribute> XMI element.
      */
-    void saveToXMI( QDomDocument & qDoc, QDomElement & qElement );
+    virtual void saveToXMI( QDomDocument & qDoc, QDomElement & qElement );
 
     /**
      * Display the properties configuration dialog for the attribute.
--- trunk/KDE/kdesdk/umbrello/umbrello/classifier.h #761841:761842
@@ -505,7 +505,7 @@
      * <UML:Attribute>, <UML:Operation>, or <UML:TemplateParameter>.
      * Used by the clipboard for paste operation.
      */
-    UMLClassifierListItem* makeChildObject(const QString& xmiTag);
+    virtual UMLClassifierListItem* makeChildObject(const QString& xmiTag);
 
     /**
      * Return the list of unidirectional association that should show up in the code
--- trunk/KDE/kdesdk/umbrello/umbrello/clipboard/umlclipboard.cpp #761841:761842
@@ -24,8 +24,13 @@
 #include "../associationwidget.h"
 #include "../attribute.h"
 #include "../classifier.h"
+#include "../enum.h"
+#include "../entity.h"
 #include "../floatingtextwidget.h"
 #include "../operation.h"
+#include "../template.h"
+#include "../enumliteral.h"
+#include "../entityattribute.h"
 #include "../umldoc.h"
 #include "../umllistview.h"
 #include "../umllistviewitem.h"
@@ -533,11 +538,11 @@
     UMLDoc *doc = UMLApp::app()->getDocument();
     UMLListView *listView = UMLApp::app()->getListView();
     UMLListViewItem* lvitem = dynamic_cast<UMLListViewItem *>( listView->currentItem() );
-    if (!lvitem ||
-            (lvitem->getType() != Uml::lvt_Class && lvitem->getType() != Uml::lvt_Interface)) {
+    if (!lvitem || !Model_Utils::typeIsClassifier( lvitem->getType() )) {
         return false;
     }
-    UMLClassifier *parent = dynamic_cast<UMLClassifier *>(lvitem->getUMLObject());
+    UMLClassifier *parent = dynamic_cast<UMLClassifier*>( lvitem->getUMLObject() );
+
     if (parent == NULL) {
         uError() << "parent is not a UMLClassifier" << endl;
         return false;
@@ -591,6 +596,68 @@
                 }
                 break;
             }
+        case Uml::ot_Template:
+            {
+                UMLTemplate* tp = static_cast<UMLTemplate*>( obj );
+                UMLTemplate* exist = parent->findTemplate( tp->getName() );
+                if ( exist ) {
+                    QString newName = parent->uniqChildName( Uml::ot_Template, obj->getName() );
+                    tp->setName( newName );
+                }
+                if ( parent->addTemplate( tp, idchanges ) ) {
+                    result = true;
+                } else {
+                    uError()<<""<<parent->getName()<<"->addTemplate("<<tp->getName()<<") failed"<<endl;
+                }
+                break;
+            }
+        case Uml::ot_EnumLiteral:
+           {
+               UMLEnum* enumParent = static_cast<UMLEnum*>( parent );
+               // if parent is not a UMLEnum, bail out immediately;
+               if ( !enumParent ) {
+                   result = false;
+                   uError() << "Parent is not an UMLEnum" << endl;
+                   break;
+               }
+
+               UMLObject* exist = enumParent->findChildObject( obj->getName(), Uml::ot_EnumLiteral );
+               if ( exist ) {
+                   QString newName = enumParent->uniqChildName( Uml::ot_EnumLiteral, obj->getName() );
+                   obj->setName( newName );
+               }
+               UMLEnumLiteral* enl = static_cast<UMLEnumLiteral*>( obj );
+
+               if ( enumParent->addEnumLiteral( enl, idchanges ) ) {
+                   result = true;
+               } else {
+                   uError()<<""<<enumParent->getName()<<"->addEnumLiteral("<<enl->getName()<<") failed"<<endl;
+               }
+               break;
+           }
+        case Uml::ot_EntityAttribute :
+            {
+                UMLEntity* entityParent = static_cast<UMLEntity*>( parent );
+                // if parent is not a UMLEntity, bail out immediately;
+                if ( !entityParent ) {
+                    result = false;
+                    uError()<<"Parent is not an UMLEntity";
+                    break;
+                }
+                UMLObject *exist = entityParent->findChildObject(obj->getName(), Uml::ot_EntityAttribute);
+                if (exist) {
+                    QString newName = entityParent->uniqChildName(Uml::ot_EntityAttribute, obj->getName());
+                    obj->setName(newName);
+                }
+                UMLEntityAttribute *att = static_cast<UMLEntityAttribute*>(obj);
+
+                if ( entityParent->addEntityAttribute(att, idchanges)) {
+                    result = true;
+                } else {
+                    uError() << "" << parent->getName() << "->addEntityAttribute(" << att->getName() << ") failed" << endl;
+                }
+                break;
+            }
         default :
             uWarning() << "pasting unknown children type in clip type 5";
             return false;
--- trunk/KDE/kdesdk/umbrello/umbrello/clipboard/umlclipboard.h #761841:761842
@@ -68,7 +68,7 @@
         clip2 = 2, ///<UMLObjects, UMLListViewItems (not diagrams) and diagrams
         clip3 = 3, ///<UMLListViewItems (not diagrams)
         clip4 = 4, ///<UMLObjects, Associations and UMLWidgets
-        clip5 = 5  ///<Only Attributes and Operations
+        clip5 = 5  ///<Only Attributes, Operations, Templates and EnumLiterals
     };
 
 private:
--- trunk/KDE/kdesdk/umbrello/umbrello/entity.cpp #761841:761842
@@ -69,7 +69,9 @@
              this, SLOT( slotEntityAttributeRemoved( UMLClassifierListItem* ) ) );
 }
 
-UMLAttribute* UMLEntity::createAttribute(const QString &name /*=null*/, UMLObject *type /*=NULL*/) {
+UMLAttribute* UMLEntity::createAttribute(const QString &name /*=null*/, UMLObject *type /*=NULL*/
+                                         , Uml::Visibility vis /* = Uml::Visibility::Private*/
+                                         , const QString& iv /* = QString()*/) {
     Uml::IDType id = UniqueID::gen();
     QString currentName;
     if (name.isNull())  {
@@ -77,10 +79,9 @@
     } else {
         currentName = name;
     }
-    const Settings::OptionState optionState = Settings::getOptionState();
-    Uml::Visibility scope = optionState.classState.defaultAttributeScope;
-    UMLEntityAttribute* newAttribute = new UMLEntityAttribute(this, currentName, id, scope, type);
 
+    UMLEntityAttribute* newAttribute = new UMLEntityAttribute(this, currentName, id, vis, type, iv);
+
     int button = QDialog::Accepted;
     bool goodName = false;
 
@@ -553,4 +554,12 @@
 }
 
 
+UMLClassifierListItem* UMLEntity::makeChildObject(const QString& xmiTag) {
+    UMLClassifierListItem* pObject = NULL;
+    if (Uml::tagEq(xmiTag, "EntityAttribute")) {
+        pObject = new UMLEntityAttribute(this);
+    }
+    return pObject;
+}
+
 #include "entity.moc"
--- trunk/KDE/kdesdk/umbrello/umbrello/entity.h #761841:761842
@@ -74,8 +74,9 @@
      * @param type  An optional type, used by when creating through UMLListView
      * @return  The UMLEntityAttribute created
      */
-    UMLAttribute* createAttribute(const QString &name = QString(),
-                                  UMLObject *type = 0);
+    virtual UMLAttribute* createAttribute(const QString &name = QString(),
+                                  UMLObject *type = 0, Uml::Visibility vis = Uml::Visibility::Private,
+                                  const QString &init = QString());
 
     /**
      * Creates a Unique Constraint for this Entity.
@@ -227,6 +228,16 @@
      */
     UMLEntityAttributeList getEntityAttributes() const;
 
+    /**
+     * Create a new ClassifierListObject (entityattribute)
+     * according to the given XMI tag.
+     * Returns NULL if the string given does not contain one of the tags
+     * <UML:EntityAttribute>
+     * Used by the clipboard for paste operation.
+     * Reimplemented from UMLClassifier for UMLEntity
+     */
+    virtual UMLClassifierListItem* makeChildObject(const QString& xmiTag);
+
 private slots:
     void slotEntityAttributeRemoved(UMLClassifierListItem*);
 
--- trunk/KDE/kdesdk/umbrello/umbrello/entityattribute.h #761841:761842
@@ -151,7 +151,7 @@
     /**
      * Creates the <UML:EntityAttribute> XMI element.
      */
-    void saveToXMI(QDomDocument& qDoc, QDomElement& qElement);
+    virtual void saveToXMI(QDomDocument& qDoc, QDomElement& qElement);
 
     /**
      * Display the properties configuration dialog for the entityattribute.
--- trunk/KDE/kdesdk/umbrello/umbrello/enum.cpp #761841:761842
@@ -197,4 +197,13 @@
 }
 
 
+UMLClassifierListItem* UMLEnum::makeChildObject(const QString& xmiTag)
+{
+    UMLClassifierListItem* pObject = NULL;
+    if (Uml::tagEq(xmiTag, "EnumerationLiteral") || Uml::tagEq( xmiTag, "EnumLiteral")) {
+        pObject = new UMLEnumLiteral(this);
+    }
+    return pObject;
+}
+
 #include "enum.moc"
--- trunk/KDE/kdesdk/umbrello/umbrello/enum.h #761841:761842
@@ -123,6 +123,16 @@
      */
     virtual void saveToXMI( QDomDocument & qDoc, QDomElement & qElement );
 
+    /**
+     * Create a new ClassifierListObject (enumLiteral)
+     * according to the given XMI tag.
+     * Returns NULL if the string given does not contain one of the tags
+     * <UML:EnumLiteral>
+     * Used by the clipboard for paste operation.
+     * Reimplemented from UMLClassifier for UMLEnum
+     */
+    virtual UMLClassifierListItem* makeChildObject(const QString& xmiTag);
+
 signals:
     void enumLiteralAdded(UMLClassifierListItem*);
     void enumLiteralRemoved(UMLClassifierListItem*);
--- trunk/KDE/kdesdk/umbrello/umbrello/enumliteral.h #761841:761842
@@ -67,7 +67,7 @@
     /**
      * Creates the <UML:EnumLiteral> XMI element.
      */
-    void saveToXMI(QDomDocument& qDoc, QDomElement& qElement);
+    virtual void saveToXMI(QDomDocument& qDoc, QDomElement& qElement);
 
     /**
      * Display the properties configuration dialog for the enum literal.
--- trunk/KDE/kdesdk/umbrello/umbrello/model_utils.cpp #761841:761842
@@ -760,6 +760,17 @@
     }
 }
 
+bool typeIsClassifier(Uml::ListView_Type type) {
+    if ( type == Uml::lvt_Class ||
+         type == Uml::lvt_Interface ||
+         type == Uml::lvt_Entity ||
+         type == Uml::lvt_Enum ) {
+        return true;
+    }
+    return false;
+
+}
+
 bool typeIsDiagram(Uml::ListView_Type type) {
     if (type == Uml::lvt_Class_Diagram ||
             type == Uml::lvt_Collaboration_Diagram ||
@@ -1366,3 +1377,4 @@
 }
 
 }  // namespace Model_Utils
+
--- trunk/KDE/kdesdk/umbrello/umbrello/model_utils.h #761841:761842
@@ -141,6 +141,11 @@
 bool typeIsClassifierList(Uml::ListView_Type type);
 
 /**
+ * Return true if the listview type is a classifier ( Class, Entity , Enum )
+ */
+bool typeIsClassifier(Uml::ListView_Type type);
+
+/**
  * Return the Model_Type which corresponds to the given Diagram_Type.
  */
 Uml::Model_Type convert_DT_MT(Uml::Diagram_Type dt);




More information about the umbrello-devel mailing list