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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Oct 2 10:52:04 UTC 2018


 include/svx/svdpagv.hxx       |   10 +++++--
 svx/source/svdraw/svdpagv.cxx |   57 +++++++++++++++---------------------------
 2 files changed, 28 insertions(+), 39 deletions(-)

New commits:
commit 25f23c6570f909a8dfd2c7b0a78d43d59868a5f9
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Sep 28 13:59:32 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Oct 2 12:51:42 2018 +0200

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

diff --git a/include/svx/svdpagv.hxx b/include/svx/svdpagv.hxx
index 8362ffb04695..d78226c1af3e 100644
--- a/include/svx/svdpagv.hxx
+++ b/include/svx/svdpagv.hxx
@@ -29,6 +29,7 @@
 #include <svx/svdtypes.hxx>
 #include <svx/svxdllapi.h>
 
+#include <memory>
 #include <vector>
 #include <basegfx/polygon/b2dpolypolygon.hxx>
 
@@ -55,7 +56,6 @@ namespace sdr
 
 // typedefs for a list of SdrPageWindow
 class SdrPageWindow;
-typedef ::std::vector< SdrPageWindow* > SdrPageWindowVector;
 
 
 class SVX_DLLPUBLIC SdrPageView
@@ -85,7 +85,7 @@ private:
     // #103834# Use one reserved slot (bReserveBool1) for the background color
     Color         maBackgroundColor;
 
-    SdrPageWindowVector maPageWindows;
+    std::vector< std::unique_ptr<SdrPageWindow> > maPageWindows;
 
     // #i72752# member to remember with which SdrPageWindow the BeginDrawLayer
     // was done
@@ -93,7 +93,7 @@ private:
 
     // interface to SdrPageWindow
     void ClearPageWindows();
-    SdrPageWindow* RemovePageWindow(SdrPageWindow& rOld);
+    std::unique_ptr<SdrPageWindow> RemovePageWindow(SdrPageWindow& rOld);
 public:
     sal_uInt32 PageWindowCount() const { return maPageWindows.size(); }
     SdrPageWindow* FindPageWindow( SdrPaintWindow& rPaintWindow ) const;
@@ -122,6 +122,10 @@ private:
 public:
     SdrPageView(SdrPage* pPage1, SdrView& rNewView);
     ~SdrPageView();
+  
+    SdrPageView& operator=( SdrPageView const & ) = delete; // MSVC2017 workaround
+    SdrPageView( SdrPageView const & ) = delete; // MSVC2017 workaround
+
 
     /// Is called by PaintView, when modal changes have finished
     void ModelHasChanged();
diff --git a/svx/source/svdraw/svdpagv.cxx b/svx/source/svdraw/svdpagv.cxx
index 1aa17c27d7f7..38c694ccfcb3 100644
--- a/svx/source/svdraw/svdpagv.cxx
+++ b/svx/source/svdraw/svdpagv.cxx
@@ -52,11 +52,11 @@ using namespace ::com::sun::star;
 
 SdrPageWindow* SdrPageView::FindPageWindow(SdrPaintWindow& rPaintWindow) const
 {
-    for(SdrPageWindowVector::const_iterator a = maPageWindows.begin(); a != maPageWindows.end(); ++a)
+    for(auto & a : maPageWindows)
     {
-        if(&((*a)->GetPaintWindow()) == &rPaintWindow)
+        if(&(a->GetPaintWindow()) == &rPaintWindow)
         {
-            return *a;
+            return a.get();
         }
     }
 
@@ -65,16 +65,12 @@ SdrPageWindow* SdrPageView::FindPageWindow(SdrPaintWindow& rPaintWindow) const
 
 const SdrPageWindow* SdrPageView::FindPatchedPageWindow( const OutputDevice& _rOutDev ) const
 {
-    for (   SdrPageWindowVector::const_iterator loop = maPageWindows.begin();
-            loop != maPageWindows.end();
-            ++loop
-        )
+    for ( auto const & pPageWindow : maPageWindows )
     {
-        const SdrPageWindow& rPageWindow( *(*loop) );
-        const SdrPaintWindow& rPaintWindow( rPageWindow.GetOriginalPaintWindow() ? *rPageWindow.GetOriginalPaintWindow() : rPageWindow.GetPaintWindow() );
+        const SdrPaintWindow& rPaintWindow( pPageWindow->GetOriginalPaintWindow() ? *pPageWindow->GetOriginalPaintWindow() : pPageWindow->GetPaintWindow() );
         if ( &rPaintWindow.GetOutputDevice() == &_rOutDev )
         {
-            return &rPageWindow;
+            return pPageWindow.get();
         }
     }
 
@@ -83,11 +79,11 @@ const SdrPageWindow* SdrPageView::FindPatchedPageWindow( const OutputDevice& _rO
 
 SdrPageWindow* SdrPageView::FindPageWindow(const OutputDevice& rOutDev) const
 {
-    for(SdrPageWindowVector::const_iterator a = maPageWindows.begin(); a != maPageWindows.end(); ++a)
+    for ( auto const & pPageWindow : maPageWindows )
     {
-        if(&((*a)->GetPaintWindow().GetOutputDevice()) == &rOutDev)
+        if(&(pPageWindow->GetPaintWindow().GetOutputDevice()) == &rOutDev)
         {
-            return *a;
+            return pPageWindow.get();
         }
     }
 
@@ -96,32 +92,23 @@ SdrPageWindow* SdrPageView::FindPageWindow(const OutputDevice& rOutDev) const
 
 SdrPageWindow* SdrPageView::GetPageWindow(sal_uInt32 nIndex) const
 {
-    if(nIndex < maPageWindows.size())
-    {
-        return maPageWindows[nIndex];
-    }
-
-    return nullptr;
+    return maPageWindows[nIndex].get();
 }
 
 void SdrPageView::ClearPageWindows()
 {
-    for(SdrPageWindowVector::const_iterator a = maPageWindows.begin(); a != maPageWindows.end(); ++a)
-    {
-        delete *a;
-    }
-
     maPageWindows.clear();
 }
 
-SdrPageWindow* SdrPageView::RemovePageWindow(SdrPageWindow& rOld)
+std::unique_ptr<SdrPageWindow> SdrPageView::RemovePageWindow(SdrPageWindow& rOld)
 {
-    const SdrPageWindowVector::iterator aFindResult = ::std::find(maPageWindows.begin(), maPageWindows.end(), &rOld);
+    auto aFindResult = ::std::find_if(maPageWindows.begin(), maPageWindows.end(),
+                        [&](const std::unique_ptr<SdrPageWindow> & p) { return p.get() == &rOld; } );
 
     if(aFindResult != maPageWindows.end())
     {
         // remember return value
-        SdrPageWindow* pSdrPageWindow = *aFindResult;
+        std::unique_ptr<SdrPageWindow> pSdrPageWindow = std::move(*aFindResult);
         maPageWindows.erase(aFindResult);
         return pSdrPageWindow;
     }
@@ -164,27 +151,25 @@ SdrPageView::SdrPageView(SdrPage* pPage1, SdrView& rNewView)
 
 SdrPageView::~SdrPageView()
 {
-
-    // cleanup window vector
-    ClearPageWindows();
 }
 
 void SdrPageView::AddPaintWindowToPageView(SdrPaintWindow& rPaintWindow)
 {
     if(!FindPageWindow(rPaintWindow))
     {
-        maPageWindows.push_back(new SdrPageWindow(*this, rPaintWindow));
+        maPageWindows.emplace_back(new SdrPageWindow(*this, rPaintWindow));
     }
 }
 
 void SdrPageView::RemovePaintWindowFromPageView(SdrPaintWindow& rPaintWindow)
 {
-    SdrPageWindow* pCandidate = FindPageWindow(rPaintWindow);
-
-    if(pCandidate)
+    for(auto it = maPageWindows.begin(); it != maPageWindows.end(); ++it)
     {
-        pCandidate = RemovePageWindow(*pCandidate);
-        delete pCandidate;
+        if(&((*it)->GetPaintWindow()) == &rPaintWindow)
+        {
+            maPageWindows.erase(it);
+            break;
+        }
     }
 }
 


More information about the Libreoffice-commits mailing list