From 450a10d5fb193ec2a7d85ae604790b9dda1e3602 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Fri, 29 Apr 2016 15:56:24 +0200 Subject: introduce ScRangeName::CopyUsedNames() Change-Id: I2f3e88f70e5d7b9b4728f5bdd0a8237c7bcc7dcb --- sc/inc/rangenam.hxx | 20 ++++++++++++++++++++ sc/source/core/tool/rangenam.cxx | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'sc') diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx index c3fff07dde55..a7a5aa81ccd3 100644 --- a/sc/inc/rangenam.hxx +++ b/sc/inc/rangenam.hxx @@ -213,6 +213,26 @@ public: */ void CompileUnresolvedXML( sc::CompileFormulaContext& rCxt ); + /** Copy names while copying a sheet if they reference the sheet to be copied. + + Assumes that new sheet was already inserted, global names have been + updated/adjusted, but sheet-local names on nOldTab are not, as is the + case in ScDocument::CopyTab() + + @param nLocalTab + -1 when operating on global names, else sheet/tab of + sheet-local name scope. The already adjusted tab on which to + find the name. + + @param nOldTab + The original unadjusted tab position. + + @param nNewTab + The new tab position. + */ + void CopyUsedNames( const SCTAB nLocalTab, const SCTAB nOldTab, const SCTAB nNewTab, + const ScDocument& rOldDoc, ScDocument& rNewDoc, const bool bGlobalNamesToLocal ) const; + SC_DLLPUBLIC const_iterator begin() const; SC_DLLPUBLIC const_iterator end() const; SC_DLLPUBLIC iterator begin(); diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx index a9ab515d99cc..89500acb0d62 100644 --- a/sc/source/core/tool/rangenam.cxx +++ b/sc/source/core/tool/rangenam.cxx @@ -785,6 +785,22 @@ void ScRangeName::CompileUnresolvedXML( sc::CompileFormulaContext& rCxt ) } } +void ScRangeName::CopyUsedNames( const SCTAB nLocalTab, const SCTAB nOldTab, const SCTAB nNewTab, + const ScDocument& rOldDoc, ScDocument& rNewDoc, const bool bGlobalNamesToLocal ) const +{ + for (auto const& itr : m_Data) + { + SCTAB nSheet = (nLocalTab < 0) ? nLocalTab : nOldTab; + sal_uInt16 nIndex = itr.second->GetIndex(); + ScAddress aOldPos( itr.second->GetPos()); + aOldPos.SetTab( nOldTab); + ScAddress aNewPos( aOldPos); + aNewPos.SetTab( nNewTab); + ScRangeData* pRangeData = nullptr; + rOldDoc.CopyAdjustRangeName( nSheet, nIndex, pRangeData, rNewDoc, aNewPos, aOldPos, bGlobalNamesToLocal); + } +} + ScRangeName::const_iterator ScRangeName::begin() const { return m_Data.begin(); -- cgit