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

Kohei Yoshida kohei.yoshida at gmail.com
Tue Mar 26 15:42:40 PDT 2013


 sc/inc/cellvalue.hxx              |    4 +
 sc/inc/dociter.hxx                |    2 
 sc/source/core/data/cellvalue.cxx |   32 +++++++++++++++
 sc/source/core/data/dociter.cxx   |   28 +------------
 sc/source/core/tool/rangeseq.cxx  |   44 +++++++--------------
 sc/source/ui/view/tabvwsh5.cxx    |   77 +++++++++++++++-----------------------
 6 files changed, 86 insertions(+), 101 deletions(-)

New commits:
commit 7fbb6dc56fde660076eb46f3e6d519bc472f3eda
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Mar 26 18:42:19 2013 -0400

    More on killing direct use of cell classes.
    
    Change-Id: Ie2b6819652f330a493b7f9fe557736b27e402803

diff --git a/sc/inc/cellvalue.hxx b/sc/inc/cellvalue.hxx
index 84127cd..d4ef307 100644
--- a/sc/inc/cellvalue.hxx
+++ b/sc/inc/cellvalue.hxx
@@ -124,6 +124,10 @@ struct SC_DLLPUBLIC ScRefCellValue
 
     bool hasNumeric() const;
 
+    double getValue();
+
+    OUString getString();
+
     bool isEmpty() const;
 
     bool equalsWithoutFormat( const ScRefCellValue& r ) const;
diff --git a/sc/inc/dociter.hxx b/sc/inc/dociter.hxx
index b50c68a..7161ac2 100644
--- a/sc/inc/dociter.hxx
+++ b/sc/inc/dociter.hxx
@@ -237,7 +237,7 @@ public:
     const EditTextObject* getEditText() const;
     ScFormulaCell* getFormulaCell();
     const ScFormulaCell* getFormulaCell() const;
-    double getValue() const;
+    double getValue();
     ScCellValue getCellValue() const;
     const ScRefCellValue& getRefCellValue() const;
 
diff --git a/sc/source/core/data/cellvalue.cxx b/sc/source/core/data/cellvalue.cxx
index 5b853a3..e4f0c2e 100644
--- a/sc/source/core/data/cellvalue.cxx
+++ b/sc/source/core/data/cellvalue.cxx
@@ -477,6 +477,38 @@ bool ScRefCellValue::hasNumeric() const
     return hasNumericImpl(meType, mpFormula);
 }
 
+double ScRefCellValue::getValue()
+{
+    switch (meType)
+    {
+        case CELLTYPE_VALUE:
+            return mfValue;
+        case CELLTYPE_FORMULA:
+            return mpFormula->GetValue();
+        default:
+            ;
+    }
+    return 0.0;
+}
+
+OUString ScRefCellValue::getString()
+{
+    switch (meType)
+    {
+        case CELLTYPE_STRING:
+            return *mpString;
+        case CELLTYPE_EDIT:
+            if (mpEditText)
+                return ScEditUtil::GetString(*mpEditText);
+        break;
+        case CELLTYPE_FORMULA:
+            return mpFormula->GetString();
+        default:
+            ;
+    }
+    return EMPTY_OUSTRING;
+}
+
 bool ScRefCellValue::isEmpty() const
 {
     return meType == CELLTYPE_NOTE || meType == CELLTYPE_NONE;
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index 8cfa1eb..6d8f758 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -1060,20 +1060,7 @@ CellType ScCellIterator::getType() const
 
 OUString ScCellIterator::getString()
 {
-    switch (maCurCell.meType)
-    {
-        case CELLTYPE_STRING:
-            return *maCurCell.mpString;
-        case CELLTYPE_EDIT:
-            if (maCurCell.mpEditText)
-                return ScEditUtil::GetString(*maCurCell.mpEditText);
-        break;
-        case CELLTYPE_FORMULA:
-            return maCurCell.mpFormula->GetString();
-        default:
-            ;
-    }
-    return EMPTY_OUSTRING;
+    return maCurCell.getString();
 }
 
 const EditTextObject* ScCellIterator::getEditText() const
@@ -1091,18 +1078,9 @@ const ScFormulaCell* ScCellIterator::getFormulaCell() const
     return maCurCell.mpFormula;
 }
 
-double ScCellIterator::getValue() const
+double ScCellIterator::getValue()
 {
-    switch (maCurCell.meType)
-    {
-        case CELLTYPE_VALUE:
-            return maCurCell.mfValue;
-        case CELLTYPE_FORMULA:
-            return maCurCell.mpFormula->GetValue();
-        default:
-            ;
-    }
-    return 0.0;
+    return maCurCell.getValue();
 }
 
 ScCellValue ScCellIterator::getCellValue() const
diff --git a/sc/source/core/tool/rangeseq.cxx b/sc/source/core/tool/rangeseq.cxx
index 114354c..9e08c89 100644
--- a/sc/source/core/tool/rangeseq.cxx
+++ b/sc/source/core/tool/rangeseq.cxx
@@ -243,22 +243,6 @@ sal_Bool ScRangeToSequence::FillStringArray( uno::Any& rAny, const ScMatrix* pMa
     return sal_True;
 }
 
-//------------------------------------------------------------------------
-
-static double lcl_GetValueFromCell( ScBaseCell& rCell )
-{
-    //! ScBaseCell member function?
-
-    CellType eType = rCell.GetCellType();
-    if ( eType == CELLTYPE_VALUE )
-        return ((ScValueCell&)rCell).GetValue();
-    else if ( eType == CELLTYPE_FORMULA )
-        return ((ScFormulaCell&)rCell).GetValue();      // called only if result is value
-
-    OSL_FAIL( "GetValueFromCell: wrong type" );
-    return 0;
-}
-
 sal_Bool ScRangeToSequence::FillMixedArray( uno::Any& rAny, ScDocument* pDoc, const ScRange& rRange,
                                         sal_Bool bAllowNV )
 {
@@ -281,22 +265,24 @@ sal_Bool ScRangeToSequence::FillMixedArray( uno::Any& rAny, ScDocument* pDoc, co
             uno::Any& rElement = pColAry[nCol];
 
             ScAddress aPos( (SCCOL)(nStartCol+nCol), (SCROW)(nStartRow+nRow), nTab );
-            ScBaseCell* pCell = pDoc->GetCell( aPos );
-            if ( pCell )
+            ScRefCellValue aCell;
+            aCell.assign(*pDoc, aPos);
+
+            if (aCell.isEmpty())
             {
-                if ( pCell->GetCellType() == CELLTYPE_FORMULA &&
-                        ((ScFormulaCell*)pCell)->GetErrCode() != 0 )
-                {
-                    // if NV is allowed, leave empty for errors
-                    bHasErrors = sal_True;
-                }
-                else if ( pCell->HasValueData() )
-                    rElement <<= (double) lcl_GetValueFromCell( *pCell );
-                else
-                    rElement <<= rtl::OUString( pCell->GetStringData() );
+                rElement <<= EMPTY_OUSTRING;
+                continue;
+            }
+
+            if (aCell.meType == CELLTYPE_FORMULA && aCell.mpFormula->GetErrCode() != 0)
+            {
+                // if NV is allowed, leave empty for errors
+                bHasErrors = true;
             }
+            else if (aCell.hasNumeric())
+                rElement <<= aCell.getValue();
             else
-                rElement <<= rtl::OUString();       // empty: empty string
+                rElement <<= aCell.getString();
         }
         pRowAry[nRow] = aColSeq;
     }
diff --git a/sc/source/ui/view/tabvwsh5.cxx b/sc/source/ui/view/tabvwsh5.cxx
index 2eeb98b..4787b61 100644
--- a/sc/source/ui/view/tabvwsh5.cxx
+++ b/sc/source/ui/view/tabvwsh5.cxx
@@ -37,7 +37,7 @@
 #include "uiitems.hxx"
 #include "editsh.hxx"
 #include "hints.hxx"
-
+#include "cellvalue.hxx"
 
 //==================================================================
 
@@ -314,62 +314,47 @@ void ScTabViewShell::MakeNumberInfoItem( ScDocument*         pDoc,
     //------------------------------
     // NumberInfo-Item konstruieren:
     //------------------------------
-    ScBaseCell*         pCell = NULL;
     SvxNumberValueType  eValType        = SVX_VALUE_TYPE_UNDEFINED;
     double              nCellValue      = 0;
-    String              aCellString;
+    OUString aCellString;
 
-    pDoc->GetCell( pViewData->GetCurX(),
-                   pViewData->GetCurY(),
-                   pViewData->GetTabNo(),
-                   pCell );
+    ScRefCellValue aCell;
+    aCell.assign(*pDoc, pViewData->GetCurPos());
 
-    if ( pCell )
+    switch (aCell.meType)
     {
-        switch ( pCell->GetCellType() )
+        case CELLTYPE_VALUE:
         {
-            case CELLTYPE_VALUE:
-                {
-                    nCellValue = ((ScValueCell*)pCell)->GetValue();
-                    eValType = SVX_VALUE_TYPE_NUMBER;
-                    aCellString.Erase();
-                }
-                break;
-
-            case CELLTYPE_STRING:
-                {
-                    aCellString = ((ScStringCell*)pCell)->GetString();
-                    eValType = SVX_VALUE_TYPE_STRING;
-                }
-                break;
+            nCellValue = aCell.mfValue;
+            eValType = SVX_VALUE_TYPE_NUMBER;
+        }
+        break;
 
-            case CELLTYPE_FORMULA:
-                {
-                    if ( ((ScFormulaCell*)pCell)->IsValue() )
-                    {
-                        nCellValue = ((ScFormulaCell*)pCell)->GetValue();
-                        eValType = SVX_VALUE_TYPE_NUMBER;
-                    }
-                    else
-                    {
-                        nCellValue = 0;
-                        eValType   = SVX_VALUE_TYPE_UNDEFINED;
-                    }
-                    aCellString.Erase();
-                }
-                break;
+        case CELLTYPE_STRING:
+        {
+            aCellString = *aCell.mpString;
+            eValType = SVX_VALUE_TYPE_STRING;
+        }
+        break;
 
-            default:
+        case CELLTYPE_FORMULA:
+        {
+            if (aCell.mpFormula->IsValue())
+            {
+                nCellValue = aCell.mpFormula->GetValue();
+                eValType = SVX_VALUE_TYPE_NUMBER;
+            }
+            else
+            {
                 nCellValue = 0;
                 eValType   = SVX_VALUE_TYPE_UNDEFINED;
-                aCellString.Erase();
+            }
         }
-    }
-    else // Zelle noch leer (== nicht erzeugt)
-    {
-        nCellValue = 0;
-        eValType   = SVX_VALUE_TYPE_UNDEFINED;
-        aCellString.Erase();
+        break;
+
+        default:
+            nCellValue = 0;
+            eValType   = SVX_VALUE_TYPE_UNDEFINED;
     }
 
     switch ( eValType )


More information about the Libreoffice-commits mailing list