kformula/flake
ElementFactory.cpp
Go to the documentation of this file.00001 /* This file is part of the KDE project 00002 Copyright (C) 2003 Ulrich Kuettler <ulrich.kuettler@gmx.de> 00003 2006 Martin Pfeiffer <hubipete@gmx.net> 00004 2006-2007 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "ElementFactory.h" 00023 00024 #include "ActionElement.h" 00025 #include "FencedElement.h" 00026 #include "EncloseElement.h" 00027 #include "ErrorElement.h" 00028 #include "FractionElement.h" 00029 #include "GlyphElement.h" 00030 #include "IdentifierElement.h" 00031 #include "TableElement.h" 00032 #include "TableRowElement.h" 00033 #include "TableEntryElement.h" 00034 #include "MultiscriptElement.h" 00035 #include "NumberElement.h" 00036 #include "OperatorElement.h" 00037 #include "PaddedElement.h" 00038 #include "PhantomElement.h" 00039 #include "RootElement.h" 00040 #include "RowElement.h" 00041 #include "SpaceElement.h" 00042 #include "StringElement.h" 00043 #include "StyleElement.h" 00044 #include "SubSupElement.h" 00045 #include "TextElement.h" 00046 #include "UnderOverElement.h" 00047 #include "SquareRootElement.h" 00048 #include "UnknownElement.h" 00049 00050 #include <kdebug.h> 00051 00052 BasicElement* ElementFactory::createElement( const QString& tagName, 00053 BasicElement* parent ) 00054 { 00055 // kWarning( DEBUGID ) << "Creating element: " << tagName; 00056 if( tagName == "mi" ) 00057 return new IdentifierElement( parent ); 00058 else if ( tagName == "mo" ) 00059 return new OperatorElement( parent ); 00060 else if ( tagName == "mn" ) 00061 return new NumberElement( parent ); 00062 else if ( tagName == "mtext" ) 00063 return new TextElement( parent ); 00064 else if ( tagName == "ms" ) 00065 return new StringElement( parent ); 00066 else if ( tagName == "mspace" ) 00067 return new SpaceElement( parent ); 00068 else if ( tagName == "mglyph" ) 00069 return new GlyphElement( parent ); 00070 else if ( tagName == "mrow" ) 00071 return new RowElement( parent ); 00072 else if ( tagName == "mfrac" ) 00073 return new FractionElement( parent ); 00074 else if ( tagName == "msqrt" ) 00075 return new SquareRootElement( parent ); 00076 else if ( tagName == "mroot" ) 00077 return new RootElement( parent ); 00078 else if ( tagName == "mstyle" ) 00079 return new StyleElement( parent ); 00080 else if ( tagName == "merror" ) 00081 return new ErrorElement( parent ); 00082 else if ( tagName == "mpadded" ) 00083 return new PaddedElement( parent ); 00084 else if ( tagName == "mphantom" ) 00085 return new PhantomElement( parent ); 00086 else if ( tagName == "mtable" ) 00087 return new TableElement( parent ); 00088 else if ( tagName == "mtr" ) 00089 return new TableRowElement( parent ); 00090 else if ( tagName == "mtd" ) 00091 return new TableEntryElement( parent ); 00092 else if ( tagName == "mfenced" ) 00093 return new FencedElement( parent ); 00094 else if ( tagName == "menclose" ) 00095 return new EncloseElement( parent ); 00096 else if ( tagName == "msub") 00097 return new SubSupElement( parent, SubScript ); 00098 else if ( tagName == "msup") 00099 return new SubSupElement( parent, SupScript ); 00100 else if ( tagName == "msubsup") 00101 return new SubSupElement( parent, SubSupScript ); 00102 else if ( tagName == "munder") 00103 return new UnderOverElement( parent, Under ); 00104 else if ( tagName == "mover") 00105 return new UnderOverElement( parent, Over ); 00106 else if ( tagName == "munderover") 00107 return new UnderOverElement( parent, UnderOver ); 00108 else if ( tagName == "mmultiscripts" ) 00109 return new MultiscriptElement( parent ); 00110 00111 kWarning( DEBUGID ) << "Do not know how to create the following element: " << tagName; 00112 return new UnknownElement( parent ); 00113 } 00114 00115 QString ElementFactory::elementName( ElementType type ) 00116 { 00117 switch ( type ) { 00118 case Identifier: 00119 return "mi"; 00120 case Operator: 00121 return "mo"; 00122 case Number: 00123 return "mn"; 00124 case Text: 00125 return "mtext"; 00126 case Glyph: 00127 return "mglyph"; 00128 case String: 00129 return "ms"; 00130 case Space: 00131 return "mspace"; 00132 case Row: 00133 return "mrow"; 00134 case Fraction: 00135 return "mfrac"; 00136 case Phantom: 00137 return "mphantom"; 00138 case Style: 00139 return "mstyle"; 00140 case Padded: 00141 return "mpadded"; 00142 case Error: 00143 return "merror"; 00144 case Fenced: 00145 return "mfenced"; 00146 case Enclose: 00147 return "menclose"; 00148 case UnderOver: 00149 return "munderover"; 00150 case Under: 00151 return "munder"; 00152 case Over: 00153 return "mover"; 00154 case SubScript: 00155 return "msub"; 00156 case SupScript: 00157 return "msup"; 00158 case SubSupScript: 00159 return "msubsup"; 00160 case MultiScript: 00161 return "mmultiscripts"; 00162 case Root: 00163 return "mroot"; 00164 case SquareRoot: 00165 return "msqrt"; 00166 case Table: 00167 return "mtable"; 00168 case TableRow: 00169 return "mtr"; // TODO: Check for mlabeledtr 00170 case TableEntry: 00171 return "mtd"; 00172 case Action: 00173 return "maction"; 00174 case Basic: 00175 return "mrow"; 00176 case Formula: 00177 return "math"; 00178 default: 00179 kWarning( DEBUGID ) << "Invalid element type " << type; 00180 } 00181 00182 return QString(); 00183 }
