Skip to content

Commit

Permalink
Convert some Q_FOREACHes to for-in
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 26, 2017
1 parent 3eefe0d commit 9339595
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -717,9 +717,9 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
updateConstraint( ft, eww );

// update eww dependencies constraint
QList<QgsEditorWidgetWrapper *> deps = constraintDependencies( eww );
const QList<QgsEditorWidgetWrapper *> deps = constraintDependencies( eww );

Q_FOREACH ( QgsEditorWidgetWrapper *depsEww, deps )
for ( QgsEditorWidgetWrapper *depsEww : deps )
updateConstraint( ft, depsEww );

// sync OK button status
Expand All @@ -728,7 +728,8 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
mExpressionContext.setFeature( ft );

// Recheck visibility for all containers which are controlled by this value
Q_FOREACH ( ContainerInformation *info, mContainerInformationDependency.value( eww->field().name() ) )
const QVector<ContainerInformation *> infos = mContainerInformationDependency.value( eww->field().name() );
for ( ContainerInformation *info : infos )
{
info->apply( &mExpressionContext );
}
Expand Down Expand Up @@ -767,10 +768,9 @@ bool QgsAttributeForm::currentFormFeature( QgsFeature &feature )
{
bool rc = true;
feature = QgsFeature( mFeature );
QgsAttributes src = feature.attributes();
QgsAttributes dst = feature.attributes();

Q_FOREACH ( QgsWidgetWrapper *ww, mWidgets )
for ( QgsWidgetWrapper *ww : qgis::as_const( mWidgets ) )
{
QgsEditorWidgetWrapper *eww = qobject_cast<QgsEditorWidgetWrapper *>( ww );

Expand Down Expand Up @@ -802,18 +802,20 @@ bool QgsAttributeForm::currentFormFeature( QgsFeature &feature )
void QgsAttributeForm::registerContainerInformation( QgsAttributeForm::ContainerInformation *info )
{
mContainerVisibilityInformation.append( info );
Q_FOREACH ( const QString &col, info->expression.referencedColumns() )

const QSet<QString> referencedColumns = info->expression.referencedColumns();

for ( const QString &col : referencedColumns )
{
mContainerInformationDependency[ col ].append( info );
}
}

bool QgsAttributeForm::currentFormValidConstraints( QStringList &invalidFields,
QStringList &descriptions )
bool QgsAttributeForm::currentFormValidConstraints( QStringList &invalidFields, QStringList &descriptions )
{
bool valid( true );

Q_FOREACH ( QgsWidgetWrapper *ww, mWidgets )
for ( QgsWidgetWrapper *ww : qgis::as_const( mWidgets ) )
{
QgsEditorWidgetWrapper *eww = qobject_cast<QgsEditorWidgetWrapper *>( ww );
if ( eww )
Expand Down Expand Up @@ -907,7 +909,7 @@ QList<QgsEditorWidgetWrapper *> QgsAttributeForm::constraintDependencies( QgsEdi
QString name = w->field().name();

// for each widget in the current form
Q_FOREACH ( QgsWidgetWrapper *ww, mWidgets )
for ( QgsWidgetWrapper *ww : qgis::as_const( mWidgets ) )
{
// get the wrapper
QgsEditorWidgetWrapper *eww = qobject_cast<QgsEditorWidgetWrapper *>( ww );
Expand All @@ -920,7 +922,9 @@ QList<QgsEditorWidgetWrapper *> QgsAttributeForm::constraintDependencies( QgsEdi
// get expression and referencedColumns
QgsExpression expr = eww->layer()->fields().at( eww->fieldIdx() ).constraints().constraintExpression();

Q_FOREACH ( const QString &colName, expr.referencedColumns() )
const auto referencedColumns = expr.referencedColumns();

for ( const QString &colName : referencedColumns )
{
if ( name == colName )
{
Expand Down Expand Up @@ -960,7 +964,7 @@ void QgsAttributeForm::synchronizeEnabledState()
|| mMode == AddFeatureMode
|| mMode == MultiEditMode ) && mLayer->isEditable();

Q_FOREACH ( QgsWidgetWrapper *ww, mWidgets )
for ( QgsWidgetWrapper *ww : qgis::as_const( mWidgets ) )
{
QgsEditorWidgetWrapper *eww = qobject_cast<QgsEditorWidgetWrapper *>( ww );
if ( eww )
Expand Down Expand Up @@ -1070,7 +1074,9 @@ void QgsAttributeForm::init()
int column = 0;
int columnCount = 1;

Q_FOREACH ( QgsAttributeEditorElement *widgDef, mLayer->editFormConfig().tabs() )
const QList<QgsAttributeEditorElement *> tabs = mLayer->editFormConfig().tabs();

for ( QgsAttributeEditorElement *widgDef : tabs )
{
if ( widgDef->type() == QgsAttributeEditorElement::AeTypeContainer )
{
Expand Down Expand Up @@ -1182,9 +1188,12 @@ void QgsAttributeForm::init()
}

int row = 0;
Q_FOREACH ( const QgsField &field, mLayer->fields().toList() )

const QgsFields fields = mLayer->fields();

for ( const QgsField &field : fields )
{
int idx = mLayer->fields().lookupField( field.name() );
int idx = fields.lookupField( field.name() );
if ( idx < 0 )
continue;

Expand Down

0 comments on commit 9339595

Please sign in to comment.