summaryrefslogtreecommitdiff
path: root/sc/source/core/data
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-07-30 01:36:28 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-07-30 23:50:02 -0400
commit5a1960f5ea9f225fda493df746e5674e3bd1cce9 (patch)
tree7f77a380e2e16500e39fdde51d379d9606507d1c /sc/source/core/data
parented671a33a31b8d8cd81e3774be603c13e8b9a6f3 (diff)
Update range names on sheet deletion.
It works fine with live calc instance, but somehow fails in unit test. Change-Id: Ie60774b4f1f8391801e0d9358f6cca78d8e52397
Diffstat (limited to 'sc/source/core/data')
-rw-r--r--sc/source/core/data/column.cxx16
-rw-r--r--sc/source/core/data/conditio.cxx11
-rw-r--r--sc/source/core/data/document.cxx24
-rw-r--r--sc/source/core/data/formulacell.cxx17
-rw-r--r--sc/source/core/data/refupdatecontext.cxx3
-rw-r--r--sc/source/core/data/table1.cxx23
6 files changed, 55 insertions, 39 deletions
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 504de753c35c..c3afde903c1d 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -2438,6 +2438,7 @@ public:
class DeleteTabUpdater
{
+ sc::RefUpdateDeleteTabContext& mrCxt;
sc::CellTextAttrStoreType& mrTextAttrs;
sc::CellTextAttrStoreType::iterator miAttrPos;
SCTAB mnDelPos;
@@ -2445,17 +2446,16 @@ class DeleteTabUpdater
SCTAB mnTab;
bool mbModified;
public:
- DeleteTabUpdater(sc::CellTextAttrStoreType& rTextAttrs, SCTAB nDelPos, SCTAB nSheets, SCTAB nTab) :
+ DeleteTabUpdater(sc::RefUpdateDeleteTabContext& rCxt, sc::CellTextAttrStoreType& rTextAttrs, SCTAB nTab) :
+ mrCxt(rCxt),
mrTextAttrs(rTextAttrs),
miAttrPos(rTextAttrs.begin()),
- mnDelPos(nDelPos),
- mnSheets(nSheets),
mnTab(nTab),
mbModified(false) {}
void operator() (size_t, ScFormulaCell* pCell)
{
- pCell->UpdateDeleteTab(mnDelPos, mnSheets);
+ pCell->UpdateDeleteTab(mrCxt);
mbModified = true;
}
@@ -2890,15 +2890,15 @@ void ScColumn::UpdateInsertTabOnlyCells( sc::RefUpdateInsertTabContext& rCxt )
CellStorageModified();
}
-void ScColumn::UpdateDeleteTab(SCTAB nDelPos, SCTAB nSheets)
+void ScColumn::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
{
- if (nTab > nDelPos)
+ if (nTab > rCxt.mnDeletePos)
{
- nTab -= nSheets;
+ nTab -= rCxt.mnSheets;
pAttrArray->SetTab(nTab);
}
- DeleteTabUpdater aFunc(maCellTextAttrs, nDelPos, nSheets, nTab);
+ DeleteTabUpdater aFunc(rCxt, maCellTextAttrs, nTab);
sc::ProcessFormulaEditText(maCells, aFunc);
if (aFunc.isModified())
CellStorageModified();
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index baf4b1839aa8..56d697ef543c 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -39,6 +39,7 @@
#include "cellvalue.hxx"
#include "editutil.hxx"
#include "tokenarray.hxx"
+#include "refupdatecontext.hxx"
using namespace formula;
//------------------------------------------------------------------------
@@ -545,7 +546,10 @@ void ScConditionEntry::UpdateReference( UpdateRefMode eUpdateRefMode,
else
{
if ( bDeleteTab )
- pFormula1->AdjustReferenceOnDeletedTab(rRange.aStart.Tab(), static_cast<SCTAB>(-1*nDz), aSrcPos);
+ {
+ sc::RefUpdateDeleteTabContext aCxt(rRange.aStart.Tab(), -1*nDz);
+ pFormula1->AdjustReferenceOnDeletedTab(aCxt, aSrcPos);
+ }
else
{
ScCompiler aComp( mpDoc, aSrcPos, *pFormula1 );
@@ -567,7 +571,10 @@ void ScConditionEntry::UpdateReference( UpdateRefMode eUpdateRefMode,
else
{
if ( bDeleteTab )
- pFormula2->AdjustReferenceOnDeletedTab(rRange.aStart.Tab(), static_cast<SCTAB>(-1*nDz), aSrcPos);
+ {
+ sc::RefUpdateDeleteTabContext aCxt(rRange.aStart.Tab(), -1*nDz);
+ pFormula2->AdjustReferenceOnDeletedTab(aCxt, aSrcPos);
+ }
else
{
ScCompiler aComp( mpDoc, aSrcPos, *pFormula2);
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 90cadf72cf35..25fc4c3ef271 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -617,8 +617,9 @@ bool ScDocument::DeleteTab( SCTAB nTab )
SCTAB nTabCount = static_cast<SCTAB>(maTabs.size());
if (nTabCount > 1)
{
- bool bOldAutoCalc = GetAutoCalc();
- SetAutoCalc( false ); // avoid multiple calculations
+ sc::AutoCalcSwitch aACSwitch(*this, false);
+ sc::RefUpdateDeleteTabContext aCxt(nTab, 1);
+
ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab );
DelBroadcastAreasInRange( aRange );
@@ -640,7 +641,7 @@ bool ScDocument::DeleteTab( SCTAB nTab )
xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,-1 );
xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,-1 );
if (pRangeName)
- pRangeName->UpdateTabRef(nTab, ScRangeData::Delete);
+ pRangeName->UpdateDeleteTab(aCxt);
pDBCollection->UpdateReference(
URM_INSDEL, 0,0,nTab, MAXCOL,MAXROW,MAXTAB, 0,0,-1 );
if (pDPCollection)
@@ -656,7 +657,7 @@ bool ScDocument::DeleteTab( SCTAB nTab )
for (SCTAB i = 0, n = static_cast<SCTAB>(maTabs.size()); i < n; ++i)
if (maTabs[i])
- maTabs[i]->UpdateDeleteTab(nTab);
+ maTabs[i]->UpdateDeleteTab(aCxt);
TableContainer::iterator it = maTabs.begin() + nTab;
delete *it;
@@ -682,7 +683,6 @@ bool ScDocument::DeleteTab( SCTAB nTab )
// sheet names of references are not valid until sheet is deleted
pChartListenerCollection->UpdateScheduledSeriesRanges();
- SetAutoCalc( bOldAutoCalc );
bValid = true;
}
}
@@ -701,8 +701,9 @@ bool ScDocument::DeleteTabs( SCTAB nTab, SCTAB nSheets )
SCTAB nTabCount = static_cast<SCTAB>(maTabs.size());
if (nTabCount > nSheets)
{
- bool bOldAutoCalc = GetAutoCalc();
- SetAutoCalc( false ); // avoid multiple calculations
+ sc::AutoCalcSwitch aACSwitch(*this, false);
+ sc::RefUpdateDeleteTabContext aCxt(nTab, nSheets);
+
for (SCTAB aTab = 0; aTab < nSheets; ++aTab)
{
ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab + aTab );
@@ -719,9 +720,11 @@ bool ScDocument::DeleteTabs( SCTAB nTab, SCTAB nSheets )
if (pDetOpList)
pDetOpList->DeleteOnTab( nTab + aTab );
DeleteAreaLinksOnTab( nTab + aTab );
- if (pRangeName)
- pRangeName->UpdateTabRef(nTab + aTab, ScRangeData::Delete);
}
+
+ if (pRangeName)
+ pRangeName->UpdateDeleteTab(aCxt);
+
// normal reference update
ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTabCount - 1 );
@@ -742,7 +745,7 @@ bool ScDocument::DeleteTabs( SCTAB nTab, SCTAB nSheets )
for (SCTAB i = 0, n = static_cast<SCTAB>(maTabs.size()); i < n; ++i)
if (maTabs[i])
- maTabs[i]->UpdateDeleteTab(nTab, nSheets);
+ maTabs[i]->UpdateDeleteTab(aCxt);
TableContainer::iterator it = maTabs.begin() + nTab;
TableContainer::iterator itEnd = it + nSheets;
@@ -769,7 +772,6 @@ bool ScDocument::DeleteTabs( SCTAB nTab, SCTAB nSheets )
// sheet names of references are not valid until sheet is deleted
pChartListenerCollection->UpdateScheduledSeriesRanges();
- SetAutoCalc( bOldAutoCalc );
bValid = true;
}
}
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 7dcfaaf5cc07..d2ddbc1c1215 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -2582,24 +2582,29 @@ void ScFormulaCell::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
// no StartListeningTo because the new sheets have not been inserted yet.
}
-bool ScFormulaCell::UpdateDeleteTab(SCTAB nTable, SCTAB nSheets)
+bool ScFormulaCell::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
{
- bool bPosChanged = ( aPos.Tab() >= nTable + nSheets ? true : false );
+ bool bPosChanged = (aPos.Tab() >= rCxt.mnDeletePos + rCxt.mnSheets);
pCode->Reset();
if (pDocument->IsClipOrUndo() || !pCode->GetNextReferenceRPN())
{
if (bPosChanged)
- aPos.IncTab(-1*nSheets);
+ aPos.IncTab(-1*rCxt.mnSheets);
return false;
}
EndListeningTo( pDocument );
// IncTab _after_ EndListeningTo und _before_ Compiler UpdateDeleteTab!
ScAddress aOldPos = aPos;
- if ( bPosChanged )
- aPos.IncTab(-1*nSheets);
+ if (bPosChanged)
+ aPos.IncTab(-1*rCxt.mnSheets);
+
+ sc::RefUpdateResult aRes = pCode->AdjustReferenceOnDeletedTab(rCxt, aOldPos);
+ if (aRes.mbNameModified)
+ // Re-compile after sheet(s) have been deleted.
+ bCompile = true;
- return pCode->AdjustReferenceOnDeletedTab(nTable, nSheets, aOldPos);
+ return aRes.mbReferenceModified;
}
void ScFormulaCell::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo )
diff --git a/sc/source/core/data/refupdatecontext.cxx b/sc/source/core/data/refupdatecontext.cxx
index ff68ea8cc0ac..e23128e1f464 100644
--- a/sc/source/core/data/refupdatecontext.cxx
+++ b/sc/source/core/data/refupdatecontext.cxx
@@ -64,6 +64,9 @@ RefUpdateResult::RefUpdateResult(const RefUpdateResult& r) :
RefUpdateInsertTabContext::RefUpdateInsertTabContext(SCTAB nInsertPos, SCTAB nSheets) :
mnInsertPos(nInsertPos), mnSheets(nSheets) {}
+RefUpdateDeleteTabContext::RefUpdateDeleteTabContext(SCTAB nDeletePos, SCTAB nSheets) :
+ mnDeletePos(nDeletePos), mnSheets(nSheets) {}
+
}
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index ad2d17e35670..74eb46ca9678 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1604,31 +1604,30 @@ void ScTable::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
}
}
-void ScTable::UpdateDeleteTab( SCTAB nTable, SCTAB nSheets )
+void ScTable::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt )
{
- if (nTab > nTable)
+ if (nTab > rCxt.mnDeletePos)
{
- nTab -= nSheets;
+ nTab -= rCxt.mnSheets;
if (pDBDataNoName)
pDBDataNoName->UpdateMoveTab(nTab + 1,nTab);
}
for (SCCOL i = 0; i <= MAXCOL; ++i)
- aCol[i].UpdateDeleteTab(nTable, nSheets);
+ aCol[i].UpdateDeleteTab(rCxt);
if (mpRangeName)
- {
- for (SCTAB aTab = 0; aTab < nSheets; ++aTab)
- mpRangeName->UpdateTabRef(nTable + aTab, ScRangeData::Delete);
-
- mpRangeName->UpdateTabRef(nTable, ScRangeData::Delete);
- }
+ mpRangeName->UpdateDeleteTab(rCxt, nTab);
if (IsStreamValid())
SetStreamValid(false);
- if(mpCondFormatList)
- mpCondFormatList->UpdateReference( URM_INSDEL, ScRange(0,0, nTable, MAXCOL, MAXROW, nTable+nSheets-1),0,0, -1*nSheets);
+ if (mpCondFormatList)
+ {
+ mpCondFormatList->UpdateReference(
+ URM_INSDEL, ScRange(0,0, rCxt.mnDeletePos, MAXCOL, MAXROW, rCxt.mnDeletePos+rCxt.mnSheets-1),
+ 0, 0, -1*rCxt.mnSheets);
+ }
}
void ScTable::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo,