Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove duplicated code and modernize
No functional changes intended
  • Loading branch information
elpaso committed Jan 23, 2019
1 parent 71e0116 commit cc9ec2d
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions src/providers/wfs/qgswfsfeatureiterator.cpp
Expand Up @@ -1423,38 +1423,33 @@ void QgsWFSFeatureIterator::copyFeature( const QgsFeature &srcFeature, QgsFeatur
QgsFields &fields = mShared->mFields;
dstFeature.initAttributes( fields.size() );

auto setAttr = [ & ]( const int i )
{
int idx = srcFeature.fields().indexFromName( fields.at( i ).name() );
if ( idx >= 0 )
{
const QVariant &v = srcFeature.attributes().value( idx );
if ( v.type() == fields.at( i ).type() )
dstFeature.setAttribute( i, v );
else if ( fields.at( i ).type() == QVariant::DateTime && !v.isNull() )
dstFeature.setAttribute( i, QVariant( QDateTime::fromMSecsSinceEpoch( v.toLongLong() ) ) );
else
dstFeature.setAttribute( i, QgsVectorDataProvider::convertValue( fields.at( i ).type(), v.toString() ) );
}
};

if ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes )
{
Q_FOREACH ( int i, mSubSetAttributes )
for ( auto i : qgis::as_const( mSubSetAttributes ) )
{
int idx = srcFeature.fields().indexFromName( fields.at( i ).name() );
if ( idx >= 0 )
{
const QVariant &v = srcFeature.attributes().value( idx );
if ( v.type() == fields.at( i ).type() )
dstFeature.setAttribute( i, v );
else if ( fields.at( i ).type() == QVariant::DateTime && !v.isNull() )
dstFeature.setAttribute( i, QVariant( QDateTime::fromMSecsSinceEpoch( v.toLongLong() ) ) );
else
dstFeature.setAttribute( i, QgsVectorDataProvider::convertValue( fields.at( i ).type(), v.toString() ) );
}
setAttr( i );
}
}
else
{
for ( int i = 0; i < fields.size(); i++ )
{
int idx = srcFeature.fields().indexFromName( fields.at( i ).name() );
if ( idx >= 0 )
{
const QVariant &v = srcFeature.attributes().value( idx );
if ( v.type() == fields.at( i ).type() )
dstFeature.setAttribute( i, v );
else if ( fields.at( i ).type() == QVariant::DateTime && !v.isNull() )
dstFeature.setAttribute( i, QVariant( QDateTime::fromMSecsSinceEpoch( v.toLongLong() ) ) );
else
dstFeature.setAttribute( i, QgsVectorDataProvider::convertValue( fields.at( i ).type(), v.toString() ) );
}
setAttr( i );
}
}

Expand Down

0 comments on commit cc9ec2d

Please sign in to comment.