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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Sep 18 18:54:19 UTC 2018


 include/svtools/valueset.hxx        |    4 +-
 svtools/source/control/valueacc.cxx |    2 -
 svtools/source/control/valueset.cxx |   49 ++++++++++++++++--------------------
 3 files changed, 25 insertions(+), 30 deletions(-)

New commits:
commit 4865d3289ba7200be436c9bac305a4519804ec0c
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Sep 17 16:18:11 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Sep 18 20:53:54 2018 +0200

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

diff --git a/include/svtools/valueset.hxx b/include/svtools/valueset.hxx
index 6c0f05960e97..6804a9622c90 100644
--- a/include/svtools/valueset.hxx
+++ b/include/svtools/valueset.hxx
@@ -180,7 +180,7 @@ to be set (before Show) with SetStyle().
 *************************************************************************/
 
 typedef std::vector<std::unique_ptr<ValueSetItem>> ValueItemList;
-typedef std::vector<SvtValueSetItem*> SvtValueItemList;
+typedef std::vector<std::unique_ptr<SvtValueSetItem>> SvtValueItemList;
 
 #define WB_ITEMBORDER           (WinBits(0x00010000))
 #define WB_DOUBLEBORDER         (WinBits(0x00020000))
@@ -460,7 +460,7 @@ private:
     SVT_DLLPRIVATE SvtValueSetItem*    ImplGetItem( size_t nPos );
     SVT_DLLPRIVATE SvtValueSetItem*    ImplGetFirstItem();
     SVT_DLLPRIVATE sal_uInt16          ImplGetVisibleItemCount() const;
-    SVT_DLLPRIVATE void         ImplInsertItem( SvtValueSetItem *const pItem, const size_t nPos );
+    SVT_DLLPRIVATE void         ImplInsertItem( std::unique_ptr<SvtValueSetItem> pItem, const size_t nPos );
     SVT_DLLPRIVATE tools::Rectangle    ImplGetItemRect( size_t nPos ) const;
     SVT_DLLPRIVATE void         ImplFireAccessibleEvent( short nEventId, const css::uno::Any& rOldValue, const css::uno::Any& rNewValue );
     SVT_DLLPRIVATE bool         ImplHasAccessibleListeners();
diff --git a/svtools/source/control/valueacc.cxx b/svtools/source/control/valueacc.cxx
index 3b214b6c4d2f..4341dfceda7a 100644
--- a/svtools/source/control/valueacc.cxx
+++ b/svtools/source/control/valueacc.cxx
@@ -1726,7 +1726,7 @@ uno::Reference< accessibility::XAccessible > SAL_CALL SvtValueSetAcc::getAccessi
 
         if( VALUESET_ITEM_NONEITEM != nItemPos )
         {
-            SvtValueSetItem *const pItem = mpParent->mItemList[nItemPos];
+            SvtValueSetItem *const pItem = mpParent->mItemList[nItemPos].get();
             xRet = pItem->GetAccessible( false/*bIsTransientChildrenDisabled*/ );
         }
     }
diff --git a/svtools/source/control/valueset.cxx b/svtools/source/control/valueset.cxx
index 23b8a4f082f2..eb3daf8be985 100644
--- a/svtools/source/control/valueset.cxx
+++ b/svtools/source/control/valueset.cxx
@@ -2331,7 +2331,7 @@ void SvtValueSet::ImplDeleteItems()
 
     for ( size_t i = 0; i < n; ++i )
     {
-        SvtValueSetItem* pItem = mItemList[i];
+        SvtValueSetItem* pItem = mItemList[i].get();
         if ( pItem->mbVisible && ImplHasAccessibleListeners() )
         {
             Any aOldAny;
@@ -2341,7 +2341,7 @@ void SvtValueSet::ImplDeleteItems()
             ImplFireAccessibleEvent(AccessibleEventId::CHILD, aOldAny, aNewAny);
         }
 
-        delete pItem;
+        mItemList[i].reset();
     }
 
     mItemList.clear();
@@ -2398,12 +2398,12 @@ SvtValueSetItem* SvtValueSet::ImplGetItem( size_t nPos )
     if (nPos == VALUESET_ITEM_NONEITEM)
         return mpNoneItem.get();
     else
-        return (nPos < mItemList.size()) ? mItemList[nPos] : nullptr;
+        return (nPos < mItemList.size()) ? mItemList[nPos].get() : nullptr;
 }
 
 SvtValueSetItem* SvtValueSet::ImplGetFirstItem()
 {
-    return mItemList.size() ? mItemList[0] : nullptr;
+    return mItemList.size() ? mItemList[0].get() : nullptr;
 }
 
 sal_uInt16 SvtValueSet::ImplGetVisibleItemCount() const
@@ -2701,10 +2701,7 @@ void SvtValueSet::RemoveItem( sal_uInt16 nItemId )
         return;
 
     if ( nPos < mItemList.size() ) {
-        SvtValueItemList::iterator it = mItemList.begin();
-        ::std::advance( it, nPos );
-        delete *it;
-        mItemList.erase( it );
+        mItemList.erase( mItemList.begin() + nPos );
     }
 
     // reset variables
@@ -2923,7 +2920,7 @@ void SvtValueSet::SelectItem( sal_uInt16 nItemId )
 
         SvtValueSetItem* pItem;
         if( nPos != VALUESET_ITEM_NOTFOUND )
-            pItem = mItemList[nPos];
+            pItem = mItemList[nPos].get();
         else
             pItem = mpNoneItem.get();
 
@@ -3231,7 +3228,7 @@ void SvtValueSet::Format(vcl::RenderContext const & rRenderContext)
         }
         for (size_t i = 0; i < nItemCount; i++)
         {
-            SvtValueSetItem* pItem = mItemList[i];
+            SvtValueSetItem* pItem = mItemList[i].get();
 
             if (i >= nFirstItem && i < nLastItem)
             {
@@ -3316,7 +3313,7 @@ void SvtValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext, sal_uInt16
     if (nItemId)
     {
         const size_t nPos = GetItemPos( nItemId );
-        pItem = mItemList[ nPos ];
+        pItem = mItemList[ nPos ].get();
         aRect = ImplGetItemRect( nPos );
     }
     else if (mpNoneItem.get())
@@ -3617,7 +3614,7 @@ void SvtValueSet::SetItemImage( sal_uInt16 nItemId, const Image& rImage )
     if ( nPos == VALUESET_ITEM_NOTFOUND )
         return;
 
-    SvtValueSetItem* pItem = mItemList[nPos];
+    SvtValueSetItem* pItem = mItemList[nPos].get();
     pItem->meType  = VALUESETITEM_IMAGE;
     pItem->maImage = rImage;
 
@@ -3714,45 +3711,43 @@ Size SvtValueSet::CalcWindowSizePixel( const Size& rItemSize, sal_uInt16 nDesire
 void SvtValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage,
                            const OUString& rText, size_t nPos )
 {
-    SvtValueSetItem* pItem = new SvtValueSetItem( *this );
+    std::unique_ptr<SvtValueSetItem> pItem(new SvtValueSetItem( *this ));
     pItem->mnId     = nItemId;
     pItem->meType   = VALUESETITEM_IMAGE;
     pItem->maImage  = rImage;
     pItem->maText   = rText;
-    ImplInsertItem( pItem, nPos );
+    ImplInsertItem( std::move(pItem), nPos );
 }
 
 void SvtValueSet::InsertItem( sal_uInt16 nItemId, size_t nPos )
 {
-    SvtValueSetItem* pItem = new SvtValueSetItem( *this );
+    std::unique_ptr<SvtValueSetItem> pItem(new SvtValueSetItem( *this ));
     pItem->mnId     = nItemId;
     pItem->meType   = VALUESETITEM_USERDRAW;
-    ImplInsertItem( pItem, nPos );
+    ImplInsertItem( std::move(pItem), nPos );
 }
 
 void SvtValueSet::InsertItem( sal_uInt16 nItemId, const Color& rColor,
                            const OUString& rText )
 {
-    SvtValueSetItem* pItem = new SvtValueSetItem( *this );
+    std::unique_ptr<SvtValueSetItem> pItem(new SvtValueSetItem( *this ));
     pItem->mnId     = nItemId;
     pItem->meType   = VALUESETITEM_COLOR;
     pItem->maColor  = rColor;
     pItem->maText   = rText;
-    ImplInsertItem( pItem, VALUESET_APPEND );
+    ImplInsertItem( std::move(pItem), VALUESET_APPEND );
 }
 
-void SvtValueSet::ImplInsertItem( SvtValueSetItem *const pItem, const size_t nPos )
+void SvtValueSet::ImplInsertItem( std::unique_ptr<SvtValueSetItem> pItem, const size_t nPos )
 {
     DBG_ASSERT( pItem->mnId, "ValueSet::InsertItem(): ItemId == 0" );
     DBG_ASSERT( GetItemPos( pItem->mnId ) == VALUESET_ITEM_NOTFOUND,
                 "ValueSet::InsertItem(): ItemId already exists" );
 
     if ( nPos < mItemList.size() ) {
-        SvtValueItemList::iterator it = mItemList.begin();
-        ::std::advance( it, nPos );
-        mItemList.insert( it, pItem );
+        mItemList.insert( mItemList.begin() + nPos, std::move(pItem) );
     } else {
-        mItemList.push_back( pItem );
+        mItemList.push_back( std::move(pItem) );
     }
 
     queue_resize();
@@ -3834,11 +3829,11 @@ void SvtValueSet::InsertItem( sal_uInt16 nItemId, const OUString& rText, size_t
     DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" );
     DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,
                 "ValueSet::InsertItem(): ItemId already exists" );
-    SvtValueSetItem* pItem = new SvtValueSetItem( *this );
+    std::unique_ptr<SvtValueSetItem> pItem(new SvtValueSetItem( *this ));
     pItem->mnId     = nItemId;
     pItem->meType   = VALUESETITEM_USERDRAW;
     pItem->maText   = rText;
-    ImplInsertItem( pItem, nPos );
+    ImplInsertItem( std::move(pItem), nPos );
 }
 
 void SvtValueSet::SetItemHeight( long nNewItemHeight )
@@ -3901,7 +3896,7 @@ void SvtValueSet::SetItemText(sal_uInt16 nItemId, const OUString& rText)
     if ( nPos == VALUESET_ITEM_NOTFOUND )
         return;
 
-    SvtValueSetItem* pItem = mItemList[nPos];
+    SvtValueSetItem* pItem = mItemList[nPos].get();
 
     // Remember old and new name for accessibility event.
     Any aOldName;
@@ -3936,7 +3931,7 @@ Size SvtValueSet::GetLargestItemSize()
 {
     Size aLargestItem;
 
-    for (SvtValueSetItem* pItem : mItemList)
+    for (std::unique_ptr<SvtValueSetItem>& pItem : mItemList)
     {
         if (!pItem->mbVisible)
             continue;


More information about the Libreoffice-commits mailing list