Kaydet (Commit) e916e0a3 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Use unique_ptr for UnodTableCpyTable_Entry members

Change-Id: I925523d3c3fde2d82aa2509aef2c62c8e9686f40
üst a6aa57ff
...@@ -287,7 +287,7 @@ class SwUndoTableCpyTable : public SwUndo ...@@ -287,7 +287,7 @@ class SwUndoTableCpyTable : public SwUndo
//b6341295: When redlining is active, PrepareRedline has to create the //b6341295: When redlining is active, PrepareRedline has to create the
//redlining attributes for the new and the old table cell content //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 ); const SwPosition& rPos, bool& rJoin, bool bRedo );
public: public:
......
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
#include <calbck.hxx> #include <calbck.hxx>
#include <memory> #include <memory>
#include <utility>
#include <vector> #include <vector>
#include <o3tl/make_unique.hxx> #include <o3tl/make_unique.hxx>
#ifdef DBG_UTIL #ifdef DBG_UTIL
...@@ -84,14 +85,13 @@ typedef std::vector<std::shared_ptr<SfxItemSet> > SfxItemSets; ...@@ -84,14 +85,13 @@ typedef std::vector<std::shared_ptr<SfxItemSet> > SfxItemSets;
struct UndoTableCpyTable_Entry struct UndoTableCpyTable_Entry
{ {
sal_uLong nBoxIdx, nOffset; sal_uLong nBoxIdx, nOffset;
SfxItemSet* pBoxNumAttr; std::unique_ptr<SfxItemSet> pBoxNumAttr;
SwUndo* pUndo; std::unique_ptr<SwUndo> pUndo;
// Was the last paragraph of the new and the first paragraph of the old content joined? // Was the last paragraph of the new and the first paragraph of the old content joined?
bool bJoin; // For redlining only bool bJoin; // For redlining only
explicit UndoTableCpyTable_Entry( const SwTableBox& rBox ); explicit UndoTableCpyTable_Entry( const SwTableBox& rBox );
~UndoTableCpyTable_Entry();
}; };
class SaveBox; class SaveBox;
...@@ -2402,16 +2402,10 @@ void SwUndoTableNumFormat::SetBox( const SwTableBox& rBox ) ...@@ -2402,16 +2402,10 @@ void SwUndoTableNumFormat::SetBox( const SwTableBox& rBox )
UndoTableCpyTable_Entry::UndoTableCpyTable_Entry( const SwTableBox& rBox ) UndoTableCpyTable_Entry::UndoTableCpyTable_Entry( const SwTableBox& rBox )
: nBoxIdx( rBox.GetSttIdx() ), nOffset( 0 ), : 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) SwUndoTableCpyTable::SwUndoTableCpyTable(const SwDoc* pDoc)
: SwUndo( SwUndoId::TBLCPYTBL, pDoc ) : SwUndo( SwUndoId::TBLCPYTBL, pDoc )
, m_pArr(new SwUndoTableCpyTable_Entries) , m_pArr(new SwUndoTableCpyTable_Entries)
...@@ -2447,7 +2441,7 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext) ...@@ -2447,7 +2441,7 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext)
// b62341295: Redline for copying tables // b62341295: Redline for copying tables
const SwNode *pEndNode = rBox.GetSttNd()->EndOfSectionNode(); const SwNode *pEndNode = rBox.GetSttNd()->EndOfSectionNode();
SwPaM aPam( aInsIdx.GetNode(), *pEndNode ); SwPaM aPam( aInsIdx.GetNode(), *pEndNode );
SwUndoDelete* pUndo = nullptr; std::unique_ptr<SwUndoDelete> pUndo;
if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() ) ) if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() ) )
{ {
...@@ -2457,9 +2451,9 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext) ...@@ -2457,9 +2451,9 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext)
if( pEntry->pUndo ) if( pEntry->pUndo )
{ {
SwUndoDelete *const pUndoDelete = SwUndoDelete *const pUndoDelete =
dynamic_cast<SwUndoDelete*>(pEntry->pUndo); dynamic_cast<SwUndoDelete*>(pEntry->pUndo.get());
SwUndoRedlineDelete *const pUndoRedlineDelete = SwUndoRedlineDelete *const pUndoRedlineDelete =
dynamic_cast<SwUndoRedlineDelete*>(pEntry->pUndo); dynamic_cast<SwUndoRedlineDelete*>(pEntry->pUndo.get());
OSL_ASSERT(pUndoDelete || pUndoRedlineDelete); OSL_ASSERT(pUndoDelete || pUndoRedlineDelete);
if (pUndoRedlineDelete) if (pUndoRedlineDelete)
{ {
...@@ -2503,8 +2497,7 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext) ...@@ -2503,8 +2497,7 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext)
if( pEntry->pUndo ) if( pEntry->pUndo )
{ {
pEntry->pUndo->UndoImpl(rContext); pEntry->pUndo->UndoImpl(rContext);
delete pEntry->pUndo; pEntry->pUndo.reset();
pEntry->pUndo = nullptr;
} }
if( bShiftPam ) if( bShiftPam )
{ {
...@@ -2520,19 +2513,18 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext) ...@@ -2520,19 +2513,18 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext)
else else
*aPam.GetPoint() = SwPosition( aTmpIdx ); *aPam.GetPoint() = SwPosition( aTmpIdx );
} }
pUndo = new SwUndoDelete( aPam, bDeleteCompleteParagraph, true ); pUndo = o3tl::make_unique<SwUndoDelete>( aPam, bDeleteCompleteParagraph, true );
} }
else else
{ {
pUndo = new SwUndoDelete( aPam, true ); pUndo = o3tl::make_unique<SwUndoDelete>( aPam, true );
if( pEntry->pUndo ) if( pEntry->pUndo )
{ {
pEntry->pUndo->UndoImpl(rContext); pEntry->pUndo->UndoImpl(rContext);
delete pEntry->pUndo; pEntry->pUndo.reset();
pEntry->pUndo = nullptr;
} }
} }
pEntry->pUndo = pUndo; pEntry->pUndo = std::move(pUndo);
aInsIdx = rBox.GetSttIdx() + 1; aInsIdx = rBox.GetSttIdx() + 1;
rDoc.GetNodes().Delete( aInsIdx ); rDoc.GetNodes().Delete( aInsIdx );
...@@ -2550,13 +2542,12 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext) ...@@ -2550,13 +2542,12 @@ void SwUndoTableCpyTable::UndoImpl(::sw::UndoRedoContext & rContext)
if( pEntry->pBoxNumAttr ) if( pEntry->pBoxNumAttr )
{ {
rBox.ClaimFrameFormat()->SetFormatAttr( *pEntry->pBoxNumAttr ); rBox.ClaimFrameFormat()->SetFormatAttr( *pEntry->pBoxNumAttr );
delete pEntry->pBoxNumAttr; pEntry->pBoxNumAttr.reset();
pEntry->pBoxNumAttr = nullptr;
} }
if( aTmpSet.Count() ) if( aTmpSet.Count() )
{ {
pEntry->pBoxNumAttr = new SfxItemSet( rDoc.GetAttrPool(), pEntry->pBoxNumAttr = o3tl::make_unique<SfxItemSet>( rDoc.GetAttrPool(),
RES_BOXATR_FORMAT, RES_BOXATR_VALUE, RES_BOXATR_FORMAT, RES_BOXATR_VALUE,
RES_VERT_ORIENT, RES_VERT_ORIENT, 0 ); RES_VERT_ORIENT, RES_VERT_ORIENT, 0 );
pEntry->pBoxNumAttr->Put( aTmpSet ); pEntry->pBoxNumAttr->Put( aTmpSet );
...@@ -2598,7 +2589,7 @@ void SwUndoTableCpyTable::RedoImpl(::sw::UndoRedoContext & rContext) ...@@ -2598,7 +2589,7 @@ void SwUndoTableCpyTable::RedoImpl(::sw::UndoRedoContext & rContext)
// b62341295: Redline for copying tables - Start. // b62341295: Redline for copying tables - Start.
rDoc.GetNodes().MakeTextNode( aInsIdx, rDoc.GetDfltTextFormatColl() ); rDoc.GetNodes().MakeTextNode( aInsIdx, rDoc.GetDfltTextFormatColl() );
SwPaM aPam( aInsIdx.GetNode(), *rBox.GetSttNd()->EndOfSectionNode()); 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 ) if( pEntry->pUndo )
{ {
pEntry->pUndo->UndoImpl(rContext); pEntry->pUndo->UndoImpl(rContext);
...@@ -2621,10 +2612,9 @@ void SwUndoTableCpyTable::RedoImpl(::sw::UndoRedoContext & rContext) ...@@ -2621,10 +2612,9 @@ void SwUndoTableCpyTable::RedoImpl(::sw::UndoRedoContext & rContext)
pUndo = PrepareRedline( &rDoc, rBox, aTmpPos, pEntry->bJoin, true ); pUndo = PrepareRedline( &rDoc, rBox, aTmpPos, pEntry->bJoin, true );
} }
} }
delete pEntry->pUndo; pEntry->pUndo.reset();
pEntry->pUndo = nullptr;
} }
pEntry->pUndo = pUndo; pEntry->pUndo = std::move(pUndo);
// b62341295: Redline for copying tables - End. // b62341295: Redline for copying tables - End.
aInsIdx = rBox.GetSttIdx() + 1; aInsIdx = rBox.GetSttIdx() + 1;
...@@ -2642,13 +2632,12 @@ void SwUndoTableCpyTable::RedoImpl(::sw::UndoRedoContext & rContext) ...@@ -2642,13 +2632,12 @@ void SwUndoTableCpyTable::RedoImpl(::sw::UndoRedoContext & rContext)
if( pEntry->pBoxNumAttr ) if( pEntry->pBoxNumAttr )
{ {
rBox.ClaimFrameFormat()->SetFormatAttr( *pEntry->pBoxNumAttr ); rBox.ClaimFrameFormat()->SetFormatAttr( *pEntry->pBoxNumAttr );
delete pEntry->pBoxNumAttr; pEntry->pBoxNumAttr.reset();
pEntry->pBoxNumAttr = nullptr;
} }
if( aTmpSet.Count() ) if( aTmpSet.Count() )
{ {
pEntry->pBoxNumAttr = new SfxItemSet( rDoc.GetAttrPool(), pEntry->pBoxNumAttr = o3tl::make_unique<SfxItemSet>( rDoc.GetAttrPool(),
RES_BOXATR_FORMAT, RES_BOXATR_VALUE, RES_BOXATR_FORMAT, RES_BOXATR_VALUE,
RES_VERT_ORIENT, RES_VERT_ORIENT, 0 ); RES_VERT_ORIENT, RES_VERT_ORIENT, 0 );
pEntry->pBoxNumAttr->Put( aTmpSet ); pEntry->pBoxNumAttr->Put( aTmpSet );
...@@ -2676,17 +2665,16 @@ void SwUndoTableCpyTable::AddBoxBefore( const SwTableBox& rBox, bool bDelContent ...@@ -2676,17 +2665,16 @@ void SwUndoTableCpyTable::AddBoxBefore( const SwTableBox& rBox, bool bDelContent
SwPaM aPam( aInsIdx.GetNode(), *rBox.GetSttNd()->EndOfSectionNode() ); SwPaM aPam( aInsIdx.GetNode(), *rBox.GetSttNd()->EndOfSectionNode() );
if( !pDoc->getIDocumentRedlineAccess().IsRedlineOn() ) 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_BOXATR_FORMAT, RES_BOXATR_VALUE,
RES_VERT_ORIENT, RES_VERT_ORIENT, 0 ); RES_VERT_ORIENT, RES_VERT_ORIENT, 0 );
pEntry->pBoxNumAttr->Put( rBox.GetFrameFormat()->GetAttrSet() ); pEntry->pBoxNumAttr->Put( rBox.GetFrameFormat()->GetAttrSet() );
if( !pEntry->pBoxNumAttr->Count() ) if( !pEntry->pBoxNumAttr->Count() )
{ {
delete pEntry->pBoxNumAttr; pEntry->pBoxNumAttr.reset();
pEntry->pBoxNumAttr = nullptr;
} }
DEBUG_REDLINE( pDoc ) DEBUG_REDLINE( pDoc )
} }
...@@ -2720,10 +2708,10 @@ void SwUndoTableCpyTable::AddBoxAfter( const SwTableBox& rBox, const SwNodeIndex ...@@ -2720,10 +2708,10 @@ void SwUndoTableCpyTable::AddBoxAfter( const SwTableBox& rBox, const SwNodeIndex
// been merged. // been merged.
// rJoin is true if Redo() is calling and the content has already 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 ) const SwPosition& rPos, bool& rJoin, bool bRedo )
{ {
SwUndo *pUndo = nullptr; std::unique_ptr<SwUndo> pUndo;
// b62341295: Redline for copying tables // b62341295: Redline for copying tables
// What's to do? // What's to do?
// Mark the cell content before rIdx as insertion, // Mark the cell content before rIdx as insertion,
...@@ -2767,7 +2755,7 @@ SwUndo* SwUndoTableCpyTable::PrepareRedline( SwDoc* pDoc, const SwTableBox& rBox ...@@ -2767,7 +2755,7 @@ SwUndo* SwUndoTableCpyTable::PrepareRedline( SwDoc* pDoc, const SwTableBox& rBox
if( aDeleteStart != aCellEnd ) if( aDeleteStart != aCellEnd )
{ // If the old (deleted) part is not empty, here we are... { // If the old (deleted) part is not empty, here we are...
SwPaM aDeletePam( aDeleteStart, aCellEnd ); 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 ); 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 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 ...@@ -2775,7 +2763,7 @@ SwUndo* SwUndoTableCpyTable::PrepareRedline( SwDoc* pDoc, const SwTableBox& rBox
aCellEnd = SwPosition( aCellEnd = SwPosition(
SwNodeIndex( *rBox.GetSttNd()->EndOfSectionNode() )); SwNodeIndex( *rBox.GetSttNd()->EndOfSectionNode() ));
SwPaM aTmpPam( aDeleteStart, aCellEnd ); SwPaM aTmpPam( aDeleteStart, aCellEnd );
pUndo = new SwUndoDelete( aTmpPam, true ); pUndo = o3tl::make_unique<SwUndoDelete>( aTmpPam, true );
} }
SwPosition aCellStart( SwNodeIndex( *rBox.GetSttNd(), 2 ) ); SwPosition aCellStart( SwNodeIndex( *rBox.GetSttNd(), 2 ) );
pText = aCellStart.nNode.GetNode().GetTextNode(); pText = aCellStart.nNode.GetNode().GetTextNode();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment