Skip to content

Commit

Permalink
Merge pull request #9653 from elpaso/bugfix-badlayers-apply-no-style
Browse files Browse the repository at this point in the history
Fix bad layers style loss when "apply"
  • Loading branch information
elpaso committed Mar 30, 2019
2 parents 41f3ac0 + 94b9d8f commit ca80fb6
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/app/qgshandlebadlayers.cpp
Expand Up @@ -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 ) );
}
}
}

Expand Down

0 comments on commit ca80fb6

Please sign in to comment.