umbrello API Documentation

xmlelementcodeblock.cpp

00001 
00002 /***************************************************************************
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (at your option) any later version.                                   *
00008  *                                                                         *
00009  *   copyright (C) 2004-2007                                               *
00010  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00011  ***************************************************************************/
00012 
00013 /*  This code generated by:
00014  *      Author : thomas
00015  *      Date   : Wed Sep 26 2003
00016  */
00017 
00018 // own header
00019 #include "xmlelementcodeblock.h"
00020 
00021 // qt/kde includes
00022 #include <kdebug.h>
00023 
00024 // local includes
00025 #include "xmlcodecomment.h"
00026 #include "../attribute.h"
00027 #include "../codedocument.h"
00028 
00029 // Constructors/Destructors
00030 //
00031 
00032 XMLElementCodeBlock::XMLElementCodeBlock ( CodeDocument * parentDoc, const QString & nodeName, const QString & comment)
00033         : HierarchicalCodeBlock(parentDoc)
00034 {
00035     init(parentDoc, nodeName, comment);
00036 }
00037 
00038 XMLElementCodeBlock::~XMLElementCodeBlock ( ) { }
00039 
00040 //
00041 // Methods
00042 //
00043 
00047 void XMLElementCodeBlock::saveToXMI ( QDomDocument & doc, QDomElement & root ) {
00048     QDomElement blockElement = doc.createElement( "xmlelementblock" );
00049 
00050     setAttributesOnNode(doc, blockElement);
00051 
00052     root.appendChild( blockElement );
00053 }
00054 
00058 void XMLElementCodeBlock::loadFromXMI ( QDomElement & root )
00059 {
00060     setAttributesFromNode(root);
00061 }
00062 
00066 void XMLElementCodeBlock::setAttributesOnNode ( QDomDocument & doc, QDomElement & docElement)
00067 {
00068 
00069     // superclass call
00070     HierarchicalCodeBlock::setAttributesOnNode(doc,docElement);
00071 
00072     // now set local attributes/fields
00073     docElement.setAttribute("nodeName",getNodeName());
00074 
00075 }
00076 
00080 void XMLElementCodeBlock::setAttributesFromNode ( QDomElement & root) {
00081 
00082     // superclass call
00083     HierarchicalCodeBlock::setAttributesFromNode(root);
00084 
00085     // now set local attributes
00086     setNodeName(root.attribute("nodeName","UNKNOWN"));
00087 
00088 }
00089 
00090 // Accessor methods
00091 //
00092 
00093 void XMLElementCodeBlock::setNodeName (const QString &name) {
00094     m_nodeName = name;
00095 }
00096 
00097 QString XMLElementCodeBlock::getNodeName () {
00098     return m_nodeName;
00099 }
00100 
00101 void XMLElementCodeBlock::addAttribute (UMLAttribute * at) {
00102     m_attList.append(at);
00103 }
00104 
00105 UMLAttributeList * XMLElementCodeBlock::getAttributeList() {
00106     return & m_attList;
00107 }
00108 
00109 
00110 // Other methods
00111 //
00112 
00116 void XMLElementCodeBlock::updateContent ( )
00117 {
00118 
00119     QString endLine = getNewLineEndingChars();
00120 
00121     QString nodeName = getNodeName();
00122 
00123     // Now update START/ENDING Text
00124     QString startText = '<' + nodeName;
00125     QString endText = "";
00126 
00127     UMLAttributeList * alist = getAttributeList();
00128     for (UMLAttribute *at = alist->first(); at; at=alist->next())
00129     {
00130         if(at->getInitialValue().isEmpty())
00131             kWarning()<<" XMLElementCodeBlock : cant print out attribute that lacks an initial value"<<endl;
00132         else {
00133             startText.append(" " +at->getName()+"=\"");
00134             startText.append(at->getInitialValue()+"\"");
00135         }
00136     }
00137 
00138     // now set close of starting/ending node, the style depending on whether we have child text or not
00139     if(getTextBlockList()->count())
00140     {
00141         startText.append(">");
00142         endText = "</" + nodeName + '>';
00143     } else {
00144         startText.append("/>");
00145         endText = "";
00146     }
00147 
00148     setStartText(startText);
00149     setEndText(endText);
00150 
00151 }
00152 
00153 void XMLElementCodeBlock::init (CodeDocument *parentDoc, const QString &nodeName, const QString &comment)
00154 {
00155 
00156     setComment(new XMLCodeComment(parentDoc));
00157     getComment()->setText(comment);
00158 
00159     m_nodeName = nodeName;
00160 
00161     updateContent();
00162 
00163 }
00164 
00165 
00166 #include "xmlelementcodeblock.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:08:03 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003