From a72f30e518883c9b2e20c6a0cf2f1e46eac1fbf9 Mon Sep 17 00:00:00 2001 From: Takeshi Abe Date: Wed, 6 Sep 2017 12:05:11 +0900 Subject: svx: Simplify code with std::unique_ptr Change-Id: I6f22417edc70812c64f7b4a9c6d59947059db414 Reviewed-on: https://gerrit.libreoffice.org/41971 Tested-by: Jenkins Reviewed-by: Noel Grandin --- svx/inc/svdibrow.hxx | 4 ++-- svx/source/svdraw/svdibrow.cxx | 29 +++++++++-------------------- 2 files changed, 11 insertions(+), 22 deletions(-) (limited to 'svx') diff --git a/svx/inc/svdibrow.hxx b/svx/inc/svdibrow.hxx index 76b855564c93..c97671e2ffbe 100644 --- a/svx/inc/svdibrow.hxx +++ b/svx/inc/svdibrow.hxx @@ -24,6 +24,7 @@ #include #include #include +#include class SfxItemSet; class ImpItemListRow; @@ -32,7 +33,7 @@ class BrowserMouseEvent; class SdrItemBrowserControl: public BrowseBox { friend class ImpItemEdit; - std::vector aList; + std::vector> aList; long nAktPaintRow; VclPtr pEditControl; OUString aWNamMerk; @@ -48,7 +49,6 @@ friend class ImpItemEdit; private: void ImpCtor(); void ImpSetEntry(const ImpItemListRow& rEntry, std::size_t nEntryNum); - ImpItemListRow* ImpGetEntry(std::size_t nPos) const { return aList[nPos]; } void ImpSaveWhich(); void ImpRestoreWhich(); std::size_t GetCurrentPos() const; diff --git a/svx/source/svdraw/svdibrow.cxx b/svx/source/svdraw/svdibrow.cxx index 270e95242182..5fdc614b7a10 100644 --- a/svx/source/svdraw/svdibrow.cxx +++ b/svx/source/svdraw/svdibrow.cxx @@ -206,8 +206,7 @@ void ImpItemEdit::KeyInput(const KeyEvent& rKEvt) #define MYBROWSEMODE (BrowserMode::THUMBDRAGGING|BrowserMode::KEEPHIGHLIGHT|BrowserMode::NO_HSCROLL|BrowserMode::HIDECURSOR) SdrItemBrowserControl::SdrItemBrowserControl(vcl::Window* pParent): - BrowseBox(pParent, WB_3DLOOK | WB_BORDER | WB_TABSTOP, MYBROWSEMODE), - aList() + BrowseBox(pParent, WB_3DLOOK | WB_BORDER | WB_TABSTOP, MYBROWSEMODE) { ImpCtor(); } @@ -274,10 +273,6 @@ void SdrItemBrowserControl::ImpCtor() void SdrItemBrowserControl::Clear() { - const std::size_t nCount=aList.size(); - for (std::size_t nNum=0; nNum= 0 && _nRow < (sal_Int32)aList.size() ) { - ImpItemListRow* pEntry = ImpGetEntry(_nRow); - if ( pEntry ) - { + auto& pEntry = aList[_nRow]; if ( pEntry->bComment ) { if (_nColId == ITEMBROWSER_NAMECOL_ID) @@ -330,7 +323,6 @@ OUString SdrItemBrowserControl::GetCellText(long _nRow, sal_uInt16 _nColId) cons case ITEMBROWSER_VALUECOL_ID: sRet = pEntry->aValue; break; } // switch } - } } return sRet; } @@ -342,7 +334,7 @@ void SdrItemBrowserControl::PaintField(OutputDevice& rDev, const tools::Rectangl } tools::Rectangle aR(rRect); aR.Bottom()++; - ImpItemListRow* pEntry=ImpGetEntry(nAktPaintRow); + auto& pEntry=aList[nAktPaintRow]; if (pEntry->bComment) { if (nColumnId==ITEMBROWSER_NAMECOL_ID) @@ -378,7 +370,7 @@ sal_uInt16 SdrItemBrowserControl::GetCurrentWhich() const sal_uInt16 nRet=0; const std::size_t nPos=GetCurrentPos(); if (nPos!=ITEM_NOT_FOUND) { - nRet=ImpGetEntry(nPos)->nWhichId; + nRet=aList[nPos]->nWhichId; } return nRet; } @@ -459,7 +451,7 @@ void SdrItemBrowserControl::ImpRestoreWhich() const std::size_t nCount=aList.size(); std::size_t nNum; for (nNum=0; nNumbComment) { sal_uInt16 nWh=pEntry->nWhichId; if (nWh==nLastWhich) bFnd = true; @@ -480,8 +472,8 @@ bool SdrItemBrowserControl::BeginChangeEntry(std::size_t nPos) { BreakChangeEntry(); bool bRet = false; - ImpItemListRow* pEntry=ImpGetEntry(nPos); - if (pEntry!=nullptr && !pEntry->bComment) { + auto& pEntry=aList[nPos]; + if (!pEntry->bComment) { SetMode(MYBROWSEMODE & BrowserMode(~BrowserMode::KEEPHIGHLIGHT)); pEditControl=VclPtr::Create(&GetDataWindow(),this,0); tools::Rectangle aRect(GetFieldRectPixel(nPos, ITEMBROWSER_VALUECOL_ID, false)); @@ -541,10 +533,10 @@ void SdrItemBrowserControl::ImpSetEntry(const ImpItemListRow& rEntry, std::size_ SAL_WARN_IF(nEntryNum > aList.size(), "svx", "trying to set item " << nEntryNum << "in a vector of size " << aList.size()); if (nEntryNum >= aList.size()) { nEntryNum = aList.size(); - aList.push_back(new ImpItemListRow(rEntry)); + aList.emplace_back(new ImpItemListRow(rEntry)); RowInserted(nEntryNum); } else { - ImpItemListRow* pAktEntry=ImpGetEntry(nEntryNum); + auto& pAktEntry=aList[nEntryNum]; if (*pAktEntry!=rEntry) { bool bStateDiff=rEntry.eState!=pAktEntry->eState; bool bValueDiff=rEntry.aValue != pAktEntry->aValue; @@ -1010,9 +1002,6 @@ void SdrItemBrowserControl::SetAttributes(const SfxItemSet* pSet, const SfxItemS if (aList.size()>nEntryNum) { // maybe still too many entries size_t const nTooMuch = aList.size() - nEntryNum; - for (size_t n = nEntryNum; n < aList.size(); ++n) { - delete aList[n]; - } aList.erase(aList.begin() + nEntryNum, aList.end()); RowRemoved(nEntryNum,nTooMuch); } -- cgit