summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-03-25 10:59:15 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-03-26 01:41:18 -0400
commit0075402e354dead483ca242962314aae5782134c (patch)
treeb04738ee13f43a2fe5dfd2ea9c13360ad1dbdad9
parent04e265e9dbe34d7417a9aefc095510979fcc8658 (diff)
Another one involving cell data validation in detective functionality.
Change-Id: I1987f45e436744d4029f8b7af812867ebcfb09c4
-rw-r--r--sc/inc/dociter.hxx3
-rw-r--r--sc/inc/validat.hxx3
-rw-r--r--sc/source/core/data/dociter.cxx5
-rw-r--r--sc/source/core/data/validat.cxx85
-rw-r--r--sc/source/core/tool/detfunc.cxx6
5 files changed, 98 insertions, 4 deletions
diff --git a/sc/inc/dociter.hxx b/sc/inc/dociter.hxx
index 6f17e2db0fce..a0ffa5c99a44 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 90d8ce76e249..8c73b7d095e1 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 fb39c8ade1a7..ebbfd65bdb49 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 71b53e5a529a..a2d4b4ad2180 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 55bea538be2a..e7d522a6115d 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++ )