Skip to content

Commit 0f26537

Browse files
authored
[spatialite provider] implement to do: show geometryless layers in browser (#5850)
This is in essence a "fix" to the QgsSpatialiteConnection's table fetching which used to return system tables.
1 parent d901221 commit 0f26537

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/providers/spatialite/qgsspatialiteconnection.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,23 @@ bool QgsSpatiaLiteConnection::getTableInfoAbstractInterface( sqlite3 *handle, bo
238238
return false;
239239
}
240240

241-
// attempting to load the VectorLayersList
241+
// List of system tables not to be shown if geometryless tables are requested
242+
QStringList ignoreTableNames;
243+
ignoreTableNames << QStringLiteral( "SpatialIndex" ) << QStringLiteral( "geom_cols_ref_sys" ) << QStringLiteral( "geometry_columns" )
244+
<< QStringLiteral( "geometry_columns_auth" ) << QStringLiteral( "views_geometry_columns" ) << QStringLiteral( "virts_geometry_columns" )
245+
<< QStringLiteral( "spatial_ref_sys" ) << QStringLiteral( "spatial_ref_sys_all" ) << QStringLiteral( "spatial_ref_sys_aux" )
246+
<< QStringLiteral( "sqlite_sequence" ) << QStringLiteral( "tableprefix_metadata" ) << QStringLiteral( "tableprefix_rasters" )
247+
<< QStringLiteral( "layer_params" ) << QStringLiteral( "layer_statistics" ) << QStringLiteral( "layer_sub_classes" )
248+
<< QStringLiteral( "layer_table_layout" ) << QStringLiteral( "pattern_bitmaps" ) << QStringLiteral( "symbol_bitmaps" )
249+
<< QStringLiteral( "project_defs" ) << QStringLiteral( "raster_pyramids" ) << QStringLiteral( "sqlite_stat1" ) << QStringLiteral( "sqlite_stat2" )
250+
<< QStringLiteral( "spatialite_history" ) << QStringLiteral( "geometry_columns_field_infos" ) << QStringLiteral( "geometry_columns_statistics" )
251+
<< QStringLiteral( "geometry_columns_time" ) << QStringLiteral( "sql_statements_log" ) << QStringLiteral( "vector_layers" )
252+
<< QStringLiteral( "vector_layers_auth" ) << QStringLiteral( "vector_layers_field_infos" ) << QStringLiteral( "vector_layers_statistics" )
253+
<< QStringLiteral( "views_geometry_columns_auth" ) << QStringLiteral( "views_geometry_columns_field_infos" )
254+
<< QStringLiteral( "views_geometry_columns_statistics" ) << QStringLiteral( "virts_geometry_columns_auth" )
255+
<< QStringLiteral( "virts_geometry_columns_field_infos" ) << QStringLiteral( "virts_geometry_columns_statistics" )
256+
<< QStringLiteral( "ElementaryGeometries" );
257+
// attempting to load the VectorLayersList
242258
list = gaiaGetVectorLayersList( handle, nullptr, nullptr, GAIA_VECTORS_LIST_FAST );
243259
if ( list )
244260
{
@@ -257,7 +273,12 @@ bool QgsSpatiaLiteConnection::getTableInfoAbstractInterface( sqlite3 *handle, bo
257273
}
258274

259275
QString tableName = QString::fromUtf8( lyr->TableName );
276+
ignoreTableNames << tableName;
260277
QString column = QString::fromUtf8( lyr->GeometryName );
278+
ignoreTableNames << QStringLiteral( "idx_%1_%2" ).arg( tableName, column )
279+
<< QStringLiteral( "idx_%1_%2_node" ).arg( tableName, column )
280+
<< QStringLiteral( "idx_%1_%2_parent" ).arg( tableName, column )
281+
<< QStringLiteral( "idx_%1_%2_rowid" ).arg( tableName, column );
261282
QString type = tr( "UNKNOWN" );
262283
switch ( lyr->GeometryType )
263284
{
@@ -309,7 +330,8 @@ bool QgsSpatiaLiteConnection::getTableInfoAbstractInterface( sqlite3 *handle, bo
309330
for ( i = 1; i <= rows; i++ )
310331
{
311332
QString tableName = QString::fromUtf8( results[( i * columns ) + 0] );
312-
mTables.append( TableEntry( tableName, QString(), QStringLiteral( "qgis_table" ) ) );
333+
if ( !ignoreTableNames.contains( tableName ) )
334+
mTables.append( TableEntry( tableName, QString(), QStringLiteral( "qgis_table" ) ) );
313335
}
314336
}
315337
sqlite3_free_table( results );

src/providers/spatialite/qgsspatialitedataitems.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ QVector<QgsDataItem *> QgsSLConnectionItem::createChildren()
113113
QVector<QgsDataItem *> children;
114114
QgsSpatiaLiteConnection connection( mName );
115115

116-
QgsSpatiaLiteConnection::Error err = connection.fetchTables( false ); // TODO: allow geometryless tables
116+
QgsSpatiaLiteConnection::Error err = connection.fetchTables( true );
117117
if ( err != QgsSpatiaLiteConnection::NoError )
118118
{
119119
QString msg;

0 commit comments

Comments
 (0)