sw/inc/redline.hxx | 9 +-- sw/qa/core/uwriter.cxx | 2 sw/source/core/doc/docredln.cxx | 62 ++++++++++++------------ sw/source/core/undo/undobj.cxx | 4 - sw/source/core/unocore/unoredline.cxx | 10 +-- sw/source/filter/xml/XMLRedlineImportHelper.cxx | 2 6 files changed, 46 insertions(+), 43 deletions(-)
New commits: commit 00f3bbc84634a9f07c046140d84445303585817c Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sun Aug 7 20:37:56 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Aug 8 21:00:59 2022 +0200 unique_ptr->optional in SwRangeRedline Change-Id: I4d4c55eef6e6b56634766bc57f11539ece9dc20d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137940 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/redline.hxx b/sw/inc/redline.hxx index c8123f178c22..1ad8c456b56c 100644 --- a/sw/inc/redline.hxx +++ b/sw/inc/redline.hxx @@ -156,7 +156,7 @@ public: class SW_DLLPUBLIC SwRangeRedline final : public SwPaM { SwRedlineData* m_pRedlineData; - SwNodeIndex* m_pContentSect; + std::optional<SwNodeIndex> m_oContentSect; std::optional<tools::Long> m_oLOKLastNodeTop; sal_uInt32 m_nId; bool m_bDelLastPara : 1; @@ -176,7 +176,7 @@ public: // For sw3io: pData is taken over! SwRangeRedline(SwRedlineData* pData, const SwPosition& rPos, bool bDelLP) : - SwPaM( rPos ), m_pRedlineData( pData ), m_pContentSect( nullptr ), + SwPaM( rPos ), m_pRedlineData( pData ), m_nId( s_nLastId++ ), m_bDelLastPara( bDelLP ), m_bIsVisible( true ) { GetBound().SetRedline(this); @@ -186,9 +186,10 @@ public: virtual ~SwRangeRedline() override; sal_uInt32 GetId() const { return m_nId; } - SwNodeIndex* GetContentIdx() const { return m_pContentSect; } + const SwNodeIndex* GetContentIdx() const { return m_oContentSect ? &*m_oContentSect : nullptr; } // For Undo. - void SetContentIdx( const SwNodeIndex* ); + void SetContentIdx( const SwNodeIndex& ); + void ClearContentIdx(); bool IsVisible() const { return m_bIsVisible; } bool IsDelLastPara() const { return m_bDelLastPara; } diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx index 7cd0b38ec2ae..79545969c457 100644 --- a/sw/qa/core/uwriter.cxx +++ b/sw/qa/core/uwriter.cxx @@ -788,7 +788,7 @@ void SwDocTest::testSwScanner() SwNodes& rNds = m_pDoc->GetNodes(); CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(1), rTable.size()); - SwNodeIndex* pNodeIdx = rTable[0]->GetContentIdx(); + const SwNodeIndex* pNodeIdx = rTable[0]->GetContentIdx(); CPPUNIT_ASSERT(pNodeIdx); pTextNode = rNds[ pNodeIdx->GetIndex() + 1 ]->GetTextNode(); //first deleted txtnode diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx index 3449a6420c5f..0f76346217d9 100644 --- a/sw/source/core/doc/docredln.cxx +++ b/sw/source/core/doc/docredln.cxx @@ -1099,7 +1099,6 @@ sal_uInt32 SwRangeRedline::s_nLastId = 1; SwRangeRedline::SwRangeRedline(RedlineType eTyp, const SwPaM& rPam ) : SwPaM( *rPam.GetMark(), *rPam.GetPoint() ), m_pRedlineData( new SwRedlineData( eTyp, GetDoc().getIDocumentRedlineAccess().GetRedlineAuthor() ) ), - m_pContentSect( nullptr ), m_nId( s_nLastId++ ) { GetBound().SetRedline(this); @@ -1122,7 +1121,6 @@ SwRangeRedline::SwRangeRedline(RedlineType eTyp, const SwPaM& rPam ) SwRangeRedline::SwRangeRedline( const SwRedlineData& rData, const SwPaM& rPam ) : SwPaM( *rPam.GetMark(), *rPam.GetPoint() ), m_pRedlineData( new SwRedlineData( rData )), - m_pContentSect( nullptr ), m_nId( s_nLastId++ ) { GetBound().SetRedline(this); @@ -1137,7 +1135,6 @@ SwRangeRedline::SwRangeRedline( const SwRedlineData& rData, const SwPaM& rPam ) SwRangeRedline::SwRangeRedline( const SwRedlineData& rData, const SwPosition& rPos ) : SwPaM( rPos ), m_pRedlineData( new SwRedlineData( rData )), - m_pContentSect( nullptr ), m_nId( s_nLastId++ ) { GetBound().SetRedline(this); @@ -1150,7 +1147,6 @@ SwRangeRedline::SwRangeRedline( const SwRedlineData& rData, const SwPosition& rP SwRangeRedline::SwRangeRedline( const SwRangeRedline& rCpy ) : SwPaM( *rCpy.GetMark(), *rCpy.GetPoint() ), m_pRedlineData( new SwRedlineData( *rCpy.m_pRedlineData )), - m_pContentSect( nullptr ), m_nId( s_nLastId++ ) { GetBound().SetRedline(this); @@ -1164,12 +1160,12 @@ SwRangeRedline::SwRangeRedline( const SwRangeRedline& rCpy ) SwRangeRedline::~SwRangeRedline() { - if( m_pContentSect ) + if( m_oContentSect ) { // delete the ContentSection if( !GetDoc().IsInDtor() ) - GetDoc().getIDocumentContentOperations().DeleteSection( &m_pContentSect->GetNode() ); - delete m_pContentSect; + GetDoc().getIDocumentContentOperations().DeleteSection( &m_oContentSect->GetNode() ); + m_oContentSect.reset(); } delete m_pRedlineData; } @@ -1498,7 +1494,7 @@ static void lcl_storeAnnotationMarks(SwDoc& rDoc, const SwPosition* pStt, const void SwRangeRedline::MoveToSection() { - if( !m_pContentSect ) + if( !m_oContentSect ) { auto [pStt, pEnd] = StartEnd(); // SwPosition* @@ -1558,7 +1554,7 @@ void SwRangeRedline::MoveToSection() rDoc.getIDocumentContentOperations().MoveRange( aPam, aPos, SwMoveFlags::DEFAULT ); } - m_pContentSect = new SwNodeIndex( *pSttNd ); + m_oContentSect.emplace( *pSttNd ); if( pStt == GetPoint() ) Exchange(); @@ -1571,7 +1567,7 @@ void SwRangeRedline::MoveToSection() void SwRangeRedline::CopyToSection() { - if( m_pContentSect ) + if( m_oContentSect ) return; auto [pStt, pEnd] = StartEnd(); // SwPosition* @@ -1638,7 +1634,7 @@ void SwRangeRedline::CopyToSection() rDoc.GetDocumentContentOperationsManager().CopyWithFlyInFly(aRg, aInsPos); } } - m_pContentSect = new SwNodeIndex( *pSttNd ); + m_oContentSect.emplace( *pSttNd ); rDoc.SetCopyIsMove( bSaveCopyFlag ); rDoc.getIDocumentRedlineAccess().SetRedlineMove( bSaveRdlMoveFlg ); @@ -1646,7 +1642,7 @@ void SwRangeRedline::CopyToSection() void SwRangeRedline::DelCopyOfSection(size_t nMyPos) { - if( !m_pContentSect ) + if( !m_oContentSect ) return; auto [pStt, pEnd] = StartEnd(); // SwPosition* @@ -1731,7 +1727,7 @@ void SwRangeRedline::DelCopyOfSection(size_t nMyPos) void SwRangeRedline::MoveFromSection(size_t nMyPos) { - if( m_pContentSect ) + if( m_oContentSect ) { SwDoc& rDoc = GetDoc(); const SwRedlineTable& rTable = rDoc.getIDocumentRedlineAccess().GetRedlineTable(); @@ -1773,10 +1769,10 @@ void SwRangeRedline::MoveFromSection(size_t nMyPos) } } - const SwNode* pKeptContentSectNode( &m_pContentSect->GetNode() ); // #i95711# + const SwNode* pKeptContentSectNode( &m_oContentSect->GetNode() ); // #i95711# { - SwPaM aPam( m_pContentSect->GetNode(), - *m_pContentSect->GetNode().EndOfSectionNode(), SwNodeOffset(1), + SwPaM aPam( m_oContentSect->GetNode(), + *m_oContentSect->GetNode().EndOfSectionNode(), SwNodeOffset(1), SwNodeOffset( m_bDelLastPara ? -2 : -1 ) ); SwContentNode* pCNd = aPam.GetContentNode(); if( pCNd ) @@ -1832,12 +1828,11 @@ void SwRangeRedline::MoveFromSection(size_t nMyPos) // by comparing it with the "indexed" <SwNode> instance copied before // perform the intrinsic move. // Note: Such condition is e.g. a "delete" change tracking only containing a table. - if ( &m_pContentSect->GetNode() == pKeptContentSectNode ) + if ( &m_oContentSect->GetNode() == pKeptContentSectNode ) { - rDoc.getIDocumentContentOperations().DeleteSection( &m_pContentSect->GetNode() ); + rDoc.getIDocumentContentOperations().DeleteSection( &m_oContentSect->GetNode() ); } - delete m_pContentSect; - m_pContentSect = nullptr; + m_oContentSect.reset(); // adjustment of redline table positions must take start and // end into account, not point and mark. @@ -1851,22 +1846,29 @@ void SwRangeRedline::MoveFromSection(size_t nMyPos) } // for Undo -void SwRangeRedline::SetContentIdx( const SwNodeIndex* pIdx ) +void SwRangeRedline::SetContentIdx( const SwNodeIndex& rIdx ) { - if( pIdx && !m_pContentSect ) + if( !m_oContentSect ) { - m_pContentSect = new SwNodeIndex( *pIdx ); + m_oContentSect = rIdx; m_bIsVisible = false; } - else if( !pIdx && m_pContentSect ) + else { - delete m_pContentSect; - m_pContentSect = nullptr; - m_bIsVisible = false; + OSL_FAIL("SwRangeRedline::SetContentIdx: invalid state"); + } +} + +// for Undo +void SwRangeRedline::ClearContentIdx() +{ + if( m_oContentSect ) + { + m_oContentSect.reset(); } else { - OSL_FAIL("SwRangeRedline::SetContentIdx: invalid state"); + OSL_FAIL("SwRangeRedline::ClearContentIdx: invalid state"); } } @@ -1975,13 +1977,13 @@ OUString SwRangeRedline::GetDescr(bool bSimplified) bool bDeletePaM = false; // if this redline is visible the content is in this PaM - if (nullptr == m_pContentSect) + if (!m_oContentSect.has_value()) { pPaM = this; } else // otherwise it is saved in pContentSect { - pPaM = new SwPaM( m_pContentSect->GetNode(), *m_pContentSect->GetNode().EndOfSectionNode() ); + pPaM = new SwPaM( m_oContentSect->GetNode(), *m_oContentSect->GetNode().EndOfSectionNode() ); bDeletePaM = true; } diff --git a/sw/source/core/undo/undobj.cxx b/sw/source/core/undo/undobj.cxx index 79df3eaf0c01..b91eb0c6a0ac 100644 --- a/sw/source/core/undo/undobj.cxx +++ b/sw/source/core/undo/undobj.cxx @@ -1359,7 +1359,7 @@ SwRedlineSaveData::SwRedlineSaveData( { // than move section into UndoArray and memorize it SaveSection( *rRedl.GetContentIdx() ); - rRedl.SetContentIdx( nullptr ); + rRedl.ClearContentIdx(); } break; @@ -1391,7 +1391,7 @@ void SwRedlineSaveData::RedlineToDoc( SwPaM const & rPam ) RestoreSection( &rDoc, &aIdx, SwNormalStartNode ); if( GetHistory() ) GetHistory()->Rollback( &rDoc ); - pRedl->SetContentIdx( &aIdx ); + pRedl->SetContentIdx( aIdx ); } SetPaM( *pRedl ); // First, delete the "old" so that in an Append no unexpected things will diff --git a/sw/source/core/unocore/unoredline.cxx b/sw/source/core/unocore/unoredline.cxx index 71d3ba36cbfd..0805c01d3372 100644 --- a/sw/source/core/unocore/unoredline.cxx +++ b/sw/source/core/unocore/unoredline.cxx @@ -199,7 +199,7 @@ uno::Any SwXRedlinePortion::getPropertyValue( const OUString& rPropertyName ) uno::Any aRet; if(rPropertyName == UNO_NAME_REDLINE_TEXT) { - SwNodeIndex* pNodeIdx = m_rRedline.GetContentIdx(); + const SwNodeIndex* pNodeIdx = m_rRedline.GetContentIdx(); if(pNodeIdx ) { if ( SwNodeOffset(1) < ( pNodeIdx->GetNode().EndOfSectionIndex() - pNodeIdx->GetNode().GetIndex() ) ) @@ -311,7 +311,7 @@ uno::Sequence< beans::PropertyValue > SwXRedlinePortion::CreateRedlineProperties pRet[nPropIdx].Name = UNO_NAME_MERGE_LAST_PARA; pRet[nPropIdx++].Value <<= !rRedline.IsDelLastPara(); - SwNodeIndex* pNodeIdx = rRedline.GetContentIdx(); + const SwNodeIndex* pNodeIdx = rRedline.GetContentIdx(); if(pNodeIdx ) { if ( SwNodeOffset(1) < ( pNodeIdx->GetNode().EndOfSectionIndex() - pNodeIdx->GetNode().GetIndex() ) ) @@ -442,7 +442,7 @@ uno::Any SwXRedline::getPropertyValue( const OUString& rPropertyName ) } else if(rPropertyName == UNO_NAME_REDLINE_TEXT) { - SwNodeIndex* pNodeIdx = m_pRedline->GetContentIdx(); + const SwNodeIndex* pNodeIdx = m_pRedline->GetContentIdx(); if( pNodeIdx ) { if ( SwNodeOffset(1) < ( pNodeIdx->GetNode().EndOfSectionIndex() - pNodeIdx->GetNode().GetIndex() ) ) @@ -499,7 +499,7 @@ uno::Reference< container::XEnumeration > SwXRedline::createEnumeration() if(!m_pDoc) throw uno::RuntimeException(); - SwNodeIndex* pNodeIndex = m_pRedline->GetContentIdx(); + const SwNodeIndex* pNodeIndex = m_pRedline->GetContentIdx(); if(!pNodeIndex) return nullptr; SwPaM aPam(*pNodeIndex); @@ -526,7 +526,7 @@ uno::Reference< text::XTextCursor > SwXRedline::createTextCursor() if(!m_pDoc) throw uno::RuntimeException(); - SwNodeIndex* pNodeIndex = m_pRedline->GetContentIdx(); + const SwNodeIndex* pNodeIndex = m_pRedline->GetContentIdx(); if(!pNodeIndex) { throw uno::RuntimeException(); diff --git a/sw/source/filter/xml/XMLRedlineImportHelper.cxx b/sw/source/filter/xml/XMLRedlineImportHelper.cxx index f2fb66d54c65..a2cc2c705556 100644 --- a/sw/source/filter/xml/XMLRedlineImportHelper.cxx +++ b/sw/source/filter/xml/XMLRedlineImportHelper.cxx @@ -680,7 +680,7 @@ void XMLRedlineImportHelper::InsertIntoDocument(RedlineInfo* pRedlineInfo) SwNodeOffset nPoint = aPaM.GetPoint()->GetNodeIndex(); if( nPoint < pRedlineInfo->pContentIndex->GetIndex() || nPoint > pRedlineInfo->pContentIndex->GetNode().EndOfSectionIndex() ) - pRedline->SetContentIdx(pRedlineInfo->pContentIndex); + pRedline->SetContentIdx(*pRedlineInfo->pContentIndex); else SAL_WARN("sw", "Recursive change tracking"); }