umbrello API Documentation

ownedcodeblock.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 Aug 19 2003
00015  */
00016 
00017 // own header
00018 #include "ownedcodeblock.h"
00019 
00020 // qt/kde includes
00021 #include <kdebug.h>
00022 
00023 // local includes
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 // Constructors/Destructors
00035 //
00036 
00037 OwnedCodeBlock::OwnedCodeBlock ( UMLObject * parent )
00038         : QObject ( (QObject*)parent, "anOwnedCodeBlock" )
00039 {
00040     initFields(parent);
00041 }
00042 
00043 OwnedCodeBlock::~OwnedCodeBlock ( ) {
00044     /*
00045         if(m_parentObject)
00046                 m_parentObject->disconnect(this);
00047     */
00048 }
00049 
00050 //
00051 // Methods
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 // Other methods
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& /*doc*/, QDomElement& elem) {
00085 
00086     // set local class attributes
00087     // setting ID's takes special treatment
00088     // as UMLRoles arent properly stored in the XMI right now.
00089     // (change would break the XMI format..save for big version change )
00090     UMLRole * role = dynamic_cast<UMLRole*>(m_parentObject);
00091     if(role)
00092     {
00093         elem.setAttribute("parent_id",ID2STR(role->getParentAssociation()->getID()));
00094         // CAUTION: role_id here is numerically inverted wrt Uml::Role_Type,
00095         //          i.e. role A is 1 and role B is 0.
00096         //          I'll resist the temptation to change this -
00097         //          in order to maintain backward compatibility.
00098         elem.setAttribute("role_id", (role->getRole() == Uml::A));
00099     }
00100     else
00101     {
00102         elem.setAttribute("parent_id",ID2STR(m_parentObject->getID()));
00103         //elem.setAttribute("role_id","-1");
00104     }
00105 
00106 }
00107 
00111 void OwnedCodeBlock::setAttributesFromNode ( QDomElement & elem) {
00112 
00113     // set local attributes, parent object first
00114     QString idStr = elem.attribute("parent_id","-1");
00115     Uml::IDType id = STR2ID(idStr);
00116 
00117     // always disconnect from current parent
00118     getParentObject()->disconnect(this);
00119 
00120     // now, what is the new object we want to set?
00121     UMLObject * obj = UMLApp::app()->getDocument()->findObjectById(id);
00122     if(obj)
00123     {
00124 
00125         // FIX..one day.
00126         // Ugh. This is UGLY, but we have to do it this way because UMLRoles
00127         // don't go into the document list of UMLobjects, and have the same
00128         // ID as their parent UMLAssociations. So..the drill is then special
00129         // for Associations..in that case we need to find out which role will
00130         // serve as the parametger here. The REAL fix, of course, would be to
00131         // treat UMLRoles on a more even footing, but im not sure how that change
00132         // might ripple throughout the code and cause problems. Thus, since the
00133         // change appears to be needed for only this part, I'll do this crappy
00134         // change instead. -b.t.
00135         UMLAssociation * assoc = dynamic_cast<UMLAssociation*>(obj);
00136         if(assoc) {
00137             // In this case we init with indicated role child obj.
00138             UMLRole * role = 0;
00139             int role_id = elem.attribute("role_id","-1").toInt();
00140             // see comment on role_id at setAttributesOnNode()
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 // this will cause a crash
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             // init using UMLRole obj
00151             initFields ( role );
00152         } else
00153             initFields ( obj); // just the regular approach
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     // one reason for being: set up the connection between
00168     // this code block and the parent UMLObject..when the parent
00169     // signals a change has been made, we automatically update
00170     // ourselves
00171     connect(m_parentObject, SIGNAL(modified()), this, SLOT(syncToParent()));
00172 }
00173 
00176 void OwnedCodeBlock::syncToParent ( ) {
00177     updateContent();
00178 }
00179 
00180 #include "ownedcodeblock.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:58 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003