File indexing completed on 2024-05-12 16:34:01

0001 /* This file is part of the KDE project
0002    Copyright (C) 2003 Ulrich Kuettler <ulrich.kuettler@gmx.de>
0003    Copyright (C) 2006 Martin Pfeiffer <hubipete@gmx.net>
0004    Copyright (C) 2006 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 #ifndef ELEMENTFACTORY_H
0023 #define ELEMENTFACTORY_H
0024 
0025 #include <QString>
0026 #include "koformula_export.h"
0027 
0028 class BasicElement;
0029 
0030 enum ElementType {
0031     Basic,
0032     Formula,
0033     Row,
0034     Identifier,
0035     Number,
0036     Operator,
0037     Space,
0038     Fraction,
0039     Table,
0040     TableRow,
0041     TableData,
0042     Under,
0043     Over,
0044     UnderOver,
0045     MultiScript,
0046     SupScript,
0047     SubScript,
0048     SubSupScript,
0049     Root,
0050     SquareRoot,
0051     Text,
0052     Style,
0053     Padded,
0054     Error,
0055     Fenced,
0056     Glyph,
0057     String,
0058     Enclose,
0059     Phantom,
0060     Action,
0061     Annotation,
0062     Unknown,
0063     Empty
0064 };
0065 
0066 
0067 /**
0068  * @short An implementation of the factory pattern to create element instances
0069  *
0070  * The creation of new BasicElement derived classes is an often done task. While
0071  * loading ElementFactory provides a very simple way to achieve an element by
0072  * passing its MathML name. Just use the static createElement() method.
0073  * While saving the elementName() method is used to map the ElementType's to the
0074  * according MathML names.
0075  *
0076  * @author Martin Pfeiffer
0077  */
0078 class KOFORMULA_EXPORT ElementFactory {
0079 public:
0080     /// The default constructor
0081     ElementFactory();
0082 
0083     /**
0084      * Obtain new instances of elements by passing the MathML tag name
0085      * @param tagName The MathML tag name of the new element
0086      * @param parent The parent element of the newly created element
0087      * @return A pointer to the new BasicElement derived element
0088      */
0089     static BasicElement* createElement( const QString& tagName, BasicElement* parent );
0090 
0091     /**
0092      * Obtain the MathML name of a ElementType.
0093      * @param type The given ElementType to get the MathML name from
0094      * @return The MathML name as QString
0095      */
0096     static QString elementName( ElementType type );
0097 };
0098 
0099 #endif // ELEMENTFACTORY_H