[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - 3 commits - sc/inc sc/source
Kohei Yoshida
kohei.yoshida at gmail.com
Tue Jul 16 12:42:39 PDT 2013
sc/inc/token.hxx | 6 ----
sc/source/core/data/documen4.cxx | 52 ++++++++++++++++++------------------
sc/source/core/data/formulacell.cxx | 33 +++++++++-------------
sc/source/core/inc/refupdat.hxx | 4 --
sc/source/core/tool/rangenam.cxx | 6 +++-
sc/source/core/tool/refupdat.cxx | 22 +++++++--------
sc/source/core/tool/token.cxx | 24 ----------------
7 files changed, 57 insertions(+), 90 deletions(-)
New commits:
commit cd82784d337941bc3f5a823b83aa4a77232632d7
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Tue Jul 16 15:42:23 2013 -0400
Remove CalcRelFromAbs() virtual method from ScToken and all its child classes.
Change-Id: I5def382f6495f332a0309795cbce8ebbd60ff471
diff --git a/sc/inc/token.hxx b/sc/inc/token.hxx
index 0839326..b10cbe4 100644
--- a/sc/inc/token.hxx
+++ b/sc/inc/token.hxx
@@ -74,7 +74,6 @@ public:
virtual const ScSingleRefData& GetSingleRef2() const;
virtual ScSingleRefData& GetSingleRef2();
virtual void CalcAbsIfRel( const ScAddress& );
- virtual void CalcRelFromAbs( const ScAddress& );
virtual const ScMatrix* GetMatrix() const;
virtual ScMatrix* GetMatrix();
virtual ScJumpMatrix* GetJumpMatrix() const;
@@ -121,7 +120,6 @@ public:
virtual const ScSingleRefData& GetSingleRef() const;
virtual ScSingleRefData& GetSingleRef();
virtual void CalcAbsIfRel( const ScAddress& );
- virtual void CalcRelFromAbs( const ScAddress& );
virtual bool operator==( const formula::FormulaToken& rToken ) const;
virtual FormulaToken* Clone() const { return new ScSingleRefToken(*this); }
@@ -150,7 +148,6 @@ public:
virtual const ScSingleRefData& GetSingleRef2() const;
virtual ScSingleRefData& GetSingleRef2();
virtual void CalcAbsIfRel( const ScAddress& );
- virtual void CalcRelFromAbs( const ScAddress& );
virtual bool operator==( const formula::FormulaToken& rToken ) const;
virtual FormulaToken* Clone() const { return new ScDoubleRefToken(*this); }
@@ -190,7 +187,6 @@ public:
virtual const ScSingleRefData& GetSingleRef() const;
virtual ScSingleRefData& GetSingleRef();
virtual void CalcAbsIfRel( const ScAddress& );
- virtual void CalcRelFromAbs( const ScAddress& );
virtual bool operator==( const formula::FormulaToken& rToken ) const;
virtual FormulaToken* Clone() const { return new ScExternalSingleRefToken(*this); }
};
@@ -218,7 +214,6 @@ public:
virtual const ScComplexRefData& GetDoubleRef() const;
virtual ScComplexRefData& GetDoubleRef();
virtual void CalcAbsIfRel( const ScAddress& );
- virtual void CalcRelFromAbs( const ScAddress& );
virtual bool operator==( const formula::FormulaToken& rToken ) const;
virtual FormulaToken* Clone() const { return new ScExternalDoubleRefToken(*this); }
};
@@ -271,7 +266,6 @@ public:
ScRefListToken( const ScRefListToken & r ) :
ScToken( r ), aRefList( r.aRefList ) {}
virtual void CalcAbsIfRel( const ScAddress& );
- virtual void CalcRelFromAbs( const ScAddress& );
virtual const ScRefList* GetRefList() const;
virtual ScRefList* GetRefList();
virtual bool operator==( const formula::FormulaToken& rToken ) const;
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 899aea5..b02334e 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -2732,7 +2732,6 @@ void ScFormulaCell::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY
{
if( t->GetType() != svIndex )
{
- t->CalcAbsIfRel( aPos );
SingleDoubleRefModifier aMod(*t);
ScComplexRefData& rRef = aMod.Ref();
ScRange aAbs = rRef.toAbs(aPos);
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 250433a..07da54e 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -701,11 +701,6 @@ void ScToken::CalcAbsIfRel( const ScAddress& /* rPos */ )
OSL_FAIL( "ScToken::CalcAbsIfRel: virtual dummy called" );
}
-void ScToken::CalcRelFromAbs( const ScAddress& /* rPos */ )
-{
- OSL_FAIL( "ScToken::CalcRelFromAbs: virtual dummy called" );
-}
-
const ScMatrix* ScToken::GetMatrix() const
{
OSL_FAIL( "ScToken::GetMatrix: virtual dummy called" );
@@ -746,8 +741,6 @@ const ScSingleRefData& ScSingleRefToken::GetSingleRef() const { return aSing
ScSingleRefData& ScSingleRefToken::GetSingleRef() { return aSingleRef; }
void ScSingleRefToken::CalcAbsIfRel( const ScAddress& rPos )
{ aSingleRef.CalcAbsIfRel( rPos ); }
-void ScSingleRefToken::CalcRelFromAbs( const ScAddress& rPos )
- { aSingleRef.CalcRelFromAbs( rPos ); }
bool ScSingleRefToken::operator==( const FormulaToken& r ) const
{
return FormulaToken::operator==( r ) && aSingleRef == static_cast<const ScToken&>(r).GetSingleRef();
@@ -762,8 +755,6 @@ const ScSingleRefData& ScDoubleRefToken::GetSingleRef2() const { return aDoub
ScSingleRefData& ScDoubleRefToken::GetSingleRef2() { return aDoubleRef.Ref2; }
void ScDoubleRefToken::CalcAbsIfRel( const ScAddress& rPos )
{ aDoubleRef.CalcAbsIfRel( rPos ); }
-void ScDoubleRefToken::CalcRelFromAbs( const ScAddress& rPos )
- { aDoubleRef.CalcRelFromAbs( rPos ); }
bool ScDoubleRefToken::operator==( const FormulaToken& r ) const
{
return FormulaToken::operator==( r ) && aDoubleRef == static_cast<const ScToken&>(r).GetDoubleRef();
@@ -777,11 +768,6 @@ void ScRefListToken::CalcAbsIfRel( const ScAddress& rPos )
for (ScRefList::iterator it( aRefList.begin()); it != aRefList.end(); ++it)
(*it).CalcAbsIfRel( rPos);
}
-void ScRefListToken::CalcRelFromAbs( const ScAddress& rPos )
-{
- for (ScRefList::iterator it( aRefList.begin()); it != aRefList.end(); ++it)
- (*it).CalcRelFromAbs( rPos);
-}
bool ScRefListToken::operator==( const FormulaToken& r ) const
{
return FormulaToken::operator==( r ) && &aRefList == static_cast<const ScToken&>(r).GetRefList();
@@ -847,11 +833,6 @@ void ScExternalSingleRefToken::CalcAbsIfRel( const ScAddress& rPos )
maSingleRef.CalcAbsIfRel( rPos );
}
-void ScExternalSingleRefToken::CalcRelFromAbs( const ScAddress& rPos )
-{
- maSingleRef.CalcRelFromAbs( rPos );
-}
-
bool ScExternalSingleRefToken::operator ==( const FormulaToken& r ) const
{
if (!FormulaToken::operator==(r))
@@ -933,11 +914,6 @@ void ScExternalDoubleRefToken::CalcAbsIfRel( const ScAddress& rPos )
maDoubleRef.CalcAbsIfRel( rPos );
}
-void ScExternalDoubleRefToken::CalcRelFromAbs( const ScAddress& rPos )
-{
- maDoubleRef.CalcRelFromAbs( rPos );
-}
-
bool ScExternalDoubleRefToken::operator ==( const FormulaToken& r ) const
{
if (!ScToken::operator==(r))
commit 326e576b9f3301c417a3ff3b7a8359d9e279f8f4
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Tue Jul 16 15:28:43 2013 -0400
InsertMatrixFormula() without CalcRelFromAbs().
Change-Id: I4579a0e467c2ba89790acfedafe5470d16159b40
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index 9211db8..54f4325 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -155,45 +155,47 @@ void ScDocument::InsertMatrixFormula(SCCOL nCol1, SCROW nRow1,
*pCell, *this, ScAddress(nCol1, nRow1, *itr), SC_CLONECELL_STARTLISTENING));
}
+ ScAddress aBasePos(nCol1, nRow1, nTab1);
ScSingleRefData aRefData;
aRefData.InitFlags();
- aRefData.nCol = nCol1;
- aRefData.nRow = nRow1;
- aRefData.nTab = nTab1;
aRefData.SetColRel( true );
aRefData.SetRowRel( true );
aRefData.SetTabRel( true );
- aRefData.CalcRelFromAbs( ScAddress( nCol1, nRow1, nTab1 ) );
+ aRefData.SetAddress(aBasePos, aBasePos);
- ScTokenArray aArr;
+ ScTokenArray aArr; // consists only of one single reference token.
ScToken* t = static_cast<ScToken*>(aArr.AddMatrixSingleReference( aRefData));
itr = rMark.begin();
for (; itr != itrEnd && *itr < nMax; ++itr)
{
- if (maTabs[*itr])
+ SCTAB nTab = *itr;
+ ScTable* pTab = FetchTable(nTab);
+ if (!pTab)
+ continue;
+
+ if (nTab != nTab1)
{
- if (*itr != nTab1)
+ aRefData.nRelTab = nTab - aBasePos.Tab();
+ t->GetSingleRef() = aRefData;
+ }
+
+ for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
+ {
+ for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
{
- aRefData.nTab = *itr;
- aRefData.nRelTab = *itr - nTab1;
+ if (nCol == nCol1 && nRow == nRow1)
+ // Skip the base position.
+ continue;
+
+ // Token array must be cloned so that each formula cell receives its own copy.
+ aPos = ScAddress(nCol, nRow, nTab);
+ // Reference in each cell must point to the origin cell relative to the current cell.
+ aRefData.SetAddress(aBasePos, aPos);
t->GetSingleRef() = aRefData;
- }
- for (SCCOL j = nCol1; j <= nCol2; j++)
- {
- for (SCROW k = nRow1; k <= nRow2; k++)
- {
- if (j != nCol1 || k != nRow1) // nicht in der ersten Zelle
- {
- // Array muss geklont werden, damit jede
- // Zelle ein eigenes Array erhaelt!
- aPos = ScAddress( j, k, *itr );
- t->CalcRelFromAbs( aPos );
- boost::scoped_ptr<ScTokenArray> pTokArr(aArr.Clone());
- pCell = new ScFormulaCell( this, aPos, pTokArr.get(), eGram, MM_REFERENCE );
- maTabs[*itr]->SetFormulaCell(j, k, pCell);
- }
- }
+ boost::scoped_ptr<ScTokenArray> pTokArr(aArr.Clone());
+ pCell = new ScFormulaCell( this, aPos, pTokArr.get(), eGram, MM_REFERENCE );
+ pTab->SetFormulaCell(nCol, nRow, pCell);
}
}
}
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 8f27a45..899aea5 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -1851,6 +1851,7 @@ bool ScFormulaCell::GetMatrixOrigin( ScAddress& rPos ) const
}
break;
}
+ fprintf(stdout, "ScFormulaCell::GetMatrixOrigin: failed\n");
return false;
}
commit 5cbf31f3274b8dd9a4add80067fbf7db0955ab82
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Tue Jul 16 14:44:02 2013 -0400
Same with UpdateGrow().
Change-Id: I1424dedbf8201469da28e60d68787ae5aa7d87f9
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 5b7f8bf..8f27a45 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -2708,17 +2708,13 @@ void ScFormulaCell::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY
}
else if( t->GetType() != svIndex )
{
- t->CalcAbsIfRel( aPos );
- bool bMod;
- { // Own scope for SingleDoubleRefModifier dtor if SingleRef
- SingleDoubleRefModifier aMod( *t );
- ScComplexRefData& rRef = aMod.Ref();
- bMod = (ScRefUpdate::UpdateGrow( rArea,nGrowX,nGrowY,
- rRef ) != UR_NOTHING);
- }
- if ( bMod )
+ SingleDoubleRefModifier aMod(*t);
+ ScComplexRefData& rRef = aMod.Ref();
+ ScRange aAbs = rRef.toAbs(aPos);
+ bool bMod = (ScRefUpdate::UpdateGrow(rArea, nGrowX, nGrowY, aAbs) != UR_NOTHING);
+ if (bMod)
{
- t->CalcRelFromAbs( aPos );
+ rRef.SetRange(aAbs, aPos);
bRefChanged = true;
}
}
@@ -2736,15 +2732,12 @@ void ScFormulaCell::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY
if( t->GetType() != svIndex )
{
t->CalcAbsIfRel( aPos );
- bool bMod;
- { // Own scope for SingleDoubleRefModifier dtor if SingleRef
- SingleDoubleRefModifier aMod( *t );
- ScComplexRefData& rRef = aMod.Ref();
- bMod = (ScRefUpdate::UpdateGrow( rArea,nGrowX,nGrowY,
- rRef ) != UR_NOTHING);
- }
- if ( bMod )
- t->CalcRelFromAbs( aPos );
+ SingleDoubleRefModifier aMod(*t);
+ ScComplexRefData& rRef = aMod.Ref();
+ ScRange aAbs = rRef.toAbs(aPos);
+ bool bMod = (ScRefUpdate::UpdateGrow(rArea, nGrowX, nGrowY, aAbs) != UR_NOTHING);
+ if (bMod)
+ rRef.SetRange(aAbs, aPos);
}
}
}
diff --git a/sc/source/core/inc/refupdat.hxx b/sc/source/core/inc/refupdat.hxx
index a5f688d..1d9f4c2 100644
--- a/sc/source/core/inc/refupdat.hxx
+++ b/sc/source/core/inc/refupdat.hxx
@@ -79,10 +79,8 @@ public:
static void DoTranspose( SCsCOL& rCol, SCsROW& rRow, SCsTAB& rTab, ScDocument* pDoc,
const ScRange& rSource, const ScAddress& rDest );
- /// Before calling, the absolute references must be up-to-date!
static ScRefUpdateRes UpdateGrow(
- const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY,
- ScComplexRefData& rRef );
+ const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY, ScRange& rRef );
};
diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx
index 75e79ec..84c3fb9 100644
--- a/sc/source/core/tool/rangenam.cxx
+++ b/sc/source/core/tool/rangenam.cxx
@@ -349,8 +349,12 @@ void ScRangeData::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY )
(!rRef.Ref2.IsColRel() && !rRef.Ref2.IsRowRel() &&
(!rRef.Ref2.IsFlag3D() || !rRef.Ref2.IsTabRel()))))
{
- if ( ScRefUpdate::UpdateGrow( rArea,nGrowX,nGrowY, rRef ) != UR_NOTHING )
+ ScRange aAbs = rRef.toAbs(aPos);
+ if (ScRefUpdate::UpdateGrow(rArea, nGrowX, nGrowY, aAbs) != UR_NOTHING)
+ {
+ rRef.SetRange(aAbs, aPos);
bChanged = true;
+ }
}
}
}
diff --git a/sc/source/core/tool/refupdat.cxx b/sc/source/core/tool/refupdat.cxx
index df0b0a4..4f97c40 100644
--- a/sc/source/core/tool/refupdat.cxx
+++ b/sc/source/core/tool/refupdat.cxx
@@ -893,8 +893,8 @@ ScRefUpdateRes ScRefUpdate::UpdateTranspose(
// kommt ohne Dokument aus
-ScRefUpdateRes ScRefUpdate::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY,
- ScComplexRefData& rRef )
+ScRefUpdateRes ScRefUpdate::UpdateGrow(
+ const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY, ScRange& rRef )
{
ScRefUpdateRes eRet = UR_NOTHING;
@@ -902,23 +902,23 @@ ScRefUpdateRes ScRefUpdate::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCRO
// falls ein Bereich Spaltenkoepfe enthaelt
bool bUpdateX = ( nGrowX &&
- rRef.Ref1.nCol == rArea.aStart.Col() && rRef.Ref2.nCol == rArea.aEnd.Col() &&
- rRef.Ref1.nRow >= rArea.aStart.Row() && rRef.Ref2.nRow <= rArea.aEnd.Row() &&
- rRef.Ref1.nTab >= rArea.aStart.Tab() && rRef.Ref2.nTab <= rArea.aEnd.Tab() );
+ rRef.aStart.Col() == rArea.aStart.Col() && rRef.aEnd.Col() == rArea.aEnd.Col() &&
+ rRef.aStart.Row() >= rArea.aStart.Row() && rRef.aEnd.Row() <= rArea.aEnd.Row() &&
+ rRef.aStart.Tab() >= rArea.aStart.Tab() && rRef.aEnd.Tab() <= rArea.aEnd.Tab() );
bool bUpdateY = ( nGrowY &&
- rRef.Ref1.nCol >= rArea.aStart.Col() && rRef.Ref2.nCol <= rArea.aEnd.Col() &&
- ( rRef.Ref1.nRow == rArea.aStart.Row() || rRef.Ref1.nRow == rArea.aStart.Row()+1 ) &&
- rRef.Ref2.nRow == rArea.aEnd.Row() &&
- rRef.Ref1.nTab >= rArea.aStart.Tab() && rRef.Ref2.nTab <= rArea.aEnd.Tab() );
+ rRef.aStart.Col() >= rArea.aStart.Col() && rRef.aEnd.Col() <= rArea.aEnd.Col() &&
+ (rRef.aStart.Row() == rArea.aStart.Row() || rRef.aStart.Row() == rArea.aStart.Row()+1) &&
+ rRef.aEnd.Row() == rArea.aEnd.Row() &&
+ rRef.aStart.Tab() >= rArea.aStart.Tab() && rRef.aEnd.Tab() <= rArea.aEnd.Tab() );
if ( bUpdateX )
{
- rRef.Ref2.nCol = sal::static_int_cast<SCsCOL>( rRef.Ref2.nCol + nGrowX );
+ rRef.aEnd.SetCol(sal::static_int_cast<SCsCOL>(rRef.aEnd.Col() + nGrowX));
eRet = UR_UPDATED;
}
if ( bUpdateY )
{
- rRef.Ref2.nRow = sal::static_int_cast<SCsROW>( rRef.Ref2.nRow + nGrowY );
+ rRef.aEnd.SetRow(sal::static_int_cast<SCsROW>(rRef.aEnd.Row() + nGrowY));
eRet = UR_UPDATED;
}
More information about the Libreoffice-commits
mailing list