summaryrefslogtreecommitdiff
path: root/sc/source/ui
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-03-20 12:54:11 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-03-22 09:53:45 +0100
commitb7654432bfeca619b7657abc8d27193e44cf4dfc (patch)
tree0935306e00e967c1dca4efc8af57f4d67c30a508 /sc/source/ui
parentf82888653c853f236ab0035bb578a7129ec72fa5 (diff)
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 <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc/source/ui')
-rw-r--r--sc/source/ui/Accessibility/AccessibleText.cxx6
-rw-r--r--sc/source/ui/docshell/dbdocfun.cxx10
-rw-r--r--sc/source/ui/docshell/docfunc.cxx2
-rw-r--r--sc/source/ui/docshell/docsh5.cxx6
-rw-r--r--sc/source/ui/inc/AccessibleText.hxx2
-rw-r--r--sc/source/ui/inc/refundo.hxx3
-rw-r--r--sc/source/ui/undo/refundo.cxx9
-rw-r--r--sc/source/ui/undo/undocell.cxx6
-rw-r--r--sc/source/ui/undo/undodat.cxx14
-rw-r--r--sc/source/ui/unoobj/cellsuno.cxx10
-rw-r--r--sc/source/ui/unoobj/docuno.cxx2
-rw-r--r--sc/source/ui/unoobj/textuno.cxx6
-rw-r--r--sc/source/ui/view/cellsh1.cxx2
-rw-r--r--sc/source/ui/view/formatsh.cxx2
14 files changed, 39 insertions, 41 deletions
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<EENotify&,void>());
- 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<ScDBCollection> 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<ScDBCollection>(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<ScRangeName>(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<ScDBData>(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<ScEditEngineDefaulter> 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 <memory>
class ScDocument;
class ScDBCollection;
@@ -41,7 +42,7 @@ private:
ScDetOpList* pDetOpList;
ScChartListenerCollection* pChartListenerCollection;
ScAreaLinkSaveCollection* pAreaLinks;
- ScUnoRefList* pUnoRefs;
+ std::unique_ptr<ScUnoRefList> 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<ScDocument*>(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<ScDBCollection>(new ScDBCollection(*pDBCollection)) );
if (pRangeName)
- pDoc->SetRangeName( new ScRangeName(*pRangeName) );
+ pDoc->SetRangeName( std::unique_ptr<ScRangeName>(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<ScDetOpList>(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<ScDetOpList>(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<ScRangeName>(new ScRangeName( *pOldRanges )) );
}
else
{
if (mnTab >= 0)
rDoc.SetRangeName( mnTab, new ScRangeName( *pNewRanges ) );
else
- rDoc.SetRangeName( new ScRangeName( *pNewRanges ) );
+ rDoc.SetRangeName( std::unique_ptr<ScRangeName>(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<ScRangeName>(new ScRangeName(*xUndoRange)));
if (xUndoDB)
- rDoc.SetDBCollection(new ScDBCollection(*xUndoDB), true);
+ rDoc.SetDBCollection(std::unique_ptr<ScDBCollection>(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<ScDBCollection>(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<ScDBCollection>(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<ScDBCollection>(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<ScRangeName>(new ScRangeName(*xUndoRange)));
if (xUndoDB)
- rDoc.SetDBCollection(new ScDBCollection(*xUndoDB), true);
+ rDoc.SetDBCollection(std::unique_ptr<ScDBCollection>(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<ScConsolidateParam>(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<const ScConsolidateItem*>(pItem)->GetData();
pTabViewShell->Consolidate( rParam );
- GetViewData()->GetDocument()->SetConsolidateDlgData( &rParam );
+ GetViewData()->GetDocument()->SetConsolidateDlgData( std::unique_ptr<ScConsolidateParam>(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<SfxItemSet>(aSetItem.GetItemSet().Clone()) );
aFuncMark.MarkToMulti();
if ( !aFuncMark.IsMarked() && !aFuncMark.IsMultiMarked() )