summaryrefslogtreecommitdiff
path: root/sw/source/uibase/dbui/dbmgr.cxx
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2019-07-02 17:18:03 +0300
committerArkadiy Illarionov <qarkai@gmail.com>2019-07-03 21:00:07 +0200
commit671517c462c51b356a35a2d51aa27e90bd3f9531 (patch)
treefb7038e1a186a6f8414ae393ecb782c8231e382b /sw/source/uibase/dbui/dbmgr.cxx
parent84ded153cb9c28ddadad773a6fbfe348bdef8fa9 (diff)
Simplify Sequence iterations in sw/source/uibase/
Use range-based loops, STL and comphelper functions Change-Id: Ia67ebfa0aa0abad855975b13e86e699811ef713a Reviewed-on: https://gerrit.libreoffice.org/75003 Tested-by: Jenkins Reviewed-by: Arkadiy Illarionov <qarkai@gmail.com>
Diffstat (limited to 'sw/source/uibase/dbui/dbmgr.cxx')
-rw-r--r--sw/source/uibase/dbui/dbmgr.cxx93
1 files changed, 42 insertions, 51 deletions
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 3b1adf7ea7ba..48ce4dc80a5a 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -730,18 +730,16 @@ bool SwDBManager::GetTableNames(weld::ComboBox& rBox, const OUString& rDBName)
{
uno::Reference<container::XNameAccess> xTables = xTSupplier->getTables();
uno::Sequence<OUString> aTables = xTables->getElementNames();
- const OUString* pTables = aTables.getConstArray();
- for (sal_Int32 i = 0; i < aTables.getLength(); ++i)
- rBox.append("0", pTables[i]);
+ for (const OUString& rTable : aTables)
+ rBox.append("0", rTable);
}
uno::Reference<sdb::XQueriesSupplier> xQSupplier(xConnection, uno::UNO_QUERY);
if(xQSupplier.is())
{
uno::Reference<container::XNameAccess> xQueries = xQSupplier->getQueries();
uno::Sequence<OUString> aQueries = xQueries->getElementNames();
- const OUString* pQueries = aQueries.getConstArray();
- for (sal_Int32 i = 0; i < aQueries.getLength(); i++)
- rBox.append("1", pQueries[i]);
+ for (const OUString& rQuery : aQueries)
+ rBox.append("1", rQuery);
}
if (!sOldTableName.isEmpty())
rBox.set_active_text(sOldTableName);
@@ -797,10 +795,9 @@ void SwDBManager::GetColumnNames(ListBox* pListBox,
{
uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
const uno::Sequence<OUString> aColNames = xCols->getElementNames();
- const OUString* pColNames = aColNames.getConstArray();
- for(int nCol = 0; nCol < aColNames.getLength(); nCol++)
+ for (const OUString& rColName : aColNames)
{
- pListBox->InsertEntry(pColNames[nCol]);
+ pListBox->InsertEntry(rColName);
}
::comphelper::disposeComponent( xColsSupp );
}
@@ -816,10 +813,9 @@ void SwDBManager::GetColumnNames(weld::ComboBox& rBox,
{
uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
const uno::Sequence<OUString> aColNames = xCols->getElementNames();
- const OUString* pColNames = aColNames.getConstArray();
- for (sal_Int32 nCol = 0; nCol < aColNames.getLength(); ++nCol)
+ for (const OUString& rColName : aColNames)
{
- rBox.append_text(pColNames[nCol]);
+ rBox.append_text(rColName);
}
::comphelper::disposeComponent( xColsSupp );
}
@@ -976,17 +972,17 @@ static void lcl_PreparePrinterOptions(
rOutPrintOptions[ 0 ].Value <<= true;
// copy print options
- const beans::PropertyValue* pOptions = rInPrintOptions.getConstArray();
- for( sal_Int32 n = 0, nIndex = nOffset ; n < rInPrintOptions.getLength(); ++n)
+ sal_Int32 nIndex = nOffset;
+ for( const beans::PropertyValue& rOption : rInPrintOptions)
{
- if( pOptions[n].Name == "CopyCount" || pOptions[n].Name == "FileName"
- || pOptions[n].Name == "Collate" || pOptions[n].Name == "Pages"
- || pOptions[n].Name == "Wait" || pOptions[n].Name == "PrinterName" )
+ if( rOption.Name == "CopyCount" || rOption.Name == "FileName"
+ || rOption.Name == "Collate" || rOption.Name == "Pages"
+ || rOption.Name == "Wait" || rOption.Name == "PrinterName" )
{
// add an option
rOutPrintOptions.realloc( nIndex + 1 );
- rOutPrintOptions[ nIndex ].Name = pOptions[n].Name;
- rOutPrintOptions[ nIndex++ ].Value = pOptions[n].Value ;
+ rOutPrintOptions[ nIndex ].Name = rOption.Name;
+ rOutPrintOptions[ nIndex++ ].Value = rOption.Value ;
}
}
}
@@ -2142,15 +2138,12 @@ bool SwDBManager::GetColumnCnt(const OUString& rSourceName, const OUString& rTab
if(pFound->aSelection.hasElements())
{
//the destination has to be an element of the selection
- const uno::Any* pSelection = pFound->aSelection.getConstArray();
- bool bFound = false;
- for(sal_Int32 nPos = 0; !bFound && nPos < pFound->aSelection.getLength(); nPos++)
- {
- sal_Int32 nSelection = 0;
- pSelection[nPos] >>= nSelection;
- if(nSelection == static_cast<sal_Int32>(nAbsRecordId))
- bFound = true;
- }
+ bool bFound = std::any_of(pFound->aSelection.begin(), pFound->aSelection.end(),
+ [nAbsRecordId](const uno::Any& rSelection) {
+ sal_Int32 nSelection = 0;
+ rSelection >>= nSelection;
+ return nSelection == static_cast<sal_Int32>(nAbsRecordId);
+ });
if(!bFound)
return false;
}
@@ -2210,18 +2203,17 @@ bool SwDBManager::FillCalcWithMergeData( SvNumberFormatter *pDocFormatter,
{
uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
const uno::Sequence<OUString> aColNames = xCols->getElementNames();
- const OUString* pColNames = aColNames.getConstArray();
OUString aString;
// add the "record number" variable, as SwCalc::VarLook would.
rCalc.VarChange( GetAppCharClass().lowercase(
SwFieldType::GetTypeStr(TYP_DBSETNUMBERFLD) ), GetSelectedRecordId() );
- for( int nCol = 0; nCol < aColNames.getLength(); nCol++ )
+ for( const OUString& rColName : aColNames )
{
// get the column type
sal_Int32 nColumnType = sdbc::DataType::SQLNULL;
- uno::Any aCol = xCols->getByName( pColNames[nCol] );
+ uno::Any aCol = xCols->getByName( rColName );
uno::Reference<beans::XPropertySet> xColumnProps;
aCol >>= xColumnProps;
uno::Any aType = xColumnProps->getPropertyValue( "Type" );
@@ -2232,7 +2224,7 @@ bool SwDBManager::FillCalcWithMergeData( SvNumberFormatter *pDocFormatter,
sal_uInt32 nFormat = GetColumnFormat( m_pImpl->pMergeData->sDataSource,
m_pImpl->pMergeData->sCommand,
- pColNames[nCol], pDocFormatter, nLanguage );
+ rColName, pDocFormatter, nLanguage );
// aNumber is overwritten by SwDBField::FormatValue, so store initial status
bool colIsNumber = aNumber != DBL_MAX;
bool bValidValue = SwDBField::FormatValue( pDocFormatter, aString, nFormat,
@@ -2244,8 +2236,8 @@ bool SwDBManager::FillCalcWithMergeData( SvNumberFormatter *pDocFormatter,
SwSbxValue aValue;
aValue.PutDouble( aNumber );
aValue.SetDBvalue( true );
- SAL_INFO( "sw.ui", "'" << pColNames[nCol] << "': " << aNumber << " / " << aString );
- rCalc.VarChange( pColNames[nCol], aValue );
+ SAL_INFO( "sw.ui", "'" << rColName << "': " << aNumber << " / " << aString );
+ rCalc.VarChange( rColName, aValue );
}
}
else
@@ -2253,8 +2245,8 @@ bool SwDBManager::FillCalcWithMergeData( SvNumberFormatter *pDocFormatter,
SwSbxValue aValue;
aValue.PutString( aString );
aValue.SetDBvalue( true );
- SAL_INFO( "sw.ui", "'" << pColNames[nCol] << "': " << aString );
- rCalc.VarChange( pColNames[nCol], aValue );
+ SAL_INFO( "sw.ui", "'" << rColName << "': " << aString );
+ rCalc.VarChange( rColName, aValue );
}
}
}
@@ -3126,22 +3118,21 @@ void SwDBManager::InsertText(SwWrtShell& rSh,
uno::Reference<sdbc::XResultSet> xResSet;
uno::Sequence<uno::Any> aSelection;
sal_Int16 nCmdType = sdb::CommandType::TABLE;
- const beans::PropertyValue* pValues = rProperties.getConstArray();
uno::Reference< sdbc::XConnection> xConnection;
- for(sal_Int32 nPos = 0; nPos < rProperties.getLength(); nPos++)
- {
- if ( pValues[nPos].Name == "DataSourceName" )
- pValues[nPos].Value >>= sDataSource;
- else if ( pValues[nPos].Name == "Command" )
- pValues[nPos].Value >>= sDataTableOrQuery;
- else if ( pValues[nPos].Name == "Cursor" )
- pValues[nPos].Value >>= xResSet;
- else if ( pValues[nPos].Name == "Selection" )
- pValues[nPos].Value >>= aSelection;
- else if ( pValues[nPos].Name == "CommandType" )
- pValues[nPos].Value >>= nCmdType;
- else if ( pValues[nPos].Name == "ActiveConnection" )
- pValues[nPos].Value >>= xConnection;
+ for(const beans::PropertyValue& rValue : rProperties)
+ {
+ if ( rValue.Name == "DataSourceName" )
+ rValue.Value >>= sDataSource;
+ else if ( rValue.Name == "Command" )
+ rValue.Value >>= sDataTableOrQuery;
+ else if ( rValue.Name == "Cursor" )
+ rValue.Value >>= xResSet;
+ else if ( rValue.Name == "Selection" )
+ rValue.Value >>= aSelection;
+ else if ( rValue.Name == "CommandType" )
+ rValue.Value >>= nCmdType;
+ else if ( rValue.Name == "ActiveConnection" )
+ rValue.Value >>= xConnection;
}
if(sDataSource.isEmpty() || sDataTableOrQuery.isEmpty() || !xResSet.is())
{