ownedcodeblock.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "ownedcodeblock.h"
00019
00020
00021 #include <kdebug.h>
00022
00023
00024 #include "association.h"
00025 #include "classifier.h"
00026 #include "umldoc.h"
00027 #include "umlobject.h"
00028 #include "umlrole.h"
00029 #include "uml.h"
00030 #include "codedocument.h"
00031 #include "codegenerator.h"
00032
00033
00034
00035
00036
00037 OwnedCodeBlock::OwnedCodeBlock ( UMLObject * parent )
00038 : QObject ( (QObject*)parent, "anOwnedCodeBlock" )
00039 {
00040 initFields(parent);
00041 }
00042
00043 OwnedCodeBlock::~OwnedCodeBlock ( ) {
00044
00045
00046
00047
00048 }
00049
00050
00051
00052
00053
00054 void OwnedCodeBlock::release () {
00055 if(m_parentObject)
00056 m_parentObject->disconnect(this);
00057 m_parentObject = 0;
00058 }
00059
00064 UMLObject * OwnedCodeBlock::getParentObject () {
00065 return m_parentObject;
00066 }
00067
00068
00069
00070
00071 void OwnedCodeBlock::setAttributesFromObject (TextBlock * obj) {
00072
00073 OwnedCodeBlock * oc = dynamic_cast<OwnedCodeBlock*>(obj);
00074 if(oc)
00075 {
00076 m_parentObject->disconnect(this);
00077 initFields(oc->getParentObject());
00078 }
00079 }
00080
00084 void OwnedCodeBlock::setAttributesOnNode(QDomDocument& , QDomElement& elem) {
00085
00086
00087
00088
00089
00090 UMLRole * role = dynamic_cast<UMLRole*>(m_parentObject);
00091 if(role)
00092 {
00093 elem.setAttribute("parent_id",ID2STR(role->getParentAssociation()->getID()));
00094
00095
00096
00097
00098 elem.setAttribute("role_id", (role->getRole() == Uml::A));
00099 }
00100 else
00101 {
00102 elem.setAttribute("parent_id",ID2STR(m_parentObject->getID()));
00103
00104 }
00105
00106 }
00107
00111 void OwnedCodeBlock::setAttributesFromNode ( QDomElement & elem) {
00112
00113
00114 QString idStr = elem.attribute("parent_id","-1");
00115 Uml::IDType id = STR2ID(idStr);
00116
00117
00118 getParentObject()->disconnect(this);
00119
00120
00121 UMLObject * obj = UMLApp::app()->getDocument()->findObjectById(id);
00122 if(obj)
00123 {
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 UMLAssociation * assoc = dynamic_cast<UMLAssociation*>(obj);
00136 if(assoc) {
00137
00138 UMLRole * role = 0;
00139 int role_id = elem.attribute("role_id","-1").toInt();
00140
00141 if(role_id == 1)
00142 role = assoc->getUMLRole(Uml::A);
00143 else if(role_id == 0)
00144 role = assoc->getUMLRole(Uml::B);
00145 else
00146 kError() << "corrupt save file? "
00147 << "cant get proper UMLRole for ownedcodeblock uml id:"
00148 << ID2STR(id) << " w/role_id:" << role_id << endl;
00149
00150
00151 initFields ( role );
00152 } else
00153 initFields ( obj);
00154
00155 }
00156 else
00157 kError() << "ERROR: can't load ownedcodeblock: parentUMLObject w/id:"
00158 << ID2STR(id) << " not found, corrupt save file?" << endl;
00159
00160 }
00161
00162 void OwnedCodeBlock::initFields(UMLObject * parent )
00163 {
00164
00165 m_parentObject = parent;
00166
00167
00168
00169
00170
00171 connect(m_parentObject, SIGNAL(modified()), this, SLOT(syncToParent()));
00172 }
00173
00176 void OwnedCodeBlock::syncToParent ( ) {
00177 updateContent();
00178 }
00179
00180 #include "ownedcodeblock.moc"
This file is part of the documentation for umbrello Version 3.1.0.