• 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
codeblockwithcomments.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 "codeblockwithcomments.h"
14 
15 // local includes
16 #include "codedocument.h"
17 #include "codegenfactory.h"
18 #include "debug_utils.h"
19 
23 CodeBlockWithComments::CodeBlockWithComments (CodeDocument * parent, const QString & body, const QString & comment)
24  : CodeBlock (parent, body)
25 {
26  CodeComment * codecomment = CodeGenFactory::newCodeComment(parent);
27  codecomment->setText(comment);
28  m_comment = codecomment;
29 }
30 
31 CodeBlockWithComments::~CodeBlockWithComments ()
32 {
33 }
34 
38 void CodeBlockWithComments::setComment (CodeComment * object)
39 {
40  m_comment = object;
41 }
42 
46 CodeComment * CodeBlockWithComments::getComment () const
47 {
48  return m_comment;
49 }
50 
54 void CodeBlockWithComments::saveToXMI (QDomDocument & doc, QDomElement & root)
55 {
56  QDomElement blockElement = doc.createElement("codeblockwithcomments");
57 
58  // set attributes
59  setAttributesOnNode(doc, blockElement);
60 
61  root.appendChild(blockElement);
62 }
63 
68 void CodeBlockWithComments::setAttributesOnNode (QDomDocument & doc, QDomElement & blockElement)
69 {
70  // set super-class attributes
71  CodeBlock::setAttributesOnNode(doc, blockElement);
72 
73  // set local attributes now..e.g. a comment
74  // which we will store in its own separate child node block
75  QDomElement commElement = doc.createElement("header");
76  getComment()->saveToXMI(doc, commElement); // comment
77  blockElement.appendChild(commElement);
78 }
79 
83 void CodeBlockWithComments::setAttributesFromObject(TextBlock * obj)
84 {
85  CodeBlock::setAttributesFromObject(obj);
86 
87  CodeBlockWithComments * cb = dynamic_cast<CodeBlockWithComments*>(obj);
88  if (cb) {
89  getComment()->setAttributesFromObject((TextBlock*)cb->getComment());
90  }
91 }
92 
96 void CodeBlockWithComments::loadFromXMI (QDomElement & root)
97 {
98  setAttributesFromNode(root);
99 }
100 
105 void CodeBlockWithComments::setAttributesFromNode(QDomElement & root)
106 {
107  // set attributes from superclass method the XMI
108  CodeBlock::setAttributesFromNode(root);
109 
110  // load comment now
111  // by looking for our particular child element
112  QDomNode node = root.firstChild();
113  QDomElement element = node.toElement();
114  bool gotComment = false;
115  while (!element.isNull()) {
116  QString tag = element.tagName();
117  if (tag == "header") {
118  QDomNode cnode = element.firstChild();
119  QDomElement celem = cnode.toElement();
120  getComment()->loadFromXMI(celem);
121  gotComment = true;
122  break;
123  }
124  node = element.nextSibling();
125  element = node.toElement();
126  }
127 
128  if (!gotComment) {
129  uWarning() << " loadFromXMI : Warning: unable to initialize CodeComment in block:" << getTag();
130  }
131 }
132 
136 QString CodeBlockWithComments::toString () const
137 {
138  QString string;
139 
140  if (getWriteOutText()) {
141  QString indent = getIndentationString();
142  QString endLine = getNewLineEndingChars();
143  QString body = formatMultiLineText (getText(), indent, endLine);
144  CodeComment* codeComment = getComment();
145  QString comment = codeComment->toString();
146 
147  if (!comment.isEmpty() && codeComment->getWriteOutText()) {
148  string.append(comment);
149  }
150  if (!body.isEmpty()) {
151  string.append(body);
152  }
153  }
154  return string;
155 }
156 
157 // slave indentation level for both the header and text body
158 
163 void CodeBlockWithComments::setOverallIndentationLevel (int level)
164 {
165  setIndentationLevel(level);
166  getComment()->setIndentationLevel(level);
167 }
CodeBlock::setAttributesOnNode
virtual void setAttributesOnNode(QDomDocument &doc, QDomElement &blockElement)
Set attributes of the node that represents this class in the XMI document.
Definition: codeblock.cpp:78
CodeBlockWithComments::~CodeBlockWithComments
virtual ~CodeBlockWithComments()
Empty Destructor.
Definition: codeblockwithcomments.cpp:31
CodeBlock
A "chunk" of code within the code document.
Definition: codeblock.h:20
CodeBlockWithComments::getComment
CodeComment * getComment() const
Get the Comment object.
Definition: codeblockwithcomments.cpp:46
CodeComment::loadFromXMI
virtual void loadFromXMI(QDomElement &root)
Load params from the appropriate XMI element node.
Definition: codecomment.cpp:42
CodeBlockWithComments::setAttributesFromObject
virtual void setAttributesFromObject(TextBlock *obj)
Set the class attributes from a passed object.
Definition: codeblockwithcomments.cpp:83
codedocument.h
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::getTag
QString getTag() const
Get the tag of this text block.
Definition: textblock.cpp:110
TextBlock::setText
void setText(const QString &text)
Set the value of m_text The actual text of this code block.
Definition: textblock.cpp:80
CodeBlockWithComments::toString
virtual QString toString() const
Definition: codeblockwithcomments.cpp:136
CodeBlockWithComments::setOverallIndentationLevel
void setOverallIndentationLevel(int level)
A utility method that causes the comment and body of the code block to have the same indentation leve...
Definition: codeblockwithcomments.cpp:163
uWarning
#define uWarning()
Definition: debug_utils.h:97
debug_utils.h
TextBlock::getNewLineEndingChars
static QString getNewLineEndingChars()
Get the new line chars which ends the line.
Definition: textblock.cpp:172
CodeBlockWithComments
class CodeBlockWithComments A very common type of text block in any type of code. ...
Definition: codeblockwithcomments.h:24
codegenfactory.h
CodeDocument
A document containing the code for one file.
Definition: codedocument.h:32
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
CodeBlockWithComments::CodeBlockWithComments
CodeBlockWithComments(CodeDocument *parent, const QString &body="", const QString &comment="")
Basic Constructor.
Definition: codeblockwithcomments.cpp:23
codeblockwithcomments.h
CodeBlockWithComments::setAttributesFromNode
virtual void setAttributesFromNode(QDomElement &element)
Set the class attributes of this object from the passed element node.
Definition: codeblockwithcomments.cpp:105
TextBlock::toString
virtual QString toString() const
Return the text in the right format.
Definition: textblock.cpp:404
TextBlock
The fundemental unit of text within an output file containing code.
Definition: textblock.h:24
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::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
CodeBlockWithComments::saveToXMI
virtual void saveToXMI(QDomDocument &doc, QDomElement &root)
Save the XMI representation of this object.
Definition: codeblockwithcomments.cpp:54
TextBlock::setIndentationLevel
void setIndentationLevel(int level)
Set how many times to indent this text block.
Definition: textblock.cpp:152
TextBlock::setAttributesFromObject
virtual void setAttributesFromObject(TextBlock *obj)
Set the class attributes from a passed object.
Definition: textblock.cpp:345
CodeComment
Text which will be comments.
Definition: codecomment.h:23
CodeBlockWithComments::setComment
void setComment(CodeComment *object)
Set the Comment object.
Definition: codeblockwithcomments.cpp:38
CodeBlock::setAttributesFromObject
virtual void setAttributesFromObject(TextBlock *obj)
Set the class attributes from a passed object.
Definition: codeblock.cpp:113
TextBlock::getText
QString getText() const
Get the value of m_text The actual text of this code block.
Definition: textblock.cpp:99
CodeBlock::setAttributesFromNode
virtual void setAttributesFromNode(QDomElement &element)
Set the class attributes of this object from the passed element node.
Definition: codeblock.cpp:101
CodeBlockWithComments::loadFromXMI
virtual void loadFromXMI(QDomElement &root)
Load params from the appropriate XMI element node.
Definition: codeblockwithcomments.cpp:96
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