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

Kohei Yoshida kohei.yoshida at gmail.com
Mon Mar 25 07:57:32 PDT 2013


 sc/inc/dociter.hxx              |    3 +
 sc/inc/validat.hxx              |    3 +
 sc/source/core/data/dociter.cxx |    5 ++
 sc/source/core/data/validat.cxx |   85 ++++++++++++++++++++++++++++++++++++++++
 sc/source/core/tool/detfunc.cxx |    6 --
 5 files changed, 98 insertions(+), 4 deletions(-)

New commits:
commit 1290cea27859439f2c56d3d3243048cacb5ccc23
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Mar 25 10:59:15 2013 -0400

    Another one involving cell data validation in detective functionality.
    
    Change-Id: I1987f45e436744d4029f8b7af812867ebcfb09c4

diff --git a/sc/inc/dociter.hxx b/sc/inc/dociter.hxx
index 6f17e2d..a0ffa5c 100644
--- a/sc/inc/dociter.hxx
+++ b/sc/inc/dociter.hxx
@@ -256,6 +256,9 @@ public:
 
     bool first();
     bool next();
+
+    // TODO: Remove this later.
+    ScBaseCell* getHackedBaseCell();
 };
 
 class ScQueryCellIterator           // walk through all non-empty cells in an area
diff --git a/sc/inc/validat.hxx b/sc/inc/validat.hxx
index 90d8ce7..8c73b7d 100644
--- a/sc/inc/validat.hxx
+++ b/sc/inc/validat.hxx
@@ -29,6 +29,7 @@ namespace ValidListType = ::com::sun::star::sheet::TableValidationVisibility;
 class ScPatternAttr;
 class ScTokenArray;
 class ScTypedStrData;
+class ScCellIterator;
 
 enum ScValidationMode
 {
@@ -129,6 +130,8 @@ public:
                                     const ScAddress& rPos ) const;
     sal_Bool            IsDataValid( ScBaseCell* pCell, const ScAddress& rPos ) const;
 
+    bool IsDataValid( ScCellIterator& rIter ) const;
+
                     // TRUE -> break
     sal_Bool            DoError( Window* pParent, const String& rInput, const ScAddress& rPos ) const;
     void            DoCalcError( ScFormulaCell* pCell ) const;
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index fb39c8a..ebbfd65 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -1326,6 +1326,11 @@ bool ScCellIterator::next()
     return getCurrent();
 }
 
+ScBaseCell* ScCellIterator::getHackedBaseCell()
+{
+    return mpDoc->GetCell(maCurPos);
+}
+
 //-------------------------------------------------------------------------------
 
 ScQueryCellIterator::ScQueryCellIterator(ScDocument* pDocument, SCTAB nTable,
diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx
index 71b53e5..a2d4b4a 100644
--- a/sc/source/core/data/validat.cxx
+++ b/sc/source/core/data/validat.cxx
@@ -40,6 +40,7 @@
 #include "rangenam.hxx"
 #include "dbdata.hxx"
 #include "typedstrdata.hxx"
+#include "dociter.hxx"
 
 #include <math.h>
 #include <memory>
@@ -545,6 +546,90 @@ sal_Bool ScValidationData::IsDataValid( ScBaseCell* pCell, const ScAddress& rPos
     return bOk;
 }
 
+bool ScValidationData::IsDataValid( ScCellIterator& rIter ) const
+{
+    const ScAddress& rPos = rIter.GetPos();
+
+    if( eDataMode == SC_VALID_LIST )
+    {
+        ScBaseCell* pBC = rIter.getHackedBaseCell();
+        return IsListValid(pBC, rPos);
+    }
+
+    double fVal = 0.0;
+    OUString aString;
+    bool bIsVal = true;
+
+    switch (rIter.getType())
+    {
+        case CELLTYPE_VALUE:
+            fVal = rIter.getValue();
+            break;
+        case CELLTYPE_STRING:
+        case CELLTYPE_EDIT:
+            aString = rIter.getString();
+            bIsVal = false;
+            break;
+        case CELLTYPE_FORMULA:
+        {
+            ScFormulaCell* pFCell = rIter.getFormulaCell();
+            bIsVal = pFCell->IsValue();
+            if ( bIsVal )
+                fVal  = pFCell->GetValue();
+            else
+                aString = pFCell->GetString();
+        }
+        break;
+        default:                        // Notizen, Broadcaster
+            return IsIgnoreBlank();     // wie eingestellt
+    }
+
+    bool bOk = true;
+    switch (eDataMode)
+    {
+        // SC_VALID_ANY schon oben
+
+        case SC_VALID_WHOLE:
+        case SC_VALID_DECIMAL:
+        case SC_VALID_DATE:         // Date/Time ist nur Formatierung
+        case SC_VALID_TIME:
+            bOk = bIsVal;
+            if ( bOk && eDataMode == SC_VALID_WHOLE )
+                bOk = ::rtl::math::approxEqual( fVal, floor(fVal+0.5) );        // ganze Zahlen
+            if ( bOk )
+            {
+                ScBaseCell* pBC = rIter.getHackedBaseCell();
+                bOk = IsCellValid(pBC, rPos);
+            }
+            break;
+
+        case SC_VALID_CUSTOM:
+        {
+            //  fuer Custom muss eOp == SC_COND_DIRECT sein
+            //! der Wert muss im Dokument stehen !!!!!!!!!!!!!!!!!!!!
+            ScBaseCell* pBC = rIter.getHackedBaseCell();
+            bOk = IsCellValid(pBC, rPos);
+        }
+        break;
+        case SC_VALID_TEXTLEN:
+            bOk = !bIsVal;          // nur Text
+            if ( bOk )
+            {
+                double nLenVal = (double) aString.getLength();
+                ScValueCell* pTmpCell = new ScValueCell( nLenVal );
+                bOk = IsCellValid( pTmpCell, rPos );
+                pTmpCell->Delete();
+            }
+            break;
+
+        default:
+            OSL_FAIL("not yet done");
+            break;
+    }
+
+    return bOk;
+}
+
 // ----------------------------------------------------------------------------
 
 namespace {
diff --git a/sc/source/core/tool/detfunc.cxx b/sc/source/core/tool/detfunc.cxx
index 55bea53..e7d522a 100644
--- a/sc/source/core/tool/detfunc.cxx
+++ b/sc/source/core/tool/detfunc.cxx
@@ -1357,8 +1357,7 @@ sal_Bool ScDetectiveFunc::MarkInvalid(sal_Bool& rOverflow)
                 SCROW nNextRow = nRow1;
                 SCROW nRow;
                 ScCellIterator aCellIter( pDoc, nCol,nRow1,nTab, nCol,nRow2,nTab );
-                ScBaseCell* pCell = aCellIter.GetFirst();
-                while ( pCell && nInsCount < SC_DET_MAXCIRCLE )
+                for (bool bHas = aCellIter.first(); bHas && nInsCount < SC_DET_MAXCIRCLE; bHas = aCellIter.next())
                 {
                     SCROW nCellRow = aCellIter.GetPos().Row();
                     if ( bMarkEmpty )
@@ -1367,13 +1366,12 @@ sal_Bool ScDetectiveFunc::MarkInvalid(sal_Bool& rOverflow)
                             DrawCircle( nCol, nRow, aData );
                             ++nInsCount;
                         }
-                    if ( !pData->IsDataValid( pCell, ScAddress( nCol, nCellRow, nTab ) ) )
+                    if (!pData->IsDataValid(aCellIter))
                     {
                         DrawCircle( nCol, nCellRow, aData );
                         ++nInsCount;
                     }
                     nNextRow = nCellRow + 1;
-                    pCell = aCellIter.GetNext();
                 }
                 if ( bMarkEmpty )
                     for ( nRow = nNextRow; nRow <= nRow2 && nInsCount < SC_DET_MAXCIRCLE; nRow++ )


More information about the Libreoffice-commits mailing list