umbrello API Documentation

codemethodblock.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2004-2006                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 /*  This code generated by:
00013  *      Author : thomas
00014  *      Date   : Fri Jun 20 2003
00015  */
00016 #include "codemethodblock.h"
00017 #include "codeclassfield.h"
00018 #include "classifiercodedocument.h"
00019 #include "codegenerationpolicy.h"
00020 #include "uml.h"
00021 
00022 // Constructors/Destructors
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 // Methods
00035 //
00036 
00037 
00038 // Accessor methods
00039 //
00040 
00041 // we can just call the superclass
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 // Other methods
00075 //
00076 
00077 void CodeMethodBlock::release () {
00078     // just call super-class versions
00079     OwnedCodeBlock::release();
00080     TextBlock::release();
00081 }
00082 
00086 void CodeMethodBlock::setAttributesOnNode ( QDomDocument & doc, QDomElement & elem) {
00087 
00088     // set super-class attributes
00089     CodeBlockWithComments::setAttributesOnNode(doc, elem);
00090     OwnedCodeBlock::setAttributesOnNode(doc, elem);
00091 
00092     // set local class attributes
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     // set attributes from the XMI
00108     CodeBlockWithComments::setAttributesFromNode(elem); // superclass load
00109     OwnedCodeBlock::setAttributesFromNode(elem); // superclass load
00110 
00111     // now load local attributes
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     // only update IF we are NOT AutoGenerated
00185     if(getContentType() != AutoGenerated)
00186         return;
00187 
00188     updateContent();
00189 }
00190 
00191 #include "codemethodblock.moc"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:55 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003