Skip to content
Permalink
Browse files

avoid detach when looping on fields and convert some Q_FOREACH (#7905)

* avoid detach when looping on fields and convert some Q_FOREACH

* fields already exist
  • Loading branch information
3nids committed Sep 14, 2018
1 parent 8b07b4e commit 73528cd152d372c110ef40c904e3442020335df4
@@ -108,7 +108,8 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
connect( mActionExpressionSelect, &QAction::triggered, this, &QgsAttributeTableDialog::mActionExpressionSelect_triggered );
connect( mMainView, &QgsDualView::showContextMenuExternally, this, &QgsAttributeTableDialog::showContextMenu );

Q_FOREACH ( const QgsField &field, mLayer->fields() )
const QgsFields fields = mLayer->fields();
for ( const QgsField &field : fields )
{
mVisibleFields.append( field.name() );
}
@@ -175,7 +175,8 @@ QString QgsJsonExporter::exportFeature( const QgsFeature &feature, const QVarian
QgsFeatureIterator it = childLayer->getFeatures( req );
QVector<QVariant> attributeWidgetCaches;
int fieldIndex = 0;
for ( const auto &field : childLayer->fields() )
const QgsFields fields = childLayer->fields();
for ( const QgsField &field : fields )
{
QgsEditorWidgetSetup setup = field.editorWidgetSetup();
QgsFieldFormatter *fieldFormatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );
@@ -256,7 +256,8 @@ bool QgsVectorLayerEditBuffer::addAttribute( const QgsField &field )
if ( field.name().isEmpty() )
return false;

Q_FOREACH ( const QgsField &updatedField, L->fields() )
const QgsFields fields = L->fields();
for ( const QgsField &updatedField : fields )
{
if ( updatedField.name() == field.name() )
return false;
@@ -303,7 +304,8 @@ bool QgsVectorLayerEditBuffer::renameAttribute( int index, const QString &newNam
if ( index < 0 || index >= L->fields().count() )
return false;

Q_FOREACH ( const QgsField &updatedField, L->fields() )
const QgsFields fields = L->fields();
for ( const QgsField &updatedField : fields )
{
if ( updatedField.name() == newName )
return false;
@@ -27,7 +27,8 @@ QgsNewAuxiliaryLayerDialog::QgsNewAuxiliaryLayerDialog( QgsVectorLayer *layer, Q
{
setupUi( this );

for ( const QgsField &field : mLayer->fields() )
const QgsFields fields = mLayer->fields();
for ( const QgsField &field : fields )
comboBox->addItem( field.name() );
}

@@ -155,7 +155,8 @@ void QgsPropertyOverrideButton::updateFieldLists()
if ( mVectorLayer )
{
// store just a list of fields of unknown type or those that match the expected type
Q_FOREACH ( const QgsField &f, mVectorLayer->fields() )
const QgsFields fields = mVectorLayer->fields();
for ( const QgsField &f : fields )
{
bool fieldMatch = false;
QString fieldType;
@@ -39,7 +39,8 @@ QgsVectorFieldSymbolLayerWidget::QgsVectorFieldSymbolLayerWidget( QgsVectorLayer
mXAttributeComboBox->addItem( QString() );
mYAttributeComboBox->addItem( QString() );
int i = 0;
Q_FOREACH ( const QgsField &f, vectorLayer()->fields() )
const QgsFields fields = vectorLayer()->fields();
for ( const QgsField &f : fields )
{
QString fieldName = f.name();
mXAttributeComboBox->addItem( vectorLayer()->fields().iconForField( i ), fieldName );
@@ -300,7 +300,8 @@ void QgsVirtualLayerSourceSelect::updateLayersList()
{
apis->add( l->name() );
QgsVectorLayer *vl = static_cast<QgsVectorLayer *>( l );
Q_FOREACH ( const QgsField &f, vl->fields().toList() )
const QgsFields fields = vl->fields();
for ( const QgsField &f : fields )
{
apis->add( f.name() );
}
@@ -1459,7 +1459,7 @@ namespace QgsWms
mAccessControl->filterFeatures( layer, fReq );

QStringList attributes;
for ( const QgsField &field : layer->fields().toList() )
for ( const QgsField &field : fields )
{
attributes.append( field.name() );
}

0 comments on commit 73528cd

Please sign in to comment.
You can’t perform that action at this time.