Skip to content

Commit

Permalink
care for the relation widget config made or read over the API
Browse files Browse the repository at this point in the history
means the force-suppress-popup and nm-rel in the editFormConfig are written according to the first instance of the widget-tree from same type and name for each relation. and on creating the widget it reads first this config and is only overwritten if there are specific widget config available.
  • Loading branch information
signedav committed Aug 10, 2020
1 parent b19f1da commit 0542f9f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp
Expand Up @@ -155,13 +155,38 @@ void QgsRelationWidgetWrapper::initWidget( QWidget *editor )

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

// read the legacy config of force-suppress-popup to support settings made by the API
if ( config( QStringLiteral( "force-suppress-popup" ), false ).toBool() )
{
const_cast<QgsVectorLayerTools *>( myContext.vectorLayerTools() )->setForceSuppressFormPopup( true );
}

/* TODO: this seems to have no effect
if ( config( QStringLiteral( "hide-save-child-edits" ), false ).toBool() )
{
w->setShowSaveChildEditsButton( false );
}
*/

// read the legacy config of nm-rel to support settings made by the API
mNmRelation = QgsProject::instance()->relationManager()->relation( config( QStringLiteral( "nm-rel" ) ).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 );

w->setEditorContext( myContext );

mWidget = w;
Expand Down
28 changes: 27 additions & 1 deletion src/gui/vector/qgsattributesformproperties.cpp
Expand Up @@ -506,7 +506,7 @@ void QgsAttributesFormProperties::loadAttributeSpecificEditor( QgsAttributesDnDT
{
case DnDTreeItemData::Relation:
{
receiver->clearSelection();
receiver->selectFirstMatchingItem( itemData );
if ( layout == QgsEditFormConfig::EditorLayout::TabLayout )
loadAttributeWidgetEdit();
break;
Expand Down Expand Up @@ -827,6 +827,32 @@ void QgsAttributesFormProperties::apply()

editFormConfig.setSuppress( static_cast<QgsEditFormConfig::FeatureFormSuppress>( mFormSuppressCmbBx->currentIndex() ) );

// write the legacy config of relation widgets to support settings read by the API
QTreeWidgetItem *relationContainer = mAvailableWidgetsTree->invisibleRootItem()->child( 1 );

for ( int i = 0; i < relationContainer->childCount(); i++ )
{
QTreeWidgetItem *relationItem = relationContainer->child( i );
DnDTreeItemData itemData = relationItem->data( 0, DnDTreeRole ).value<DnDTreeItemData>();

for ( int t = 0; t < mFormLayoutTree->invisibleRootItem()->childCount(); t++ )
{
QTreeWidgetItem *tabItem = mFormLayoutTree->invisibleRootItem()->child( t );
const DnDTreeItemData tabItemData = tabItem->data( 0, DnDTreeRole ).value<DnDTreeItemData>();

if ( tabItemData.type() == itemData.type() && tabItemData.name() == itemData.name() )
{
QVariantMap cfg;

cfg[QStringLiteral( "nm-rel" )] = tabItemData.relationEditorConfiguration().cardinality;
cfg[QStringLiteral( "force-suppress-popup" )] = tabItemData.relationEditorConfiguration().forceSuppressFormPopup;

editFormConfig.setWidgetConfig( tabItemData.name(), cfg );
break;
}
}
}

mLayer->setEditFormConfig( editFormConfig );
}

Expand Down

0 comments on commit 0542f9f

Please sign in to comment.