loplugin:useuniqueptr in ScUndoDBData
Change-Id: I6107079f8474a2ddc76a9cb6e93552d95861dc6c Reviewed-on: https://gerrit.libreoffice.org/56563 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <o3tl/make_unique.hxx>
|
||||||
#include <sfx2/app.hxx>
|
#include <sfx2/app.hxx>
|
||||||
#include <vcl/weld.hxx>
|
#include <vcl/weld.hxx>
|
||||||
#include <vcl/waitobj.hxx>
|
#include <vcl/waitobj.hxx>
|
||||||
@@ -69,9 +70,9 @@ bool ScDBDocFunc::AddDBRange( const OUString& rName, const ScRange& rRange )
|
|||||||
ScDBCollection* pDocColl = rDoc.GetDBCollection();
|
ScDBCollection* pDocColl = rDoc.GetDBCollection();
|
||||||
bool bUndo (rDoc.IsUndoEnabled());
|
bool bUndo (rDoc.IsUndoEnabled());
|
||||||
|
|
||||||
ScDBCollection* pUndoColl = nullptr;
|
std::unique_ptr<ScDBCollection> pUndoColl;
|
||||||
if (bUndo)
|
if (bUndo)
|
||||||
pUndoColl = new ScDBCollection( *pDocColl );
|
pUndoColl.reset( new ScDBCollection( *pDocColl ) );
|
||||||
|
|
||||||
std::unique_ptr<ScDBData> pNew(new ScDBData( rName, rRange.aStart.Tab(),
|
std::unique_ptr<ScDBData> pNew(new ScDBData( rName, rRange.aStart.Tab(),
|
||||||
rRange.aStart.Col(), rRange.aStart.Row(),
|
rRange.aStart.Col(), rRange.aStart.Row(),
|
||||||
@@ -98,15 +99,14 @@ bool ScDBDocFunc::AddDBRange( const OUString& rName, const ScRange& rRange )
|
|||||||
|
|
||||||
if (!bOk)
|
if (!bOk)
|
||||||
{
|
{
|
||||||
delete pUndoColl;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bUndo)
|
if (bUndo)
|
||||||
{
|
{
|
||||||
ScDBCollection* pRedoColl = new ScDBCollection( *pDocColl );
|
|
||||||
rDocShell.GetUndoManager()->AddUndoAction(
|
rDocShell.GetUndoManager()->AddUndoAction(
|
||||||
new ScUndoDBData( &rDocShell, pUndoColl, pRedoColl ) );
|
new ScUndoDBData( &rDocShell, std::move(pUndoColl),
|
||||||
|
o3tl::make_unique<ScDBCollection>( *pDocColl ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
aModificator.SetDocumentModified();
|
aModificator.SetDocumentModified();
|
||||||
@@ -127,9 +127,9 @@ bool ScDBDocFunc::DeleteDBRange(const OUString& rName)
|
|||||||
{
|
{
|
||||||
ScDocShellModificator aModificator( rDocShell );
|
ScDocShellModificator aModificator( rDocShell );
|
||||||
|
|
||||||
ScDBCollection* pUndoColl = nullptr;
|
std::unique_ptr<ScDBCollection> pUndoColl;
|
||||||
if (bUndo)
|
if (bUndo)
|
||||||
pUndoColl = new ScDBCollection( *pDocColl );
|
pUndoColl.reset( new ScDBCollection( *pDocColl ) );
|
||||||
|
|
||||||
rDoc.PreprocessDBDataUpdate();
|
rDoc.PreprocessDBDataUpdate();
|
||||||
rDBs.erase(iter);
|
rDBs.erase(iter);
|
||||||
@@ -137,9 +137,9 @@ bool ScDBDocFunc::DeleteDBRange(const OUString& rName)
|
|||||||
|
|
||||||
if (bUndo)
|
if (bUndo)
|
||||||
{
|
{
|
||||||
ScDBCollection* pRedoColl = new ScDBCollection( *pDocColl );
|
|
||||||
rDocShell.GetUndoManager()->AddUndoAction(
|
rDocShell.GetUndoManager()->AddUndoAction(
|
||||||
new ScUndoDBData( &rDocShell, pUndoColl, pRedoColl ) );
|
new ScUndoDBData( &rDocShell, std::move(pUndoColl),
|
||||||
|
o3tl::make_unique<ScDBCollection>( *pDocColl ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
aModificator.SetDocumentModified();
|
aModificator.SetDocumentModified();
|
||||||
@@ -181,9 +181,9 @@ bool ScDBDocFunc::RenameDBRange( const OUString& rOld, const OUString& rNew )
|
|||||||
{
|
{
|
||||||
if (bUndo)
|
if (bUndo)
|
||||||
{
|
{
|
||||||
ScDBCollection* pRedoColl = new ScDBCollection( *pDocColl );
|
|
||||||
rDocShell.GetUndoManager()->AddUndoAction(
|
rDocShell.GetUndoManager()->AddUndoAction(
|
||||||
new ScUndoDBData( &rDocShell, pUndoColl.release(), pRedoColl ) );
|
new ScUndoDBData( &rDocShell, std::move(pUndoColl),
|
||||||
|
o3tl::make_unique<ScDBCollection>( *pDocColl ) ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pUndoColl.reset();
|
pUndoColl.reset();
|
||||||
@@ -222,9 +222,9 @@ void ScDBDocFunc::ModifyDBData( const ScDBData& rNewData )
|
|||||||
rNewData.GetArea(aNewRange);
|
rNewData.GetArea(aNewRange);
|
||||||
bool bAreaChanged = ( aOldRange != aNewRange ); // then a recompilation is needed
|
bool bAreaChanged = ( aOldRange != aNewRange ); // then a recompilation is needed
|
||||||
|
|
||||||
ScDBCollection* pUndoColl = nullptr;
|
std::unique_ptr<ScDBCollection> pUndoColl;
|
||||||
if (bUndo)
|
if (bUndo)
|
||||||
pUndoColl = new ScDBCollection( *pDocColl );
|
pUndoColl.reset( new ScDBCollection( *pDocColl ) );
|
||||||
|
|
||||||
*pData = rNewData;
|
*pData = rNewData;
|
||||||
if (bAreaChanged)
|
if (bAreaChanged)
|
||||||
@@ -232,9 +232,9 @@ void ScDBDocFunc::ModifyDBData( const ScDBData& rNewData )
|
|||||||
|
|
||||||
if (bUndo)
|
if (bUndo)
|
||||||
{
|
{
|
||||||
ScDBCollection* pRedoColl = new ScDBCollection( *pDocColl );
|
|
||||||
rDocShell.GetUndoManager()->AddUndoAction(
|
rDocShell.GetUndoManager()->AddUndoAction(
|
||||||
new ScUndoDBData( &rDocShell, pUndoColl, pRedoColl ) );
|
new ScUndoDBData( &rDocShell, std::move(pUndoColl),
|
||||||
|
o3tl::make_unique<ScDBCollection>( *pDocColl ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
aModificator.SetDocumentModified();
|
aModificator.SetDocumentModified();
|
||||||
@@ -246,7 +246,7 @@ void ScDBDocFunc::ModifyAllDBData( const ScDBCollection& rNewColl, const std::ve
|
|||||||
ScDocShellModificator aModificator(rDocShell);
|
ScDocShellModificator aModificator(rDocShell);
|
||||||
ScDocument& rDoc = rDocShell.GetDocument();
|
ScDocument& rDoc = rDocShell.GetDocument();
|
||||||
ScDBCollection* pOldColl = rDoc.GetDBCollection();
|
ScDBCollection* pOldColl = rDoc.GetDBCollection();
|
||||||
ScDBCollection* pUndoColl = nullptr;
|
std::unique_ptr<ScDBCollection> pUndoColl;
|
||||||
bool bRecord = rDoc.IsUndoEnabled();
|
bool bRecord = rDoc.IsUndoEnabled();
|
||||||
|
|
||||||
std::vector<ScRange>::const_iterator iter;
|
std::vector<ScRange>::const_iterator iter;
|
||||||
@@ -260,7 +260,7 @@ void ScDBDocFunc::ModifyAllDBData( const ScDBCollection& rNewColl, const std::ve
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bRecord)
|
if (bRecord)
|
||||||
pUndoColl = new ScDBCollection( *pOldColl );
|
pUndoColl.reset( new ScDBCollection( *pOldColl ) );
|
||||||
|
|
||||||
// register target in SBA no longer necessary
|
// register target in SBA no longer necessary
|
||||||
|
|
||||||
@@ -274,9 +274,9 @@ void ScDBDocFunc::ModifyAllDBData( const ScDBCollection& rNewColl, const std::ve
|
|||||||
|
|
||||||
if (bRecord)
|
if (bRecord)
|
||||||
{
|
{
|
||||||
ScDBCollection* pRedoColl = new ScDBCollection(rNewColl);
|
|
||||||
rDocShell.GetUndoManager()->AddUndoAction(
|
rDocShell.GetUndoManager()->AddUndoAction(
|
||||||
new ScUndoDBData(&rDocShell, pUndoColl, pRedoColl));
|
new ScUndoDBData(&rDocShell, std::move(pUndoColl),
|
||||||
|
o3tl::make_unique<ScDBCollection>(rNewColl)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -55,6 +55,7 @@
|
|||||||
#include <clipparam.hxx>
|
#include <clipparam.hxx>
|
||||||
#include <rowheightcontext.hxx>
|
#include <rowheightcontext.hxx>
|
||||||
#include <refupdatecontext.hxx>
|
#include <refupdatecontext.hxx>
|
||||||
|
#include <o3tl/make_unique.hxx>
|
||||||
|
|
||||||
using com::sun::star::script::XLibraryContainer;
|
using com::sun::star::script::XLibraryContainer;
|
||||||
using com::sun::star::script::vba::XVBACompatibility;
|
using com::sun::star::script::vba::XVBACompatibility;
|
||||||
@@ -286,12 +287,12 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ScDBCollection* pUndoColl = nullptr;
|
std::unique_ptr<ScDBCollection> pUndoColl;
|
||||||
|
|
||||||
if (eMode==SC_DB_IMPORT)
|
if (eMode==SC_DB_IMPORT)
|
||||||
{
|
{
|
||||||
m_aDocument.PreprocessDBDataUpdate();
|
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 );
|
OUString aImport = ScResId( STR_DBNAME_IMPORT );
|
||||||
long nCount = 0;
|
long nCount = 0;
|
||||||
@@ -323,8 +324,9 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe
|
|||||||
{
|
{
|
||||||
m_aDocument.CompileHybridFormula();
|
m_aDocument.CompileHybridFormula();
|
||||||
|
|
||||||
ScDBCollection* pRedoColl = new ScDBCollection( *pColl );
|
GetUndoManager()->AddUndoAction( new ScUndoDBData( this,
|
||||||
GetUndoManager()->AddUndoAction( new ScUndoDBData( this, pUndoColl, pRedoColl ) );
|
std::move(pUndoColl),
|
||||||
|
o3tl::make_unique<ScDBCollection>( *pColl ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// no longer needed to register new range at the Sba
|
// no longer needed to register new range at the Sba
|
||||||
|
@@ -266,7 +266,8 @@ class ScUndoDBData: public ScSimpleUndo
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScUndoDBData( ScDocShell* pNewDocShell,
|
ScUndoDBData( ScDocShell* pNewDocShell,
|
||||||
ScDBCollection* pNewUndoColl, ScDBCollection* pNewRedoColl );
|
std::unique_ptr<ScDBCollection> pNewUndoColl,
|
||||||
|
std::unique_ptr<ScDBCollection> pNewRedoColl );
|
||||||
virtual ~ScUndoDBData() override;
|
virtual ~ScUndoDBData() override;
|
||||||
|
|
||||||
virtual void Undo() override;
|
virtual void Undo() override;
|
||||||
@@ -277,8 +278,8 @@ public:
|
|||||||
virtual OUString GetComment() const override;
|
virtual OUString GetComment() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScDBCollection* pUndoColl;
|
std::unique_ptr<ScDBCollection> pUndoColl;
|
||||||
ScDBCollection* pRedoColl;
|
std::unique_ptr<ScDBCollection> pRedoColl;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ScUndoImportData: public ScSimpleUndo
|
class ScUndoImportData: public ScSimpleUndo
|
||||||
|
@@ -954,17 +954,16 @@ bool ScUndoAutoFilter::CanRepeat(SfxRepeatTarget& /* rTarget */) const
|
|||||||
|
|
||||||
// change database sections (dialog)
|
// change database sections (dialog)
|
||||||
ScUndoDBData::ScUndoDBData( ScDocShell* pNewDocShell,
|
ScUndoDBData::ScUndoDBData( ScDocShell* pNewDocShell,
|
||||||
ScDBCollection* pNewUndoColl, ScDBCollection* pNewRedoColl ) :
|
std::unique_ptr<ScDBCollection> pNewUndoColl,
|
||||||
|
std::unique_ptr<ScDBCollection> pNewRedoColl ) :
|
||||||
ScSimpleUndo( pNewDocShell ),
|
ScSimpleUndo( pNewDocShell ),
|
||||||
pUndoColl( pNewUndoColl ),
|
pUndoColl( std::move(pNewUndoColl) ),
|
||||||
pRedoColl( pNewRedoColl )
|
pRedoColl( std::move(pNewRedoColl) )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ScUndoDBData::~ScUndoDBData()
|
ScUndoDBData::~ScUndoDBData()
|
||||||
{
|
{
|
||||||
delete pUndoColl;
|
|
||||||
delete pRedoColl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OUString ScUndoDBData::GetComment() const
|
OUString ScUndoDBData::GetComment() const
|
||||||
|
Reference in New Issue
Block a user