Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fallback writing nm-rel and force-suppress-popup to the tab config
  • Loading branch information
signedav committed Aug 17, 2020
1 parent 79d50da commit 8689c09
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/core/qgseditformconfig.cpp
Expand Up @@ -88,6 +88,45 @@ void QgsEditFormConfig::onRelationsLoaded()
}
}

bool QgsEditFormConfig::updateRelationWidgetInTabs( QgsAttributeEditorContainer *container, const QString &widgetName, const QVariantMap &config )
{
QList<QgsAttributeEditorElement *> children = container->children();
for ( QgsAttributeEditorElement *child : children )
{
qDebug() << QString( "it's item named %1 and type %2" ).arg( child->name() ).arg( child->type() );

if ( child->type() == QgsAttributeEditorElement::AeTypeContainer )
{
QgsAttributeEditorContainer *container = dynamic_cast<QgsAttributeEditorContainer *>( child );
if ( updateRelationWidgetInTabs( container, widgetName, config ) )
{
//return when a relation has been set in a child or child child...
return true;
}
}
else if ( child->type() == QgsAttributeEditorElement::AeTypeRelation )
{
QgsAttributeEditorRelation *relation = dynamic_cast< QgsAttributeEditorRelation * >( child );
if ( relation )
{
if ( relation->relation().id() == widgetName )
{
if ( config.contains( QStringLiteral( "nm-rel" ) ) )
{
relation->setNmRelationId( config[QStringLiteral( "nm-rel" )] );
}
if ( config.contains( QStringLiteral( "force-suppress-popup" ) ) )
{
relation->setForceSuppressFormPopup( config[QStringLiteral( "force-suppress-popup" )].toBool() );
}
return true;
}
}
}
}
return false;
}

bool QgsEditFormConfig::setWidgetConfig( const QString &widgetName, const QVariantMap &config )
{
if ( d->mFields.indexOf( widgetName ) != -1 )
Expand All @@ -96,6 +135,12 @@ bool QgsEditFormConfig::setWidgetConfig( const QString &widgetName, const QVaria
return false;
}

if ( config.contains( QStringLiteral( "force-suppress-popup" ) ) || config.contains( QStringLiteral( "nm-rel" ) ) )
{
//set it in the tab for the first relation editor widget
updateRelationWidgetInTabs( d->mInvisibleRootContainer, widgetName, config );
}

d.detach();
d->mWidgetConfigs[widgetName] = config;
return true;
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgseditformconfig.h
Expand Up @@ -348,6 +348,12 @@ class CORE_EXPORT QgsEditFormConfig
*/
void onRelationsLoaded();

/**
* Used internally for the backwards compatibility of the api, on setting nmrel or force-suppress-popup for relations
* Returns true when a relation (the first one found) has been updated
*/
bool updateRelationWidgetInTabs( QgsAttributeEditorContainer *container, const QString &widgetName, const QVariantMap &config );

private:
QExplicitlySharedDataPointer<QgsEditFormConfigPrivate> d;

Expand Down

0 comments on commit 8689c09

Please sign in to comment.