Skip to content

Commit 4b33e2f

Browse files
committedMay 24, 2017
Small optimisations
1 parent a5e3f19 commit 4b33e2f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed
 

‎src/core/qgsjsonutils.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ QString QgsJSONExporter::exportFeature( const QgsFeature &feature, const QVarian
121121

122122
if ( mIncludeAttributes )
123123
{
124-
QgsFields fields = mLayer.data() ? mLayer->fields() : feature.fields();
124+
QgsFields fields = mLayer ? mLayer->fields() : feature.fields();
125125

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

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

163163
// related attributes
164-
if ( mLayer.data() && mIncludeRelatedAttributes )
164+
if ( mLayer && mIncludeRelatedAttributes )
165165
{
166166
QList< QgsRelation > relations = QgsProject::instance()->relationManager()->referencedRelations( mLayer.data() );
167167
Q_FOREACH ( const QgsRelation &relation, relations )
@@ -177,11 +177,13 @@ QString QgsJSONExporter::exportFeature( const QgsFeature &feature, const QVarian
177177
{
178178
QgsFeatureIterator it = childLayer->getFeatures( req );
179179
QVector<QVariant> attributeWidgetCaches;
180-
for ( int fieldIndex = 0; fieldIndex < childLayer->fields().count(); ++fieldIndex )
180+
int fieldIndex = 0;
181+
Q_FOREACH ( const QgsField &field, childLayer->fields() )
181182
{
182-
QgsEditorWidgetSetup setup = childLayer->fields().at( fieldIndex ).editorWidgetSetup();
183+
QgsEditorWidgetSetup setup = field.editorWidgetSetup();
183184
QgsFieldFormatter *fieldFormatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );
184185
attributeWidgetCaches.append( fieldFormatter->createCache( childLayer, fieldIndex, setup.config() ) );
186+
fieldIndex++;
185187
}
186188

187189
QgsFeature relatedFet;

0 commit comments

Comments
 (0)
Please sign in to comment.