diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2019-07-07 16:20:12 +0300 |
---|---|---|
committer | Arkadiy Illarionov <qarkai@gmail.com> | 2019-07-09 17:48:06 +0200 |
commit | 44a6335f49a64ac77207d3aa46c267503c65c5ff (patch) | |
tree | 8ed220967528dc6caa72fa9e753c0955f3de2433 /svx/source/form | |
parent | 4a96a5d862ed46bbcb64d34b32720b5b1b3d7ca8 (diff) |
Simplify Sequence iterations in svx
Use range-based loops, STL and comphelper functions
Change-Id: If6d190cf72b8653c1c3fbe9a6a6e47f10f1a6765
Reviewed-on: https://gerrit.libreoffice.org/75255
Tested-by: Jenkins
Reviewed-by: Arkadiy Illarionov <qarkai@gmail.com>
Diffstat (limited to 'svx/source/form')
-rw-r--r-- | svx/source/form/dataaccessdescriptor.cxx | 17 | ||||
-rw-r--r-- | svx/source/form/datanavi.cxx | 51 | ||||
-rw-r--r-- | svx/source/form/filtnav.cxx | 14 | ||||
-rw-r--r-- | svx/source/form/fmdmod.cxx | 6 | ||||
-rw-r--r-- | svx/source/form/fmexch.cxx | 10 | ||||
-rw-r--r-- | svx/source/form/fmshimp.cxx | 63 | ||||
-rw-r--r-- | svx/source/form/fmsrcimp.cxx | 17 | ||||
-rw-r--r-- | svx/source/form/fmtextcontrolshell.cxx | 9 | ||||
-rw-r--r-- | svx/source/form/formcontrolfactory.cxx | 14 | ||||
-rw-r--r-- | svx/source/form/formcontroller.cxx | 127 | ||||
-rw-r--r-- | svx/source/form/formdispatchinterceptor.cxx | 9 | ||||
-rw-r--r-- | svx/source/form/tabwin.cxx | 10 |
12 files changed, 124 insertions, 223 deletions
diff --git a/svx/source/form/dataaccessdescriptor.cxx b/svx/source/form/dataaccessdescriptor.cxx index 33c4fee2902d..361be0c11ce7 100644 --- a/svx/source/form/dataaccessdescriptor.cxx +++ b/svx/source/form/dataaccessdescriptor.cxx @@ -97,15 +97,13 @@ namespace svx bool bValidPropsOnly = true; // loop through the sequence, and fill our m_aValues - const PropertyValue* pValues = _rValues.getConstArray(); - const PropertyValue* pValuesEnd = pValues + _rValues.getLength(); - for (;pValues != pValuesEnd; ++pValues) + for (const PropertyValue& rValue : _rValues) { - MapString2PropertyEntry::const_iterator aPropPos = rProperties.find( pValues->Name ); + MapString2PropertyEntry::const_iterator aPropPos = rProperties.find( rValue.Name ); if ( aPropPos != rProperties.end() ) { DataAccessDescriptorProperty eProperty = aPropPos->second; - m_aValues[eProperty] = pValues->Value; + m_aValues[eProperty] = rValue.Value; } else // unknown property @@ -136,16 +134,15 @@ namespace svx // build a PropertyValue sequence with the current values Sequence< Property > aProperties = xPropInfo->getProperties(); - const Property* pProperty = aProperties.getConstArray(); - const Property* pPropertyEnd = pProperty + aProperties.getLength(); Sequence< PropertyValue > aValues(aProperties.getLength()); PropertyValue* pValues = aValues.getArray(); - for (;pProperty != pPropertyEnd; ++pProperty, ++pValues) + for (const Property& rProperty : aProperties) { - pValues->Name = pProperty->Name; - pValues->Value = _rxValues->getPropertyValue(pProperty->Name); + pValues->Name = rProperty.Name; + pValues->Value = _rxValues->getPropertyValue(rProperty.Name); + ++pValues; } bool bValidPropsOnly = buildFrom(aValues); diff --git a/svx/source/form/datanavi.cxx b/svx/source/form/datanavi.cxx index c214352e1ea4..d0af70020036 100644 --- a/svx/source/form/datanavi.cxx +++ b/svx/source/form/datanavi.cxx @@ -1231,14 +1231,12 @@ namespace svxform OUString sInstModel = PN_INSTANCE_MODEL; OUString sInstName = PN_INSTANCE_ID; OUString sInstURL = PN_INSTANCE_URL; - const PropertyValue* pProps = _xPropSeq.getConstArray(); - const PropertyValue* pPropsEnd = pProps + _xPropSeq.getLength(); - for ( ; pProps != pPropsEnd; ++pProps ) + for ( const PropertyValue& rProp : _xPropSeq ) { - if ( sInstModel == pProps->Name ) + if ( sInstModel == rProp.Name ) { Reference< css::xml::dom::XNode > xRoot; - if ( pProps->Value >>= xRoot ) + if ( rProp.Value >>= xRoot ) { try { @@ -1260,9 +1258,9 @@ namespace svxform } } } - else if ( sInstName == pProps->Name && ( pProps->Value >>= sTemp ) ) + else if ( sInstName == rProp.Name && ( rProp.Value >>= sTemp ) ) m_sInstanceName = sRet = sTemp; - else if ( sInstURL == pProps->Name && ( pProps->Value >>= sTemp ) ) + else if ( sInstURL == rProp.Name && ( rProp.Value >>= sTemp ) ) m_sInstanceURL = sTemp; } @@ -1906,11 +1904,9 @@ namespace svxform { m_xDataContainer = xContainer; Sequence< OUString > aNameList = m_xDataContainer->getElementNames(); - sal_Int32 i, nCount = aNameList.getLength(); - OUString* pNames = aNameList.getArray(); - for ( i = 0; i < nCount; ++i ) + for ( const OUString& rName : aNameList ) { - Any aAny = m_xDataContainer->getByName( pNames[i] ); + Any aAny = m_xDataContainer->getByName( rName ); Reference< css::xforms::XModel > xFormsModel; if ( aAny >>= xFormsModel ) m_pModelsBox->InsertEntry( xFormsModel->getID() ); @@ -2047,16 +2043,10 @@ namespace svxform void DataNavigatorWindow::CreateInstancePage( const Sequence< PropertyValue >& _xPropSeq ) { OUString sInstName; - const PropertyValue* pProps = _xPropSeq.getConstArray(); - const PropertyValue* pPropsEnd = pProps + _xPropSeq.getLength(); - for ( ; pProps != pPropsEnd; ++pProps ) - { - if ( PN_INSTANCE_ID == pProps->Name ) - { - pProps->Value >>= sInstName; - break; - } - } + auto pProp = std::find_if(_xPropSeq.begin(), _xPropSeq.end(), + [](const PropertyValue& rProp) { return PN_INSTANCE_ID == rProp.Name; }); + if (pProp != _xPropSeq.end()) + pProp->Value >>= sInstName; sal_uInt16 nPageId = GetNewPageId(); if ( sInstName.isEmpty() ) @@ -2418,12 +2408,10 @@ namespace svxform { // get property names & infos, and iterate over target properties Sequence< Property > aProperties = xTo->getPropertySetInfo()->getProperties(); - sal_Int32 nProperties = aProperties.getLength(); - const Property* pProperties = aProperties.getConstArray(); Reference< XPropertySetInfo > xFromInfo = xFrom->getPropertySetInfo(); - for ( sal_Int32 i = 0; i < nProperties; ++i ) + for ( const Property& rProperty : aProperties ) { - const OUString& rName = pProperties[i].Name; + const OUString& rName = rProperty.Name; // if both set have the property, copy the value // (catch and ignore exceptions, if any) @@ -2684,10 +2672,8 @@ namespace svxform if ( xDataTypes.is() ) { Sequence< OUString > aNameList = xDataTypes->getElementNames(); - sal_Int32 i, nCount = aNameList.getLength(); - OUString* pNames = aNameList.getArray(); - for ( i = 0; i < nCount; ++i ) - m_xDataTypeLB->append_text(pNames[i]); + for ( const OUString& rName : aNameList ) + m_xDataTypeLB->append_text(rName); } if ( m_xTempBinding.is() ) @@ -2975,14 +2961,11 @@ namespace svxform { int nRow = 0; Sequence< OUString > aAllNames = m_rNamespaces->getElementNames(); - const OUString* pAllNames = aAllNames.getConstArray(); - const OUString* pAllNamesEnd = pAllNames + aAllNames.getLength(); - for ( ; pAllNames != pAllNamesEnd; ++pAllNames ) + for ( const OUString& sPrefix : aAllNames ) { - OUString sURL; - OUString sPrefix = *pAllNames; if ( m_rNamespaces->hasByName( sPrefix ) ) { + OUString sURL; Any aAny = m_rNamespaces->getByName( sPrefix ); if (aAny >>= sURL) { diff --git a/svx/source/form/filtnav.cxx b/svx/source/form/filtnav.cxx index 1fbe04e3b55c..dc406e6bd9ea 100644 --- a/svx/source/form/filtnav.cxx +++ b/svx/source/form/filtnav.cxx @@ -564,23 +564,21 @@ void FmFilterModel::Update(const Reference< XIndexAccess > & xControllers, FmPar Insert( pFormItem->GetChildren().end(), std::unique_ptr<FmFilterData>(pFilterItems) ); const Sequence< OUString >& rDisjunction( conjunctionTerm ); - for ( const OUString* pDisjunctiveTerm = rDisjunction.getConstArray(); - pDisjunctiveTerm != rDisjunction.getConstArray() + rDisjunction.getLength(); - ++pDisjunctiveTerm - ) + sal_Int32 nComponentIndex = -1; + for ( const OUString& rDisjunctiveTerm : rDisjunction ) { - if ( pDisjunctiveTerm->isEmpty() ) + ++nComponentIndex; + + if ( rDisjunctiveTerm.isEmpty() ) // no condition for this particular component in this particular conjunction term continue; - const sal_Int32 nComponentIndex = pDisjunctiveTerm - rDisjunction.getConstArray(); - // determine the display name of the control const Reference< XControl > xFilterControl( xFilterController->getFilterComponent( nComponentIndex ) ); const OUString sDisplayName( lcl_getLabelName_nothrow( xFilterControl ) ); // insert a new entry - std::unique_ptr<FmFilterItem> pANDCondition(new FmFilterItem( pFilterItems, sDisplayName, *pDisjunctiveTerm, nComponentIndex )); + std::unique_ptr<FmFilterItem> pANDCondition(new FmFilterItem( pFilterItems, sDisplayName, rDisjunctiveTerm, nComponentIndex )); Insert( pFilterItems->GetChildren().end(), std::move(pANDCondition) ); } diff --git a/svx/source/form/fmdmod.cxx b/svx/source/form/fmdmod.cxx index 849d21b25871..6f34a16d4d5f 100644 --- a/svx/source/form/fmdmod.cxx +++ b/svx/source/form/fmdmod.cxx @@ -23,6 +23,7 @@ #include <fmobj.hxx> #include <svx/unoshape.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/sequence.hxx> #include <com/sun/star/uno/XComponentContext.hpp> #include <svx/fmglob.hxx> @@ -81,10 +82,7 @@ using namespace ::svxform; static const sal_uInt16 nSvxComponentServiceNameListCount = SAL_N_ELEMENTS(aSvxComponentServiceNameList); - ::com::sun::star::uno::Sequence< OUString > aSeq( nSvxComponentServiceNameListCount ); - OUString* pStrings = aSeq.getArray(); - for( sal_uInt16 nIdx = 0; nIdx < nSvxComponentServiceNameListCount; nIdx++ ) - pStrings[nIdx] = aSvxComponentServiceNameList[nIdx]; + auto aSeq( comphelper::arrayToSequence< OUString >(aSvxComponentServiceNameList, nSvxComponentServiceNameListCount) ); ::com::sun::star::uno::Sequence< OUString > aParentSeq( SvxUnoDrawMSFactory::getAvailableServiceNames() ); return concatServiceNames( aParentSeq, aSeq ); diff --git a/svx/source/form/fmexch.cxx b/svx/source/form/fmexch.cxx index ad3c2e8427f7..139aeb4ffeb6 100644 --- a/svx/source/form/fmexch.cxx +++ b/svx/source/form/fmexch.cxx @@ -250,15 +250,11 @@ namespace svxform ListBoxEntrySet aEmpty; m_aSelectedEntries.swap( aEmpty ); - sal_Int32 nControls = m_aControlPaths.getLength(); - const css::uno::Sequence<sal_uInt32>* pPaths = m_aControlPaths.getConstArray(); - for (sal_Int32 i=0; i<nControls; ++i) + for (const css::uno::Sequence<sal_uInt32>& rPaths : m_aControlPaths) { - sal_Int32 nThisPatLength = pPaths[i].getLength(); - const sal_uInt32* pThisPath = pPaths[i].getConstArray(); SvTreeListEntry* pSearch = pRoot; - for (sal_Int32 j=0; j<nThisPatLength; ++j) - pSearch = pTreeBox->GetEntry(pSearch, pThisPath[j]); + for (const sal_uInt32 nThisPath : rPaths) + pSearch = pTreeBox->GetEntry(pSearch, nThisPath); m_aSelectedEntries.insert( pSearch ); } diff --git a/svx/source/form/fmshimp.cxx b/svx/source/form/fmshimp.cxx index 6ee16148076a..cd0474fd5fad 100644 --- a/svx/source/form/fmshimp.cxx +++ b/svx/source/form/fmshimp.cxx @@ -83,6 +83,7 @@ #include <comphelper/evtmethodhelper.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/property.hxx> +#include <comphelper/sequence.hxx> #include <comphelper/solarmutex.hxx> #include <comphelper/string.hxx> #include <comphelper/types.hxx> @@ -398,44 +399,31 @@ namespace Sequence< ScriptEventDescriptor> aTransferable(nMaxNewLen); ScriptEventDescriptor* pTransferable = aTransferable.getArray(); - const ScriptEventDescriptor* pCurrent = rTransferIfAvailable.getConstArray(); - sal_Int32 i,j,k; - for (i=0; i<rTransferIfAvailable.getLength(); ++i, ++pCurrent) + for (const ScriptEventDescriptor& rCurrent : rTransferIfAvailable) { // search the model/control idl classes for the event described by pCurrent - for ( Sequence< Type>* pCurrentArray = &aModelListeners; - pCurrentArray; - pCurrentArray = (pCurrentArray == &aModelListeners) ? &aControlListeners : nullptr - ) + for (Sequence< Type>* pCurrentArray : { &aModelListeners, &aControlListeners }) { - const Type* pCurrentListeners = pCurrentArray->getConstArray(); - for (j=0; j<pCurrentArray->getLength(); ++j, ++pCurrentListeners) + for (const Type& rCurrentListener : *pCurrentArray) { - OUString aListener = (*pCurrentListeners).getTypeName(); + OUString aListener = rCurrentListener.getTypeName(); if (!aListener.isEmpty()) aListener = aListener.copy(aListener.lastIndexOf('.')+1); - if (aListener == pCurrent->ListenerType) + if (aListener == rCurrent.ListenerType) // the current ScriptEventDescriptor doesn't match the current listeners class continue; // now check the methods - Sequence< OUString> aMethodsNames = ::comphelper::getEventMethodsForType(*pCurrentListeners); + Sequence< OUString> aMethodsNames = ::comphelper::getEventMethodsForType(rCurrentListener); - const OUString* pMethodsNames = aMethodsNames.getConstArray(); - for (k=0; k<aMethodsNames.getLength(); ++k, ++pMethodsNames) + if (comphelper::findValue(aMethodsNames, rCurrent.EventMethod) != -1) { - if ((*pMethodsNames) != pCurrent->EventMethod) - // the current ScriptEventDescriptor doesn't match the current listeners current method - continue; - // we can transfer the script event : the model (control) supports it - *pTransferable = *pCurrent; + *pTransferable = rCurrent; ++pTransferable; break; } - if (k<aMethodsNames.getLength()) - break; } } } @@ -1213,18 +1201,12 @@ bool FmXFormShell::executeControlConversionSlot_Lock(const Reference<XFormCompon Reference<XControlContainer> xControlContainer(getControlContainerForView_Lock()); Sequence< Reference< XControl> > aControls( xControlContainer->getControls() ); - const Reference< XControl>* pControls = aControls.getConstArray(); - sal_uInt32 nLen = aControls.getLength(); Reference< XControl> xControl; - for (sal_uInt32 i=0 ; i<nLen; ++i) - { - if (pControls[i]->getModel() == xNewModel) - { - xControl = pControls[i]; - break; - } - } + auto pControl = std::find_if(aControls.begin(), aControls.end(), + [&xNewModel](const Reference< XControl>& rControl) { return rControl->getModel() == xNewModel; }); + if (pControl != aControls.end()) + xControl = *pControl; TransferEventScripts(xNewModel, xControl, aOldScripts); } @@ -3358,27 +3340,26 @@ void FmXFormShell::CreateExternalView_Lock() Reference< XPropertySetInfo> xControlModelInfo( xCurrentModelSet->getPropertySetInfo()); DBG_ASSERT(xControlModelInfo.is(), "FmXFormShell::CreateExternalView : the control model has no property info ! This will crash !"); aProps = xControlModelInfo->getProperties(); - const Property* pProps = aProps.getConstArray(); // realloc the control description sequence sal_Int32 nExistentDescs = pColumnProps - aColumnProps.getArray(); aColumnProps.realloc(nExistentDescs + aProps.getLength()); pColumnProps = aColumnProps.getArray() + nExistentDescs; - for (sal_Int32 i=0; i<aProps.getLength(); ++i, ++pProps) + for (const Property& rProp : aProps) { - if (pProps->Name == FM_PROP_LABEL) + if (rProp.Name == FM_PROP_LABEL) // already set continue; - if (pProps->Name == FM_PROP_DEFAULTCONTROL) + if (rProp.Name == FM_PROP_DEFAULTCONTROL) // allow the column's own "default control" continue; - if (pProps->Attributes & PropertyAttribute::READONLY) + if (rProp.Attributes & PropertyAttribute::READONLY) // assume that properties which are readonly for the control are ro for the column to be created, too continue; - pColumnProps->Name = pProps->Name; - pColumnProps->Value = xCurrentModelSet->getPropertyValue(pProps->Name); + pColumnProps->Name = rProp.Name; + pColumnProps->Value = xCurrentModelSet->getPropertyValue(rProp.Name); ++pColumnProps; } aColumnProps.realloc(pColumnProps - aColumnProps.getArray()); @@ -3530,10 +3511,8 @@ void FmXFormShell::Notify( const css::uno::Sequence< OUString >& _rPropertyNames if (impl_checkDisposed_Lock()) return; - const OUString* pSearch = _rPropertyNames.getConstArray(); - const OUString* pSearchTil = pSearch + _rPropertyNames.getLength(); - for (;pSearch < pSearchTil; ++pSearch) - if (*pSearch == "FormControlPilotsEnabled") + for (const OUString& rName : _rPropertyNames) + if (rName == "FormControlPilotsEnabled") { implAdjustConfigCache_Lock(); InvalidateSlot_Lock(SID_FM_USE_WIZARDS, true); diff --git a/svx/source/form/fmsrcimp.cxx b/svx/source/form/fmsrcimp.cxx index ae1803c9d85b..96e993b6527c 100644 --- a/svx/source/form/fmsrcimp.cxx +++ b/svx/source/form/fmsrcimp.cxx @@ -688,8 +688,6 @@ void FmSearchEngine::Init(const OUString& sVisibleFields) DBG_ASSERT(xSupplyCols.is(), "FmSearchEngine::Init : invalid cursor (no columns supplier) !"); Reference< css::container::XNameAccess > xAllFieldNames = xSupplyCols->getColumns(); Sequence< OUString > seqFieldNames = xAllFieldNames->getElementNames(); - OUString* pFieldNames = seqFieldNames.getArray(); - OUString sCurrentField; sal_Int32 nIndex = 0; @@ -699,16 +697,11 @@ void FmSearchEngine::Init(const OUString& sVisibleFields) // search in the field collection sal_Int32 nFoundIndex = -1; - for (sal_Int32 j=0; j<seqFieldNames.getLength(); ++j, ++pFieldNames) - { - if ( 0 == m_aStringCompare.compareString( *pFieldNames, sCurrentField ) ) - { - nFoundIndex = j; - break; - } - } - // set the field selection back to the first - pFieldNames = seqFieldNames.getArray(); + auto pFieldName = std::find_if(seqFieldNames.begin(), seqFieldNames.end(), + [this, &sCurrentField](const OUString& rFieldName) { + return 0 == m_aStringCompare.compareString( rFieldName, sCurrentField ); }); + if (pFieldName != seqFieldNames.end()) + nFoundIndex = static_cast<sal_Int32>(std::distance(seqFieldNames.begin(), pFieldName)); DBG_ASSERT(nFoundIndex != -1, "FmSearchEngine::Init : Invalid field name were given !"); m_arrFieldMapping.push_back(nFoundIndex); } diff --git a/svx/source/form/fmtextcontrolshell.cxx b/svx/source/form/fmtextcontrolshell.cxx index 0076a59b36e5..15d36a0e82f3 100644 --- a/svx/source/form/fmtextcontrolshell.cxx +++ b/svx/source/form/fmtextcontrolshell.cxx @@ -1075,12 +1075,9 @@ namespace svx m_aControlObservers.resize( 0 ); m_aControlObservers.reserve( aControls.getLength() ); - const Reference< css::awt::XControl >* pControls = aControls.getConstArray(); - const Reference< css::awt::XControl >* pControlsEnd = pControls + aControls.getLength(); - for ( ; pControls != pControlsEnd; ++pControls ) - { - m_aControlObservers.push_back( FocusListenerAdapter( new FmFocusListenerAdapter( *pControls, this ) ) ); - } + std::transform(aControls.begin(), aControls.end(), std::back_inserter(m_aControlObservers), + [this](const Reference< css::awt::XControl >& rControl) -> FocusListenerAdapter { + return FocusListenerAdapter( new FmFocusListenerAdapter( rControl, this ) ); }); } catch( const Exception& ) { diff --git a/svx/source/form/formcontrolfactory.cxx b/svx/source/form/formcontrolfactory.cxx index f0fc654b504b..5f7cbedef8f4 100644 --- a/svx/source/form/formcontrolfactory.cxx +++ b/svx/source/form/formcontrolfactory.cxx @@ -525,16 +525,10 @@ namespace svxform // has a setting for the preferred line end format bool bDosLineEnds = false; Sequence< PropertyValue > aInfo = lcl_getDataSourceIndirectProperties( _rxModel, m_pData->m_xContext ); - const PropertyValue* pInfo = aInfo.getConstArray(); - const PropertyValue* pInfoEnd = pInfo + aInfo.getLength(); - for ( ; pInfo != pInfoEnd; ++pInfo ) - { - if ( pInfo->Name == "PreferDosLikeLineEnds" ) - { - pInfo->Value >>= bDosLineEnds; - break; - } - } + const PropertyValue* pInfo = std::find_if(aInfo.begin(), aInfo.end(), + [](const PropertyValue& rInfo) { return rInfo.Name == "PreferDosLikeLineEnds"; }); + if (pInfo != aInfo.end()) + pInfo->Value >>= bDosLineEnds; sal_Int16 nLineEndFormat = bDosLineEnds ? LineEndFormat::CARRIAGE_RETURN_LINE_FEED : LineEndFormat::LINE_FEED; _rxModel->setPropertyValue( FM_PROP_LINEENDFORMAT, makeAny( nLineEndFormat ) ); diff --git a/svx/source/form/formcontroller.cxx b/svx/source/form/formcontroller.cxx index c1d71eaed344..1dc951452899 100644 --- a/svx/source/form/formcontroller.cxx +++ b/svx/source/form/formcontroller.cxx @@ -1273,16 +1273,13 @@ bool FormController::replaceControl( const Reference< XControl >& _rxExistentCon { // look up the ID of _rxExistentControl Sequence< sal_Int32 > aIdentifiers( xContainer->getIdentifiers() ); - const sal_Int32* pIdentifiers = aIdentifiers.getConstArray(); - const sal_Int32* pIdentifiersEnd = aIdentifiers.getConstArray() + aIdentifiers.getLength(); - for ( ; pIdentifiers != pIdentifiersEnd; ++pIdentifiers ) - { - Reference< XControl > xCheck( xContainer->getByIdentifier( *pIdentifiers ), UNO_QUERY ); - if ( xCheck == _rxExistentControl ) - break; - } - DBG_ASSERT( pIdentifiers != pIdentifiersEnd, "FormController::replaceControl: did not find the control in the container!" ); - if ( pIdentifiers != pIdentifiersEnd ) + const sal_Int32* pIdentifiers = std::find_if(aIdentifiers.begin(), aIdentifiers.end(), + [&xContainer, &_rxExistentControl](const sal_Int32 nId) { + Reference< XControl > xCheck( xContainer->getByIdentifier( nId ), UNO_QUERY ); + return xCheck == _rxExistentControl; + }); + DBG_ASSERT( pIdentifiers != aIdentifiers.end(), "FormController::replaceControl: did not find the control in the container!" ); + if ( pIdentifiers != aIdentifiers.end() ) { bool bReplacedWasActive = ( m_xActiveControl.get() == _rxExistentControl.get() ); bool bReplacedWasCurrent = ( m_xCurrentControl.get() == _rxExistentControl.get() ); @@ -1988,10 +1985,8 @@ void FormController::setContainer(const Reference< XControlContainer > & xContai m_aFilterComponents.clear(); // collecting the controls - const Reference< XControl >* pControls = m_aControls.getConstArray(); - const Reference< XControl >* pControlsEnd = pControls + m_aControls.getLength(); - while ( pControls != pControlsEnd ) - implControlRemoved( *pControls++, true ); + for ( const Reference< XControl >& rControl : m_aControls ) + implControlRemoved( rControl, true ); // make database-specific things if (m_bDBConnection && isListeningForChanges()) @@ -2007,7 +2002,6 @@ void FormController::setContainer(const Reference< XControlContainer > & xContai if (xContainer.is() && xTabModel.is()) { Sequence< Reference< XControlModel > > aModels = xTabModel->getControlModels(); - const Reference< XControlModel > * pModels = aModels.getConstArray(); Sequence< Reference< XControl > > aAllControls = xContainer->getControls(); sal_Int32 nCount = aModels.getLength(); @@ -2015,10 +2009,10 @@ void FormController::setContainer(const Reference< XControlContainer > & xContai Reference< XControl > * pControls = m_aControls.getArray(); // collecting the controls - sal_Int32 i, j; - for (i = 0, j = 0; i < nCount; ++i, ++pModels ) + sal_Int32 j = 0; + for (const Reference< XControlModel >& rModel : aModels ) { - Reference< XControl > xControl = findControl( aAllControls, *pModels, false, true ); + Reference< XControl > xControl = findControl( aAllControls, rModel, false, true ); if ( xControl.is() ) { pControls[j++] = xControl; @@ -2027,7 +2021,7 @@ void FormController::setContainer(const Reference< XControlContainer > & xContai } // not every model had an associated control - if (j != i) + if (j != nCount) m_aControls.realloc(j); // listen at the container @@ -2073,7 +2067,6 @@ Sequence< Reference< XControl > > FormController::getControls() return m_aControls; Sequence< Reference< XControlModel > > aControlModels = xModel->getControlModels(); - const Reference< XControlModel > * pModels = aControlModels.getConstArray(); sal_Int32 nModels = aControlModels.getLength(); Sequence< Reference< XControl > > aNewControls(nModels); @@ -2083,9 +2076,9 @@ Sequence< Reference< XControl > > FormController::getControls() // rearrange the controls according to the tab order sequence sal_Int32 j = 0; - for (sal_Int32 i = 0; i < nModels; ++i, ++pModels ) + for ( const Reference< XControlModel >& rModel : aControlModels ) { - xControl = findControl( m_aControls, *pModels, true, true ); + xControl = findControl( m_aControls, rModel, true, true ); if ( xControl.is() ) pControls[j++] = xControl; } @@ -2182,10 +2175,8 @@ void FormController::setLocks() { OSL_ENSURE( !impl_isDisposed_nofail(), "FormController: already disposed!" ); // lock/unlock all controls connected to a data source - const Reference< XControl >* pControls = m_aControls.getConstArray(); - const Reference< XControl >* pControlsEnd = pControls + m_aControls.getLength(); - while ( pControls != pControlsEnd ) - setControlLock( *pControls++ ); + for ( const Reference< XControl >& rControl : m_aControls ) + setControlLock( rControl ); } @@ -2322,10 +2313,8 @@ void FormController::startListening() m_bModified = false; // now register at bound fields - const Reference< XControl >* pControls = m_aControls.getConstArray(); - const Reference< XControl >* pControlsEnd = pControls + m_aControls.getLength(); - while ( pControls != pControlsEnd ) - startControlModifyListening( *pControls++ ); + for ( const Reference< XControl >& rControl : m_aControls ) + startControlModifyListening( rControl ); } @@ -2335,10 +2324,8 @@ void FormController::stopListening() m_bModified = false; // now register at bound fields - const Reference< XControl >* pControls = m_aControls.getConstArray(); - const Reference< XControl >* pControlsEnd = pControls + m_aControls.getLength(); - while ( pControls != pControlsEnd ) - stopControlModifyListening( *pControls++ ); + for ( const Reference< XControl >& rControl : m_aControls ) + stopControlModifyListening( rControl ); } @@ -2347,23 +2334,20 @@ Reference< XControl > FormController::findControl(Sequence< Reference< XControl OSL_ENSURE( !impl_isDisposed_nofail(), "FormController: already disposed!" ); DBG_ASSERT( xCtrlModel.is(), "findControl - which ?!" ); - Reference< XControl >* pControls = _rControls.getArray(); - Reference< XControlModel > xModel; - for ( sal_Int32 i = 0, nCount = _rControls.getLength(); i < nCount; ++i, ++pControls ) + Reference< XControl >* pControls = std::find_if(_rControls.begin(), _rControls.end(), + [&xCtrlModel](const Reference< XControl >& rControl) { + return rControl.is() && rControl->getModel().get() == xCtrlModel.get(); }); + if (pControls != _rControls.end()) { - if ( pControls->is() ) + Reference< XControl > xControl( *pControls ); + if ( _bRemove ) { - xModel = (*pControls)->getModel(); - if ( xModel.get() == xCtrlModel.get() ) - { - Reference< XControl > xControl( *pControls ); - if ( _bRemove ) - ::comphelper::removeElementAt( _rControls, i ); - else if ( _bOverWrite ) - pControls->clear(); - return xControl; - } + auto i = static_cast<sal_Int32>(std::distance(_rControls.begin(), pControls)); + ::comphelper::removeElementAt( _rControls, i ); } + else if ( _bOverWrite ) + pControls->clear(); + return xControl; } return Reference< XControl > (); } @@ -2479,15 +2463,12 @@ void FormController::insertControl(const Reference< XControl > & xControl) void FormController::removeControl(const Reference< XControl > & xControl) { OSL_ENSURE( !impl_isDisposed_nofail(), "FormController: already disposed!" ); - const Reference< XControl >* pControls = m_aControls.getConstArray(); - const Reference< XControl >* pControlsEnd = pControls + m_aControls.getLength(); - while ( pControls != pControlsEnd ) + auto pControl = std::find_if(m_aControls.begin(), m_aControls.end(), + [&xControl](const Reference< XControl >& rControl) { return xControl.get() == rControl.get(); }); + if (pControl != m_aControls.end()) { - if ( xControl.get() == (*pControls++).get() ) - { - ::comphelper::removeElementAt( m_aControls, pControls - m_aControls.getConstArray() - 1 ); - break; - } + auto nIndex = static_cast<sal_Int32>(std::distance(m_aControls.begin(), pControl)); + ::comphelper::removeElementAt( m_aControls, nIndex ); } FilterComponents::iterator componentPos = ::std::find( m_aFilterComponents.begin(), m_aFilterComponents.end(), xControl ); @@ -2654,11 +2635,9 @@ void FormController::unload() void FormController::removeBoundFieldListener() { - const Reference< XControl >* pControls = m_aControls.getConstArray(); - const Reference< XControl >* pControlsEnd = pControls + m_aControls.getLength(); - while ( pControls != pControlsEnd ) + for ( const Reference< XControl >& rControl : m_aControls ) { - Reference< XPropertySet > xProp( *pControls++, UNO_QUERY ); + Reference< XPropertySet > xProp( rControl, UNO_QUERY ); if ( xProp.is() ) xProp->removePropertyChangeListener( FM_PROP_BOUNDFIELD, this ); } @@ -3064,14 +3043,12 @@ void FormController::setFilter(::std::vector<FmFieldInfo>& rFieldInfos) "svx.form", "FormController::setFilter: wrong cast of decimal separator to sal_Char!"); // retrieving the filter - const Sequence < PropertyValue >* pRow = aFilterRows.getConstArray(); - for (sal_Int32 i = 0, nLen = aFilterRows.getLength(); i < nLen; ++i) + for (const Sequence < PropertyValue >& rRow : aFilterRows) { FmFilterRow aRow; // search a field for the given name - const PropertyValue* pRefValues = pRow[i].getConstArray(); - for (sal_Int32 j = 0, nLen1 = pRow[i].getLength(); j < nLen1; j++) + for (const PropertyValue& rRefValue : rRow) { // look for the text component Reference< XPropertySet > xField; @@ -3081,15 +3058,15 @@ void FormController::setFilter(::std::vector<FmFieldInfo>& rFieldInfos) OUString aRealName; // first look with the given name - if (xQueryColumns->hasByName(pRefValues[j].Name)) + if (xQueryColumns->hasByName(rRefValue.Name)) { - xQueryColumns->getByName(pRefValues[j].Name) >>= xSet; + xQueryColumns->getByName(rRefValue.Name) >>= xSet; // get the RealName xSet->getPropertyValue("RealName") >>= aRealName; // compare the condition field name and the RealName - if (aCompare(aRealName, pRefValues[j].Name)) + if (aCompare(aRealName, rRefValue.Name)) xField = xSet; } if (!xField.is()) @@ -3100,7 +3077,7 @@ void FormController::setFilter(::std::vector<FmFieldInfo>& rFieldInfos) { xColumnsByIndex->getByIndex(n) >>= xSet; xSet->getPropertyValue("RealName") >>= aRealName; - if (aCompare(aRealName, pRefValues[j].Name)) + if (aCompare(aRealName, rRefValue.Name)) { // get the column by its alias xField = xSet; @@ -3130,18 +3107,18 @@ void FormController::setFilter(::std::vector<FmFieldInfo>& rFieldInfos) OString aVal = m_pParser->getContext().getIntlKeywordAscii(IParseContext::InternationalKeyCode::And); aCompText += OUString(aVal.getStr(),aVal.getLength(),RTL_TEXTENCODING_ASCII_US); aCompText += " "; - aCompText += ::comphelper::getString(pRefValues[j].Value); + aCompText += ::comphelper::getString(rRefValue.Value); aRow[rFieldInfo.xText] = aCompText; } else { OUString sPredicate,sErrorMsg; - pRefValues[j].Value >>= sPredicate; + rRefValue.Value >>= sPredicate; std::shared_ptr< OSQLParseNode > pParseNode = predicateTree(sErrorMsg, sPredicate, xFormatter, xField); if ( pParseNode != nullptr ) { OUString sCriteria; - switch (pRefValues[j].Handle) + switch (rRefValue.Handle) { case css::sdb::SQLFilterOperator::EQUAL: sCriteria += "="; @@ -3482,13 +3459,7 @@ sal_Bool SAL_CALL FormController::supportsMode(const OUString& Mode) impl_checkDisposed_throw(); Sequence< OUString > aModes(getSupportedModes()); - const OUString* pModes = aModes.getConstArray(); - for (sal_Int32 i = aModes.getLength(); i > 0; ) - { - if (pModes[--i] == Mode) - return true; - } - return false; + return comphelper::findValue(aModes, Mode) != -1; } diff --git a/svx/source/form/formdispatchinterceptor.cxx b/svx/source/form/formdispatchinterceptor.cxx index e5d1d9de826a..85f33b8e87d7 100644 --- a/svx/source/form/formdispatchinterceptor.cxx +++ b/svx/source/form/formdispatchinterceptor.cxx @@ -91,12 +91,9 @@ namespace svxform { ::osl::MutexGuard aGuard( *m_pMutex ); Sequence< Reference< XDispatch> > aReturn(aDescripts.getLength()); - Reference< XDispatch>* pReturn = aReturn.getArray(); - const DispatchDescriptor* pDescripts = aDescripts.getConstArray(); - for (sal_Int32 i=0; i<aDescripts.getLength(); ++i, ++pReturn, ++pDescripts) - { - *pReturn = queryDispatch(pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags); - } + std::transform(aDescripts.begin(), aDescripts.end(), aReturn.begin(), + [this](const DispatchDescriptor& rDescript) -> Reference< XDispatch> { + return queryDispatch(rDescript.FeatureURL, rDescript.FrameName, rDescript.SearchFlags); }); return aReturn; } diff --git a/svx/source/form/tabwin.cxx b/svx/source/form/tabwin.cxx index 5620c9ffdea5..fd8fe32c4628 100644 --- a/svx/source/form/tabwin.cxx +++ b/svx/source/form/tabwin.cxx @@ -90,18 +90,16 @@ struct ColumnInfo static void lcl_addToList( SvTreeListBox& _rListBox, const uno::Reference< container::XNameAccess>& i_xColumns ) { uno::Sequence< OUString > aEntries = i_xColumns->getElementNames(); - const OUString* pEntries = aEntries.getConstArray(); - sal_Int32 nEntries = aEntries.getLength(); - for ( sal_Int32 i = 0; i < nEntries; ++i, ++pEntries ) + for ( const OUString& rEntry : aEntries ) { - uno::Reference< beans::XPropertySet> xColumn(i_xColumns->getByName(*pEntries),UNO_QUERY_THROW); + uno::Reference< beans::XPropertySet> xColumn(i_xColumns->getByName(rEntry),UNO_QUERY_THROW); OUString sLabel; if ( xColumn->getPropertySetInfo()->hasPropertyByName(FM_PROP_LABEL) ) xColumn->getPropertyValue(FM_PROP_LABEL) >>= sLabel; if ( !sLabel.isEmpty() ) - _rListBox.InsertEntry( sLabel, nullptr, false, TREELIST_APPEND, new ColumnInfo(*pEntries) ); + _rListBox.InsertEntry( sLabel, nullptr, false, TREELIST_APPEND, new ColumnInfo(rEntry) ); else - _rListBox.InsertEntry( *pEntries, nullptr, false, TREELIST_APPEND, new ColumnInfo(*pEntries) ); + _rListBox.InsertEntry( rEntry, nullptr, false, TREELIST_APPEND, new ColumnInfo(rEntry) ); } } |