[Uml-devel] KDE/kdesdk/umbrello/umbrello
Sharan Rao
sharanrao at gmail.com
Mon Jun 25 15:32:28 UTC 2007
SVN commit 680171 by sharan:
* XMI representation for foreign key constraints
( many thanks to Oliver Kellogg for all his tips :) )
M +11 -2 entity.cpp
M +0 -40 entityconstraint.cpp
M +1 -32 entityconstraint.h
M +101 -3 foreignkeyconstraint.cpp
M +19 -0 foreignkeyconstraint.h
--- trunk/KDE/kdesdk/umbrello/umbrello/entity.cpp #680170:680171
@@ -272,8 +272,17 @@
UMLObject* obj = oit.current();
if (obj->resolveRef()) {
UMLClassifierListItem *cli = static_cast<UMLClassifierListItem*>(obj);
- if (cli->getBaseType() == Uml::ot_EntityAttribute)
- emit entityAttributeAdded(cli);
+ switch (cli->getBaseType() ) {
+ case Uml::ot_EntityAttribute:
+ emit entityAttributeAdded(cli);
+ break;
+ case Uml::ot_UniqueConstraint:
+ case Uml::ot_ForeignKeyConstraint:
+ emit entityConstraintAdded(cli);
+ break;
+ default:
+ break;
+ }
}
}
return success;
--- trunk/KDE/kdesdk/umbrello/umbrello/entityconstraint.cpp #680170:680171
@@ -18,8 +18,6 @@
#include "umlobject.h"
#include "umldoc.h"
#include "uml.h"
-#include "dialogs/umlattributedialog.h"
-#include "object_factory.h"
UMLEntityConstraint::UMLEntityConstraint(const UMLObject *parent,
@@ -49,45 +47,7 @@
UMLEntityConstraint::~UMLEntityConstraint() {}
-UMLObject* UMLEntityConstraint::clone() const {
- //FIXME: The new attribute should be slaved to the NEW parent not the old.
- UMLEntityConstraint *clone = new UMLEntityConstraint( static_cast<UMLObject*>(parent()) );
- copyInto(clone);
- return clone;
-}
-QString UMLEntityConstraint::getFullyQualifiedName(QString separator,
- bool includeRoot ) const
-{
- kDebug() << k_funcinfo << "Not Yet implemented "<< endl;
- return QString();
-}
-
-void UMLEntityConstraint::saveToXMI( QDomDocument & qDoc, QDomElement & qElement )
-{
- kDebug() << k_funcinfo << "Not Yet implemented "<< endl;
-
-}
-
-bool UMLEntityConstraint::showPropertiesDialog(QWidget* parent)
-{
- kDebug() << k_funcinfo << "Not Yet implemented "<< endl;
- return false;
-}
-
-bool UMLEntityConstraint::load( QDomElement & element )
-{
- kDebug() << k_funcinfo << "Not Yet implemented "<< endl;
- return false;
-}
-
-QString UMLEntityConstraint::toString(Uml::Signature_Type sig )
-{
- kDebug() << k_funcinfo << "Not Yet implemented "<< endl;
- return QString();
-
-}
-
void UMLEntityConstraint::copyInto(UMLEntityConstraint *rhs) const {
// call the parent first.
--- trunk/KDE/kdesdk/umbrello/umbrello/entityconstraint.h #680170:680171
@@ -65,40 +65,9 @@
/**
* Make a clone of the UMLEntityConstraint.
*/
- virtual UMLObject* clone() const;
+ virtual UMLObject* clone() const = 0;
- /**
- * Returns a string representation of the UMLEntityConstraint.
- *
- * @param sig If true will show the attribute type and
- * initial value.
- * @return Returns a string representation of the UMLAttribute.
- */
- QString toString(Uml::Signature_Type sig = Uml::st_NoSig);
- /**
- * Reimplement method from UMLObject.
- */
- QString getFullyQualifiedName(QString separator = QString(),
- bool includeRoot = false) const;
-
- /**
- * Creates the <UML:EntityConstraint> XMI element.
- */
- void saveToXMI( QDomDocument & qDoc, QDomElement & qElement );
-
- /**
- * Display the properties configuration dialog for the attribute.
- */
- virtual bool showPropertiesDialog(QWidget* parent);
-
-
-protected:
- /**
- * Loads the <UML:EntityConstraint> XMI element.
- */
- bool load( QDomElement & element );
-
};
#endif
--- trunk/KDE/kdesdk/umbrello/umbrello/foreignkeyconstraint.cpp #680170:680171
@@ -14,6 +14,7 @@
// qt/kde includes
#include <qregexp.h>
#include <kdebug.h>
+#include <qpair.h>
// app includes
#include "entity.h"
#include "entityattribute.h"
@@ -105,7 +106,25 @@
void UMLForeignKeyConstraint::saveToXMI( QDomDocument & qDoc, QDomElement & qElement ) {
- kDebug()<< k_funcinfo <<"Nothing implemented yet"<<endl;
+ QDomElement foreignKeyConstraintElement = UMLObject::save( "UML:ForeignKeyConstraint", qDoc );
+
+ foreignKeyConstraintElement.setAttribute( "referencedEntity", ID2STR( m_ReferencedEntity->getID() ) );
+
+ int updateAction = (int)m_UpdateAction;
+ int deleteAction = (int)m_DeleteAction;
+
+ foreignKeyConstraintElement.setAttribute( "updateAction", updateAction );
+ foreignKeyConstraintElement.setAttribute( "deleteAction", deleteAction );
+
+ QMap<UMLEntityAttribute*, UMLEntityAttribute*>::iterator i;
+ for (i = m_AttributeMap.begin(); i!= m_AttributeMap.end() ; ++i) {
+ QDomElement mapElement = qDoc.createElement( "AttributeMap" );
+ mapElement.setAttribute( "key", ID2STR((i.key())->getID()) );
+ mapElement.setAttribute( "value", ID2STR((i.value())->getID()) );
+ foreignKeyConstraintElement.appendChild( mapElement );
+ }
+
+ qElement.appendChild(foreignKeyConstraintElement);
}
bool UMLForeignKeyConstraint::showPropertiesDialog(QWidget* parent) {
@@ -192,8 +211,58 @@
}
bool UMLForeignKeyConstraint::load( QDomElement & element ) {
- kDebug()<< k_funcinfo <<"Nothing implemented yet";
- return true;
+ UMLDoc* doc = UMLApp::app()->getDocument();
+
+ Uml::IDType referencedEntityId = STR2ID( element.attribute("referencedEntity","" ) );
+
+ UMLObject* obj = doc->findObjectById(referencedEntityId);
+ m_ReferencedEntity = static_cast<UMLEntity*>(obj);
+
+ if ( m_ReferencedEntity == NULL ) {
+ // save for resolving later
+ m_pReferencedEntityID = referencedEntityId;
+ }
+
+ m_UpdateAction = (UpdateDeleteAction)element.attribute( "updateAction" ).toInt();
+ m_DeleteAction = (UpdateDeleteAction)element.attribute( "deleteAction" ).toInt();
+
+ 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, "AttributeMap")) {
+
+ Uml::IDType keyId = STR2ID(tempElement.attribute("key","" ));
+ Uml::IDType valueId = STR2ID(tempElement.attribute("value","" ));
+
+ UMLEntityAttribute* key = NULL , *value = NULL;
+
+ UMLEntity* parentEntity = static_cast<UMLEntity*>( parent() );
+ UMLObject* keyObj = parentEntity->findChildObjectById(keyId);
+ key = static_cast<UMLEntityAttribute*>(keyObj);
+
+ if ( m_ReferencedEntity == NULL ) {
+ // if referenced entity is null, then we won't find its attributes even
+ // save for resolving later
+ m_pEntityAttributeIDMap.insert( key, valueId );
+ } else {
+ UMLObject* valueObj = m_ReferencedEntity->findChildObjectById(valueId);
+ value = static_cast<UMLEntityAttribute*>( valueObj );
+ }
+
+
+ } else {
+ kWarning() << "unknown child type in UMLUniqueConstraint::load" << endl;
+ }
+
+ node = node.nextSibling();
+ }
+
+ return true;
}
@@ -219,6 +288,35 @@
}
+bool UMLForeignKeyConstraint::resolveRef() {
+ // resolve referenced entity first
+ UMLDoc* doc = UMLApp::app()->getDocument();
+
+ bool success = true;
+
+ //resolve the referenced entity
+ if ( !ID2STR(m_pReferencedEntityID).isEmpty() ) {
+ UMLObject* obj = doc->findObjectById(m_pReferencedEntityID);
+ m_ReferencedEntity = static_cast<UMLEntity*>(obj);
+ if (m_ReferencedEntity == NULL ) {
+ success = false;
+ }
+ }
+
+ QMap<UMLEntityAttribute*, Uml::IDType>::iterator i;
+ for (i = m_pEntityAttributeIDMap.begin(); i!= m_pEntityAttributeIDMap.end() ; ++i) {
+ if ( !ID2STR(i.value()).isEmpty() ) {
+ UMLObject* obj = doc->findObjectById(i.value());
+ m_AttributeMap[i.key()] = static_cast<UMLEntityAttribute*>(obj);
+ if ( m_AttributeMap[i.key()] == NULL ) {
+ success = false;
+ }
+ }
+ }
+
+ return success;
+}
+
#include "foreignkeyconstraint.moc"
--- trunk/KDE/kdesdk/umbrello/umbrello/foreignkeyconstraint.h #680170:680171
@@ -176,6 +176,12 @@
*/
void clearMappings();
+ /**
+ * Remimplementation from base classes
+ * Used to resolve forward references to referenced entities in xmi
+ */
+ bool resolveRef();
+
signals:
void sigReferencedEntityChanged();
@@ -191,7 +197,20 @@
private:
+ /**
+ * Used to resolve forward references to UMLEntity
+ */
+ Uml::IDType m_pReferencedEntityID;
+
/**
+ * Used to resolve forward references to UMLEntityAttributes
+ * Key -> The local attribute
+ * Value -> Id of the attribute it is mapping to
+ */
+ QMap<UMLEntityAttribute*, Uml::IDType> m_pEntityAttributeIDMap;
+
+
+ /**
* Initialisation of common variables
*/
void init();
More information about the umbrello-devel
mailing list