[Libreoffice-commits] core.git: cui/source include/svtools svtools/source

Noel Grandin noel.grandin at collabora.co.uk
Thu Apr 12 06:46:12 UTC 2018


 cui/source/tabpages/chardlg.cxx     |   26 ++++----------------------
 include/svtools/ctrltool.hxx        |    2 +-
 svtools/source/control/ctrltool.cxx |    5 ++---
 3 files changed, 7 insertions(+), 26 deletions(-)

New commits:
commit d1ae2387c729ac8a0e616c57075174eb0d06d389
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Apr 11 12:09:57 2018 +0200

    make FontList::Clone return a std::unique_ptr
    
    and simplify the logic in SvxCharNamePage
    
    Change-Id: Ic1b379bb83203aa1ebf47b44d944c83a02c04224
    Reviewed-on: https://gerrit.libreoffice.org/52744
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/cui/source/tabpages/chardlg.cxx b/cui/source/tabpages/chardlg.cxx
index 08bababd9bbf..1d06dae5cb04 100644
--- a/cui/source/tabpages/chardlg.cxx
+++ b/cui/source/tabpages/chardlg.cxx
@@ -223,27 +223,17 @@ struct SvxCharNamePage_Impl
 {
     Idle            m_aUpdateIdle;
     OUString        m_aNoStyleText;
-    const FontList* m_pFontList;
+    std::unique_ptr<FontList> m_pFontList;
     sal_Int32           m_nExtraEntryPos;
-    bool            m_bMustDelete;
     bool            m_bInSearchMode;
 
     SvxCharNamePage_Impl() :
-
-        m_pFontList     ( nullptr ),
         m_nExtraEntryPos( COMBOBOX_ENTRY_NOTFOUND ),
-        m_bMustDelete   ( false ),
         m_bInSearchMode ( false )
 
     {
         m_aUpdateIdle.SetPriority( TaskPriority::LOWEST );
     }
-
-    ~SvxCharNamePage_Impl()
-    {
-        if ( m_bMustDelete )
-            delete m_pFontList;
-    }
 };
 
 // class SvxCharNamePage -------------------------------------------------
@@ -435,19 +425,16 @@ const FontList* SvxCharNamePage::GetFontList() const
             {
                 DBG_ASSERT(nullptr != static_cast<const SvxFontListItem*>(pItem)->GetFontList(),
                            "Where is the font list?");
-                    m_pImpl->m_pFontList =  static_cast<const SvxFontListItem*>(pItem )->GetFontList()->Clone();
-                m_pImpl->m_bMustDelete = true;
+                    m_pImpl->m_pFontList = static_cast<const SvxFontListItem*>(pItem )->GetFontList()->Clone();
             }
         }
         if(!m_pImpl->m_pFontList)
         {
-            m_pImpl->m_pFontList =
-                new FontList( Application::GetDefaultDevice() );
-            m_pImpl->m_bMustDelete = true;
+            m_pImpl->m_pFontList.reset(new FontList( Application::GetDefaultDevice() ));
         }
     }
 
-    return m_pImpl->m_pFontList;
+    return m_pImpl->m_pFontList.get();
 }
 
 
@@ -1228,12 +1215,7 @@ bool SvxCharNamePage::FillItemSet( SfxItemSet* rSet )
 
 void SvxCharNamePage::SetFontList( const SvxFontListItem& rItem )
 {
-    if ( m_pImpl->m_bMustDelete )
-    {
-        delete m_pImpl->m_pFontList;
-    }
     m_pImpl->m_pFontList = rItem.GetFontList()->Clone();
-    m_pImpl->m_bMustDelete = true;
 }
 
 
diff --git a/include/svtools/ctrltool.hxx b/include/svtools/ctrltool.hxx
index 4c642df4be47..da7be4b3c770 100644
--- a/include/svtools/ctrltool.hxx
+++ b/include/svtools/ctrltool.hxx
@@ -159,7 +159,7 @@ public:
                                       OutputDevice* pDevice2 = nullptr);
                             ~FontList();
 
-    FontList*               Clone() const;
+    std::unique_ptr<FontList> Clone() const;
 
     OUString                GetFontMapText( const FontMetric& rFontMetric ) const;
 
diff --git a/svtools/source/control/ctrltool.cxx b/svtools/source/control/ctrltool.cxx
index ad0e038dacc9..993a0ffb8b30 100644
--- a/svtools/source/control/ctrltool.cxx
+++ b/svtools/source/control/ctrltool.cxx
@@ -381,10 +381,9 @@ FontList::~FontList()
     }
 }
 
-FontList* FontList::Clone() const
+std::unique_ptr<FontList> FontList::Clone() const
 {
-    FontList* pReturn = new FontList(mpDev, mpDev2);
-    return pReturn;
+    return std::unique_ptr<FontList>(new FontList(mpDev, mpDev2));
 }
 
 const OUString& FontList::GetStyleName(FontWeight eWeight, FontItalic eItalic) const


More information about the Libreoffice-commits mailing list