codemethodblock.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "codemethodblock.h"
00017 #include "codeclassfield.h"
00018 #include "classifiercodedocument.h"
00019 #include "codegenerationpolicy.h"
00020 #include "uml.h"
00021
00022
00023
00024
00025 CodeMethodBlock::CodeMethodBlock ( ClassifierCodeDocument * doc, UMLObject * parentObj, const QString & body, const QString & comment)
00026 : CodeBlockWithComments ((CodeDocument*)doc, body, comment), OwnedCodeBlock (parentObj)
00027 {
00028 initFields();
00029 }
00030
00031 CodeMethodBlock::~CodeMethodBlock ( ) { }
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 CodeDocument * CodeMethodBlock::getParentDocument() {
00043 return TextBlock::getParentDocument();
00044 }
00045
00049 QString CodeMethodBlock::getStartMethodText() const {
00050 return m_startMethod;
00051 }
00052
00056 QString CodeMethodBlock::getEndMethodText() const {
00057 return m_endMethod;
00058 }
00059
00063 void CodeMethodBlock::setStartMethodText (const QString &value) {
00064 m_startMethod = value;
00065 }
00066
00070 void CodeMethodBlock::setEndMethodText (const QString &value) {
00071 m_endMethod = value;
00072 }
00073
00074
00075
00076
00077 void CodeMethodBlock::release () {
00078
00079 OwnedCodeBlock::release();
00080 TextBlock::release();
00081 }
00082
00086 void CodeMethodBlock::setAttributesOnNode ( QDomDocument & doc, QDomElement & elem) {
00087
00088
00089 CodeBlockWithComments::setAttributesOnNode(doc, elem);
00090 OwnedCodeBlock::setAttributesOnNode(doc, elem);
00091
00092
00093 if(getContentType() != AutoGenerated)
00094 {
00095 QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();
00096 elem.setAttribute("startMethodText",encodeText(getStartMethodText(),endLine));
00097 elem.setAttribute("endMethodText",encodeText(getEndMethodText(),endLine));
00098 }
00099
00100 }
00101
00105 void CodeMethodBlock::setAttributesFromNode ( QDomElement & elem) {
00106
00107
00108 CodeBlockWithComments::setAttributesFromNode(elem);
00109 OwnedCodeBlock::setAttributesFromNode(elem);
00110
00111
00112 if(getContentType() != AutoGenerated)
00113 {
00114 QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();
00115 setStartMethodText(decodeText(elem.attribute("startMethodText",""),endLine));
00116 setEndMethodText(decodeText(elem.attribute("endMethodText",""),endLine));
00117 }
00118
00119 }
00120
00121 void CodeMethodBlock::setAttributesFromObject(TextBlock * obj)
00122 {
00123
00124 CodeBlockWithComments::setAttributesFromObject(obj);
00125
00126 CodeMethodBlock * mb = dynamic_cast<CodeMethodBlock*>(obj);
00127 if(mb)
00128 {
00129 setStartMethodText(mb->getStartMethodText());
00130 setEndMethodText(mb->getEndMethodText());
00131 }
00132
00133 }
00134
00138 QString CodeMethodBlock::toString ( ) {
00139
00140 QString string = QString("");
00141
00142 if(getWriteOutText()) {
00143
00144 QString indent = getIndentationString();
00145 QString bodyIndent = getIndentationString(getIndentationLevel()+1);
00146 QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();
00147
00148 QString startMethod = formatMultiLineText ( getStartMethodText(), indent, endLine);
00149 QString body = formatMultiLineText (getText(), bodyIndent, endLine);
00150 QString endMethod = formatMultiLineText( getEndMethodText(), indent, endLine);
00151
00152 QString comment = getComment()->toString();
00153 if(!comment.isEmpty() && getComment()->getWriteOutText())
00154 string.append(comment);
00155
00156 if(!startMethod.isEmpty())
00157 string.append(startMethod);
00158
00159 if(!body.isEmpty())
00160 string.append(body);
00161
00162 if(!endMethod.isEmpty())
00163 string.append(endMethod);
00164
00165 }
00166
00167 return string;
00168
00169 }
00170
00171 void CodeMethodBlock::initFields ( ) {
00172
00173 m_startMethod = QString("");
00174 m_endMethod = QString("");
00175 }
00176
00177 void CodeMethodBlock::syncToParent ( )
00178 {
00179
00180 getComment()->setText(getParentObject()->getDoc());
00181
00182 updateMethodDeclaration();
00183
00184
00185 if(getContentType() != AutoGenerated)
00186 return;
00187
00188 updateContent();
00189 }
00190
00191 #include "codemethodblock.moc"
This file is part of the documentation for umbrello Version 3.1.0.