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

Kohei Yoshida kohei.yoshida at gmail.com
Fri Mar 22 17:54:35 PDT 2013


 sc/inc/dociter.hxx                |    2 +-
 sc/source/core/data/dociter.cxx   |   17 +++++++++++++++--
 sc/source/core/data/documen3.cxx  |   36 ++++++++++++++++++++----------------
 sc/source/core/data/document.cxx  |   15 +++++++--------
 sc/source/core/tool/detfunc.cxx   |   20 ++++++++++----------
 sc/source/core/tool/interpr1.cxx  |   26 +++++++++-----------------
 sc/source/core/tool/rangeseq.cxx  |   10 ++++++----
 sc/source/ui/docshell/tablink.cxx |   27 ++++++++++++---------------
 sc/source/ui/unoobj/funcuno.cxx   |   30 ++++++++++++++----------------
 sc/source/ui/view/tabview4.cxx    |   13 +++++++------
 10 files changed, 101 insertions(+), 95 deletions(-)

New commits:
commit b65381e6e4da159bfd65c31fa9a20beccaa87bf6
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Mar 22 20:54:13 2013 -0400

    More on ScCellIterator usage conversion... Still not done.
    
    Change-Id: I5023a57f3a089f1af7cd7fe53f57f82c60eb2b65

diff --git a/sc/inc/dociter.hxx b/sc/inc/dociter.hxx
index 8e3b28b..1a6d3e7 100644
--- a/sc/inc/dociter.hxx
+++ b/sc/inc/dociter.hxx
@@ -244,7 +244,7 @@ public:
     const ScAddress& GetPos() const { return maCurPos; }
 
     CellType getType() const;
-    const OUString& getString() const;
+    OUString getString();
     const EditTextObject* getEditText() const;
     ScFormulaCell* getFormulaCell();
     bool hasString() const;
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index 6517f5b..a280555 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -1138,9 +1138,22 @@ CellType ScCellIterator::getType() const
     return meCurType;
 }
 
-const OUString& ScCellIterator::getString() const
+OUString ScCellIterator::getString()
 {
-    return maCurString;
+    switch (meCurType)
+    {
+        case CELLTYPE_STRING:
+            return maCurString;
+        case CELLTYPE_EDIT:
+            if (mpCurEditText)
+                return ScEditUtil::GetString(*mpCurEditText);
+        break;
+        case CELLTYPE_FORMULA:
+            return mpCurFormula->GetString();
+        default:
+            ;
+    }
+    return EMPTY_OUSTRING;
 }
 
 const EditTextObject* ScCellIterator::getEditText() const
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index f2fc819..3196b2e 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -742,13 +742,13 @@ bool ScDocument::DoSubTotals( SCTAB nTab, ScSubTotalParam& rParam )
 bool ScDocument::HasSubTotalCells( const ScRange& rRange )
 {
     ScCellIterator aIter( this, rRange );
-    ScBaseCell* pCell = aIter.GetFirst();
-    while (pCell)
+    for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
     {
-        if ( pCell->GetCellType() == CELLTYPE_FORMULA && ((ScFormulaCell*)pCell)->IsSubTotal() )
-            return true;
+        if (aIter.getType() != CELLTYPE_FORMULA)
+            continue;
 
-        pCell = aIter.GetNext();
+        if (aIter.getFormulaCell()->IsSubTotal())
+            return true;
     }
     return false;   // none found
 }
@@ -1576,19 +1576,23 @@ bool ScDocument::GetFormulaEntries( ScTypedCaseStrSet& rStrings )
     for (sal_uInt16 nListNo=0; nListNo<2; nListNo++)
     {
         ScRangePairList* pList = pLists[ nListNo ];
-        if (pList)
-            for ( size_t i = 0, nPairs = pList->size(); i < nPairs; ++i )
+        if (!pList)
+            continue;
+
+        for ( size_t i = 0, nPairs = pList->size(); i < nPairs; ++i )
+        {
+            ScRangePair* pPair = (*pList)[i];
+            ScRange aRange = pPair->GetRange(0);
+            ScCellIterator aIter( this, aRange );
+            for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
             {
-                ScRangePair* pPair = (*pList)[i];
-                ScRange aRange = pPair->GetRange(0);
-                ScCellIterator aIter( this, aRange );
-                for ( ScBaseCell* pCell = aIter.GetFirst(); pCell; pCell = aIter.GetNext() )
-                    if ( pCell->HasStringData() )
-                    {
-                        OUString aStr = pCell->GetStringData();
-                        rStrings.insert(ScTypedStrData(aStr, 0.0, ScTypedStrData::Header));
-                    }
+                if (!aIter.hasString())
+                    continue;
+
+                OUString aStr = aIter.getString();
+                rStrings.insert(ScTypedStrData(aStr, 0.0, ScTypedStrData::Header));
             }
+        }
     }
 
     return true;
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index a0ec234..6ebbf39 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3418,15 +3418,14 @@ void ScDocument::InterpretDirtyCells( const ScRangeList& rRanges )
     for (size_t nPos=0, nRangeCount = rRanges.size(); nPos < nRangeCount; nPos++)
     {
         ScCellIterator aIter( this, *rRanges[ nPos ] );
-        ScBaseCell* pCell = aIter.GetFirst();
-        while (pCell)
+        for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
         {
-            if (pCell->GetCellType() == CELLTYPE_FORMULA)
-            {
-                if ( static_cast<ScFormulaCell*>(pCell)->GetDirty() && GetAutoCalc() )
-                    static_cast<ScFormulaCell*>(pCell)->Interpret();
-            }
-            pCell = aIter.GetNext();
+            if (aIter.getType() != CELLTYPE_FORMULA)
+                continue;
+
+            ScFormulaCell* p = aIter.getFormulaCell();
+            if (p->GetDirty() && GetAutoCalc())
+                p->Interpret();
         }
     }
 }
diff --git a/sc/source/core/tool/detfunc.cxx b/sc/source/core/tool/detfunc.cxx
index ee5f820..09881b4 100644
--- a/sc/source/core/tool/detfunc.cxx
+++ b/sc/source/core/tool/detfunc.cxx
@@ -1400,18 +1400,18 @@ sal_Bool ScDetectiveFunc::MarkInvalid(sal_Bool& rOverflow)
 void ScDetectiveFunc::GetAllPreds(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                                   vector<ScTokenRef>& rRefTokens)
 {
-    ScCellIterator aCellIter(pDoc, nCol1, nRow1, nTab, nCol2, nRow2, nTab);
-    for (ScBaseCell* pCell = aCellIter.GetFirst(); pCell; pCell = aCellIter.GetNext())
+    ScCellIterator aIter(pDoc, nCol1, nRow1, nTab, nCol2, nRow2, nTab);
+    for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
     {
-        if (pCell->GetCellType() != CELLTYPE_FORMULA)
+        if (aIter.getType() != CELLTYPE_FORMULA)
             continue;
 
-        ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
+        ScFormulaCell* pFCell = aIter.getFormulaCell();
         ScDetectiveRefIter aRefIter(pFCell);
         for (ScToken* p = aRefIter.GetNextRefToken(); p; p = aRefIter.GetNextRefToken())
         {
             ScTokenRef pRef(static_cast<ScToken*>(p->Clone()));
-            pRef->CalcAbsIfRel(aCellIter.GetPos());
+            pRef->CalcAbsIfRel(aIter.GetPos());
             ScRefTokenHelper::join(rRefTokens, pRef);
         }
     }
@@ -1424,17 +1424,17 @@ void ScDetectiveFunc::GetAllSuccs(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW n
     aSrcRange.push_back(
         ScRefTokenHelper::createRefToken(ScRange(nCol1, nRow1, nTab, nCol2, nRow2, nTab)));
 
-    ScCellIterator aCellIter(pDoc, 0, 0, nTab, MAXCOL, MAXROW, nTab);
-    for (ScBaseCell* pCell = aCellIter.GetFirst(); pCell; pCell = aCellIter.GetNext())
+    ScCellIterator aIter(pDoc, ScRange(0, 0, nTab, MAXCOL, MAXROW, nTab));
+    for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
     {
-        if (pCell->GetCellType() != CELLTYPE_FORMULA)
+        if (aIter.getType() != CELLTYPE_FORMULA)
             continue;
 
-        ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
+        ScFormulaCell* pFCell = aIter.getFormulaCell();
         ScDetectiveRefIter aRefIter(pFCell);
         for (ScToken* p = aRefIter.GetNextRefToken(); p; p = aRefIter.GetNextRefToken())
         {
-            ScAddress aPos = aCellIter.GetPos();
+            const ScAddress& aPos = aIter.GetPos();
             ScTokenRef pRef(static_cast<ScToken*>(p->Clone()));
             pRef->CalcAbsIfRel(aPos);
             if (ScRefTokenHelper::intersects(aSrcRange, pRef))
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 9e793c0..a51f28a 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -4155,16 +4155,12 @@ double ScInterpreter::IterateParameters( ScIterFunc eFunc, bool bTextAsZero )
                 {
                     ScBaseCell* pCell;
                     ScCellIterator aIter( pDok, aRange, glSubTotal );
-                    if ( (pCell = aIter.GetFirst()) != NULL )
+                    for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
                     {
-                        do
-                        {
-                            CellType eType = pCell->GetCellType();
-                            if( eType != CELLTYPE_NONE && eType != CELLTYPE_NOTE )
-                                nCount++;
-                        }
-                        while ( (pCell = aIter.GetNext()) != NULL );
+                        if (!aIter.isEmpty())
+                            ++nCount;
                     }
+
                     if ( nGlobalError )
                         nGlobalError = 0;
                 }
@@ -5373,16 +5369,12 @@ void ScInterpreter::ScCountEmptyCells()
                         static_cast<sal_uLong>(aRange.aEnd.Row() - aRange.aStart.Row() + 1) *
                         static_cast<sal_uLong>(aRange.aEnd.Col() - aRange.aStart.Col() + 1) *
                         static_cast<sal_uLong>(aRange.aEnd.Tab() - aRange.aStart.Tab() + 1);
-                    ScBaseCell* pCell;
-                    ScCellIterator aDocIter( pDok, aRange, glSubTotal);
-                    if ( (pCell = aDocIter.GetFirst()) != NULL )
+
+                    ScCellIterator aIter( pDok, aRange, glSubTotal);
+                    for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
                     {
-                        do
-                        {
-                            if ((eCellType = pCell->GetCellType()) != CELLTYPE_NONE
-                                    && eCellType != CELLTYPE_NOTE)
-                                nCount++;
-                        } while ( (pCell = aDocIter.GetNext()) != NULL );
+                        if (!aIter.isEmpty())
+                            ++nCount;
                     }
                 }
             }
diff --git a/sc/source/core/tool/rangeseq.cxx b/sc/source/core/tool/rangeseq.cxx
index b5df5e9..114354c 100644
--- a/sc/source/core/tool/rangeseq.cxx
+++ b/sc/source/core/tool/rangeseq.cxx
@@ -37,12 +37,14 @@ static bool lcl_HasErrors( ScDocument* pDoc, const ScRange& rRange )
 {
     // no need to look at empty cells - just use ScCellIterator
     ScCellIterator aIter( pDoc, rRange );
-    ScBaseCell* pCell = aIter.GetFirst();
-    while (pCell)
+    for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
     {
-        if ( pCell->GetCellType() == CELLTYPE_FORMULA && static_cast<ScFormulaCell*>(pCell)->GetErrCode() != 0 )
+        if (aIter.getType() != CELLTYPE_FORMULA)
+            continue;
+
+        ScFormulaCell* pCell = aIter.getFormulaCell();
+        if (pCell->GetErrCode() != 0)
             return true;
-        pCell = aIter.GetNext();
     }
     return false;   // no error found
 }
diff --git a/sc/source/ui/docshell/tablink.cxx b/sc/source/ui/docshell/tablink.cxx
index 9105ee2..628a15f 100644
--- a/sc/source/ui/docshell/tablink.cxx
+++ b/sc/source/ui/docshell/tablink.cxx
@@ -302,27 +302,24 @@ sal_Bool ScTableLink::Refresh(const String& rNewFile, const String& rNewFilter,
 
                     ScRangeList aErrorCells;        // cells on the linked sheets that need error values
 
-                    ScCellIterator aCellIter( pDoc, 0,0,0, MAXCOL,MAXROW,MAXTAB );          // all sheets
-                    ScBaseCell* pCell = aCellIter.GetFirst();
-                    while (pCell)
+                    ScCellIterator aIter(pDoc, ScRange(0,0,0,MAXCOL,MAXROW,MAXTAB));          // all sheets
+                    for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
                     {
-                        if (pCell->GetCellType() == CELLTYPE_FORMULA)
-                        {
-                            ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
+                        if (aIter.getType() != CELLTYPE_FORMULA)
+                            continue;
 
-                            ScDetectiveRefIter aRefIter( pFCell );
-                            ScRange aRefRange;
-                            while ( aRefIter.GetNextRef( aRefRange ) )
+                        ScFormulaCell* pCell = aIter.getFormulaCell();
+                        ScDetectiveRefIter aRefIter(pCell);
+                        ScRange aRefRange;
+                        while ( aRefIter.GetNextRef( aRefRange ) )
+                        {
+                            if ( aRefRange.aStart.Tab() <= nTab && aRefRange.aEnd.Tab() >= nTab )
                             {
-                                if ( aRefRange.aStart.Tab() <= nTab && aRefRange.aEnd.Tab() >= nTab )
-                                {
-                                    // use first cell of range references (don't fill potentially large ranges)
+                                // use first cell of range references (don't fill potentially large ranges)
 
-                                    aErrorCells.Join( ScRange( aRefRange.aStart ) );
-                                }
+                                aErrorCells.Join( ScRange( aRefRange.aStart ) );
                             }
                         }
-                        pCell = aCellIter.GetNext();
                     }
 
                     size_t nRanges = aErrorCells.size();
diff --git a/sc/source/ui/unoobj/funcuno.cxx b/sc/source/ui/unoobj/funcuno.cxx
index 776f946..40fa41c 100644
--- a/sc/source/ui/unoobj/funcuno.cxx
+++ b/sc/source/ui/unoobj/funcuno.cxx
@@ -175,27 +175,25 @@ static sal_Bool lcl_CopyData( ScDocument* pSrcDoc, const ScRange& rSrcRange,
     // If the range contains formula cells with default number format,
     // apply a number format for the formula result
     ScCellIterator aIter( pClipDoc, rSrcRange );
-    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;
+
+        ScAddress aCellPos = aIter.GetPos();
+        sal_uInt32 nFormat = pClipDoc->GetNumberFormat(aCellPos);
+        if ( (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
         {
-            ScAddress aCellPos = aIter.GetPos();
-            sal_uInt32 nFormat = pClipDoc->GetNumberFormat(aCellPos);
-            if ( (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
+            ScFormulaCell* pFCell = aIter.getFormulaCell();
+            sal_uInt16 nErrCode = pFCell->GetErrCode();
+            if ( nErrCode == 0 && pFCell->IsValue() )
             {
-                ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
-                sal_uInt16 nErrCode = pFCell->GetErrCode();
-                if ( nErrCode == 0 && pFCell->IsValue() )
-                {
-                    sal_uInt32 nNewFormat = pFCell->GetStandardFormat( *pClipDoc->GetFormatTable(), nFormat );
-                    if ( nNewFormat != nFormat )
-                        pClipDoc->ApplyAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(),
-                                             SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) );
-                }
+                sal_uInt32 nNewFormat = pFCell->GetStandardFormat( *pClipDoc->GetFormatTable(), nFormat );
+                if ( nNewFormat != nFormat )
+                    pClipDoc->ApplyAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(),
+                                         SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) );
             }
         }
-        pCell = aIter.GetNext();
     }
 
     ScMarkData aDestMark;
diff --git a/sc/source/ui/view/tabview4.cxx b/sc/source/ui/view/tabview4.cxx
index 8d8de0f..900e03d 100644
--- a/sc/source/ui/view/tabview4.cxx
+++ b/sc/source/ui/view/tabview4.cxx
@@ -506,14 +506,15 @@ void ScTabView::InterpretVisible()
             if (nX2 > MAXCOL) nX2 = MAXCOL;
             if (nY2 > MAXROW) nY2 = MAXROW;
 
-            ScCellIterator aIter( pDoc, nX1, nY1, nTab, nX2, nY2, nTab );
-            ScBaseCell* pCell = aIter.GetFirst();
-            while ( pCell )
+            ScCellIterator aIter(pDoc, ScRange(nX1, nY1, nTab, nX2, nY2, nTab));
+            for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
             {
-                if ( pCell->GetCellType() == CELLTYPE_FORMULA && ((ScFormulaCell*)pCell)->GetDirty() )
-                    ((ScFormulaCell*)pCell)->Interpret();
+                if (aIter.getType() != CELLTYPE_FORMULA)
+                    continue;
 
-                pCell = aIter.GetNext();
+                ScFormulaCell* p = aIter.getFormulaCell();
+                if (p->GetDirty())
+                    p->Interpret();
             }
         }
     }


More information about the Libreoffice-commits mailing list