Skip to content

Commit cd59091

Browse files
committed
use layer's displayExpression in relation reference widget line edit
1 parent 69fc9bb commit cd59091

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/gui/editorwidgets/qgsrelationreferencewidget.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,13 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
230230

231231
if ( mReadOnlySelector )
232232
{
233-
mLineEdit->setText( f.attribute( mFkeyFieldIdx ).toString() );
233+
QgsExpression expr( mReferencedLayer->displayExpression() );
234+
QString title = expr.evaluate( &f ).toString();
235+
if ( expr.hasEvalError() )
236+
{
237+
title = f.attribute( mFkeyFieldIdx ).toString();
238+
}
239+
mLineEdit->setText( title );
234240
mFeatureId = f.id();
235241
}
236242
else
@@ -565,7 +571,13 @@ void QgsRelationReferenceWidget::featureIdentified( const QgsFeature& feature )
565571
{
566572
if ( mReadOnlySelector )
567573
{
568-
mLineEdit->setText( feature.attribute( mFkeyFieldIdx ).toString() );
574+
QgsExpression expr( mReferencedLayer->displayExpression() );
575+
QString title = expr.evaluate( &feature ).toString();
576+
if ( expr.hasEvalError() )
577+
{
578+
title = feature.attribute( mFkeyFieldIdx ).toString();
579+
}
580+
mLineEdit->setText( title );
569581
mForeignKey = feature.attribute( mFkeyFieldIdx );
570582
mFeatureId = feature.id();
571583
}

0 commit comments

Comments
 (0)