Merge pull request #9653 from elpaso/bugfix-badlayers-apply-no-style

Fix bad layers style loss when "apply"
This commit is contained in:
Alessandro Pasotti 2019-03-30 10:32:30 +01:00 committed by GitHub
commit ca80fb6052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -412,11 +412,22 @@ void QgsHandleBadLayers::apply()
if ( QgsProject::instance()->mapLayer( layerId ) )
{
QgsMapLayer *mapLayer = QgsProject::instance()->mapLayer( layerId );
if ( mapLayer )
QgsDataProvider::ProviderOptions options;
const auto absolutePath { QgsProject::instance()->pathResolver().readPath( datasource ) };
mapLayer->setDataSource( absolutePath, name, provider, options );
dataSourceFixed = mapLayer->isValid();
if ( dataSourceFixed )
{
QgsDataProvider::ProviderOptions options;
mapLayer->setDataSource( datasource, name, provider, options );
dataSourceFixed = mapLayer->isValid();
QString errorMsg;
QgsReadWriteContext context;
context.setPathResolver( QgsProject::instance()->pathResolver() );
context.setProjectTranslator( QgsProject::instance() );
if ( ! mapLayer->readSymbology( node, errorMsg, context ) )
{
QgsDebugMsg( QStringLiteral( "Failed to restore original layer style from node XML for layer %1: %2" )
.arg( mapLayer->name( ) )
.arg( errorMsg ) );
}
}
}