[Libreoffice-commits] core.git: 2 commits - include/svtools include/xmloff svtools/source xmloff/qa xmloff/source

Noel Grandin noel.grandin at collabora.co.uk
Mon Apr 30 06:39:27 UTC 2018


 include/svtools/svtabbx.hxx       |    9 +++---
 include/xmloff/txtparae.hxx       |    2 -
 svtools/source/contnr/svtabbx.cxx |   50 +++++++++++++++-----------------------
 xmloff/qa/unit/uxmloff.cxx        |    8 +++---
 xmloff/source/text/txtparae.cxx   |    7 ++---
 5 files changed, 32 insertions(+), 44 deletions(-)

New commits:
commit 39c7e09ca5cb9b6dab143483bd6cb72fcad8307e
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Apr 25 12:37:18 2018 +0200

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

diff --git a/include/svtools/svtabbx.hxx b/include/svtools/svtabbx.hxx
index 6f9a44e54246..3fba520202ec 100644
--- a/include/svtools/svtabbx.hxx
+++ b/include/svtools/svtabbx.hxx
@@ -47,8 +47,7 @@ struct TabListBoxEventData
 class SVT_DLLPUBLIC SvTabListBox : public SvTreeListBox
 {
 private:
-    SvLBoxTab*                  pTabList;
-    sal_uInt16                  nTabCount;
+    std::vector<SvLBoxTab>      mvTabList;
     OUString                    aCurEntry;
 
 protected:
@@ -66,7 +65,7 @@ public:
     virtual ~SvTabListBox() override;
     virtual void dispose() override;
     void            SetTabs(sal_uInt16 nTabs, long const pTabPositions[], MapUnit = MapUnit::MapAppFont);
-    sal_uInt16      TabCount() const { return nTabCount; }
+    sal_uInt16      TabCount() const { return mvTabList.size(); }
     using SvTreeListBox::GetTab;
     long            GetTab( sal_uInt16 nTab ) const;
     void            SetTab( sal_uInt16 nTab, long nValue, MapUnit = MapUnit::MapAppFont );
@@ -108,8 +107,8 @@ public:
 
 inline long SvTabListBox::GetTab( sal_uInt16 nTab ) const
 {
-    DBG_ASSERT( nTab < nTabCount, "GetTabPos:Invalid Tab" );
-    return pTabList[nTab].GetPos();
+    DBG_ASSERT( nTab < mvTabList.size(), "GetTabPos:Invalid Tab" );
+    return mvTabList[nTab].GetPos();
 }
 
 // class SvHeaderTabListBox ---------------------------------------------------
diff --git a/svtools/source/contnr/svtabbx.cxx b/svtools/source/contnr/svtabbx.cxx
index 6d6b9c1528d7..f1106d6e220b 100644
--- a/svtools/source/contnr/svtabbx.cxx
+++ b/svtools/source/contnr/svtabbx.cxx
@@ -40,10 +40,10 @@ using namespace ::com::sun::star::accessibility;
 void SvTabListBox::SetTabs()
 {
     SvTreeListBox::SetTabs();
-    if( !nTabCount )
+    if( mvTabList.empty() )
         return;
 
-    DBG_ASSERT(pTabList,"TabList ?");
+    DBG_ASSERT(!mvTabList.empty(),"TabList ?");
 
     // The tree listbox has now inserted its tabs into the list. Now we
     // fluff up the list with additional tabs and adjust the rightmost tab
@@ -66,10 +66,10 @@ void SvTabListBox::SetTabs()
     */
 
     // append all other tabs to the list
-    for( sal_uInt16 nCurTab = 1; nCurTab < nTabCount; nCurTab++ )
+    for( sal_uInt16 nCurTab = 1; nCurTab < sal_uInt16(mvTabList.size()); nCurTab++ )
     {
-        SvLBoxTab* pTab = pTabList+nCurTab;
-        AddTab( pTab->GetPos(), pTab->nFlags );
+        SvLBoxTab& rTab = mvTabList[nCurTab];
+        AddTab( rTab.GetPos(), rTab.nFlags );
     }
 }
 
@@ -80,7 +80,7 @@ void SvTabListBox::InitEntry(SvTreeListEntry* pEntry, const OUString& rStr,
 
     sal_Int32 nIndex = 0;
     // TODO: verify if nTabCount is always >0 here!
-    const sal_uInt16 nCount = nTabCount - 1;
+    const sal_uInt16 nCount = mvTabList.size() - 1;
     for( sal_uInt16 nToken = 0; nToken < nCount; nToken++ )
     {
         const OUString aToken = GetToken(aCurEntry, nIndex);
@@ -90,8 +90,6 @@ void SvTabListBox::InitEntry(SvTreeListEntry* pEntry, const OUString& rStr,
 SvTabListBox::SvTabListBox( vcl::Window* pParent, WinBits nBits )
     : SvTreeListBox( pParent, nBits )
 {
-    pTabList = nullptr;
-    nTabCount = 0;
     SetHighlightRange();    // select full width
 }
 
@@ -104,32 +102,24 @@ SvTabListBox::~SvTabListBox()
 
 void SvTabListBox::dispose()
 {
-    // delete array
-    delete [] pTabList;
-#ifdef DBG_UTIL
-    pTabList = nullptr;
-    nTabCount = 0;
-#endif
+    mvTabList.clear();
     SvTreeListBox::dispose();
 }
 
 void SvTabListBox::SetTabs(sal_uInt16 nTabs, long const pTabPositions[], MapUnit eMapUnit)
 {
-    delete [] pTabList;
-    sal_uInt16 nCount = nTabs;
-    pTabList = new SvLBoxTab[ nCount ];
-    nTabCount = nCount;
+    mvTabList.resize(nTabs);
 
     MapMode aMMSource( eMapUnit );
     MapMode aMMDest( MapUnit::MapPixel );
 
-    for( sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++, pTabPositions++ )
+    for( sal_uInt16 nIdx = 0; nIdx < sal_uInt16(mvTabList.size()); nIdx++, pTabPositions++ )
     {
         Size aSize( *pTabPositions, 0 );
         aSize = LogicToLogic( aSize, &aMMSource, &aMMDest );
         long nNewTab = aSize.Width();
-        pTabList[nIdx].SetPos( nNewTab );
-        pTabList[nIdx].nFlags=(SvLBoxTabFlags::ADJUST_LEFT| SvLBoxTabFlags::INV_ALWAYS);
+        mvTabList[nIdx].SetPos( nNewTab );
+        mvTabList[nIdx].nFlags=(SvLBoxTabFlags::ADJUST_LEFT| SvLBoxTabFlags::INV_ALWAYS);
     }
     SvTreeListBox::nTreeFlags |= SvTreeFlags::RECALCTABS;
     if( IsUpdateMode() )
@@ -138,17 +128,16 @@ void SvTabListBox::SetTabs(sal_uInt16 nTabs, long const pTabPositions[], MapUnit
 
 void SvTabListBox::SetTab( sal_uInt16 nTab,long nValue,MapUnit eMapUnit )
 {
-    DBG_ASSERT(nTab<nTabCount,"Invalid Tab-Pos");
-    if( nTab >= nTabCount )
+    DBG_ASSERT(nTab<mvTabList.size(),"Invalid Tab-Pos");
+    if( nTab >= mvTabList.size() )
         return;
 
-    DBG_ASSERT(pTabList,"TabList?");
     MapMode aMMSource( eMapUnit );
     MapMode aMMDest( MapUnit::MapPixel );
     Size aSize( nValue, 0 );
     aSize = LogicToLogic( aSize, &aMMSource, &aMMDest );
     nValue = aSize.Width();
-    pTabList[ nTab ].SetPos( nValue );
+    mvTabList[ nTab ].SetPos( nValue );
     SvTreeListBox::nTreeFlags |= SvTreeFlags::RECALCTABS;
     if( IsUpdateMode() )
         Invalidate();
@@ -454,13 +443,14 @@ SvTreeListEntry* SvTabListBox::GetChildOnPos( SvTreeListEntry* _pParent, sal_uLo
 
 void SvTabListBox::SetTabJustify( sal_uInt16 nTab, SvTabJustify eJustify)
 {
-    if( nTab >= nTabCount )
+    DBG_ASSERT(nTab<mvTabList.size(),"GetTabPos:Invalid Tab");
+    if( nTab >= mvTabList.size() )
         return;
-    SvLBoxTab* pTab = &(pTabList[ nTab ]);
-    SvLBoxTabFlags nFlags = pTab->nFlags;
+    SvLBoxTab& rTab = mvTabList[ nTab ];
+    SvLBoxTabFlags nFlags = rTab.nFlags;
     nFlags &= (~MYTABMASK);
     nFlags |= static_cast<SvLBoxTabFlags>(eJustify);
-    pTab->nFlags = nFlags;
+    rTab.nFlags = nFlags;
     SvTreeListBox::nTreeFlags |= SvTreeFlags::RECALCTABS;
     if( IsUpdateMode() )
         Invalidate();
@@ -471,7 +461,7 @@ long SvTabListBox::GetLogicTab( sal_uInt16 nTab )
     if( SvTreeListBox::nTreeFlags & SvTreeFlags::RECALCTABS )
         SetTabs();
 
-    DBG_ASSERT(nTab<nTabCount,"GetTabPos:Invalid Tab");
+    DBG_ASSERT(nTab<mvTabList.size(),"GetTabPos:Invalid Tab");
     return aTabs[ nTab ]->GetPos();
 }
 
commit b0631cc1454d99cbaa948e54c3b0c246bd27bf1c
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Apr 25 10:52:46 2018 +0200

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

diff --git a/include/xmloff/txtparae.hxx b/include/xmloff/txtparae.hxx
index 9c3d27e3dd33..8fb299cae511 100644
--- a/include/xmloff/txtparae.hxx
+++ b/include/xmloff/txtparae.hxx
@@ -109,7 +109,7 @@ class XMLOFF_DLLPUBLIC XMLTextParagraphExport : public XMLStyleExport
     bool                        bOpenRuby;
 
     XMLTextListsHelper* mpTextListsHelper;
-    ::std::vector< XMLTextListsHelper* > maTextListsHelperStack;
+    ::std::vector< std::unique_ptr<XMLTextListsHelper> > maTextListsHelperStack;
 
     enum class FrameType { Text, Graphic, Embedded, Shape };
 public:
diff --git a/xmloff/qa/unit/uxmloff.cxx b/xmloff/qa/unit/uxmloff.cxx
index 71a1b371f006..c2460dc496d5 100644
--- a/xmloff/qa/unit/uxmloff.cxx
+++ b/xmloff/qa/unit/uxmloff.cxx
@@ -43,7 +43,7 @@ public:
     CPPUNIT_TEST(testMetaGenerator);
     CPPUNIT_TEST_SUITE_END();
 private:
-    SvXMLExport *pExport;
+    std::unique_ptr<SvXMLExport> pExport;
 };
 
 Test::Test()
@@ -55,14 +55,14 @@ void Test::setUp()
 {
     BootstrapFixture::setUp();
 
-    pExport = new SchXMLExport(
+    pExport.reset(new SchXMLExport(
         comphelper::getProcessComponentContext(), "SchXMLExport.Compact",
-        SvXMLExportFlags::ALL);
+        SvXMLExportFlags::ALL));
 }
 
 void Test::tearDown()
 {
-    delete pExport;
+    pExport.reset();
     BootstrapFixture::tearDown();
 }
 
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 2e7349780ed2..36c161abc79c 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -3844,18 +3844,17 @@ void XMLTextParagraphExport::PreventExportOfControlsInMuteSections(
 
 void XMLTextParagraphExport::PushNewTextListsHelper()
 {
-    mpTextListsHelper = new XMLTextListsHelper();
-    maTextListsHelperStack.push_back( mpTextListsHelper );
+    maTextListsHelperStack.emplace_back( new XMLTextListsHelper() );
+    mpTextListsHelper = maTextListsHelperStack.back().get();
 }
 
 void XMLTextParagraphExport::PopTextListsHelper()
 {
-    delete mpTextListsHelper;
     mpTextListsHelper = nullptr;
     maTextListsHelperStack.pop_back();
     if ( !maTextListsHelperStack.empty() )
     {
-        mpTextListsHelper = maTextListsHelperStack.back();
+        mpTextListsHelper = maTextListsHelperStack.back().get();
     }
 }
 


More information about the Libreoffice-commits mailing list