Skip to content

Commit 94b9d8f

Browse files
committedMar 29, 2019
Fix bad layers style loss when "apply"
1 parent 559a4cb commit 94b9d8f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed
 

‎src/app/qgshandlebadlayers.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,22 @@ void QgsHandleBadLayers::apply()
413413
if ( QgsProject::instance()->mapLayer( layerId ) )
414414
{
415415
QgsMapLayer *mapLayer = QgsProject::instance()->mapLayer( layerId );
416-
if ( mapLayer )
416+
QgsDataProvider::ProviderOptions options;
417+
const auto absolutePath { QgsProject::instance()->pathResolver().readPath( datasource ) };
418+
mapLayer->setDataSource( absolutePath, name, provider, options );
419+
dataSourceFixed = mapLayer->isValid();
420+
if ( dataSourceFixed )
417421
{
418-
QgsDataProvider::ProviderOptions options;
419-
mapLayer->setDataSource( datasource, name, provider, options );
420-
dataSourceFixed = mapLayer->isValid();
422+
QString errorMsg;
423+
QgsReadWriteContext context;
424+
context.setPathResolver( QgsProject::instance()->pathResolver() );
425+
context.setProjectTranslator( QgsProject::instance() );
426+
if ( ! mapLayer->readSymbology( node, errorMsg, context ) )
427+
{
428+
QgsDebugMsg( QStringLiteral( "Failed to restore original layer style from node XML for layer %1: %2" )
429+
.arg( mapLayer->name( ) )
430+
.arg( errorMsg ) );
431+
}
421432
}
422433
}
423434

0 commit comments

Comments
 (0)
Please sign in to comment.