[Libreoffice-commits] core.git: sw/inc sw/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Nov 9 05:42:58 UTC 2018
sw/inc/doc.hxx | 4 -
sw/inc/fesh.hxx | 4 -
sw/source/core/doc/tblafmt.cxx | 6 --
sw/source/core/docnode/ndtbl1.cxx | 78 +++++++++++-----------------
sw/source/core/frmedt/fetab.cxx | 10 +--
sw/source/ui/table/rowht.cxx | 5 -
sw/source/uibase/shells/tabsh.cxx | 22 ++-----
sw/source/uibase/uiview/formatclipboard.cxx | 3 -
8 files changed, 52 insertions(+), 80 deletions(-)
New commits:
commit ee204f8f54de5bef526f2ad7fc78a425b196bb63
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Oct 31 09:23:15 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Nov 9 06:41:05 2018 +0100
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: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 6688f19ae77e..1ab0b0775f4c 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1431,9 +1431,9 @@ public:
const bool _bPosCorr );
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 );
- 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.
/// bOptimize: distribute current table height, instead of using the largest row.
diff --git a/sw/inc/fesh.hxx b/sw/inc/fesh.hxx
index 6bf34ba62f2c..5d45fa3e6621 100644
--- a/sw/inc/fesh.hxx
+++ b/sw/inc/fesh.hxx
@@ -647,10 +647,10 @@ public:
void SetRowHeight( const SwFormatFrameSize &rSz );
/// Pointer must be destroyed by caller != 0.
- void GetRowHeight( SwFormatFrameSize *&rpSz ) const;
+ std::unique_ptr<SwFormatFrameSize> GetRowHeight() const;
void SetRowSplit( const SwFormatRowSplit &rSz );
- void GetRowSplit( SwFormatRowSplit *&rpSz ) const;
+ std::unique_ptr<SwFormatRowSplit> GetRowSplit() const;
void SetBoxAlign( sal_uInt16 nOrient );
sal_uInt16 GetBoxAlign() const; ///< USHRT_MAX if ambiguous.
diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx
index cacd3b268f71..b018a468a793 100644
--- a/sw/source/core/doc/tblafmt.cxx
+++ b/sw/source/core/doc/tblafmt.cxx
@@ -930,11 +930,9 @@ void SwTableAutoFormat::StoreTableProperties(const SwTable &table)
return;
SwEditShell *pShell = pDoc->GetEditShell();
- SwFormatRowSplit *pRowSplit = nullptr;
- SwDoc::GetRowSplit(*pShell->getShellCursor(false), pRowSplit);
+ std::unique_ptr<SwFormatRowSplit> pRowSplit = SwDoc::GetRowSplit(*pShell->getShellCursor(false));
m_bRowSplit = pRowSplit && pRowSplit->GetValue();
- delete pRowSplit;
- pRowSplit = nullptr;
+ pRowSplit.reset();
const SfxItemSet &rSet = pFormat->GetAttrSet();
diff --git a/sw/source/core/docnode/ndtbl1.cxx b/sw/source/core/docnode/ndtbl1.cxx
index fcec43de7db4..fc9d328335f8 100644
--- a/sw/source/core/docnode/ndtbl1.cxx
+++ b/sw/source/core/docnode/ndtbl1.cxx
@@ -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();
- if( pTableNd )
- {
- std::vector<SwTableLine*> aRowArr; // For Lines collecting
- ::lcl_CollectLines( aRowArr, rCursor, false );
+ if( !pTableNd )
+ return nullptr;
- if( !aRowArr.empty() )
- {
- rpSz = &const_cast<SwFormatRowSplit&>(aRowArr[0]->GetFrameFormat()->GetRowSplit());
+ std::vector<SwTableLine*> aRowArr; // For Lines collecting
+ ::lcl_CollectLines( aRowArr, rCursor, false );
- if (rpSz)
- {
- for ( auto pLn : aRowArr )
- {
- if ( (*rpSz).GetValue() != pLn->GetFrameFormat()->GetRowSplit().GetValue() )
- {
- rpSz = nullptr;
- break;
- }
- }
- }
- if ( rpSz )
- rpSz = new SwFormatRowSplit( *rpSz );
+ if( aRowArr.empty() )
+ return nullptr;
+
+ SwFormatRowSplit* pSz = &const_cast<SwFormatRowSplit&>(aRowArr[0]->GetFrameFormat()->GetRowSplit());
+
+ for ( auto pLn : aRowArr )
+ {
+ if ( pSz->GetValue() != pLn->GetFrameFormat()->GetRowSplit().GetValue() )
+ {
+ return nullptr;
}
}
+ return o3tl::make_unique<SwFormatRowSplit>( *pSz );
}
/* Class: SwDoc
@@ -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();
- if( pTableNd )
- {
- std::vector<SwTableLine*> aRowArr; // For Lines collecting
- ::lcl_CollectLines( aRowArr, rCursor, true );
+ if( !pTableNd )
+ return nullptr;
- if( !aRowArr.empty() )
- {
- rpSz = &const_cast<SwFormatFrameSize&>(aRowArr[0]->GetFrameFormat()->GetFrameSize());
+ std::vector<SwTableLine*> aRowArr; // For Lines collecting
+ ::lcl_CollectLines( aRowArr, rCursor, true );
- if (rpSz)
- {
- for ( auto pLn : aRowArr )
- {
- if ( *rpSz != pLn->GetFrameFormat()->GetFrameSize() )
- {
- rpSz = nullptr;
- break;
- }
- }
- }
- if ( rpSz )
- rpSz = new SwFormatFrameSize( *rpSz );
- }
+ if( aRowArr.empty() )
+ return nullptr;
+
+ SwFormatFrameSize* pSz = &const_cast<SwFormatFrameSize&>(aRowArr[0]->GetFrameFormat()->GetFrameSize());
+
+ for ( auto pLn : aRowArr )
+ {
+ if ( *pSz != pLn->GetFrameFormat()->GetFrameSize() )
+ return nullptr;
}
+ return o3tl::make_unique<SwFormatFrameSize>( *pSz );
}
bool SwDoc::BalanceRowHeight( const SwCursor& rCursor, bool bTstOnly, const bool bOptimize )
diff --git a/sw/source/core/frmedt/fetab.cxx b/sw/source/core/frmedt/fetab.cxx
index 61001866b042..5aa912204eac 100644
--- a/sw/source/core/frmedt/fetab.cxx
+++ b/sw/source/core/frmedt/fetab.cxx
@@ -63,7 +63,7 @@
#include <swerror.h>
#include <swundo.hxx>
#include <frmtool.hxx>
-
+#include <fmtrowsplt.hxx>
#include <node.hxx>
#include <sortedobjs.hxx>
@@ -718,9 +718,9 @@ void SwFEShell::SetRowSplit( const SwFormatRowSplit& rNew )
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 )
@@ -731,9 +731,9 @@ void SwFEShell::SetRowHeight( const SwFormatFrameSize &rNew )
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 )
diff --git a/sw/source/ui/table/rowht.cxx b/sw/source/ui/table/rowht.cxx
index 2a46f3e36629..066209e6389a 100644
--- a/sw/source/ui/table/rowht.cxx
+++ b/sw/source/ui/table/rowht.cxx
@@ -58,15 +58,12 @@ SwTableHeightDlg::SwTableHeightDlg(weld::Window *pParent, SwWrtShell &rS)
::SetFieldUnit(*m_xHeightEdit, eFieldUnit);
m_xHeightEdit->set_min(MINLAY, FieldUnit::TWIP);
- SwFormatFrameSize *pSz;
- m_rSh.GetRowHeight(pSz);
+ std::unique_ptr<SwFormatFrameSize> pSz = m_rSh.GetRowHeight();
if (pSz)
{
auto nHeight = pSz->GetHeight();
m_xAutoHeightCB->set_active(pSz->GetHeightSizeType() != ATT_FIX_SIZE);
m_xHeightEdit->set_value(m_xHeightEdit->normalize(nHeight), FieldUnit::TWIP);
-
- delete pSz;
}
}
diff --git a/sw/source/uibase/shells/tabsh.cxx b/sw/source/uibase/shells/tabsh.cxx
index b8da4958ede3..4b3c3dc78f41 100644
--- a/sw/source/uibase/shells/tabsh.cxx
+++ b/sw/source/uibase/shells/tabsh.cxx
@@ -203,12 +203,11 @@ static SwTableRep* lcl_TableParamToItemSet( SfxItemSet& rSet, SwWrtShell &rSh )
rSh.GetTabBorders( rSet );
//row split
- SwFormatRowSplit* pSplit = nullptr;
- rSh.GetRowSplit(pSplit);
+ std::unique_ptr<SwFormatRowSplit> pSplit = rSh.GetRowSplit();
if(pSplit)
{
rSet.Put(*pSplit);
- delete pSplit;
+ pSplit.reset();
}
if(!bTableSel)
@@ -1184,21 +1183,20 @@ void SwTableShell::Execute(SfxRequest &rReq)
case FN_TABLE_ROW_SPLIT :
{
const SfxBoolItem* pBool = static_cast<const SfxBoolItem*>(pItem);
- SwFormatRowSplit* pSplit = nullptr;
+ std::unique_ptr<SwFormatRowSplit> pSplit;
if(!pBool)
{
- rSh.GetRowSplit(pSplit);
+ pSplit = rSh.GetRowSplit();
if(pSplit)
pSplit->SetValue(!pSplit->GetValue());
else
- pSplit = new SwFormatRowSplit(true);
+ pSplit.reset(new SwFormatRowSplit(true));
}
else
{
- pSplit = new SwFormatRowSplit(pBool->GetValue());
+ pSplit.reset(new SwFormatRowSplit(pBool->GetValue()));
}
rSh.SetRowSplit( *pSplit );
- delete pSplit;
break;
}
@@ -1268,13 +1266,11 @@ void SwTableShell::GetState(SfxItemSet &rSet)
case SID_TABLE_MINIMAL_ROW_HEIGHT:
{
// Disable if auto height already is enabled.
- SwFormatFrameSize *pSz;
- rSh.GetRowHeight( pSz );
+ std::unique_ptr<SwFormatFrameSize> pSz = rSh.GetRowHeight();
if ( pSz )
{
if ( ATT_VAR_SIZE == pSz->GetHeightSizeType() )
rSet.DisableItem( nSlot );
- delete pSz;
}
break;
}
@@ -1365,13 +1361,11 @@ void SwTableShell::GetState(SfxItemSet &rSet)
}
else
{
- SwFormatRowSplit* pSplit = nullptr;
- rSh.GetRowSplit(pSplit);
+ std::unique_ptr<SwFormatRowSplit> pSplit = rSh.GetRowSplit();
if(pSplit)
rSet.Put(*pSplit);
else
rSet.InvalidateItem( nSlot );
- delete pSplit;
}
break;
}
diff --git a/sw/source/uibase/uiview/formatclipboard.cxx b/sw/source/uibase/uiview/formatclipboard.cxx
index 7ea583af5305..8585795b3d4d 100644
--- a/sw/source/uibase/uiview/formatclipboard.cxx
+++ b/sw/source/uibase/uiview/formatclipboard.cxx
@@ -139,8 +139,7 @@ void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh )
rSet.Put( pFrameFormat->GetFrameDir() );
}
- SwFormatRowSplit* pSplit = nullptr;
- rSh.GetRowSplit(pSplit);
+ std::unique_ptr<SwFormatRowSplit> pSplit = rSh.GetRowSplit();
if(pSplit)
rSet.Put(*pSplit);
}
More information about the Libreoffice-commits
mailing list