Skip to content

Commit

Permalink
Merge pull request #59707 from qgis/backport-59654-to-release-3_40
Browse files Browse the repository at this point in the history
[Backport release-3_40] [attribute form] Avoid showing a blank item in the drag and drop form layout for invalid/missing relations
  • Loading branch information
alexbruy authored Dec 3, 2024
2 parents f3527e7 + d9d1b98 commit dfe213a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/gui/vector/qgsattributesformproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid
case DnDTreeItemData::Relation:
{
const QgsRelation relation = QgsProject::instance()->relationManager()->relation( itemData.name() );

QgsAttributeEditorRelation *relDef = new QgsAttributeEditorRelation( relation, parent );
const QgsAttributesFormProperties::RelationEditorConfiguration relationEditorConfig = itemData.relationEditorConfiguration();
relDef->setRelationWidgetTypeId( relationEditorConfig.mRelationWidgetType );
Expand Down Expand Up @@ -1157,6 +1158,16 @@ QTreeWidgetItem *QgsAttributesDnDTree::addItem( QTreeWidgetItem *parent, QgsAttr
newItem->setText( 0, data.displayName() );
newItem->setIcon( 0, icon );

if ( data.type() == QgsAttributesFormProperties::DnDTreeItemData::Relation )
{
const QgsRelation relation = QgsProject::instance()->relationManager()->relation( data.name() );
if ( !relation.isValid() || relation.referencedLayer() != mLayer )
{
newItem->setText( 0, tr( "Invalid relation" ) );
newItem->setForeground( 0, QColor( 255, 0, 0 ) );
}
}

if ( index < 0 )
parent->addChild( newItem );
else
Expand Down

0 comments on commit dfe213a

Please sign in to comment.