[Libreoffice-commits] core.git: sc/inc sc/source

Noel Grandin noel.grandin at collabora.co.uk
Tue Mar 13 12:25:17 UTC 2018


 sc/inc/attrib.hxx              |   12 ++++++------
 sc/source/core/data/attrib.cxx |   41 ++++++++++++++++-------------------------
 2 files changed, 22 insertions(+), 31 deletions(-)

New commits:
commit ebd9a6a6521859a465dbbe134e75ead45e1383c1
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Mar 13 12:25:33 2018 +0200

    loplugin:useuniqueptr in ScPageHFItem
    
    Change-Id: I430ee7ff6dc5357593b152f9fe0f73d4b69ccf6a
    Reviewed-on: https://gerrit.libreoffice.org/51204
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/inc/attrib.hxx b/sc/inc/attrib.hxx
index 24218eb8bdb4..628aae1167d1 100644
--- a/sc/inc/attrib.hxx
+++ b/sc/inc/attrib.hxx
@@ -161,9 +161,9 @@ public:
 
 class SC_DLLPUBLIC ScPageHFItem : public SfxPoolItem
 {
-    EditTextObject* pLeftArea;
-    EditTextObject* pCenterArea;
-    EditTextObject* pRightArea;
+    std::unique_ptr<EditTextObject> pLeftArea;
+    std::unique_ptr<EditTextObject> pCenterArea;
+    std::unique_ptr<EditTextObject> pRightArea;
 
 public:
                 ScPageHFItem( sal_uInt16 nWhich );
@@ -176,9 +176,9 @@ public:
     virtual bool            QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
     virtual bool            PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
 
-    const EditTextObject* GetLeftArea() const       { return pLeftArea; }
-    const EditTextObject* GetCenterArea() const     { return pCenterArea; }
-    const EditTextObject* GetRightArea() const      { return pRightArea; }
+    const EditTextObject* GetLeftArea() const       { return pLeftArea.get(); }
+    const EditTextObject* GetCenterArea() const     { return pCenterArea.get(); }
+    const EditTextObject* GetRightArea() const      { return pRightArea.get(); }
 
     void SetLeftArea( const EditTextObject& rNew );
     void SetCenterArea( const EditTextObject& rNew );
diff --git a/sc/source/core/data/attrib.cxx b/sc/source/core/data/attrib.cxx
index 29b1d92fd317..ee104e0cc08c 100644
--- a/sc/source/core/data/attrib.cxx
+++ b/sc/source/core/data/attrib.cxx
@@ -389,25 +389,22 @@ ScPageHFItem::ScPageHFItem( const ScPageHFItem& rItem )
         pRightArea  ( nullptr )
 {
     if ( rItem.pLeftArea )
-        pLeftArea = rItem.pLeftArea->Clone();
+        pLeftArea.reset(rItem.pLeftArea->Clone());
     if ( rItem.pCenterArea )
-        pCenterArea = rItem.pCenterArea->Clone();
+        pCenterArea.reset(rItem.pCenterArea->Clone());
     if ( rItem.pRightArea )
-        pRightArea = rItem.pRightArea->Clone();
+        pRightArea.reset(rItem.pRightArea->Clone());
 }
 
 ScPageHFItem::~ScPageHFItem()
 {
-    delete pLeftArea;
-    delete pCenterArea;
-    delete pRightArea;
 }
 
 bool ScPageHFItem::QueryValue( uno::Any& rVal, sal_uInt8 /* nMemberId */ ) const
 {
     rtl::Reference<ScHeaderFooterContentObj> xContent =
         new ScHeaderFooterContentObj();
-    xContent->Init(pLeftArea, pCenterArea, pRightArea);
+    xContent->Init(pLeftArea.get(), pCenterArea.get(), pRightArea.get());
 
     uno::Reference<sheet::XHeaderFooterContent> xCont(xContent.get());
 
@@ -428,27 +425,24 @@ bool ScPageHFItem::PutValue( const uno::Any& rVal, sal_uInt8 /* nMemberId */ )
             if (pImp.is())
             {
                 const EditTextObject* pImpLeft = pImp->GetLeftEditObject();
-                delete pLeftArea;
-                pLeftArea = pImpLeft ? pImpLeft->Clone() : nullptr;
+                pLeftArea.reset( pImpLeft ? pImpLeft->Clone() : nullptr );
 
                 const EditTextObject* pImpCenter = pImp->GetCenterEditObject();
-                delete pCenterArea;
-                pCenterArea = pImpCenter ? pImpCenter->Clone() : nullptr;
+                pCenterArea.reset( pImpCenter ? pImpCenter->Clone() : nullptr );
 
                 const EditTextObject* pImpRight = pImp->GetRightEditObject();
-                delete pRightArea;
-                pRightArea = pImpRight ? pImpRight->Clone() : nullptr;
+                pRightArea.reset( pImpRight ? pImpRight->Clone() : nullptr );
 
                 if ( !pLeftArea || !pCenterArea || !pRightArea )
                 {
                     // no Text with Null are left
                     ScEditEngineDefaulter aEngine( EditEngine::CreatePool(), true );
                     if (!pLeftArea)
-                        pLeftArea = aEngine.CreateTextObject();
+                        pLeftArea.reset( aEngine.CreateTextObject() );
                     if (!pCenterArea)
-                        pCenterArea = aEngine.CreateTextObject();
+                        pCenterArea.reset( aEngine.CreateTextObject() );
                     if (!pRightArea)
-                        pRightArea = aEngine.CreateTextObject();
+                        pRightArea.reset( aEngine.CreateTextObject() );
                 }
 
                 bRet = true;
@@ -470,9 +464,9 @@ bool ScPageHFItem::operator==( const SfxPoolItem& rItem ) const
 
     const ScPageHFItem& r = static_cast<const ScPageHFItem&>(rItem);
 
-    return    ScGlobal::EETextObjEqual(pLeftArea,   r.pLeftArea)
-           && ScGlobal::EETextObjEqual(pCenterArea, r.pCenterArea)
-           && ScGlobal::EETextObjEqual(pRightArea,  r.pRightArea);
+    return    ScGlobal::EETextObjEqual(pLeftArea.get(),   r.pLeftArea.get())
+           && ScGlobal::EETextObjEqual(pCenterArea.get(), r.pCenterArea.get())
+           && ScGlobal::EETextObjEqual(pRightArea.get(),  r.pRightArea.get());
 }
 
 SfxPoolItem* ScPageHFItem::Clone( SfxItemPool* ) const
@@ -482,20 +476,17 @@ SfxPoolItem* ScPageHFItem::Clone( SfxItemPool* ) const
 
 void ScPageHFItem::SetLeftArea( const EditTextObject& rNew )
 {
-    delete pLeftArea;
-    pLeftArea = rNew.Clone();
+    pLeftArea.reset( rNew.Clone() );
 }
 
 void ScPageHFItem::SetCenterArea( const EditTextObject& rNew )
 {
-    delete pCenterArea;
-    pCenterArea = rNew.Clone();
+    pCenterArea.reset( rNew.Clone() );
 }
 
 void ScPageHFItem::SetRightArea( const EditTextObject& rNew )
 {
-    delete pRightArea;
-    pRightArea = rNew.Clone();
+    pRightArea.reset( rNew.Clone() );
 }
 
 /**


More information about the Libreoffice-commits mailing list