From b7654432bfeca619b7657abc8d27193e44cf4dfc Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 20 Mar 2018 12:54:11 +0200 Subject: loplugin:useuniqueptr in ScDocument and fix bug where we were deleting a pointer to an object we did not own via pFormatExchangeList Change-Id: I488c679734c48bd21bc6be04837e037e97550647 Reviewed-on: https://gerrit.libreoffice.org/51668 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sc/source/ui/Accessibility/AccessibleText.cxx | 6 +++--- sc/source/ui/docshell/dbdocfun.cxx | 10 +++++----- sc/source/ui/docshell/docfunc.cxx | 2 +- sc/source/ui/docshell/docsh5.cxx | 6 +++--- sc/source/ui/inc/AccessibleText.hxx | 2 +- sc/source/ui/inc/refundo.hxx | 3 ++- sc/source/ui/undo/refundo.cxx | 9 ++++----- sc/source/ui/undo/undocell.cxx | 6 +++--- sc/source/ui/undo/undodat.cxx | 14 +++++++------- sc/source/ui/unoobj/cellsuno.cxx | 10 ++++------ sc/source/ui/unoobj/docuno.cxx | 2 +- sc/source/ui/unoobj/textuno.cxx | 6 +++--- sc/source/ui/view/cellsh1.cxx | 2 +- sc/source/ui/view/formatsh.cxx | 2 +- 14 files changed, 39 insertions(+), 41 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/Accessibility/AccessibleText.cxx b/sc/source/ui/Accessibility/AccessibleText.cxx index 4842d7b211c6..66bcc5f4ad88 100644 --- a/sc/source/ui/Accessibility/AccessibleText.cxx +++ b/sc/source/ui/Accessibility/AccessibleText.cxx @@ -1251,7 +1251,7 @@ SvxTextForwarder* ScAccessiblePreviewHeaderCellTextData::GetTextForwarder() { SfxItemPool* pEnginePool = EditEngine::CreatePool(); pEnginePool->FreezeIdRanges(); - pEditEngine = new ScFieldEditEngine(nullptr, pEnginePool, nullptr, true); + pEditEngine.reset( new ScFieldEditEngine(nullptr, pEnginePool, nullptr, true) ); } pEditEngine->EnableUndo( false ); if (pDocShell) @@ -1443,7 +1443,7 @@ ScAccessibleNoteTextData::~ScAccessibleNoteTextData() mpDocSh->GetDocument().RemoveUnoObject(*this); if (mpEditEngine) mpEditEngine->SetNotifyHdl(Link()); - delete mpEditEngine; + mpEditEngine.reset(); delete mpForwarder; } @@ -1476,7 +1476,7 @@ SvxTextForwarder* ScAccessibleNoteTextData::GetTextForwarder() { SfxItemPool* pEnginePool = EditEngine::CreatePool(); pEnginePool->FreezeIdRanges(); - mpEditEngine = new ScFieldEditEngine(nullptr, pEnginePool, nullptr, true); + mpEditEngine.reset( new ScFieldEditEngine(nullptr, pEnginePool, nullptr, true) ); } mpEditEngine->EnableUndo( false ); if (mpDocSh) diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx index 7e21ade37edd..3a409e774d64 100644 --- a/sc/source/ui/docshell/dbdocfun.cxx +++ b/sc/source/ui/docshell/dbdocfun.cxx @@ -163,7 +163,7 @@ bool ScDBDocFunc::RenameDBRange( const OUString& rOld, const OUString& rNew ) ScDBData* pNewData = new ScDBData(rNew, **iterOld); - ScDBCollection* pUndoColl = new ScDBCollection( *pDocColl ); + std::unique_ptr pUndoColl( new ScDBCollection( *pDocColl ) ); rDoc.PreprocessDBDataUpdate(); rDBs.erase(iterOld); @@ -171,7 +171,7 @@ bool ScDBDocFunc::RenameDBRange( const OUString& rOld, const OUString& rNew ) if (!bInserted) // error -> restore old state { delete pNewData; - rDoc.SetDBCollection(pUndoColl); // belongs to the document then + rDoc.SetDBCollection(std::move(pUndoColl)); // belongs to the document then } rDoc.CompileHybridFormula(); @@ -182,10 +182,10 @@ bool ScDBDocFunc::RenameDBRange( const OUString& rOld, const OUString& rNew ) { ScDBCollection* pRedoColl = new ScDBCollection( *pDocColl ); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDBData( &rDocShell, pUndoColl, pRedoColl ) ); + new ScUndoDBData( &rDocShell, pUndoColl.release(), pRedoColl ) ); } else - delete pUndoColl; + pUndoColl.reset(); aModificator.SetDocumentModified(); SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScDbAreasChanged ) ); @@ -264,7 +264,7 @@ void ScDBDocFunc::ModifyAllDBData( const ScDBCollection& rNewColl, const std::ve // register target in SBA no longer necessary rDoc.PreprocessDBDataUpdate(); - rDoc.SetDBCollection( new ScDBCollection( rNewColl ) ); + rDoc.SetDBCollection( std::unique_ptr(new ScDBCollection( rNewColl )) ); rDoc.CompileHybridFormula(); pOldColl = nullptr; rDocShell.PostPaint(ScRange(0, 0, 0, MAXCOL, MAXROW, MAXTAB), PaintPartFlags::Grid); diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 1e4e6556c9b3..80c99cef7f40 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -5037,7 +5037,7 @@ void ScDocFunc::SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc, SCTA if (nTab >= 0) rDoc.SetRangeName( nTab, pNewRanges ); // takes ownership else - rDoc.SetRangeName( pNewRanges ); // takes ownership + rDoc.SetRangeName( std::unique_ptr(pNewRanges) ); // takes ownership if ( bCompile ) rDoc.CompileHybridFormula(); diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx index acd05f0ec21b..3eae94341395 100644 --- a/sc/source/ui/docshell/docsh5.cxx +++ b/sc/source/ui/docshell/docsh5.cxx @@ -232,9 +232,9 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe pNoNameData = aDocument.GetAnonymousDBData(); if (!pNoNameData) { - pNoNameData = new ScDBData( STR_DB_LOCAL_NONAME, - nTab, nStartCol, nStartRow, nEndCol, nEndRow, true, bHasHeader); - aDocument.SetAnonymousDBData( pNoNameData); + aDocument.SetAnonymousDBData( std::unique_ptr(new ScDBData( STR_DB_LOCAL_NONAME, + nTab, nStartCol, nStartRow, nEndCol, nEndRow, true, bHasHeader) ) ); + pNoNameData = aDocument.GetAnonymousDBData(); } // ScDocShell::CancelAutoDBRange() would restore the // sheet-local anonymous DBData from pOldAutoDBRange, unset so diff --git a/sc/source/ui/inc/AccessibleText.hxx b/sc/source/ui/inc/AccessibleText.hxx index 940b854b7d13..c36c63f02cab 100644 --- a/sc/source/ui/inc/AccessibleText.hxx +++ b/sc/source/ui/inc/AccessibleText.hxx @@ -245,7 +245,7 @@ public: private: ScPreviewViewForwarder* mpViewForwarder; ScPreviewShell* mpViewShell; - ScEditEngineDefaulter* mpEditEngine; + std::unique_ptr mpEditEngine; SvxEditEngineForwarder* mpForwarder; ScDocShell* mpDocSh; OUString msText; diff --git a/sc/source/ui/inc/refundo.hxx b/sc/source/ui/inc/refundo.hxx index 12d267ce0da9..c3e4466f8733 100644 --- a/sc/source/ui/inc/refundo.hxx +++ b/sc/source/ui/inc/refundo.hxx @@ -20,6 +20,7 @@ #ifndef INCLUDED_SC_SOURCE_UI_INC_REFUNDO_HXX #define INCLUDED_SC_SOURCE_UI_INC_REFUNDO_HXX +#include class ScDocument; class ScDBCollection; @@ -41,7 +42,7 @@ private: ScDetOpList* pDetOpList; ScChartListenerCollection* pChartListenerCollection; ScAreaLinkSaveCollection* pAreaLinks; - ScUnoRefList* pUnoRefs; + std::unique_ptr pUnoRefs; public: ScRefUndoData( const ScDocument* pDoc ); diff --git a/sc/source/ui/undo/refundo.cxx b/sc/source/ui/undo/refundo.cxx index 7488465e63af..857120cc69da 100644 --- a/sc/source/ui/undo/refundo.cxx +++ b/sc/source/ui/undo/refundo.cxx @@ -80,7 +80,6 @@ ScRefUndoData::~ScRefUndoData() delete pDetOpList; delete pChartListenerCollection; delete pAreaLinks; - delete pUnoRefs; } void ScRefUndoData::DeleteUnchanged( const ScDocument* pDoc ) @@ -140,7 +139,7 @@ void ScRefUndoData::DeleteUnchanged( const ScDocument* pDoc ) pUnoRefs = const_cast(pDoc)->EndUnoRefUndo(); if ( pUnoRefs && pUnoRefs->IsEmpty() ) { - DELETEZ( pUnoRefs ); + pUnoRefs.reset(); } } } @@ -148,9 +147,9 @@ void ScRefUndoData::DeleteUnchanged( const ScDocument* pDoc ) void ScRefUndoData::DoUndo( ScDocument* pDoc, bool bUndoRefFirst ) { if (pDBCollection) - pDoc->SetDBCollection( new ScDBCollection(*pDBCollection) ); + pDoc->SetDBCollection( std::unique_ptr(new ScDBCollection(*pDBCollection)) ); if (pRangeName) - pDoc->SetRangeName( new ScRangeName(*pRangeName) ); + pDoc->SetRangeName( std::unique_ptr(new ScRangeName(*pRangeName)) ); if (pPrintRanges) pDoc->RestorePrintRanges(*pPrintRanges); @@ -163,7 +162,7 @@ void ScRefUndoData::DoUndo( ScDocument* pDoc, bool bUndoRefFirst ) } if (pDetOpList) - pDoc->SetDetOpList( new ScDetOpList(*pDetOpList) ); + pDoc->SetDetOpList( std::unique_ptr(new ScDetOpList(*pDetOpList)) ); // bUndoRefFirst is bSetChartRangeLists if ( pChartListenerCollection ) diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx index 522914ec9cdc..9e8e09a1bb6f 100644 --- a/sc/source/ui/undo/undocell.cxx +++ b/sc/source/ui/undo/undocell.cxx @@ -912,7 +912,7 @@ void ScUndoDetective::Undo() if (bIsDelete) { if ( pOldList ) - rDoc.SetDetOpList( new ScDetOpList(*pOldList) ); + rDoc.SetDetOpList( std::unique_ptr(new ScDetOpList(*pOldList)) ); } else { @@ -999,14 +999,14 @@ void ScUndoRangeNames::DoChange( bool bUndo ) if (mnTab >= 0) rDoc.SetRangeName( mnTab, new ScRangeName( *pOldRanges ) ); else - rDoc.SetRangeName( new ScRangeName( *pOldRanges ) ); + rDoc.SetRangeName( std::unique_ptr(new ScRangeName( *pOldRanges )) ); } else { if (mnTab >= 0) rDoc.SetRangeName( mnTab, new ScRangeName( *pNewRanges ) ); else - rDoc.SetRangeName( new ScRangeName( *pNewRanges ) ); + rDoc.SetRangeName( std::unique_ptr(new ScRangeName( *pNewRanges )) ); } rDoc.CompileHybridFormula(); diff --git a/sc/source/ui/undo/undodat.cxx b/sc/source/ui/undo/undodat.cxx index d3cef474a5d0..afaed1811b1e 100644 --- a/sc/source/ui/undo/undodat.cxx +++ b/sc/source/ui/undo/undodat.cxx @@ -656,9 +656,9 @@ void ScUndoSubTotals::Undo() aParam.nCol2,aParam.nRow2,nTab ); if (xUndoRange) - rDoc.SetRangeName(new ScRangeName(*xUndoRange)); + rDoc.SetRangeName(std::unique_ptr(new ScRangeName(*xUndoRange))); if (xUndoDB) - rDoc.SetDBCollection(new ScDBCollection(*xUndoDB), true); + rDoc.SetDBCollection(std::unique_ptr(new ScDBCollection(*xUndoDB)), true); SCTAB nVisTab = pViewShell->GetViewData().GetTabNo(); if ( nVisTab != nTab ) @@ -796,7 +796,7 @@ void ScUndoQuery::Undo() InsertDeleteFlags::NONE, false, rDoc); if (xUndoDB) - rDoc.SetDBCollection(new ScDBCollection(*xUndoDB ), true); + rDoc.SetDBCollection(std::unique_ptr(new ScDBCollection(*xUndoDB )), true); if (!bCopy) { @@ -980,7 +980,7 @@ void ScUndoDBData::Undo() bool bOldAutoCalc = rDoc.GetAutoCalc(); rDoc.SetAutoCalc( false ); // Avoid unnecessary calculations rDoc.PreprocessDBDataUpdate(); - rDoc.SetDBCollection( new ScDBCollection(*pUndoColl), true ); + rDoc.SetDBCollection( std::unique_ptr(new ScDBCollection(*pUndoColl)), true ); rDoc.CompileHybridFormula(); rDoc.SetAutoCalc( bOldAutoCalc ); @@ -998,7 +998,7 @@ void ScUndoDBData::Redo() bool bOldAutoCalc = rDoc.GetAutoCalc(); rDoc.SetAutoCalc( false ); // Avoid unnecessary calculations rDoc.PreprocessDBDataUpdate(); - rDoc.SetDBCollection( new ScDBCollection(*pRedoColl), true ); + rDoc.SetDBCollection( std::unique_ptr(new ScDBCollection(*pRedoColl)), true ); rDoc.CompileHybridFormula(); rDoc.SetAutoCalc( bOldAutoCalc ); @@ -1333,9 +1333,9 @@ void ScUndoRepeatDB::Undo() aBlockEnd.Col(),aBlockEnd.Row(),nTab ); if (xUndoRange) - rDoc.SetRangeName(new ScRangeName(*xUndoRange)); + rDoc.SetRangeName(std::unique_ptr(new ScRangeName(*xUndoRange))); if (xUndoDB) - rDoc.SetDBCollection(new ScDBCollection(*xUndoDB), true); + rDoc.SetDBCollection(std::unique_ptr(new ScDBCollection(*xUndoDB)), true); SCTAB nVisTab = pViewShell->GetViewData().GetTabNo(); if ( nVisTab != nTab ) diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index 0e6b0ef4e16a..c5830ce06c56 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -1485,12 +1485,10 @@ ScCellRangesBase::~ScCellRangesBase() void ScCellRangesBase::ForgetCurrentAttrs() { - delete pCurrentFlat; - delete pCurrentDeep; + pCurrentFlat.reset(); + pCurrentDeep.reset(); delete pCurrentDataSet; delete pNoDfltCurrentDataSet; - pCurrentFlat = nullptr; - pCurrentDeep = nullptr; pCurrentDataSet = nullptr; pNoDfltCurrentDataSet = nullptr; @@ -1512,7 +1510,7 @@ const ScPatternAttr* ScCellRangesBase::GetCurrentAttrsFlat() ScDocument& rDoc = pDocShell->GetDocument(); pCurrentFlat = rDoc.CreateSelectionPattern( *GetMarkData(), false ); } - return pCurrentFlat; + return pCurrentFlat.get(); } const ScPatternAttr* ScCellRangesBase::GetCurrentAttrsDeep() @@ -1524,7 +1522,7 @@ const ScPatternAttr* ScCellRangesBase::GetCurrentAttrsDeep() ScDocument& rDoc = pDocShell->GetDocument(); pCurrentDeep = rDoc.CreateSelectionPattern( *GetMarkData() ); } - return pCurrentDeep; + return pCurrentDeep.get(); } SfxItemSet* ScCellRangesBase::GetCurrentDataSet(bool bNoDflt) diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 88e1a43dd7b8..c60b03778692 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -2328,7 +2328,7 @@ void SAL_CALL ScModelObj::consolidate( { const ScConsolidateParam& rParam = xImpl->GetParam(); pDocShell->DoConsolidate( rParam ); - pDocShell->GetDocument().SetConsolidateDlgData( &rParam ); + pDocShell->GetDocument().SetConsolidateDlgData( std::unique_ptr(new ScConsolidateParam(rParam)) ); } } diff --git a/sc/source/ui/unoobj/textuno.cxx b/sc/source/ui/unoobj/textuno.cxx index ee4600b6627c..5d4576636105 100644 --- a/sc/source/ui/unoobj/textuno.cxx +++ b/sc/source/ui/unoobj/textuno.cxx @@ -889,7 +889,7 @@ ScCellTextData::~ScCellTextData() pDocShell->GetDocument().DisposeFieldEditEngine(pEditEngine); } else - delete pEditEngine; + pEditEngine.reset(); delete pForwarder; @@ -916,7 +916,7 @@ SvxTextForwarder* ScCellTextData::GetTextForwarder() { SfxItemPool* pEnginePool = EditEngine::CreatePool(); pEnginePool->FreezeIdRanges(); - pEditEngine = new ScFieldEditEngine(nullptr, pEnginePool, nullptr, true); + pEditEngine.reset( new ScFieldEditEngine(nullptr, pEnginePool, nullptr, true) ); } // currently, GetPortions doesn't work if UpdateMode is sal_False, // this will be fixed (in EditEngine) by src600 @@ -1004,7 +1004,7 @@ void ScCellTextData::Notify( SfxBroadcaster&, const SfxHint& rHint ) pDocShell = nullptr; // invalid now DELETEZ( pForwarder ); - DELETEZ( pEditEngine ); // EditEngine uses document's pool + pEditEngine.reset(); // EditEngine uses document's pool } else if ( nId == SfxHintId::DataChanged ) { diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index 93779d60752b..a36745ce4fc8 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -1851,7 +1851,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) static_cast(pItem)->GetData(); pTabViewShell->Consolidate( rParam ); - GetViewData()->GetDocument()->SetConsolidateDlgData( &rParam ); + GetViewData()->GetDocument()->SetConsolidateDlgData( std::unique_ptr(new ScConsolidateParam(rParam)) ); rReq.Done(); } diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx index d75204e3546d..364ab9c654ef 100644 --- a/sc/source/ui/view/formatsh.cxx +++ b/sc/source/ui/view/formatsh.cxx @@ -1775,7 +1775,7 @@ void ScFormatShell::ExecuteAttr( SfxRequest& rReq ) ScMarkData aFuncMark( pViewData->GetMarkData() ); ScViewUtil::UnmarkFiltered( aFuncMark, pDoc ); - pDoc->SetPreviewFont( aSetItem.GetItemSet().Clone() ); + pDoc->SetPreviewFont( std::unique_ptr(aSetItem.GetItemSet().Clone()) ); aFuncMark.MarkToMulti(); if ( !aFuncMark.IsMarked() && !aFuncMark.IsMultiMarked() ) -- cgit