Skip to content

Commit 9768b13

Browse files
committed
[FEATURE] postgres provider: optionally skip columns without geometry type constraint
1 parent 1c2b025 commit 9768b13

6 files changed

+43
-5
lines changed

src/providers/postgres/qgspgnewconnection.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ QgsPgNewConnection::QgsPgNewConnection( QWidget *parent, const QString& connName
5252
txtDatabase->setText( settings.value( key + "/database" ).toString() );
5353
cb_publicSchemaOnly->setChecked( settings.value( key + "/publicOnly", false ).toBool() );
5454
cb_geometryColumnsOnly->setChecked( settings.value( key + "/geometryColumnsOnly", true ).toBool() );
55+
cb_dontResolveType->setChecked( settings.value( key + "/dontResolveType", false ).toBool() );
5556
cb_allowGeometrylessTables->setChecked( settings.value( key + "/allowGeometrylessTables", false ).toBool() );
5657
// Ensure that cb_publicSchemaOnly is set correctly
5758
on_cb_geometryColumnsOnly_clicked();
@@ -131,6 +132,7 @@ void QgsPgNewConnection::accept()
131132
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : "" );
132133
settings.setValue( baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked() );
133134
settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() );
135+
settings.setValue( baseKey + "/dontResolveType", cb_dontResolveType->isChecked() );
134136
settings.setValue( baseKey + "/allowGeometrylessTables", cb_allowGeometrylessTables->isChecked() );
135137
settings.setValue( baseKey + "/sslmode", cbxSSLmode->itemData( cbxSSLmode->currentIndex() ).toInt() );
136138
settings.setValue( baseKey + "/saveUsername", chkStoreUsername->isChecked() ? "true" : "false" );

src/providers/postgres/qgspgsourceselect.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ void QgsPgSourceSelect::on_btnConnect_clicked()
444444

445445
bool searchPublicOnly = QgsPostgresConn::publicSchemaOnly( cmbConnections->currentText() );
446446
bool searchGeometryColumnsOnly = QgsPostgresConn::geometryColumnsOnly( cmbConnections->currentText() );
447+
bool dontResolveType = QgsPostgresConn::dontResolveType( cmbConnections->currentText() );
447448
bool allowGeometrylessTables = cbxAllowGeometrylessTables->isChecked();
448449

449450
QVector<QgsPostgresLayerProperty> layers;
@@ -458,6 +459,12 @@ void QgsPgSourceSelect::on_btnConnect_clicked()
458459
{
459460
if ( QgsPostgresConn::wkbTypeFromPostgis( type ) == QGis::WKBUnknown || srid.isEmpty() )
460461
{
462+
if ( dontResolveType )
463+
{
464+
QgsDebugMsg( QString( "skipping column %1.%2 without type constraint" ).arg( layer.schemaName ).arg( layer.tableName ) );
465+
continue;
466+
}
467+
461468
addSearchGeometryColumn( layer );
462469
type = "";
463470
srid = "";

src/providers/postgres/qgspostgresconn.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,13 @@ bool QgsPostgresConn::geometryColumnsOnly( QString theConnName )
14841484
return settings.value( "/PostgreSQL/connections/" + theConnName + "/geometryColumnsOnly", false ).toBool();
14851485
}
14861486

1487+
bool QgsPostgresConn::dontResolveType( QString theConnName )
1488+
{
1489+
QSettings settings;
1490+
1491+
return settings.value( "/PostgreSQL/connections/" + theConnName + "/dontResolveType", false ).toBool();
1492+
}
1493+
14871494
bool QgsPostgresConn::allowGeometrylessTables( QString theConnName )
14881495
{
14891496
QSettings settings;

src/providers/postgres/qgspostgresconn.h

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class QgsPostgresConn : public QObject
195195
static QgsDataSourceURI connUri( QString theConnName );
196196
static bool publicSchemaOnly( QString theConnName );
197197
static bool geometryColumnsOnly( QString theConnName );
198+
static bool dontResolveType( QString theConnName );
198199
static bool allowGeometrylessTables( QString theConnName );
199200
static void deleteConnection( QString theConnName );
200201

src/providers/postgres/qgspostgresdataitems.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ QVector<QgsDataItem*> QgsPGConnectionItem::createChildren()
100100

101101
stop();
102102

103+
bool dontResolveType = QgsPostgresConn::dontResolveType( mName );
104+
103105
foreach ( QgsPostgresLayerProperty layerProperty, layerProperties )
104106
{
105107
QgsPGSchemaItem *schemaItem = mSchemaMap.value( layerProperty.schemaName, 0 );
@@ -112,6 +114,12 @@ QVector<QgsDataItem*> QgsPGConnectionItem::createChildren()
112114

113115
if ( QgsPostgresConn::wkbTypeFromPostgis( layerProperty.type ) == QGis::WKBUnknown )
114116
{
117+
if ( !dontResolveType )
118+
{
119+
QgsDebugMsg( QString( "Skip column %1.%2 without type constraint" ).arg( layerProperty.schemaName ).arg( layerProperty.tableName ).arg( layerProperty.geometryColName ) );
120+
continue;
121+
}
122+
115123
if ( !mColumnTypeThread )
116124
{
117125
QgsPostgresConn *conn = QgsPostgresConn::connectDb( uri.connectionInfo(), true /* readonly */ );

src/ui/qgspgnewconnectionbase.ui

+18-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>352</width>
10-
<height>500</height>
9+
<width>408</width>
10+
<height>556</height>
1111
</rect>
1212
</property>
1313
<property name="sizePolicy">
@@ -203,7 +203,7 @@
203203
</property>
204204
</widget>
205205
</item>
206-
<item row="3" column="0">
206+
<item row="4" column="0">
207207
<widget class="QCheckBox" name="cb_publicSchemaOnly">
208208
<property name="toolTip">
209209
<string>Restrict the search to the public schema for spatial tables not in the geometry_columns table</string>
@@ -244,7 +244,7 @@
244244
</item>
245245
</layout>
246246
</item>
247-
<item row="5" column="0">
247+
<item row="6" column="0">
248248
<widget class="QCheckBox" name="cb_useEstimatedMetadata">
249249
<property name="toolTip">
250250
<string>Use estimated table statistics for the layer metadata.</string>
@@ -265,7 +265,7 @@
265265
</property>
266266
</widget>
267267
</item>
268-
<item row="4" column="0">
268+
<item row="5" column="0">
269269
<widget class="QCheckBox" name="cb_allowGeometrylessTables">
270270
<property name="text">
271271
<string>Also list tables with no geometry</string>
@@ -275,6 +275,19 @@
275275
</property>
276276
</widget>
277277
</item>
278+
<item row="3" column="0">
279+
<widget class="QCheckBox" name="cb_dontResolveType">
280+
<property name="toolTip">
281+
<string>Restrict the displayed tables to those that are in the layer registries.</string>
282+
</property>
283+
<property name="whatsThis">
284+
<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>
285+
</property>
286+
<property name="text">
287+
<string>Don't resolve type of unrestricted columns (GEOMETRY)</string>
288+
</property>
289+
</widget>
290+
</item>
278291
</layout>
279292
</widget>
280293
</item>

0 commit comments

Comments
 (0)