[FEATURE] postgres provider: optionally skip columns without geometry type constraint

This commit is contained in:
Juergen E. Fischer 2013-02-19 18:21:29 +01:00
parent 1c2b025a69
commit 9768b13c76
6 changed files with 43 additions and 5 deletions

View File

@ -52,6 +52,7 @@ QgsPgNewConnection::QgsPgNewConnection( QWidget *parent, const QString& connName
txtDatabase->setText( settings.value( key + "/database" ).toString() ); txtDatabase->setText( settings.value( key + "/database" ).toString() );
cb_publicSchemaOnly->setChecked( settings.value( key + "/publicOnly", false ).toBool() ); cb_publicSchemaOnly->setChecked( settings.value( key + "/publicOnly", false ).toBool() );
cb_geometryColumnsOnly->setChecked( settings.value( key + "/geometryColumnsOnly", true ).toBool() ); 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_allowGeometrylessTables->setChecked( settings.value( key + "/allowGeometrylessTables", false ).toBool() );
// Ensure that cb_publicSchemaOnly is set correctly // Ensure that cb_publicSchemaOnly is set correctly
on_cb_geometryColumnsOnly_clicked(); on_cb_geometryColumnsOnly_clicked();
@ -131,6 +132,7 @@ void QgsPgNewConnection::accept()
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : "" ); settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : "" );
settings.setValue( baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked() ); settings.setValue( baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked() );
settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() ); settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() );
settings.setValue( baseKey + "/dontResolveType", cb_dontResolveType->isChecked() );
settings.setValue( baseKey + "/allowGeometrylessTables", cb_allowGeometrylessTables->isChecked() ); settings.setValue( baseKey + "/allowGeometrylessTables", cb_allowGeometrylessTables->isChecked() );
settings.setValue( baseKey + "/sslmode", cbxSSLmode->itemData( cbxSSLmode->currentIndex() ).toInt() ); settings.setValue( baseKey + "/sslmode", cbxSSLmode->itemData( cbxSSLmode->currentIndex() ).toInt() );
settings.setValue( baseKey + "/saveUsername", chkStoreUsername->isChecked() ? "true" : "false" ); settings.setValue( baseKey + "/saveUsername", chkStoreUsername->isChecked() ? "true" : "false" );

View File

@ -444,6 +444,7 @@ void QgsPgSourceSelect::on_btnConnect_clicked()
bool searchPublicOnly = QgsPostgresConn::publicSchemaOnly( cmbConnections->currentText() ); bool searchPublicOnly = QgsPostgresConn::publicSchemaOnly( cmbConnections->currentText() );
bool searchGeometryColumnsOnly = QgsPostgresConn::geometryColumnsOnly( cmbConnections->currentText() ); bool searchGeometryColumnsOnly = QgsPostgresConn::geometryColumnsOnly( cmbConnections->currentText() );
bool dontResolveType = QgsPostgresConn::dontResolveType( cmbConnections->currentText() );
bool allowGeometrylessTables = cbxAllowGeometrylessTables->isChecked(); bool allowGeometrylessTables = cbxAllowGeometrylessTables->isChecked();
QVector<QgsPostgresLayerProperty> layers; QVector<QgsPostgresLayerProperty> layers;
@ -458,6 +459,12 @@ void QgsPgSourceSelect::on_btnConnect_clicked()
{ {
if ( QgsPostgresConn::wkbTypeFromPostgis( type ) == QGis::WKBUnknown || srid.isEmpty() ) if ( QgsPostgresConn::wkbTypeFromPostgis( type ) == QGis::WKBUnknown || srid.isEmpty() )
{ {
if ( dontResolveType )
{
QgsDebugMsg( QString( "skipping column %1.%2 without type constraint" ).arg( layer.schemaName ).arg( layer.tableName ) );
continue;
}
addSearchGeometryColumn( layer ); addSearchGeometryColumn( layer );
type = ""; type = "";
srid = ""; srid = "";

View File

@ -1484,6 +1484,13 @@ bool QgsPostgresConn::geometryColumnsOnly( QString theConnName )
return settings.value( "/PostgreSQL/connections/" + theConnName + "/geometryColumnsOnly", false ).toBool(); return settings.value( "/PostgreSQL/connections/" + theConnName + "/geometryColumnsOnly", false ).toBool();
} }
bool QgsPostgresConn::dontResolveType( QString theConnName )
{
QSettings settings;
return settings.value( "/PostgreSQL/connections/" + theConnName + "/dontResolveType", false ).toBool();
}
bool QgsPostgresConn::allowGeometrylessTables( QString theConnName ) bool QgsPostgresConn::allowGeometrylessTables( QString theConnName )
{ {
QSettings settings; QSettings settings;

View File

@ -195,6 +195,7 @@ class QgsPostgresConn : public QObject
static QgsDataSourceURI connUri( QString theConnName ); static QgsDataSourceURI connUri( QString theConnName );
static bool publicSchemaOnly( QString theConnName ); static bool publicSchemaOnly( QString theConnName );
static bool geometryColumnsOnly( QString theConnName ); static bool geometryColumnsOnly( QString theConnName );
static bool dontResolveType( QString theConnName );
static bool allowGeometrylessTables( QString theConnName ); static bool allowGeometrylessTables( QString theConnName );
static void deleteConnection( QString theConnName ); static void deleteConnection( QString theConnName );

View File

@ -100,6 +100,8 @@ QVector<QgsDataItem*> QgsPGConnectionItem::createChildren()
stop(); stop();
bool dontResolveType = QgsPostgresConn::dontResolveType( mName );
foreach ( QgsPostgresLayerProperty layerProperty, layerProperties ) foreach ( QgsPostgresLayerProperty layerProperty, layerProperties )
{ {
QgsPGSchemaItem *schemaItem = mSchemaMap.value( layerProperty.schemaName, 0 ); QgsPGSchemaItem *schemaItem = mSchemaMap.value( layerProperty.schemaName, 0 );
@ -112,6 +114,12 @@ QVector<QgsDataItem*> QgsPGConnectionItem::createChildren()
if ( QgsPostgresConn::wkbTypeFromPostgis( layerProperty.type ) == QGis::WKBUnknown ) if ( QgsPostgresConn::wkbTypeFromPostgis( layerProperty.type ) == QGis::WKBUnknown )
{ {
if ( !dontResolveType )
{
QgsDebugMsg( QString( "Skip column %1.%2 without type constraint" ).arg( layerProperty.schemaName ).arg( layerProperty.tableName ).arg( layerProperty.geometryColName ) );
continue;
}
if ( !mColumnTypeThread ) if ( !mColumnTypeThread )
{ {
QgsPostgresConn *conn = QgsPostgresConn::connectDb( uri.connectionInfo(), true /* readonly */ ); QgsPostgresConn *conn = QgsPostgresConn::connectDb( uri.connectionInfo(), true /* readonly */ );

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>352</width> <width>408</width>
<height>500</height> <height>556</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -203,7 +203,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="4" column="0">
<widget class="QCheckBox" name="cb_publicSchemaOnly"> <widget class="QCheckBox" name="cb_publicSchemaOnly">
<property name="toolTip"> <property name="toolTip">
<string>Restrict the search to the public schema for spatial tables not in the geometry_columns table</string> <string>Restrict the search to the public schema for spatial tables not in the geometry_columns table</string>
@ -244,7 +244,7 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="5" column="0"> <item row="6" column="0">
<widget class="QCheckBox" name="cb_useEstimatedMetadata"> <widget class="QCheckBox" name="cb_useEstimatedMetadata">
<property name="toolTip"> <property name="toolTip">
<string>Use estimated table statistics for the layer metadata.</string> <string>Use estimated table statistics for the layer metadata.</string>
@ -265,7 +265,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="5" column="0">
<widget class="QCheckBox" name="cb_allowGeometrylessTables"> <widget class="QCheckBox" name="cb_allowGeometrylessTables">
<property name="text"> <property name="text">
<string>Also list tables with no geometry</string> <string>Also list tables with no geometry</string>
@ -275,6 +275,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0">
<widget class="QCheckBox" name="cb_dontResolveType">
<property name="toolTip">
<string>Restrict the displayed tables to those that are in the layer registries.</string>
</property>
<property name="whatsThis">
<string>Restricts the displayed tables to those that are found in the layer registries (geometry_columns, geography_columns, topology.layer). This can speed up the initial display of spatial tables.</string>
</property>
<property name="text">
<string>Don't resolve type of unrestricted columns (GEOMETRY)</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>