@@ -268,7 +268,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
268
268
269
269
// We have to filter by extensions, otherwise e.g. all Shapefile files are displayed
270
270
// because OGR drive can open also .dbf, .shx.
271
- if ( myExtensions.indexOf ( info. suffix (). toLower () ) < 0 )
271
+ if ( myExtensions.indexOf ( suffix ) < 0 )
272
272
{
273
273
bool matches = false ;
274
274
foreach ( QString wildcard, wildcards () )
@@ -285,7 +285,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
285
285
}
286
286
287
287
// .dbf should probably appear if .shp is not present
288
- if ( info. suffix (). toLower () == " dbf" )
288
+ if ( suffix == " dbf" )
289
289
{
290
290
QString pathShp = thePath.left ( thePath.count () - 4 ) + " .shp" ;
291
291
if ( QFileInfo ( pathShp ).exists () )
@@ -310,20 +310,33 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
310
310
}
311
311
}
312
312
313
- // if setting = 2 (Basic scan), return a /vsizip/ item without testing
314
- if ( is_vsizip && scanZipSetting == 2 )
315
- {
316
- QStringList sublayers;
317
- QgsDebugMsg ( QString ( " adding item name=%1 thePath=%2" ).arg ( name ).arg ( thePath ) );
318
- QgsLayerItem * item = new QgsOgrLayerItem ( parentItem, name, thePath, thePath, QgsLayerItem::Vector );
319
- if ( item )
320
- return item;
321
- }
322
-
323
- // if scan items == "Check extension", add item here without trying to open
324
- // unless item is /vsizip
325
- if ( scanItemsSetting == 1 && !is_vsizip && !is_vsigzip )
313
+ // return a /vsizip/ item without testing if:
314
+ // zipfile and scan zip == "Basic scan"
315
+ // not zipfile and scan items == "Check extension"
316
+ if (( is_vsizip && scanZipSetting == 2 ) ||
317
+ ( !is_vsizip && scanItemsSetting == 1 ) )
326
318
{
319
+ // if this is a VRT file make sure it is vector VRT to avoid duplicates
320
+ if ( suffix == " vrt" )
321
+ {
322
+ OGRSFDriverH hDriver = OGRGetDriverByName ( " VRT" );
323
+ if ( hDriver )
324
+ {
325
+ // do not print errors, but write to debug
326
+ CPLPushErrorHandler ( CPLQuietErrorHandler );
327
+ CPLErrorReset ();
328
+ OGRDataSourceH hDataSource = OGR_Dr_Open ( hDriver, thePath.toLocal8Bit ().constData (), 0 );
329
+ CPLPopErrorHandler ();
330
+ if ( ! hDataSource )
331
+ {
332
+ QgsDebugMsg ( " Skipping VRT file because root is not a OGR VRT" );
333
+ return 0 ;
334
+ }
335
+ OGR_DS_Destroy ( hDataSource );
336
+ }
337
+ }
338
+ // add the item
339
+ // TODO: how to handle collections?
327
340
QgsLayerItem * item = new QgsOgrLayerItem ( parentItem, name, thePath, thePath, QgsLayerItem::Vector );
328
341
if ( item )
329
342
return item;
@@ -333,10 +346,10 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
333
346
OGRRegisterAll ();
334
347
OGRSFDriverH hDriver;
335
348
// do not print errors, but write to debug
336
- CPLErrorHandler oErrorHandler = CPLSetErrorHandler ( CPLQuietErrorHandler );
349
+ CPLPushErrorHandler ( CPLQuietErrorHandler );
337
350
CPLErrorReset ();
338
351
OGRDataSourceH hDataSource = OGROpen ( TO8F ( thePath ), false , &hDriver );
339
- CPLSetErrorHandler ( oErrorHandler );
352
+ CPLPopErrorHandler ( );
340
353
341
354
if ( ! hDataSource )
342
355
{
0 commit comments