[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - 2 commits - sc/inc sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Mon Mar 25 07:36:47 PDT 2013


 sc/inc/dociter.hxx               |    2 
 sc/source/core/data/dociter.cxx  |   26 +++++
 sc/source/core/inc/interpre.hxx  |    3 
 sc/source/core/tool/interpr4.cxx |  173 +++++++++++++++++++++++++++------------
 sc/source/core/tool/interpr5.cxx |   12 +-
 sc/source/ui/view/viewfun4.cxx   |   41 ++++-----
 6 files changed, 180 insertions(+), 77 deletions(-)

New commits:
commit 194196cfdb25d8bd741d87aa4d3dc717bd3c3834
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Mar 25 10:37:25 2013 -0400

    Add variant of GetCellValue() that takes ScCellIterator instead of ScBaseCell.
    
    And hopefully we can eventually remove the original one that takes ScBaseCell
    somehow...
    
    Change-Id: I162c8072aa2c699abfd3eb202b90a6331123eb1b

diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index 906f4d6..760a0c7 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -51,6 +51,7 @@ struct ScComplexRefData;
 
 class ScToken;
 class ScJumpMatrix;
+class ScCellIterator;
 
 #define MAXSTACK      (4096 / sizeof(formula::FormulaToken*))
 
@@ -186,7 +187,9 @@ bool IsTableOpInRange( const ScRange& );
 sal_uLong GetCellNumberFormat( const ScAddress&, const ScBaseCell* );
 double ConvertStringToValue( const String& );
 double GetCellValue( const ScAddress&, const ScBaseCell* );
+double GetCellValue( ScCellIterator& rIter );
 double GetCellValueOrZero( const ScAddress&, const ScBaseCell* );
+double GetCellValueOrZero( ScCellIterator& rIter );
 double GetValueCellValue( const ScAddress&, const ScValueCell* );
 ScBaseCell* GetCell( const ScAddress& rPos );
 void GetCellString( String& rStr, const ScBaseCell* pCell );
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 752c595..bfd9494 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -470,77 +470,152 @@ double ScInterpreter::GetCellValue( const ScAddress& rPos, const ScBaseCell* pCe
     return nVal;
 }
 
+double ScInterpreter::GetCellValue( ScCellIterator& rIter )
+{
+    sal_uInt16 nErr = nGlobalError;
+    nGlobalError = 0;
+    double nVal = GetCellValueOrZero(rIter);
+    if ( !nGlobalError || nGlobalError == errCellNoValue )
+        nGlobalError = nErr;
+    return nVal;
+}
 
 double ScInterpreter::GetCellValueOrZero( const ScAddress& rPos, const ScBaseCell* pCell )
 {
     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::GetCellValueOrZero" );
     double fValue = 0.0;
-    if (pCell)
+    if (!pCell)
+        return fValue;
+
+    CellType eType = pCell->GetCellType();
+    switch (eType)
     {
-        CellType eType = pCell->GetCellType();
-        switch ( eType )
+        case CELLTYPE_FORMULA:
         {
-            case CELLTYPE_FORMULA:
+            ScFormulaCell* pFCell = (ScFormulaCell*) pCell;
+            sal_uInt16 nErr = pFCell->GetErrCode();
+            if( !nErr )
             {
-                ScFormulaCell* pFCell = (ScFormulaCell*) pCell;
-                sal_uInt16 nErr = pFCell->GetErrCode();
-                if( !nErr )
+                if (pFCell->IsValue())
                 {
-                    if (pFCell->IsValue())
-                    {
-                        fValue = pFCell->GetValue();
-                        pDok->GetNumberFormatInfo( nCurFmtType, nCurFmtIndex,
-                            rPos, pFCell );
-                    }
-                    else
-                    {
-                        String aStr = pFCell->GetString();
-                        fValue = ConvertStringToValue( aStr );
-                    }
+                    fValue = pFCell->GetValue();
+                    pDok->GetNumberFormatInfo( nCurFmtType, nCurFmtIndex,
+                        rPos, pFCell );
                 }
                 else
                 {
-                    fValue = 0.0;
-                    SetError(nErr);
+                    String aStr = pFCell->GetString();
+                    fValue = ConvertStringToValue( aStr );
                 }
             }
-            break;
-            case CELLTYPE_VALUE:
+            else
             {
-                fValue = ((ScValueCell*)pCell)->GetValue();
-                nCurFmtIndex = pDok->GetNumberFormat( rPos );
-                nCurFmtType = pFormatter->GetType( nCurFmtIndex );
-                if ( bCalcAsShown && fValue != 0.0 )
-                    fValue = pDok->RoundValueAsShown( fValue, nCurFmtIndex );
+                fValue = 0.0;
+                SetError(nErr);
             }
-            break;
-            case  CELLTYPE_STRING:
-            case  CELLTYPE_EDIT:
+        }
+        break;
+        case CELLTYPE_VALUE:
+        {
+            fValue = ((ScValueCell*)pCell)->GetValue();
+            nCurFmtIndex = pDok->GetNumberFormat( rPos );
+            nCurFmtType = pFormatter->GetType( nCurFmtIndex );
+            if ( bCalcAsShown && fValue != 0.0 )
+                fValue = pDok->RoundValueAsShown( fValue, nCurFmtIndex );
+        }
+        break;
+        case  CELLTYPE_STRING:
+        case  CELLTYPE_EDIT:
+        {
+            // SUM(A1:A2) differs from A1+A2. No good. But people insist on
+            // it ... #i5658#
+            String aStr;
+            if ( eType == CELLTYPE_STRING )
+                aStr = ((ScStringCell*)pCell)->GetString();
+            else
+                aStr = ((ScEditCell*)pCell)->GetString();
+            fValue = ConvertStringToValue( aStr );
+        }
+        break;
+        case CELLTYPE_NONE:
+        case CELLTYPE_NOTE:
+            fValue = 0.0;       // empty or broadcaster cell
+        break;
+#if OSL_DEBUG_LEVEL > 0
+        case CELLTYPE_DESTROYED:
+#endif
+            SetError(errCellNoValue);
+            fValue = 0.0;
+        break;
+    }
+
+    return fValue;
+}
+
+double ScInterpreter::GetCellValueOrZero( ScCellIterator& rIter )
+{
+    RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::GetCellValueOrZero" );
+    double fValue = 0.0;
+
+    CellType eType = rIter.getType();
+    const ScAddress& rPos = rIter.GetPos();
+    switch (eType)
+    {
+        case CELLTYPE_FORMULA:
+        {
+            ScFormulaCell* pFCell = rIter.getFormulaCell();
+            sal_uInt16 nErr = pFCell->GetErrCode();
+            if( !nErr )
             {
-                // SUM(A1:A2) differs from A1+A2. No good. But people insist on
-                // it ... #i5658#
-                String aStr;
-                if ( eType == CELLTYPE_STRING )
-                    aStr = ((ScStringCell*)pCell)->GetString();
+                if (pFCell->IsValue())
+                {
+                    fValue = pFCell->GetValue();
+                    pDok->GetNumberFormatInfo( nCurFmtType, nCurFmtIndex,
+                        rPos, pFCell );
+                }
                 else
-                    aStr = ((ScEditCell*)pCell)->GetString();
-                fValue = ConvertStringToValue( aStr );
+                {
+                    String aStr = pFCell->GetString();
+                    fValue = ConvertStringToValue( aStr );
+                }
             }
-            break;
-            case CELLTYPE_NONE:
-            case CELLTYPE_NOTE:
-                fValue = 0.0;       // empty or broadcaster cell
-            break;
-#if OSL_DEBUG_LEVEL > 0
-            case CELLTYPE_DESTROYED:
-#endif
-                SetError(errCellNoValue);
+            else
+            {
                 fValue = 0.0;
-            break;
+                SetError(nErr);
+            }
+        }
+        break;
+        case CELLTYPE_VALUE:
+        {
+            fValue = rIter.getValue();
+            nCurFmtIndex = pDok->GetNumberFormat( rPos );
+            nCurFmtType = pFormatter->GetType( nCurFmtIndex );
+            if ( bCalcAsShown && fValue != 0.0 )
+                fValue = pDok->RoundValueAsShown( fValue, nCurFmtIndex );
+        }
+        break;
+        case  CELLTYPE_STRING:
+        case  CELLTYPE_EDIT:
+        {
+            // SUM(A1:A2) differs from A1+A2. No good. But people insist on
+            // it ... #i5658#
+            OUString aStr = rIter.getString();
+            fValue = ConvertStringToValue( aStr );
         }
+        break;
+        case CELLTYPE_NONE:
+        case CELLTYPE_NOTE:
+            fValue = 0.0;       // empty or broadcaster cell
+        break;
+#if OSL_DEBUG_LEVEL > 0
+        case CELLTYPE_DESTROYED:
+#endif
+            SetError(errCellNoValue);
+            fValue = 0.0;
+        break;
     }
-    else
-        fValue = 0.0;
+
     return fValue;
 }
 
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index 74bccc7..28e3b97 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -437,10 +437,7 @@ ScMatrixRef ScInterpreter::CreateMatrixFromDoubleRef( const FormulaToken* pToken
             if (aCellIter.hasNumeric())
             {
                 ScAddress aAdr(nCol, nThisRow, nTab1);
-
-                // TODO: Come back to this and fix it.
-                ScBaseCell* pBC = pDok->GetCell(aAdr);
-                double fVal = GetCellValue(aAdr, pBC);
+                double fVal = GetCellValue(aCellIter);
 
                 if ( nGlobalError )
                 {
commit 27eef91bc0d8fcef920b8fe0659ae049cc7ec8e2
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Mar 25 09:30:57 2013 -0400

    More on ScCellIterator usage migration.
    
    Change-Id: I4ee6b1b3ae110ebfb59a84d6e9fd509ce38ca28c

diff --git a/sc/inc/dociter.hxx b/sc/inc/dociter.hxx
index c490a9d..6f17e2d 100644
--- a/sc/inc/dociter.hxx
+++ b/sc/inc/dociter.hxx
@@ -247,6 +247,8 @@ public:
     OUString getString();
     const EditTextObject* getEditText() const;
     ScFormulaCell* getFormulaCell();
+    double getValue() const;
+
     bool hasString() const;
     bool hasNumeric() const;
     bool isEmpty() const;
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index 8e503b8..fb39c8a 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -1166,6 +1166,20 @@ ScFormulaCell* ScCellIterator::getFormulaCell()
     return mpCurFormula;
 }
 
+double ScCellIterator::getValue() const
+{
+    switch (meCurType)
+    {
+        case CELLTYPE_VALUE:
+            return mfCurValue;
+        case CELLTYPE_FORMULA:
+            return mpCurFormula->GetValue();
+        default:
+            ;
+    }
+    return 0.0;
+}
+
 bool ScCellIterator::hasString() const
 {
     switch (meCurType)
@@ -1199,7 +1213,17 @@ bool ScCellIterator::hasNumeric() const
 
 bool ScCellIterator::isEmpty() const
 {
-    return meCurType == CELLTYPE_NOTE || meCurType == CELLTYPE_NONE;
+    switch (meCurType)
+    {
+        case CELLTYPE_NOTE:
+        case CELLTYPE_NONE:
+            return true;
+        case CELLTYPE_FORMULA:
+            return mpCurFormula->IsEmpty();
+        default:
+            ;
+    }
+    return false;
 }
 
 namespace {
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index 7a716ed..74bccc7 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -424,20 +424,24 @@ ScMatrixRef ScInterpreter::CreateMatrixFromDoubleRef( const FormulaToken* pToken
 
         // Neighboring cell values of identical type are stored and passed as
         // an array to the matrix object, for performance reasons.
-        for (ScBaseCell* pCell = aCellIter.GetFirst(); pCell; pCell = aCellIter.GetNext(), nPrevRow = nThisRow)
+        for (bool bHas = aCellIter.first(); bHas; bHas = aCellIter.next(), nPrevRow = nThisRow)
         {
             nThisRow = aCellIter.GetPos().Row();
 
-            if (HasCellEmptyData(pCell))
+            if (aCellIter.isEmpty())
             {
                 aBucket.flush(*pMat, static_cast<SCSIZE>(nCol-nCol1));
                 continue;
             }
 
-            if (HasCellValueData(pCell))
+            if (aCellIter.hasNumeric())
             {
                 ScAddress aAdr(nCol, nThisRow, nTab1);
-                double fVal = GetCellValue( aAdr, pCell);
+
+                // TODO: Come back to this and fix it.
+                ScBaseCell* pBC = pDok->GetCell(aAdr);
+                double fVal = GetCellValue(aAdr, pBC);
+
                 if ( nGlobalError )
                 {
                     fVal = CreateDoubleError( nGlobalError);
@@ -459,8 +463,7 @@ ScMatrixRef ScInterpreter::CreateMatrixFromDoubleRef( const FormulaToken* pToken
                 continue;
             }
 
-            String aStr;
-            GetCellString( aStr, pCell);
+            String aStr = aCellIter.getString();
             if ( nGlobalError )
             {
                 double fVal = CreateDoubleError( nGlobalError);
diff --git a/sc/source/ui/view/viewfun4.cxx b/sc/source/ui/view/viewfun4.cxx
index 944c508..d05795e 100644
--- a/sc/source/ui/view/viewfun4.cxx
+++ b/sc/source/ui/view/viewfun4.cxx
@@ -240,30 +240,29 @@ void ScViewFunc::DoRefConversion( sal_Bool bRecord )
             aRange.aStart.SetTab(i);
             aRange.aEnd.SetTab(i);
             ScCellIterator aIter( pDoc, aRange );
-            ScBaseCell* pCell = aIter.GetFirst();
-            while ( pCell )
+            for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
             {
-                if (pCell->GetCellType() == CELLTYPE_FORMULA)
+                if (aIter.getType() != CELLTYPE_FORMULA)
+                    continue;
+
+                ScFormulaCell* pCell = aIter.getFormulaCell();
+                OUString aOld;
+                pCell->GetFormula(aOld);
+                sal_Int32 nLen = aOld.getLength();
+                ScRefFinder aFinder( aOld, aIter.GetPos(), pDoc, pDoc->GetAddressConvention() );
+                aFinder.ToggleRel( 0, nLen );
+                if (aFinder.GetFound())
                 {
-                    rtl::OUString aOld;
-                    ((ScFormulaCell*)pCell)->GetFormula(aOld);
-                    xub_StrLen nLen = aOld.getLength();
-                    ScRefFinder aFinder( aOld, aIter.GetPos(), pDoc, pDoc->GetAddressConvention() );
-                    aFinder.ToggleRel( 0, nLen );
-                    if (aFinder.GetFound())
-                    {
-                        ScAddress aPos = ((ScFormulaCell*)pCell)->aPos;
-                        String aNew = aFinder.GetText();
-                        ScCompiler aComp( pDoc, aPos);
-                        aComp.SetGrammar(pDoc->GetGrammar());
-                        ScTokenArray* pArr = aComp.CompileString( aNew );
-                        ScFormulaCell* pNewCell = new ScFormulaCell( pDoc, aPos,
-                                                    pArr,formula::FormulaGrammar::GRAM_DEFAULT, MM_NONE );
-                        pDoc->SetFormulaCell(aPos, pNewCell);
-                        bOk = true;
-                    }
+                    ScAddress aPos = pCell->aPos;
+                    String aNew = aFinder.GetText();
+                    ScCompiler aComp( pDoc, aPos);
+                    aComp.SetGrammar(pDoc->GetGrammar());
+                    ScTokenArray* pArr = aComp.CompileString( aNew );
+                    ScFormulaCell* pNewCell = new ScFormulaCell( pDoc, aPos,
+                                                pArr,formula::FormulaGrammar::GRAM_DEFAULT, MM_NONE );
+                    pDoc->SetFormulaCell(aPos, pNewCell);
+                    bOk = true;
                 }
-                pCell = aIter.GetNext();
             }
         }
     }


More information about the Libreoffice-commits mailing list