Skip to content

Commit

Permalink
Merge pull request #5018 from boundlessgeo/gpkg-show-tables
Browse files Browse the repository at this point in the history
Browser tree: also show geopackage geometryless layers as tables
  • Loading branch information
elpaso committed Aug 14, 2017
2 parents b26e681 + 11f1791 commit 904cd6f
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/providers/ogr/qgsgeopackagedataitems.cpp
Expand Up @@ -154,27 +154,28 @@ QVector<QgsDataItem *> QgsGeoPackageConnectionItem::createChildren()
QString geometryType = pieces[3];
QgsLayerItem::LayerType layerType;
layerType = layerTypeFromDb( geometryType );
if ( layerType != QgsLayerItem::LayerType::NoType )
if ( geometryType.contains( QStringLiteral( "Collection" ), Qt::CaseInsensitive ) )
{
if ( geometryType.contains( QStringLiteral( "Collection" ), Qt::CaseInsensitive ) )
QgsDebugMsgLevel( QStringLiteral( "Layer %1 is a geometry collection: skipping %2" ).arg( name, mPath ), 3 );
}
else
{
// example URI: '/path/gdal_sample_v1.2_no_extensions.gpkg|layerid=7|geometrytype=Point'
QString uri;
// We do not need to add a geometry type for table layers
if ( layerType != QgsLayerItem::LayerType::TableLayer )
{
QgsDebugMsgLevel( QStringLiteral( "Layer %1 is a geometry collection: skipping %2" ).arg( name, mPath ), 3 );
uri = QStringLiteral( "%1|layerid=%2|geometrytype=%3" ).arg( mPath, layerId, geometryType );
}
else
{
// example URI: '/path/gdal_sample_v1.2_no_extensions.gpkg|layerid=7|geometrytype=Point'
QString uri = QStringLiteral( "%1|layerid=%2|geometrytype=%3" ).arg( mPath, layerId, geometryType );
// TODO?: not sure, but if it's a collection, an expandable node would be better?
QgsGeoPackageVectorLayerItem *item = new QgsGeoPackageVectorLayerItem( this, name, mPath, uri, layerType );
QgsDebugMsgLevel( QStringLiteral( "Adding GPKG Vector item %1 %2 %3" ).arg( name, uri, geometryType ), 3 );
children.append( item );
uri = QStringLiteral( "%1|layerid=%2" ).arg( mPath, layerId );
}
// TODO?: not sure, but if it's a collection, an expandable node would be better?
QgsGeoPackageVectorLayerItem *item = new QgsGeoPackageVectorLayerItem( this, name, mPath, uri, layerType );
QgsDebugMsgLevel( QStringLiteral( "Adding GPKG Vector item %1 %2 %3" ).arg( name, uri, geometryType ), 3 );
children.append( item );
}
else
{
QgsDebugMsgLevel( QStringLiteral( "Layer type is not a supported GeoPackage Vector layer %1" ).arg( mPath ), 3 );
}

}
}
// Raster layers
Expand Down Expand Up @@ -235,16 +236,12 @@ QgsLayerItem::LayerType QgsGeoPackageConnectionItem::layerTypeFromDb( const QStr
{
return QgsLayerItem::LayerType::Vector;
}
else if ( geometryType.contains( QStringLiteral( "Table" ), Qt::CaseInsensitive ) )
{
return QgsLayerItem::LayerType::Table;
}
// To be moved in a parent class that would also work for gdal and rasters
else if ( geometryType.contains( QStringLiteral( "Raster" ), Qt::CaseInsensitive ) )
{
return QgsLayerItem::LayerType::Raster;
}
return QgsLayerItem::LayerType::NoType;
return QgsLayerItem::LayerType::TableLayer;
}

void QgsGeoPackageConnectionItem::deleteConnection()
Expand Down

0 comments on commit 904cd6f

Please sign in to comment.