Skip to content
Permalink
Browse files

Prepare expression and only request required pieces

  • Loading branch information
m-kuhn committed Feb 20, 2019
1 parent 5fe225b commit 9f77b2dd239741082cdc12b806d780379d798eb2
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/core/fieldformatter/qgsrelationreferencefieldformatter.cpp
@@ -130,12 +130,20 @@ QVariant QgsRelationReferenceFieldFormatter::createCache( QgsVectorLayer *layer,
return QVariant();
}

QgsExpression expr( referencedLayer->displayExpression() );

QgsFeatureRequest request;
request.setFlags( QgsFeatureRequest::NoGeometry );
QgsAttributeList requiredAttributes = expr.referencedAttributeIndexes( referencedLayer->fields() ).toList();
requiredAttributes << referencedFieldIdx;
request.setSubsetOfAttributes( requiredAttributes );
QgsFeature feature;
auto iterator = referencedLayer->getFeatures();
auto iterator = referencedLayer->getFeatures( request );

QgsExpression expr( referencedLayer->displayExpression() );
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( referencedLayer ) );

expr.prepare( &context );

while ( iterator.nextFeature( feature ) )
{
context.setFeature( feature );

0 comments on commit 9f77b2d

Please sign in to comment.
You can’t perform that action at this time.