diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx index 3a726d31ec27..9f9eccaef9e0 100644 --- a/sc/source/ui/docshell/dbdocfun.cxx +++ b/sc/source/ui/docshell/dbdocfun.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include #include #include #include @@ -69,9 +70,9 @@ bool ScDBDocFunc::AddDBRange( const OUString& rName, const ScRange& rRange ) ScDBCollection* pDocColl = rDoc.GetDBCollection(); bool bUndo (rDoc.IsUndoEnabled()); - ScDBCollection* pUndoColl = nullptr; + std::unique_ptr pUndoColl; if (bUndo) - pUndoColl = new ScDBCollection( *pDocColl ); + pUndoColl.reset( new ScDBCollection( *pDocColl ) ); std::unique_ptr pNew(new ScDBData( rName, rRange.aStart.Tab(), rRange.aStart.Col(), rRange.aStart.Row(), @@ -98,15 +99,14 @@ bool ScDBDocFunc::AddDBRange( const OUString& rName, const ScRange& rRange ) if (!bOk) { - delete pUndoColl; return false; } if (bUndo) { - ScDBCollection* pRedoColl = new ScDBCollection( *pDocColl ); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDBData( &rDocShell, pUndoColl, pRedoColl ) ); + new ScUndoDBData( &rDocShell, std::move(pUndoColl), + o3tl::make_unique( *pDocColl ) ) ); } aModificator.SetDocumentModified(); @@ -127,9 +127,9 @@ bool ScDBDocFunc::DeleteDBRange(const OUString& rName) { ScDocShellModificator aModificator( rDocShell ); - ScDBCollection* pUndoColl = nullptr; + std::unique_ptr pUndoColl; if (bUndo) - pUndoColl = new ScDBCollection( *pDocColl ); + pUndoColl.reset( new ScDBCollection( *pDocColl ) ); rDoc.PreprocessDBDataUpdate(); rDBs.erase(iter); @@ -137,9 +137,9 @@ bool ScDBDocFunc::DeleteDBRange(const OUString& rName) if (bUndo) { - ScDBCollection* pRedoColl = new ScDBCollection( *pDocColl ); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDBData( &rDocShell, pUndoColl, pRedoColl ) ); + new ScUndoDBData( &rDocShell, std::move(pUndoColl), + o3tl::make_unique( *pDocColl ) ) ); } aModificator.SetDocumentModified(); @@ -181,9 +181,9 @@ bool ScDBDocFunc::RenameDBRange( const OUString& rOld, const OUString& rNew ) { if (bUndo) { - ScDBCollection* pRedoColl = new ScDBCollection( *pDocColl ); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDBData( &rDocShell, pUndoColl.release(), pRedoColl ) ); + new ScUndoDBData( &rDocShell, std::move(pUndoColl), + o3tl::make_unique( *pDocColl ) ) ); } else pUndoColl.reset(); @@ -222,9 +222,9 @@ void ScDBDocFunc::ModifyDBData( const ScDBData& rNewData ) rNewData.GetArea(aNewRange); bool bAreaChanged = ( aOldRange != aNewRange ); // then a recompilation is needed - ScDBCollection* pUndoColl = nullptr; + std::unique_ptr pUndoColl; if (bUndo) - pUndoColl = new ScDBCollection( *pDocColl ); + pUndoColl.reset( new ScDBCollection( *pDocColl ) ); *pData = rNewData; if (bAreaChanged) @@ -232,9 +232,9 @@ void ScDBDocFunc::ModifyDBData( const ScDBData& rNewData ) if (bUndo) { - ScDBCollection* pRedoColl = new ScDBCollection( *pDocColl ); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDBData( &rDocShell, pUndoColl, pRedoColl ) ); + new ScUndoDBData( &rDocShell, std::move(pUndoColl), + o3tl::make_unique( *pDocColl ) ) ); } aModificator.SetDocumentModified(); @@ -246,7 +246,7 @@ void ScDBDocFunc::ModifyAllDBData( const ScDBCollection& rNewColl, const std::ve ScDocShellModificator aModificator(rDocShell); ScDocument& rDoc = rDocShell.GetDocument(); ScDBCollection* pOldColl = rDoc.GetDBCollection(); - ScDBCollection* pUndoColl = nullptr; + std::unique_ptr pUndoColl; bool bRecord = rDoc.IsUndoEnabled(); std::vector::const_iterator iter; @@ -260,7 +260,7 @@ void ScDBDocFunc::ModifyAllDBData( const ScDBCollection& rNewColl, const std::ve } if (bRecord) - pUndoColl = new ScDBCollection( *pOldColl ); + pUndoColl.reset( new ScDBCollection( *pOldColl ) ); // register target in SBA no longer necessary @@ -274,9 +274,9 @@ void ScDBDocFunc::ModifyAllDBData( const ScDBCollection& rNewColl, const std::ve if (bRecord) { - ScDBCollection* pRedoColl = new ScDBCollection(rNewColl); rDocShell.GetUndoManager()->AddUndoAction( - new ScUndoDBData(&rDocShell, pUndoColl, pRedoColl)); + new ScUndoDBData(&rDocShell, std::move(pUndoColl), + o3tl::make_unique(rNewColl))); } } diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx index 06fe4e22c7ba..5a7734749b5a 100644 --- a/sc/source/ui/docshell/docsh5.cxx +++ b/sc/source/ui/docshell/docsh5.cxx @@ -55,6 +55,7 @@ #include #include #include +#include using com::sun::star::script::XLibraryContainer; using com::sun::star::script::vba::XVBACompatibility; @@ -286,12 +287,12 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe } else { - ScDBCollection* pUndoColl = nullptr; + std::unique_ptr pUndoColl; if (eMode==SC_DB_IMPORT) { m_aDocument.PreprocessDBDataUpdate(); - pUndoColl = new ScDBCollection( *pColl ); // Undo for import range + pUndoColl.reset( new ScDBCollection( *pColl ) ); // Undo for import range OUString aImport = ScResId( STR_DBNAME_IMPORT ); long nCount = 0; @@ -323,8 +324,9 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe { m_aDocument.CompileHybridFormula(); - ScDBCollection* pRedoColl = new ScDBCollection( *pColl ); - GetUndoManager()->AddUndoAction( new ScUndoDBData( this, pUndoColl, pRedoColl ) ); + GetUndoManager()->AddUndoAction( new ScUndoDBData( this, + std::move(pUndoColl), + o3tl::make_unique( *pColl ) ) ); } // no longer needed to register new range at the Sba diff --git a/sc/source/ui/inc/undodat.hxx b/sc/source/ui/inc/undodat.hxx index 6f377013d53c..092936461e36 100644 --- a/sc/source/ui/inc/undodat.hxx +++ b/sc/source/ui/inc/undodat.hxx @@ -266,7 +266,8 @@ class ScUndoDBData: public ScSimpleUndo { public: ScUndoDBData( ScDocShell* pNewDocShell, - ScDBCollection* pNewUndoColl, ScDBCollection* pNewRedoColl ); + std::unique_ptr pNewUndoColl, + std::unique_ptr pNewRedoColl ); virtual ~ScUndoDBData() override; virtual void Undo() override; @@ -277,8 +278,8 @@ public: virtual OUString GetComment() const override; private: - ScDBCollection* pUndoColl; - ScDBCollection* pRedoColl; + std::unique_ptr pUndoColl; + std::unique_ptr pRedoColl; }; class ScUndoImportData: public ScSimpleUndo diff --git a/sc/source/ui/undo/undodat.cxx b/sc/source/ui/undo/undodat.cxx index a53d2c6fa616..ea4cacef499c 100644 --- a/sc/source/ui/undo/undodat.cxx +++ b/sc/source/ui/undo/undodat.cxx @@ -954,17 +954,16 @@ bool ScUndoAutoFilter::CanRepeat(SfxRepeatTarget& /* rTarget */) const // change database sections (dialog) ScUndoDBData::ScUndoDBData( ScDocShell* pNewDocShell, - ScDBCollection* pNewUndoColl, ScDBCollection* pNewRedoColl ) : + std::unique_ptr pNewUndoColl, + std::unique_ptr pNewRedoColl ) : ScSimpleUndo( pNewDocShell ), - pUndoColl( pNewUndoColl ), - pRedoColl( pNewRedoColl ) + pUndoColl( std::move(pNewUndoColl) ), + pRedoColl( std::move(pNewRedoColl) ) { } ScUndoDBData::~ScUndoDBData() { - delete pUndoColl; - delete pRedoColl; } OUString ScUndoDBData::GetComment() const