summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorNoel <noelgrandin@gmail.com>2020-10-26 10:03:47 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-10-26 11:51:07 +0100
commitf49a6361ce4d7dc4efaca0b1701a3ca0e0702eb2 (patch)
tree40b6fe6056fc68ad9fd129cef6b5b450be5ef53c /sw
parent1629244a83092dc726276380115481283644986d (diff)
std::unique_ptr -> std::optional
Change-Id: Icf8168423af437fda88a6bd26679fecb699606e8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104795 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/swtable.hxx13
-rw-r--r--sw/source/core/table/swtable.cxx46
2 files changed, 19 insertions, 40 deletions
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 <vector>
#include <algorithm>
#include <o3tl/sorted_vector.hxx>
+#include <optional>
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<Color> mpUserColor;
- std::unique_ptr<Color> mpNumFormatColor;
+ std::optional<Color> mxUserColor;
+ std::optional<Color> 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<Color>& GetSaveUserColor() const { return mxUserColor; }
+ const std::optional<Color>& GetSaveNumFormatColor() const { return mxNumFormatColor; }
+ void SetSaveUserColor(std::optional<Color> p ) { mxUserColor = p; }
+ void SetSaveNumFormatColor( std::optional<Color> 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<const SvxColorItem*>(pItem)->GetValue() : nullptr;
+ const std::optional<Color>& pOldNumFormatColor = rBox.GetSaveNumFormatColor();
+ std::optional<Color> pNewUserColor;
+ if (pItem)
+ pNewUserColor = static_cast<const SvxColorItem*>(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<Color>() );
if( pCol )
// if needed, set the color
pTNd->SetAttr( SvxColorItem( *pCol, RES_CHRATR_COLOR ));
}
- rBox.SetSaveNumFormatColor( pCol );
+ rBox.SetSaveNumFormatColor( pCol ? *pCol : std::optional<Color>() );
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<const SvxColorItem*>(pItem)->GetValue() : nullptr;
+ const std::optional<Color>& pOldNumFormatColor = rBox.GetSaveNumFormatColor();
+ std::optional<Color> pNewUserColor;
+ if (pItem)
+ pNewUserColor = static_cast<const SvxColorItem*>(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<Color>() );
// assign vertical orientation
if( bChgAlign &&