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

Noel Grandin noel.grandin at collabora.co.uk
Thu Mar 15 13:21:56 UTC 2018


 sd/inc/sdmod.hxx                   |   10 +++++-----
 sd/source/ui/app/sdmod.cxx         |   21 ++++++++++++---------
 sd/source/ui/docshell/docshel3.cxx |   12 ++----------
 3 files changed, 19 insertions(+), 24 deletions(-)

New commits:
commit a98465920f0c82759d3e74b437c4fb4dd9f2c4c6
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Mar 15 10:54:44 2018 +0200

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

diff --git a/sd/inc/sdmod.hxx b/sd/inc/sdmod.hxx
index 409745422ddf..1c5e3848711a 100644
--- a/sd/inc/sdmod.hxx
+++ b/sd/inc/sdmod.hxx
@@ -96,8 +96,8 @@ public:
     bool                    GetWaterCan() const { return bWaterCan; }
     void                    SetWaterCan( bool bWC ) { bWaterCan = bWC; }
 
-    SvxSearchItem*          GetSearchItem() { return pSearchItem; }
-    void                    SetSearchItem(SvxSearchItem* pItem) { pSearchItem = pItem; }
+    SvxSearchItem*          GetSearchItem() { return pSearchItem.get(); }
+    void                    SetSearchItem(std::unique_ptr<SvxSearchItem> pItem);
 
     /** Return the virtual device that can be used for printer independent
         layout.
@@ -125,11 +125,11 @@ private:
 
     SdOptions*              pImpressOptions;
     SdOptions*              pDrawOptions;
-    SvxSearchItem*          pSearchItem;
-    SvNumberFormatter*      pNumberFormatter;
+    std::unique_ptr<SvxSearchItem>      pSearchItem;
+    std::unique_ptr<SvNumberFormatter>  pNumberFormatter;
     tools::SvRef<SotStorage>            xOptionStorage;
     bool                    bWaterCan;
-    SfxErrorHandler*        mpErrorHdl;
+    std::unique_ptr<SfxErrorHandler> mpErrorHdl;
     /** This device is used for printer independent layout.  It is virtual
         in the sense that it does not represent a printer.  The pointer may
         be NULL when the virtual device could not be created.
diff --git a/sd/source/ui/app/sdmod.cxx b/sd/source/ui/app/sdmod.cxx
index d442e6c50357..c519302a8fa5 100644
--- a/sd/source/ui/app/sdmod.cxx
+++ b/sd/source/ui/app/sdmod.cxx
@@ -71,18 +71,16 @@ SdModule::SdModule(SfxObjectFactory* pFact1, SfxObjectFactory* pFact2 )
     pTransferSelection(nullptr),
     pImpressOptions(nullptr),
     pDrawOptions(nullptr),
-    pSearchItem(nullptr),
-    pNumberFormatter( nullptr ),
     bWaterCan(false),
     mbEventListenerAdded(false),
     mpColorConfig(new svtools::ColorConfig)
 {
     SetName( "StarDraw" );  // Do not translate!
-    pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM);
+    pSearchItem.reset( new SvxSearchItem(SID_SEARCH_ITEM) );
     pSearchItem->SetAppFlag(SvxSearchApp::DRAW);
     StartListening( *SfxGetpApp() );
     SvxErrorHandler::ensure();
-    mpErrorHdl = new SfxErrorHandler(RID_SD_ERRHDL, ErrCodeArea::Sd, ErrCodeArea::Sd, GetResLocale());
+    mpErrorHdl.reset( new SfxErrorHandler(RID_SD_ERRHDL, ErrCodeArea::Sd, ErrCodeArea::Sd, GetResLocale()) );
 
     // Create a new ref device and (by calling SetReferenceDevice())
     // set its resolution to 600 DPI.  This leads to a visually better
@@ -100,18 +98,23 @@ OUString SdResId(const char* pId)
 // Dtor
 SdModule::~SdModule()
 {
-    delete pSearchItem;
-    delete pNumberFormatter;
+    pSearchItem.reset();
+    pNumberFormatter.reset();
 
     if (mbEventListenerAdded)
     {
         Application::RemoveEventListener( LINK( this, SdModule, EventListenerHdl ) );
     }
 
-    delete mpErrorHdl;
+    mpErrorHdl.reset();
     mpVirtualRefDevice.disposeAndClear();
 }
 
+void SdModule::SetSearchItem(std::unique_ptr<SvxSearchItem> pItem)
+{
+    pSearchItem = std::move(pItem);
+}
+
 /// get notifications
 void SdModule::Notify( SfxBroadcaster&, const SfxHint& rHint )
 {
@@ -205,9 +208,9 @@ tools::SvRef<SotStorageStream> SdModule::GetOptionStream( const OUString& rOptio
 SvNumberFormatter* SdModule::GetNumberFormatter()
 {
     if( !pNumberFormatter )
-        pNumberFormatter = new SvNumberFormatter( ::comphelper::getProcessComponentContext(), LANGUAGE_SYSTEM );
+        pNumberFormatter.reset( new SvNumberFormatter( ::comphelper::getProcessComponentContext(), LANGUAGE_SYSTEM ) );
 
-    return pNumberFormatter;
+    return pNumberFormatter.get();
 }
 
 svtools::ColorConfig& SdModule::GetColorConfig()
diff --git a/sd/source/ui/docshell/docshel3.cxx b/sd/source/ui/docshell/docshel3.cxx
index e65d0729b009..c49841bcb969 100644
--- a/sd/source/ui/docshell/docshel3.cxx
+++ b/sd/source/ui/docshell/docshel3.cxx
@@ -147,11 +147,7 @@ void DrawDocShell::Execute( SfxRequest& rReq )
             {
                 const SvxSearchItem* pSearchItem = static_cast<const SvxSearchItem*>( &pReqArgs->Get(SID_SEARCH_ITEM) );
 
-                // would be nice to have an assign operation at SearchItem
-                SvxSearchItem* pAppSearchItem = SD_MOD()->GetSearchItem();
-                delete pAppSearchItem;
-                pAppSearchItem = static_cast<SvxSearchItem*>( pSearchItem->Clone() );
-                SD_MOD()->SetSearchItem(pAppSearchItem);
+                SD_MOD()->SetSearchItem(std::unique_ptr<SvxSearchItem>(static_cast<SvxSearchItem*>(pSearchItem->Clone())));
             }
 
             rReq.Done();
@@ -215,11 +211,7 @@ void DrawDocShell::Execute( SfxRequest& rReq )
                     const SvxSearchItem* pSearchItem =
                         static_cast<const SvxSearchItem*>( &pReqArgs->Get(SID_SEARCH_ITEM) );
 
-                    // would be nice to have an assign operation at SearchItem
-                    SvxSearchItem* pAppSearchItem = SD_MOD()->GetSearchItem();
-                    delete pAppSearchItem;
-                    pAppSearchItem = static_cast<SvxSearchItem*>( pSearchItem->Clone() );
-                    SD_MOD()->SetSearchItem(pAppSearchItem);
+                    SD_MOD()->SetSearchItem(std::unique_ptr<SvxSearchItem>(static_cast<SvxSearchItem*>( pSearchItem->Clone() )));
                     xFuSearch->SearchAndReplace(pSearchItem);
                 }
             }


More information about the Libreoffice-commits mailing list