Skip to content

Commit 4852ceb

Browse files
author
jef
committed
apply #2460 (slightly modified). Thanks Jeremy Palmer.
git-svn-id: http://svn.osgeo.org/qgis/trunk@13044 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 669d9bd commit 4852ceb

10 files changed

+157
-44
lines changed

python/core/qgsdatasourceuri.sip

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public:
6060
QString table() const;
6161
QString sql() const;
6262
QString geometryColumn() const;
63+
64+
//! set use Estimated Metadata
65+
// added in 1.5
66+
void setUseEstimatedMetadata( bool theFlag );
67+
bool useEstimatedMetadata() const;
6368

6469
// added in 1.1
6570
QString host() const;

src/app/postgres/qgspgnewconnection.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,13 @@ QgsPgNewConnection::QgsPgNewConnection( QWidget *parent, const QString& connName
5656
port = "5432";
5757
}
5858
txtPort->setText( port );
59-
Qt::CheckState s = Qt::Checked;
60-
if ( ! settings.value( key + "/publicOnly", false ).toBool() )
61-
s = Qt::Unchecked;
62-
cb_publicSchemaOnly->setCheckState( s );
63-
s = Qt::Checked;
64-
if ( ! settings.value( key + "/geometrycolumnsOnly", false ).toBool() )
65-
s = Qt::Unchecked;
66-
cb_geometryColumnsOnly->setCheckState( s );
59+
cb_publicSchemaOnly->setChecked( settings.value( key + "/publicOnly", false ).toBool() );
60+
cb_geometryColumnsOnly->setChecked( settings.value( key + "/geometrycolumnsOnly", false ).toBool() );
6761
// Ensure that cb_plublicSchemaOnly is set correctly
6862
on_cb_geometryColumnsOnly_clicked();
6963

64+
cb_useEstimatedMetadata->setChecked( settings.value( key + "/estimatedMetadata", false ).toBool() );
65+
7066
cbxSSLmode->setCurrentIndex( cbxSSLmode->findData( settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() ) );
7167

7268
if ( settings.value( key + "/saveUsername" ).toString() == "true" )
@@ -132,6 +128,7 @@ void QgsPgNewConnection::accept()
132128
settings.setValue( baseKey + "/sslmode", cbxSSLmode->itemData( cbxSSLmode->currentIndex() ).toInt() );
133129
settings.setValue( baseKey + "/saveUsername", chkStoreUsername->isChecked() ? "true" : "false" );
134130
settings.setValue( baseKey + "/savePassword", chkStorePassword->isChecked() ? "true" : "false" );
131+
settings.setValue( baseKey + "/estimatedMetadata", cb_useEstimatedMetadata->isChecked() );
135132

136133
// remove old save setting
137134
settings.remove( baseKey + "/save" );

src/app/postgres/qgspgsourceselect.cpp

+28-6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ email : sherman at mrcc.com
4141
#include <pg_config.h>
4242
#endif
4343

44+
// Note: Because the the geometry type select SQL is also in the qgspostgresprovider
45+
// code this parameter is duplicated there.
46+
static const int sGeomTypeSelectLimit = 100;
47+
4448
QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WFlags fl )
4549
: QDialog( parent, fl ), mColumnTypeThread( NULL ), pd( 0 )
4650
{
@@ -142,6 +146,7 @@ void QgsPgSourceSelect::on_btnDelete_clicked()
142146
settings.remove( key + "/sslmode" );
143147
settings.remove( key + "/publicOnly" );
144148
settings.remove( key + "/geometryColumnsOnly" );
149+
settings.remove( key + "/estimatedMetadata" );
145150
settings.remove( key + "/saveUsername" );
146151
settings.remove( key + "/savePassword" );
147152
settings.remove( key + "/save" );
@@ -352,6 +357,11 @@ QString QgsPgSourceSelect::layerURI( const QModelIndex &index )
352357
uri += QString( " key=\"%1\"" ).arg( pkColumnName );
353358
}
354359

360+
if ( mUseEstimatedMetadata )
361+
{
362+
uri += QString( " estimatedmetadata=true" );
363+
}
364+
355365
uri += QString( " table=\"%1\".\"%2\" (%3) sql=%4" )
356366
.arg( schemaName ).arg( tableName )
357367
.arg( geomColumnName )
@@ -419,7 +429,7 @@ void QgsPgSourceSelect::on_btnConnect_clicked()
419429

420430
bool searchPublicOnly = settings.value( key + "/publicOnly" ).toBool();
421431
bool searchGeometryColumnsOnly = settings.value( key + "/geometryColumnsOnly" ).toBool();
422-
432+
mUseEstimatedMetadata = settings.value( key + "/estimatedMetadata" ).toBool();
423433
// Need to escape the password to allow for single quotes and backslashes
424434

425435
QgsDebugMsg( "Connection info: " + uri.connectionInfo() );
@@ -562,7 +572,7 @@ void QgsPgSourceSelect::addSearchGeometryColumn( const QString &schema, const QS
562572
if ( mColumnTypeThread == NULL )
563573
{
564574
mColumnTypeThread = new QgsGeomColumnTypeThread();
565-
mColumnTypeThread->setConnInfo( m_privConnInfo );
575+
mColumnTypeThread->setConnInfo( m_privConnInfo, mUseEstimatedMetadata );
566576
}
567577
mColumnTypeThread->addGeometryColumn( schema, table, column );
568578
}
@@ -794,9 +804,10 @@ void QgsPgSourceSelect::setSearchExpression( const QString& regexp )
794804
{
795805
}
796806

797-
void QgsGeomColumnTypeThread::setConnInfo( QString s )
807+
void QgsGeomColumnTypeThread::setConnInfo( QString conninfo, bool useEstimatedMetadata )
798808
{
799-
mConnInfo = s;
809+
mConnInfo = conninfo;
810+
mUseEstimatedMetadata = useEstimatedMetadata;
800811
}
801812

802813
void QgsGeomColumnTypeThread::addGeometryColumn( QString schema, QString table, QString column )
@@ -828,8 +839,19 @@ void QgsGeomColumnTypeThread::getLayerTypes()
828839
" when geometrytype(%1) IN ('LINESTRING','MULTILINESTRING') THEN 'LINESTRING'"
829840
" when geometrytype(%1) IN ('POLYGON','MULTIPOLYGON') THEN 'POLYGON'"
830841
" end "
831-
"from "
832-
"\"%2\".\"%3\"" ).arg( "\"" + columns[i] + "\"" ).arg( schemas[i] ).arg( tables[i] );
842+
"from " ).arg( "\"" + columns[i] + "\"" );
843+
if ( mUseEstimatedMetadata )
844+
{
845+
query += QString( "(select %1 from %2 where %1 is not null limit %3) as t" )
846+
.arg( "\"" + columns[i] + "\"" )
847+
.arg( "\"" + schemas[i] + "\".\"" + tables[i] + "\"" )
848+
.arg( sGeomTypeSelectLimit );
849+
}
850+
else
851+
{
852+
query += "\"" + schemas[i] + "\".\"" + tables[i] + "\"";
853+
}
854+
833855
PGresult* gresult = PQexec( pd, query.toUtf8() );
834856
QString type;
835857
if ( PQresultStatus( gresult ) == PGRES_TUPLES_OK )

src/app/postgres/qgspgsourceselect.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase
154154
typedef QPair<QString, QString> geomPair;
155155
typedef QList<geomPair> geomCol;
156156

157-
bool getGeometryColumnInfo( PGconn *pd,
158-
geomCol& details,
159-
bool searchGeometryColumnsOnly,
160-
bool searchPublicOnly );
161-
162157
/**Inserts information about the spatial tables into mTableModel*/
163158
bool getTableInfo( PGconn *pg, bool searchGeometryColumnsOnly, bool searchPublicOnly );
164159

@@ -181,6 +176,7 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase
181176
QString m_connInfo;
182177
QString m_privConnInfo;
183178
QStringList m_selectedTables;
179+
bool mUseEstimatedMetadata;
184180
// Storage for the range of layer type icons
185181
QMap<QString, QPair<QString, QIcon> > mLayerIcons;
186182
PGconn *pd;
@@ -205,7 +201,7 @@ class QgsGeomColumnTypeThread : public QThread
205201
Q_OBJECT
206202
public:
207203

208-
void setConnInfo( QString s );
204+
void setConnInfo( QString s, bool useEstimatedMetadata );
209205
void addGeometryColumn( QString schema, QString table, QString column );
210206

211207
// These functions get the layer types and pass that information out
@@ -226,6 +222,7 @@ class QgsGeomColumnTypeThread : public QThread
226222

227223
private:
228224
QString mConnInfo;
225+
bool mUseEstimatedMetadata;
229226
bool mStopped;
230227
std::vector<QString> schemas, tables, columns;
231228
};

src/app/qgsmanageconnectionsdialog.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ QDomDocument QgsManageConnectionsDialog::savePgConnections( const QStringList &c
291291
el.setAttribute( "port", settings.value( path + "/port", "" ).toString() );
292292
el.setAttribute( "database", settings.value( path + "/database", "" ).toString() );
293293
el.setAttribute( "sslmode", settings.value( path + "/sslmode", "1" ).toString() );
294+
el.setAttribute( "estimatedMetadata", settings.value( path + "/estimatedMetadata", "0" ).toString() );
294295

295296
el.setAttribute( "saveUsername", settings.value( path + "/saveUsername", "false" ).toString() );
296297

@@ -415,9 +416,10 @@ void QgsManageConnectionsDialog::loadPgConnections( const QDomDocument &doc, con
415416
settings.setValue( "/port", child.attribute( "port" ) );
416417
settings.setValue( "/database", child.attribute( "database" ) );
417418
settings.setValue( "/sslmode", child.attribute( "sslmode" ) );
418-
settings.setValue( "/saveUsername", child.attribute( "saveUsername" ) );
419+
settings.setValue( "/estimatedMetadata", child.attribute( "estimatedMetadata" ) );
420+
settings.setValue( "/saveUsername", child.attribute( "saveUsername" ) );
419421
settings.setValue( "/username", child.attribute( "username" ) );
420-
settings.setValue( "/savePassword", child.attribute( "savePassword" ) );
422+
settings.setValue( "/savePassword", child.attribute( "savePassword" ) );
421423
settings.setValue( "/password", child.attribute( "password" ) );
422424
settings.endGroup();
423425

src/core/qgsdatasourceuri.cpp

+22-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
#include <QStringList>
2424
#include <QRegExp>
2525

26-
QgsDataSourceURI::QgsDataSourceURI() : mSSLmode( SSLprefer ), mKeyColumn( "" )
26+
QgsDataSourceURI::QgsDataSourceURI() : mSSLmode( SSLprefer ), mKeyColumn( "" ), mUseEstimatedMetadata( false )
2727
{
2828
// do nothing
2929
}
3030

31-
QgsDataSourceURI::QgsDataSourceURI( QString uri ) : mSSLmode( SSLprefer ), mKeyColumn( "" )
31+
QgsDataSourceURI::QgsDataSourceURI( QString uri ) : mSSLmode( SSLprefer ), mKeyColumn( "" ), mUseEstimatedMetadata( false )
3232
{
3333
int i = 0;
3434
while ( i < uri.length() )
@@ -108,6 +108,10 @@ QgsDataSourceURI::QgsDataSourceURI( QString uri ) : mSSLmode( SSLprefer ), mKeyC
108108
{
109109
mKeyColumn = pval;
110110
}
111+
else if ( pname == "estimatedmetadata" )
112+
{
113+
mUseEstimatedMetadata = pval == "true";
114+
}
111115
else if ( pname == "service" )
112116
{
113117
QgsDebugMsg( "service keyword ignored" );
@@ -281,6 +285,17 @@ void QgsDataSourceURI::setKeyColumn( QString column )
281285
mKeyColumn = column;
282286
}
283287

288+
289+
void QgsDataSourceURI::setUseEstimatedMetadata( bool theFlag )
290+
{
291+
mUseEstimatedMetadata = theFlag;
292+
}
293+
294+
bool QgsDataSourceURI::useEstimatedMetadata() const
295+
{
296+
return mUseEstimatedMetadata;
297+
}
298+
284299
void QgsDataSourceURI::setSql( QString sql )
285300
{
286301
mSql = sql;
@@ -419,6 +434,11 @@ QString QgsDataSourceURI::uri() const
419434
theUri += QString( " key='%1'" ).arg( escape( mKeyColumn ) );
420435
}
421436

437+
if ( mUseEstimatedMetadata )
438+
{
439+
theUri += QString( " estimatedmetadata=true" );
440+
}
441+
422442
theUri += QString( " table=%1 (%2) sql=%3" )
423443
.arg( quotedTablename() )
424444
.arg( mGeometryColumn )

src/core/qgsdatasourceuri.h

+7
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ class CORE_EXPORT QgsDataSourceURI
8585
QString sql() const;
8686
QString geometryColumn() const;
8787

88+
//! set use Estimated Metadata
89+
// added in 1.5
90+
void setUseEstimatedMetadata( bool theFlag );
91+
bool useEstimatedMetadata() const;
92+
8893
void clearSchema();
8994
void setSql( QString sql );
9095

@@ -128,6 +133,8 @@ class CORE_EXPORT QgsDataSourceURI
128133
enum SSLmode mSSLmode;
129134
//! key column
130135
QString mKeyColumn;
136+
//Use estimated metadata flag
137+
bool mUseEstimatedMetadata;
131138
};
132139

133140
#endif //QGSDATASOURCEURI_H

0 commit comments

Comments
 (0)