codeblockwithcomments.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "codeblockwithcomments.h"
00019
00020
00021 #include <kdebug.h>
00022
00023
00024 #include "codedocument.h"
00025 #include "hierarchicalcodeblock.h"
00026 #include "codegenerators/codegenfactory.h"
00027
00028
00029
00030
00031 CodeBlockWithComments::CodeBlockWithComments ( HierarchicalCodeBlock * hb, const QString & body, const QString & comment)
00032 : CodeBlock (hb, body)
00033 {
00034 initFields(hb->getParentDocument(), comment);
00035 }
00036
00037 CodeBlockWithComments::CodeBlockWithComments ( CodeDocument * parent , const QString & body, const QString & comment)
00038 : CodeBlock (parent, body)
00039 {
00040 initFields(parent, comment);
00041 }
00042
00043 CodeBlockWithComments::~CodeBlockWithComments ( ) { }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00057 void CodeBlockWithComments::setComment ( CodeComment * object ) {
00058 m_comment = object;
00059 }
00060
00064 CodeComment * CodeBlockWithComments::getComment ( ) {
00065 return m_comment;
00066 }
00067
00068
00069
00070
00074 void CodeBlockWithComments::saveToXMI ( QDomDocument & doc, QDomElement & root ) {
00075 QDomElement blockElement = doc.createElement( "codeblockwithcomments" );
00076
00077
00078 setAttributesOnNode(doc, blockElement);
00079
00080 root.appendChild( blockElement );
00081 }
00082
00083 void CodeBlockWithComments::setAttributesOnNode ( QDomDocument & doc, QDomElement & blockElement)
00084 {
00085
00086
00087 CodeBlock::setAttributesOnNode(doc, blockElement);
00088
00089
00090
00091 QDomElement commElement = doc.createElement( "header" );
00092 getComment()->saveToXMI(doc, commElement);
00093 blockElement.appendChild( commElement);
00094
00095 }
00096
00097 void CodeBlockWithComments::setAttributesFromObject(TextBlock * obj)
00098 {
00099
00100 CodeBlock::setAttributesFromObject(obj);
00101
00102 CodeBlockWithComments * cb = dynamic_cast<CodeBlockWithComments*>(obj);
00103 if(cb)
00104 getComment()->setAttributesFromObject((TextBlock*)cb->getComment());
00105
00106 }
00107
00111 void CodeBlockWithComments::loadFromXMI ( QDomElement & root )
00112 {
00113 setAttributesFromNode(root);
00114 }
00115
00116 void CodeBlockWithComments::setAttributesFromNode( QDomElement & root)
00117 {
00118
00119
00120 CodeBlock::setAttributesFromNode(root);
00121
00122
00123
00124 QDomNode node = root.firstChild();
00125 QDomElement element = node.toElement();
00126 bool gotComment = false;
00127 while( !element.isNull() ) {
00128 QString tag = element.tagName();
00129 if( tag == "header" ) {
00130 QDomNode cnode = element.firstChild();
00131 QDomElement celem = cnode.toElement();
00132 getComment()->loadFromXMI(celem);
00133 gotComment = true;
00134 break;
00135 }
00136 node = element.nextSibling();
00137 element = node.toElement();
00138 }
00139
00140 if(!gotComment)
00141 kWarning()<<" loadFromXMI : Warning: unable to initialize CodeComment in block:"<<getTag()<<endl;
00142
00143 }
00144
00148 QString CodeBlockWithComments::toString ( ) {
00149
00150 QString string = QString();
00151
00152 if(getWriteOutText()) {
00153 QString indent = getIndentationString();
00154 QString endLine = getNewLineEndingChars();
00155 QString body = formatMultiLineText (getText(), indent, endLine);
00156 QString comment = getComment()->toString();
00157
00158 if(!comment.isEmpty() && getComment()->getWriteOutText())
00159 string.append(comment);
00160 if(!body.isEmpty())
00161 string.append(body);
00162 }
00163
00164 return string;
00165 }
00166
00167
00168 void CodeBlockWithComments::setOverallIndentationLevel ( int level )
00169 {
00170 setIndentationLevel(level);
00171 m_comment->setIndentationLevel(level);
00172 }
00173
00174 void CodeBlockWithComments::initFields(CodeDocument *parent, QString comment)
00175 {
00176 CodeComment * codecomment = CodeGenFactory::newCodeComment(parent);
00177 codecomment->setText(comment);
00178 m_comment = codecomment;
00179 }
00180
00181 #include "codeblockwithcomments.moc"
This file is part of the documentation for umbrello Version 3.1.0.