umbrello API Documentation

codeaccessormethod.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   : Tue Jul 1 2003
00015  */
00016 
00017 // own header
00018 #include "codeaccessormethod.h"
00019 
00020 // qt/kde includes
00021 #include <kdebug.h>
00022 
00023 // local includes
00024 #include "classifiercodedocument.h"
00025 #include "codeclassfield.h"
00026 #include "attribute.h"
00027 #include "umlobject.h"
00028 #include "umlrole.h"
00029 
00030 // Constructors/Destructors
00031 //
00032 
00033 CodeAccessorMethod::CodeAccessorMethod ( CodeClassField * parentCF )
00034         : CodeMethodBlock ( parentCF->getParentDocument(), parentCF->getParentObject() )
00035 {
00036     initFields(parentCF);
00037 }
00038 
00039 CodeAccessorMethod::~CodeAccessorMethod ( ) { }
00040 
00041 //
00042 // Methods
00043 //
00044 
00045 
00046 // Accessor methods
00047 //
00048 
00053 CodeClassField * CodeAccessorMethod::getParentClassField ( ) {
00054     return m_parentclassfield;
00055 }
00056 
00057 bool CodeAccessorMethod::parentIsAttribute( ) {
00058     return getParentClassField()->parentIsAttribute();
00059 }
00060 
00065 /*
00066 UMLObject * CodeAccessorMethod::getParentObject ( ) {
00067     return getParentClassField()->getParentObject();
00068 }
00069 */
00070 
00073 CodeAccessorMethod::AccessorType CodeAccessorMethod::getType( ) {
00074     return m_accessorType;
00075 }
00076 
00079 void CodeAccessorMethod::setType ( CodeAccessorMethod::AccessorType atype) {
00080     m_accessorType = atype;
00081 }
00082 
00083 // Other methods
00084 //
00085 
00086 
00087 // this type of textblock is special
00088 // we DON'T release it when resetTextBlocks is
00089 // called because we re-use it over and over
00090 // until the codeclassfield is released.
00091 void CodeAccessorMethod::release () {
00092     // do nothing
00093 }
00094 
00095 // ok, a method so the parent can force it to release
00096 void CodeAccessorMethod::forceRelease () {
00097     if(m_parentclassfield)
00098         m_parentclassfield->disconnect(this);
00099     CodeMethodBlock::release();
00100 }
00101 
00105 void CodeAccessorMethod::loadFromXMI ( QDomElement & root ) {
00106     setAttributesFromNode(root);
00107 }
00108 
00112 void CodeAccessorMethod::saveToXMI ( QDomDocument & doc, QDomElement & root ) {
00113     QDomElement docElement = doc.createElement( "codeaccessormethod" );
00114 
00115     setAttributesOnNode(doc, docElement);
00116 
00117     root.appendChild( docElement );
00118 }
00119 
00123 void CodeAccessorMethod::setAttributesOnNode ( QDomDocument & doc, QDomElement & elem)
00124 {
00125 
00126     // set super-class attributes
00127     CodeMethodBlock::setAttributesOnNode(doc, elem);
00128 
00129     // set local class attributes
00130     elem.setAttribute("accessType",getType());
00131     elem.setAttribute("classfield_id",getParentClassField()->getID());
00132 
00133 }
00134 
00138 void CodeAccessorMethod::setAttributesFromNode ( QDomElement & root) {
00139 
00140     // set attributes from the XMI
00141     CodeMethodBlock::setAttributesFromNode(root); // superclass load
00142 
00143     /*
00144         // I don't believe this is needed for a load from XMI. We never delete
00145         // accessor methods from the parent classfield.. they are essentially
00146         // in composition with the parent class and are arent meant to be out
00147         // on their own. Well, this is fine for now, but IF we start allowing
00148         // clipping and pasting of these methods between classes/ classfields
00149         // then we may have problems (ugh.. I cant imagine allowing this, but
00150         // perhaps someone will see a need to allow it. -b.t.)
00151         QString id = root.attribute("classfield_id","-1");
00152         CodeClassField * newCF = 0;
00153         ClassifierCodeDocument * cdoc = dynamic_cast<ClassifierCodeDocument*>(getParentDocument());
00154         if(cdoc)
00155                 newCF = cdoc->findCodeClassFieldFromParentID (STR2ID(id));
00156 
00157         m_parentclassfield->disconnect(this); // always disconnect
00158         if(newCF)
00159                 initFields(newCF);
00160         else
00161                 kError()<<"ERROR: code accessor method cant load parent codeclassfield, corrupt file?"<<endl;
00162 
00163     */
00164     // now load/set other local attributes
00165     setType((AccessorType) root.attribute("accessType","0").toInt());
00166 
00167 }
00168 
00169 void CodeAccessorMethod::setAttributesFromObject(TextBlock * obj)
00170 {
00171 
00172     CodeMethodBlock::setAttributesFromObject(obj);
00173 
00174     CodeAccessorMethod * mb = dynamic_cast<CodeAccessorMethod*>(obj);
00175     if(mb)
00176     {
00177         m_parentclassfield->disconnect(this); // always disconnect
00178 
00179         initFields(mb->getParentClassField());
00180 
00181         setType(mb->getType());
00182     }
00183 
00184 }
00185 
00186 void CodeAccessorMethod::initFields(CodeClassField * parentClassField ) {
00187 
00188     m_parentclassfield = parentClassField;
00189     m_accessorType = GET;
00190     m_canDelete = false; // we cant delete these with the codeeditor, delete the UML operation instead.
00191 
00192     connect(m_parentclassfield,SIGNAL(modified()),this,SLOT(syncToParent()));
00193 }
00194 
00195 #include "codeaccessormethod.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