ScRefUndoData: pass ScDocument by ref

Change-Id: If389a4581933daccf6f4f5e9c6cda1a24e179d5a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185656
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Tested-by: Jenkins
This commit is contained in:
Xisco Fauli
2025-05-22 20:51:24 +02:00
parent 277364ed05
commit b046d0cfd4
15 changed files with 70 additions and 70 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ public:
~ScUnoRefList();
void Add( sal_Int64 nId, const ScRangeList& rOldRanges );
void Undo( ScDocument* pDoc );
void Undo( ScDocument& rDoc );
bool IsEmpty() const { return aEntries.empty(); }
};
+1 -1
View File
@@ -811,7 +811,7 @@ ScUndoPaste* ScUcalcTestBase::createUndoPaste(ScDocShell& rDocSh, const ScRange&
ScDocument& rDoc = rDocSh.GetDocument();
ScMarkData aMarkData(rDoc.GetSheetLimits());
aMarkData.SetMarkArea(rRange);
std::unique_ptr<ScRefUndoData> pRefUndoData(new ScRefUndoData(&rDoc));
std::unique_ptr<ScRefUndoData> pRefUndoData(new ScRefUndoData(rDoc));
return new ScUndoPaste(
&rDocSh, rRange, aMarkData, std::move(pUndoDoc), nullptr, InsertDeleteFlags::ALL, std::move(pRefUndoData), false);
+2 -2
View File
@@ -175,7 +175,7 @@ void TestCopyPaste::prepareUndoBeforePaste(bool bCut, ScDocumentUniquePtr& pPast
pPasteRefUndoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
pPasteRefUndoDoc->InitUndo(*m_pDoc, 0, nTabCount - 1);
pUndoData.reset(new ScRefUndoData(m_pDoc));
pUndoData.reset(new ScRefUndoData(*m_pDoc));
}
}
@@ -9344,7 +9344,7 @@ CPPUNIT_TEST_FIXTURE(TestCopyPaste, testCopyPasteSkipEmpty)
m_pDoc->CopyToDocument(aDestRange, InsertDeleteFlags::ALL, false, *pRedoDoc, &aMark);
// Create an undo object for this.
std::unique_ptr<ScRefUndoData> pRefUndoData(new ScRefUndoData(m_pDoc));
std::unique_ptr<ScRefUndoData> pRefUndoData(new ScRefUndoData(*m_pDoc));
ScUndoPaste aUndo(m_xDocShell.get(), aDestRange, aMark, std::move(pUndoDoc),
std::move(pRedoDoc), InsertDeleteFlags::ALL, std::move(pRefUndoData));
+3 -3
View File
@@ -1948,7 +1948,7 @@ bool ScDocFunc::InsertCells( const ScRange& rRange, const ScMarkData* pTabMark,
// pRefUndoDoc is filled in InsertCol / InsertRow
pUndoData.reset(new ScRefUndoData( &rDoc ));
pUndoData.reset(new ScRefUndoData( rDoc ));
rDoc.BeginDrawUndo();
}
@@ -2621,7 +2621,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark,
pRefUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
pRefUndoDoc->InitUndo( rDoc, 0, nTabCount-1 );
pUndoData.reset(new ScRefUndoData( &rDoc ));
pUndoData.reset(new ScRefUndoData( rDoc ));
rDoc.BeginDrawUndo();
}
@@ -3394,7 +3394,7 @@ bool ScDocFunc::DeleteTable( SCTAB nTab, bool bRecord )
// Drawing-Layer has to take care of its own undo!!!
rDoc.BeginDrawUndo(); // DeleteTab generates SdrUndoDelPage
pUndoData.reset(new ScRefUndoData( &rDoc ));
pUndoData.reset(new ScRefUndoData( rDoc ));
}
if (rDoc.DeleteTab(nTab))
+4 -4
View File
@@ -44,7 +44,7 @@ public:
bool IsEqualSource( const ScAreaLink& rCompare ) const;
void WriteToLink( ScAreaLink& rLink ) const;
void InsertNewLink( ScDocument* pDoc );
void InsertNewLink( ScDocument& rDoc );
};
class ScAreaLinkSaveCollection
@@ -55,11 +55,11 @@ public:
ScAreaLinkSaveCollection();
~ScAreaLinkSaveCollection();
bool IsEqual( const ScDocument* pDoc ) const;
void Restore( ScDocument* pDoc );
bool IsEqual( ScDocument& rDoc ) const;
void Restore( ScDocument& rDoc );
// returns NULL if empty
static std::unique_ptr<ScAreaLinkSaveCollection> CreateFromDoc( const ScDocument* pDoc );
static std::unique_ptr<ScAreaLinkSaveCollection> CreateFromDoc( ScDocument& rDoc );
ScAreaLinkSaver& operator[](size_t nIndex);
const ScAreaLinkSaver& operator[](size_t nIndex) const;
+3 -3
View File
@@ -45,11 +45,11 @@ private:
std::unique_ptr<ScUnoRefList> pUnoRefs;
public:
ScRefUndoData( const ScDocument* pDoc );
ScRefUndoData(ScDocument& rDoc );
~ScRefUndoData();
void DeleteUnchanged( const ScDocument* pDoc );
void DoUndo( ScDocument* pDoc, bool bUndoRefFirst );
void DeleteUnchanged(ScDocument& rDoc);
void DoUndo(ScDocument& rDoc, bool bUndoRefFirst );
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+10 -10
View File
@@ -55,12 +55,12 @@ void ScAreaLinkSaver::WriteToLink( ScAreaLink& rLink ) const
rLink.SetDestArea( aDestArea );
}
void ScAreaLinkSaver::InsertNewLink( ScDocument* pDoc )
void ScAreaLinkSaver::InsertNewLink( ScDocument& rDoc )
{
// (see ScUndoRemoveAreaLink::Undo)
sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
ScDocShell* pObjSh = pDoc->GetDocumentShell();
sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager();
ScDocShell* pObjSh = rDoc.GetDocumentShell();
if ( pLinkManager && pObjSh )
{
@@ -79,12 +79,12 @@ ScAreaLinkSaveCollection::ScAreaLinkSaveCollection() {}
ScAreaLinkSaveCollection::~ScAreaLinkSaveCollection() {}
bool ScAreaLinkSaveCollection::IsEqual( const ScDocument* pDoc ) const
bool ScAreaLinkSaveCollection::IsEqual( ScDocument& rDoc ) const
{
// IsEqual can be checked in sequence.
// Neither ref-update nor removing links will change the order.
const sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
const sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager();
if (pLinkManager)
{
size_t nPos = 0;
@@ -121,14 +121,14 @@ static ScAreaLink* lcl_FindLink( const ::sfx2::SvBaseLinks& rLinks, const ScArea
return nullptr; // not found
}
void ScAreaLinkSaveCollection::Restore( ScDocument* pDoc )
void ScAreaLinkSaveCollection::Restore( ScDocument& rDoc )
{
// The save collection may contain additional entries that are not in the document.
// They must be inserted again.
// Entries from the save collection must be searched via source data, as the order
// of links changes if deleted entries are re-added to the link manager (always at the end).
sfx2::LinkManager* pLinkManager = pDoc->GetDocLinkManager().getLinkManager(false);
sfx2::LinkManager* pLinkManager = rDoc.GetDocLinkManager().getLinkManager(false);
if (!pLinkManager)
return;
@@ -141,15 +141,15 @@ void ScAreaLinkSaveCollection::Restore( ScDocument* pDoc )
if ( pLink )
rSaver.WriteToLink( *pLink ); // restore output position
else
rSaver.InsertNewLink( pDoc ); // re-insert deleted link
rSaver.InsertNewLink( rDoc ); // re-insert deleted link
}
}
std::unique_ptr<ScAreaLinkSaveCollection> ScAreaLinkSaveCollection::CreateFromDoc( const ScDocument* pDoc )
std::unique_ptr<ScAreaLinkSaveCollection> ScAreaLinkSaveCollection::CreateFromDoc( ScDocument& rDoc )
{
std::unique_ptr<ScAreaLinkSaveCollection> pColl;
sfx2::LinkManager* pLinkManager = const_cast<ScDocument*>(pDoc)->GetLinkManager();
sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager();
if (pLinkManager)
{
const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
+31 -31
View File
@@ -30,34 +30,34 @@
#include <scopetools.hxx>
#include <refupdatecontext.hxx>
ScRefUndoData::ScRefUndoData( const ScDocument* pDoc ) :
pPrintRanges(pDoc->CreatePrintRangeSaver())
ScRefUndoData::ScRefUndoData( ScDocument& rDoc ) :
pPrintRanges(rDoc.CreatePrintRangeSaver())
{
const ScDBCollection* pOldDBColl = pDoc->GetDBCollection();
const ScDBCollection* pOldDBColl = rDoc.GetDBCollection();
if (pOldDBColl && !pOldDBColl->empty())
pDBCollection.reset(new ScDBCollection(*pOldDBColl));
const ScRangeName* pOldRanges = pDoc->GetRangeName();
const ScRangeName* pOldRanges = rDoc.GetRangeName();
if (pOldRanges && !pOldRanges->empty())
pRangeName.reset(new ScRangeName(*pOldRanges));
// when handling Pivot solely keep the range?
const ScDPCollection* pOldDP = pDoc->GetDPCollection();
const ScDPCollection* pOldDP = rDoc.GetDPCollection();
if (pOldDP && pOldDP->GetCount())
pDPCollection.reset(new ScDPCollection(*pOldDP));
const ScDetOpList* pOldDetOp = pDoc->GetDetOpList();
const ScDetOpList* pOldDetOp = rDoc.GetDetOpList();
if (pOldDetOp && pOldDetOp->Count())
pDetOpList.reset(new ScDetOpList(*pOldDetOp));
const ScChartListenerCollection* pOldChartLisColl = pDoc->GetChartListenerCollection();
const ScChartListenerCollection* pOldChartLisColl = rDoc.GetChartListenerCollection();
if (pOldChartLisColl)
pChartListenerCollection.reset(new ScChartListenerCollection(*pOldChartLisColl));
pAreaLinks = ScAreaLinkSaveCollection::CreateFromDoc(pDoc); // returns NULL if empty
pAreaLinks = ScAreaLinkSaveCollection::CreateFromDoc(rDoc); // returns NULL if empty
const_cast<ScDocument*>(pDoc)->BeginUnoRefUndo();
rDoc.BeginUnoRefUndo();
}
ScRefUndoData::~ScRefUndoData()
@@ -71,38 +71,38 @@ ScRefUndoData::~ScRefUndoData()
pAreaLinks.reset();
}
void ScRefUndoData::DeleteUnchanged( const ScDocument* pDoc )
void ScRefUndoData::DeleteUnchanged( ScDocument& rDoc )
{
if (pDBCollection)
{
ScDBCollection* pNewDBColl = pDoc->GetDBCollection();
ScDBCollection* pNewDBColl = rDoc.GetDBCollection();
if ( pNewDBColl && *pDBCollection == *pNewDBColl )
pDBCollection.reset();
}
if (pRangeName)
{
ScRangeName* pNewRanges = pDoc->GetRangeName();
ScRangeName* pNewRanges = rDoc.GetRangeName();
if ( pNewRanges && *pRangeName == *pNewRanges )
pRangeName.reset();
}
if (pPrintRanges)
{
std::unique_ptr<ScPrintRangeSaver> pNewRanges = pDoc->CreatePrintRangeSaver();
std::unique_ptr<ScPrintRangeSaver> pNewRanges = rDoc.CreatePrintRangeSaver();
if ( pNewRanges && *pPrintRanges == *pNewRanges )
pPrintRanges.reset();
}
if (pDPCollection)
{
ScDPCollection* pNewDP = const_cast<ScDocument*>(pDoc)->GetDPCollection(); //! const
ScDPCollection* pNewDP = rDoc.GetDPCollection(); //! const
if ( pNewDP && pDPCollection->RefsEqual(*pNewDP) )
pDPCollection.reset();
}
if (pDetOpList)
{
ScDetOpList* pNewDetOp = pDoc->GetDetOpList();
ScDetOpList* pNewDetOp = rDoc.GetDetOpList();
if ( pNewDetOp && *pDetOpList == *pNewDetOp )
pDetOpList.reset();
}
@@ -110,7 +110,7 @@ void ScRefUndoData::DeleteUnchanged( const ScDocument* pDoc )
if ( pChartListenerCollection )
{
ScChartListenerCollection* pNewChartListenerCollection =
pDoc->GetChartListenerCollection();
rDoc.GetChartListenerCollection();
if ( pNewChartListenerCollection &&
*pChartListenerCollection == *pNewChartListenerCollection )
pChartListenerCollection.reset();
@@ -118,13 +118,13 @@ void ScRefUndoData::DeleteUnchanged( const ScDocument* pDoc )
if (pAreaLinks)
{
if ( pAreaLinks->IsEqual( pDoc ) )
if ( pAreaLinks->IsEqual( rDoc ) )
pAreaLinks.reset();
}
if ( pDoc->HasUnoRefUndo() )
if ( rDoc.HasUnoRefUndo() )
{
pUnoRefs = const_cast<ScDocument*>(pDoc)->EndUnoRefUndo();
pUnoRefs = rDoc.EndUnoRefUndo();
if ( pUnoRefs && pUnoRefs->IsEmpty() )
{
pUnoRefs.reset();
@@ -132,45 +132,45 @@ void ScRefUndoData::DeleteUnchanged( const ScDocument* pDoc )
}
}
void ScRefUndoData::DoUndo( ScDocument* pDoc, bool bUndoRefFirst )
void ScRefUndoData::DoUndo( ScDocument& rDoc, bool bUndoRefFirst )
{
if (pDBCollection)
pDoc->SetDBCollection( std::unique_ptr<ScDBCollection>(new ScDBCollection(*pDBCollection)) );
rDoc.SetDBCollection( std::unique_ptr<ScDBCollection>(new ScDBCollection(*pDBCollection)) );
if (pRangeName)
pDoc->SetRangeName( std::unique_ptr<ScRangeName>(new ScRangeName(*pRangeName)) );
rDoc.SetRangeName( std::unique_ptr<ScRangeName>(new ScRangeName(*pRangeName)) );
if (pPrintRanges)
pDoc->RestorePrintRanges(*pPrintRanges);
rDoc.RestorePrintRanges(*pPrintRanges);
if (pDPCollection)
{
ScDPCollection* pDocDP = pDoc->GetDPCollection();
ScDPCollection* pDocDP = rDoc.GetDPCollection();
if (pDocDP)
pDPCollection->WriteRefsTo( *pDocDP );
}
if (pDetOpList)
pDoc->SetDetOpList( std::unique_ptr<ScDetOpList>(new ScDetOpList(*pDetOpList)) );
rDoc.SetDetOpList( std::unique_ptr<ScDetOpList>(new ScDetOpList(*pDetOpList)) );
// bUndoRefFirst is bSetChartRangeLists
if ( pChartListenerCollection )
pDoc->SetChartListenerCollection( std::make_unique<ScChartListenerCollection>(
rDoc.SetChartListenerCollection( std::make_unique<ScChartListenerCollection>(
*pChartListenerCollection ), bUndoRefFirst );
if (pDBCollection || pRangeName)
{
sc::AutoCalcSwitch aACSwitch(*pDoc, false);
pDoc->CompileAll();
sc::AutoCalcSwitch aACSwitch(rDoc, false);
rDoc.CompileAll();
sc::SetFormulaDirtyContext aCxt;
pDoc->SetAllFormulasDirty(aCxt);
rDoc.SetAllFormulasDirty(aCxt);
}
if (pAreaLinks)
pAreaLinks->Restore( pDoc );
pAreaLinks->Restore( rDoc );
if ( pUnoRefs )
pUnoRefs->Undo( pDoc );
pUnoRefs->Undo( rDoc );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+2 -2
View File
@@ -427,7 +427,7 @@ ScMoveUndo::ScMoveUndo( ScDocShell* pDocSh, ScDocumentUniquePtr pRefDoc, std::un
{
ScDocument& rDoc = pDocShell->GetDocument();
if (pRefUndoData)
pRefUndoData->DeleteUnchanged(&rDoc);
pRefUndoData->DeleteUnchanged(rDoc);
pDrawUndo = GetSdrUndoAction( &rDoc );
}
@@ -444,7 +444,7 @@ void ScMoveUndo::UndoRef()
ScRange aRange(0,0,0, rDoc.MaxCol(),rDoc.MaxRow(),pRefUndoDoc->GetTableCount()-1);
pRefUndoDoc->CopyToDocument(aRange, InsertDeleteFlags::FORMULA, false, rDoc, nullptr, false);
if (pRefUndoData)
pRefUndoData->DoUndo( &rDoc, false );
pRefUndoData->DoUndo( rDoc, false );
}
void ScMoveUndo::BeginUndo()
+4 -4
View File
@@ -926,7 +926,7 @@ ScUndoPaste::ScUndoPaste( ScDocShell* pNewDocShell, const ScRangeList& rRanges,
bRedoFilled( bRedoIsFilled )
{
if ( pRefUndoData )
pRefUndoData->DeleteUnchanged( &pDocShell->GetDocument() );
pRefUndoData->DeleteUnchanged( pDocShell->GetDocument() );
if ( pOptions )
aPasteOptions = *pOptions; // used only for Repeat
@@ -970,7 +970,7 @@ void ScUndoPaste::DoChange(bool bUndo)
// (with DeleteUnchanged after the DoUndo call)
bool bCreateRedoData = ( bUndo && pRefUndoData && !pRefRedoData );
if ( bCreateRedoData )
pRefRedoData.reset( new ScRefUndoData( &rDoc ) );
pRefRedoData.reset( new ScRefUndoData( rDoc ) );
ScRefUndoData* pWorkRefData = bUndo ? pRefUndoData.get() : pRefRedoData.get();
@@ -1058,14 +1058,14 @@ void ScUndoPaste::DoChange(bool bUndo)
if (pWorkRefData)
{
pWorkRefData->DoUndo( &rDoc, true ); // true = bSetChartRangeLists for SetChartListenerCollection
pWorkRefData->DoUndo( rDoc, true ); // true = bSetChartRangeLists for SetChartListenerCollection
if (!maBlockRanges.empty() &&
rDoc.RefreshAutoFilter(0, 0, rDoc.MaxCol(), rDoc.MaxRow(), maBlockRanges[0].aStart.Tab()))
bPaintAll = true;
}
if ( bCreateRedoData && pRefRedoData )
pRefRedoData->DeleteUnchanged( &rDoc );
pRefRedoData->DeleteUnchanged( rDoc );
if (bUndo) // Undo: UndoToDocument after handling RefData
{
+4 -4
View File
@@ -1820,7 +1820,7 @@ ScUndoDataForm::ScUndoDataForm( ScDocShell* pNewDocShell,
mxMarkData->SetMarkArea(aBlockRange); // mark paste block
if (xRefUndoData)
xRefUndoData->DeleteUnchanged(&pDocShell->GetDocument());
xRefUndoData->DeleteUnchanged(pDocShell->GetDocument());
}
OUString ScUndoDataForm::GetComment() const
@@ -1865,7 +1865,7 @@ void ScUndoDataForm::DoChange( const bool bUndo )
// (with DeleteUnchanged after the DoUndo call)
bool bCreateRedoData = (bUndo && xRefUndoData && !xRefRedoData);
if (bCreateRedoData)
xRefRedoData.reset(new ScRefUndoData(&rDoc));
xRefRedoData.reset(new ScRefUndoData(rDoc));
ScRefUndoData* pWorkRefData = bUndo ? xRefUndoData.get() : xRefRedoData.get();
@@ -1905,13 +1905,13 @@ void ScUndoDataForm::DoChange( const bool bUndo )
if (pWorkRefData)
{
pWorkRefData->DoUndo( &rDoc, true ); // TRUE = bSetChartRangeLists for SetChartListenerCollection
pWorkRefData->DoUndo( rDoc, true ); // TRUE = bSetChartRangeLists for SetChartListenerCollection
if ( rDoc.RefreshAutoFilter( 0,0, rDoc.MaxCol(),rDoc.MaxRow(), aBlockRange.aStart.Tab() ) )
bPaintAll = true;
}
if (bCreateRedoData && xRefRedoData)
xRefRedoData->DeleteUnchanged(&rDoc);
xRefRedoData->DeleteUnchanged(rDoc);
if ( bUndo )
{
+2 -2
View File
@@ -34,12 +34,12 @@ void ScUnoRefList::Add( sal_Int64 nId, const ScRangeList& rOldRanges )
aEntries.emplace_back( nId, rOldRanges );
}
void ScUnoRefList::Undo( ScDocument* pDoc )
void ScUnoRefList::Undo( ScDocument& rDoc )
{
for (const auto & entry: aEntries)
{
ScUnoRefUndoHint aHint(entry);
pDoc->BroadcastUno( aHint );
rDoc.BroadcastUno( aHint );
}
}
+1 -1
View File
@@ -2623,7 +2623,7 @@ bool ScViewFunc::DeleteTables(const vector<SCTAB> &TheTabs, bool bRecord )
rDoc.BeginDrawUndo(); // DeleteTab creates a SdrUndoDelPage
pUndoData.reset(new ScRefUndoData( &rDoc ));
pUndoData.reset(new ScRefUndoData( rDoc ));
}
bool bDelDone = false;
+1 -1
View File
@@ -1276,7 +1276,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
pRefUndoDoc.reset(new ScDocument( SCDOCMODE_UNDO ));
pRefUndoDoc->InitUndo( rDoc, 0, nTabCount-1 );
pUndoData.reset(new ScRefUndoData( &rDoc ));
pUndoData.reset(new ScRefUndoData( rDoc ));
}
}
+1 -1
View File
@@ -2115,7 +2115,7 @@ void ScViewFunc::DeleteMulti( bool bRows )
pUndoDoc->AddUndoTab( 0, nTabCount-1 );
rDoc.CopyToDocument( 0,0,0, rDoc.MaxCol(), rDoc.MaxRow(), MAXTAB, InsertDeleteFlags::FORMULA,false,*pUndoDoc );
pUndoData.reset(new ScRefUndoData( &rDoc ));
pUndoData.reset(new ScRefUndoData( rDoc ));
rDoc.BeginDrawUndo();
}