Skip to content

Commit

Permalink
Disable the generated relations for poly rels in the relation dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus committed Jan 18, 2021
1 parent d092770 commit 17deefe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/gui/editorwidgets/qgsrelationreferenceconfigdlg.cpp
Expand Up @@ -38,13 +38,17 @@ QgsRelationReferenceConfigDlg::QgsRelationReferenceConfigDlg( QgsVectorLayer *vl
const auto constReferencingRelations = vl->referencingRelations( fieldIdx );
for ( const QgsRelation &relation : constReferencingRelations )
{
if ( relation.type() == QgsRelation::Generated )
continue;

if ( relation.name().isEmpty() )
mComboRelation->addItem( QStringLiteral( "%1 (%2)" ).arg( relation.id(), relation.referencedLayerId() ), relation.id() );
else
mComboRelation->addItem( QStringLiteral( "%1 (%2)" ).arg( relation.name(), relation.referencedLayerId() ), relation.id() );

QStandardItemModel *model = qobject_cast<QStandardItemModel *>( mComboRelation->model() );
QStandardItem *item = model->item( model->rowCount() - 1 );
item->setFlags( relation.type() == QgsRelation::Generated
? item->flags() & ~Qt::ItemIsEnabled
: item->flags() | Qt::ItemIsEnabled );

if ( auto *lReferencedLayer = relation.referencedLayer() )
{
mExpressionWidget->setField( lReferencedLayer->displayExpression() );
Expand Down
3 changes: 3 additions & 0 deletions src/ui/editorwidgets/qgsrelationreferenceconfigdlgbase.ui
Expand Up @@ -30,6 +30,9 @@
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mComboRelation">
<property name="toolTip">
<string>The generated relations for a polymorphic relation cannot be used.</string>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
Expand Down

0 comments on commit 17deefe

Please sign in to comment.