Skip to content

Commit

Permalink
Revert "Tell the bridge to update when a bad layer was fixed"
Browse files Browse the repository at this point in the history
This reverts commit 408e2d3.
  • Loading branch information
elpaso committed Dec 5, 2018
1 parent 408e2d3 commit bb2b6a0
Showing 1 changed file with 0 additions and 77 deletions.
77 changes: 0 additions & 77 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6934,83 +6934,6 @@ void QgisApp::refreshFeatureActions()
updateDefaultFeatureAction( mFeatureActionMenu->activeAction() );
}

void QgisApp::changeDataSource( QgsMapLayer *layer )
{
// Get provider type
QString providerType( layer->providerType() );
QgsMapLayer::LayerType layerType( layer->type() );

QgsDataSourceSelectDialog dlg( mBrowserModel, true, layerType );

if ( dlg.exec() == QDialog::Accepted )
{
QgsMimeDataUtils::Uri uri( dlg.uri() );
if ( uri.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 ( !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 ( !( layerWasValid || layer->originalXmlProperties().isEmpty() ) )
{
if ( ! subsetString.isEmpty() )
{
vlayer->setSubsetString( subsetString );
}
QgsReadWriteContext context;
context.setPathResolver( QgsProject::instance()->pathResolver() );
context.setProjectTranslator( QgsProject::instance() );
QString errorMsg;
QDomDocument doc;
if ( doc.setContent( layer->originalXmlProperties() ) )
{
QDomNode layer_node( doc.firstChild( ) );
if ( ! layer->readSymbology( layer_node, errorMsg, context ) )
{
QgsDebugMsg( QStringLiteral( "Failed to restore original layer style from stored XML for layer %1: %2" )
.arg( layer->name( ) )
.arg( errorMsg ) );
}
}
else
{
QgsDebugMsg( QStringLiteral( "Failed to create XML QDomDocument for layer %1: %2" )
.arg( layer->name( ) )
.arg( errorMsg ) );
}
}

// All the following code is necessary to refresh the layer
QgsLayerTreeModel *model = qobject_cast<QgsLayerTreeModel *>( mLayerTreeView->model() );
if ( model )
{
QgsLayerTreeLayer *tl( model->rootGroup()->findLayer( layer->id() ) );
if ( tl && tl->itemVisibilityChecked() )
{
tl->setItemVisibilityChecked( false );
tl->setItemVisibilityChecked( true );
}
}

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

void QgisApp::measure()
{
mMapCanvas->setMapTool( mMapTools.mMeasureDist );
Expand Down

0 comments on commit bb2b6a0

Please sign in to comment.