• 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
ownedcodeblock.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 "ownedcodeblock.h"
14 
15 // local includes
16 #include "association.h"
17 #include "classifier.h"
18 #include "debug_utils.h"
19 #include "umldoc.h"
20 #include "umlobject.h"
21 #include "umlrole.h"
22 #include "uml.h"
23 #include "textblock.h"
24 
28 OwnedCodeBlock::OwnedCodeBlock (UMLObject * parent)
29  : QObject (parent)
30 {
31  setObjectName("anOwnedCodeBlock");
32  initFields(parent);
33 }
34 
38 OwnedCodeBlock::~OwnedCodeBlock ()
39 {
40  /*
41  if (m_parentObject) {
42  m_parentObject->disconnect(this);
43  }
44  */
45 }
46 
52 void OwnedCodeBlock::release ()
53 {
54  if (m_parentObject) {
55  m_parentObject->disconnect(this);
56  }
57  m_parentObject = 0;
58 }
59 
64 UMLObject * OwnedCodeBlock::getParentObject ()
65 {
66  return m_parentObject;
67 }
68 
72 void OwnedCodeBlock::setAttributesFromObject (TextBlock * obj)
73 {
74  OwnedCodeBlock * oc = dynamic_cast<OwnedCodeBlock*>(obj);
75  if (oc) {
76  m_parentObject->disconnect(this);
77  initFields(oc->getParentObject());
78  }
79 }
80 
81 void OwnedCodeBlock::setAttributesOnNode(QDomDocument& /*doc*/, QDomElement& elem)
82 {
83  // set local class attributes
84  // setting ID's takes special treatment
85  // as UMLRoles arent properly stored in the XMI right now.
86  // (change would break the XMI format..save for big version change)
87  UMLRole * role = dynamic_cast<UMLRole*>(m_parentObject);
88  if (role) {
89  elem.setAttribute("parent_id", Uml::ID::toString(role->parentAssociation()->id()));
90  // CAUTION: role_id here is numerically inverted wrt Uml::Role_Type,
91  // i.e. role A is 1 and role B is 0.
92  // I'll resist the temptation to change this -
93  // in order to maintain backward compatibility.
94  elem.setAttribute("role_id", (role->role() == Uml::RoleType::A));
95  }
96  else {
97  elem.setAttribute("parent_id", Uml::ID::toString(m_parentObject->id()));
98  //elem.setAttribute("role_id","-1");
99  }
100 }
101 
106 void OwnedCodeBlock::setAttributesFromNode (QDomElement & elem)
107 {
108  // set local attributes, parent object first
109  QString idStr = elem.attribute("parent_id","-1");
110  Uml::ID::Type id = Uml::ID::fromString(idStr);
111 
112  // always disconnect from current parent
113  getParentObject()->disconnect(this);
114 
115  // now, what is the new object we want to set?
116  UMLObject * obj = UMLApp::app()->document()->findObjectById(id);
117  if (obj) {
118  // FIX..one day.
119  // Ugh. This is UGLY, but we have to do it this way because UMLRoles
120  // don't go into the document list of UMLobjects, and have the same
121  // ID as their parent UMLAssociations. So..the drill is then special
122  // for Associations..in that case we need to find out which role will
123  // serve as the parametger here. The REAL fix, of course, would be to
124  // treat UMLRoles on a more even footing, but im not sure how that change
125  // might ripple throughout the code and cause problems. Thus, since the
126  // change appears to be needed for only this part, I'll do this crappy
127  // change instead. -b.t.
128  UMLAssociation * assoc = dynamic_cast<UMLAssociation*>(obj);
129  if (assoc) {
130  // In this case we init with indicated role child obj.
131  UMLRole * role = 0;
132  int role_id = elem.attribute("role_id","-1").toInt();
133  // see comment on role_id at setAttributesOnNode()
134  if (role_id == 1)
135  role = assoc->getUMLRole(Uml::RoleType::A);
136  else if (role_id == 0)
137  role = assoc->getUMLRole(Uml::RoleType::B);
138  else // this will cause a crash
139  uError() << "corrupt save file? "
140  << "cant get proper UMLRole for ownedcodeblock uml id:"
141  << Uml::ID::toString(id) << " w/role_id:" << role_id;
142 
143  // init using UMLRole obj
144  initFields (role);
145  }
146  else
147  initFields (obj); // just the regular approach
148  }
149  else
150  uError() << "ERROR: can not load ownedcodeblock: parentUMLObject w/id:"
151  << Uml::ID::toString(id) << " not found, corrupt save file?";
152 }
153 
154 void OwnedCodeBlock::initFields(UMLObject * parent)
155 {
156  m_parentObject = parent;
157 
158  // one reason for being: set up the connection between
159  // this code block and the parent UMLObject..when the parent
160  // signals a change has been made, we automatically update
161  // ourselves
162  connect(m_parentObject, SIGNAL(modified()), this, SLOT(syncToParent()));
163 }
164 
165 void OwnedCodeBlock::syncToParent()
166 {
167  updateContent();
168 }
169 
170 #include "ownedcodeblock.moc"
OwnedCodeBlock::syncToParent
virtual void syncToParent()
Definition: ownedcodeblock.cpp:165
OwnedCodeBlock::release
virtual void release()
Causes the text block to release all of its connections and any other text blocks that it 'owns'...
Definition: ownedcodeblock.cpp:52
umlobject.h
OwnedCodeBlock::getParentObject
UMLObject * getParentObject()
Get the value of m_parentObject.
Definition: ownedcodeblock.cpp:64
association.h
OwnedCodeBlock::OwnedCodeBlock
OwnedCodeBlock(UMLObject *parent)
Constructor.
Definition: ownedcodeblock.cpp:28
Uml::RoleType::A
Definition: basictypes.h:209
OwnedCodeBlock::setAttributesOnNode
virtual void setAttributesOnNode(QDomDocument &doc, QDomElement &blockElement)
Definition: ownedcodeblock.cpp:81
UMLRole::parentAssociation
UMLAssociation * parentAssociation() const
Definition: umlrole.cpp:67
umlrole.h
Uml::RoleType::B
Definition: basictypes.h:210
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:206
classifier.h
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
textblock.h
OwnedCodeBlock::~OwnedCodeBlock
virtual ~OwnedCodeBlock()
Empty Destructor.
Definition: ownedcodeblock.cpp:38
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
OwnedCodeBlock
Describes any codeblock which is 'owned' by a UMLobject of some sort and should be in sync with that ...
Definition: ownedcodeblock.h:26
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
OwnedCodeBlock::updateContent
virtual void updateContent()=0
Uml::ID::toString
QString toString(const ID::Type &id)
Definition: basictypes.cpp:1048
UMLDoc::findObjectById
UMLObject * findObjectById(Uml::ID::Type id)
Used to find a reference to a UMLObject by its ID.
Definition: umldoc.cpp:766
umldoc.h
TextBlock
The fundemental unit of text within an output file containing code.
Definition: textblock.h:24
ownedcodeblock.h
OwnedCodeBlock::setAttributesFromNode
virtual void setAttributesFromNode(QDomElement &element)
Set the class attributes of this object from the passed element node.
Definition: ownedcodeblock.cpp:106
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
uError
#define uError()
Definition: debug_utils.h:96
Uml::ID::fromString
ID::Type fromString(const QString &id)
Definition: basictypes.cpp:1053
OwnedCodeBlock::setAttributesFromObject
virtual void setAttributesFromObject(TextBlock *obj)
Set the class attributes from a passed object.
Definition: ownedcodeblock.cpp:72
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:06:00 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