Skip to content

Commit 8689c09

Browse files
committedAug 17, 2020
fallback writing nm-rel and force-suppress-popup to the tab config
1 parent 79d50da commit 8689c09

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
 

‎src/core/qgseditformconfig.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,45 @@ void QgsEditFormConfig::onRelationsLoaded()
8888
}
8989
}
9090

91+
bool QgsEditFormConfig::updateRelationWidgetInTabs( QgsAttributeEditorContainer *container, const QString &widgetName, const QVariantMap &config )
92+
{
93+
QList<QgsAttributeEditorElement *> children = container->children();
94+
for ( QgsAttributeEditorElement *child : children )
95+
{
96+
qDebug() << QString( "it's item named %1 and type %2" ).arg( child->name() ).arg( child->type() );
97+
98+
if ( child->type() == QgsAttributeEditorElement::AeTypeContainer )
99+
{
100+
QgsAttributeEditorContainer *container = dynamic_cast<QgsAttributeEditorContainer *>( child );
101+
if ( updateRelationWidgetInTabs( container, widgetName, config ) )
102+
{
103+
//return when a relation has been set in a child or child child...
104+
return true;
105+
}
106+
}
107+
else if ( child->type() == QgsAttributeEditorElement::AeTypeRelation )
108+
{
109+
QgsAttributeEditorRelation *relation = dynamic_cast< QgsAttributeEditorRelation * >( child );
110+
if ( relation )
111+
{
112+
if ( relation->relation().id() == widgetName )
113+
{
114+
if ( config.contains( QStringLiteral( "nm-rel" ) ) )
115+
{
116+
relation->setNmRelationId( config[QStringLiteral( "nm-rel" )] );
117+
}
118+
if ( config.contains( QStringLiteral( "force-suppress-popup" ) ) )
119+
{
120+
relation->setForceSuppressFormPopup( config[QStringLiteral( "force-suppress-popup" )].toBool() );
121+
}
122+
return true;
123+
}
124+
}
125+
}
126+
}
127+
return false;
128+
}
129+
91130
bool QgsEditFormConfig::setWidgetConfig( const QString &widgetName, const QVariantMap &config )
92131
{
93132
if ( d->mFields.indexOf( widgetName ) != -1 )
@@ -96,6 +135,12 @@ bool QgsEditFormConfig::setWidgetConfig( const QString &widgetName, const QVaria
96135
return false;
97136
}
98137

138+
if ( config.contains( QStringLiteral( "force-suppress-popup" ) ) || config.contains( QStringLiteral( "nm-rel" ) ) )
139+
{
140+
//set it in the tab for the first relation editor widget
141+
updateRelationWidgetInTabs( d->mInvisibleRootContainer, widgetName, config );
142+
}
143+
99144
d.detach();
100145
d->mWidgetConfigs[widgetName] = config;
101146
return true;

‎src/core/qgseditformconfig.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ class CORE_EXPORT QgsEditFormConfig
348348
*/
349349
void onRelationsLoaded();
350350

351+
/**
352+
* Used internally for the backwards compatibility of the api, on setting nmrel or force-suppress-popup for relations
353+
* Returns true when a relation (the first one found) has been updated
354+
*/
355+
bool updateRelationWidgetInTabs( QgsAttributeEditorContainer *container, const QString &widgetName, const QVariantMap &config );
356+
351357
private:
352358
QExplicitlySharedDataPointer<QgsEditFormConfigPrivate> d;
353359

0 commit comments

Comments
 (0)
Please sign in to comment.