Kaydet (Commit) ee204f8f authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in SwDoc::GetRowHeight and GetRowSplit

fixing a memory leak in the process

Change-Id: I1b168159a8aa23e392768c49127f42b72e1ce3b3
Reviewed-on: https://gerrit.libreoffice.org/63128
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 939de6a6
...@@ -1431,9 +1431,9 @@ public: ...@@ -1431,9 +1431,9 @@ public:
const bool _bPosCorr ); const bool _bPosCorr );
void SetRowHeight( const SwCursor& rCursor, const SwFormatFrameSize &rNew ); void SetRowHeight( const SwCursor& rCursor, const SwFormatFrameSize &rNew );
static void GetRowHeight( const SwCursor& rCursor, SwFormatFrameSize *& rpSz ); static std::unique_ptr<SwFormatFrameSize> GetRowHeight( const SwCursor& rCursor );
void SetRowSplit( const SwCursor& rCursor, const SwFormatRowSplit &rNew ); void SetRowSplit( const SwCursor& rCursor, const SwFormatRowSplit &rNew );
static void GetRowSplit( const SwCursor& rCursor, SwFormatRowSplit *& rpSz ); static std::unique_ptr<SwFormatRowSplit> GetRowSplit( const SwCursor& rCursor );
/// Adjustment of Rowheights. Determine via bTstOnly if more than one row is selected. /// Adjustment of Rowheights. Determine via bTstOnly if more than one row is selected.
/// bOptimize: distribute current table height, instead of using the largest row. /// bOptimize: distribute current table height, instead of using the largest row.
......
...@@ -647,10 +647,10 @@ public: ...@@ -647,10 +647,10 @@ public:
void SetRowHeight( const SwFormatFrameSize &rSz ); void SetRowHeight( const SwFormatFrameSize &rSz );
/// Pointer must be destroyed by caller != 0. /// Pointer must be destroyed by caller != 0.
void GetRowHeight( SwFormatFrameSize *&rpSz ) const; std::unique_ptr<SwFormatFrameSize> GetRowHeight() const;
void SetRowSplit( const SwFormatRowSplit &rSz ); void SetRowSplit( const SwFormatRowSplit &rSz );
void GetRowSplit( SwFormatRowSplit *&rpSz ) const; std::unique_ptr<SwFormatRowSplit> GetRowSplit() const;
void SetBoxAlign( sal_uInt16 nOrient ); void SetBoxAlign( sal_uInt16 nOrient );
sal_uInt16 GetBoxAlign() const; ///< USHRT_MAX if ambiguous. sal_uInt16 GetBoxAlign() const; ///< USHRT_MAX if ambiguous.
......
...@@ -930,11 +930,9 @@ void SwTableAutoFormat::StoreTableProperties(const SwTable &table) ...@@ -930,11 +930,9 @@ void SwTableAutoFormat::StoreTableProperties(const SwTable &table)
return; return;
SwEditShell *pShell = pDoc->GetEditShell(); SwEditShell *pShell = pDoc->GetEditShell();
SwFormatRowSplit *pRowSplit = nullptr; std::unique_ptr<SwFormatRowSplit> pRowSplit = SwDoc::GetRowSplit(*pShell->getShellCursor(false));
SwDoc::GetRowSplit(*pShell->getShellCursor(false), pRowSplit);
m_bRowSplit = pRowSplit && pRowSplit->GetValue(); m_bRowSplit = pRowSplit && pRowSplit->GetValue();
delete pRowSplit; pRowSplit.reset();
pRowSplit = nullptr;
const SfxItemSet &rSet = pFormat->GetAttrSet(); const SfxItemSet &rSet = pFormat->GetAttrSet();
......
...@@ -336,35 +336,28 @@ void SwDoc::SetRowSplit( const SwCursor& rCursor, const SwFormatRowSplit &rNew ) ...@@ -336,35 +336,28 @@ void SwDoc::SetRowSplit( const SwCursor& rCursor, const SwFormatRowSplit &rNew )
} }
} }
void SwDoc::GetRowSplit( const SwCursor& rCursor, SwFormatRowSplit *& rpSz ) std::unique_ptr<SwFormatRowSplit> SwDoc::GetRowSplit( const SwCursor& rCursor )
{ {
rpSz = nullptr;
SwTableNode* pTableNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode(); SwTableNode* pTableNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
if( pTableNd ) if( !pTableNd )
{ return nullptr;
std::vector<SwTableLine*> aRowArr; // For Lines collecting
::lcl_CollectLines( aRowArr, rCursor, false );
if( !aRowArr.empty() ) std::vector<SwTableLine*> aRowArr; // For Lines collecting
{ ::lcl_CollectLines( aRowArr, rCursor, false );
rpSz = &const_cast<SwFormatRowSplit&>(aRowArr[0]->GetFrameFormat()->GetRowSplit());
if (rpSz) if( aRowArr.empty() )
{ return nullptr;
for ( auto pLn : aRowArr )
{ SwFormatRowSplit* pSz = &const_cast<SwFormatRowSplit&>(aRowArr[0]->GetFrameFormat()->GetRowSplit());
if ( (*rpSz).GetValue() != pLn->GetFrameFormat()->GetRowSplit().GetValue() )
{ for ( auto pLn : aRowArr )
rpSz = nullptr; {
break; if ( pSz->GetValue() != pLn->GetFrameFormat()->GetRowSplit().GetValue() )
} {
} return nullptr;
}
if ( rpSz )
rpSz = new SwFormatRowSplit( *rpSz );
} }
} }
return o3tl::make_unique<SwFormatRowSplit>( *pSz );
} }
/* Class: SwDoc /* Class: SwDoc
...@@ -407,35 +400,26 @@ void SwDoc::SetRowHeight( const SwCursor& rCursor, const SwFormatFrameSize &rNew ...@@ -407,35 +400,26 @@ void SwDoc::SetRowHeight( const SwCursor& rCursor, const SwFormatFrameSize &rNew
} }
} }
void SwDoc::GetRowHeight( const SwCursor& rCursor, SwFormatFrameSize *& rpSz ) std::unique_ptr<SwFormatFrameSize> SwDoc::GetRowHeight( const SwCursor& rCursor )
{ {
rpSz = nullptr;
SwTableNode* pTableNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode(); SwTableNode* pTableNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
if( pTableNd ) if( !pTableNd )
{ return nullptr;
std::vector<SwTableLine*> aRowArr; // For Lines collecting
::lcl_CollectLines( aRowArr, rCursor, true );
if( !aRowArr.empty() ) std::vector<SwTableLine*> aRowArr; // For Lines collecting
{ ::lcl_CollectLines( aRowArr, rCursor, true );
rpSz = &const_cast<SwFormatFrameSize&>(aRowArr[0]->GetFrameFormat()->GetFrameSize());
if (rpSz) if( aRowArr.empty() )
{ return nullptr;
for ( auto pLn : aRowArr )
{ SwFormatFrameSize* pSz = &const_cast<SwFormatFrameSize&>(aRowArr[0]->GetFrameFormat()->GetFrameSize());
if ( *rpSz != pLn->GetFrameFormat()->GetFrameSize() )
{ for ( auto pLn : aRowArr )
rpSz = nullptr; {
break; if ( *pSz != pLn->GetFrameFormat()->GetFrameSize() )
} return nullptr;
}
}
if ( rpSz )
rpSz = new SwFormatFrameSize( *rpSz );
}
} }
return o3tl::make_unique<SwFormatFrameSize>( *pSz );
} }
bool SwDoc::BalanceRowHeight( const SwCursor& rCursor, bool bTstOnly, const bool bOptimize ) bool SwDoc::BalanceRowHeight( const SwCursor& rCursor, bool bTstOnly, const bool bOptimize )
......
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
#include <swerror.h> #include <swerror.h>
#include <swundo.hxx> #include <swundo.hxx>
#include <frmtool.hxx> #include <frmtool.hxx>
#include <fmtrowsplt.hxx>
#include <node.hxx> #include <node.hxx>
#include <sortedobjs.hxx> #include <sortedobjs.hxx>
...@@ -718,9 +718,9 @@ void SwFEShell::SetRowSplit( const SwFormatRowSplit& rNew ) ...@@ -718,9 +718,9 @@ void SwFEShell::SetRowSplit( const SwFormatRowSplit& rNew )
EndAllActionAndCall(); EndAllActionAndCall();
} }
void SwFEShell::GetRowSplit( SwFormatRowSplit*& rpSz ) const std::unique_ptr<SwFormatRowSplit> SwFEShell::GetRowSplit() const
{ {
SwDoc::GetRowSplit( *getShellCursor( false ), rpSz ); return SwDoc::GetRowSplit( *getShellCursor( false ) );
} }
void SwFEShell::SetRowHeight( const SwFormatFrameSize &rNew ) void SwFEShell::SetRowHeight( const SwFormatFrameSize &rNew )
...@@ -731,9 +731,9 @@ void SwFEShell::SetRowHeight( const SwFormatFrameSize &rNew ) ...@@ -731,9 +731,9 @@ void SwFEShell::SetRowHeight( const SwFormatFrameSize &rNew )
EndAllActionAndCall(); EndAllActionAndCall();
} }
void SwFEShell::GetRowHeight( SwFormatFrameSize *& rpSz ) const std::unique_ptr<SwFormatFrameSize> SwFEShell::GetRowHeight() const
{ {
SwDoc::GetRowHeight( *getShellCursor( false ), rpSz ); return SwDoc::GetRowHeight( *getShellCursor( false ) );
} }
bool SwFEShell::BalanceRowHeight( bool bTstOnly, const bool bOptimize ) bool SwFEShell::BalanceRowHeight( bool bTstOnly, const bool bOptimize )
......
...@@ -58,15 +58,12 @@ SwTableHeightDlg::SwTableHeightDlg(weld::Window *pParent, SwWrtShell &rS) ...@@ -58,15 +58,12 @@ SwTableHeightDlg::SwTableHeightDlg(weld::Window *pParent, SwWrtShell &rS)
::SetFieldUnit(*m_xHeightEdit, eFieldUnit); ::SetFieldUnit(*m_xHeightEdit, eFieldUnit);
m_xHeightEdit->set_min(MINLAY, FieldUnit::TWIP); m_xHeightEdit->set_min(MINLAY, FieldUnit::TWIP);
SwFormatFrameSize *pSz; std::unique_ptr<SwFormatFrameSize> pSz = m_rSh.GetRowHeight();
m_rSh.GetRowHeight(pSz);
if (pSz) if (pSz)
{ {
auto nHeight = pSz->GetHeight(); auto nHeight = pSz->GetHeight();
m_xAutoHeightCB->set_active(pSz->GetHeightSizeType() != ATT_FIX_SIZE); m_xAutoHeightCB->set_active(pSz->GetHeightSizeType() != ATT_FIX_SIZE);
m_xHeightEdit->set_value(m_xHeightEdit->normalize(nHeight), FieldUnit::TWIP); m_xHeightEdit->set_value(m_xHeightEdit->normalize(nHeight), FieldUnit::TWIP);
delete pSz;
} }
} }
......
...@@ -203,12 +203,11 @@ static SwTableRep* lcl_TableParamToItemSet( SfxItemSet& rSet, SwWrtShell &rSh ) ...@@ -203,12 +203,11 @@ static SwTableRep* lcl_TableParamToItemSet( SfxItemSet& rSet, SwWrtShell &rSh )
rSh.GetTabBorders( rSet ); rSh.GetTabBorders( rSet );
//row split //row split
SwFormatRowSplit* pSplit = nullptr; std::unique_ptr<SwFormatRowSplit> pSplit = rSh.GetRowSplit();
rSh.GetRowSplit(pSplit);
if(pSplit) if(pSplit)
{ {
rSet.Put(*pSplit); rSet.Put(*pSplit);
delete pSplit; pSplit.reset();
} }
if(!bTableSel) if(!bTableSel)
...@@ -1184,21 +1183,20 @@ void SwTableShell::Execute(SfxRequest &rReq) ...@@ -1184,21 +1183,20 @@ void SwTableShell::Execute(SfxRequest &rReq)
case FN_TABLE_ROW_SPLIT : case FN_TABLE_ROW_SPLIT :
{ {
const SfxBoolItem* pBool = static_cast<const SfxBoolItem*>(pItem); const SfxBoolItem* pBool = static_cast<const SfxBoolItem*>(pItem);
SwFormatRowSplit* pSplit = nullptr; std::unique_ptr<SwFormatRowSplit> pSplit;
if(!pBool) if(!pBool)
{ {
rSh.GetRowSplit(pSplit); pSplit = rSh.GetRowSplit();
if(pSplit) if(pSplit)
pSplit->SetValue(!pSplit->GetValue()); pSplit->SetValue(!pSplit->GetValue());
else else
pSplit = new SwFormatRowSplit(true); pSplit.reset(new SwFormatRowSplit(true));
} }
else else
{ {
pSplit = new SwFormatRowSplit(pBool->GetValue()); pSplit.reset(new SwFormatRowSplit(pBool->GetValue()));
} }
rSh.SetRowSplit( *pSplit ); rSh.SetRowSplit( *pSplit );
delete pSplit;
break; break;
} }
...@@ -1268,13 +1266,11 @@ void SwTableShell::GetState(SfxItemSet &rSet) ...@@ -1268,13 +1266,11 @@ void SwTableShell::GetState(SfxItemSet &rSet)
case SID_TABLE_MINIMAL_ROW_HEIGHT: case SID_TABLE_MINIMAL_ROW_HEIGHT:
{ {
// Disable if auto height already is enabled. // Disable if auto height already is enabled.
SwFormatFrameSize *pSz; std::unique_ptr<SwFormatFrameSize> pSz = rSh.GetRowHeight();
rSh.GetRowHeight( pSz );
if ( pSz ) if ( pSz )
{ {
if ( ATT_VAR_SIZE == pSz->GetHeightSizeType() ) if ( ATT_VAR_SIZE == pSz->GetHeightSizeType() )
rSet.DisableItem( nSlot ); rSet.DisableItem( nSlot );
delete pSz;
} }
break; break;
} }
...@@ -1365,13 +1361,11 @@ void SwTableShell::GetState(SfxItemSet &rSet) ...@@ -1365,13 +1361,11 @@ void SwTableShell::GetState(SfxItemSet &rSet)
} }
else else
{ {
SwFormatRowSplit* pSplit = nullptr; std::unique_ptr<SwFormatRowSplit> pSplit = rSh.GetRowSplit();
rSh.GetRowSplit(pSplit);
if(pSplit) if(pSplit)
rSet.Put(*pSplit); rSet.Put(*pSplit);
else else
rSet.InvalidateItem( nSlot ); rSet.InvalidateItem( nSlot );
delete pSplit;
} }
break; break;
} }
......
...@@ -139,8 +139,7 @@ void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh ) ...@@ -139,8 +139,7 @@ void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh )
rSet.Put( pFrameFormat->GetFrameDir() ); rSet.Put( pFrameFormat->GetFrameDir() );
} }
SwFormatRowSplit* pSplit = nullptr; std::unique_ptr<SwFormatRowSplit> pSplit = rSh.GetRowSplit();
rSh.GetRowSplit(pSplit);
if(pSplit) if(pSplit)
rSet.Put(*pSplit); rSet.Put(*pSplit);
} }
......
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