• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

umbrello/umbrello

  • sources
  • kde-4.12
  • kdesdk
  • umbrello
  • umbrello
  • codegenerators
codeparameter.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * This program is free software; you can redistribute it and/or modify *
3  * it under the terms of the GNU General Public License as published by *
4  * the Free Software Foundation; either version 2 of the License, or *
5  * (at your option) any later version. *
6  * *
7  * copyright (C) 2003 Brian Thomas <thomas@mail630.gsfc.nasa.gov> *
8  * copyright (C) 2004-2013 *
9  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
10  ***************************************************************************/
11 
12 // own header
13 #include "codeparameter.h"
14 
15 // local includes
16 #include "association.h"
17 #include "attribute.h"
18 #include "classifiercodedocument.h"
19 #include "debug_utils.h"
20 #include "umldoc.h"
21 #include "umlobject.h"
22 #include "umlrole.h"
23 #include "uml.h"
24 #include "codegenfactory.h"
25 
29 CodeParameter::CodeParameter(ClassifierCodeDocument * parentDoc, UMLObject * parentObject)
30  : QObject(parentObject)
31 {
32  setObjectName("ACodeParam");
33  initFields(parentDoc, parentObject);
34 }
35 
39 CodeParameter::~CodeParameter()
40 {
41 }
42 
47 bool CodeParameter::getAbstract()
48 {
49  return m_parentObject->isAbstract();
50 }
51 
57 bool CodeParameter::getStatic()
58 {
59  return m_parentObject->isStatic();
60 }
61 
67 QString CodeParameter::getName() const
68 {
69  return m_parentObject->name();
70 }
71 
78 QString CodeParameter::getTypeName()
79 {
80  UMLAttribute * at = (UMLAttribute*) m_parentObject;
81  return at->getTypeName();
82 }
83 
89 Uml::Visibility::Enum CodeParameter::getVisibility() const
90 {
91  return m_parentObject->visibility();
92 }
93 
99 void CodeParameter::setInitialValue(const QString &new_var)
100 {
101  m_initialValue = new_var;
102 }
103 
109 QString CodeParameter::getInitialValue()
110 {
111  return m_initialValue;
112 }
113 
117 void CodeParameter::setComment(CodeComment * object)
118 {
119  m_comment = object;
120 }
121 
125 CodeComment * CodeParameter::getComment()
126 {
127  return m_comment;
128 }
129 
133 ClassifierCodeDocument * CodeParameter::getParentDocument()
134 {
135  return m_parentDocument;
136 }
137 
141 UMLObject * CodeParameter::getParentObject()
142 {
143  return m_parentObject;
144 }
145 
146 // need to get the ID of the parent object
147 // this is kind of broken for UMLRoles.
148 QString CodeParameter::ID()
149 {
150  UMLRole * role = dynamic_cast<UMLRole*>(m_parentObject);
151  if(role)
152  {
153  // cant use Role "ID" as that is used to distinquish if its
154  // role "A" or "B"
155  UMLAssociation *assoc = role->parentAssociation();
156  return Uml::ID::toString(assoc->id());
157  } else
158  return Uml::ID::toString(m_parentObject->id());
159 
160 }
161 
166 void CodeParameter::setAttributesOnNode(QDomDocument & doc, QDomElement & blockElement)
167 {
168  // set local attributes
169  blockElement.setAttribute("parent_id", ID());
170 
171  // setting ID's takes special treatment
172  // as UMLRoles arent properly stored in the XMI right now.
173  // (change would break the XMI format..save for big version change)
174  UMLRole * role = dynamic_cast<UMLRole*>(m_parentObject);
175  if(role)
176  blockElement.setAttribute("role_id", role->role());
177  else
178  blockElement.setAttribute("role_id","-1");
179 
180  blockElement.setAttribute("initialValue", getInitialValue());
181 
182  // a comment which we will store in its own separate child node block
183  QDomElement commElement = doc.createElement("header");
184  getComment()->saveToXMI(doc, commElement); // comment
185  blockElement.appendChild(commElement);
186 }
187 
192 void CodeParameter::setAttributesFromNode(QDomElement & root)
193 {
194  // set local attributes, parent object first
195  QString idStr = root.attribute("parent_id","-1");
196  Uml::ID::Type id = Uml::ID::fromString(idStr);
197 
198  // always disconnect
199  m_parentObject->disconnect(this);
200 
201  // now, what is the new object we want to set?
202  UMLObject * obj = UMLApp::app()->document()->findObjectById(id);
203  if(obj)
204  {
205  // FIX..one day.
206  // Ugh. This is UGLY, but we have to do it this way because UMLRoles
207  // don't go into the document list of UMLobjects, and have the same
208  // ID as their parent UMLAssociations. So..the drill is then special
209  // for Associations..in that case we need to find out which role will
210  // serve as the parameter here. The REAL fix, of course, would be to
211  // treat UMLRoles on a more even footing, but im not sure how that change
212  // might ripple throughout the code and cause problems. Thus, since the
213  // change appears to be needed for only this part, I'll do this crappy
214  // change instead. -b.t.
215  UMLAssociation * assoc = dynamic_cast<UMLAssociation*>(obj);
216  if(assoc) {
217  // In this case we init with indicated role child obj.
218  UMLRole * role = 0;
219  int role_id = root.attribute("role_id","-1").toInt();
220  if(role_id == 1)
221  role = assoc->getUMLRole(Uml::RoleType::A);
222  else if(role_id == 0)
223  role = assoc->getUMLRole(Uml::RoleType::B);
224  else
225  uError() << "corrupt save file? "
226  << "cant get proper UMLRole for codeparameter uml id:"
227  << Uml::ID::toString(id) << " w/role_id:" << role_id;
228 
229  // init using UMLRole obj
230  initFields (m_parentDocument, role);
231 
232  } else
233  initFields (m_parentDocument, obj); // just the regular approach
234 
235  } else
236  uError() << "Cant load CodeParam: parentUMLObject w/id:"
237  << Uml::ID::toString(id) << " not found, corrupt save file?";
238 
239  // other attribs now
240  setInitialValue(root.attribute("initialValue",""));
241 
242  // load comment now
243  // by looking for our particular child element
244  QDomNode node = root.firstChild();
245  QDomElement element = node.toElement();
246  bool gotComment = false;
247  while(!element.isNull()) {
248  QString tag = element.tagName();
249  if(tag == "header") {
250  QDomNode cnode = element.firstChild();
251  QDomElement celem = cnode.toElement();
252  getComment()->loadFromXMI(celem);
253  gotComment = true;
254  break;
255  }
256  node = element.nextSibling();
257  element = node.toElement();
258  }
259 
260  if(!gotComment)
261  uWarning()<<" loadFromXMI : Warning: unable to initialize CodeComment in codeparam:"<<this;
262 }
263 
268 void CodeParameter::syncToParent()
269 {
270  getComment()->setText(getParentObject()->doc());
271 
272  updateContent();
273 }
274 
275 void CodeParameter::initFields(ClassifierCodeDocument * doc, UMLObject * obj)
276 {
277  m_parentObject = obj;
278 
279  m_parentDocument = doc;
280  m_initialValue.clear();
281 
282  m_comment = CodeGenFactory::newCodeComment(m_parentDocument);
283  m_comment->setText(getParentObject()->doc());
284 
285  connect(m_parentObject, SIGNAL(modified()), this, SLOT(syncToParent()));
286 }
287 
288 #include "codeparameter.moc"
umlobject.h
CodeParameter::CodeParameter
CodeParameter(ClassifierCodeDocument *doc, UMLObject *parentObj)
Constructor.
Definition: codeparameter.cpp:29
association.h
ClassifierCodeDocument
class ClassifierCodeDocument A CodeDocument which represents a UMLClassifier (e.g.
Definition: classifiercodedocument.h:33
Uml::RoleType::A
Definition: basictypes.h:209
Uml::Visibility::Enum
Enum
Definition: basictypes.h:56
CodeComment::loadFromXMI
virtual void loadFromXMI(QDomElement &root)
Load params from the appropriate XMI element node.
Definition: codecomment.cpp:42
UMLObject::visibility
Uml::Visibility::Enum visibility() const
Returns the visibility of the object.
Definition: umlobject.cpp:435
UMLRole::parentAssociation
UMLAssociation * parentAssociation() const
Definition: umlrole.cpp:67
TextBlock::setText
void setText(const QString &text)
Set the value of m_text The actual text of this code block.
Definition: textblock.cpp:80
umlrole.h
CodeParameter::setInitialValue
virtual void setInitialValue(const QString &new_var)
Set the value of m_initialValue.
Definition: codeparameter.cpp:99
CodeParameter::getName
QString getName() const
Utility method to get the value of parent object name The name of this code parameter.
Definition: codeparameter.cpp:67
CodeParameter::syncToParent
void syncToParent()
Create the string representation of this code parameter.
Definition: codeparameter.cpp:268
Uml::RoleType::B
Definition: basictypes.h:210
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:206
CodeParameter::getAbstract
bool getAbstract()
Utility method to get the value of parent object abstract value.
Definition: codeparameter.cpp:47
UMLAttribute
This class is used to set up information for an attribute.
Definition: attribute.h:27
uWarning
#define uWarning()
Definition: debug_utils.h:97
CodeParameter::ID
QString ID()
Definition: codeparameter.cpp:148
QObject
UMLApp::document
UMLDoc * document() const
Returns a pointer to the current document connected to the KMainWindow instance.
Definition: uml.cpp:872
debug_utils.h
CodeParameter::getParentDocument
ClassifierCodeDocument * getParentDocument()
Get the parent Code Document.
Definition: codeparameter.cpp:133
UMLObject
This class is the non-graphical version of UMLWidget.
Definition: umlobject.h:41
UMLAssociation
This class contains the non-graphic representation of an association.
Definition: association.h:32
CodeParameter::getInitialValue
virtual QString getInitialValue()
Get the value of m_initialValue The initial value of this code parameter.
Definition: codeparameter.cpp:109
codeparameter.h
attribute.h
codegenfactory.h
CodeGenFactory::newCodeComment
CodeComment * newCodeComment(CodeDocument *cd)
Definition: codegenfactory.cpp:402
CodeComment::saveToXMI
virtual void saveToXMI(QDomDocument &doc, QDomElement &root)
Save the XMI representation of this object.
Definition: codecomment.cpp:31
UMLAssociation::getUMLRole
UMLRole * getUMLRole(Uml::RoleType::Enum role) const
Get the underlying UMLRole object for the given role.
Definition: association.cpp:563
Uml::ID::Type
std::string Type
Definition: basictypes.h:317
CodeParameter::updateContent
virtual void updateContent()=0
CodeParameter::setComment
void setComment(CodeComment *comment)
Set a Comment object.
Definition: codeparameter.cpp:117
CodeParameter::getComment
CodeComment * getComment()
Get the Comment on this object.
Definition: codeparameter.cpp:125
Uml::ID::toString
QString toString(const ID::Type &id)
Definition: basictypes.cpp:1048
CodeParameter::setAttributesFromNode
virtual void setAttributesFromNode(QDomElement &element)
Set the class attributes of this object from the passed element node.
Definition: codeparameter.cpp:192
CodeParameter::setAttributesOnNode
virtual void setAttributesOnNode(QDomDocument &doc, QDomElement &blockElement)
Set attributes of the node that represents this class in the XMI document.
Definition: codeparameter.cpp:166
UMLDoc::findObjectById
UMLObject * findObjectById(Uml::ID::Type id)
Used to find a reference to a UMLObject by its ID.
Definition: umldoc.cpp:766
UMLObject::isStatic
bool isStatic() const
Returns true if this UMLObject has classifier scope, otherwise false (the default).
Definition: umlobject.cpp:335
umldoc.h
CodeParameter::getVisibility
Uml::Visibility::Enum getVisibility() const
Utility method to get the value of parent object scope.
Definition: codeparameter.cpp:89
CodeParameter::getTypeName
virtual QString getTypeName()
Utility method to get the value of parent object type.
Definition: codeparameter.cpp:78
UMLRole
This class contains the non-graphic representation of an association role.
Definition: umlrole.h:24
UMLRole::role
Uml::RoleType::Enum role() const
Get the 'id' of the role (NOT the parent object).
Definition: umlrole.cpp:152
CodeParameter::~CodeParameter
virtual ~CodeParameter()
Destructor.
Definition: codeparameter.cpp:39
uError
#define uError()
Definition: debug_utils.h:96
UMLObject::name
QString name() const
Returns a copy of m_name.
Definition: umlobject.cpp:185
UMLObject::isAbstract
bool isAbstract() const
Returns the abstract state of the object.
Definition: umlobject.cpp:312
Uml::ID::fromString
ID::Type fromString(const QString &id)
Definition: basictypes.cpp:1053
classifiercodedocument.h
CodeComment
Text which will be comments.
Definition: codecomment.h:23
CodeParameter::getStatic
bool getStatic()
Utility method to get the value of parent object static Whether or not this is static.
Definition: codeparameter.cpp:57
UMLClassifierListItem::getTypeName
virtual QString getTypeName() const
Returns the type name of the UMLClassifierListItem.
Definition: classifierlistitem.cpp:110
CodeParameter::getParentObject
UMLObject * getParentObject()
Get the ParentObject object.
Definition: codeparameter.cpp:141
uml.h
UMLObject::id
virtual Uml::ID::Type id() const
Returns the ID of the object.
Definition: umlobject.cpp:394
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:05:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

umbrello/umbrello

Skip menu "umbrello/umbrello"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal