Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
When loading a QLR, try to match the layer name if id does not
Fixes #30115
  • Loading branch information
elpaso committed Jun 10, 2019
1 parent 5201151 commit f02b1ee
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/gui/editorwidgets/qgsvaluerelationconfigdlg.cpp
Expand Up @@ -55,6 +55,7 @@ QVariantMap QgsValueRelationConfigDlg::config()
QVariantMap cfg;

cfg.insert( QStringLiteral( "Layer" ), mLayerName->currentLayer() ? mLayerName->currentLayer()->id() : QString() );
cfg.insert( QStringLiteral( "LayerName" ), mLayerName->currentLayer() ? mLayerName->currentLayer()->name() : QString() );
cfg.insert( QStringLiteral( "Key" ), mKeyColumn->currentField() );
cfg.insert( QStringLiteral( "Value" ), mValueColumn->currentField() );
cfg.insert( QStringLiteral( "AllowMulti" ), mAllowMulti->isChecked() );
Expand All @@ -70,6 +71,23 @@ QVariantMap QgsValueRelationConfigDlg::config()
void QgsValueRelationConfigDlg::setConfig( const QVariantMap &config )
{
QgsVectorLayer *lyr = QgsProject::instance()->mapLayer<QgsVectorLayer *>( config.value( QStringLiteral( "Layer" ) ).toString() );
// If layer is null, let's try to match it against name and provider
if ( ! lyr )
{
const auto name { config.value( QStringLiteral( "LayerName" ) ).toString() };
if ( ! name.isEmpty() )
{
for ( const auto &l : QgsProject::instance()->mapLayers( true ) )
{
QgsVectorLayer *vl { qobject_cast<QgsVectorLayer *>( l ) };
if ( vl && vl->name() == name )
{
lyr = vl;
break;
}
}
}
}
mLayerName->setLayer( lyr );
mKeyColumn->setField( config.value( QStringLiteral( "Key" ) ).toString() );
mValueColumn->setField( config.value( QStringLiteral( "Value" ) ).toString() );
Expand Down

0 comments on commit f02b1ee

Please sign in to comment.