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

Noel Grandin noel.grandin at collabora.co.uk
Fri Jun 29 09:42:59 UTC 2018


 sw/inc/docufld.hxx                       |    6 +++---
 sw/source/core/fields/docufld.cxx        |   18 +++++++-----------
 sw/source/core/unocore/unofield.cxx      |    4 ++--
 sw/source/filter/ww8/ww8graf.cxx         |    6 +++---
 sw/source/filter/ww8/ww8par.cxx          |    5 +++--
 sw/source/filter/ww8/ww8par.hxx          |    2 +-
 sw/source/uibase/docvw/AnnotationWin.cxx |    4 ++--
 7 files changed, 21 insertions(+), 24 deletions(-)

New commits:
commit ab1bba8de47aa0ca1ba49f1624358558400b2b26
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Jun 28 13:46:10 2018 +0200

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

diff --git a/sw/inc/docufld.hxx b/sw/inc/docufld.hxx
index 28dc230ce8fb..8afc0a1e425a 100644
--- a/sw/inc/docufld.hxx
+++ b/sw/inc/docufld.hxx
@@ -444,7 +444,7 @@ class SW_DLLPUBLIC SwPostItField : public SwField
     OUString m_sInitials; ///< Initials of the author.
     OUString m_sName;     ///< Name of the comment.
     DateTime    m_aDateTime;
-    OutlinerParaObject* mpText;
+    std::unique_ptr<OutlinerParaObject> mpText;
     rtl::Reference<SwTextAPIObject> m_xTextObject;
     sal_uInt32 m_nPostItId;
 
@@ -484,8 +484,8 @@ public:
     void                    SetName(const OUString& rStr);
     const OUString&         GetName() const { return m_sName;}
 
-    const OutlinerParaObject* GetTextObject() const { return mpText;}
-    void SetTextObject( OutlinerParaObject* pText );
+    const OutlinerParaObject* GetTextObject() const { return mpText.get();}
+    void SetTextObject( std::unique_ptr<OutlinerParaObject> pText );
 
     sal_Int32 GetNumberOfParagraphs() const;
 
diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx
index c89f26f4b2e0..051c5f06b457 100644
--- a/sw/source/core/fields/docufld.cxx
+++ b/sw/source/core/fields/docufld.cxx
@@ -34,6 +34,7 @@
 #include <com/sun/star/util/Date.hpp>
 #include <com/sun/star/util/Duration.hpp>
 #include <o3tl/any.hxx>
+#include <o3tl/make_unique.hxx>
 #include <unotools/localedatawrapper.hxx>
 #include <editeng/unolingu.hxx>
 #include <comphelper/processfactory.hxx>
@@ -1762,7 +1763,7 @@ SwPostItField::~SwPostItField()
         m_xTextObject->DisposeEditSource();
     }
 
-    delete mpText;
+    mpText.reset();
 }
 
 OUString SwPostItField::Expand() const
@@ -1780,7 +1781,7 @@ SwField* SwPostItField::Copy() const
     SwPostItField* pRet = new SwPostItField( static_cast<SwPostItFieldType*>(GetTyp()), m_sAuthor, m_sText, m_sInitials, m_sName,
                                              m_aDateTime, m_nPostItId);
     if (mpText)
-        pRet->SetTextObject( new OutlinerParaObject(*mpText) );
+        pRet->SetTextObject( o3tl::make_unique<OutlinerParaObject>(*mpText) );
 
     // Note: member <m_xTextObject> not copied.
 
@@ -1818,10 +1819,9 @@ void SwPostItField::SetName(const OUString& rName)
 }
 
 
-void SwPostItField::SetTextObject( OutlinerParaObject* pText )
+void SwPostItField::SetTextObject( std::unique_ptr<OutlinerParaObject> pText )
 {
-    delete mpText;
-    mpText = pText;
+    mpText = std::move(pText);
 }
 
 sal_Int32 SwPostItField::GetNumberOfParagraphs() const
@@ -1892,11 +1892,7 @@ bool SwPostItField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     case FIELD_PROP_PAR2:
         rAny >>= m_sText;
         //#i100374# new string via api, delete complex text object so SwPostItNote picks up the new string
-        if (mpText)
-        {
-            delete mpText;
-            mpText = nullptr;
-        }
+        mpText.reset();
         break;
     case FIELD_PROP_PAR3:
         rAny >>= m_sInitials;
@@ -1935,7 +1931,7 @@ void SwPostItField::dumpAsXml(xmlTextWriterPtr pWriter) const
     SwField::dumpAsXml(pWriter);
 
     xmlTextWriterStartElement(pWriter, BAD_CAST("mpText"));
-    xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", mpText);
+    xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", mpText.get());
     if (mpText)
         mpText->dumpAsXml(pWriter);
     xmlTextWriterEndElement(pWriter);
diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx
index b3e11d502d3a..00c8677a5136 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -20,7 +20,7 @@
 #include <config_features.h>
 
 #include <sal/config.h>
-
+#include <editeng/outlobj.hxx>
 #include <algorithm>
 #include <memory>
 
@@ -1354,7 +1354,7 @@ void SAL_CALL SwXTextField::attach(
                     aDateTime );
                 if ( m_pImpl->m_xTextObject.is() )
                 {
-                    pPostItField->SetTextObject( m_pImpl->m_xTextObject->CreateText() );
+                    pPostItField->SetTextObject( std::unique_ptr<OutlinerParaObject>(m_pImpl->m_xTextObject->CreateText()) );
                     pPostItField->SetPar2(m_pImpl->m_xTextObject->GetText());
                 }
                 xField.reset(pPostItField);
diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx
index 7a0ce8b9bb89..cca597c50413 100644
--- a/sw/source/filter/ww8/ww8graf.cxx
+++ b/sw/source/filter/ww8/ww8graf.cxx
@@ -952,9 +952,9 @@ void removePositions(EditEngine &rDrawEditEngine, const std::vector<sal_Int32>&
     }
 }
 
-OutlinerParaObject* SwWW8ImplReader::ImportAsOutliner(OUString &rString, WW8_CP nStartCp, WW8_CP nEndCp, ManTypes eType)
+std::unique_ptr<OutlinerParaObject> SwWW8ImplReader::ImportAsOutliner(OUString &rString, WW8_CP nStartCp, WW8_CP nEndCp, ManTypes eType)
 {
-    OutlinerParaObject* pRet = nullptr;
+    std::unique_ptr<OutlinerParaObject> pRet;
 
     sal_Int32 nLen = GetRangeAsDrawingString(rString, nStartCp, nEndCp, eType);
     if (nLen > 0)
@@ -984,7 +984,7 @@ OutlinerParaObject* SwWW8ImplReader::ImportAsOutliner(OUString &rString, WW8_CP
         }
 
         std::unique_ptr<EditTextObject> pTemporaryText = m_pDrawEditEngine->CreateTextObject();
-        pRet = new OutlinerParaObject(*pTemporaryText);
+        pRet.reset( new OutlinerParaObject(*pTemporaryText) );
         pRet->SetOutlinerMode( OutlinerMode::TextObject );
         pTemporaryText.reset();
 
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 7860245bd411..f5c723f2d30e 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -41,6 +41,7 @@
 #include <comphelper/docpasswordrequest.hxx>
 #include <comphelper/propertysequence.hxx>
 
+#include <editeng/outlobj.hxx>
 #include <editeng/brushitem.hxx>
 #include <editeng/tstpitem.hxx>
 #include <editeng/ulspitem.hxx>
@@ -2119,14 +2120,14 @@ long SwWW8ImplReader::Read_And(WW8PLCFManResult* pRes)
     DateTime aDate = msfilter::util::DTTM2DateTime(nDateTime);
 
     OUString sText;
-    OutlinerParaObject *pOutliner = ImportAsOutliner( sText, pRes->nCp2OrIdx,
+    std::unique_ptr<OutlinerParaObject> pOutliner = ImportAsOutliner( sText, pRes->nCp2OrIdx,
         pRes->nCp2OrIdx + pRes->nMemLen, MAN_AND );
 
     m_pFormatOfJustInsertedApo = nullptr;
     SwPostItField aPostIt(
         static_cast<SwPostItFieldType*>(m_rDoc.getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::Postit)), sAuthor,
         sText, sInitials, OUString(), aDate );
-    aPostIt.SetTextObject(pOutliner);
+    aPostIt.SetTextObject(std::move(pOutliner));
 
     SwPaM aEnd(*m_pPaM->End(), *m_pPaM->End());
     m_xCtrlStck->NewAttr(*aEnd.GetPoint(), SvxCharHiddenItem(false, RES_CHRATR_HIDDEN));
diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx
index 289303da11c1..c50e9c6484af 100644
--- a/sw/source/filter/ww8/ww8par.hxx
+++ b/sw/source/filter/ww8/ww8par.hxx
@@ -1578,7 +1578,7 @@ private:
     bool GetTxbxTextSttEndCp(WW8_CP& rStartCp, WW8_CP& rEndCp, sal_uInt16 nTxBxS,
         sal_uInt16 nSequence);
     sal_Int32 GetRangeAsDrawingString(OUString& rString, long StartCp, long nEndCp, ManTypes eType);
-    OutlinerParaObject* ImportAsOutliner(OUString &rString, WW8_CP nStartCp, WW8_CP nEndCp, ManTypes eType);
+    std::unique_ptr<OutlinerParaObject> ImportAsOutliner(OUString &rString, WW8_CP nStartCp, WW8_CP nEndCp, ManTypes eType);
     void InsertTxbxText(SdrTextObj* pTextObj, Size const * pObjSiz,
         sal_uInt16 nTxBxS, sal_uInt16 nSequence, long nPosCp, SwFrameFormat const * pFlyFormat,
         bool bMakeSdrGrafObj, bool& rbEraseTextObj,
diff --git a/sw/source/uibase/docvw/AnnotationWin.cxx b/sw/source/uibase/docvw/AnnotationWin.cxx
index 7fef02cdf522..4b641a57dfa9 100644
--- a/sw/source/uibase/docvw/AnnotationWin.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin.cxx
@@ -241,7 +241,7 @@ void SwAnnotationWin::UpdateData()
             pOldField.reset(mpField->Copy());
         }
         mpField->SetPar2(mpOutliner->GetEditEngine().GetText());
-        mpField->SetTextObject(mpOutliner->CreateParaObject());
+        mpField->SetTextObject(std::unique_ptr<OutlinerParaObject>(mpOutliner->CreateParaObject()));
         if (rUndoRedo.DoesUndo())
         {
             SwTextField *const pTextField = mpFormatField->GetTextField();
@@ -404,7 +404,7 @@ void SwAnnotationWin::InitAnswer(OutlinerParaObject const * pText)
         pOldField.reset(mpField->Copy());
     }
     mpField->SetPar2(mpOutliner->GetEditEngine().GetText());
-    mpField->SetTextObject(mpOutliner->CreateParaObject());
+    mpField->SetTextObject(std::unique_ptr<OutlinerParaObject>(mpOutliner->CreateParaObject()));
     if (rUndoRedo.DoesUndo())
     {
         SwTextField *const pTextField = mpFormatField->GetTextField();


More information about the Libreoffice-commits mailing list