Skip to content

Commit

Permalink
Generated relations should not be used for relation reference widget
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus committed Jan 18, 2021
1 parent 439e290 commit 8a9fa3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/gui/editorwidgets/qgsrelationreferenceconfigdlg.cpp
Expand Up @@ -38,6 +38,9 @@ QgsRelationReferenceConfigDlg::QgsRelationReferenceConfigDlg( QgsVectorLayer *vl
const auto constReferencingRelations = vl->referencingRelations( fieldIdx );
for ( const QgsRelation &relation : constReferencingRelations )
{
if ( !relation.polymorphicRelationId().isNull() )
continue;

if ( relation.name().isEmpty() )
mComboRelation->addItem( QStringLiteral( "%1 (%2)" ).arg( relation.id(), relation.referencedLayerId() ), relation.id() );
else
Expand Down
9 changes: 8 additions & 1 deletion src/gui/editorwidgets/qgsrelationreferencefactory.cpp
Expand Up @@ -56,6 +56,13 @@ QHash<const char *, int> QgsRelationReferenceFactory::supportedWidgetTypes()

unsigned int QgsRelationReferenceFactory::fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const
{
int nonGeneratedRelationsCount = 0;
const QList<QgsRelation> relations = vl->referencingRelations( fieldIdx );
return !relations.isEmpty() ? 21 /*A bit stronger than the range widget*/ : 5;
for ( const QgsRelation &rel : relations )
{
if ( rel.polymorphicRelationId().isNull() )
nonGeneratedRelationsCount++;
}
// generated relations should not be used for relation reference widget
return nonGeneratedRelationsCount > 0 ? 21 /*A bit stronger than the range widget*/ : 5;
}

0 comments on commit 8a9fa3a

Please sign in to comment.