From f49a6361ce4d7dc4efaca0b1701a3ca0e0702eb2 Mon Sep 17 00:00:00 2001 From: Noel Date: Mon, 26 Oct 2020 10:03:47 +0200 Subject: std::unique_ptr -> std::optional Change-Id: Icf8168423af437fda88a6bd26679fecb699606e8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104795 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sw/inc/swtable.hxx | 13 ++++++------ sw/source/core/table/swtable.cxx | 46 +++++++++++----------------------------- 2 files changed, 19 insertions(+), 40 deletions(-) (limited to 'sw') diff --git a/sw/inc/swtable.hxx b/sw/inc/swtable.hxx index a101cfeeb85e..d878478f8978 100644 --- a/sw/inc/swtable.hxx +++ b/sw/inc/swtable.hxx @@ -31,6 +31,7 @@ #include #include #include +#include class SwStartNode; class SwFormat; @@ -402,8 +403,8 @@ class SW_DLLPUBLIC SwTableBox: public SwClient //Client of FrameFormat. const SwStartNode * m_pStartNode; SwTableLine *m_pUpper; - std::unique_ptr mpUserColor; - std::unique_ptr mpNumFormatColor; + std::optional mxUserColor; + std::optional mxNumFormatColor; tools::Long mnRowSpan; bool mbDummyFlag; @@ -478,10 +479,10 @@ public: void ActualiseValueBox(); // Access on internal data - currently used for the NumFormatter. - inline const Color* GetSaveUserColor() const; - inline const Color* GetSaveNumFormatColor() const; - inline void SetSaveUserColor(const Color* p ); - inline void SetSaveNumFormatColor( const Color* p ); + const std::optional& GetSaveUserColor() const { return mxUserColor; } + const std::optional& GetSaveNumFormatColor() const { return mxNumFormatColor; } + void SetSaveUserColor(std::optional p ) { mxUserColor = p; } + void SetSaveNumFormatColor( std::optional p ) { mxNumFormatColor = p; } tools::Long getRowSpan() const; void setRowSpan( tools::Long nNewRowSpan ); diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx index 003dd062aaaf..c78c9ffdea89 100644 --- a/sw/source/core/table/swtable.cxx +++ b/sw/source/core/table/swtable.cxx @@ -71,32 +71,6 @@ using namespace com::sun::star; static void ChgTextToNum( SwTableBox& rBox, const OUString& rText, const Color* pCol, bool bChgAlign, sal_uLong nNdPos ); -inline const Color* SwTableBox::GetSaveUserColor() const -{ - return mpUserColor.get(); -} - -inline const Color* SwTableBox::GetSaveNumFormatColor() const -{ - return mpNumFormatColor.get(); -} - -inline void SwTableBox::SetSaveUserColor(const Color* p ) -{ - if (p) - mpUserColor.reset(new Color(*p)); - else - mpUserColor.reset(); -} - -inline void SwTableBox::SetSaveNumFormatColor( const Color* p ) -{ - if (p) - mpNumFormatColor.reset(new Color(*p)); - else - mpNumFormatColor.reset(); -} - tools::Long SwTableBox::getRowSpan() const { return mnRowSpan; @@ -1990,8 +1964,10 @@ void ChgTextToNum( SwTableBox& rBox, const OUString& rText, const Color* pCol, GetItemState( RES_CHRATR_COLOR, false, &pItem )) pItem = nullptr; - const Color* pOldNumFormatColor = rBox.GetSaveNumFormatColor(); - const Color* pNewUserColor = pItem ? &static_cast(pItem)->GetValue() : nullptr; + const std::optional& pOldNumFormatColor = rBox.GetSaveNumFormatColor(); + std::optional pNewUserColor; + if (pItem) + pNewUserColor = static_cast(pItem)->GetValue(); if( ( pNewUserColor && pOldNumFormatColor && *pNewUserColor == *pOldNumFormatColor ) || @@ -2013,14 +1989,14 @@ void ChgTextToNum( SwTableBox& rBox, const OUString& rText, const Color* pCol, else { // Save user color, set NumFormat color if needed, but never reset the color - rBox.SetSaveUserColor( pNewUserColor ); + rBox.SetSaveUserColor( pNewUserColor ? *pNewUserColor : std::optional() ); if( pCol ) // if needed, set the color pTNd->SetAttr( SvxColorItem( *pCol, RES_CHRATR_COLOR )); } - rBox.SetSaveNumFormatColor( pCol ); + rBox.SetSaveNumFormatColor( pCol ? *pCol : std::optional() ); if( pTNd->GetText() != rText ) { @@ -2098,7 +2074,7 @@ static void ChgNumToText( SwTableBox& rBox, sal_uLong nFormat ) bool bChgAlign = pDoc->IsInsTableAlignNum(); const SfxPoolItem* pItem; - const Color* pCol = nullptr; + const Color * pCol = nullptr; if( getSwDefaultTextFormat() != nFormat ) { // special text format: @@ -2132,8 +2108,10 @@ static void ChgNumToText( SwTableBox& rBox, sal_uLong nFormat ) GetItemState( RES_CHRATR_COLOR, false, &pItem )) pItem = nullptr; - const Color* pOldNumFormatColor = rBox.GetSaveNumFormatColor(); - const Color* pNewUserColor = pItem ? &static_cast(pItem)->GetValue() : nullptr; + const std::optional& pOldNumFormatColor = rBox.GetSaveNumFormatColor(); + std::optional pNewUserColor; + if (pItem) + pNewUserColor = static_cast(pItem)->GetValue(); if( ( pNewUserColor && pOldNumFormatColor && *pNewUserColor == *pOldNumFormatColor ) || @@ -2162,7 +2140,7 @@ static void ChgNumToText( SwTableBox& rBox, sal_uLong nFormat ) pTNd->SetAttr( SvxColorItem( *pCol, RES_CHRATR_COLOR )); } - rBox.SetSaveNumFormatColor( pCol ); + rBox.SetSaveNumFormatColor( pCol ? *pCol : std::optional() ); // assign vertical orientation if( bChgAlign && -- cgit