Skip to content
Permalink
Browse files

[browser] Avoid always opening every file using gdal to test for

update capabilities

This is no longer required - it was previously done in order to
detect if the item should expose the SetCrs capability, but
that's deprecated and unused.

Fixes #16807, fixes #20411, and avoids QGIS opening every file encountered in
the browser even when the Data Source setting is set to the
default (fast) "Check Extension" setting only.
  • Loading branch information
nyalldawson committed Feb 6, 2019
1 parent d61694c commit 2c64cece0d1a51c37d27c1b11e76d76bb62184f3
Showing with 0 additions and 27 deletions.
  1. +0 −8 src/providers/gdal/qgsgdaldataitems.cpp
  2. +0 −19 src/providers/ogr/qgsogrdataitems.cpp
@@ -48,14 +48,6 @@ QgsGdalLayerItem::QgsGdalLayerItem( QgsDataItem *parent,
}
else
setState( Populated );

GDALAllRegister();
gdal::dataset_unique_ptr hDS( GDALOpen( mPath.toUtf8().constData(), GA_Update ) );

if ( hDS )
{
mCapabilities |= SetCrs;
}
}


@@ -53,30 +53,11 @@ QgsOgrLayerItem::QgsOgrLayerItem( QgsDataItem *parent,
mIsSubLayer = isSubLayer;
mToolTip = uri;
setState( Populated ); // children are not expected

if ( mPath.endsWith( QLatin1String( ".shp" ), Qt::CaseInsensitive ) )
{
if ( OGRGetDriverCount() == 0 )
{
OGRRegisterAll();
}
gdal::dataset_unique_ptr hDataSource( GDALOpenEx( mPath.toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
if ( hDataSource )
{
mCapabilities |= SetCrs;
}

// It it is impossible to assign a crs to an existing layer
// No OGR_L_SetSpatialRef : http://trac.osgeo.org/gdal/ticket/4032
}
}


bool QgsOgrLayerItem::setCrs( const QgsCoordinateReferenceSystem &crs )
{
if ( !( mCapabilities & SetCrs ) )
return false;

QString layerName = mPath.left( mPath.indexOf( QLatin1String( ".shp" ), Qt::CaseInsensitive ) );
QString wkt = crs.toWkt();

0 comments on commit 2c64cec

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