lib

actionelement.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "creationstrategy.h"
00021 #include "actionelement.h"
00022 
00023 KFORMULA_NAMESPACE_BEGIN
00024 
00025 ActionElement::ActionElement( BasicElement* parent ) : SequenceElement( parent ),
00026                                                        m_selection( 0 )
00027 {
00028 }
00029 
00030 bool ActionElement::readAttributesFromMathMLDom(const QDomElement& element)
00031 {
00032     if ( ! BasicElement::readAttributesFromMathMLDom( element ) ) {
00033         return false;
00034     }
00035 
00036     m_actionType = element.attribute( "actiontype" );
00037     QString selectionStr = element.attribute( "selection" );
00038     if ( ! selectionStr.isNull() ) {
00039         bool ok;
00040         m_selection = selectionStr.toUInt( &ok ); 
00041         if ( ! ok ) m_selection = 0;
00042     }
00043 
00044     return true;
00045 }
00046 
00047 int ActionElement::buildChildrenFromMathMLDom(QPtrList<BasicElement>& list, QDomNode n) 
00048 {
00049     if ( ! n.isElement() )
00050         return -1;
00051     QDomElement e = n.toElement();
00052     QString tag = e.tagName().lower();
00053     BasicElement* child = getCreationStrategy()->createElement( tag, e );
00054     if ( child == 0 )
00055         return -1;
00056     child->setParent( this );
00057     if ( child->buildFromMathMLDom( e ) == -1 ) {
00058         delete child;
00059         return -1;
00060     }
00061     list.append( child );
00062     parse();
00063     return 1;
00064 }
00065 
00066 void ActionElement::writeMathMLAttributes( QDomElement& element ) const
00067 {
00068     if ( ! m_actionType.isNull() ) {
00069         element.setAttribute( "actiontype", m_actionType );
00070     }
00071     if ( m_selection ) {
00072         element.setAttribute( "selection", QString( "%1" ).arg( m_selection ) );
00073     }
00074 }
00075 
00076 
00077 KFORMULA_NAMESPACE_END
KDE Home | KDE Accessibility Home | Description of Access Keys