diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-28 13:59:32 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-02 12:51:42 +0200 |
commit | 25f23c6570f909a8dfd2c7b0a78d43d59868a5f9 (patch) | |
tree | 3604fdf61c03eb08c32de372789346c7ed60b6d7 /svx | |
parent | 800bf1071a30955ff70373b2fb5886eadce59dee (diff) |
loplugin:useuniqueptr in SdrPageView
Change-Id: I85aaf0f28c30055003b48209d15b1b496c234e4b
Reviewed-on: https://gerrit.libreoffice.org/61120
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/svdraw/svdpagv.cxx | 57 |
1 files changed, 21 insertions, 36 deletions
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; + } } } |