Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgreprovider hide raster overviews #59884

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/providers/postgres/qgspgnewconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ QgsPgNewConnection::QgsPgNewConnection( QWidget *parent, const QString &connName
cb_geometryColumnsOnly->setChecked( settings.value( key + "/geometryColumnsOnly", true ).toBool() );
cb_dontResolveType->setChecked( settings.value( key + "/dontResolveType", false ).toBool() );
cb_allowGeometrylessTables->setChecked( settings.value( key + "/allowGeometrylessTables", false ).toBool() );
cb_showRasterOverviews->setChecked( settings.value( key + "/showRasterOverviews", true ).toBool() );
// Ensure that cb_publicSchemaOnly is set correctly
cb_geometryColumnsOnly_clicked();

Expand Down Expand Up @@ -177,6 +178,7 @@ void QgsPgNewConnection::accept()
configuration.insert( "projectsInDatabase", cb_projectsInDatabase->isChecked() );
configuration.insert( "metadataInDatabase", cb_metadataInDatabase->isChecked() );
configuration.insert( "session_role", txtSessionRole->text() );
configuration.insert( "showRasterOverviews", cb_showRasterOverviews->isChecked() );

QgsProviderMetadata *providerMetadata = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "postgres" ) );
std::unique_ptr<QgsPostgresProviderConnection> providerConnection( qgis::down_cast<QgsPostgresProviderConnection *>( providerMetadata->createConnection( txtName->text() ) ) );
Expand Down
67 changes: 61 additions & 6 deletions src/providers/postgres/qgspostgresconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ void QgsPostgresConn::addColumnInfo( QgsPostgresLayerProperty &layerProperty, co
}
}

bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchPublicOnly, bool allowGeometrylessTables, const QString &schema, const QString &name )
bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchPublicOnly, bool allowGeometrylessTables, bool showRasterOverviews, const QString &schema, const QString &name )
{
QMutexLocker locker( &mLock );
int nColumns = 0;
Expand Down Expand Up @@ -1054,6 +1054,53 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
}
}

// remove raster overivews if showRasterOverviews is FALSE
if ( !showRasterOverviews )
{
QString sqlRasterOverviews = QString( "SELECT o_table_schema, o_table_name FROM public.raster_overviews" );

QgsPostgresResult resultRasterOverviews;
resultRasterOverviews = LoggedPQexec( "QgsPostgresConn", sqlRasterOverviews );

if ( resultRasterOverviews.result() )
{
QVector<QgsPostgresRasterOverviewLayerProperty> overviews;
for ( int idx = 0; idx < resultRasterOverviews.PQntuples(); idx++ )
{
QgsPostgresRasterOverviewLayerProperty rasterOverviewProperty;
rasterOverviewProperty.schemaName = resultRasterOverviews.PQgetvalue( idx, 0 );
rasterOverviewProperty.tableName = resultRasterOverviews.PQgetvalue( idx, 1 );
overviews.append( rasterOverviewProperty );
}

QVector<QgsPostgresLayerProperty> layersToKeep;
for ( int i = 0; i < mLayersSupported.count(); i++ )
{
QgsPostgresLayerProperty property = mLayersSupported.at( i );

if ( !property.isRaster )
{
layersToKeep.append( property );
}
else
{
bool keepRasterTable = true;
for ( QgsPostgresRasterOverviewLayerProperty overview : overviews )
{
if ( property.schemaName == overview.schemaName && property.tableName == overview.tableName )
{
keepRasterTable = false;
}
}

if ( keepRasterTable )
layersToKeep.append( property );
}
}
mLayersSupported = layersToKeep;
}
}

if ( nColumns == 0 && schema.isEmpty() )
{
QgsMessageLog::logMessage( tr( "Database connection was successful, but the accessible tables could not be determined." ), tr( "PostGIS" ) );
Expand All @@ -1062,14 +1109,14 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
return true;
}

bool QgsPostgresConn::supportedLayersPrivate( QVector<QgsPostgresLayerProperty> &layers, bool searchGeometryColumnsOnly, bool searchPublicOnly, bool allowGeometrylessTables, const QString &schema, const QString &table )
bool QgsPostgresConn::supportedLayersPrivate( QVector<QgsPostgresLayerProperty> &layers, bool searchGeometryColumnsOnly, bool searchPublicOnly, bool allowGeometrylessTables, bool showRasterOverviews, const QString &schema, const QString &table )
{
QMutexLocker locker( &mLock );

mLayersSupported.clear();

// Get the list of supported tables
if ( !getTableInfo( searchGeometryColumnsOnly, searchPublicOnly, allowGeometrylessTables, schema, table ) )
if ( !getTableInfo( searchGeometryColumnsOnly, searchPublicOnly, allowGeometrylessTables, showRasterOverviews, schema, table ) )
{
QgsMessageLog::logMessage( tr( "Unable to get list of spatially enabled tables from the database" ), tr( "PostGIS" ) );
return false;
Expand Down Expand Up @@ -1458,15 +1505,15 @@ Qgis::PostgresRelKind QgsPostgresConn::relKindFromValue( const QString &value )
return Qgis::PostgresRelKind::Unknown;
}

bool QgsPostgresConn::supportedLayers( QVector<QgsPostgresLayerProperty> &layers, bool searchGeometryColumnsOnly, bool searchPublicOnly, bool allowGeometrylessTables, const QString &schema )
bool QgsPostgresConn::supportedLayers( QVector<QgsPostgresLayerProperty> &layers, bool searchGeometryColumnsOnly, bool searchPublicOnly, bool allowGeometrylessTables, bool showRasterOverviews, const QString &schema )
{
return supportedLayersPrivate( layers, searchGeometryColumnsOnly, searchPublicOnly, allowGeometrylessTables, schema );
return supportedLayersPrivate( layers, searchGeometryColumnsOnly, searchPublicOnly, allowGeometrylessTables, showRasterOverviews, schema );
}

bool QgsPostgresConn::supportedLayer( QgsPostgresLayerProperty &layerProperty, const QString &schema, const QString &table )
{
QVector<QgsPostgresLayerProperty> layers;
if ( !supportedLayersPrivate( layers, false, false, true /* allowGeometrylessTables */, schema, table ) || layers.empty() )
if ( !supportedLayersPrivate( layers, false, false, true /* allowGeometrylessTables */, false, schema, table ) || layers.empty() )
{
return false;
}
Expand Down Expand Up @@ -2731,6 +2778,12 @@ bool QgsPostgresConn::allowProjectsInDatabase( const QString &connName )
return settings.value( "/PostgreSQL/connections/" + connName + "/projectsInDatabase", false ).toBool();
}

bool QgsPostgresConn::showRasterOverviewTables( const QString &connName )
{
QgsSettings settings;
return settings.value( "/PostgreSQL/connections/" + connName + "/showRasterOverviews", true ).toBool();
}

void QgsPostgresConn::deleteConnection( const QString &connName )
{
QgsSettings settings;
Expand All @@ -2755,6 +2808,7 @@ void QgsPostgresConn::deleteConnection( const QString &connName )
settings.remove( key + "/metadataInDatabase" );
settings.remove( key + "/dontResolveType" );
settings.remove( key + "/session_role" );
settings.remove( key + "/showRasterOverviews" );
settings.remove( key );
}

Expand Down Expand Up @@ -2782,6 +2836,7 @@ void QgsPostgresConn::duplicateConnection( const QString &src, const QString &ds
settings.setValue( newKey + QStringLiteral( "/saveUsername" ), settings.value( key + QStringLiteral( "/saveUsername" ) ).toString() );
settings.setValue( newKey + QStringLiteral( "/savePassword" ), settings.value( key + QStringLiteral( "/savePassword" ) ).toString() );
settings.setValue( newKey + QStringLiteral( "/authcfg" ), settings.value( key + QStringLiteral( "/authcfg" ) ).toString() );
settings.setValue( newKey + QStringLiteral( "/showRasterOverviews" ), settings.value( key + QStringLiteral( "/showRasterOverviews" ) ).toString() );

settings.sync();
}
Expand Down
16 changes: 13 additions & 3 deletions src/providers/postgres/qgspostgresconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ struct QgsPostgresSchemaProperty
QString owner;
};

//! Raster overview table properties structure
struct QgsPostgresRasterOverviewLayerProperty
{
QString schemaName;
QString tableName;
};

//! Layer Property structure
// TODO: Fill to Postgres/PostGIS specifications
Expand Down Expand Up @@ -382,10 +388,11 @@ class QgsPostgresConn : public QObject
* contained in the geometry_columns metatable
* \param searchPublicOnly
* \param allowGeometrylessTables
* \param showRasterOverviews list raster layer overviews
* \param schema restrict layers to layers within specified schema
* \returns true if layers were fetched successfully
*/
bool supportedLayers( QVector<QgsPostgresLayerProperty> &layers, bool searchGeometryColumnsOnly = true, bool searchPublicOnly = true, bool allowGeometrylessTables = false, const QString &schema = QString() );
bool supportedLayers( QVector<QgsPostgresLayerProperty> &layers, bool searchGeometryColumnsOnly = true, bool searchPublicOnly = true, bool allowGeometrylessTables = false, bool showRasterOverviews = false, const QString &schema = QString() );

/**
* Get the information about a supported layer
Expand Down Expand Up @@ -418,11 +425,12 @@ class QgsPostgresConn : public QObject
* contained in the geometry_columns metatable
* \param searchPublicOnly
* \param allowGeometrylessTables
* \param showRasterOverviews list raster layer overviews
* \param schema restrict tables to those within specified schema
* \param name restrict tables to those with specified name
* \returns true if tables were successfully queried
*/
bool getTableInfo( bool searchGeometryColumnsOnly, bool searchPublicOnly, bool allowGeometrylessTables, const QString &schema = QString(), const QString &name = QString() );
bool getTableInfo( bool searchGeometryColumnsOnly, bool searchPublicOnly, bool allowGeometrylessTables, bool showRasterOverviews = false, const QString &schema = QString(), const QString &name = QString() );

qint64 getBinaryInt( QgsPostgresResult &queryResult, int row, int col );

Expand Down Expand Up @@ -471,6 +479,7 @@ class QgsPostgresConn : public QObject
static bool allowProjectsInDatabase( const QString &connName );
static void deleteConnection( const QString &connName );
static bool allowMetadataInDatabase( const QString &connName );
static bool showRasterOverviewTables( const QString &connName );

/**
* Duplicates \a src connection settings to a new \a dst connection.
Expand Down Expand Up @@ -543,11 +552,12 @@ class QgsPostgresConn : public QObject
* contained in the geometry_columns metatable
* \param searchPublicOnly
* \param allowGeometrylessTables
* \param showRasterOverviews list raster layer overviews
* \param schema restrict layers to layers within specified schema
* \param table restrict tables to those with specified table
* \returns true if layers were fetched successfully
*/
bool supportedLayersPrivate( QVector<QgsPostgresLayerProperty> &layers, bool searchGeometryColumnsOnly = true, bool searchPublicOnly = true, bool allowGeometrylessTables = false, const QString &schema = QString(), const QString &table = QString() );
bool supportedLayersPrivate( QVector<QgsPostgresLayerProperty> &layers, bool searchGeometryColumnsOnly = true, bool searchPublicOnly = true, bool allowGeometrylessTables = false, bool showRasterOverviews = false, const QString &schema = QString(), const QString &table = QString() );

//! List of the supported layers
QVector<QgsPostgresLayerProperty> mLayersSupported;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/postgres/qgspostgresdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ QVector<QgsDataItem *> QgsPGSchemaItem::createChildren()
}

QVector<QgsPostgresLayerProperty> layerProperties;
const bool ok = conn->supportedLayers( layerProperties, QgsPostgresConn::geometryColumnsOnly( mConnectionName ), QgsPostgresConn::publicSchemaOnly( mConnectionName ), QgsPostgresConn::allowGeometrylessTables( mConnectionName ), mName );
const bool ok = conn->supportedLayers( layerProperties, QgsPostgresConn::geometryColumnsOnly( mConnectionName ), QgsPostgresConn::publicSchemaOnly( mConnectionName ), QgsPostgresConn::allowGeometrylessTables( mConnectionName ), QgsPostgresConn::showRasterOverviewTables( mConnectionName ), mName );

if ( !ok )
{
Expand Down
3 changes: 2 additions & 1 deletion src/providers/postgres/qgspostgresproviderconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const QStringList QgsPostgresProviderConnection::CONFIGURATION_PARAMETERS = {
QStringLiteral( "projectsInDatabase" ),
QStringLiteral( "metadataInDatabase" ),
QStringLiteral( "session_role" ),
QStringLiteral( "showRasterOverviews" ),
};

const QString QgsPostgresProviderConnection::SETTINGS_BASE_KEY = QStringLiteral( "/PostgreSQL/connections/" );
Expand Down Expand Up @@ -239,7 +240,7 @@ QList<QgsAbstractDatabaseProviderConnection::TableProperty> QgsPostgresProviderC
}
else
{
ok = conn->supportedLayers( properties, false, schema == QStringLiteral( "public" ), aspatial, schema );
ok = conn->supportedLayers( properties, false, schema == QStringLiteral( "public" ), aspatial, false, schema );
}

if ( !ok )
Expand Down
9 changes: 8 additions & 1 deletion src/ui/qgspgnewconnectionbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>448</width>
<height>510</height>
<height>573</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -236,6 +236,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_showRasterOverviews">
<property name="text">
<string>List raster overview tables</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down
Loading