summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-08-13 15:31:04 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-08-15 14:31:57 +0200
commit95fe8fa97a62ae90b6d092c52d2fc6fae198e011 (patch)
treeb2bed821a48e70f3ea6f75466b77a4070a89aa61 /svx
parent5779b4966954d845f3c526c340bdee8c6a92ef95 (diff)
loplugin:useuniqueptr in GalleryTheme
Change-Id: I6c709b9c38f24af37b355f85e5957790eb20a326 Reviewed-on: https://gerrit.libreoffice.org/59022 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/gallery2/galtheme.cxx121
1 files changed, 46 insertions, 75 deletions
diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx
index 31fac1269a4d..02d8d07a7236 100644
--- a/svx/source/gallery2/galtheme.cxx
+++ b/svx/source/gallery2/galtheme.cxx
@@ -79,11 +79,11 @@ GalleryTheme::~GalleryTheme()
{
ImplWrite();
- for (GalleryObject* pEntry : aObjectList)
+ for (auto & pEntry : aObjectList)
{
- Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pEntry ) );
- Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED, GetName(), pEntry ) );
- delete pEntry;
+ Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pEntry.get() ) );
+ Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED, GetName(), pEntry.get() ) );
+ pEntry.reset();
}
aObjectList.clear();
@@ -126,12 +126,10 @@ bool GalleryTheme::ImplWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, Ga
pEntry = new GalleryObject;
if ( nPos < aObjectList.size() )
{
- GalleryObjectList::iterator it = aObjectList.begin();
- ::std::advance( it, nPos );
- aObjectList.insert( it, pEntry );
+ aObjectList.emplace( aObjectList.begin() + nPos, pEntry );
}
else
- aObjectList.push_back( pEntry );
+ aObjectList.emplace_back( pEntry );
}
else
pEntry = pExistentEntry;
@@ -222,9 +220,9 @@ void GalleryTheme::ImplWrite()
const GalleryObject* GalleryTheme::ImplGetGalleryObject( const INetURLObject& rURL )
{
- for (GalleryObject* i : aObjectList)
+ for (auto const & i : aObjectList)
if ( i->aURL == rURL )
- return i;
+ return i.get();
return nullptr;
}
@@ -295,7 +293,7 @@ INetURLObject GalleryTheme::ImplCreateUniqueURL( SgaObjKind eObjKind, ConvertDat
bExists = false;
- for (GalleryObject* p : aObjectList)
+ for (auto const & p : aObjectList)
if ( p->aURL == aNewURL )
{
bExists = true;
@@ -375,7 +373,7 @@ bool GalleryTheme::InsertObject(const SgaObject& rObj, sal_uInt32 nInsertPos)
{
if (aObjectList[ iFoundPos ]->aURL == rObj.GetURL())
{
- pFoundEntry = aObjectList[ iFoundPos ];
+ pFoundEntry = aObjectList[ iFoundPos ].get();
break;
}
}
@@ -416,64 +414,42 @@ std::unique_ptr<SgaObject> GalleryTheme::AcquireObject(sal_uInt32 nPos)
void GalleryTheme::GetPreviewBitmapExAndStrings(sal_uInt32 nPos, BitmapEx& rBitmapEx, Size& rSize, OUString& rTitle, OUString& rPath) const
{
- const GalleryObject* pGalleryObject = nPos < aObjectList.size() ? aObjectList[ nPos ] : nullptr;
+ const GalleryObject* pGalleryObject = aObjectList[ nPos ].get();
- if(pGalleryObject)
- {
- rBitmapEx = pGalleryObject->maPreviewBitmapEx;
- rSize = pGalleryObject->maPreparedSize;
- rTitle = pGalleryObject->maTitle;
- rPath = pGalleryObject->maPath;
- }
- else
- {
- OSL_ENSURE(false, "OOps, no GalleryObject at this index (!)");
- }
+ rBitmapEx = pGalleryObject->maPreviewBitmapEx;
+ rSize = pGalleryObject->maPreparedSize;
+ rTitle = pGalleryObject->maTitle;
+ rPath = pGalleryObject->maPath;
}
void GalleryTheme::SetPreviewBitmapExAndStrings(sal_uInt32 nPos, const BitmapEx& rBitmapEx, const Size& rSize, const OUString& rTitle, const OUString& rPath)
{
- GalleryObject* pGalleryObject = nPos < aObjectList.size() ? aObjectList[ nPos ] : nullptr;
+ GalleryObject* pGalleryObject = aObjectList[ nPos ].get();
- if(pGalleryObject)
- {
- pGalleryObject->maPreviewBitmapEx = rBitmapEx;
- pGalleryObject->maPreparedSize = rSize;
- pGalleryObject->maTitle = rTitle;
- pGalleryObject->maPath = rPath;
- }
- else
- {
- OSL_ENSURE(false, "OOps, no GalleryObject at this index (!)");
- }
+ pGalleryObject->maPreviewBitmapEx = rBitmapEx;
+ pGalleryObject->maPreparedSize = rSize;
+ pGalleryObject->maTitle = rTitle;
+ pGalleryObject->maPath = rPath;
}
void GalleryTheme::RemoveObject(sal_uInt32 nPos)
{
- GalleryObject* pEntry = nullptr;
- if ( nPos < aObjectList.size() )
- {
- GalleryObjectList::iterator it = aObjectList.begin();
- ::std::advance( it, nPos );
- pEntry = *it;
- aObjectList.erase( it );
- }
+ auto it = aObjectList.begin() + nPos;
+ std::unique_ptr<GalleryObject> pEntry = std::move(*it);
+ aObjectList.erase( it );
if( aObjectList.empty() )
KillFile( GetSdgURL() );
- if( pEntry )
- {
- if( SgaObjKind::SvDraw == pEntry->eObjKind )
- aSvDrawStorageRef->Remove( pEntry->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
+ if( SgaObjKind::SvDraw == pEntry->eObjKind )
+ aSvDrawStorageRef->Remove( pEntry->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
- Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pEntry ) );
- Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED, GetName(), pEntry ) );
- delete pEntry;
+ Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pEntry.get() ) );
+ Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED, GetName(), pEntry.get() ) );
+ pEntry.reset();
- ImplSetModified( true );
- ImplBroadcast( nPos );
- }
+ ImplSetModified( true );
+ ImplBroadcast( nPos );
}
bool GalleryTheme::ChangeObjectPos(sal_uInt32 nOldPos, sal_uInt32 nNewPos)
@@ -481,17 +457,14 @@ bool GalleryTheme::ChangeObjectPos(sal_uInt32 nOldPos, sal_uInt32 nNewPos)
if (nOldPos == nNewPos || nOldPos >= aObjectList.size())
return false;
- GalleryObject* pEntry = aObjectList[nOldPos];
+ std::unique_ptr<GalleryObject> pEntry = std::move(aObjectList[nOldPos]);
- GalleryObjectList::iterator it = aObjectList.begin();
- ::std::advance(it, nNewPos);
- aObjectList.insert(it, pEntry);
+ aObjectList.insert(aObjectList.begin() + nNewPos, std::move(pEntry));
if (nNewPos < nOldPos)
nOldPos++;
- it = aObjectList.begin();
- ::std::advance(it, nOldPos);
+ auto it = aObjectList.begin() + nOldPos;
aObjectList.erase(it);
ImplSetModified(true);
@@ -507,7 +480,6 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize
Graphic aGraphic;
OUString aFormat;
- GalleryObject* pEntry;
const sal_uInt32 nCount = aObjectList.size();
LockBroadcaster();
@@ -522,7 +494,7 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize
if( pProgress )
pProgress->Update( i, nCount - 1 );
- pEntry = aObjectList[ i ];
+ GalleryObject* pEntry = aObjectList[ i ].get();
const INetURLObject aURL( pEntry->aURL );
@@ -585,16 +557,16 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize
}
// remove all entries with set flag
- for ( GalleryObjectList::iterator it = aObjectList.begin(); it != aObjectList.end(); /* increment is in the body of loop */)
+ for ( auto it = aObjectList.begin(); it != aObjectList.end(); /* increment is in the body of loop */)
{
if( (*it)->mbDelete )
{
- Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), *it ) );
- Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED, GetName(), *it ) );
- delete *it;
+ Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), it->get() ) );
+ Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED, GetName(), it->get() ) );
it = aObjectList.erase( it );
}
- else ++it;
+ else
+ ++it;
}
// update theme
@@ -610,9 +582,9 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize
if( pIStm && pTmpStm )
{
- for (GalleryObject* i : aObjectList)
+ for (auto & i : aObjectList)
{
- pEntry = i;
+ GalleryObject* pEntry = i.get();
std::unique_ptr<SgaObject> pObj;
switch( pEntry->eObjKind )
@@ -1371,24 +1343,23 @@ SvStream& GalleryTheme::ReadData( SvStream& rIStm )
if( nCount <= ( 1 << 14 ) )
{
- GalleryObject* pObj;
INetURLObject aRelURL1( GetParent()->GetRelativeURL() );
INetURLObject aRelURL2( GetParent()->GetUserURL() );
sal_uInt32 nId1, nId2;
bool bRel;
- for(GalleryObject* i : aObjectList)
+ for(auto & i : aObjectList)
{
- pObj = i;
+ GalleryObject* pObj = i.get();
Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pObj ) );
Broadcast( GalleryHint( GalleryHintType::OBJECT_REMOVED, GetName(), pObj ) );
- delete pObj;
+ i.reset();
}
aObjectList.clear();
for( sal_uInt32 i = 0; i < nCount; i++ )
{
- pObj = new GalleryObject;
+ std::unique_ptr<GalleryObject> pObj(new GalleryObject);
OUString aFileName;
OUString aPath;
@@ -1446,7 +1417,7 @@ SvStream& GalleryTheme::ReadData( SvStream& rIStm )
}
}
}
- aObjectList.push_back( pObj );
+ aObjectList.push_back( std::move(pObj) );
}
rIStm.ReadUInt32( nId1 ).ReadUInt32( nId2 );