Skip to content
Permalink
Browse files

Revert "Tell the bridge to update when a bad layer was fixed"

This reverts commit 408e2d3.
  • Loading branch information
elpaso committed Dec 5, 2018
1 parent 408e2d3 commit bb2b6a033eaf11ff309997ca25e7f5baaf092def
Showing with 0 additions and 77 deletions.
  1. +0 −77 src/app/qgisapp.cpp
@@ -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 );

0 comments on commit bb2b6a0

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