Skip to content

Commit 686d211

Browse files
committed
Fix n:m relations in autogenerated attribute forms
Fix #16446 Fix #21491
1 parent 825c240 commit 686d211

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

‎src/gui/qgsattributeform.cpp‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,16 @@ QList<QgsEditorWidgetWrapper *> QgsAttributeForm::constraintDependencies( QgsEdi
10401040
return wDeps;
10411041
}
10421042

1043+
QgsRelationWidgetWrapper *QgsAttributeForm::setupRelationWidgetWrapper( const QgsRelation &rel, const QgsAttributeEditorContext &context )
1044+
{
1045+
QgsRelationWidgetWrapper *rww = new QgsRelationWidgetWrapper( mLayer, rel, nullptr, this );
1046+
const QVariantMap config = mLayer->editFormConfig().widgetConfig( rel.id() );
1047+
rww->setConfig( config );
1048+
rww->setContext( context );
1049+
1050+
return rww;
1051+
}
1052+
10431053
void QgsAttributeForm::preventFeatureRefresh()
10441054
{
10451055
mPreventFeatureRefresh = true;
@@ -1377,10 +1387,7 @@ void QgsAttributeForm::init()
13771387
const QList<QgsRelation> relations = QgsProject::instance()->relationManager()->referencedRelations( mLayer );
13781388
for ( const QgsRelation &rel : relations )
13791389
{
1380-
QgsRelationWidgetWrapper *rww = new QgsRelationWidgetWrapper( mLayer, rel, nullptr, this );
1381-
const QVariantMap config = mLayer->editFormConfig().widgetConfig( rel.id() );
1382-
rww->setConfig( config );
1383-
rww->setContext( mContext );
1390+
QgsRelationWidgetWrapper *rww = setupRelationWidgetWrapper( rel, mContext );
13841391

13851392
QgsAttributeFormRelationEditorWidget *formWidget = new QgsAttributeFormRelationEditorWidget( rww, this );
13861393
formWidget->createSearchWidgetWrappers( mContext );
@@ -1678,9 +1685,8 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
16781685
{
16791686
const QgsAttributeEditorRelation *relDef = static_cast<const QgsAttributeEditorRelation *>( widgetDef );
16801687

1681-
QgsRelationWidgetWrapper *rww = new QgsRelationWidgetWrapper( mLayer, relDef->relation(), nullptr, this );
1682-
rww->setConfig( mLayer->editFormConfig().widgetConfig( relDef->relation().id() ) );
1683-
rww->setContext( context );
1688+
QgsRelationWidgetWrapper *rww = setupRelationWidgetWrapper( relDef->relation(), context );
1689+
16841690
rww->setShowLabel( relDef->showLabel() );
16851691
rww->setShowLinkButton( relDef->showLinkButton() );
16861692
rww->setShowUnlinkButton( relDef->showUnlinkButton() );

‎src/gui/qgsattributeform.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class QgsMessageBarItem;
3535
class QgsWidgetWrapper;
3636
class QgsTabWidget;
3737
class QgsAttributeFormWidget;
38+
class QgsRelationWidgetWrapper;
3839

3940
/**
4041
* \ingroup gui
@@ -367,6 +368,8 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
367368
bool currentFormValidConstraints( QStringList &invalidFields, QStringList &descriptions );
368369
QList<QgsEditorWidgetWrapper *> constraintDependencies( QgsEditorWidgetWrapper *w );
369370

371+
QgsRelationWidgetWrapper *setupRelationWidgetWrapper( const QgsRelation &rel, const QgsAttributeEditorContext &context );
372+
370373
QgsVectorLayer *mLayer = nullptr;
371374
QgsFeature mFeature;
372375
QgsMessageBar *mMessageBar = nullptr;

0 commit comments

Comments
 (0)