Skip to content

Commit

Permalink
avoid detach when looping on fields and convert some Q_FOREACH (#7905)
Browse files Browse the repository at this point in the history
* avoid detach when looping on fields and convert some Q_FOREACH

* fields already exist
  • Loading branch information
3nids authored Sep 14, 2018
1 parent 8b07b4e commit 73528cd
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/app/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsjsonutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
6 changes: 4 additions & 2 deletions src/core/qgsvectorlayereditbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsnewauxiliarylayerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}

Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgspropertyoverridebutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/symbology/qgsvectorfieldsymbollayerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
3 changes: 2 additions & 1 deletion src/providers/virtual/qgsvirtuallayersourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
Expand Down

0 comments on commit 73528cd

Please sign in to comment.