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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Sep 25 09:04:09 UTC 2018


 include/sfx2/dinfdlg.hxx                   |    6 +--
 include/sfx2/thumbnailview.hxx             |    6 +--
 sfx2/source/control/emojiview.cxx          |    4 +-
 sfx2/source/control/recentdocsview.cxx     |    5 +-
 sfx2/source/control/templatelocalview.cxx  |   26 +++++++------
 sfx2/source/control/templatesearchview.cxx |    4 +-
 sfx2/source/control/thumbnailview.cxx      |   26 ++++++-------
 sfx2/source/dialog/dinfdlg.cxx             |   54 ++++++++---------------------
 8 files changed, 54 insertions(+), 77 deletions(-)

New commits:
commit 80f28ef95e7c74c8df799a47fa90ff90bfd13f61
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Sep 19 12:20:42 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Sep 25 11:03:56 2018 +0200

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

diff --git a/include/sfx2/dinfdlg.hxx b/include/sfx2/dinfdlg.hxx
index 66c5726e8eca..d7894172753a 100644
--- a/include/sfx2/dinfdlg.hxx
+++ b/include/sfx2/dinfdlg.hxx
@@ -554,9 +554,9 @@ struct CmisPropertyLine : public VclBuilderContainer
     bool                          m_bOpenChoice;
     VclPtr<FixedText>             m_aName;
     VclPtr<FixedText>             m_aType;
-    std::vector< CmisValue* >     m_aValues;
-    std::vector< CmisDateTime* >  m_aDateTimes;
-    std::vector< CmisYesNo* >     m_aYesNos;
+    std::vector< std::unique_ptr<CmisValue> >     m_aValues;
+    std::vector< std::unique_ptr<CmisDateTime> >  m_aDateTimes;
+    std::vector< std::unique_ptr<CmisYesNo> >     m_aYesNos;
     long getItemHeight() const;
     CmisPropertyLine( vcl::Window* pParent );
     virtual ~CmisPropertyLine() override;
diff --git a/sfx2/source/dialog/dinfdlg.cxx b/sfx2/source/dialog/dinfdlg.cxx
index c015edebeff6..6fad98d00222 100644
--- a/sfx2/source/dialog/dinfdlg.cxx
+++ b/sfx2/source/dialog/dinfdlg.cxx
@@ -2260,33 +2260,9 @@ CmisPropertyLine::CmisPropertyLine(vcl::Window* pParent)
 
 CmisPropertyLine::~CmisPropertyLine( )
 {
-    std::vector< CmisValue* >::iterator pIter;
-    for ( pIter = m_aValues.begin();
-          pIter != m_aValues.end(); ++pIter )
-    {
-        CmisValue* pValue = *pIter;
-        delete pValue;
-    }
     m_aValues.clear();
-
-    std::vector< CmisYesNo* >::iterator pIterYesNo;
-    for ( pIterYesNo = m_aYesNos.begin();
-          pIterYesNo != m_aYesNos.end(); ++pIterYesNo )
-    {
-        CmisYesNo* pYesNo = *pIterYesNo;
-        delete pYesNo;
-    }
     m_aYesNos.clear();
-
-    std::vector< CmisDateTime* >::iterator pIterDateTime;
-    for ( pIterDateTime = m_aDateTimes.begin();
-          pIterDateTime != m_aDateTimes.end(); ++pIterDateTime )
-    {
-        CmisDateTime* pDateTime = *pIterDateTime;
-        delete pDateTime;
-    }
     m_aDateTimes.clear();
-
 }
 
 long CmisPropertyLine::getItemHeight() const
@@ -2346,9 +2322,9 @@ void CmisPropertiesWindow::AddLine( const OUString& sId, const OUString& sName,
         {
             OUString sValue;
             m_aNumberFormatter.GetInputLineString( seqValue[i], nIndex, sValue );
-            CmisValue* pValue = new CmisValue( m_pBox, sValue );
+            std::unique_ptr<CmisValue> pValue(new CmisValue( m_pBox, sValue ));
             pValue->m_aValueEdit->SetReadOnly( !bUpdatable );
-            pNewLine->m_aValues.push_back( pValue );
+            pNewLine->m_aValues.push_back( std::move(pValue) );
         }
     }
     else if ( sType == CMIS_TYPE_DECIMAL )
@@ -2361,9 +2337,9 @@ void CmisPropertiesWindow::AddLine( const OUString& sId, const OUString& sName,
         {
             OUString sValue;
             m_aNumberFormatter.GetInputLineString( seqValue[i], nIndex, sValue );
-            CmisValue* pValue = new CmisValue( m_pBox, sValue );
+            std::unique_ptr<CmisValue> pValue(new CmisValue( m_pBox, sValue ));
             pValue->m_aValueEdit->SetReadOnly( !bUpdatable );
-            pNewLine->m_aValues.push_back( pValue );
+            pNewLine->m_aValues.push_back( std::move(pValue) );
         }
 
     }
@@ -2374,10 +2350,10 @@ void CmisPropertiesWindow::AddLine( const OUString& sId, const OUString& sName,
         sal_Int32 nNumValue = seqValue.getLength( );
         for ( sal_Int32 i = 0; i < nNumValue; ++i )
         {
-            CmisYesNo* pYesNo = new CmisYesNo( m_pBox, seqValue[i] );
+            std::unique_ptr<CmisYesNo> pYesNo(new CmisYesNo( m_pBox, seqValue[i] ));
             pYesNo->m_aYesButton->Enable( bUpdatable );
             pYesNo->m_aNoButton->Enable( bUpdatable );
-            pNewLine->m_aYesNos.push_back( pYesNo );
+            pNewLine->m_aYesNos.push_back( std::move(pYesNo) );
         }
     }
     else if ( sType == CMIS_TYPE_STRING )
@@ -2387,9 +2363,9 @@ void CmisPropertiesWindow::AddLine( const OUString& sId, const OUString& sName,
         sal_Int32 nNumValue = seqValue.getLength( );
         for ( sal_Int32 i = 0; i < nNumValue; ++i )
         {
-            CmisValue* pValue = new CmisValue( m_pBox, seqValue[i] );
+            std::unique_ptr<CmisValue> pValue(new CmisValue( m_pBox, seqValue[i] ));
             pValue->m_aValueEdit->SetReadOnly( !bUpdatable );
-            pNewLine->m_aValues.push_back( pValue );
+            pNewLine->m_aValues.push_back( std::move(pValue) );
         }
     }
     else if ( sType == CMIS_TYPE_DATETIME )
@@ -2399,10 +2375,10 @@ void CmisPropertiesWindow::AddLine( const OUString& sId, const OUString& sName,
         sal_Int32 nNumValue = seqValue.getLength( );
         for ( sal_Int32 i = 0; i < nNumValue; ++i )
         {
-            CmisDateTime* pDateTime = new CmisDateTime( m_pBox, seqValue[i]);
+            std::unique_ptr<CmisDateTime> pDateTime(new CmisDateTime( m_pBox, seqValue[i]));
             pDateTime->m_aDateField->SetReadOnly( !bUpdatable );
             pDateTime->m_aTimeField->SetReadOnly( !bUpdatable );
-            pNewLine->m_aDateTimes.push_back( pDateTime );
+            pNewLine->m_aDateTimes.push_back( std::move(pDateTime) );
         }
     }
     pNewLine->m_aName->SetText( sName );
@@ -2446,7 +2422,7 @@ Sequence< document::CmisProperty > CmisPropertiesWindow::GetCmisProperties() con
                     m_aNumberFormatter ).GetFormatIndex( NF_NUMBER_SYSTEM );
                 Sequence< double > seqValue( pLine->m_aValues.size( ) );
                 sal_Int32 k = 0;
-                for ( std::vector< CmisValue*>::const_iterator it = pLine->m_aValues.begin();
+                for ( auto it = pLine->m_aValues.begin();
                     it != pLine->m_aValues.end(); ++it, ++k)
                 {
                     double dValue = 0.0;
@@ -2464,7 +2440,7 @@ Sequence< document::CmisProperty > CmisPropertiesWindow::GetCmisProperties() con
                     m_aNumberFormatter ).GetFormatIndex( NF_NUMBER_SYSTEM );
                 Sequence< sal_Int64 > seqValue( pLine->m_aValues.size( ) );
                 sal_Int32 k = 0;
-                for ( std::vector< CmisValue*>::const_iterator it = pLine->m_aValues.begin();
+                for ( auto it = pLine->m_aValues.begin();
                     it != pLine->m_aValues.end(); ++it, ++k)
                 {
                     double dValue = 0;
@@ -2480,7 +2456,7 @@ Sequence< document::CmisProperty > CmisPropertiesWindow::GetCmisProperties() con
             {
                 Sequence<sal_Bool> seqValue( pLine->m_aYesNos.size( ) );
                 sal_Int32 k = 0;
-                for ( std::vector< CmisYesNo*>::const_iterator it = pLine->m_aYesNos.begin();
+                for ( auto it = pLine->m_aYesNos.begin();
                     it != pLine->m_aYesNos.end(); ++it, ++k)
                 {
                     bool bValue = (*it)->m_aYesButton->IsChecked();
@@ -2493,7 +2469,7 @@ Sequence< document::CmisProperty > CmisPropertiesWindow::GetCmisProperties() con
             {
                 Sequence< util::DateTime > seqValue( pLine->m_aDateTimes.size( ) );
                 sal_Int32 k = 0;
-                for ( std::vector< CmisDateTime*>::const_iterator it = pLine->m_aDateTimes.begin();
+                for ( auto it = pLine->m_aDateTimes.begin();
                     it != pLine->m_aDateTimes.end(); ++it, ++k)
                 {
                     Date aTmpDate = (*it)->m_aDateField->GetDate();
@@ -2510,7 +2486,7 @@ Sequence< document::CmisProperty > CmisPropertiesWindow::GetCmisProperties() con
             {
                 Sequence< OUString > seqValue( pLine->m_aValues.size( ) );
                 sal_Int32 k = 0;
-                for ( std::vector< CmisValue*>::const_iterator it = pLine->m_aValues.begin();
+                for ( auto it = pLine->m_aValues.begin();
                     it != pLine->m_aValues.end(); ++it, ++k)
                 {
                     OUString sValue( (*it)->m_aValueEdit->GetText() );
commit 72c191e046112df73c66be8dc8d1bec5a546fa60
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Sep 19 12:11:38 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Sep 25 11:03:47 2018 +0200

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

diff --git a/include/sfx2/thumbnailview.hxx b/include/sfx2/thumbnailview.hxx
index c628d38a2eb1..2ea319b36c3d 100644
--- a/include/sfx2/thumbnailview.hxx
+++ b/include/sfx2/thumbnailview.hxx
@@ -185,7 +185,7 @@ public:
 
     virtual void MouseMove(const MouseEvent& rMEvt) override;
 
-    void AppendItem(ThumbnailViewItem *pItem);
+    void AppendItem(std::unique_ptr<ThumbnailViewItem> pItem);
 
     void RemoveItem(sal_uInt16 nItemId);
 
@@ -195,7 +195,7 @@ public:
     virtual void Reload() {}
 
     // Change current thumbnail item list with new one (invalidates all pointers to a thumbnail item)
-    void updateItems(const std::vector<ThumbnailViewItem *> &items);
+    void updateItems(std::vector<std::unique_ptr<ThumbnailViewItem>> items);
 
     size_t GetItemPos( sal_uInt16 nItemId ) const;
 
@@ -288,7 +288,7 @@ protected:
 
 protected:
 
-    ThumbnailValueItemList mItemList;
+    std::vector< std::unique_ptr<ThumbnailViewItem> > mItemList;
     ThumbnailValueItemList mFilteredItemList; ///< Cache to store the filtered items
     ThumbnailValueItemList::iterator mpStartSelRange;
     VclPtr<ScrollBar> mpScrBar;
diff --git a/sfx2/source/control/emojiview.cxx b/sfx2/source/control/emojiview.cxx
index 2175d42c37b3..f0003cc1ebad 100644
--- a/sfx2/source/control/emojiview.cxx
+++ b/sfx2/source/control/emojiview.cxx
@@ -209,13 +209,13 @@ void EmojiView::setInsertEmojiHdl(const Link<ThumbnailViewItem*, void> &rLink)
 
 void EmojiView::AppendItem(const OUString &rTitle, const OUString &rCategory, const OUString &rName)
 {
-    EmojiViewItem *pItem = new EmojiViewItem(*this, getNextItemId());
+    std::unique_ptr<EmojiViewItem> pItem(new EmojiViewItem(*this, getNextItemId()));
 
     pItem->maTitle = rTitle;
     pItem->setCategory(rCategory);
     pItem->setHelpText(rName);
 
-    ThumbnailView::AppendItem(pItem);
+    ThumbnailView::AppendItem(std::move(pItem));
 
     CalculateItemPositions();
 }
diff --git a/sfx2/source/control/recentdocsview.cxx b/sfx2/source/control/recentdocsview.cxx
index d8d2a833e9c6..2c4ad0bc4ebc 100644
--- a/sfx2/source/control/recentdocsview.cxx
+++ b/sfx2/source/control/recentdocsview.cxx
@@ -38,6 +38,7 @@
 #include <bitmaps.hlst>
 
 #include <officecfg/Office/Common.hxx>
+#include <o3tl/make_unique.hxx>
 
 using namespace ::com::sun::star;
 using namespace com::sun::star::uno;
@@ -216,9 +217,7 @@ BitmapEx RecentDocsView::getDefaultThumbnail(const OUString &rURL)
 
 void RecentDocsView::insertItem(const OUString &rURL, const OUString &rTitle, const BitmapEx &rThumbnail, sal_uInt16 nId)
 {
-    RecentDocsViewItem *pChild = new RecentDocsViewItem(*this, rURL, rTitle, rThumbnail, nId, mnItemMaxSize);
-
-    AppendItem(pChild);
+    AppendItem( o3tl::make_unique<RecentDocsViewItem>(*this, rURL, rTitle, rThumbnail, nId, mnItemMaxSize) );
 }
 
 void RecentDocsView::Reload()
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index efc66dda09ab..3218fc97453e 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -548,8 +548,9 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_
             // Keep view document id synchronized with SfxDocumentTemplates
             for (auto const& item : mItemList)
             {
-                if (static_cast<TemplateViewItem*>(item)->mnDocId > pViewItem->mnDocId)
-                    --static_cast<TemplateViewItem*>(item)->mnDocId;
+                auto pTemplateViewItem = static_cast<TemplateViewItem*>(item.get());
+                if (pTemplateViewItem->mnDocId > pViewItem->mnDocId)
+                    --pTemplateViewItem->mnDocId;
             }
         }
 
@@ -658,8 +659,9 @@ void TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, s
                     // Keep view document id synchronized with SfxDocumentTemplates
                     for (auto const& item : mItemList)
                     {
-                        if (static_cast<TemplateViewItem*>(item)->mnDocId > pViewItem->mnDocId)
-                            --static_cast<TemplateViewItem*>(item)->mnDocId;
+                        auto pTemplateViewItem = static_cast<TemplateViewItem*>(item.get());
+                        if (pTemplateViewItem->mnDocId > pViewItem->mnDocId)
+                            --pTemplateViewItem->mnDocId;
                     }
                 }
             }
@@ -753,16 +755,16 @@ bool TemplateLocalView::renameItem(ThumbnailViewItem* pItem, const OUString& sNe
 
 void TemplateLocalView::insertItems(const std::vector<TemplateItemProperties> &rTemplates, bool isRegionSelected, bool bShowCategoryInTooltip)
 {
-    std::vector<ThumbnailViewItem*> aItems(rTemplates.size());
+    std::vector<std::unique_ptr<ThumbnailViewItem>> aItems(rTemplates.size());
     for (size_t i = 0, n = rTemplates.size(); i < n; ++i )
     {
         const TemplateItemProperties *pCur = &rTemplates[i];
 
-        TemplateViewItem *pChild;
+        std::unique_ptr<TemplateViewItem> pChild;
         if(isRegionSelected)
-            pChild = new TemplateViewItem(*this, pCur->nId);
+            pChild.reset(new TemplateViewItem(*this, pCur->nId));
         else
-            pChild = new TemplateViewItem(*this, i+1);
+            pChild.reset(new TemplateViewItem(*this, i+1));
 
         pChild->mnDocId = pCur->nDocId;
         pChild->mnRegionId = pCur->nRegionId;
@@ -789,10 +791,10 @@ void TemplateLocalView::insertItems(const std::vector<TemplateItemProperties> &r
             pChild->maPreview1 = TemplateLocalView::getDefaultThumbnail(pCur->aPath);
         }
 
-        aItems[i] = pChild;
+        aItems[i] = std::move(pChild);
     }
 
-    updateItems(aItems);
+    updateItems(std::move(aItems));
 }
 
 void TemplateLocalView::updateThumbnailDimensions(long itemMaxSize)
@@ -976,9 +978,9 @@ bool TemplateLocalView::IsDefaultTemplate(const OUString& rPath)
 
 void TemplateLocalView::RemoveDefaultTemplateIcon(const OUString& rPath)
 {
-    for (ThumbnailViewItem* pItem : mItemList)
+    for (std::unique_ptr<ThumbnailViewItem>& pItem : mItemList)
     {
-        TemplateViewItem* pViewItem = dynamic_cast<TemplateViewItem*>(pItem);
+        TemplateViewItem* pViewItem = dynamic_cast<TemplateViewItem*>(pItem.get());
         if (pViewItem && pViewItem->getPath().match(rPath))
         {
             pViewItem->showDefaultIcon(false);
diff --git a/sfx2/source/control/templatesearchview.cxx b/sfx2/source/control/templatesearchview.cxx
index ace6b4fcb32e..3f891ae2c1bb 100644
--- a/sfx2/source/control/templatesearchview.cxx
+++ b/sfx2/source/control/templatesearchview.cxx
@@ -216,7 +216,7 @@ void TemplateSearchView::AppendItem(sal_uInt16 nAssocItemId, sal_uInt16 nRegionI
                                     const OUString &rPath,
                                     const BitmapEx &rImage)
 {
-    TemplateSearchViewItem *pItem = new TemplateSearchViewItem(*this, getNextItemId());
+    std::unique_ptr<TemplateSearchViewItem> pItem(new TemplateSearchViewItem(*this, getNextItemId()));
     pItem->mnAssocId = nAssocItemId;
     pItem->mnDocId = nIdx;
     pItem->mnRegionId = nRegionId;
@@ -233,7 +233,7 @@ void TemplateSearchView::AppendItem(sal_uInt16 nAssocItemId, sal_uInt16 nRegionI
     if(TemplateLocalView::IsDefaultTemplate(rPath))
         pItem->showDefaultIcon(true);
 
-    ThumbnailView::AppendItem(pItem);
+    ThumbnailView::AppendItem(std::move(pItem));
 
     CalculateItemPositions();
 }
diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx
index 81a5021c2766..13435a923627 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -101,9 +101,9 @@ void ThumbnailView::MouseMove(const MouseEvent& rMEvt)
         SetQuickHelpText(aHelp);
 }
 
-void ThumbnailView::AppendItem(ThumbnailViewItem *pItem)
+void ThumbnailView::AppendItem(std::unique_ptr<ThumbnailViewItem> pItem)
 {
-    if (maFilterFunc(pItem))
+    if (maFilterFunc(pItem.get()))
     {
         // Save current start,end range, iterator might get invalidated
         size_t nSelStartPos = 0;
@@ -115,11 +115,11 @@ void ThumbnailView::AppendItem(ThumbnailViewItem *pItem)
             nSelStartPos = mpStartSelRange - mFilteredItemList.begin();
         }
 
-        mFilteredItemList.push_back(pItem);
+        mFilteredItemList.push_back(pItem.get());
         mpStartSelRange = pSelStartItem != nullptr ? mFilteredItemList.begin() + nSelStartPos : mFilteredItemList.end();
     }
 
-    mItemList.push_back(pItem);
+    mItemList.push_back(std::move(pItem));
 }
 
 void ThumbnailView::ImplInit()
@@ -159,7 +159,7 @@ void ThumbnailView::ImplDeleteItems()
 
     for ( size_t i = 0; i < n; ++i )
     {
-        ThumbnailViewItem *const pItem = mItemList[i];
+        ThumbnailViewItem *const pItem = mItemList[i].get();
 
         // deselect all current selected items and fire events
         if (pItem->isSelected())
@@ -178,7 +178,7 @@ void ThumbnailView::ImplDeleteItems()
             ImplFireAccessibleEvent( css::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
         }
 
-        delete pItem;
+        mItemList[i].reset();
     }
 
     mItemList.clear();
@@ -456,7 +456,7 @@ ThumbnailViewItem* ThumbnailView::ImplGetVisibleItem( sal_uInt16 nVisiblePos )
 
     for ( size_t n = 0; n < nItemCount; ++n )
     {
-        ThumbnailViewItem *const pItem = mItemList[n];
+        ThumbnailViewItem *const pItem = mItemList[n].get();
 
         if ( pItem->isVisible() && !nVisiblePos-- )
             return pItem;
@@ -848,7 +848,7 @@ void ThumbnailView::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rec
     // draw items
     for (size_t i = 0; i < nItemCount; i++)
     {
-        ThumbnailViewItem *const pItem = mItemList[i];
+        ThumbnailViewItem *const pItem = mItemList[i].get();
 
         if (pItem->isVisible())
         {
@@ -1005,14 +1005,14 @@ void ThumbnailView::Clear()
         Invalidate();
 }
 
-void ThumbnailView::updateItems (const std::vector<ThumbnailViewItem*> &items)
+void ThumbnailView::updateItems (std::vector<std::unique_ptr<ThumbnailViewItem>> items)
 {
     ImplDeleteItems();
 
     // reset variables
     mnFirstLine     = 0;
 
-    mItemList = items;
+    mItemList = std::move(items);
 
     filterItems(maFilterFunc);
 }
@@ -1137,13 +1137,13 @@ bool ThumbnailView::IsItemSelected( sal_uInt16 nItemId ) const
 
 void ThumbnailView::deselectItems()
 {
-    for (ThumbnailViewItem* p : mItemList)
+    for (std::unique_ptr<ThumbnailViewItem>& p : mItemList)
     {
         if (p->isSelected())
         {
             p->setSelection(false);
 
-            maItemStateHdl.Call(p);
+            maItemStateHdl.Call(p.get());
         }
     }
 
@@ -1174,7 +1174,7 @@ void ThumbnailView::filterItems(const std::function<bool (const ThumbnailViewIte
 
     for (size_t i = 0, n = mItemList.size(); i < n; ++i)
     {
-        ThumbnailViewItem *const pItem = mItemList[i];
+        ThumbnailViewItem *const pItem = mItemList[i].get();
 
         if (maFilterFunc(pItem))
         {


More information about the Libreoffice-commits mailing list