[Libreoffice-commits] core.git: 3 commits - sc/inc sc/source
Eike Rathke
erack at redhat.com
Wed Apr 27 19:06:46 UTC 2016
sc/inc/document.hxx | 6 -
sc/source/core/data/conditio.cxx | 2
sc/source/core/data/documen3.cxx | 2
sc/source/core/data/formulacell.cxx | 119 ++++++++++++++++++++----------------
sc/source/core/data/validat.cxx | 2
sc/source/core/tool/compiler.cxx | 2
6 files changed, 75 insertions(+), 58 deletions(-)
New commits:
commit f5cd030ee0d15ae0519d68b8675773ce0b223a36
Author: Eike Rathke <erack at redhat.com>
Date: Wed Apr 27 20:04:47 2016 +0200
extract adjustCopyRangeName() from adjustRangeName()
Change-Id: I1dd41a4fe96187750d4269e732ca39c19de3c060
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 7949010..280c1eb 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -636,22 +636,25 @@ ScRangeData* copyRangeNames( SheetIndexMap& rSheetIndexMap, std::vector<ScRangeD
return pRangeData;
}
-void adjustRangeName(formula::FormulaToken* pToken, ScDocument& rNewDoc, const ScDocument* pOldDoc,
- const ScAddress& rNewPos, const ScAddress& rOldPos, bool bGlobalNamesToLocal)
+/** Adjust or copy name.
+ @return TRUE if copied and caller may need to evaluate rpRangeData and rNewSheet.
+ FALSE if nothing to be done.
+ */
+bool adjustCopyRangeName( const SCTAB nOldSheet, const sal_uInt16 nOldIndex,
+ ScRangeData*& rpRangeData, SCTAB& rNewSheet, ScDocument& rNewDoc, const ScDocument* pOldDoc,
+ const ScAddress& rNewPos, const ScAddress& rOldPos, const bool bGlobalNamesToLocal)
{
- bool bSameDoc = (rNewDoc.GetPool() == const_cast<ScDocument*>(pOldDoc)->GetPool());
- const SCTAB nOldSheet = pToken->GetSheet();
+ const bool bSameDoc = (rNewDoc.GetPool() == const_cast<ScDocument*>(pOldDoc)->GetPool());
if (bSameDoc && ((nOldSheet < 0 && !bGlobalNamesToLocal) || (nOldSheet >= 0 && nOldSheet != rOldPos.Tab())))
// Same doc and global name, if not copied to local name, or
// sheet-local name on other sheet stays the same.
- return;
+ return false;
SAL_WARN_IF( !bSameDoc && nOldSheet >= 0 && nOldSheet != rOldPos.Tab(),
- "sc.core", "adjustRangeName - sheet-local name was on other sheet in other document");
+ "sc.core", "adjustCopyRangeName - sheet-local name was on other sheet in other document");
/* TODO: can we do something about that? e.g. loop over sheets? */
OUString aRangeName;
- const sal_uInt16 nOldIndex = pToken->GetIndex();
ScRangeData* pOldRangeData = nullptr;
// XXX bGlobalNamesToLocal is also a synonym for copied sheet.
@@ -673,42 +676,41 @@ void adjustRangeName(formula::FormulaToken* pToken, ScDocument& rNewDoc, const S
const ScRangeName* pRangeName = pOldDoc->GetRangeName(nOldTab);
pOldRangeData = pRangeName ? pRangeName->findByIndex(nOldIndex) : nullptr;
if (!pOldRangeData)
- return; // might be an error in the formula array
+ return false; // might be an error in the formula array
aRangeName = pOldRangeData->GetUpperName();
}
else
{
pOldRangeData = pOldDoc->GetRangeName()->findByIndex(nOldIndex);
if (!pOldRangeData)
- return; // might be an error in the formula array
+ return false; // might be an error in the formula array
aRangeName = pOldRangeData->GetUpperName();
}
// Find corresponding range name in new document.
// First search for local range name then global range names.
- SCTAB nNewSheet = rNewPos.Tab();
- ScRangeName* pRangeName = rNewDoc.GetRangeName(nNewSheet);
- ScRangeData* pRangeData = nullptr;
+ rNewSheet = rNewPos.Tab();
+ ScRangeName* pRangeName = rNewDoc.GetRangeName(rNewSheet);
// Search local range names.
if (pRangeName)
{
- pRangeData = pRangeName->findByUpperName(aRangeName);
+ rpRangeData = pRangeName->findByUpperName(aRangeName);
}
// Search global range names.
- if (!pRangeData && !bGlobalNamesToLocal)
+ if (!rpRangeData && !bGlobalNamesToLocal)
{
- nNewSheet = -1;
+ rNewSheet = -1;
pRangeName = rNewDoc.GetRangeName();
if (pRangeName)
- pRangeData = pRangeName->findByUpperName(aRangeName);
+ rpRangeData = pRangeName->findByUpperName(aRangeName);
}
// If no range name was found copy it.
- if (!pRangeData)
+ if (!rpRangeData)
{
bool bEarlyBailOut = (nOldSheet < 0 && bSameDoc);
MightReferenceSheet eMightReference = mightRangeNameReferenceSheet( pOldRangeData, nOldTab);
if (bEarlyBailOut && eMightReference == MightReferenceSheet::NONE)
- return;
+ return false;
if (eMightReference == MightReferenceSheet::NAME)
{
@@ -721,17 +723,17 @@ void adjustRangeName(formula::FormulaToken* pToken, ScDocument& rNewDoc, const S
findRangeNamesReferencingSheet( aReferencingNames, nOldSheet, nOldIndex, pOldDoc,
nGlobalRefTab, nLocalRefTab, nOldTokenTab, nOldTokenTabReplacement, bSameDoc, 0);
if (bEarlyBailOut && aReferencingNames.isEmpty(-1) && aReferencingNames.isEmpty(nOldTokenTabReplacement))
- return;
+ return false;
SheetIndexMap aSheetIndexMap;
std::vector<ScRangeData*> aRangeDataVec;
if (!aReferencingNames.isEmpty(nOldTokenTabReplacement))
{
const SCTAB nTmpOldSheet = (nOldSheet < 0 ? nOldTab : nOldSheet);
- nNewSheet = rNewPos.Tab();
- pRangeData = copyRangeNames( aSheetIndexMap, aRangeDataVec, aReferencingNames, nOldTab,
+ rNewSheet = rNewPos.Tab();
+ rpRangeData = copyRangeNames( aSheetIndexMap, aRangeDataVec, aReferencingNames, nOldTab,
pOldRangeData, rNewDoc, pOldDoc, rNewPos, rOldPos,
- bGlobalNamesToLocal, nTmpOldSheet, nNewSheet, bSameDoc);
+ bGlobalNamesToLocal, nTmpOldSheet, rNewSheet, bSameDoc);
}
if ((bGlobalNamesToLocal || !bSameDoc) && !aReferencingNames.isEmpty(-1))
{
@@ -740,10 +742,10 @@ void adjustRangeName(formula::FormulaToken* pToken, ScDocument& rNewDoc, const S
ScRangeData* pTmpData = copyRangeNames( aSheetIndexMap, aRangeDataVec, aReferencingNames, -1,
pOldRangeData, rNewDoc, pOldDoc, rNewPos, rOldPos,
bGlobalNamesToLocal, nTmpOldSheet, nTmpNewSheet, bSameDoc);
- if (!pRangeData)
+ if (!rpRangeData)
{
- pRangeData = pTmpData;
- nNewSheet = nTmpNewSheet;
+ rpRangeData = pTmpData;
+ rNewSheet = nTmpNewSheet;
}
}
@@ -765,7 +767,7 @@ void adjustRangeName(formula::FormulaToken* pToken, ScDocument& rNewDoc, const S
}
else if (!bSameDoc)
{
- SAL_WARN("sc.core","adjustRangeName - mapping to new name in other doc missing");
+ SAL_WARN("sc.core","adjustCopyRangeName - mapping to new name in other doc missing");
p->SetIndex(0); // #NAME? error instead of arbitrary name.
}
}
@@ -775,19 +777,31 @@ void adjustRangeName(formula::FormulaToken* pToken, ScDocument& rNewDoc, const S
}
else
{
- nNewSheet = ((nOldSheet < 0 && !bGlobalNamesToLocal) ? -1 : rNewPos.Tab());
- pRangeData = copyRangeName( pOldRangeData, rNewDoc, pOldDoc, rNewPos, rOldPos, bGlobalNamesToLocal,
- nOldSheet, nNewSheet, bSameDoc);
+ rNewSheet = ((nOldSheet < 0 && !bGlobalNamesToLocal) ? -1 : rNewPos.Tab());
+ rpRangeData = copyRangeName( pOldRangeData, rNewDoc, pOldDoc, rNewPos, rOldPos, bGlobalNamesToLocal,
+ nOldSheet, rNewSheet, bSameDoc);
}
+ }
+ return true;
+}
- if (!pRangeData)
- {
- // If this happened we have a real problem.
- pToken->SetIndex(0);
- OSL_FAIL("inserting the range name should not fail");
- return;
- }
+void adjustRangeName(formula::FormulaToken* pToken, ScDocument& rNewDoc, const ScDocument* pOldDoc,
+ const ScAddress& rNewPos, const ScAddress& rOldPos, bool bGlobalNamesToLocal)
+{
+ ScRangeData* pRangeData = nullptr;
+ SCTAB nNewSheet = rNewPos.Tab();
+ if (!adjustCopyRangeName( pToken->GetSheet(), pToken->GetIndex(), pRangeData, nNewSheet, rNewDoc, pOldDoc,
+ rNewPos, rOldPos, bGlobalNamesToLocal))
+ return; // nothing to do
+
+ if (!pRangeData)
+ {
+ // If this happened we have a real problem.
+ pToken->SetIndex(0);
+ OSL_FAIL("inserting the range name should not fail");
+ return;
}
+
sal_Int32 nIndex = pRangeData->GetIndex();
pToken->SetIndex(nIndex);
pToken->SetSheet(nNewSheet);
commit bd2800df8462808c53221fe422eaefd42d0a71e7
Author: Eike Rathke <erack at redhat.com>
Date: Wed Apr 27 18:57:51 2016 +0200
make findRangeNamesReferencingSheet() independent from a passed FormulaToken
Preparing to extract some functionality.
Change-Id: Ic0e298273f6f047a7d35aaa31fb99d9a45128ad0
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index a916816..7949010 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -450,17 +450,20 @@ MightReferenceSheet mightRangeNameReferenceSheet( ScRangeData* pData, SCTAB nRef
// See also lcl_FindRangeNamesInUse() below.
/** Recursively find all named expressions that directly or indirectly (nested)
- reference a given sheet.
+ reference a given sheet, starting from a given named expression
+ nTokenTab/nTokenIndex.
- @param pToken
- A token of type svIndex with OpCode ocName.
+ @param nTokenTab
+ Tab/sheet on which to find the name, -1 if global scope. Obtained
+ from ocName token.
+
+ @param nTokenIndex
+ Index of named expression. Obtained from ocName token.
*/
-bool findRangeNamesReferencingSheet( sc::UpdatedRangeNames& rIndexes, const FormulaToken* pToken,
+bool findRangeNamesReferencingSheet( sc::UpdatedRangeNames& rIndexes, SCTAB nTokenTab, const sal_uInt16 nTokenIndex,
const ScDocument* pDoc, SCTAB nGlobalRefTab, SCTAB nLocalRefTab,
SCTAB nOldTokenTab, SCTAB nOldTokenTabReplacement, bool bSameDoc, int nRecursion)
{
- const sal_uInt16 nTokenIndex = pToken->GetIndex();
- SCTAB nTokenTab = pToken->GetSheet();
if (nTokenTab < -1)
{
SAL_WARN("sc.core", "findRangeNamesReferencingSheet - nTokenTab < -1 : " <<
@@ -500,8 +503,8 @@ bool findRangeNamesReferencingSheet( sc::UpdatedRangeNames& rIndexes, const Form
{
if (p->GetOpCode() == ocName)
{
- bRef |= findRangeNamesReferencingSheet( rIndexes, p, pDoc, nGlobalRefTab, nLocalRefTab,
- nOldTokenTab, nOldTokenTabReplacement, bSameDoc, nRecursion+1);
+ bRef |= findRangeNamesReferencingSheet( rIndexes, p->GetSheet(), p->GetIndex(), pDoc,
+ nGlobalRefTab, nLocalRefTab, nOldTokenTab, nOldTokenTabReplacement, bSameDoc, nRecursion+1);
}
}
}
@@ -648,7 +651,7 @@ void adjustRangeName(formula::FormulaToken* pToken, ScDocument& rNewDoc, const S
/* TODO: can we do something about that? e.g. loop over sheets? */
OUString aRangeName;
- int nOldIndex = pToken->GetIndex();
+ const sal_uInt16 nOldIndex = pToken->GetIndex();
ScRangeData* pOldRangeData = nullptr;
// XXX bGlobalNamesToLocal is also a synonym for copied sheet.
@@ -715,7 +718,7 @@ void adjustRangeName(formula::FormulaToken* pToken, ScDocument& rNewDoc, const S
const SCTAB nOldTokenTab = (nOldSheet < 0 ? (bInsertingBefore ? nOldTab-1 : nOldTab) : nOldSheet);
const SCTAB nOldTokenTabReplacement = nOldTab;
sc::UpdatedRangeNames aReferencingNames;
- findRangeNamesReferencingSheet( aReferencingNames, pToken, pOldDoc,
+ findRangeNamesReferencingSheet( aReferencingNames, nOldSheet, nOldIndex, pOldDoc,
nGlobalRefTab, nLocalRefTab, nOldTokenTab, nOldTokenTabReplacement, bSameDoc, 0);
if (bEarlyBailOut && aReferencingNames.isEmpty(-1) && aReferencingNames.isEmpty(nOldTokenTabReplacement))
return;
commit cc5f8c6bf09c88859a317f822800e569670873f8
Author: Eike Rathke <erack at redhat.com>
Date: Wed Apr 27 16:00:29 2016 +0200
FindRangeNameByIndexAndSheet() to FindRangeNameBySheetAndIndex()
index,sheet was slightly confusing as we lookup an index within a sheet.
Change-Id: I164dd48187e6652639094e33ca83a91a96c893a0
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 958ffc4..d04e896 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -543,13 +543,13 @@ public:
void SetRangeName( ScRangeName* pNewRangeName );
/** Find a named expression / range name in either global or a local scope.
- @param nIndex
- Index of named expression / range name.
@param nTab
If <0 search nIndex in global scope, if >=0 search nIndex in scope of nTab.
+ @param nIndex
+ Index of named expression / range name.
@return nullptr if indexed name not found.
*/
- ScRangeData* FindRangeNameByIndexAndSheet( sal_uInt16 nIndex, SCTAB nTab ) const;
+ ScRangeData* FindRangeNameBySheetAndIndex( SCTAB nTab, sal_uInt16 nIndex ) const;
/**
* Call this immediately before updating all named ranges.
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index e1a42f8..1e3373f 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -107,7 +107,7 @@ static bool lcl_HasRelRef( ScDocument* pDoc, ScTokenArray* pFormula, sal_uInt16
case svIndex:
{
if( t->GetOpCode() == ocName ) // DB areas always absolute
- if( ScRangeData* pRangeData = pDoc->FindRangeNameByIndexAndSheet( t->GetIndex(), t->GetSheet()) )
+ if( ScRangeData* pRangeData = pDoc->FindRangeNameBySheetAndIndex( t->GetSheet(), t->GetIndex()) )
if( (nRecursion < 42) && lcl_HasRelRef( pDoc, pRangeData->GetCode(), nRecursion + 1 ) )
return true;
}
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index c6ae38f..9eac83d 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -244,7 +244,7 @@ const ScRangeData* ScDocument::GetRangeAtBlock( const ScRange& rBlock, OUString*
return pData;
}
-ScRangeData* ScDocument::FindRangeNameByIndexAndSheet( sal_uInt16 nIndex, SCTAB nTab ) const
+ScRangeData* ScDocument::FindRangeNameBySheetAndIndex( SCTAB nTab, sal_uInt16 nIndex ) const
{
const ScRangeName* pRN = (nTab < 0 ? GetRangeName() : GetRangeName(nTab));
return (pRN ? pRN->findByIndex( nIndex) : nullptr);
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index d3bb65e..a916816 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -466,7 +466,7 @@ bool findRangeNamesReferencingSheet( sc::UpdatedRangeNames& rIndexes, const Form
SAL_WARN("sc.core", "findRangeNamesReferencingSheet - nTokenTab < -1 : " <<
nTokenTab << ", nTokenIndex " << nTokenIndex << " Fix the creator!");
#if OSL_DEBUG_LEVEL > 0
- const ScRangeData* pData = pDoc->FindRangeNameByIndexAndSheet( nTokenIndex, nTokenTab);
+ const ScRangeData* pData = pDoc->FindRangeNameBySheetAndIndex( nTokenTab, nTokenIndex);
SAL_WARN_IF( pData, "sc.core", "findRangeNamesReferencingSheet - named expression is: " << pData->GetName());
#endif
nTokenTab = -1;
@@ -485,7 +485,7 @@ bool findRangeNamesReferencingSheet( sc::UpdatedRangeNames& rIndexes, const Form
if (rIndexes.isNameUpdated( nTokenTab, nTokenIndex))
return true;
- ScRangeData* pData = pDoc->FindRangeNameByIndexAndSheet( nTokenIndex, nTokenTab);
+ ScRangeData* pData = pDoc->FindRangeNameBySheetAndIndex( nTokenTab, nTokenIndex);
if (!pData)
return false;
@@ -1235,7 +1235,7 @@ ScFormulaCell::ScFormulaCell( const ScFormulaCell& rCell, ScDocument& rDoc, cons
}
else if ( t->GetType() == svIndex )
{
- const ScRangeData* pRangeData = rDoc.FindRangeNameByIndexAndSheet( t->GetIndex(), t->GetSheet());
+ const ScRangeData* pRangeData = rDoc.FindRangeNameBySheetAndIndex( t->GetSheet(), t->GetIndex());
if( pRangeData )
{
if( pRangeData->HasReferences() )
@@ -3899,7 +3899,7 @@ void ScFormulaCell::UpdateTranspose( const ScRange& rSource, const ScAddress& rD
{
if( t->GetOpCode() == ocName )
{
- const ScRangeData* pName = pDocument->FindRangeNameByIndexAndSheet( t->GetIndex(), t->GetSheet());
+ const ScRangeData* pName = pDocument->FindRangeNameBySheetAndIndex( t->GetSheet(), t->GetIndex());
if (pName)
{
if (pName->IsModified())
@@ -3953,7 +3953,7 @@ void ScFormulaCell::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY
{
if( t->GetOpCode() == ocName )
{
- const ScRangeData* pName = pDocument->FindRangeNameByIndexAndSheet( t->GetIndex(), t->GetSheet());
+ const ScRangeData* pName = pDocument->FindRangeNameBySheetAndIndex( t->GetSheet(), t->GetIndex());
if (pName)
{
if (pName->IsModified())
@@ -3998,7 +3998,7 @@ static void lcl_FindRangeNamesInUse(sc::UpdatedRangeNames& rIndexes, ScTokenArra
if (nRecursion < 126) // whatever.. 42*3
{
- ScRangeData* pSubName = pDoc->FindRangeNameByIndexAndSheet( nTokenIndex, nTab);
+ ScRangeData* pSubName = pDoc->FindRangeNameBySheetAndIndex( nTab, nTokenIndex);
if (pSubName)
lcl_FindRangeNamesInUse(rIndexes, pSubName->GetCode(), pDoc, nRecursion+1);
}
diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx
index 803140d..1f4583e 100644
--- a/sc/source/core/data/validat.cxx
+++ b/sc/source/core/data/validat.cxx
@@ -694,7 +694,7 @@ bool ScValidationData::GetSelectionFromFormula(
}
else if (eOpCode == ocName)
{
- const ScRangeData* pName = pDocument->FindRangeNameByIndexAndSheet( t->GetIndex(), t->GetSheet());
+ const ScRangeData* pName = pDocument->FindRangeNameBySheetAndIndex( t->GetSheet(), t->GetIndex());
if (pName && pName->IsReference(aRange))
{
bRef = true;
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index e760997..958f5b3 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -4435,7 +4435,7 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula, const OUStrin
ScRangeData* ScCompiler::GetRangeData( const FormulaToken& rToken ) const
{
- return pDoc->FindRangeNameByIndexAndSheet( rToken.GetIndex(), rToken.GetSheet());
+ return pDoc->FindRangeNameBySheetAndIndex( rToken.GetSheet(), rToken.GetIndex());
}
bool ScCompiler::HandleRange()
More information about the Libreoffice-commits
mailing list