[Libreoffice-commits] core.git: sw/source
Stephan Bergmann
sbergman at redhat.com
Wed Jun 14 13:43:36 UTC 2017
sw/source/core/inc/UndoTable.hxx | 2 -
sw/source/core/undo/untbl.cxx | 64 +++++++++++++++------------------------
2 files changed, 27 insertions(+), 39 deletions(-)
New commits:
commit e916e0a39ad2e96a0d6b5b866763e57498898c55
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Wed Jun 14 15:43:09 2017 +0200
Use unique_ptr for UnodTableCpyTable_Entry members
Change-Id: I925523d3c3fde2d82aa2509aef2c62c8e9686f40
diff --git a/sw/source/core/inc/UndoTable.hxx b/sw/source/core/inc/UndoTable.hxx
index 83dab4172198..a83434660497 100644
--- a/sw/source/core/inc/UndoTable.hxx
+++ b/sw/source/core/inc/UndoTable.hxx
@@ -287,7 +287,7 @@ class SwUndoTableCpyTable : public SwUndo
//b6341295: When redlining is active, PrepareRedline has to create the
//redlining attributes for the new and the old table cell content
- static SwUndo* PrepareRedline( SwDoc* pDoc, const SwTableBox& rBox,
+ static std::unique_ptr<SwUndo> PrepareRedline( SwDoc* pDoc, const SwTableBox& rBox,
const SwPosition& rPos, bool& rJoin, bool bRedo );
public:
diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx
index 25552f46b326..c1d0dc50afaa 100644
--- a/sw/source/core/undo/untbl.cxx
+++ b/sw/source/core/undo/untbl.cxx
@@ -65,6 +65,7 @@
#include <calbck.hxx>
#include <memory>
+#include <utility>
#include <vector>
#include <o3tl/make_unique.hxx>
#ifdef DBG_UTIL
@@ -84,14 +85,13 @@ typedef std::vector<std::shared_ptr<SfxItemSet> > SfxItemSets;
struct UndoTableCpyTable_Entry
{
sal_uLong nBoxIdx, nOffset;
- SfxItemSet* pBoxNumAttr;
- SwUndo* pUndo;
+ std::unique_ptr<SfxItemSet> pBoxNumAttr;
+ std::unique_ptr<SwUndo> pUndo;
// Was the last paragraph of the new and the first paragraph of the old content joined?
bool bJoin; // For redlining only
explicit UndoTableCpyTable_Entry( const SwTableBox& rBox );
- ~UndoTableCpyTable_Entry();
};
class SaveBox;
@@ -2402,16 +2402,10 @@ void SwUndoTableNumFormat::SetBox( const SwTableBox& rBox )
UndoTableCpyTable_Entry::UndoTableCpyTable_Entry( const SwTableBox& rBox )
: nBoxIdx( rBox.GetSttIdx() ), nOffset( 0 ),
- pBoxNumAttr( nullptr ), pUndo( nullptr ), bJoin( false )
+ bJoin( false )
{
}
-UndoTableCpyTable_Entry::~UndoTableCpyTable_Entry()
-{
- delete pUndo;
- delete pBoxNumAttr;
-}
-
SwUndoTableCpyTable::SwUndoTableCpyTable(const SwDoc* pDoc)
: SwUndo( SwUndoId::TBLCPYTBL, pDoc )
, m_pArr(new SwUndoTableCpyTable_Entries)
@@ -2447,7 +2441,7 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext)
// b62341295: Redline for copying tables
const SwNode *pEndNode = rBox.GetSttNd()->EndOfSectionNode();
SwPaM aPam( aInsIdx.GetNode(), *pEndNode );
- SwUndoDelete* pUndo = nullptr;
+ std::unique_ptr<SwUndoDelete> pUndo;
if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() ) )
{
@@ -2457,9 +2451,9 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext)
if( pEntry->pUndo )
{
SwUndoDelete *const pUndoDelete =
- dynamic_cast<SwUndoDelete*>(pEntry->pUndo);
+ dynamic_cast<SwUndoDelete*>(pEntry->pUndo.get());
SwUndoRedlineDelete *const pUndoRedlineDelete =
- dynamic_cast<SwUndoRedlineDelete*>(pEntry->pUndo);
+ dynamic_cast<SwUndoRedlineDelete*>(pEntry->pUndo.get());
OSL_ASSERT(pUndoDelete || pUndoRedlineDelete);
if (pUndoRedlineDelete)
{
@@ -2503,8 +2497,7 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext)
if( pEntry->pUndo )
{
pEntry->pUndo->UndoImpl(rContext);
- delete pEntry->pUndo;
- pEntry->pUndo = nullptr;
+ pEntry->pUndo.reset();
}
if( bShiftPam )
{
@@ -2520,19 +2513,18 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext)
else
*aPam.GetPoint() = SwPosition( aTmpIdx );
}
- pUndo = new SwUndoDelete( aPam, bDeleteCompleteParagraph, true );
+ pUndo = o3tl::make_unique<SwUndoDelete>( aPam, bDeleteCompleteParagraph, true );
}
else
{
- pUndo = new SwUndoDelete( aPam, true );
+ pUndo = o3tl::make_unique<SwUndoDelete>( aPam, true );
if( pEntry->pUndo )
{
pEntry->pUndo->UndoImpl(rContext);
- delete pEntry->pUndo;
- pEntry->pUndo = nullptr;
+ pEntry->pUndo.reset();
}
}
- pEntry->pUndo = pUndo;
+ pEntry->pUndo = std::move(pUndo);
aInsIdx = rBox.GetSttIdx() + 1;
rDoc.GetNodes().Delete( aInsIdx );
@@ -2550,13 +2542,12 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext)
if( pEntry->pBoxNumAttr )
{
rBox.ClaimFrameFormat()->SetFormatAttr( *pEntry->pBoxNumAttr );
- delete pEntry->pBoxNumAttr;
- pEntry->pBoxNumAttr = nullptr;
+ pEntry->pBoxNumAttr.reset();
}
if( aTmpSet.Count() )
{
- pEntry->pBoxNumAttr = new SfxItemSet( rDoc.GetAttrPool(),
+ pEntry->pBoxNumAttr = o3tl::make_unique<SfxItemSet>( rDoc.GetAttrPool(),
RES_BOXATR_FORMAT, RES_BOXATR_VALUE,
RES_VERT_ORIENT, RES_VERT_ORIENT, 0 );
pEntry->pBoxNumAttr->Put( aTmpSet );
@@ -2598,7 +2589,7 @@ void SwUndoTableCpyTable::RedoImpl(::sw::UndoRedoContext & rContext)
// b62341295: Redline for copying tables - Start.
rDoc.GetNodes().MakeTextNode( aInsIdx, rDoc.GetDfltTextFormatColl() );
SwPaM aPam( aInsIdx.GetNode(), *rBox.GetSttNd()->EndOfSectionNode());
- SwUndo* pUndo = IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() ) ? nullptr : new SwUndoDelete( aPam, true );
+ std::unique_ptr<SwUndo> pUndo = IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() ) ? nullptr : o3tl::make_unique<SwUndoDelete>( aPam, true );
if( pEntry->pUndo )
{
pEntry->pUndo->UndoImpl(rContext);
@@ -2621,10 +2612,9 @@ void SwUndoTableCpyTable::RedoImpl(::sw::UndoRedoContext & rContext)
pUndo = PrepareRedline( &rDoc, rBox, aTmpPos, pEntry->bJoin, true );
}
}
- delete pEntry->pUndo;
- pEntry->pUndo = nullptr;
+ pEntry->pUndo.reset();
}
- pEntry->pUndo = pUndo;
+ pEntry->pUndo = std::move(pUndo);
// b62341295: Redline for copying tables - End.
aInsIdx = rBox.GetSttIdx() + 1;
@@ -2642,13 +2632,12 @@ void SwUndoTableCpyTable::RedoImpl(::sw::UndoRedoContext & rContext)
if( pEntry->pBoxNumAttr )
{
rBox.ClaimFrameFormat()->SetFormatAttr( *pEntry->pBoxNumAttr );
- delete pEntry->pBoxNumAttr;
- pEntry->pBoxNumAttr = nullptr;
+ pEntry->pBoxNumAttr.reset();
}
if( aTmpSet.Count() )
{
- pEntry->pBoxNumAttr = new SfxItemSet( rDoc.GetAttrPool(),
+ pEntry->pBoxNumAttr = o3tl::make_unique<SfxItemSet>( rDoc.GetAttrPool(),
RES_BOXATR_FORMAT, RES_BOXATR_VALUE,
RES_VERT_ORIENT, RES_VERT_ORIENT, 0 );
pEntry->pBoxNumAttr->Put( aTmpSet );
@@ -2676,17 +2665,16 @@ void SwUndoTableCpyTable::AddBoxBefore( const SwTableBox& rBox, bool bDelContent
SwPaM aPam( aInsIdx.GetNode(), *rBox.GetSttNd()->EndOfSectionNode() );
if( !pDoc->getIDocumentRedlineAccess().IsRedlineOn() )
- pEntry->pUndo = new SwUndoDelete( aPam, true );
+ pEntry->pUndo = o3tl::make_unique<SwUndoDelete>( aPam, true );
}
- pEntry->pBoxNumAttr = new SfxItemSet( pDoc->GetAttrPool(),
+ pEntry->pBoxNumAttr = o3tl::make_unique<SfxItemSet>( pDoc->GetAttrPool(),
RES_BOXATR_FORMAT, RES_BOXATR_VALUE,
RES_VERT_ORIENT, RES_VERT_ORIENT, 0 );
pEntry->pBoxNumAttr->Put( rBox.GetFrameFormat()->GetAttrSet() );
if( !pEntry->pBoxNumAttr->Count() )
{
- delete pEntry->pBoxNumAttr;
- pEntry->pBoxNumAttr = nullptr;
+ pEntry->pBoxNumAttr.reset();
}
DEBUG_REDLINE( pDoc )
}
@@ -2720,10 +2708,10 @@ void SwUndoTableCpyTable::AddBoxAfter( const SwTableBox& rBox, const SwNodeIndex
// been merged.
// rJoin is true if Redo() is calling and the content has already been merged
-SwUndo* SwUndoTableCpyTable::PrepareRedline( SwDoc* pDoc, const SwTableBox& rBox,
+std::unique_ptr<SwUndo> SwUndoTableCpyTable::PrepareRedline( SwDoc* pDoc, const SwTableBox& rBox,
const SwPosition& rPos, bool& rJoin, bool bRedo )
{
- SwUndo *pUndo = nullptr;
+ std::unique_ptr<SwUndo> pUndo;
// b62341295: Redline for copying tables
// What's to do?
// Mark the cell content before rIdx as insertion,
@@ -2767,7 +2755,7 @@ SwUndo* SwUndoTableCpyTable::PrepareRedline( SwDoc* pDoc, const SwTableBox& rBox
if( aDeleteStart != aCellEnd )
{ // If the old (deleted) part is not empty, here we are...
SwPaM aDeletePam( aDeleteStart, aCellEnd );
- pUndo = new SwUndoRedlineDelete( aDeletePam, SwUndoId::DELETE );
+ pUndo = o3tl::make_unique<SwUndoRedlineDelete>( aDeletePam, SwUndoId::DELETE );
pDoc->getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( nsRedlineType_t::REDLINE_DELETE, aDeletePam ), true );
}
else if( !rJoin ) // If the old part is empty and joined, we are finished
@@ -2775,7 +2763,7 @@ SwUndo* SwUndoTableCpyTable::PrepareRedline( SwDoc* pDoc, const SwTableBox& rBox
aCellEnd = SwPosition(
SwNodeIndex( *rBox.GetSttNd()->EndOfSectionNode() ));
SwPaM aTmpPam( aDeleteStart, aCellEnd );
- pUndo = new SwUndoDelete( aTmpPam, true );
+ pUndo = o3tl::make_unique<SwUndoDelete>( aTmpPam, true );
}
SwPosition aCellStart( SwNodeIndex( *rBox.GetSttNd(), 2 ) );
pText = aCellStart.nNode.GetNode().GetTextNode();
More information about the Libreoffice-commits
mailing list