File indexing completed on 2024-05-19 16:06:59
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003 Ulrich Kuettler <ulrich.kuettler@gmx.de> 0003 2006 Martin Pfeiffer <hubipete@gmx.net> 0004 2006-2007 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Library General Public 0008 License as published by the Free Software Foundation; either 0009 version 2 of the License, or (at your option) any later version. 0010 0011 This library is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 Library General Public License for more details. 0015 0016 You should have received a copy of the GNU Library General Public License 0017 along with this library; see the file COPYING.LIB. If not, write to 0018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #include "ElementFactory.h" 0023 0024 #include "ActionElement.h" 0025 #include "AnnotationElement.h" 0026 #include "FencedElement.h" 0027 #include "EncloseElement.h" 0028 #include "ErrorElement.h" 0029 #include "FractionElement.h" 0030 #include "GlyphElement.h" 0031 #include "IdentifierElement.h" 0032 #include "TableElement.h" 0033 #include "TableRowElement.h" 0034 #include "TableDataElement.h" 0035 #include "MultiscriptElement.h" 0036 #include "NumberElement.h" 0037 #include "OperatorElement.h" 0038 #include "PaddedElement.h" 0039 #include "PhantomElement.h" 0040 #include "RootElement.h" 0041 #include "RowElement.h" 0042 #include "SpaceElement.h" 0043 #include "StringElement.h" 0044 #include "StyleElement.h" 0045 #include "SubSupElement.h" 0046 #include "TextElement.h" 0047 #include "UnderOverElement.h" 0048 #include "SquareRootElement.h" 0049 #include "UnknownElement.h" 0050 #include "FormulaDebug.h" 0051 0052 0053 BasicElement* ElementFactory::createElement( const QString& tagName, 0054 BasicElement* parent ) 0055 { 0056 // warnFormulaElement << "Creating element: " << tagName; 0057 if ( tagName == "mi" ) 0058 return new IdentifierElement( parent ); 0059 else if ( tagName == "mo" ) 0060 return new OperatorElement( parent ); 0061 else if ( tagName == "mn" ) 0062 return new NumberElement( parent ); 0063 else if ( tagName == "mtext" ) 0064 return new TextElement( parent ); 0065 else if ( tagName == "ms" ) 0066 return new StringElement( parent ); 0067 else if ( tagName == "mspace" ) 0068 return new SpaceElement( parent ); 0069 else if ( tagName == "mglyph" ) 0070 return new GlyphElement( parent ); 0071 else if ( tagName == "mrow" ) 0072 return new RowElement( parent ); 0073 else if ( tagName == "mfrac" ) 0074 return new FractionElement( parent ); 0075 else if ( tagName == "msqrt" ) 0076 return new SquareRootElement( parent ); 0077 else if ( tagName == "mroot" ) 0078 return new RootElement( parent ); 0079 else if ( tagName == "mstyle" ) 0080 return new StyleElement( parent ); 0081 else if ( tagName == "merror" ) 0082 return new ErrorElement( parent ); 0083 else if ( tagName == "mpadded" ) 0084 return new PaddedElement( parent ); 0085 else if ( tagName == "mphantom" ) 0086 return new PhantomElement( parent ); 0087 else if ( tagName == "mtable" ) 0088 return new TableElement( parent ); 0089 else if ( tagName == "mtr" ) 0090 return new TableRowElement( parent ); 0091 else if ( tagName == "mtd" ) 0092 return new TableDataElement( parent ); 0093 else if ( tagName == "mfenced" ) 0094 return new FencedElement( parent ); 0095 else if ( tagName == "menclose" ) 0096 return new EncloseElement( parent ); 0097 else if ( tagName == "msub") 0098 return new SubSupElement( parent, SubScript ); 0099 else if ( tagName == "msup") 0100 return new SubSupElement( parent, SupScript ); 0101 else if ( tagName == "msubsup") 0102 return new SubSupElement( parent, SubSupScript ); 0103 else if ( tagName == "munder") 0104 return new UnderOverElement( parent, Under ); 0105 else if ( tagName == "mover") 0106 return new UnderOverElement( parent, Over ); 0107 else if ( tagName == "munderover") 0108 return new UnderOverElement( parent, UnderOver ); 0109 else if ( tagName == "mmultiscripts" ) 0110 return new MultiscriptElement( parent ); 0111 else if ( tagName == "annotation" ) 0112 return new AnnotationElement( parent ); 0113 0114 warnFormulaElement << "Do not know how to create the following element: " << tagName; 0115 return new UnknownElement( parent ); 0116 } 0117 0118 QString ElementFactory::elementName( ElementType type ) 0119 { 0120 switch ( type ) { 0121 case Identifier: 0122 return "mi"; 0123 case Operator: 0124 return "mo"; 0125 case Number: 0126 return "mn"; 0127 case Text: 0128 return "mtext"; 0129 case Glyph: 0130 return "mglyph"; 0131 case String: 0132 return "ms"; 0133 case Space: 0134 return "mspace"; 0135 case Row: 0136 return "mrow"; 0137 case Fraction: 0138 return "mfrac"; 0139 case Phantom: 0140 return "mphantom"; 0141 case Style: 0142 return "mstyle"; 0143 case Padded: 0144 return "mpadded"; 0145 case Error: 0146 return "merror"; 0147 case Fenced: 0148 return "mfenced"; 0149 case Enclose: 0150 return "menclose"; 0151 case UnderOver: 0152 return "munderover"; 0153 case Under: 0154 return "munder"; 0155 case Over: 0156 return "mover"; 0157 case SubScript: 0158 return "msub"; 0159 case SupScript: 0160 return "msup"; 0161 case SubSupScript: 0162 return "msubsup"; 0163 case MultiScript: 0164 return "mmultiscripts"; 0165 case Root: 0166 return "mroot"; 0167 case SquareRoot: 0168 return "msqrt"; 0169 case Table: 0170 return "mtable"; 0171 case TableRow: 0172 return "mtr"; // TODO: Check for mlabeledtr 0173 case TableData: 0174 return "mtd"; 0175 case Action: 0176 return "maction"; 0177 case Basic: 0178 return "mrow"; 0179 case Formula: 0180 return "math"; 0181 case Annotation: 0182 return "annotation"; 0183 default: 0184 warnFormulaElement << "Invalid element type " << type; 0185 } 0186 0187 return QString(); 0188 }