Skip to content

Commit

Permalink
set cardinality (and with it the relation) of the widget and the forc…
Browse files Browse the repository at this point in the history
…eSuppressFormPopup state after the widget has been created
  • Loading branch information
signedav committed Aug 10, 2020
1 parent ba911ca commit 2f13c3c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
60 changes: 31 additions & 29 deletions src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp
Expand Up @@ -125,9 +125,10 @@ void QgsRelationWidgetWrapper::setShowSaveChildEditsButton( bool showSaveChildEd
bool QgsRelationWidgetWrapper::showLabel() const
{
if ( mWidget )
{
return mWidget->showLabel();
else
return false;
}
return false;
}

void QgsRelationWidgetWrapper::setShowLabel( bool showLabel )
Expand All @@ -154,11 +155,6 @@ void QgsRelationWidgetWrapper::initWidget( QWidget *editor )

QgsAttributeEditorContext myContext( QgsAttributeEditorContext( context(), mRelation, QgsAttributeEditorContext::Multiple, QgsAttributeEditorContext::Embed ) );

if ( forceSuppressFormPopup() )
{
const_cast<QgsVectorLayerTools *>( myContext.vectorLayerTools() )->setForceSuppressFormPopup( true );
}

/* TODO: this seems to have no effect
if ( config( QStringLiteral( "hide-save-child-edits" ), false ).toBool() )
{
Expand All @@ -168,24 +164,6 @@ void QgsRelationWidgetWrapper::initWidget( QWidget *editor )

w->setEditorContext( myContext );

mNmRelation = QgsProject::instance()->relationManager()->relation( cardinality().toString() );

// If this widget is already embedded by the same relation, reduce functionality
const QgsAttributeEditorContext *ctx = &context();
do
{
if ( ( ctx->relation().name() == mRelation.name() && ctx->formMode() == QgsAttributeEditorContext::Embed )
|| ( mNmRelation.isValid() && ctx->relation().name() == mNmRelation.name() ) )
{
w->setVisible( false );
break;
}
ctx = ctx->parentContext();
}
while ( ctx );

w->setRelations( mRelation, mNmRelation );

mWidget = w;
}

Expand Down Expand Up @@ -226,27 +204,51 @@ QgsAttributeEditorRelation::Buttons QgsRelationWidgetWrapper::visibleButtons() c
void QgsRelationWidgetWrapper::setForceSuppressFormPopup( bool forceSuppressFormPopup )
{
if ( mWidget )
{
mWidget->setForceSuppressFormPopup( forceSuppressFormPopup );
if ( forceSuppressFormPopup )
{
const_cast<QgsVectorLayerTools *>( mWidget->editorContext().vectorLayerTools() )->setForceSuppressFormPopup( true );
}
}
}

bool QgsRelationWidgetWrapper::forceSuppressFormPopup() const
{
if ( mWidget )
return mWidget->forceSuppressFormPopup();
else
return false;
return false;
}

void QgsRelationWidgetWrapper::setCardinality( const QVariant &cardinality )
{
if ( mWidget )
{
mWidget->setCardinality( cardinality );

mNmRelation = QgsProject::instance()->relationManager()->relation( cardinality.toString() );

// If this widget is already embedded by the same relation, reduce functionality
const QgsAttributeEditorContext *ctx = &context();
do
{
if ( ( ctx->relation().name() == mRelation.name() && ctx->formMode() == QgsAttributeEditorContext::Embed )
|| ( mNmRelation.isValid() && ctx->relation().name() == mNmRelation.name() ) )
{
mWidget->setVisible( false );
break;
}
ctx = ctx->parentContext();
}
while ( ctx );

mWidget->setRelations( mRelation, mNmRelation );
}
}

QVariant QgsRelationWidgetWrapper::cardinality() const
{
if ( mWidget )
return mWidget->cardinality();
else
return QVariant();
return QVariant();
}
3 changes: 1 addition & 2 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -1254,8 +1254,6 @@ QList<QgsEditorWidgetWrapper *> QgsAttributeForm::constraintDependencies( QgsEdi
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;
Expand Down Expand Up @@ -1962,6 +1960,7 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
mFormWidgets.append( formWidget );

newWidgetInfo.widget = formWidget;
newWidgetInfo.showLabel = relDef->showLabel();
newWidgetInfo.labelText = QString();
newWidgetInfo.labelOnTop = true;
break;
Expand Down

0 comments on commit 2f13c3c

Please sign in to comment.