Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix n:m relations in autogenerated attribute forms
Fix #16446
Fix #21491
  • Loading branch information
m-kuhn committed Mar 6, 2019
1 parent 825c240 commit 686d211
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -1040,6 +1040,16 @@ QList<QgsEditorWidgetWrapper *> QgsAttributeForm::constraintDependencies( QgsEdi
return wDeps;
}

QgsRelationWidgetWrapper *QgsAttributeForm::setupRelationWidgetWrapper( const QgsRelation &rel, const QgsAttributeEditorContext &context )
{
QgsRelationWidgetWrapper *rww = new QgsRelationWidgetWrapper( mLayer, rel, nullptr, this );
const QVariantMap config = mLayer->editFormConfig().widgetConfig( rel.id() );
rww->setConfig( config );
rww->setContext( context );

return rww;
}

void QgsAttributeForm::preventFeatureRefresh()
{
mPreventFeatureRefresh = true;
Expand Down Expand Up @@ -1377,10 +1387,7 @@ void QgsAttributeForm::init()
const QList<QgsRelation> relations = QgsProject::instance()->relationManager()->referencedRelations( mLayer );
for ( const QgsRelation &rel : relations )
{
QgsRelationWidgetWrapper *rww = new QgsRelationWidgetWrapper( mLayer, rel, nullptr, this );
const QVariantMap config = mLayer->editFormConfig().widgetConfig( rel.id() );
rww->setConfig( config );
rww->setContext( mContext );
QgsRelationWidgetWrapper *rww = setupRelationWidgetWrapper( rel, mContext );

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

QgsRelationWidgetWrapper *rww = new QgsRelationWidgetWrapper( mLayer, relDef->relation(), nullptr, this );
rww->setConfig( mLayer->editFormConfig().widgetConfig( relDef->relation().id() ) );
rww->setContext( context );
QgsRelationWidgetWrapper *rww = setupRelationWidgetWrapper( relDef->relation(), context );

rww->setShowLabel( relDef->showLabel() );
rww->setShowLinkButton( relDef->showLinkButton() );
rww->setShowUnlinkButton( relDef->showUnlinkButton() );
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsattributeform.h
Expand Up @@ -35,6 +35,7 @@ class QgsMessageBarItem;
class QgsWidgetWrapper;
class QgsTabWidget;
class QgsAttributeFormWidget;
class QgsRelationWidgetWrapper;

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

QgsRelationWidgetWrapper *setupRelationWidgetWrapper( const QgsRelation &rel, const QgsAttributeEditorContext &context );

QgsVectorLayer *mLayer = nullptr;
QgsFeature mFeature;
QgsMessageBar *mMessageBar = nullptr;
Expand Down

0 comments on commit 686d211

Please sign in to comment.