25
25
#include " qgsgeopackagedataitems.h"
26
26
#include " qgsogrutils.h"
27
27
#include " qgsproviderregistry.h"
28
+ #include " qgssqliteutils.h"
28
29
#include " symbology/qgsstyle.h"
29
30
30
31
#include < QFileInfo>
33
34
#include < QMessageBox>
34
35
#include < QInputDialog>
35
36
#include < QFileDialog>
37
+ #include < QRegularExpression>
36
38
37
39
#include < ogr_srs_api.h>
38
40
#include < cpl_error.h>
@@ -388,14 +390,27 @@ QgsOgrDataCollectionItem::QgsOgrDataCollectionItem( QgsDataItem *parent, const Q
388
390
QVector<QgsDataItem *> QgsOgrDataCollectionItem::createChildren ()
389
391
{
390
392
QVector<QgsDataItem *> children;
393
+ QStringList skippedLayerNames;
394
+
395
+ char **papszOptions = nullptr ;
396
+ papszOptions = CSLSetNameValue ( papszOptions, " @LIST_ALL_TABLES" , " YES" );
397
+ gdal::dataset_unique_ptr hDataSource ( GDALOpenEx ( mPath .toUtf8 ().constData (), GDAL_OF_VECTOR, nullptr , papszOptions, nullptr ) );
398
+ CSLDestroy ( papszOptions );
399
+
400
+ GDALDriverH hDriver = GDALGetDatasetDriver ( hDataSource.get () );
401
+ QString driverName = QString::fromUtf8 ( GDALGetDriverShortName ( hDriver ) );
402
+ if ( driverName == QStringLiteral ( " SQLite" ) )
403
+ {
404
+ skippedLayerNames = QgsSqliteUtils::systemTables ();
405
+ }
391
406
392
- gdal::dataset_unique_ptr hDataSource ( GDALOpenEx ( mPath .toUtf8 ().constData (), GDAL_OF_VECTOR, nullptr , nullptr , nullptr ) );
393
407
if ( !hDataSource )
394
408
return children;
395
409
int numLayers = GDALDatasetGetLayerCount ( hDataSource.get () );
396
410
397
411
// Check if layer names are unique, so we can use |layername= in URI
398
412
QMap< QString, int > mapLayerNameToCount;
413
+ QList< int > skippedLayers;
399
414
bool uniqueNames = true ;
400
415
for ( int i = 0 ; i < numLayers; ++i )
401
416
{
@@ -408,13 +423,21 @@ QVector<QgsDataItem *> QgsOgrDataCollectionItem::createChildren()
408
423
uniqueNames = false ;
409
424
break ;
410
425
}
426
+ if ( ( driverName == QStringLiteral ( " SQLite" ) && layerName.contains ( QRegularExpression ( QStringLiteral ( " idx_.*_geometry($|_.*)" ) ) ) )
427
+ || skippedLayerNames.contains ( layerName ) )
428
+ {
429
+ skippedLayers << i;
430
+ }
411
431
}
412
432
413
433
children.reserve ( numLayers );
414
434
for ( int i = 0 ; i < numLayers; ++i )
415
435
{
416
- QgsOgrLayerItem *item = dataItemForLayer ( this , QString (), mPath , hDataSource.get (), i, true , uniqueNames );
417
- children.append ( item );
436
+ if ( !skippedLayers.contains ( i ) )
437
+ {
438
+ QgsOgrLayerItem *item = dataItemForLayer ( this , QString (), mPath , hDataSource.get (), i, true , uniqueNames );
439
+ children.append ( item );
440
+ }
418
441
}
419
442
420
443
return children;
0 commit comments