umbrello API Documentation

codeparameter.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2004-2007                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 /*  This code generated by:
00013  *      Author : thomas
00014  *      Date   : Fri Jun 20 2003
00015  */
00016 
00017 // own header
00018 #include "codeparameter.h"
00019 
00020 // qt/kde includes
00021 #include <kdebug.h>
00022 
00023 // local includes
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 // Constructors/Destructors
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 // Methods
00046 //
00047 
00048 
00049 // Accessor methods
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 // need to get the ID of the parent object
00143 // this is kind of broken for UMLRoles.
00144 QString CodeParameter::getID () {
00145     UMLRole * role = dynamic_cast<UMLRole*>(m_parentObject);
00146     if(role)
00147     {
00148         // cant use Role "ID" as that is used to distinquish if its
00149         // role "A" or "B"
00150         UMLAssociation *assoc = role->getParentAssociation();
00151         return ID2STR(assoc->getID());
00152     } else
00153         return ID2STR(m_parentObject->getID());
00154 
00155 }
00156 
00157 // Other methods
00158 //
00159 
00160 void CodeParameter::setAttributesOnNode ( QDomDocument & doc, QDomElement & blockElement)
00161 {
00162 
00163 
00164     // set local attributes
00165     blockElement.setAttribute("parent_id",getID());
00166 
00167     // setting ID's takes special treatment
00168     // as UMLRoles arent properly stored in the XMI right now.
00169     // (change would break the XMI format..save for big version change )
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     // a comment which we will store in its own separate child node block
00179     QDomElement commElement = doc.createElement( "header" );
00180     getComment()->saveToXMI(doc, commElement); // comment
00181     blockElement.appendChild( commElement);
00182 
00183 }
00184 
00188 void CodeParameter::setAttributesFromNode ( QDomElement & root) {
00189 
00190     // set local attributes, parent object first
00191     QString idStr = root.attribute("parent_id","-1");
00192     Uml::IDType id = STR2ID(idStr);
00193 
00194     // always disconnect
00195     m_parentObject->disconnect(this);
00196 
00197     // now, what is the new object we want to set?
00198     UMLObject * obj = UMLApp::app()->getDocument()->findObjectById(id);
00199     if(obj)
00200     {
00201 
00202         // FIX..one day.
00203         // Ugh. This is UGLY, but we have to do it this way because UMLRoles
00204         // don't go into the document list of UMLobjects, and have the same
00205         // ID as their parent UMLAssociations. So..the drill is then special
00206         // for Associations..in that case we need to find out which role will
00207         // serve as the parameter here. The REAL fix, of course, would be to
00208         // treat UMLRoles on a more even footing, but im not sure how that change
00209         // might ripple throughout the code and cause problems. Thus, since the
00210         // change appears to be needed for only this part, I'll do this crappy
00211         // change instead. -b.t.
00212         UMLAssociation * assoc = dynamic_cast<UMLAssociation*>(obj);
00213         if(assoc) {
00214             // In this case we init with indicated role child obj.
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             // init using UMLRole obj
00227             initFields ( m_parentDocument, role);
00228 
00229         } else
00230             initFields ( m_parentDocument, obj); // just the regular approach
00231 
00232     } else
00233         kError() << "Cant load CodeParam: parentUMLObject w/id:"
00234         << ID2STR(id) << " not found, corrupt save file?" << endl;
00235 
00236     // other attribs now
00237     setInitialValue(root.attribute("initialValue",""));
00238 
00239     // load comment now
00240     // by looking for our particular child element
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"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:55 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003