[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice
From:       Jeremias Epperlein <jeeree () web ! de>
Date:       2009-08-08 18:16:25
Message-ID: 1249755385.646935.24690.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1008944 by jeremiase:

change loading of rows, add debug writeout

Adds an action that writes the current element tree to kDebug(),
changes the loading of rows and fractions, so that empty mrows
are treated as placeholders and mrows with one child as equivalent to
the child

 M  +23 -3     kformula/flake/BasicElement.cpp  
 M  +8 -2      kformula/flake/BasicElement.h  
 M  +17 -4     kformula/flake/FixedElement.cpp  
 M  +7 -6      kformula/flake/FixedElement.h  
 M  +6 -0      kformula/flake/FormulaData.cpp  
 M  +4 -0      kformula/flake/FormulaData.h  
 M  +14 -16    kformula/flake/FractionElement.cpp  
 M  +0 -2      kformula/flake/KoFormulaShape.cpp  
 M  +6 -0      kformula/flake/KoFormulaTool.cpp  
 M  +26 -4     kformula/flake/RowElement.cpp  
 M  +18 -15    kformula/flake/RowElement.h  
 M  +15 -15    kformula/flake/SubSupElement.cpp  
 M  +2 -2      kformula/flake/SubSupElement.h  
 M  +1 -1      plugins/artistictextshape/ArtisticTextShape.cpp  


--- trunk/koffice/kformula/flake/BasicElement.cpp #1008943:1008944
@@ -328,12 +328,12 @@
     while(level-- > 0)  //raise multiplier to the power of level
         m_scaleFactor *= 0.71;
 }
-BasicElement* BasicElement::elementBefore ( int position )
+BasicElement* BasicElement::elementBefore ( int position ) const
 {
     return 0;
 }
 
-BasicElement* BasicElement::elementAfter ( int position )
+BasicElement* BasicElement::elementAfter ( int position ) const
 {
     return 0;
 }
@@ -384,7 +384,6 @@
     return 0;
 }
 
-
 //TODO: This should be cached
 BasicElement* BasicElement::formulaElement() 
 {
@@ -395,4 +394,25 @@
     }
 }
 
+bool BasicElement::isEmpty() const
+{
+    return false;
+}
 
+
+void BasicElement::setScaleFactor ( double scaleFactor )
+{
+    m_scaleFactor=scaleFactor;
+}
+
+void BasicElement::writeElementTree(int indent)
+{
+    QString s;
+    for (int i=0; i<indent; ++i) {
+        s+="   ";
+    }
+    kDebug()<<s<<ElementFactory::elementName(elementType());
+    foreach (BasicElement* tmp, childElements()) {
+        tmp->writeElementTree(indent+1);
+    }
+}
--- trunk/koffice/kformula/flake/BasicElement.h #1008943:1008944
@@ -223,10 +223,10 @@
     virtual int positionOfChild(BasicElement* child) const;
         
     /// @return the element right before the cursor position @p position and 0 if \
                there is none
-    virtual BasicElement* elementBefore(int position);
+    virtual BasicElement* elementBefore(int position) const;
     
     /// @return the element right after the cursor position @p position and 0 if \
                there is none
-    virtual BasicElement* elementAfter(int position);
+    virtual BasicElement* elementAfter(int position) const;
     
     /// Set the element's m_scaleFactor to @p scaleFactor
     void setScaleFactor( double scaleFactor );
@@ -274,9 +274,15 @@
     /// @return first empty element, that is a descendant of this element, if there \
is one  BasicElement* emptyDescendant();
 
+    /// @return true, when the element is empty
+    virtual bool isEmpty() const;
+
     /// @return the formula element
     BasicElement* formulaElement();
 
+    /// writes the element to kDebug(), only for debugging purpose
+    void writeElementTree(int indent=0);
+
 protected:
     /// Read all attributes loaded and add them to the m_attributes map 
     virtual bool readMathMLAttributes( const KoXmlElement& element );
--- trunk/koffice/kformula/flake/FixedElement.cpp #1008943:1008944
@@ -56,9 +56,8 @@
 QPainterPath FixedElement::selectionRegion(const int pos1, const int pos2) const 
 {
     QPainterPath temp;
-//     foreach (BasicElement *child, elementsBetween(pos1, pos2)) {
-//         temp.addRect(child->absoluteBoundingRect());
-//     }
+    Q_UNUSED(pos1);
+    Q_UNUSED(pos2);
     return temp;
 }
 
@@ -139,5 +138,19 @@
     } else {
         return 2*tmp;
     }
-        
 }
+
+bool FixedElement::loadElement ( KoXmlElement& tmp, BasicElement** child )
+{
+    BasicElement *element;
+    element = ElementFactory::createElement( tmp.tagName(), this );
+    if( !element->readMathML( tmp ) ) {
+        return false;
+    }
+    if (element->elementType()==Row && element->childElements().count()<=1) {
+        delete (*child);
+        (*child)=element;
+    } else {
+        (*child)->insertChild(0,element);
+    }
+}
--- trunk/koffice/kformula/flake/FixedElement.h #1008943:1008944
@@ -22,10 +22,11 @@
 
 #include "BasicElement.h"
 #include "kformula_export.h"
+#include <KoXmlReader.h>
 
+
 class FormulaCursor;
 class QPainterPath;
-
 /**
  * @short Abstract Base Class for MathML elements with fixed number of childs
  *
@@ -40,15 +41,15 @@
     virtual ~FixedElement();
 
     virtual bool acceptCursor ( const FormulaCursor& cursor );
-    
+
     BasicElement* elementBefore(int position) const;
-    
+
     BasicElement* elementAfter(int position) const;
 
     virtual QLineF cursorLine ( int position ) const;
-    
-//     virtual QList<BasicElement*> elementsBetween(int pos1, int pos2) const = 0;
-    
+
+    bool loadElement(KoXmlElement& tmp, BasicElement** child);
+
     virtual QPainterPath selectionRegion ( const int pos1, const int pos2 ) const;
 
     /// inherited from BasicElement
--- trunk/koffice/kformula/flake/FormulaData.cpp #1008943:1008944
@@ -1,3 +1,4 @@
+
 /* This file is part of the KDE project
    Copyright (C) 2009 Jeremias Epperlein <jeeree@web.de>
 
@@ -52,4 +53,9 @@
     return m_element;
 }
 
+void FormulaData::writeElementTree()
+{
+    m_element->writeElementTree();
+}
 
+
--- trunk/koffice/kformula/flake/FormulaData.h #1008943:1008944
@@ -48,6 +48,10 @@
     
 signals:
     void dataChanged(FormulaCommand* element, bool undo);
+
+public slots:
+    ///only for debugging
+    void writeElementTree();
     
 private:
     FormulaElement* m_element;
--- trunk/koffice/kformula/flake/FractionElement.cpp #1008943:1008944
@@ -1,3 +1,4 @@
+
 /* This file is part of the KDE project
    Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
 	              Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
@@ -30,8 +31,8 @@
 
 FractionElement::FractionElement( BasicElement* parent ) : FixedElement( parent )
 {
-    m_numerator = new EmptyElement( this );
-    m_denominator = new EmptyElement( this );
+    m_numerator = new RowElement( this );
+    m_denominator = new RowElement( this );
     m_lineThickness = 1.0;
 }
 
@@ -257,24 +258,21 @@
 bool FractionElement::readMathMLContent( const KoXmlElement& parent )
 {
     KoXmlElement tmp;
+    BasicElement* element;
+    int counter=0;
     forEachElement( tmp, parent ) {
-        if( m_numerator->elementType() == Empty ) {
-            delete m_numerator;
-            m_numerator = ElementFactory::createElement( tmp.tagName(), this );
-            if( !m_numerator->readMathML( tmp ) )
-                return false;
-        } else if( m_denominator->elementType() == Empty ) {
-            delete m_denominator;
-            m_denominator = ElementFactory::createElement( tmp.tagName(), this );
-            if( !m_denominator->readMathML( tmp ) )
-                return false;
+        if (counter==0) {
+            loadElement(tmp,&m_numerator);
+        } else if (counter==1) {
+            loadElement(tmp,&m_denominator);
         } else {
             kDebug(39001) << "Too many arguments to mfrac";
-	}
+        }
+        counter++;
     }
-    Q_ASSERT( m_numerator );
-    Q_ASSERT( m_denominator );
-
+    if (counter<2) {
+        kDebug(39001) << "Not enough arguments to mfrac";
+    }
     return true;
 }
 
--- trunk/koffice/kformula/flake/KoFormulaShape.cpp #1008943:1008944
@@ -49,11 +49,9 @@
 }
 
 void KoFormulaShape::updateLayout() {
-    kDebug() << "before:" << KoShape::size()<<"," <<size();
     m_formulaRenderer->layoutElement( m_formulaData->formulaElement() );
 
      KoShape::setSize(m_formulaData->formulaElement()->boundingRect().size());
-     kDebug() << "after:" << KoShape::size()<<"," <<size();
 }
 
 
--- trunk/koffice/kformula/flake/KoFormulaTool.cpp #1008943:1008944
@@ -106,6 +106,8 @@
         m_formulaEditor = new FormulaEditor( m_formulaShape->formulaData());
     }
     connect(m_formulaShape->formulaData(), \
SIGNAL(dataChanged(FormulaCommand*,bool)), this, \
SLOT(updateCursor(FormulaCommand*,bool))); +    //Only for debugging:
+    connect(action("write_elementTree"),SIGNAL(triggered(bool)), \
m_formulaShape->formulaData(), SLOT(writeElementTree()));  }
 
 void KoFormulaTool::deactivate()
@@ -433,5 +435,9 @@
     action->setData( QString( "<msubsup><mrow/><mrow/><mrow/></msubsup>" ) );
     addAction( "insert_subsupscript", action );
     action->setIcon( KIcon("rsub"));
+
+    //only for debugging
+    action = new KAction( "Debug - writeElementTree" , this );
+    addAction( "write_elementTree", action );
 }
 
--- trunk/koffice/kformula/flake/RowElement.cpp #1008943:1008944
@@ -207,9 +207,26 @@
     {
         tmpElement = ElementFactory::createElement( tmp.tagName(), this );
         Q_ASSERT( tmpElement );
-        m_childElements << tmpElement;
-        if( !tmpElement->readMathML( tmp ) )
+        if( !tmpElement->readMathML( tmp ) ) {
             return false;
+        }
+        if (tmpElement->elementType() == Row) {
+            if (tmpElement->childElements().count()==0) {
+                //we don't load in this case, empty elements in rows are not needed
+            } else if (tmpElement->childElements().count()==1) {
+                //mrows with one element are equivalent to mrows with one child are \
equivalent to the child +                //TODO: inverstigate, if we should load them \
nevertheless +                RowElement* tmprow = \
static_cast<RowElement*>(tmpElement); +                BasicElement* child = \
tmprow->childElements()[0]; +                tmprow->removeChild(child);
+                delete tmprow;
+                insertChild(childElements().count(),child);
+            } else {
+                m_childElements << tmpElement;
+            }
+        } else {
+            m_childElements << tmpElement;
+        }
     }
     return true;
 }
@@ -225,7 +242,7 @@
 }
 
 
-BasicElement* RowElement::elementAfter ( int position )
+BasicElement* RowElement::elementAfter ( int position ) const
 {
     if (position<length()) {
         return m_childElements[position];
@@ -234,7 +251,7 @@
     }
 }
 
-BasicElement* RowElement::elementBefore ( int position )
+BasicElement* RowElement::elementBefore ( int position ) const
 {
     if (position>1) {
         return m_childElements[position-1];
@@ -261,6 +278,10 @@
     return true;
 }
 
+bool RowElement::isEmpty() const
+{
+    return (elementType()==Row && m_childElements.count()==0);
+}
 
 
 
@@ -268,3 +289,4 @@
 
 
 
+
--- trunk/koffice/kformula/flake/RowElement.h #1008943:1008944
@@ -71,32 +71,32 @@
 
     /// inherited from BasicElement
     virtual QList< BasicElement* > elementsBetween ( int pos1, int pos2 ) const;
-    
+
     /// inherited from BasicElement
     virtual bool insertChild( int position, BasicElement* child );
-    
+
     /**
      * Remove a child element
      * @param element The BasicElement to remove
      */
     bool removeChild( BasicElement* child);
-    
+
     ///inherited form BasicElement
     virtual bool replaceChild ( BasicElement* oldelement, BasicElement* newelement \
                );
-    
+
     /**
      * Implement the cursor behaviour for the element
      * @param direction Indicates whether the cursor moves up, down, right or left
      * @return A this pointer if the element accepts if not the element to asked \
                instead
      */
     bool acceptCursor( const FormulaCursor& cursor );
-    
+
     /// inherited from BasicElement
     virtual bool moveCursor(FormulaCursor& newcursor, FormulaCursor& oldcursor);
-    
+
     /// inherited from BasicElement
     virtual bool setCursorTo(FormulaCursor& cursor, QPointF point);
-    
+
     /// @return The element's ElementType
     ElementType elementType() const;
 
@@ -105,22 +105,25 @@
      *  This stretches the children inside, then readjusts their vertical offsets
      */
     virtual void stretch();
-    
+
     /// inherited from BasicElement
     virtual int length() const;
-    
+
     /// inherited from BasicElement
     virtual int positionOfChild(BasicElement* child) const;
-    
+
     /// inherited from BasicElement
     virtual QLineF cursorLine(int position) const;
-    
+
     /// inherited from BasicElement
-    virtual BasicElement* elementAfter ( int position );
-    
+    virtual BasicElement* elementAfter ( int position ) const;
+
     /// inherited from BasicElement
-    virtual BasicElement* elementBefore ( int position );
-    
+    virtual BasicElement* elementBefore ( int position ) const;
+
+    /// inherited from BasicElement
+    virtual bool isEmpty() const;
+
 protected:
     /// Read contents of the token element. Content should be unicode text strings \
or mglyphs  bool readMathMLContent( const KoXmlElement& parent );
--- trunk/koffice/kformula/flake/SubSupElement.cpp #1008943:1008944
@@ -94,10 +94,10 @@
     }
 }
 
-bool SubSupElement::acceptCursor( const FormulaCursor* cursor )
-{
-    return true;
-}
+// bool SubSupElement::acceptCursor( const FormulaCursor* cursor )
+// {
+//     return true;
+// }
 
 const QList<BasicElement*> SubSupElement::childElements() const
 {
@@ -108,17 +108,17 @@
     return tmp;
 }
 
-void SubSupElement::insertChild( FormulaCursor* cursor, BasicElement* child )
-{
-    if( cursor->currentElement() == m_baseElement )
-        m_baseElement = child;
-    else if( cursor->currentElement() == m_subScript )
-        m_subScript = child;
-    else if( cursor->currentElement() == m_superScript )
-        m_superScript = child;
-//    else
-//    TODO add some error
-}
+// void SubSupElement::insertChild( FormulaCursor* cursor, BasicElement* child )
+// {
+//     if( cursor->currentElement() == m_baseElement )
+//         m_baseElement = child;
+//     else if( cursor->currentElement() == m_subScript )
+//         m_subScript = child;
+//     else if( cursor->currentElement() == m_superScript )
+//         m_superScript = child;
+// //    else
+// //    TODO add some error
+// }
 
 QString SubSupElement::attributesDefaultValue( const QString& attribute ) const
 {
--- trunk/koffice/kformula/flake/SubSupElement.h #1008943:1008944
@@ -55,14 +55,14 @@
     void layout( const AttributeManager* am );
 
     /// inherited from BasicElement
-    bool acceptCursor( const FormulaCursor* cursor );
+//     bool acceptCursor( const FormulaCursor* cursor );
 
     /**
      * Insert a new child at the cursor position
      * @param cursor The cursor holding the position where to insert
      * @param child A BasicElement to insert
      */
-    void insertChild( FormulaCursor* cursor, BasicElement* child );
+//     void insertChild( FormulaCursor* cursor, BasicElement* child );
 
     /// @return The default value of the attribute for this element
     QString attributesDefaultValue( const QString& attribute ) const; 
--- trunk/koffice/plugins/artistictextshape/ArtisticTextShape.cpp #1008943:1008944
@@ -12,7 +12,7 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Library General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public License
+ * Yoßu should have received a copy of the GNU Library General Public License
  * along with this library; see the file COPYING.LIB.  If not, write to
  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301, USA.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic