Skip to content

Commit

Permalink
set the first relation editor widget instance when setting the nm-rel…
Browse files Browse the repository at this point in the history
… and the force-suppress-popup the legacy way over setWidgetConfig to keep it backwards compatible
  • Loading branch information
signedav committed Aug 17, 2020
1 parent 8689c09 commit ee13bc2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/core/qgseditformconfig.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgslogger.h"
#include "qgsxmlutils.h"
#include "qgsapplication.h"
#include "qgsmessagelog.h"

QgsAttributeEditorContainer::~QgsAttributeEditorContainer()
{
Expand Down Expand Up @@ -88,17 +89,15 @@ void QgsEditFormConfig::onRelationsLoaded()
}
}

bool QgsEditFormConfig::updateRelationWidgetInTabs( QgsAttributeEditorContainer *container, const QString &widgetName, const QVariantMap &config )
bool QgsEditFormConfig::legacyUpdateRelationWidgetInTabs( QgsAttributeEditorContainer *container, const QString &widgetName, const QVariantMap &config )
{
QList<QgsAttributeEditorElement *> children = container->children();
const 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 ) )
if ( legacyUpdateRelationWidgetInTabs( container, widgetName, config ) )
{
//return when a relation has been set in a child or child child...
return true;
Expand Down Expand Up @@ -135,10 +134,11 @@ bool QgsEditFormConfig::setWidgetConfig( const QString &widgetName, const QVaria
return false;
}

//for legacy use it writes the relation editor configuration into the first instance of the widget
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 );
QgsMessageLog::logMessage( QStringLiteral( "Relation settings should be done for the specific widget instance like attributeEditorRelation->setNmRelationId() instead." ) );
legacyUpdateRelationWidgetInTabs( d->mInvisibleRootContainer, widgetName, config );
}

d.detach();
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgseditformconfig.h
Expand Up @@ -349,10 +349,10 @@ 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
* Used for the backwards compatibility of the api, on setting nmrel or force-suppress-popup for relations.
* Returns true when a relation instance (the first one found) has been updated.
*/
bool updateRelationWidgetInTabs( QgsAttributeEditorContainer *container, const QString &widgetName, const QVariantMap &config );
bool legacyUpdateRelationWidgetInTabs( QgsAttributeEditorContainer *container, const QString &widgetName, const QVariantMap &config );

private:
QExplicitlySharedDataPointer<QgsEditFormConfigPrivate> d;
Expand Down

0 comments on commit ee13bc2

Please sign in to comment.