Skip to content

Commit 99a0167

Browse files
committedMar 7, 2019
Fix n:m relations in autogenerated attribute forms
Fix #16446 Fix #21491
1 parent c8a0051 commit 99a0167

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed
 

‎src/gui/qgsattributeform.cpp

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

1042+
QgsRelationWidgetWrapper *QgsAttributeForm::setupRelationWidgetWrapper( const QgsRelation &rel, const QgsAttributeEditorContext &context )
1043+
{
1044+
QgsRelationWidgetWrapper *rww = new QgsRelationWidgetWrapper( mLayer, rel, nullptr, this );
1045+
const QVariantMap config = mLayer->editFormConfig().widgetConfig( rel.id() );
1046+
rww->setConfig( config );
1047+
rww->setContext( context );
1048+
1049+
return rww;
1050+
}
1051+
10421052
void QgsAttributeForm::preventFeatureRefresh()
10431053
{
10441054
mPreventFeatureRefresh = true;
@@ -1375,10 +1385,7 @@ void QgsAttributeForm::init()
13751385

13761386
Q_FOREACH ( const QgsRelation &rel, QgsProject::instance()->relationManager()->referencedRelations( mLayer ) )
13771387
{
1378-
QgsRelationWidgetWrapper *rww = new QgsRelationWidgetWrapper( mLayer, rel, nullptr, this );
1379-
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, rel.id() );
1380-
rww->setConfig( setup.config() );
1381-
rww->setContext( mContext );
1388+
QgsRelationWidgetWrapper *rww = setupRelationWidgetWrapper( rel, mContext );
13821389

13831390
QgsAttributeFormRelationEditorWidget *formWidget = new QgsAttributeFormRelationEditorWidget( rww, this );
13841391
formWidget->createSearchWidgetWrappers( mContext );
@@ -1676,9 +1683,8 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
16761683
{
16771684
const QgsAttributeEditorRelation *relDef = static_cast<const QgsAttributeEditorRelation *>( widgetDef );
16781685

1679-
QgsRelationWidgetWrapper *rww = new QgsRelationWidgetWrapper( mLayer, relDef->relation(), nullptr, this );
1680-
rww->setConfig( mLayer->editFormConfig().widgetConfig( relDef->relation().id() ) );
1681-
rww->setContext( context );
1686+
QgsRelationWidgetWrapper *rww = setupRelationWidgetWrapper( relDef->relation(), context );
1687+
16821688
rww->setShowLabel( relDef->showLabel() );
16831689
rww->setShowLinkButton( relDef->showLinkButton() );
16841690
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
@@ -364,6 +365,8 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
364365
bool currentFormValidConstraints( QStringList &invalidFields, QStringList &descriptions );
365366
QList<QgsEditorWidgetWrapper *> constraintDependencies( QgsEditorWidgetWrapper *w );
366367

368+
QgsRelationWidgetWrapper *setupRelationWidgetWrapper( const QgsRelation &rel, const QgsAttributeEditorContext &context );
369+
367370
QgsVectorLayer *mLayer = nullptr;
368371
QgsFeature mFeature;
369372
QgsMessageBar *mMessageBar = nullptr;

0 commit comments

Comments
 (0)
Please sign in to comment.