Kaydet (Commit) 72c191e0 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in ThumbnailView

Change-Id: I95817a03afedbee4ffb28041a9834e591356102d
Reviewed-on: https://gerrit.libreoffice.org/60953
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst daf44342
...@@ -185,7 +185,7 @@ public: ...@@ -185,7 +185,7 @@ public:
virtual void MouseMove(const MouseEvent& rMEvt) override; virtual void MouseMove(const MouseEvent& rMEvt) override;
void AppendItem(ThumbnailViewItem *pItem); void AppendItem(std::unique_ptr<ThumbnailViewItem> pItem);
void RemoveItem(sal_uInt16 nItemId); void RemoveItem(sal_uInt16 nItemId);
...@@ -195,7 +195,7 @@ public: ...@@ -195,7 +195,7 @@ public:
virtual void Reload() {} virtual void Reload() {}
// Change current thumbnail item list with new one (invalidates all pointers to a thumbnail item) // 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; size_t GetItemPos( sal_uInt16 nItemId ) const;
...@@ -288,7 +288,7 @@ protected: ...@@ -288,7 +288,7 @@ protected:
protected: protected:
ThumbnailValueItemList mItemList; std::vector< std::unique_ptr<ThumbnailViewItem> > mItemList;
ThumbnailValueItemList mFilteredItemList; ///< Cache to store the filtered items ThumbnailValueItemList mFilteredItemList; ///< Cache to store the filtered items
ThumbnailValueItemList::iterator mpStartSelRange; ThumbnailValueItemList::iterator mpStartSelRange;
VclPtr<ScrollBar> mpScrBar; VclPtr<ScrollBar> mpScrBar;
......
...@@ -209,13 +209,13 @@ void EmojiView::setInsertEmojiHdl(const Link<ThumbnailViewItem*, void> &rLink) ...@@ -209,13 +209,13 @@ void EmojiView::setInsertEmojiHdl(const Link<ThumbnailViewItem*, void> &rLink)
void EmojiView::AppendItem(const OUString &rTitle, const OUString &rCategory, const OUString &rName) 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->maTitle = rTitle;
pItem->setCategory(rCategory); pItem->setCategory(rCategory);
pItem->setHelpText(rName); pItem->setHelpText(rName);
ThumbnailView::AppendItem(pItem); ThumbnailView::AppendItem(std::move(pItem));
CalculateItemPositions(); CalculateItemPositions();
} }
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <bitmaps.hlst> #include <bitmaps.hlst>
#include <officecfg/Office/Common.hxx> #include <officecfg/Office/Common.hxx>
#include <o3tl/make_unique.hxx>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
...@@ -216,9 +217,7 @@ BitmapEx RecentDocsView::getDefaultThumbnail(const OUString &rURL) ...@@ -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) 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( o3tl::make_unique<RecentDocsViewItem>(*this, rURL, rTitle, rThumbnail, nId, mnItemMaxSize) );
AppendItem(pChild);
} }
void RecentDocsView::Reload() void RecentDocsView::Reload()
......
...@@ -548,8 +548,9 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_ ...@@ -548,8 +548,9 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_
// Keep view document id synchronized with SfxDocumentTemplates // Keep view document id synchronized with SfxDocumentTemplates
for (auto const& item : mItemList) for (auto const& item : mItemList)
{ {
if (static_cast<TemplateViewItem*>(item)->mnDocId > pViewItem->mnDocId) auto pTemplateViewItem = static_cast<TemplateViewItem*>(item.get());
--static_cast<TemplateViewItem*>(item)->mnDocId; if (pTemplateViewItem->mnDocId > pViewItem->mnDocId)
--pTemplateViewItem->mnDocId;
} }
} }
...@@ -658,8 +659,9 @@ void TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, s ...@@ -658,8 +659,9 @@ void TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, s
// Keep view document id synchronized with SfxDocumentTemplates // Keep view document id synchronized with SfxDocumentTemplates
for (auto const& item : mItemList) for (auto const& item : mItemList)
{ {
if (static_cast<TemplateViewItem*>(item)->mnDocId > pViewItem->mnDocId) auto pTemplateViewItem = static_cast<TemplateViewItem*>(item.get());
--static_cast<TemplateViewItem*>(item)->mnDocId; if (pTemplateViewItem->mnDocId > pViewItem->mnDocId)
--pTemplateViewItem->mnDocId;
} }
} }
} }
...@@ -753,16 +755,16 @@ bool TemplateLocalView::renameItem(ThumbnailViewItem* pItem, const OUString& sNe ...@@ -753,16 +755,16 @@ bool TemplateLocalView::renameItem(ThumbnailViewItem* pItem, const OUString& sNe
void TemplateLocalView::insertItems(const std::vector<TemplateItemProperties> &rTemplates, bool isRegionSelected, bool bShowCategoryInTooltip) 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 ) for (size_t i = 0, n = rTemplates.size(); i < n; ++i )
{ {
const TemplateItemProperties *pCur = &rTemplates[i]; const TemplateItemProperties *pCur = &rTemplates[i];
TemplateViewItem *pChild; std::unique_ptr<TemplateViewItem> pChild;
if(isRegionSelected) if(isRegionSelected)
pChild = new TemplateViewItem(*this, pCur->nId); pChild.reset(new TemplateViewItem(*this, pCur->nId));
else else
pChild = new TemplateViewItem(*this, i+1); pChild.reset(new TemplateViewItem(*this, i+1));
pChild->mnDocId = pCur->nDocId; pChild->mnDocId = pCur->nDocId;
pChild->mnRegionId = pCur->nRegionId; pChild->mnRegionId = pCur->nRegionId;
...@@ -789,10 +791,10 @@ void TemplateLocalView::insertItems(const std::vector<TemplateItemProperties> &r ...@@ -789,10 +791,10 @@ void TemplateLocalView::insertItems(const std::vector<TemplateItemProperties> &r
pChild->maPreview1 = TemplateLocalView::getDefaultThumbnail(pCur->aPath); 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) void TemplateLocalView::updateThumbnailDimensions(long itemMaxSize)
...@@ -976,9 +978,9 @@ bool TemplateLocalView::IsDefaultTemplate(const OUString& rPath) ...@@ -976,9 +978,9 @@ bool TemplateLocalView::IsDefaultTemplate(const OUString& rPath)
void TemplateLocalView::RemoveDefaultTemplateIcon(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)) if (pViewItem && pViewItem->getPath().match(rPath))
{ {
pViewItem->showDefaultIcon(false); pViewItem->showDefaultIcon(false);
......
...@@ -216,7 +216,7 @@ void TemplateSearchView::AppendItem(sal_uInt16 nAssocItemId, sal_uInt16 nRegionI ...@@ -216,7 +216,7 @@ void TemplateSearchView::AppendItem(sal_uInt16 nAssocItemId, sal_uInt16 nRegionI
const OUString &rPath, const OUString &rPath,
const BitmapEx &rImage) const BitmapEx &rImage)
{ {
TemplateSearchViewItem *pItem = new TemplateSearchViewItem(*this, getNextItemId()); std::unique_ptr<TemplateSearchViewItem> pItem(new TemplateSearchViewItem(*this, getNextItemId()));
pItem->mnAssocId = nAssocItemId; pItem->mnAssocId = nAssocItemId;
pItem->mnDocId = nIdx; pItem->mnDocId = nIdx;
pItem->mnRegionId = nRegionId; pItem->mnRegionId = nRegionId;
...@@ -233,7 +233,7 @@ void TemplateSearchView::AppendItem(sal_uInt16 nAssocItemId, sal_uInt16 nRegionI ...@@ -233,7 +233,7 @@ void TemplateSearchView::AppendItem(sal_uInt16 nAssocItemId, sal_uInt16 nRegionI
if(TemplateLocalView::IsDefaultTemplate(rPath)) if(TemplateLocalView::IsDefaultTemplate(rPath))
pItem->showDefaultIcon(true); pItem->showDefaultIcon(true);
ThumbnailView::AppendItem(pItem); ThumbnailView::AppendItem(std::move(pItem));
CalculateItemPositions(); CalculateItemPositions();
} }
......
...@@ -101,9 +101,9 @@ void ThumbnailView::MouseMove(const MouseEvent& rMEvt) ...@@ -101,9 +101,9 @@ void ThumbnailView::MouseMove(const MouseEvent& rMEvt)
SetQuickHelpText(aHelp); 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 // Save current start,end range, iterator might get invalidated
size_t nSelStartPos = 0; size_t nSelStartPos = 0;
...@@ -115,11 +115,11 @@ void ThumbnailView::AppendItem(ThumbnailViewItem *pItem) ...@@ -115,11 +115,11 @@ void ThumbnailView::AppendItem(ThumbnailViewItem *pItem)
nSelStartPos = mpStartSelRange - mFilteredItemList.begin(); nSelStartPos = mpStartSelRange - mFilteredItemList.begin();
} }
mFilteredItemList.push_back(pItem); mFilteredItemList.push_back(pItem.get());
mpStartSelRange = pSelStartItem != nullptr ? mFilteredItemList.begin() + nSelStartPos : mFilteredItemList.end(); mpStartSelRange = pSelStartItem != nullptr ? mFilteredItemList.begin() + nSelStartPos : mFilteredItemList.end();
} }
mItemList.push_back(pItem); mItemList.push_back(std::move(pItem));
} }
void ThumbnailView::ImplInit() void ThumbnailView::ImplInit()
...@@ -159,7 +159,7 @@ void ThumbnailView::ImplDeleteItems() ...@@ -159,7 +159,7 @@ void ThumbnailView::ImplDeleteItems()
for ( size_t i = 0; i < n; ++i ) 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 // deselect all current selected items and fire events
if (pItem->isSelected()) if (pItem->isSelected())
...@@ -178,7 +178,7 @@ void ThumbnailView::ImplDeleteItems() ...@@ -178,7 +178,7 @@ void ThumbnailView::ImplDeleteItems()
ImplFireAccessibleEvent( css::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny ); ImplFireAccessibleEvent( css::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
} }
delete pItem; mItemList[i].reset();
} }
mItemList.clear(); mItemList.clear();
...@@ -456,7 +456,7 @@ ThumbnailViewItem* ThumbnailView::ImplGetVisibleItem( sal_uInt16 nVisiblePos ) ...@@ -456,7 +456,7 @@ ThumbnailViewItem* ThumbnailView::ImplGetVisibleItem( sal_uInt16 nVisiblePos )
for ( size_t n = 0; n < nItemCount; ++n ) for ( size_t n = 0; n < nItemCount; ++n )
{ {
ThumbnailViewItem *const pItem = mItemList[n]; ThumbnailViewItem *const pItem = mItemList[n].get();
if ( pItem->isVisible() && !nVisiblePos-- ) if ( pItem->isVisible() && !nVisiblePos-- )
return pItem; return pItem;
...@@ -848,7 +848,7 @@ void ThumbnailView::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rec ...@@ -848,7 +848,7 @@ void ThumbnailView::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rec
// draw items // draw items
for (size_t i = 0; i < nItemCount; i++) for (size_t i = 0; i < nItemCount; i++)
{ {
ThumbnailViewItem *const pItem = mItemList[i]; ThumbnailViewItem *const pItem = mItemList[i].get();
if (pItem->isVisible()) if (pItem->isVisible())
{ {
...@@ -1005,14 +1005,14 @@ void ThumbnailView::Clear() ...@@ -1005,14 +1005,14 @@ void ThumbnailView::Clear()
Invalidate(); Invalidate();
} }
void ThumbnailView::updateItems (const std::vector<ThumbnailViewItem*> &items) void ThumbnailView::updateItems (std::vector<std::unique_ptr<ThumbnailViewItem>> items)
{ {
ImplDeleteItems(); ImplDeleteItems();
// reset variables // reset variables
mnFirstLine = 0; mnFirstLine = 0;
mItemList = items; mItemList = std::move(items);
filterItems(maFilterFunc); filterItems(maFilterFunc);
} }
...@@ -1137,13 +1137,13 @@ bool ThumbnailView::IsItemSelected( sal_uInt16 nItemId ) const ...@@ -1137,13 +1137,13 @@ bool ThumbnailView::IsItemSelected( sal_uInt16 nItemId ) const
void ThumbnailView::deselectItems() void ThumbnailView::deselectItems()
{ {
for (ThumbnailViewItem* p : mItemList) for (std::unique_ptr<ThumbnailViewItem>& p : mItemList)
{ {
if (p->isSelected()) if (p->isSelected())
{ {
p->setSelection(false); p->setSelection(false);
maItemStateHdl.Call(p); maItemStateHdl.Call(p.get());
} }
} }
...@@ -1174,7 +1174,7 @@ void ThumbnailView::filterItems(const std::function<bool (const ThumbnailViewIte ...@@ -1174,7 +1174,7 @@ void ThumbnailView::filterItems(const std::function<bool (const ThumbnailViewIte
for (size_t i = 0, n = mItemList.size(); i < n; ++i) 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)) if (maFilterFunc(pItem))
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment