Skip to content
Permalink
Browse files

Merge pull request #9413 from m-kuhn/nm-autogenerated-backport-3_6

Fix n:m relations in autogenerated attribute forms
  • Loading branch information
m-kuhn committed Mar 7, 2019
2 parents fb19acf + 9bf3410 commit a0cb6534a4b754eb09e67c0971b2e7b57c63b477
Showing with 16 additions and 7 deletions.
  1. +13 −7 src/gui/qgsattributeform.cpp
  2. +3 −0 src/gui/qgsattributeform.h
@@ -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;
@@ -1376,10 +1386,7 @@ void QgsAttributeForm::init()

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

QgsAttributeFormRelationEditorWidget *formWidget = new QgsAttributeFormRelationEditorWidget( rww, this );
formWidget->createSearchWidgetWrappers( mContext );
@@ -1677,9 +1684,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() );
@@ -35,6 +35,7 @@ class QgsMessageBarItem;
class QgsWidgetWrapper;
class QgsTabWidget;
class QgsAttributeFormWidget;
class QgsRelationWidgetWrapper;

/**
* \ingroup gui
@@ -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;

0 comments on commit a0cb653

Please sign in to comment.
You can’t perform that action at this time.