• 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
codemethodblock.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 #include "codemethodblock.h"
13 
14 #include "codeclassfield.h"
15 #include "classifiercodedocument.h"
16 #include "codegenerationpolicy.h"
17 #include "uml.h"
18 
19 CodeMethodBlock::CodeMethodBlock(ClassifierCodeDocument * doc, UMLObject * parentObj, const QString & body, const QString & comment)
20  : OwnedCodeBlock (parentObj), CodeBlockWithComments ((CodeDocument*)doc, body, comment)
21 {
22  m_startMethod.clear();
23  m_endMethod.clear();
24 }
25 
26 CodeMethodBlock::~CodeMethodBlock()
27 {
28 }
29 
33 CodeDocument * CodeMethodBlock::getParentDocument()
34 {
35  // we can just call the superclass
36  return TextBlock::getParentDocument();
37 }
38 
42 QString CodeMethodBlock::getStartMethodText() const
43 {
44  return m_startMethod;
45 }
46 
50 QString CodeMethodBlock::getEndMethodText() const
51 {
52  return m_endMethod;
53 }
54 
58 void CodeMethodBlock::setStartMethodText (const QString &value)
59 {
60  m_startMethod = value;
61 }
62 
66 void CodeMethodBlock::setEndMethodText(const QString &value)
67 {
68  m_endMethod = value;
69 }
70 
76 void CodeMethodBlock::release ()
77 {
78  // just call super-class versions
79  OwnedCodeBlock::release();
80  TextBlock::release();
81 }
82 
87 void CodeMethodBlock::setAttributesOnNode(QDomDocument & doc, QDomElement & elem)
88 {
89  // set super-class attributes
90  CodeBlockWithComments::setAttributesOnNode(doc, elem);
91  OwnedCodeBlock::setAttributesOnNode(doc, elem);
92 
93  // set local class attributes
94  if (contentType() != AutoGenerated)
95  {
96  QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars();
97  elem.setAttribute("startMethodText", encodeText(getStartMethodText(), endLine));
98  elem.setAttribute("endMethodText", encodeText(getEndMethodText(), endLine));
99  }
100 }
101 
106 void CodeMethodBlock::setAttributesFromNode(QDomElement & elem)
107 {
108  // set attributes from the XMI
109  CodeBlockWithComments::setAttributesFromNode(elem); // superclass load
110  OwnedCodeBlock::setAttributesFromNode(elem); // superclass load
111 
112  // now load local attributes
113  if (contentType() != AutoGenerated)
114  {
115  QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars();
116  setStartMethodText(decodeText(elem.attribute("startMethodText",""), endLine));
117  setEndMethodText(decodeText(elem.attribute("endMethodText",""), endLine));
118  }
119 }
120 
124 void CodeMethodBlock::setAttributesFromObject(TextBlock * obj)
125 {
126  CodeBlockWithComments::setAttributesFromObject(obj);
127 
128  CodeMethodBlock * mb = dynamic_cast<CodeMethodBlock*>(obj);
129  if (mb)
130  {
131  setStartMethodText(mb->getStartMethodText());
132  setEndMethodText(mb->getEndMethodText());
133  }
134 }
135 
139 QString CodeMethodBlock::toString() const
140 {
141  QString string;
142 
143  if (getWriteOutText()) {
144  QString indent = getIndentationString();
145  QString bodyIndent = getIndentationString(getIndentationLevel()+1);
146  QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars();
147 
148  QString startMethod = formatMultiLineText (getStartMethodText(), indent, endLine);
149  QString body = formatMultiLineText (getText(), bodyIndent, endLine);
150  QString endMethod = formatMultiLineText(getEndMethodText(), indent, endLine);
151 
152  QString comment = getComment()->toString();
153  if (!comment.isEmpty() && getComment()->getWriteOutText())
154  string.append(comment);
155 
156  if (!startMethod.isEmpty())
157  string.append(startMethod);
158 
159  if (!body.isEmpty())
160  string.append(body);
161 
162  if (!endMethod.isEmpty())
163  string.append(endMethod);
164 
165  }
166  return string;
167 }
168 
169 void CodeMethodBlock::syncToParent()
170 {
171  getComment()->setText(getParentObject()->doc());
172 
173  updateMethodDeclaration();
174 
175  // only update IF we are NOT AutoGenerated
176  if (contentType() != AutoGenerated)
177  return;
178 
179  updateContent();
180 }
181 
182 #include "codemethodblock.moc"
CodeMethodBlock::toString
virtual QString toString() const
Definition: codemethodblock.cpp:139
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
OwnedCodeBlock::getParentObject
UMLObject * getParentObject()
Get the value of m_parentObject.
Definition: ownedcodeblock.cpp:64
CodeMethodBlock::setEndMethodText
void setEndMethodText(const QString &value)
Set the ending text that finishes this method after the body is printed.
Definition: codemethodblock.cpp:66
CodeMethodBlock::setStartMethodText
void setStartMethodText(const QString &value)
Set the starting text that begins this method before the body is printed.
Definition: codemethodblock.cpp:58
CodeBlockWithComments::getComment
CodeComment * getComment() const
Get the Comment object.
Definition: codeblockwithcomments.cpp:46
ClassifierCodeDocument
class ClassifierCodeDocument A CodeDocument which represents a UMLClassifier (e.g.
Definition: classifiercodedocument.h:33
OwnedCodeBlock::setAttributesOnNode
virtual void setAttributesOnNode(QDomDocument &doc, QDomElement &blockElement)
Definition: ownedcodeblock.cpp:81
CodeBlockWithComments::setAttributesFromObject
virtual void setAttributesFromObject(TextBlock *obj)
Set the class attributes from a passed object.
Definition: codeblockwithcomments.cpp:83
CodeBlockWithComments::setAttributesOnNode
virtual void setAttributesOnNode(QDomDocument &doc, QDomElement &blockElement)
Set attributes of the node that represents this class in the XMI document.
Definition: codeblockwithcomments.cpp:68
TextBlock::setText
void setText(const QString &text)
Set the value of m_text The actual text of this code block.
Definition: textblock.cpp:80
CodeBlock::AutoGenerated
the content was generated by code generation itself
Definition: codeblock.h:28
CodeGenerationPolicy::getNewLineEndingChars
QString getNewLineEndingChars() const
Utility function to get the actual characters.
Definition: codegenerationpolicy.cpp:248
CodeMethodBlock::release
virtual void release()
Causes the text block to release all of its connections and any other text blocks that it 'owns'...
Definition: codemethodblock.cpp:76
CodeMethodBlock::updateContent
virtual void updateContent()=0
This is the method called from within syncToparent() to update the body of the method.
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:206
CodeMethodBlock::getStartMethodText
QString getStartMethodText() const
Get the starting text that begins this method before the body is printed.
Definition: codemethodblock.cpp:42
CodeBlock::contentType
ContentType contentType() const
Get the value of m_contentType specifies whether the content (text) of this object was generated by t...
Definition: codeblock.cpp:54
TextBlock::getIndentationLevel
int getIndentationLevel() const
Get how many times to indent this text block.
Definition: textblock.cpp:163
CodeMethodBlock::updateMethodDeclaration
virtual void updateMethodDeclaration()=0
This is the method called from within syncToparent().
codegenerationpolicy.h
UMLObject
This class is the non-graphical version of UMLWidget.
Definition: umlobject.h:41
CodeBlockWithComments
class CodeBlockWithComments A very common type of text block in any type of code. ...
Definition: codeblockwithcomments.h:24
CodeMethodBlock
class CodeMethodBlock A common type of "code block" that occurs in OO code.
Definition: codemethodblock.h:28
CodeDocument
A document containing the code for one file.
Definition: codedocument.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
codemethodblock.h
codeclassfield.h
CodeBlockWithComments::setAttributesFromNode
virtual void setAttributesFromNode(QDomElement &element)
Set the class attributes of this object from the passed element node.
Definition: codeblockwithcomments.cpp:105
CodeMethodBlock::getParentDocument
CodeDocument * getParentDocument()
Get the parent code document.
Definition: codemethodblock.cpp:33
UMLApp::commonPolicy
CodeGenerationPolicy * commonPolicy() const
Returns the default code generation policy.
Definition: uml.cpp:2132
TextBlock::toString
virtual QString toString() const
Return the text in the right format.
Definition: textblock.cpp:404
CodeMethodBlock::setAttributesFromNode
virtual void setAttributesFromNode(QDomElement &element)
Set the class attributes of this object from the passed element node.
Definition: codemethodblock.cpp:106
TextBlock
The fundemental unit of text within an output file containing code.
Definition: textblock.h:24
OwnedCodeBlock::setAttributesFromNode
virtual void setAttributesFromNode(QDomElement &element)
Set the class attributes of this object from the passed element node.
Definition: ownedcodeblock.cpp:106
TextBlock::getParentDocument
CodeDocument * getParentDocument() const
Get the value of m_parentDoc.
Definition: textblock.cpp:70
TextBlock::formatMultiLineText
static QString formatMultiLineText(const QString &work, const QString &linePrefix, const QString &breakStr, bool addBreak=true, bool lastLineHasBreak=true)
Format a long text string to be more readable.
Definition: textblock.cpp:288
TextBlock::getIndentationString
QString getIndentationString(int level=0) const
Get the actual amount of indentation for a given level of indentation.
Definition: textblock.cpp:193
TextBlock::decodeText
static QString decodeText(const QString &text, const QString &endLine)
Decode text from XML storage.
Definition: textblock.cpp:392
TextBlock::getWriteOutText
bool getWriteOutText() const
Get the value of m_writeOutText Whether or not to include the text of this TextBlock into a file...
Definition: textblock.cpp:141
CodeMethodBlock::setAttributesOnNode
virtual void setAttributesOnNode(QDomDocument &doc, QDomElement &blockElement)
Set attributes of the node that represents this class in the XMI document.
Definition: codemethodblock.cpp:87
CodeMethodBlock::CodeMethodBlock
CodeMethodBlock(ClassifierCodeDocument *doc, UMLObject *parentObj, const QString &body="", const QString &comment="")
Constructors.
Definition: codemethodblock.cpp:19
CodeMethodBlock::~CodeMethodBlock
virtual ~CodeMethodBlock()
Empty Destructor.
Definition: codemethodblock.cpp:26
classifiercodedocument.h
TextBlock::encodeText
static QString encodeText(const QString &text, const QString &endLine)
Encode text for XML storage.
Definition: textblock.cpp:378
CodeMethodBlock::syncToParent
virtual void syncToParent()
Definition: codemethodblock.cpp:169
CodeMethodBlock::getEndMethodText
QString getEndMethodText() const
Get the ending text that finishes this method after the body is printed.
Definition: codemethodblock.cpp:50
TextBlock::getText
QString getText() const
Get the value of m_text The actual text of this code block.
Definition: textblock.cpp:99
CodeMethodBlock::setAttributesFromObject
virtual void setAttributesFromObject(TextBlock *obj)
Set the class attributes from a passed object.
Definition: codemethodblock.cpp:124
TextBlock::release
virtual void release()
Causes the text block to release all of its connections and any other text blocks that it 'owns'...
Definition: textblock.cpp:275
uml.h
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