umbrello API Documentation

cppcodedocumentation.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   : Mon Jun 23 2003
00015  */
00016 
00017 // own header
00018 #include "cppcodedocumentation.h"
00019 // qt/kde includes
00020 #include <qregexp.h>
00021 #include <kdebug.h>
00022 // app includes
00023 #include "../codedocument.h"
00024 #include "../codegenerator.h"
00025 #include "../codegenerationpolicy.h"
00026 #include "../uml.h"
00027 
00028 // Constructors/Destructors
00029 //
00030 
00031 CPPCodeDocumentation::CPPCodeDocumentation ( CodeDocument * doc, const QString & text )
00032         : CodeComment (doc, text)
00033 {
00034 
00035 }
00036 
00037 CPPCodeDocumentation::~CPPCodeDocumentation ( ) { }
00038 
00039 //
00040 // Methods
00041 //
00042 
00043 
00044 // Accessor methods
00045 //
00046 
00047 // Other methods
00048 //
00049 
00053 void CPPCodeDocumentation::saveToXMI ( QDomDocument & doc, QDomElement & root ) {
00054     QDomElement blockElement = doc.createElement( "cppcodedocumentation" );
00055     setAttributesOnNode(doc, blockElement); // as we added no additional fields to this class we may
00056     // just use parent TextBlock method
00057     root.appendChild( blockElement );
00058 }
00059 
00063 QString CPPCodeDocumentation::toString ( )
00064 {
00065 
00066     QString output = "";
00067 
00068     // simple output method
00069     if(getWriteOutText())
00070     {
00071         bool useDoubleDashOutput = true;
00072 
00073         // need to figure out output type from cpp policy
00074         CodeGenerationPolicy * p = UMLApp::app()->getCommonPolicy();
00075         if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
00076             useDoubleDashOutput = false;
00077 
00078         QString indent = getIndentationString();
00079         QString endLine = getNewLineEndingChars();
00080         QString body = getText();
00081         if(useDoubleDashOutput)
00082         {
00083             if(!body.isEmpty())
00084                 output.append(formatMultiLineText (body, indent +"// ", endLine));
00085         } else {
00086             output.append(indent+""+endLine);
00089         }
00090     }
00091 
00092     return output;
00093 }
00094 
00095 QString CPPCodeDocumentation::getNewEditorLine ( int amount )
00096 {
00097     CodeGenerationPolicy * p = UMLApp::app()->getCommonPolicy();
00098     if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
00099         return getIndentationString(amount) + " * ";
00100     else
00101         return getIndentationString(amount) + "// ";
00102 }
00103 
00104 int CPPCodeDocumentation::firstEditableLine() {
00105     CodeGenerationPolicy * p = UMLApp::app()->getCommonPolicy();
00106     if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
00107         return 1;
00108     return 0;
00109 }
00110 
00111 int CPPCodeDocumentation::lastEditableLine() {
00112     CodeGenerationPolicy * p = UMLApp::app()->getCommonPolicy();
00113     if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
00114     {
00115         return -1; // very last line is NOT editable
00116     }
00117     return 0;
00118 }
00119 
00123 QString CPPCodeDocumentation::unformatText ( const QString & text , const QString & indent)
00124 {
00125 
00126     QString mytext = TextBlock::unformatText(text, indent);
00127     CodeGenerationPolicy * p = UMLApp::app()->getCommonPolicy();
00128     // remove leading or trailing comment stuff
00129     mytext.remove(QRegExp('^'+indent));
00130     if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
00131     {
00132         mytext.remove(QRegExp("^\\/\\*\\*\\s*\n?"));
00133         mytext.remove(QRegExp("\\s*\\*\\/\\s*\n?$"));
00134         mytext.remove(QRegExp("^\\s*\\*\\s*"));
00135     } else
00136         mytext.remove(QRegExp("^\\/\\/\\s*"));
00137 
00138     return mytext;
00139 }
00140 
00141 
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