Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes relation reference widget crash when no relation
  • Loading branch information
pblottiere committed Nov 27, 2017
1 parent 9bfb3f3 commit b1008c7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/gui/editorwidgets/qgsrelationreferencewidgetwrapper.cpp
Expand Up @@ -64,9 +64,12 @@ void QgsRelationReferenceWidgetWrapper::initWidget( QWidget *editor )
mWidget->setAllowAddFeatures( config( QStringLiteral( "AllowAddFeatures" ), false ).toBool() );

const QVariant relationName = config( QStringLiteral( "Relation" ) );
QgsRelation relation = relationName.isValid() ?
QgsProject::instance()->relationManager()->relation( relationName.toString() ) :
layer()->referencingRelations( fieldIdx() )[0];

QgsRelation relation; // invalid relation by default
if ( relationName.isValid() )
relation = QgsProject::instance()->relationManager()->relation( relationName.toString() );
else if ( ! layer()->referencingRelations( fieldIdx() ).isEmpty() )
relation = layer()->referencingRelations( fieldIdx() )[0];

// If this widget is already embedded by the same relation, reduce functionality
const QgsAttributeEditorContext *ctx = &context();
Expand Down

0 comments on commit b1008c7

Please sign in to comment.