Skip to content

Commit cc9ec2d

Browse files
committedJan 23, 2019
Remove duplicated code and modernize
No functional changes intended
1 parent 71e0116 commit cc9ec2d

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed
 

‎src/providers/wfs/qgswfsfeatureiterator.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,38 +1423,33 @@ void QgsWFSFeatureIterator::copyFeature( const QgsFeature &srcFeature, QgsFeatur
14231423
QgsFields &fields = mShared->mFields;
14241424
dstFeature.initAttributes( fields.size() );
14251425

1426+
auto setAttr = [ & ]( const int i )
1427+
{
1428+
int idx = srcFeature.fields().indexFromName( fields.at( i ).name() );
1429+
if ( idx >= 0 )
1430+
{
1431+
const QVariant &v = srcFeature.attributes().value( idx );
1432+
if ( v.type() == fields.at( i ).type() )
1433+
dstFeature.setAttribute( i, v );
1434+
else if ( fields.at( i ).type() == QVariant::DateTime && !v.isNull() )
1435+
dstFeature.setAttribute( i, QVariant( QDateTime::fromMSecsSinceEpoch( v.toLongLong() ) ) );
1436+
else
1437+
dstFeature.setAttribute( i, QgsVectorDataProvider::convertValue( fields.at( i ).type(), v.toString() ) );
1438+
}
1439+
};
1440+
14261441
if ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes )
14271442
{
1428-
Q_FOREACH ( int i, mSubSetAttributes )
1443+
for ( auto i : qgis::as_const( mSubSetAttributes ) )
14291444
{
1430-
int idx = srcFeature.fields().indexFromName( fields.at( i ).name() );
1431-
if ( idx >= 0 )
1432-
{
1433-
const QVariant &v = srcFeature.attributes().value( idx );
1434-
if ( v.type() == fields.at( i ).type() )
1435-
dstFeature.setAttribute( i, v );
1436-
else if ( fields.at( i ).type() == QVariant::DateTime && !v.isNull() )
1437-
dstFeature.setAttribute( i, QVariant( QDateTime::fromMSecsSinceEpoch( v.toLongLong() ) ) );
1438-
else
1439-
dstFeature.setAttribute( i, QgsVectorDataProvider::convertValue( fields.at( i ).type(), v.toString() ) );
1440-
}
1445+
setAttr( i );
14411446
}
14421447
}
14431448
else
14441449
{
14451450
for ( int i = 0; i < fields.size(); i++ )
14461451
{
1447-
int idx = srcFeature.fields().indexFromName( fields.at( i ).name() );
1448-
if ( idx >= 0 )
1449-
{
1450-
const QVariant &v = srcFeature.attributes().value( idx );
1451-
if ( v.type() == fields.at( i ).type() )
1452-
dstFeature.setAttribute( i, v );
1453-
else if ( fields.at( i ).type() == QVariant::DateTime && !v.isNull() )
1454-
dstFeature.setAttribute( i, QVariant( QDateTime::fromMSecsSinceEpoch( v.toLongLong() ) ) );
1455-
else
1456-
dstFeature.setAttribute( i, QgsVectorDataProvider::convertValue( fields.at( i ).type(), v.toString() ) );
1457-
}
1452+
setAttr( i );
14581453
}
14591454
}
14601455

0 commit comments

Comments
 (0)
Please sign in to comment.