codeparameter.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "codeparameter.h"
00019
00020
00021 #include <kdebug.h>
00022
00023
00024 #include "association.h"
00025 #include "attribute.h"
00026 #include "classifiercodedocument.h"
00027 #include "umldoc.h"
00028 #include "umlobject.h"
00029 #include "umlrole.h"
00030 #include "uml.h"
00031 #include "codegenerators/codegenfactory.h"
00032
00033
00034
00035
00036 CodeParameter::CodeParameter ( ClassifierCodeDocument * parentDoc, UMLObject * parentObject )
00037 : QObject ( (QObject*) parentObject, "ACodeParam")
00038 {
00039 initFields( parentDoc, parentObject );
00040 }
00041
00042 CodeParameter::~CodeParameter ( ) { }
00043
00044
00045
00046
00047
00048
00049
00050
00051
00056 bool CodeParameter::getAbstract ( ) {
00057 return m_parentObject->getAbstract();
00058 }
00059
00065 bool CodeParameter::getStatic ( ) {
00066 return m_parentObject->getStatic();
00067 }
00068
00074 QString CodeParameter::getName ( ) const {
00075 return m_parentObject->getName();
00076 }
00077
00084 QString CodeParameter::getTypeName ( ) {
00085 UMLAttribute * at = (UMLAttribute*) m_parentObject;
00086 return at->getTypeName();
00087 }
00088
00094 Uml::Visibility CodeParameter::getVisibility ( ) const {
00095 return m_parentObject->getVisibility();
00096 }
00097
00103 void CodeParameter::setInitialValue ( const QString &new_var ) {
00104 m_initialValue = new_var;
00105 }
00106
00112 QString CodeParameter::getInitialValue ( ) {
00113 return m_initialValue;
00114 }
00115
00119 void CodeParameter::setComment ( CodeComment * object ) {
00120 m_comment = object;
00121 }
00122
00126 CodeComment * CodeParameter::getComment ( ) {
00127 return m_comment;
00128 }
00129
00130
00131 ClassifierCodeDocument * CodeParameter::getParentDocument ( ) {
00132 return m_parentDocument;
00133 }
00134
00138 UMLObject * CodeParameter::getParentObject ( ) {
00139 return m_parentObject;
00140 }
00141
00142
00143
00144 QString CodeParameter::getID () {
00145 UMLRole * role = dynamic_cast<UMLRole*>(m_parentObject);
00146 if(role)
00147 {
00148
00149
00150 UMLAssociation *assoc = role->getParentAssociation();
00151 return ID2STR(assoc->getID());
00152 } else
00153 return ID2STR(m_parentObject->getID());
00154
00155 }
00156
00157
00158
00159
00160 void CodeParameter::setAttributesOnNode ( QDomDocument & doc, QDomElement & blockElement)
00161 {
00162
00163
00164
00165 blockElement.setAttribute("parent_id",getID());
00166
00167
00168
00169
00170 UMLRole * role = dynamic_cast<UMLRole*>(m_parentObject);
00171 if(role)
00172 blockElement.setAttribute("role_id", role->getRole());
00173 else
00174 blockElement.setAttribute("role_id","-1");
00175
00176 blockElement.setAttribute("initialValue",getInitialValue());
00177
00178
00179 QDomElement commElement = doc.createElement( "header" );
00180 getComment()->saveToXMI(doc, commElement);
00181 blockElement.appendChild( commElement);
00182
00183 }
00184
00188 void CodeParameter::setAttributesFromNode ( QDomElement & root) {
00189
00190
00191 QString idStr = root.attribute("parent_id","-1");
00192 Uml::IDType id = STR2ID(idStr);
00193
00194
00195 m_parentObject->disconnect(this);
00196
00197
00198 UMLObject * obj = UMLApp::app()->getDocument()->findObjectById(id);
00199 if(obj)
00200 {
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 UMLAssociation * assoc = dynamic_cast<UMLAssociation*>(obj);
00213 if(assoc) {
00214
00215 UMLRole * role = 0;
00216 int role_id = root.attribute("role_id","-1").toInt();
00217 if(role_id == 1)
00218 role = assoc->getUMLRole(Uml::A);
00219 else if(role_id == 0)
00220 role = assoc->getUMLRole(Uml::B);
00221 else
00222 kError() << "corrupt save file? "
00223 << "cant get proper UMLRole for codeparameter uml id:"
00224 << ID2STR(id) << " w/role_id:" << role_id << endl;
00225
00226
00227 initFields ( m_parentDocument, role);
00228
00229 } else
00230 initFields ( m_parentDocument, obj);
00231
00232 } else
00233 kError() << "Cant load CodeParam: parentUMLObject w/id:"
00234 << ID2STR(id) << " not found, corrupt save file?" << endl;
00235
00236
00237 setInitialValue(root.attribute("initialValue",""));
00238
00239
00240
00241 QDomNode node = root.firstChild();
00242 QDomElement element = node.toElement();
00243 bool gotComment = false;
00244 while( !element.isNull() ) {
00245 QString tag = element.tagName();
00246 if( tag == "header" ) {
00247 QDomNode cnode = element.firstChild();
00248 QDomElement celem = cnode.toElement();
00249 getComment()->loadFromXMI(celem);
00250 gotComment = true;
00251 break;
00252 }
00253 node = element.nextSibling();
00254 element = node.toElement();
00255 }
00256
00257 if(!gotComment)
00258 kWarning()<<" loadFromXMI : Warning: unable to initialize CodeComment in codeparam:"<<this<<endl;
00259
00260
00261 }
00262
00267 void CodeParameter::syncToParent( ) {
00268
00269 getComment()->setText(getParentObject()->getDoc());
00270
00271 updateContent();
00272 }
00273
00274 void CodeParameter::initFields ( ClassifierCodeDocument * doc, UMLObject * obj) {
00275
00276 m_parentObject = obj;
00277
00278 m_parentDocument = doc;
00279 m_initialValue = QString("");
00280
00281 m_comment = CodeGenFactory::newCodeComment(m_parentDocument);
00282 m_comment->setText(getParentObject()->getDoc());
00283
00284 connect(m_parentObject,SIGNAL(modified()),this,SLOT(syncToParent()));
00285 }
00286
00287 #include "codeparameter.moc"
This file is part of the documentation for umbrello Version 3.1.0.