[Libreoffice-commits] core.git: dbaccess/source

Julien Nabet serval2412 at yahoo.fr
Thu Jan 11 08:40:06 UTC 2018


 dbaccess/source/ui/relationdesign/RTableConnection.cxx     |   10 +--
 dbaccess/source/ui/relationdesign/RTableConnectionData.cxx |   38 +++++-------
 dbaccess/source/ui/relationdesign/RelationController.cxx   |   22 +++----
 dbaccess/source/ui/tabledesign/TEditControl.cxx            |   39 +++++--------
 dbaccess/source/ui/tabledesign/TableController.cxx         |   32 ++++------
 dbaccess/source/ui/tabledesign/TableRowExchange.cxx        |    6 --
 dbaccess/source/ui/tabledesign/TableUndo.cxx               |   24 +++-----
 7 files changed, 71 insertions(+), 100 deletions(-)

New commits:
commit 4cb3e1c05a16af3dad03db9d789dc7ea061b33cf
Author: Julien Nabet <serval2412 at yahoo.fr>
Date:   Sat Dec 30 09:43:25 2017 +0100

    Use for-range loops in dbaccess (part2)
    
    Change-Id: I7a247584a88fa516c7d28068b3d860499f090c92
    Reviewed-on: https://gerrit.libreoffice.org/47189
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Julien Nabet <serval2412 at yahoo.fr>

diff --git a/dbaccess/source/ui/relationdesign/RTableConnection.cxx b/dbaccess/source/ui/relationdesign/RTableConnection.cxx
index 7f818429930f..b76016d14c1a 100644
--- a/dbaccess/source/ui/relationdesign/RTableConnection.cxx
+++ b/dbaccess/source/ui/relationdesign/RTableConnection.cxx
@@ -61,19 +61,17 @@ void ORelationTableConnection::Draw(vcl::RenderContext& rRenderContext, const to
 
     const OConnectionLine* pTopLine = nullptr;
     const std::vector<OConnectionLine*>& rConnLineList = GetConnLineList();
-    std::vector<OConnectionLine*>::const_iterator aIter = rConnLineList.begin();
-    std::vector<OConnectionLine*>::const_iterator aEnd = rConnLineList.end();
 
-    for(;aIter != aEnd;++aIter)
+    for (auto const& elem : rConnLineList)
     {
-        if( (*aIter)->IsValid() )
+        if( elem->IsValid() )
         {
-            aBoundingRect = (*aIter)->GetBoundingRect();
+            aBoundingRect = elem->GetBoundingRect();
             nTemp = aBoundingRect.Top();
             if(nTemp < nTop)
             {
                 nTop = nTemp;
-                pTopLine = (*aIter);
+                pTopLine = elem;
             }
         }
     }
diff --git a/dbaccess/source/ui/relationdesign/RTableConnectionData.cxx b/dbaccess/source/ui/relationdesign/RTableConnectionData.cxx
index a4553e3913aa..e7a590c85866 100644
--- a/dbaccess/source/ui/relationdesign/RTableConnectionData.cxx
+++ b/dbaccess/source/ui/relationdesign/RTableConnectionData.cxx
@@ -109,13 +109,11 @@ void ORelationTableConnectionData::ChangeOrientation()
 {
     // exchange Source- and DestFieldName of the lines
     OUString sTempString;
-    OConnectionLineDataVec::const_iterator aIter = m_vConnLineData.begin();
-    OConnectionLineDataVec::const_iterator aEnd = m_vConnLineData.end();
-    for(;aIter != aEnd;++aIter)
+    for (auto const& elem : m_vConnLineData)
     {
-        sTempString = (*aIter)->GetSourceFieldName();
-        (*aIter)->SetSourceFieldName( (*aIter)->GetDestFieldName() );
-        (*aIter)->SetDestFieldName( sTempString );
+        sTempString = elem->GetSourceFieldName();
+        elem->SetSourceFieldName( elem->GetDestFieldName() );
+        elem->SetDestFieldName( sTempString );
     }
 
     // adapt member
@@ -159,12 +157,10 @@ bool ORelationTableConnectionData::checkPrimaryKey(const Reference< XPropertySet
 
         for(;pKeyIter != pKeyEnd;++pKeyIter)
         {
-            OConnectionLineDataVec::const_iterator aIter = m_vConnLineData.begin();
-            OConnectionLineDataVec::const_iterator aEnd = m_vConnLineData.end();
-            for(;aIter != aEnd;++aIter)
+            for (auto const& elem : m_vConnLineData)
             {
                 ++nValidLinesCount;
-                if ( (*aIter)->GetFieldName(_eEConnectionSide) == *pKeyIter )
+                if ( elem->GetFieldName(_eEConnectionSide) == *pKeyIter )
                 {
                     ++nPrimKeysCount;
                     break;
@@ -226,14 +222,16 @@ bool operator==(const ORelationTableConnectionData& lhs, const ORelationTableCon
 
     if ( bEqual )
     {
-        std::vector< OConnectionLineDataRef >::const_iterator aIter = lhs.m_vConnLineData.begin();
-        std::vector< OConnectionLineDataRef >::const_iterator aEnd = lhs.m_vConnLineData.end();
-        for (sal_Int32 i = 0; aIter != aEnd; ++aIter,++i)
+        sal_Int32 i = 0;
+        for (auto const& elem : lhs.m_vConnLineData)
         {
-            if ( *(rhs.m_vConnLineData[i]) != **aIter )
+            if ( *(rhs.m_vConnLineData[i]) != *elem )
+            {
+                bEqual = false;
                 break;
+            }
+            ++i;
         }
-        bEqual = aIter == aEnd;
     }
     return bEqual;
 }
@@ -286,18 +284,16 @@ bool ORelationTableConnectionData::Update()
         Reference<XAppend> xColumnAppend(xColumns,UNO_QUERY);
         if ( xColumnFactory.is() )
         {
-            OConnectionLineDataVec::const_iterator aIter = m_vConnLineData.begin();
-            OConnectionLineDataVec::const_iterator aEnd = m_vConnLineData.end();
-            for(;aIter != aEnd;++aIter)
+            for (auto const& elem : m_vConnLineData)
             {
-                if(!((*aIter)->GetSourceFieldName().isEmpty() || (*aIter)->GetDestFieldName().isEmpty()))
+                if(!(elem->GetSourceFieldName().isEmpty() || elem->GetDestFieldName().isEmpty()))
                 {
                     Reference<XPropertySet> xColumn;
                     xColumn = xColumnFactory->createDataDescriptor();
                     if ( xColumn.is() )
                     {
-                        xColumn->setPropertyValue(PROPERTY_NAME,makeAny((*aIter)->GetSourceFieldName()));
-                        xColumn->setPropertyValue(PROPERTY_RELATEDCOLUMN,makeAny((*aIter)->GetDestFieldName()));
+                        xColumn->setPropertyValue(PROPERTY_NAME,makeAny(elem->GetSourceFieldName()));
+                        xColumn->setPropertyValue(PROPERTY_RELATEDCOLUMN,makeAny(elem->GetDestFieldName()));
                         xColumnAppend->appendByDescriptor(xColumn);
                     }
                 }
diff --git a/dbaccess/source/ui/relationdesign/RelationController.cxx b/dbaccess/source/ui/relationdesign/RelationController.cxx
index 233141474c4c..dfafc9291c24 100644
--- a/dbaccess/source/ui/relationdesign/RelationController.cxx
+++ b/dbaccess/source/ui/relationdesign/RelationController.cxx
@@ -442,17 +442,15 @@ void ORelationController::mergeData(const TTableConnectionData& _aConnectionData
 
     std::copy( _aConnectionData.begin(), _aConnectionData.end(), std::back_inserter( m_vTableConnectionData ));
     // here we are finished, so we can collect the table from connection data
-    TTableConnectionData::const_iterator aConnDataIter = m_vTableConnectionData.begin();
-    TTableConnectionData::const_iterator aConnDataEnd = m_vTableConnectionData.end();
-    for(;aConnDataIter != aConnDataEnd;++aConnDataIter)
+    for (auto const& elem : m_vTableConnectionData)
     {
-        if ( !existsTable((*aConnDataIter)->getReferencingTable()->GetComposedName()) )
+        if ( !existsTable(elem->getReferencingTable()->GetComposedName()) )
         {
-            m_vTableData.push_back((*aConnDataIter)->getReferencingTable());
+            m_vTableData.push_back(elem->getReferencingTable());
         }
-        if ( !existsTable((*aConnDataIter)->getReferencedTable()->GetComposedName()) )
+        if ( !existsTable(elem->getReferencedTable()->GetComposedName()) )
         {
-            m_vTableData.push_back((*aConnDataIter)->getReferencedTable());
+            m_vTableData.push_back(elem->getReferencedTable());
         }
     }
     if ( m_nThreadEvent )
@@ -532,14 +530,12 @@ void ORelationController::loadData()
 TTableWindowData::value_type ORelationController::existsTable(const OUString& _rComposedTableName)  const
 {
     ::comphelper::UStringMixEqual bCase(true);
-    TTableWindowData::const_iterator aIter = m_vTableData.begin();
-    TTableWindowData::const_iterator aEnd = m_vTableData.end();
-    for(;aIter != aEnd;++aIter)
+    for (auto const& elem : m_vTableData)
     {
-        if(bCase((*aIter)->GetComposedName(),_rComposedTableName))
-            break;
+        if(bCase(elem->GetComposedName(),_rComposedTableName))
+            return elem;
     }
-    return ( aIter != aEnd) ? *aIter : TTableWindowData::value_type();
+    return TTableWindowData::value_type();
 }
 
 void ORelationController::loadLayoutInformation()
diff --git a/dbaccess/source/ui/tabledesign/TEditControl.cxx b/dbaccess/source/ui/tabledesign/TEditControl.cxx
index b717c5c276ff..65be68236e2d 100644
--- a/dbaccess/source/ui/tabledesign/TEditControl.cxx
+++ b/dbaccess/source/ui/tabledesign/TEditControl.cxx
@@ -376,10 +376,8 @@ void OTableEditorCtrl::InitController(CellControllerRef&, long nRow, sal_uInt16
                     break;
 
                 const OTypeInfoMap& rTypeInfo = GetView()->getController().getTypeInfo();
-                OTypeInfoMap::const_iterator aIter = rTypeInfo.begin();
-                OTypeInfoMap::const_iterator aEnd = rTypeInfo.end();
-                for(;aIter != aEnd;++aIter)
-                    pTypeCell->InsertEntry( aIter->second->aUIName );
+                for (auto const& elem : rTypeInfo)
+                    pTypeCell->InsertEntry( elem.second->aUIName );
                 pTypeCell->SelectEntry( aInitString );
             }
 
@@ -481,12 +479,10 @@ sal_Int32 OTableEditorCtrl::HasFieldName( const OUString& rFieldName )
 
     ::comphelper::UStringMixEqual bCase(!xMetaData.is() || xMetaData->supportsMixedCaseQuotedIdentifiers());
 
-    std::vector< std::shared_ptr<OTableRow> >::const_iterator aIter = m_pRowList->begin();
-    std::vector< std::shared_ptr<OTableRow> >::const_iterator aEnd = m_pRowList->end();
     sal_Int32 nCount(0);
-    for(;aIter != aEnd;++aIter)
+    for (auto const& row : *m_pRowList)
     {
-        OFieldDescription* pFieldDescr = (*aIter)->GetActFieldDescr();
+        OFieldDescription* pFieldDescr = row->GetActFieldDescr();
         if( pFieldDescr && bCase(rFieldName,pFieldDescr->GetName()))
             nCount++;
     }
@@ -1501,15 +1497,15 @@ void OTableEditorCtrl::SetPrimaryKey( bool bSet )
     MultiSelection aDeletedPrimKeys;
     aDeletedPrimKeys.SetTotalRange( Range(0,GetRowCount()) );
 
-    std::vector< std::shared_ptr<OTableRow> >::const_iterator aIter = m_pRowList->begin();
-    std::vector< std::shared_ptr<OTableRow> >::const_iterator aEnd = m_pRowList->end();
-    for(sal_Int32 nRow = 0;aIter != aEnd;++aIter,++nRow)
+    sal_Int32 nRow = 0;
+    for (auto const& row : *m_pRowList)
     {
-        OFieldDescription* pFieldDescr = (*aIter)->GetActFieldDescr();
-        if( pFieldDescr && (*aIter)->IsPrimaryKey() && (!bSet || !IsRowSelected(nRow)) )
+        OFieldDescription* pFieldDescr = row->GetActFieldDescr();
+        if( pFieldDescr && row->IsPrimaryKey() && (!bSet || !IsRowSelected(nRow)) )
         {
             AdjustFieldDescription(pFieldDescr,aDeletedPrimKeys,nRow,bSet,false);
         }
+        ++nRow;
     }
 
     // Set the primary keys of the marked rows
@@ -1544,14 +1540,14 @@ bool OTableEditorCtrl::IsPrimaryKey()
 {
     // Are all marked fields part of the Primary Key ?
     long nPrimaryKeys = 0;
-    std::vector< std::shared_ptr<OTableRow> >::const_iterator aIter = m_pRowList->begin();
-    std::vector< std::shared_ptr<OTableRow> >::const_iterator aEnd = m_pRowList->end();
-    for(sal_Int32 nRow=0;aIter != aEnd;++aIter,++nRow)
+    sal_Int32 nRow=0;
+    for (auto const& row : *m_pRowList)
     {
-        if( IsRowSelected(nRow) && !(*aIter)->IsPrimaryKey() )
+        if( IsRowSelected(nRow) && !row->IsPrimaryKey() )
             return false;
-        if( (*aIter)->IsPrimaryKey() )
+        if( row->IsPrimaryKey() )
             ++nPrimaryKeys;
+        ++nRow;
     }
 
     // Are there any unselected fields that are part of the Key ?
@@ -1582,12 +1578,11 @@ void OTableEditorCtrl::SwitchType( const TOTypeInfoSP& _pType )
         {
             sal_Int32 nEntryPos = 0;
             const OTypeInfoMap& rTypeInfo = GetView()->getController().getTypeInfo();
-            OTypeInfoMap::const_iterator aIter = rTypeInfo.begin();
-            OTypeInfoMap::const_iterator aEnd = rTypeInfo.end();
-            for(;aIter != aEnd;++aIter,++nEntryPos)
+            for (auto const& elem : rTypeInfo)
             {
-                if(aIter->second == _pType)
+                if(elem.second == _pType)
                     break;
+                ++nEntryPos;
             }
             if (nEntryPos < pTypeCell->GetEntryCount())
                 pTypeCell->SelectEntryPos( nEntryPos );
diff --git a/dbaccess/source/ui/tabledesign/TableController.cxx b/dbaccess/source/ui/tabledesign/TableController.cxx
index 86bcbbdd2692..2125ce4c777a 100644
--- a/dbaccess/source/ui/tabledesign/TableController.cxx
+++ b/dbaccess/source/ui/tabledesign/TableController.cxx
@@ -674,13 +674,11 @@ void OTableController::appendColumns(Reference<XColumnsSupplier> const & _rxColS
         Reference<XAppend> xAppend(xColumns,UNO_QUERY);
         OSL_ENSURE(xAppend.is(),"No XAppend Interface!");
 
-        std::vector< std::shared_ptr<OTableRow> >::const_iterator aIter = m_vRowList.begin();
-        std::vector< std::shared_ptr<OTableRow> >::const_iterator aEnd = m_vRowList.end();
-        for(;aIter != aEnd;++aIter)
+        for (auto const& row : m_vRowList)
         {
-            OSL_ENSURE(*aIter,"OTableRow is null!");
-            OFieldDescription* pField = (*aIter)->GetActFieldDescr();
-            if ( !pField || (!_bNew && (*aIter)->IsReadOnly() && !_bKeyColumns) )
+            OSL_ENSURE(row,"OTableRow is null!");
+            OFieldDescription* pField = row->GetActFieldDescr();
+            if ( !pField || (!_bNew && row->IsReadOnly() && !_bKeyColumns) )
                 continue;
 
             Reference<XPropertySet> xColumn;
@@ -985,8 +983,7 @@ void OTableController::alterColumns()
     std::vector< std::shared_ptr<OTableRow> >::const_iterator aIter = m_vRowList.begin();
     std::vector< std::shared_ptr<OTableRow> >::const_iterator aEnd = m_vRowList.end();
     // first look for columns where something other than the name changed
-    sal_Int32 nPos = 0;
-    for(;aIter != aEnd;++aIter,++nPos)
+    for(sal_Int32 nPos = 0;aIter != aEnd;++aIter,++nPos)
     {
         OSL_ENSURE(*aIter,"OTableRow is null!");
         OFieldDescription* pField = (*aIter)->GetActFieldDescr();
@@ -1131,16 +1128,15 @@ void OTableController::alterColumns()
             bReload = true;
     }
     // alter column settings
-    aIter = m_vRowList.begin();
 
     // first look for columns where something other than the name changed
-    for(nPos = 0;aIter != aEnd;++aIter,++nPos)
+    for (auto const& row : m_vRowList)
     {
         OSL_ENSURE(*aIter,"OTableRow is null!");
-        OFieldDescription* pField = (*aIter)->GetActFieldDescr();
+        OFieldDescription* pField = row->GetActFieldDescr();
         if ( !pField )
             continue;
-        if ( (*aIter)->IsReadOnly() )
+        if ( row->IsReadOnly() )
         {
             aColumns.insert(pField->GetName());
             continue;
@@ -1423,16 +1419,14 @@ void OTableController::reSyncRows()
 {
     bool bAlterAllowed  = isAlterAllowed();
     bool bAddAllowed    = isAddAllowed();
-    std::vector< std::shared_ptr<OTableRow> >::const_iterator aIter = m_vRowList.begin();
-    std::vector< std::shared_ptr<OTableRow> >::const_iterator aEnd = m_vRowList.end();
-    for(;aIter != aEnd;++aIter)
+    for (auto const& row : m_vRowList)
     {
-        OSL_ENSURE(*aIter,"OTableRow is null!");
-        OFieldDescription* pField = (*aIter)->GetActFieldDescr();
+        OSL_ENSURE(row,"OTableRow is null!");
+        OFieldDescription* pField = row->GetActFieldDescr();
         if ( pField )
-            (*aIter)->SetReadOnly(!bAlterAllowed);
+            row->SetReadOnly(!bAlterAllowed);
         else
-            (*aIter)->SetReadOnly(!bAddAllowed);
+            row->SetReadOnly(!bAddAllowed);
 
     }
     static_cast<OTableDesignView*>(getView())->reSync();    // show the windows and fill with our information
diff --git a/dbaccess/source/ui/tabledesign/TableRowExchange.cxx b/dbaccess/source/ui/tabledesign/TableRowExchange.cxx
index 559a500302fe..53b54cef400c 100644
--- a/dbaccess/source/ui/tabledesign/TableRowExchange.cxx
+++ b/dbaccess/source/ui/tabledesign/TableRowExchange.cxx
@@ -40,10 +40,8 @@ namespace dbaui
             if(pRows)
             {
                 (*rxOStm).WriteInt32( pRows->size() ); // first stream the size
-                std::vector< std::shared_ptr<OTableRow> >::const_iterator aIter = pRows->begin();
-                std::vector< std::shared_ptr<OTableRow> >::const_iterator aEnd = pRows->end();
-                for(;aIter != aEnd;++aIter)
-                    WriteOTableRow(*rxOStm, **aIter);
+                for (auto const& row : *pRows)
+                    WriteOTableRow(*rxOStm, *row);
                 return true;
             }
         }
diff --git a/dbaccess/source/ui/tabledesign/TableUndo.cxx b/dbaccess/source/ui/tabledesign/TableUndo.cxx
index f340bbc763c7..76564b18569d 100644
--- a/dbaccess/source/ui/tabledesign/TableUndo.cxx
+++ b/dbaccess/source/ui/tabledesign/TableUndo.cxx
@@ -184,16 +184,14 @@ void OTableEditorDelUndoAct::Undo()
 {
     // Insert the deleted line
     sal_uLong nPos;
-    std::vector< std::shared_ptr<OTableRow> >::const_iterator aIter = m_aDeletedRows.begin();
-    std::vector< std::shared_ptr<OTableRow> >::const_iterator aEnd = m_aDeletedRows.end();
 
-     std::shared_ptr<OTableRow>  pNewOrigRow;
+    std::shared_ptr<OTableRow>  pNewOrigRow;
     std::vector< std::shared_ptr<OTableRow> >* pOriginalRows = pTabEdCtrl->GetRowList();
 
-    for(;aIter != aEnd;++aIter)
+    for (auto const& deletedRow : m_aDeletedRows)
     {
-        pNewOrigRow.reset(new OTableRow( **aIter ));
-        nPos = (*aIter)->GetPos();
+        pNewOrigRow.reset(new OTableRow( *deletedRow ));
+        nPos = deletedRow->GetPos();
         pOriginalRows->insert( pOriginalRows->begin()+nPos,pNewOrigRow);
     }
 
@@ -206,13 +204,11 @@ void OTableEditorDelUndoAct::Redo()
 {
     // delete line again
     sal_uLong nPos;
-    std::vector< std::shared_ptr<OTableRow> >::const_iterator aIter = m_aDeletedRows.begin();
-    std::vector< std::shared_ptr<OTableRow> >::const_iterator aEnd = m_aDeletedRows.end();
     std::vector< std::shared_ptr<OTableRow> >* pOriginalRows = pTabEdCtrl->GetRowList();
 
-    for(;aIter != aEnd;++aIter)
+    for (auto const& deletedRow : m_aDeletedRows)
     {
-        nPos = (*aIter)->GetPos();
+        nPos = deletedRow->GetPos();
         pOriginalRows->erase( pOriginalRows->begin()+nPos );
     }
 
@@ -255,13 +251,11 @@ void OTableEditorInsUndoAct::Redo()
 {
     // insert lines again
     long nInsertRow = m_nInsPos;
-     std::shared_ptr<OTableRow>  pRow;
-    std::vector< std::shared_ptr<OTableRow> >::const_iterator aIter = m_vInsertedRows.begin();
-    std::vector< std::shared_ptr<OTableRow> >::const_iterator aEnd = m_vInsertedRows.end();
+    std::shared_ptr<OTableRow>  pRow;
     std::vector< std::shared_ptr<OTableRow> >* pRowList = pTabEdCtrl->GetRowList();
-    for(;aIter != aEnd;++aIter)
+    for (auto const& insertedRow : m_vInsertedRows)
     {
-        pRow.reset(new OTableRow( **aIter ));
+        pRow.reset(new OTableRow( *insertedRow ));
         pRowList->insert( pRowList->begin()+nInsertRow ,pRow );
         nInsertRow++;
     }


More information about the Libreoffice-commits mailing list