umbrello API Documentation

codeblockwithcomments.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-2007                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 /*  This code generated by:
00013  *      Author : thomas
00014  *      Date   : Wed Jun 18 2003
00015  */
00016 
00017 // own header
00018 #include "codeblockwithcomments.h"
00019 
00020 // qt/kde includes
00021 #include <kdebug.h>
00022 
00023 // local includes
00024 #include "codedocument.h"
00025 #include "hierarchicalcodeblock.h"
00026 #include "codegenerators/codegenfactory.h"
00027 
00028 // Constructors/Destructors
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 // Methods
00047 //
00048 
00049 
00050 // Accessor methods
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 // Other methods
00069 //
00070 
00074 void CodeBlockWithComments::saveToXMI ( QDomDocument & doc, QDomElement & root ) {
00075     QDomElement blockElement = doc.createElement( "codeblockwithcomments" );
00076 
00077     // set attributes
00078     setAttributesOnNode(doc, blockElement);
00079 
00080     root.appendChild( blockElement );
00081 }
00082 
00083 void CodeBlockWithComments::setAttributesOnNode ( QDomDocument & doc, QDomElement & blockElement)
00084 {
00085 
00086     // set super-class attributes
00087     CodeBlock::setAttributesOnNode(doc, blockElement);
00088 
00089     // set local attributes now..e.g. a comment
00090     // which we will store in its own separate child node block
00091     QDomElement commElement = doc.createElement( "header" );
00092     getComment()->saveToXMI(doc, commElement); // comment
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     // set attributes from superclass method the XMI
00120     CodeBlock::setAttributesFromNode(root);
00121 
00122     // load comment now
00123     // by looking for our particular child element
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 // slave indentation level for both the header and text body
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"
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