Skip to content
Permalink
Browse files

[browser] List non-spatial layers for mixed spatial/non-spatial sqlit…

…e files
  • Loading branch information
nirvn committed Feb 26, 2019
1 parent 5cb673a commit 0df39bd0919a88928f188d6fb83b0f4601215e99
Showing with 26 additions and 3 deletions.
  1. +26 −3 src/providers/ogr/qgsogrdataitems.cpp
@@ -25,6 +25,7 @@
#include "qgsgeopackagedataitems.h"
#include "qgsogrutils.h"
#include "qgsproviderregistry.h"
#include "qgssqliteutils.h"
#include "symbology/qgsstyle.h"

#include <QFileInfo>
@@ -33,6 +34,7 @@
#include <QMessageBox>
#include <QInputDialog>
#include <QFileDialog>
#include <QRegularExpression>

#include <ogr_srs_api.h>
#include <cpl_error.h>
@@ -388,14 +390,27 @@ QgsOgrDataCollectionItem::QgsOgrDataCollectionItem( QgsDataItem *parent, const Q
QVector<QgsDataItem *> QgsOgrDataCollectionItem::createChildren()
{
QVector<QgsDataItem *> children;
QStringList skippedLayerNames;

char **papszOptions = nullptr;
papszOptions = CSLSetNameValue( papszOptions, "@LIST_ALL_TABLES", "YES" );
gdal::dataset_unique_ptr hDataSource( GDALOpenEx( mPath.toUtf8().constData(), GDAL_OF_VECTOR, nullptr, papszOptions, nullptr ) );
CSLDestroy( papszOptions );

GDALDriverH hDriver = GDALGetDatasetDriver( hDataSource.get() );
QString driverName = QString::fromUtf8( GDALGetDriverShortName( hDriver ) );
if ( driverName == QStringLiteral( "SQLite" ) )
{
skippedLayerNames = QgsSqliteUtils::systemTables();
}

gdal::dataset_unique_ptr hDataSource( GDALOpenEx( mPath.toUtf8().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr ) );
if ( !hDataSource )
return children;
int numLayers = GDALDatasetGetLayerCount( hDataSource.get() );

// Check if layer names are unique, so we can use |layername= in URI
QMap< QString, int > mapLayerNameToCount;
QList< int > skippedLayers;
bool uniqueNames = true;
for ( int i = 0; i < numLayers; ++i )
{
@@ -408,13 +423,21 @@ QVector<QgsDataItem *> QgsOgrDataCollectionItem::createChildren()
uniqueNames = false;
break;
}
if ( ( driverName == QStringLiteral( "SQLite" ) && layerName.contains( QRegularExpression( QStringLiteral( "idx_.*_geometry($|_.*)" ) ) ) )
|| skippedLayerNames.contains( layerName ) )
{
skippedLayers << i;
}
}

children.reserve( numLayers );
for ( int i = 0; i < numLayers; ++i )
{
QgsOgrLayerItem *item = dataItemForLayer( this, QString(), mPath, hDataSource.get(), i, true, uniqueNames );
children.append( item );
if ( !skippedLayers.contains( i ) )
{
QgsOgrLayerItem *item = dataItemForLayer( this, QString(), mPath, hDataSource.get(), i, true, uniqueNames );
children.append( item );
}
}

return children;

0 comments on commit 0df39bd

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