Skip to content
Permalink
Browse files

Restore subset string when fixing a bad layer

  • Loading branch information
elpaso committed Nov 6, 2018
1 parent 7bf4e5b commit 39e0b7be7a5737a32ea2a08af968a03615b4e647
Showing with 16 additions and 1 deletion.
  1. +16 −1 src/app/qgisapp.cpp
@@ -6951,10 +6951,25 @@ void QgisApp::changeDataSource( QgsMapLayer *layer )
if ( uri.isValid() )
{
bool layerIsValid( layer->isValid() );
// Store subset string form vlayer if we are fixing a bad layer
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
QString subsetString;
// Get the subset string directly from the data provider because
// layer's method will return a null string from invalid layers
if ( !layerIsValid && vlayer && vlayer->dataProvider() &&
vlayer->dataProvider()->supportsSubsetString() &&
!vlayer->dataProvider()->subsetString( ).isEmpty() )
{
subsetString = vlayer->dataProvider()->subsetString();
}
layer->setDataSource( uri.uri, layer->name(), uri.providerKey, QgsDataProvider::ProviderOptions() );
// Re-apply style
// Re-apply original style and subset string when fixing bad layers
if ( !( layerIsValid || layer->originalXmlProperties().isEmpty() ) )
{
if ( ! subsetString.isEmpty() )
{
vlayer->setSubsetString( subsetString );
}
QgsReadWriteContext context;
context.setPathResolver( QgsProject::instance()->pathResolver() );
context.setProjectTranslator( QgsProject::instance() );

0 comments on commit 39e0b7b

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