Skip to content
Browse files
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 8e4278380ac5c8add9d651dc249d59de65925f65
Showing with 5 additions and 0 deletions.
  1. +5 −0 src/core/qgsmaplayerstore.cpp
@@ -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() ) )

0 comments on commit 8e42783

Please sign in to comment.