More on ScCellIterator usage migration.

Change-Id: I4ee6b1b3ae110ebfb59a84d6e9fd509ce38ca28c
This commit is contained in:
Kohei Yoshida 2013-03-25 09:30:57 -04:00
parent 4597296276
commit 0e9e3be6f5
4 changed files with 56 additions and 28 deletions

View file

@ -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;

View file

@ -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 {

View file

@ -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);

View file

@ -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();
}
}
}