Skip to content
Permalink
Browse files

Fix bad layers style loss when "apply"

  • Loading branch information
elpaso committed Mar 29, 2019
1 parent 559a4cb commit 94b9d8f6f6e9336fbf04d00bb869f5c9ee6a8c5d
Showing with 15 additions and 4 deletions.
  1. +15 −4 src/app/qgshandlebadlayers.cpp
@@ -413,11 +413,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 ) );
}
}
}

0 comments on commit 94b9d8f

Please sign in to comment.
You can’t perform that action at this time.