Skip to content


Browse files Browse the repository at this point in the history
Change data source when re-adding an existing layer to the store
The previous implementation was just skipping a layer if
a layer with the same id was already in the store, we are
now checking if the layer validity has changed from invalid
to valid, and in that case we reset the data source of the
existing layer.

Use case: bad layer handling.
  • Loading branch information
elpaso committed Mar 25, 2019
1 parent 4a43bba commit 8e42783
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/qgsmaplayerstore.cpp
Expand Up @@ -74,6 +74,11 @@ QList<QgsMapLayer *> QgsMapLayerStore::addMapLayers( const QList<QgsMapLayer *>
QgsDebugMsg( QStringLiteral( "Cannot add null layers" ) );
// If the layer is already in the store but its validity has changed reset data source
if ( mMapLayers.contains( myLayer->id() ) && ! mMapLayers[myLayer->id()]->isValid() && myLayer->isValid() && myLayer->dataProvider() )
mMapLayers[myLayer->id()]->setDataSource( myLayer->dataProvider()->dataSourceUri(), myLayer->name(), myLayer->providerType(), QgsDataProvider::ProviderOptions() );
//check the layer is not already registered!
if ( !mMapLayers.contains( myLayer->id() ) )
Expand Down

0 comments on commit 8e42783

Please sign in to comment.