Skip to content

Commit

Permalink
Small optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 24, 2017
1 parent a5e3f19 commit 4b33e2f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/core/qgsjsonutils.cpp
Expand Up @@ -121,7 +121,7 @@ QString QgsJSONExporter::exportFeature( const QgsFeature &feature, const QVarian

if ( mIncludeAttributes )
{
QgsFields fields = mLayer.data() ? mLayer->fields() : feature.fields();
QgsFields fields = mLayer ? mLayer->fields() : feature.fields();

for ( int i = 0; i < fields.count(); ++i )
{
Expand All @@ -132,7 +132,7 @@ QString QgsJSONExporter::exportFeature( const QgsFeature &feature, const QVarian
properties += QLatin1String( ",\n" );
QVariant val = feature.attributes().at( i );

if ( mLayer.data() )
if ( mLayer )
{
QgsEditorWidgetSetup setup = fields.at( i ).editorWidgetSetup();
QgsFieldFormatter *fieldFormatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );
Expand Down Expand Up @@ -161,7 +161,7 @@ QString QgsJSONExporter::exportFeature( const QgsFeature &feature, const QVarian
}

// related attributes
if ( mLayer.data() && mIncludeRelatedAttributes )
if ( mLayer && mIncludeRelatedAttributes )
{
QList< QgsRelation > relations = QgsProject::instance()->relationManager()->referencedRelations( mLayer.data() );
Q_FOREACH ( const QgsRelation &relation, relations )
Expand All @@ -177,11 +177,13 @@ QString QgsJSONExporter::exportFeature( const QgsFeature &feature, const QVarian
{
QgsFeatureIterator it = childLayer->getFeatures( req );
QVector<QVariant> attributeWidgetCaches;
for ( int fieldIndex = 0; fieldIndex < childLayer->fields().count(); ++fieldIndex )
int fieldIndex = 0;
Q_FOREACH ( const QgsField &field, childLayer->fields() )
{
QgsEditorWidgetSetup setup = childLayer->fields().at( fieldIndex ).editorWidgetSetup();
QgsEditorWidgetSetup setup = field.editorWidgetSetup();
QgsFieldFormatter *fieldFormatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );
attributeWidgetCaches.append( fieldFormatter->createCache( childLayer, fieldIndex, setup.config() ) );
fieldIndex++;
}

QgsFeature relatedFet;
Expand Down

0 comments on commit 4b33e2f

Please sign in to comment.