Skip to content

Commit

Permalink
Tell the bridge to update when a bad layer was fixed
Browse files Browse the repository at this point in the history
This fixes an unreported issue: when a bad layer is fixed
it does not appear in the layer order panel.

The reason why it does not appear is that a bad layer
has no geometry information, and the layer order
model does not list geometryless layers.

But after a bad layer has been fixed, it has a geometry
and the panel should show it.
  • Loading branch information
elpaso committed Dec 4, 2018
1 parent 930c56f commit b45ab5d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -6976,21 +6976,21 @@ void QgisApp::changeDataSource( QgsMapLayer *layer )
QgsMimeDataUtils::Uri uri( dlg.uri() );
if ( uri.isValid() )
{
bool layerIsValid( layer->isValid() );
bool layerWasValid( 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() &&
if ( !layerWasValid && 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 original style and subset string when fixing bad layers
if ( !( layerIsValid || layer->originalXmlProperties().isEmpty() ) )
if ( !( layerWasValid || layer->originalXmlProperties().isEmpty() ) )
{
if ( ! subsetString.isEmpty() )
{
Expand Down Expand Up @@ -7030,6 +7030,12 @@ void QgisApp::changeDataSource( QgsMapLayer *layer )
tl->setItemVisibilityChecked( true );
}
}

// Tell the bridge that we have fixed a layer
if ( ! layerWasValid && layer->isValid() )
{
QgsProject::instance()->layerTreeRoot()->customLayerOrderChanged( );
}
}
}
}
Expand Down

0 comments on commit b45ab5d

Please sign in to comment.