diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-28 13:59:47 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-02 08:48:02 +0200 |
commit | dc1c424acfb4b3504a19be52417d23f1c5c30ee8 (patch) | |
tree | 26ce4e21f0f387300c8fdd8c9229342083c1fcb7 /svx/source | |
parent | 81f713802ea6d1def41a29a83d7122e8bb0e4dde (diff) |
loplugin:useuniqueptr in FmParentData
Change-Id: Ie6c2c3f10e2ca4037c0607f1faac8f6235ed2eed
Reviewed-on: https://gerrit.libreoffice.org/61121
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx/source')
-rw-r--r-- | svx/source/form/filtnav.cxx | 130 | ||||
-rw-r--r-- | svx/source/inc/filtnav.hxx | 14 |
2 files changed, 64 insertions, 80 deletions
diff --git a/svx/source/form/filtnav.cxx b/svx/source/form/filtnav.cxx index c5b88d79d4d0..a98aea59100a 100644 --- a/svx/source/form/filtnav.cxx +++ b/svx/source/form/filtnav.cxx @@ -137,9 +137,6 @@ Image FmFilterData::GetImage() const FmParentData::~FmParentData() { - for (::std::vector<FmFilterData*>::const_iterator i = m_aChildren.begin(); - i != m_aChildren.end(); ++i) - delete *i; } Image FmFormItem::GetImage() const @@ -149,12 +146,8 @@ Image FmFormItem::GetImage() const FmFilterItem* FmFilterItems::Find( const ::sal_Int32 _nFilterComponentIndex ) const { - for ( ::std::vector< FmFilterData* >::const_iterator i = m_aChildren.begin(); - i != m_aChildren.end(); - ++i - ) + for ( auto & pData : m_aChildren ) { - FmFilterData* pData = *i; FmFilterItem& rCondition = dynamic_cast<FmFilterItem&>(*pData); if ( _nFilterComponentIndex == rCondition.GetComponentIndex() ) return &rCondition; @@ -377,7 +370,7 @@ void FmFilterAdapter::predicateExpressionChanged( const FilterEvent& Event ) const sal_Int32 nActiveTerm( xFilterController->getActiveTerm() ); - FmFilterData* pData = pFormItem->GetChildren()[nActiveTerm]; + FmFilterData* pData = pFormItem->GetChildren()[nActiveTerm].get(); FmFilterItems& rFilter = dynamic_cast<FmFilterItems&>(*pData); FmFilterItem* pFilterItem = rFilter.Find( Event.FilterComponent ); if ( pFilterItem ) @@ -400,8 +393,8 @@ void FmFilterAdapter::predicateExpressionChanged( const FilterEvent& Event ) // searching the component by field name OUString aFieldName( lcl_getLabelName_nothrow( xFilterController->getFilterComponent( Event.FilterComponent ) ) ); - pFilterItem = new FmFilterItem(&rFilter, aFieldName, Event.PredicateExpression, Event.FilterComponent); - m_pModel->Insert(rFilter.GetChildren().end(), pFilterItem); + std::unique_ptr<FmFilterItem> pNewFilterItem(new FmFilterItem(&rFilter, aFieldName, Event.PredicateExpression, Event.FilterComponent)); + m_pModel->Insert(rFilter.GetChildren().end(), std::move(pNewFilterItem)); } // ensure there's one empty term in the filter, just in case the active term was previously empty @@ -422,7 +415,7 @@ void SAL_CALL FmFilterAdapter::disjunctiveTermRemoved( const FilterEvent& Event if ( !pFormItem ) return; - ::std::vector< FmFilterData* >& rTermItems = pFormItem->GetChildren(); + auto& rTermItems = pFormItem->GetChildren(); const bool bValidIndex = ( Event.DisjunctiveTerm >= 0 ) && ( static_cast<size_t>(Event.DisjunctiveTerm) < rTermItems.size() ); OSL_ENSURE( bValidIndex, "FmFilterAdapter::disjunctiveTermRemoved: invalid term index!" ); if ( !bValidIndex ) @@ -432,7 +425,7 @@ void SAL_CALL FmFilterAdapter::disjunctiveTermRemoved( const FilterEvent& Event if ( Event.DisjunctiveTerm == 0 ) { rTermItems[1]->SetText( SvxResId(RID_STR_FILTER_FILTER_FOR)); - FmFilterTextChangedHint aChangeHint( rTermItems[1] ); + FmFilterTextChangedHint aChangeHint( rTermItems[1].get() ); m_pModel->Broadcast( aChangeHint ); } @@ -465,11 +458,11 @@ void SAL_CALL FmFilterAdapter::disjunctiveTermAdded( const FilterEvent& Event ) return; } - const ::std::vector< FmFilterData* >::iterator insertPos = pFormItem->GetChildren().begin() + nInsertPos; + auto insertPos = pFormItem->GetChildren().begin() + nInsertPos; // "Filter for" for first position, "Or" for the other positions - FmFilterItems* pFilterItems = new FmFilterItems(pFormItem, (nInsertPos?SvxResId(RID_STR_FILTER_FILTER_OR):SvxResId(RID_STR_FILTER_FILTER_FOR))); - m_pModel->Insert( insertPos, pFilterItems ); + std::unique_ptr<FmFilterItems> pFilterItems(new FmFilterItems(pFormItem, (nInsertPos?SvxResId(RID_STR_FILTER_FILTER_OR):SvxResId(RID_STR_FILTER_FILTER_FOR)))); + m_pModel->Insert( insertPos, std::move(pFilterItems) ); } @@ -504,10 +497,6 @@ void FmFilterModel::Clear() m_xController = nullptr; m_xControllers = nullptr; - for (::std::vector<FmFilterData*>::const_iterator i = m_aChildren.begin(); - i != m_aChildren.end(); ++i) - delete *i; - m_aChildren.clear(); } @@ -559,7 +548,7 @@ void FmFilterModel::Update(const Reference< XIndexAccess > & xControllers, FmPar // Insert a new item for the form FmFormItem* pFormItem = new FmFormItem( pParent, xController, aName ); - Insert( pParent->GetChildren().end(), pFormItem ); + Insert( pParent->GetChildren().end(), std::unique_ptr<FmFilterData>(pFormItem) ); Reference< XFilterController > xFilterController( pFormItem->GetFilterController(), UNO_SET_THROW ); @@ -571,7 +560,7 @@ void FmFilterModel::Update(const Reference< XIndexAccess > & xControllers, FmPar { // we always display one row, even if there's no term to be displayed FmFilterItems* pFilterItems = new FmFilterItems( pFormItem, aTitle ); - Insert( pFormItem->GetChildren().end(), pFilterItems ); + Insert( pFormItem->GetChildren().end(), std::unique_ptr<FmFilterData>(pFilterItems) ); const Sequence< OUString >& rDisjunction( conjunctionTerm ); for ( const OUString* pDisjunctiveTerm = rDisjunction.getConstArray(); @@ -590,8 +579,8 @@ void FmFilterModel::Update(const Reference< XIndexAccess > & xControllers, FmPar const OUString sDisplayName( lcl_getLabelName_nothrow( xFilterControl ) ); // insert a new entry - FmFilterItem* pANDCondition = new FmFilterItem( pFilterItems, sDisplayName, *pDisjunctiveTerm, nComponentIndex ); - Insert( pFilterItems->GetChildren().end(), pANDCondition ); + std::unique_ptr<FmFilterItem> pANDCondition(new FmFilterItem( pFilterItems, sDisplayName, *pDisjunctiveTerm, nComponentIndex )); + Insert( pFilterItems->GetChildren().end(), std::move(pANDCondition) ); } // title for the next conditions @@ -609,12 +598,11 @@ void FmFilterModel::Update(const Reference< XIndexAccess > & xControllers, FmPar } -FmFormItem* FmFilterModel::Find(const ::std::vector<FmFilterData*>& rItems, const Reference< XFormController > & xController) const +FmFormItem* FmFilterModel::Find(const ::std::vector<std::unique_ptr<FmFilterData>>& rItems, const Reference< XFormController > & xController) const { - for (::std::vector<FmFilterData*>::const_iterator i = rItems.begin(); - i != rItems.end(); ++i) + for (auto i = rItems.begin(); i != rItems.end(); ++i) { - FmFormItem* pForm = dynamic_cast<FmFormItem*>( *i ); + FmFormItem* pForm = dynamic_cast<FmFormItem*>( i->get() ); if (pForm) { if ( xController == pForm->GetController() ) @@ -631,12 +619,11 @@ FmFormItem* FmFilterModel::Find(const ::std::vector<FmFilterData*>& rItems, cons } -FmFormItem* FmFilterModel::Find(const ::std::vector<FmFilterData*>& rItems, const Reference< XForm >& xForm) const +FmFormItem* FmFilterModel::Find(const ::std::vector<std::unique_ptr<FmFilterData>>& rItems, const Reference< XForm >& xForm) const { - for (::std::vector<FmFilterData*>::const_iterator i = rItems.begin(); - i != rItems.end(); ++i) + for (auto i = rItems.begin(); i != rItems.end(); ++i) { - FmFormItem* pForm = dynamic_cast<FmFormItem*>( *i ); + FmFormItem* pForm = dynamic_cast<FmFormItem*>( i->get() ); if (pForm) { if (xForm == pForm->GetController()->getModel()) @@ -670,7 +657,7 @@ void FmFilterModel::SetCurrentController(const Reference< XFormController > & xC const sal_Int32 nActiveTerm( xFilterController->getActiveTerm() ); if ( pItem->GetChildren().size() > static_cast<size_t>(nActiveTerm) ) { - SetCurrentItems( static_cast< FmFilterItems* >( pItem->GetChildren()[ nActiveTerm ] ) ); + SetCurrentItems( static_cast< FmFilterItems* >( pItem->GetChildren()[ nActiveTerm ].get() ) ); } } catch( const Exception& ) @@ -683,14 +670,11 @@ void FmFilterModel::SetCurrentController(const Reference< XFormController > & xC void FmFilterModel::AppendFilterItems( FmFormItem& _rFormItem ) { // insert the condition behind the last filter items - ::std::vector<FmFilterData*>::const_reverse_iterator aEnd = _rFormItem.GetChildren().rend(); - ::std::vector<FmFilterData*>::reverse_iterator iter; - for ( iter = _rFormItem.GetChildren().rbegin(); - iter != aEnd; - ++iter - ) + auto aEnd = _rFormItem.GetChildren().rend(); + auto iter = _rFormItem.GetChildren().rbegin(); + while ( iter != aEnd ) { - if (dynamic_cast<const FmFilterItems*>(*iter) != nullptr) + if (dynamic_cast<const FmFilterItems*>(iter->get()) != nullptr) break; } @@ -708,33 +692,35 @@ void FmFilterModel::AppendFilterItems( FmFormItem& _rFormItem ) } } -void FmFilterModel::Insert(const ::std::vector<FmFilterData*>::iterator& rPos, FmFilterData* pData) +void FmFilterModel::Insert(const ::std::vector<std::unique_ptr<FmFilterData>>::iterator& rPos, std::unique_ptr<FmFilterData> pData) { + auto pTemp = pData.get(); size_t nPos; - ::std::vector<FmFilterData*>& rItems = pData->GetParent()->GetChildren(); + ::std::vector<std::unique_ptr<FmFilterData>>& rItems = pData->GetParent()->GetChildren(); if (rPos == rItems.end()) { nPos = rItems.size(); - rItems.push_back(pData); + rItems.push_back(std::move(pData)); } else { nPos = rPos - rItems.begin(); - rItems.insert(rPos, pData); + rItems.insert(rPos, std::move(pData)); } // notify the UI - FmFilterInsertedHint aInsertedHint(pData, nPos); + FmFilterInsertedHint aInsertedHint(pTemp, nPos); Broadcast( aInsertedHint ); } void FmFilterModel::Remove(FmFilterData* pData) { FmParentData* pParent = pData->GetParent(); - ::std::vector<FmFilterData*>& rItems = pParent->GetChildren(); + ::std::vector<std::unique_ptr<FmFilterData>>& rItems = pParent->GetChildren(); // erase the item from the model - ::std::vector<FmFilterData*>::iterator i = ::std::find(rItems.begin(), rItems.end(), pData); + auto i = ::std::find_if(rItems.begin(), rItems.end(), + [&](const std::unique_ptr<FmFilterData>& p) { return p.get() == pData; } ); DBG_ASSERT(i != rItems.end(), "FmFilterModel::Remove(): unknown Item"); // position within the parent sal_Int32 nPos = i - rItems.begin(); @@ -750,11 +736,11 @@ void FmFilterModel::Remove(FmFilterData* pData) if ( bEmptyLastTerm ) { // remove all children (by setting an empty predicate expression) - ::std::vector< FmFilterData* >& rChildren = static_cast<FmFilterItems*>(pData)->GetChildren(); + ::std::vector< std::unique_ptr<FmFilterData> >& rChildren = static_cast<FmFilterItems*>(pData)->GetChildren(); while ( !rChildren.empty() ) { - ::std::vector< FmFilterData* >::iterator removePos = rChildren.end() - 1; - if (FmFilterItem* pFilterItem = dynamic_cast<FmFilterItem*>( *removePos)) + auto removePos = rChildren.end() - 1; + if (FmFilterItem* pFilterItem = dynamic_cast<FmFilterItem*>( removePos->get() )) { FmFilterAdapter::setText( nPos, pFilterItem, OUString() ); } @@ -781,8 +767,9 @@ void FmFilterModel::Remove(FmFilterData* pData) else { // find the position of the father within his father - ::std::vector<FmFilterData*>& rParentParentItems = pData->GetParent()->GetParent()->GetChildren(); - ::std::vector<FmFilterData*>::iterator j = ::std::find(rParentParentItems.begin(), rParentParentItems.end(), rFilterItem.GetParent()); + ::std::vector<std::unique_ptr<FmFilterData>>& rParentParentItems = pData->GetParent()->GetParent()->GetChildren(); + auto j = ::std::find_if(rParentParentItems.begin(), rParentParentItems.end(), + [&](const std::unique_ptr<FmFilterData>& p) { return p.get() == rFilterItem.GetParent(); }); DBG_ASSERT(j != rParentParentItems.end(), "FmFilterModel::Remove(): unknown Item"); sal_Int32 nParentPos = j - rParentParentItems.begin(); @@ -793,17 +780,15 @@ void FmFilterModel::Remove(FmFilterData* pData) } } -void FmFilterModel::Remove( const ::std::vector<FmFilterData*>::iterator& rPos ) +void FmFilterModel::Remove( const ::std::vector<std::unique_ptr<FmFilterData>>::iterator& rPos ) { // remove from parent's child list - FmFilterData* pData = *rPos; + std::unique_ptr<FmFilterData> pData = std::move(*rPos); pData->GetParent()->GetChildren().erase( rPos ); // notify the view, this will remove the actual SvTreeListEntry - FmFilterRemovedHint aRemoveHint( pData ); + FmFilterRemovedHint aRemoveHint( pData.get() ); Broadcast( aRemoveHint ); - - delete pData; } @@ -851,16 +836,17 @@ bool FmFilterModel::ValidateText(FmFilterItem const * pItem, OUString& rText, OU } -void FmFilterModel::Append(FmFilterItems* pItems, FmFilterItem* pFilterItem) +void FmFilterModel::Append(FmFilterItems* pItems, std::unique_ptr<FmFilterItem> pFilterItem) { - Insert(pItems->GetChildren().end(), pFilterItem); + Insert(pItems->GetChildren().end(), std::move(pFilterItem)); } void FmFilterModel::SetTextForItem(FmFilterItem* pItem, const OUString& rText) { - ::std::vector<FmFilterData*>& rItems = pItem->GetParent()->GetParent()->GetChildren(); - ::std::vector<FmFilterData*>::const_iterator i = ::std::find(rItems.begin(), rItems.end(), pItem->GetParent()); + ::std::vector<std::unique_ptr<FmFilterData>>& rItems = pItem->GetParent()->GetParent()->GetChildren(); + auto i = ::std::find_if(rItems.begin(), rItems.end(), + [&](const std::unique_ptr<FmFilterData>& p) { return p.get() == pItem->GetParent(); }); sal_Int32 nParentPos = i - rItems.begin(); FmFilterAdapter::setText(nParentPos, pItem, rText); @@ -886,8 +872,9 @@ void FmFilterModel::SetCurrentItems(FmFilterItems* pCurrent) if (pCurrent) { FmFormItem* pFormItem = static_cast<FmFormItem*>(pCurrent->GetParent()); - ::std::vector<FmFilterData*>& rItems = pFormItem->GetChildren(); - ::std::vector<FmFilterData*>::const_iterator i = ::std::find(rItems.begin(), rItems.end(), pCurrent); + ::std::vector<std::unique_ptr<FmFilterData>>& rItems = pFormItem->GetChildren(); + auto i = ::std::find_if(rItems.begin(), rItems.end(), + [&](const std::unique_ptr<FmFilterData>& p) { return p.get() == pCurrent; }); if (i != rItems.end()) { @@ -925,23 +912,20 @@ void FmFilterModel::SetCurrentItems(FmFilterItems* pCurrent) void FmFilterModel::EnsureEmptyFilterRows( FmParentData& _rItem ) { // checks whether for each form there's one free level for input - ::std::vector< FmFilterData* >& rChildren = _rItem.GetChildren(); + ::std::vector< std::unique_ptr<FmFilterData> >& rChildren = _rItem.GetChildren(); bool bAppendLevel = dynamic_cast<const FmFormItem*>(&_rItem) != nullptr; - ::std::vector<FmFilterData*>::const_iterator aEnd = rChildren.end(); + auto aEnd = rChildren.end(); - for ( ::std::vector<FmFilterData*>::iterator i = rChildren.begin(); - i != aEnd; - ++i - ) + for ( auto i = rChildren.begin(); i != aEnd; ++i ) { - FmFilterItems* pItems = dynamic_cast<FmFilterItems*>( *i ); + FmFilterItems* pItems = dynamic_cast<FmFilterItems*>( i->get() ); if ( pItems && pItems->GetChildren().empty() ) { bAppendLevel = false; break; } - FmFormItem* pFormItem = dynamic_cast<FmFormItem*>( *i ); + FmFormItem* pFormItem = dynamic_cast<FmFormItem*>( i->get() ); if (pFormItem) { EnsureEmptyFilterRows( *pFormItem ); @@ -980,7 +964,7 @@ void FmFilterItemsString::Paint(const Point& rPos, SvTreeListBox& rDev, vcl::Ren FmFormItem* pForm = static_cast<FmFormItem*>(pRow->GetParent()); // current filter is significant painted - const bool bIsCurrentFilter = pForm->GetChildren()[ pForm->GetFilterController()->getActiveTerm() ] == pRow; + const bool bIsCurrentFilter = pForm->GetChildren()[ pForm->GetFilterController()->getActiveTerm() ].get() == pRow; if (bIsCurrentFilter) { rRenderContext.Push(PushFlags::LINECOLOR); @@ -1526,7 +1510,7 @@ void FmFilterNavigator::insertFilterItem(const ::std::vector<FmFilterItem*>& _rF if ( !pFilterItem ) { pFilterItem = new FmFilterItem( _pTargetItems, pLookupItem->GetFieldName(), aText, pLookupItem->GetComponentIndex() ); - m_pModel->Append( _pTargetItems, pFilterItem ); + m_pModel->Append( _pTargetItems, std::unique_ptr<FmFilterItem>(pFilterItem) ); } if ( !_bCopy ) diff --git a/svx/source/inc/filtnav.hxx b/svx/source/inc/filtnav.hxx index 0910a68b350d..826bd07223dc 100644 --- a/svx/source/inc/filtnav.hxx +++ b/svx/source/inc/filtnav.hxx @@ -79,7 +79,7 @@ public: class FmParentData : public FmFilterData { protected: - ::std::vector< FmFilterData* > m_aChildren; + ::std::vector< std::unique_ptr<FmFilterData> > m_aChildren; public: FmParentData(FmParentData* pParent, const OUString& rText) @@ -87,7 +87,7 @@ public: {} virtual ~FmParentData() override; - ::std::vector< FmFilterData* >& GetChildren() { return m_aChildren; } + ::std::vector< std::unique_ptr<FmFilterData> >& GetChildren() { return m_aChildren; } }; @@ -166,7 +166,7 @@ public: void Update(const css::uno::Reference< css::container::XIndexAccess > & xControllers, const css::uno::Reference< css::form::runtime::XFormController > & xCurrent); void Clear(); bool ValidateText(FmFilterItem const * pItem, OUString& rText, OUString& rErrorMsg) const; - void Append(FmFilterItems* pItems, FmFilterItem* pFilterItem); + void Append(FmFilterItems* pItems, std::unique_ptr<FmFilterItem> pFilterItem); void SetTextForItem(FmFilterItem* pItem, const OUString& rText); FmFormItem* GetCurrentForm() const {return m_pCurrentItems ? static_cast<FmFormItem*>(m_pCurrentItems->GetParent()) : nullptr;} @@ -181,10 +181,10 @@ public: void EnsureEmptyFilterRows( FmParentData& _rItem ); private: - void Insert(const ::std::vector<FmFilterData*>::iterator& rPos, FmFilterData* pFilterItem); - void Remove( const ::std::vector<FmFilterData*>::iterator& rPos ); - FmFormItem* Find(const ::std::vector<FmFilterData*>& rItems, const css::uno::Reference< css::form::runtime::XFormController > & xController) const; - FmFormItem* Find(const ::std::vector<FmFilterData*>& rItems, const css::uno::Reference< css::form::XForm >& xForm) const; + void Insert(const ::std::vector<std::unique_ptr<FmFilterData>>::iterator& rPos, std::unique_ptr<FmFilterData> pFilterItem); + void Remove( const ::std::vector<std::unique_ptr<FmFilterData>>::iterator& rPos ); + FmFormItem* Find(const ::std::vector<std::unique_ptr<FmFilterData>>& rItems, const css::uno::Reference< css::form::runtime::XFormController > & xController) const; + FmFormItem* Find(const ::std::vector<std::unique_ptr<FmFilterData>>& rItems, const css::uno::Reference< css::form::XForm >& xForm) const; void Update(const css::uno::Reference< css::container::XIndexAccess > & xControllers, FmParentData* pParent); }; |