diff options
author | Julien Nabet <serval2412@yahoo.fr> | 2018-03-10 14:49:40 +0100 |
---|---|---|
committer | Julien Nabet <serval2412@yahoo.fr> | 2018-03-10 16:52:53 +0100 |
commit | ba98f6e3e4dbfc23474e13d59bb08c618ee8c4e5 (patch) | |
tree | 31e69726116d87a088d561cadae96bf2e08d07a4 /dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx | |
parent | 351043e5120470ff4d382f01e4c2f215ba84ef59 (diff) |
Modernize a bit more dbaccess (part2)
mainly by using for-range loops but also by simplifying some simple algo
Change-Id: If5ce6d901761db2b872a99e6de0eb6d2f098df99
Reviewed-on: https://gerrit.libreoffice.org/51044
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Diffstat (limited to 'dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx')
-rw-r--r-- | dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx | 153 |
1 files changed, 69 insertions, 84 deletions
diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx index 8937943db748..faa0274117b1 100644 --- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx +++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx @@ -295,13 +295,19 @@ void OSelectionBrowseBox::ColumnMoved( sal_uInt16 nColId, bool _bCreateUndo ) if ( rFields.size() > sal_uInt16(nNewPos-1) ) { sal_uInt16 nOldPos = 0; - OTableFields::const_iterator aEnd = rFields.end(); - OTableFields::const_iterator aIter = rFields.begin(); - for (; aIter != aEnd && ( (*aIter)->GetColumnId() != nColId ); ++aIter,++nOldPos) - ; + bool bFoundElem = false; + for (auto const& field : rFields) + { + if (field->GetColumnId() == nColId) + { + bFoundElem = true; + break; + } + ++nOldPos; + } OSL_ENSURE( (nNewPos-1) != nOldPos && nOldPos < rFields.size(),"Old and new position are equal!"); - if ( aIter != aEnd ) + if (bFoundElem) { OTableFieldDescRef pOldEntry = rFields[nOldPos]; rFields.erase(rFields.begin() + nOldPos); @@ -492,12 +498,8 @@ void OSelectionBrowseBox::InitController(CellControllerRef& /*rController*/, lon enableControl(pEntry,m_pTableCell); if ( !pEntry->isCondition() ) { - OJoinTableView::OTableWindowMap& rTabWinList = getDesignView()->getTableView()->GetTabWinMap(); - OJoinTableView::OTableWindowMap::const_iterator aIter = rTabWinList.begin(); - OJoinTableView::OTableWindowMap::const_iterator aEnd = rTabWinList.end(); - - for(;aIter != aEnd;++aIter) - m_pTableCell->InsertEntry(static_cast<OQueryTableWindow*>(aIter->second.get())->GetAliasName()); + for (auto const& tabWin : getDesignView()->getTableView()->GetTabWinMap()) + m_pTableCell->InsertEntry(static_cast<OQueryTableWindow*>(tabWin.second.get())->GetAliasName()); m_pTableCell->InsertEntry(DBA_RES(STR_QUERY_NOTABLE), 0); if (!pEntry->GetAlias().isEmpty()) @@ -1589,15 +1591,11 @@ OTableFieldDescRef OSelectionBrowseBox::InsertField(const OTableFieldDescRef& _r sal_uInt16 OSelectionBrowseBox::FieldsCount() { - OTableFields::const_iterator aIter = getFields().begin(); - OTableFields::const_iterator aEnd = getFields().end(); sal_uInt16 nCount = 0; - - while (aIter != aEnd) + for (auto const& field : getFields()) { - if ((*aIter).is() && !(*aIter)->IsEmpty()) + if (field.is() && !field->IsEmpty()) ++nCount; - ++aIter; } return nCount; @@ -1605,18 +1603,14 @@ sal_uInt16 OSelectionBrowseBox::FieldsCount() OTableFieldDescRef OSelectionBrowseBox::FindFirstFreeCol(sal_uInt16& _rColumnPosition ) { - OTableFields::const_iterator aIter = getFields().begin(); - OTableFields::const_iterator aEnd = getFields().end(); _rColumnPosition = BROWSER_INVALIDID; - while ( aIter != aEnd ) + for (auto const& field : getFields()) { ++_rColumnPosition; - OTableFieldDescRef pEntry = (*aIter); - if ( pEntry.is() && pEntry->IsEmpty() ) - return pEntry; - ++aIter; + if ( field.is() && field->IsEmpty() ) + return field; } return nullptr; @@ -1643,26 +1637,24 @@ void OSelectionBrowseBox::AddGroupBy( const OTableFieldDescRef& rInfo ) const ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers()); //sal_Bool bAppend = sal_False; - OTableFields& rFields = getFields(); - OTableFields::const_iterator aIter = rFields.begin(); - OTableFields::const_iterator aEnd = rFields.end(); - for(;aIter != aEnd;++aIter) + bool bAllFieldsSearched = true; + for (auto const& field : getFields()) { - pEntry = *aIter; OSL_ENSURE(pEntry.is(),"OTableFieldDescRef was null!"); - const OUString aField = pEntry->GetField(); - const OUString aAlias = pEntry->GetAlias(); + const OUString aField = field->GetField(); + const OUString aAlias = field->GetAlias(); if (bCase(aField,rInfo->GetField()) && bCase(aAlias,rInfo->GetAlias()) && - pEntry->GetFunctionType() == rInfo->GetFunctionType() && - pEntry->GetFunction() == rInfo->GetFunction()) + field->GetFunctionType() == rInfo->GetFunctionType() && + field->GetFunction() == rInfo->GetFunction()) { - if ( pEntry->isNumericOrAggreateFunction() && rInfo->IsGroupBy() ) + if ( field->isNumericOrAggreateFunction() && rInfo->IsGroupBy() ) { - pEntry->SetGroupBy(false); - aIter = rFields.end(); + field->SetGroupBy(false); + // we do want to consider that bAllFieldsSearched still true here + // bAllFieldsSearched = false; break; } else @@ -1672,6 +1664,7 @@ void OSelectionBrowseBox::AddGroupBy( const OTableFieldDescRef& rInfo ) pEntry->SetGroupBy(rInfo->IsGroupBy()); if(!m_bGroupByUnRelated && pEntry->IsGroupBy()) pEntry->SetVisible(); + bAllFieldsSearched = false; break; } } @@ -1679,7 +1672,7 @@ void OSelectionBrowseBox::AddGroupBy( const OTableFieldDescRef& rInfo ) } } - if (aIter == rFields.end()) + if (bAllFieldsSearched) { OTableFieldDescRef pTmp = InsertField(rInfo, BROWSER_INVALIDID, false, false ); if ( pTmp->isNumericOrAggreateFunction() && rInfo->IsGroupBy() ) // the GroupBy is inherited from rInfo @@ -1690,17 +1683,12 @@ void OSelectionBrowseBox::AddGroupBy( const OTableFieldDescRef& rInfo ) void OSelectionBrowseBox::DuplicateConditionLevel( const sal_uInt16 nLevel) { const sal_uInt16 nNewLevel = nLevel +1; - OTableFields& rFields = getFields(); - OTableFields::const_iterator aIter = rFields.begin(); - OTableFields::const_iterator aEnd = rFields.end(); - for(;aIter != aEnd;++aIter) + for (auto const& field : getFields()) { - OTableFieldDescRef pEntry = *aIter; - - OUString sValue = pEntry->GetCriteria(nLevel); + OUString sValue = field->GetCriteria(nLevel); if ( !sValue.isEmpty() ) { - pEntry->SetCriteria( nNewLevel, sValue); + field->SetCriteria( nNewLevel, sValue); if ( nNewLevel == (m_nVisibleCount-BROW_CRIT1_ROW-1) ) { RowInserted( GetRowCount()-1 ); @@ -1723,31 +1711,28 @@ void OSelectionBrowseBox::AddCondition( const OTableFieldDescRef& rInfo, const O Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData(); ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers()); - OTableFields& rFields = getFields(); - OTableFields::const_iterator aIter = rFields.begin(); - OTableFields::const_iterator aEnd = rFields.end(); - for(;aIter != aEnd;++aIter) + bool bAllFieldsSearched = true; + for (auto const& field : getFields()) { - OTableFieldDescRef pEntry = *aIter; - const OUString aField = pEntry->GetField(); - const OUString aAlias = pEntry->GetAlias(); + const OUString aField = field->GetField(); + const OUString aAlias = field->GetAlias(); if (bCase(aField,rInfo->GetField()) && bCase(aAlias,rInfo->GetAlias()) && - pEntry->GetFunctionType() == rInfo->GetFunctionType() && - pEntry->GetFunction() == rInfo->GetFunction() && - pEntry->IsGroupBy() == rInfo->IsGroupBy() ) + field->GetFunctionType() == rInfo->GetFunctionType() && + field->GetFunction() == rInfo->GetFunction() && + field->IsGroupBy() == rInfo->IsGroupBy() ) { - if ( pEntry->isNumericOrAggreateFunction() && rInfo->IsGroupBy() ) - pEntry->SetGroupBy(false); + if ( field->isNumericOrAggreateFunction() && rInfo->IsGroupBy() ) + field->SetGroupBy(false); else { - if(!m_bGroupByUnRelated && pEntry->IsGroupBy()) - pEntry->SetVisible(); + if(!m_bGroupByUnRelated && field->IsGroupBy()) + field->SetVisible(); } - if (pEntry->GetCriteria(nLevel).isEmpty() ) + if (field->GetCriteria(nLevel).isEmpty() ) { - pEntry->SetCriteria( nLevel, rValue); + field->SetCriteria( nLevel, rValue); if(nLevel == (m_nVisibleCount-BROW_CRIT1_ROW-1)) { RowInserted( GetRowCount()-1 ); @@ -1755,11 +1740,12 @@ void OSelectionBrowseBox::AddCondition( const OTableFieldDescRef& rInfo, const O ++m_nVisibleCount; } m_bVisibleRow[BROW_CRIT1_ROW + nLevel] = true; + bAllFieldsSearched = false; break; } if ( _bAddOrOnOneLine ) { - pLastEntry = pEntry; + pLastEntry = field; } } } @@ -1780,7 +1766,7 @@ void OSelectionBrowseBox::AddCondition( const OTableFieldDescRef& rInfo, const O } m_bVisibleRow[BROW_CRIT1_ROW + nLevel] = true; } - else if (aIter == rFields.end()) + else if (bAllFieldsSearched) { OTableFieldDescRef pTmp = InsertField(rInfo, BROWSER_INVALIDID, false, false ); if ( pTmp->isNumericOrAggreateFunction() && rInfo->IsGroupBy() ) // the GroupBy was inherited from rInfo @@ -1812,34 +1798,37 @@ void OSelectionBrowseBox::AddOrder( const OTableFieldDescRef& rInfo, const EOrde ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers()); bool bAppend = false; - OTableFields& rFields = getFields(); - OTableFields::const_iterator aIter = rFields.begin(); - OTableFields::const_iterator aEnd = rFields.end(); - for(;aIter != aEnd;++aIter) + sal_uInt32 nPos = 0; + bool bAllFieldsSearched = true; + for (auto const& field : getFields()) { - pEntry = *aIter; - OUString aField = pEntry->GetField(); - OUString aAlias = pEntry->GetAlias(); + OUString aField = field->GetField(); + OUString aAlias = field->GetAlias(); if (bCase(aField,rInfo->GetField()) && bCase(aAlias,rInfo->GetAlias())) { - sal_uInt32 nPos = aIter - rFields.begin(); bAppend = (m_nLastSortColumn != SORT_COLUMN_NONE) && (nPos <= m_nLastSortColumn); if ( bAppend ) - aIter = rFields.end(); + { + // we do want to consider that bAllFieldsSearched still true here + // bAllFieldsSearched = false; + break; + } else { if ( !m_bOrderByUnRelated ) - pEntry->SetVisible(); - pEntry->SetOrderDir( eDir ); + field->SetVisible(); + field->SetOrderDir( eDir ); m_nLastSortColumn = nPos; } + bAllFieldsSearched = false; break; } + ++nPos; } - if (aIter == rFields.end()) + if (bAllFieldsSearched) { OTableFieldDescRef pTmp = InsertField(rInfo, BROWSER_INVALIDID, false, false ); if(pTmp.is()) @@ -2670,19 +2659,15 @@ Reference< XAccessible > OSelectionBrowseBox::CreateAccessibleCell( sal_Int32 _n bool OSelectionBrowseBox::HasFieldByAliasName(const OUString& rFieldName, OTableFieldDescRef const & rInfo) const { - OTableFields& aFields = getFields(); - OTableFields::const_iterator aIter = aFields.begin(); - OTableFields::const_iterator aEnd = aFields.end(); - - for(;aIter != aEnd;++aIter) + for (auto const& field : getFields()) { - if ( (*aIter)->GetFieldAlias() == rFieldName ) + if ( field->GetFieldAlias() == rFieldName ) { - *rInfo = *(*aIter); - break; + *rInfo = *field; + return true; } } - return aIter != aEnd; + return false; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |