summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-10-30 14:22:23 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-11-02 08:14:10 +0100
commitb6df5604e2eafbe5857efcf9a5cb6440c47ffd16 (patch)
tree73df60947a299a2af3cc3182aeaea4a159faeaa7 /sd
parent13449ddc667008bfe0486e5e70110f4556609c3a (diff)
loplugin:useuniqueptr in SdCustomShowList
Change-Id: I604f4cd616ec6eb31198806456a660e7a1e915ca Reviewed-on: https://gerrit.libreoffice.org/62662 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sd')
-rw-r--r--sd/inc/cusshow.hxx2
-rw-r--r--sd/inc/customshowlist.hxx34
-rw-r--r--sd/source/core/cusshow.cxx6
-rw-r--r--sd/source/core/drawdoc.cxx14
-rw-r--r--sd/source/core/drawdoc3.cxx1
-rw-r--r--sd/source/core/drawdoc_animations.cxx2
-rw-r--r--sd/source/filter/ppt/pptin.cxx6
-rw-r--r--sd/source/ui/dlg/custsdlg.cxx44
-rw-r--r--sd/source/ui/dlg/sdtreelb.cxx2
-rw-r--r--sd/source/ui/inc/custsdlg.hxx5
-rw-r--r--sd/source/ui/unoidl/unocpres.cxx8
11 files changed, 58 insertions, 66 deletions
diff --git a/sd/inc/cusshow.hxx b/sd/inc/cusshow.hxx
index 612798bdc473..b8dafdd373aa 100644
--- a/sd/inc/cusshow.hxx
+++ b/sd/inc/cusshow.hxx
@@ -47,6 +47,8 @@ public:
// @@@ copy ctor, but no copy assignment? @@@
SdCustomShow( const SdCustomShow& rShow );
+ SdCustomShow& operator=( const SdCustomShow& rShow ) = delete;
+
/** Provides a direct access to the collection of the SdPage objects. */
PageVec& PagesVector() { return maPages;}
/**
diff --git a/sd/inc/customshowlist.hxx b/sd/inc/customshowlist.hxx
index 1d30473e5050..5c70f8a63522 100644
--- a/sd/inc/customshowlist.hxx
+++ b/sd/inc/customshowlist.hxx
@@ -20,14 +20,15 @@
#ifndef INCLUDED_SD_INC_CUSTOMSHOWLIST_HXX
#define INCLUDED_SD_INC_CUSTOMSHOWLIST_HXX
+#include "sddllapi.h"
#include <vector>
class SdCustomShow;
-class SdCustomShowList
+class SD_DLLPUBLIC SdCustomShowList
{
private:
- std::vector<SdCustomShow*> mShows;
+ std::vector<std::unique_ptr<SdCustomShow>> mShows;
sal_uInt16 mnCurPos;
public:
SdCustomShowList()
@@ -35,17 +36,20 @@ public:
{
}
+ SdCustomShowList& operator=( SdCustomShowList const & ) = delete; // MSVC2017 workaround
+ SdCustomShowList( SdCustomShowList const & ) = delete; // MSVC2017 workaround
+
bool empty() const {return mShows.empty();}
size_t size() const {return mShows.size();}
- SdCustomShow* &operator[](size_t i) {return mShows[i];}
+ std::unique_ptr<SdCustomShow>& operator[](size_t i) {return mShows[i];}
- std::vector<SdCustomShow*>::iterator begin() {return mShows.begin();}
+ std::vector<std::unique_ptr<SdCustomShow>>::iterator begin() {return mShows.begin();}
- void erase(std::vector<SdCustomShow*>::iterator it) {mShows.erase(it);}
+ void erase(std::vector<std::unique_ptr<SdCustomShow>>::iterator it);
- void push_back(SdCustomShow* p) {mShows.push_back(p);}
+ void push_back(std::unique_ptr<SdCustomShow> p) {mShows.push_back(std::move(p));}
sal_uInt16 GetCurPos() const { return mnCurPos; }
void Seek(sal_uInt16 nNewPos) { mnCurPos = nNewPos; }
@@ -55,12 +59,12 @@ public:
if( mShows.empty() )
return nullptr;
mnCurPos = 0;
- return mShows[mnCurPos];
+ return mShows[mnCurPos].get();
}
SdCustomShow* Next()
{
++mnCurPos;
- return mnCurPos >= mShows.size() ? nullptr : mShows[mnCurPos];
+ return mnCurPos >= mShows.size() ? nullptr : mShows[mnCurPos].get();
}
void Last()
{
@@ -69,15 +73,15 @@ public:
}
SdCustomShow* GetCurObject()
{
- return mShows.empty() ? nullptr : mShows[mnCurPos];
+ return mShows.empty() ? nullptr : mShows[mnCurPos].get();
}
- SdCustomShow* Remove(SdCustomShow* p)
+ void erase(SdCustomShow* p)
{
- std::vector<SdCustomShow*>::iterator it = std::find(mShows.begin(), mShows.end(), p);
- if( it == mShows.end() )
- return nullptr;
- mShows.erase(it);
- return p;
+ auto it = std::find_if(mShows.begin(), mShows.end(),
+ [&] (std::unique_ptr<SdCustomShow> const &i) { return i.get() == p; });
+ assert( it != mShows.end() );
+ if( it != mShows.end() )
+ mShows.erase(it);
}
};
diff --git a/sd/source/core/cusshow.cxx b/sd/source/core/cusshow.cxx
index 48424999c79c..83b569617354 100644
--- a/sd/source/core/cusshow.cxx
+++ b/sd/source/core/cusshow.cxx
@@ -24,6 +24,7 @@
#include <cusshow.hxx>
#include <sdpage.hxx>
#include <drawdoc.hxx>
+#include <customshowlist.hxx>
#include <tools/tenccvt.hxx>
@@ -99,4 +100,9 @@ void SdCustomShow::SetName(const OUString& rName)
aName = rName;
}
+void SdCustomShowList::erase(std::vector<std::unique_ptr<SdCustomShow>>::iterator it)
+{
+ mShows.erase(it);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/core/drawdoc.cxx b/sd/source/core/drawdoc.cxx
index 3376b022de84..8580d9982b4b 100644
--- a/sd/source/core/drawdoc.cxx
+++ b/sd/source/core/drawdoc.cxx
@@ -380,19 +380,7 @@ SdDrawDocument::~SdDrawDocument()
}
maFrameViewList.clear();
-
- if (mpCustomShowList)
- {
- for (sal_uLong j = 0; j < mpCustomShowList->size(); j++)
- {
- // If necessary, delete CustomShows
- SdCustomShow* pCustomShow = (*mpCustomShowList)[j];
- delete pCustomShow;
- }
-
- mpCustomShowList.reset();
- }
-
+ mpCustomShowList.reset();
mpOutliner.reset();
mpInternalOutliner.reset();
mpCharClass.reset();
diff --git a/sd/source/core/drawdoc3.cxx b/sd/source/core/drawdoc3.cxx
index 298fc125f6f1..e340a930cd78 100644
--- a/sd/source/core/drawdoc3.cxx
+++ b/sd/source/core/drawdoc3.cxx
@@ -49,6 +49,7 @@
#include <strmname.h>
#include <anminfo.hxx>
#include <customshowlist.hxx>
+#include <cusshow.hxx>
#include <sdxfer.hxx>
#include <unmovss.hxx>
diff --git a/sd/source/core/drawdoc_animations.cxx b/sd/source/core/drawdoc_animations.cxx
index bf1ef64266bc..f4d2d51fcab8 100644
--- a/sd/source/core/drawdoc_animations.cxx
+++ b/sd/source/core/drawdoc_animations.cxx
@@ -36,7 +36,7 @@ void SdDrawDocument::ReplacePageInCustomShows( const SdPage* pOldPage, const SdP
{
for (sal_uLong i = 0; i < mpCustomShowList->size(); i++)
{
- SdCustomShow* pCustomShow = (*mpCustomShowList)[i];
+ SdCustomShow* pCustomShow = (*mpCustomShowList)[i].get();
pCustomShow->ReplacePage(pOldPage, pNewPage);
}
}
diff --git a/sd/source/filter/ppt/pptin.cxx b/sd/source/filter/ppt/pptin.cxx
index 0d7842a6db8c..7fa7ad359a02 100644
--- a/sd/source/filter/ppt/pptin.cxx
+++ b/sd/source/filter/ppt/pptin.cxx
@@ -1304,7 +1304,7 @@ bool ImplSdPPTImport::Import()
SdCustomShowList* pList = mpDoc->GetCustomShowList( true );
if ( pList )
{
- SdCustomShow* pSdCustomShow = new SdCustomShow;
+ std::unique_ptr<SdCustomShow> pSdCustomShow(new SdCustomShow);
pSdCustomShow->SetName( aCuShow );
sal_uInt32 nFound = 0;
for ( sal_uInt32 nS = 0; nS < nSCount; nS++ )
@@ -1323,9 +1323,7 @@ bool ImplSdPPTImport::Import()
}
}
if ( nFound )
- pList->push_back( pSdCustomShow );
- else
- delete pSdCustomShow;
+ pList->push_back( std::move(pSdCustomShow) );
}
}
}
diff --git a/sd/source/ui/dlg/custsdlg.cxx b/sd/source/ui/dlg/custsdlg.cxx
index e610fe222875..4ece6d0e9c8f 100644
--- a/sd/source/ui/dlg/custsdlg.cxx
+++ b/sd/source/ui/dlg/custsdlg.cxx
@@ -37,7 +37,6 @@ SdCustomShowDlg::SdCustomShowDlg(weld::Window* pWindow, SdDrawDocument& rDrawDoc
: GenericDialogController(pWindow, "modules/simpress/ui/customslideshows.ui", "CustomSlideShows")
, rDoc(rDrawDoc)
, pCustomShowList(nullptr)
- , pCustomShow(nullptr)
, bModified(false)
, m_xLbCustomShows(m_xBuilder->weld_tree_view("customshowlist"))
, m_xCbxUseCustomShow(m_xBuilder->weld_check_button("usecustomshows"))
@@ -68,7 +67,7 @@ SdCustomShowDlg::SdCustomShowDlg(weld::Window* pWindow, SdDrawDocument& rDrawDoc
{
long nPosToSelect = pCustomShowList->GetCurPos();
// fill ListBox with CustomShows
- for( pCustomShow = pCustomShowList->First();
+ for( SdCustomShow* pCustomShow = pCustomShowList->First();
pCustomShow != nullptr;
pCustomShow = pCustomShowList->Next() )
{
@@ -117,7 +116,7 @@ void SdCustomShowDlg::SelectHdl(void const *p)
// new CustomShow
if (p == m_xBtnNew.get())
{
- pCustomShow = nullptr;
+ std::unique_ptr<SdCustomShow> pCustomShow;
SdDefineCustomShowDlg aDlg(m_xDialog.get(), rDoc, pCustomShow);
if (aDlg.run() == RET_OK)
{
@@ -126,17 +125,16 @@ void SdCustomShowDlg::SelectHdl(void const *p)
if( !pCustomShowList )
pCustomShowList = rDoc.GetCustomShowList( true );
- pCustomShowList->push_back( pCustomShow );
+ SdCustomShow* pCustomShowTmp = pCustomShow.get();
+ pCustomShowList->push_back( std::move(pCustomShow) );
pCustomShowList->Last();
- m_xLbCustomShows->append_text( pCustomShow->GetName() );
- m_xLbCustomShows->select_text( pCustomShow->GetName() );
+ m_xLbCustomShows->append_text( pCustomShowTmp->GetName() );
+ m_xLbCustomShows->select_text( pCustomShowTmp->GetName() );
}
if (aDlg.IsModified())
bModified = true;
}
- else if( pCustomShow )
- DELETEZ( pCustomShow );
}
// edit CustomShow
else if( p == m_xBtnEdit.get() )
@@ -145,19 +143,15 @@ void SdCustomShowDlg::SelectHdl(void const *p)
if (nPos != -1)
{
DBG_ASSERT( pCustomShowList, "pCustomShowList does not exist" );
- pCustomShow = (*pCustomShowList)[ nPos ];
+ std::unique_ptr<SdCustomShow>& pCustomShow = (*pCustomShowList)[ nPos ];
SdDefineCustomShowDlg aDlg(m_xDialog.get(), rDoc, pCustomShow);
if (aDlg.run() == RET_OK)
{
- if( pCustomShow )
- {
- (*pCustomShowList)[nPos] = pCustomShow;
- pCustomShowList->Seek(nPos);
- m_xLbCustomShows->remove(nPos);
- m_xLbCustomShows->insert_text(nPos, pCustomShow->GetName());
- m_xLbCustomShows->select(nPos);
- }
+ pCustomShowList->Seek(nPos);
+ m_xLbCustomShows->remove(nPos);
+ m_xLbCustomShows->insert_text(nPos, pCustomShow->GetName());
+ m_xLbCustomShows->select(nPos);
if (aDlg.IsModified())
bModified = true;
}
@@ -169,7 +163,6 @@ void SdCustomShowDlg::SelectHdl(void const *p)
int nPos = m_xLbCustomShows->get_selected_index();
if (nPos != -1)
{
- delete (*pCustomShowList)[nPos];
pCustomShowList->erase( pCustomShowList->begin() + nPos );
m_xLbCustomShows->remove(nPos);
m_xLbCustomShows->select(nPos == 0 ? nPos : nPos - 1);
@@ -182,7 +175,7 @@ void SdCustomShowDlg::SelectHdl(void const *p)
int nPos = m_xLbCustomShows->get_selected_index();
if (nPos != -1)
{
- SdCustomShow* pShow = new SdCustomShow( *(*pCustomShowList)[nPos] );
+ std::unique_ptr<SdCustomShow> pShow(new SdCustomShow( *(*pCustomShowList)[nPos] ));
OUString aStr( pShow->GetName() );
OUString aStrCopy( SdResId( STR_COPY_CUSTOMSHOW ) );
@@ -206,7 +199,7 @@ void SdCustomShowDlg::SelectHdl(void const *p)
while( !bDifferent )
{
bDifferent = true;
- for( pCustomShow = pCustomShowList->First();
+ for( SdCustomShow* pCustomShow = pCustomShowList->First();
pCustomShow != nullptr && bDifferent;
pCustomShow = pCustomShowList->Next() )
{
@@ -227,10 +220,11 @@ void SdCustomShowDlg::SelectHdl(void const *p)
//pCustomShowList->Seek( nPosToSelect );
pShow->SetName( aStr );
- pCustomShowList->push_back( pShow );
+ auto pShowTmp = pShow.get();
+ pCustomShowList->push_back( std::move(pShow) );
pCustomShowList->Last();
- m_xLbCustomShows->append_text(pShow->GetName());
- m_xLbCustomShows->select_text(pShow->GetName());
+ m_xLbCustomShows->append_text(pShowTmp->GetName());
+ m_xLbCustomShows->select_text(pShowTmp->GetName());
bModified = true;
}
@@ -264,7 +258,7 @@ bool SdCustomShowDlg::IsCustomShow() const
}
// SdDefineCustomShowDlg
-SdDefineCustomShowDlg::SdDefineCustomShowDlg(weld::Window* pWindow, SdDrawDocument& rDrawDoc, SdCustomShow*& rpCS)
+SdDefineCustomShowDlg::SdDefineCustomShowDlg(weld::Window* pWindow, SdDrawDocument& rDrawDoc, std::unique_ptr<SdCustomShow>& rpCS)
: GenericDialogController(pWindow, "modules/simpress/ui/definecustomslideshow.ui", "DefineCustomSlideShow")
, rDoc(rDrawDoc)
, rpCustomShow(rpCS)
@@ -317,7 +311,7 @@ SdDefineCustomShowDlg::SdDefineCustomShowDlg(weld::Window* pWindow, SdDrawDocume
}
else
{
- rpCustomShow = new SdCustomShow;
+ rpCustomShow.reset(new SdCustomShow);
m_xEdtName->set_text( SdResId( STR_NEW_CUSTOMSHOW ) );
m_xEdtName->select_region(0, -1);
rpCustomShow->SetName( m_xEdtName->get_text() );
diff --git a/sd/source/ui/dlg/sdtreelb.cxx b/sd/source/ui/dlg/sdtreelb.cxx
index 95f85579a746..d76038ba1481 100644
--- a/sd/source/ui/dlg/sdtreelb.cxx
+++ b/sd/source/ui/dlg/sdtreelb.cxx
@@ -1237,7 +1237,7 @@ bool SdPageObjsTLB::PageBelongsToCurrentShow (const SdPage* pPage) const
if (pShowList != nullptr)
{
sal_uLong nCurrentShowIndex = pShowList->GetCurPos();
- pCustomShow = (*pShowList)[nCurrentShowIndex];
+ pCustomShow = (*pShowList)[nCurrentShowIndex].get();
}
// Check whether the given page is part of that custom show.
diff --git a/sd/source/ui/inc/custsdlg.hxx b/sd/source/ui/inc/custsdlg.hxx
index c02a9df48892..b114a48758e1 100644
--- a/sd/source/ui/inc/custsdlg.hxx
+++ b/sd/source/ui/inc/custsdlg.hxx
@@ -31,7 +31,6 @@ class SdCustomShowDlg : public weld::GenericDialogController
private:
SdDrawDocument& rDoc;
SdCustomShowList* pCustomShowList;
- SdCustomShow* pCustomShow;
bool bModified;
std::unique_ptr<weld::TreeView> m_xLbCustomShows;
@@ -62,7 +61,7 @@ class SdDefineCustomShowDlg : public weld::GenericDialogController
{
private:
SdDrawDocument& rDoc;
- SdCustomShow*& rpCustomShow;
+ std::unique_ptr<SdCustomShow>& rpCustomShow;
bool bModified;
OUString aOldName;
@@ -87,7 +86,7 @@ private:
public:
- SdDefineCustomShowDlg(weld::Window* pWindow, SdDrawDocument& rDrawDoc, SdCustomShow*& rpCS);
+ SdDefineCustomShowDlg(weld::Window* pWindow, SdDrawDocument& rDrawDoc, std::unique_ptr<SdCustomShow>& rpCS);
virtual ~SdDefineCustomShowDlg() override;
bool IsModified() const { return bModified; }
diff --git a/sd/source/ui/unoidl/unocpres.cxx b/sd/source/ui/unoidl/unocpres.cxx
index e7a25751d17f..1ad8cc975d3c 100644
--- a/sd/source/ui/unoidl/unocpres.cxx
+++ b/sd/source/ui/unoidl/unocpres.cxx
@@ -350,7 +350,7 @@ void SAL_CALL SdXCustomPresentationAccess::insertByName( const OUString& aName,
throw container::ElementExistException();
}
- pList->push_back(pShow);
+ pList->push_back(std::unique_ptr<SdCustomShow>(pShow));
mrModel.SetModified();
}
@@ -365,7 +365,7 @@ void SAL_CALL SdXCustomPresentationAccess::removeByName( const OUString& Name )
if(!pList || !pShow)
throw container::NoSuchElementException();
- delete pList->Remove( pShow );
+ pList->erase( pShow );
mrModel.SetModified();
}
@@ -405,7 +405,7 @@ uno::Sequence< OUString > SAL_CALL SdXCustomPresentationAccess::getElementNames(
sal_uInt32 nIdx = 0;
while( nIdx < nCount )
{
- const SdCustomShow* pShow = (*pList)[nIdx];
+ const SdCustomShow* pShow = (*pList)[nIdx].get();
pStringList[nIdx] = pShow->GetName();
nIdx++;
}
@@ -442,7 +442,7 @@ SdCustomShow * SdXCustomPresentationAccess::getSdCustomShow( const OUString& rNa
while( nIdx < nCount )
{
- SdCustomShow* pShow = (*pList)[nIdx];
+ SdCustomShow* pShow = (*pList)[nIdx].get();
if( pShow->GetName() == rName )
return pShow;
nIdx++;