[Libreoffice-commits] core.git: sc/inc sc/source
Eike Rathke
erack at redhat.com
Fri Mar 18 11:30:21 UTC 2016
sc/inc/column.hxx | 2 +-
sc/inc/formulacell.hxx | 3 ++-
sc/inc/refupdatecontext.hxx | 13 +++++++++----
sc/inc/table.hxx | 2 +-
sc/source/core/data/column.cxx | 6 +++---
sc/source/core/data/document.cxx | 9 ++++++---
sc/source/core/data/formulacell.cxx | 19 +++++++------------
sc/source/core/data/refupdatecontext.cxx | 14 ++++++++++++++
sc/source/core/data/table1.cxx | 2 +-
9 files changed, 44 insertions(+), 26 deletions(-)
New commits:
commit 090de0e963fd3b0c7c4f8db4124b71b0fd92f61f
Author: Eike Rathke <erack at redhat.com>
Date: Fri Mar 18 12:27:09 2016 +0100
let FindRangeNamesInUse() collect also sheet-local names, tdf#96915 related
... though CopyRangeNamesToClip()/copyUsedNamesToClip() don't handle
them yet.
Change-Id: I570c13725ed6448688d1a2ce877f8bc1d1ff9916
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 62009ca..38e49b6 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -418,7 +418,7 @@ public:
void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
void SetTabNo(SCTAB nNewTab);
- void FindRangeNamesInUse(SCROW nRow1, SCROW nRow2, std::set<sal_uInt16>& rIndexes) const;
+ void FindRangeNamesInUse(SCROW nRow1, SCROW nRow2, sc::UpdatedRangeNames& rIndexes) const;
void PreprocessRangeNameUpdate(
sc::EndListeningContext& rEndListenCxt, sc::CompileFormulaContext& rCompileCxt );
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index d2c8c70..2d4c047 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -46,6 +46,7 @@ struct RefUpdateDeleteTabContext;
struct RefUpdateMoveTabContext;
class CompileFormulaContext;
class FormulaGroupAreaListener;
+class UpdatedRangeNames;
}
@@ -276,7 +277,7 @@ public:
void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nTabNo );
bool TestTabRefAbs(SCTAB nTable);
void UpdateCompile( bool bForceIfNameInUse = false );
- void FindRangeNamesInUse(std::set<sal_uInt16>& rIndexes) const;
+ void FindRangeNamesInUse(sc::UpdatedRangeNames& rIndexes) const;
bool IsSubTotal() const { return bSubTotal;}
bool IsChanged() const { return bChanged;}
void SetChanged(bool b);
diff --git a/sc/inc/refupdatecontext.hxx b/sc/inc/refupdatecontext.hxx
index bee194c..272c3a2 100644
--- a/sc/inc/refupdatecontext.hxx
+++ b/sc/inc/refupdatecontext.hxx
@@ -24,17 +24,22 @@ namespace sc {
/**
* Keep track of all named expressions that have been updated during
* reference update.
+ *
+ * Can also be used to collect any set of named expressions / ranges.
*/
class UpdatedRangeNames
{
+public:
typedef std::unordered_set<sal_uInt16> NameIndicesType;
- typedef std::unordered_map<SCTAB, NameIndicesType> UpdatedNamesType;
-
- UpdatedNamesType maUpdatedNames;
-public:
void setUpdatedName(SCTAB nTab, sal_uInt16 nIndex);
bool isNameUpdated(SCTAB nTab, sal_uInt16 nIndex) const;
+ NameIndicesType getUpdatedNames(SCTAB nTab) const;
+
+private:
+ typedef std::unordered_map<SCTAB, NameIndicesType> UpdatedNamesType;
+
+ UpdatedNamesType maUpdatedNames;
};
/**
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 95d3225..31b277f 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -565,7 +565,7 @@ public:
void UpdateCompile( bool bForceIfNameInUse = false );
void SetTabNo(SCTAB nNewTab);
void FindRangeNamesInUse(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
- std::set<sal_uInt16>& rIndexes) const;
+ sc::UpdatedRangeNames& rIndexes) const;
void Fill( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
sal_uLong nFillCount, FillDir eFillDir, FillCmd eFillCmd, FillDateCmd eFillDateCmd,
double nStepValue, double nMaxValue, ScProgress* pProgress);
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index ce2ab47..f3ae280 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -2632,9 +2632,9 @@ public:
class UsedRangeNameFinder
{
- std::set<sal_uInt16>& mrIndexes;
+ sc::UpdatedRangeNames& mrIndexes;
public:
- explicit UsedRangeNameFinder(std::set<sal_uInt16>& rIndexes) : mrIndexes(rIndexes) {}
+ explicit UsedRangeNameFinder(sc::UpdatedRangeNames& rIndexes) : mrIndexes(rIndexes) {}
void operator() (size_t /*nRow*/, const ScFormulaCell* pCell)
{
@@ -3060,7 +3060,7 @@ void ScColumn::SetTabNo(SCTAB nNewTab)
sc::ProcessFormula(maCells, aFunc);
}
-void ScColumn::FindRangeNamesInUse(SCROW nRow1, SCROW nRow2, std::set<sal_uInt16>& rIndexes) const
+void ScColumn::FindRangeNamesInUse(SCROW nRow1, SCROW nRow2, sc::UpdatedRangeNames& rIndexes) const
{
UsedRangeNameFinder aFunc(rIndexes);
sc::ParseFormula(maCells.begin(), maCells, nRow1, nRow2, aFunc);
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 73eb510..53544c5 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -2328,7 +2328,8 @@ void ScDocument::TransposeClip( ScDocument* pTransClip, InsertDeleteFlags nFlags
namespace {
-void copyUsedNamesToClip(ScRangeName* pClipRangeName, ScRangeName* pRangeName, const std::set<sal_uInt16>& rUsedNames)
+void copyUsedNamesToClip(ScRangeName* pClipRangeName, ScRangeName* pRangeName,
+ const sc::UpdatedRangeNames::NameIndicesType& rUsedNames)
{
pClipRangeName->clear();
ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end();
@@ -2352,7 +2353,7 @@ void ScDocument::CopyRangeNamesToClip(ScDocument* pClipDoc, const ScRange& rClip
if (!pRangeName || pRangeName->empty())
return;
- std::set<sal_uInt16> aUsedNames; // indexes of named ranges that are used in the copied cells
+ sc::UpdatedRangeNames aUsedNames; // indexes of named ranges that are used in the copied cells
SCTAB nMinSizeBothTabs = static_cast<SCTAB>(std::min(maTabs.size(), pClipDoc->maTabs.size()));
for (SCTAB i = 0; i < nMinSizeBothTabs; ++i)
if (maTabs[i] && pClipDoc->maTabs[i])
@@ -2361,7 +2362,9 @@ void ScDocument::CopyRangeNamesToClip(ScDocument* pClipDoc, const ScRange& rClip
rClipRange.aStart.Col(), rClipRange.aStart.Row(),
rClipRange.aEnd.Col(), rClipRange.aEnd.Row(), aUsedNames);
- copyUsedNamesToClip(pClipDoc->GetRangeName(), pRangeName, aUsedNames);
+ /* TODO: handle also sheet-local names */
+ sc::UpdatedRangeNames::NameIndicesType aUsedGlobalNames( aUsedNames.getUpdatedNames(-1));
+ copyUsedNamesToClip(pClipDoc->GetRangeName(), pRangeName, aUsedGlobalNames);
}
ScDocument::NumFmtMergeHandler::NumFmtMergeHandler(ScDocument* pDoc, ScDocument* pSrcDoc) :
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 0db0ab4..9ef82e4 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -3700,31 +3700,26 @@ void ScFormulaCell::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY
StartListeningTo( pDocument ); // Listener as previous
}
-static void lcl_FindRangeNamesInUse(std::set<sal_uInt16>& rIndexes, ScTokenArray* pCode, ScRangeName* pNames)
+static void lcl_FindRangeNamesInUse(sc::UpdatedRangeNames& rIndexes, ScTokenArray* pCode, const ScDocument* pDoc)
{
for (FormulaToken* p = pCode->First(); p; p = pCode->Next())
{
if (p->GetOpCode() == ocName)
{
- /* TODO: this should collect also sheet-local names, currently it
- * collects only global names. But looking even for indexes of
- * local names.. this always was wrong. Probably use
- * UpdatedRangeNames instead of the set, but doing so would also
- * need more work in copying things over clipboard and such. */
-
sal_uInt16 nTokenIndex = p->GetIndex();
- rIndexes.insert( nTokenIndex );
+ SCTAB nTab = p->GetSheet();
+ rIndexes.setUpdatedName( nTab, nTokenIndex);
- ScRangeData* pSubName = pNames->findByIndex(p->GetIndex());
+ ScRangeData* pSubName = pDoc->FindRangeNameByIndexAndSheet( nTokenIndex, nTab);
if (pSubName)
- lcl_FindRangeNamesInUse(rIndexes, pSubName->GetCode(), pNames);
+ lcl_FindRangeNamesInUse(rIndexes, pSubName->GetCode(), pDoc);
}
}
}
-void ScFormulaCell::FindRangeNamesInUse(std::set<sal_uInt16>& rIndexes) const
+void ScFormulaCell::FindRangeNamesInUse(sc::UpdatedRangeNames& rIndexes) const
{
- lcl_FindRangeNamesInUse( rIndexes, pCode, pDocument->GetRangeName() );
+ lcl_FindRangeNamesInUse( rIndexes, pCode, pDocument );
}
void ScFormulaCell::SetChanged(bool b)
diff --git a/sc/source/core/data/refupdatecontext.cxx b/sc/source/core/data/refupdatecontext.cxx
index 07cb060..79a3792b 100644
--- a/sc/source/core/data/refupdatecontext.cxx
+++ b/sc/source/core/data/refupdatecontext.cxx
@@ -14,6 +14,11 @@ namespace sc {
void UpdatedRangeNames::setUpdatedName(SCTAB nTab, sal_uInt16 nIndex)
{
+ // Map anything <-1 to global names. Unless we really want to come up with
+ // some classification there..
+ if (nTab < -1)
+ nTab = -1;
+
UpdatedNamesType::iterator it = maUpdatedNames.find(nTab);
if (it == maUpdatedNames.end())
{
@@ -43,6 +48,15 @@ bool UpdatedRangeNames::isNameUpdated(SCTAB nTab, sal_uInt16 nIndex) const
return rIndices.count(nIndex) > 0;
}
+UpdatedRangeNames::NameIndicesType UpdatedRangeNames::getUpdatedNames(SCTAB nTab) const
+{
+ UpdatedNamesType::const_iterator it = maUpdatedNames.find(nTab);
+ if (it == maUpdatedNames.end())
+ return NameIndicesType();
+ return it->second;
+}
+
+
RefUpdateContext::RefUpdateContext(ScDocument& rDoc) :
mrDoc(rDoc), meMode(URM_INSDEL), mnColDelta(0), mnRowDelta(0), mnTabDelta(0) {}
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 2d79511..af61151 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1709,7 +1709,7 @@ void ScTable::SetTabNo(SCTAB nNewTab)
}
void ScTable::FindRangeNamesInUse(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
- std::set<sal_uInt16>& rIndexes) const
+ sc::UpdatedRangeNames& rIndexes) const
{
for (SCCOL i = nCol1; i <= nCol2 && ValidCol(i); i++)
aCol[i].FindRangeNamesInUse(nRow1, nRow2, rIndexes);
More information about the Libreoffice-commits
mailing list