Skip to content
Permalink
Browse files

apply #2460 (slightly modified). Thanks Jeremy Palmer.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13044 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Mar 10, 2010
1 parent 08ecab7 commit ab9e926be24bde2fad2ba8b7ab7ea497dc27a1c7
@@ -60,6 +60,11 @@ public:
QString table() const;
QString sql() const;
QString geometryColumn() const;

//! set use Estimated Metadata
// added in 1.5
void setUseEstimatedMetadata( bool theFlag );
bool useEstimatedMetadata() const;

// added in 1.1
QString host() const;
@@ -56,17 +56,13 @@ QgsPgNewConnection::QgsPgNewConnection( QWidget *parent, const QString& connName
port = "5432";
}
txtPort->setText( port );
Qt::CheckState s = Qt::Checked;
if ( ! settings.value( key + "/publicOnly", false ).toBool() )
s = Qt::Unchecked;
cb_publicSchemaOnly->setCheckState( s );
s = Qt::Checked;
if ( ! settings.value( key + "/geometrycolumnsOnly", false ).toBool() )
s = Qt::Unchecked;
cb_geometryColumnsOnly->setCheckState( s );
cb_publicSchemaOnly->setChecked( settings.value( key + "/publicOnly", false ).toBool() );
cb_geometryColumnsOnly->setChecked( settings.value( key + "/geometrycolumnsOnly", false ).toBool() );
// Ensure that cb_plublicSchemaOnly is set correctly
on_cb_geometryColumnsOnly_clicked();

cb_useEstimatedMetadata->setChecked( settings.value( key + "/estimatedMetadata", false ).toBool() );

cbxSSLmode->setCurrentIndex( cbxSSLmode->findData( settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() ) );

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

// remove old save setting
settings.remove( baseKey + "/save" );
@@ -41,6 +41,10 @@ email : sherman at mrcc.com
#include <pg_config.h>
#endif

// Note: Because the the geometry type select SQL is also in the qgspostgresprovider
// code this parameter is duplicated there.
static const int sGeomTypeSelectLimit = 100;

QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WFlags fl )
: QDialog( parent, fl ), mColumnTypeThread( NULL ), pd( 0 )
{
@@ -142,6 +146,7 @@ void QgsPgSourceSelect::on_btnDelete_clicked()
settings.remove( key + "/sslmode" );
settings.remove( key + "/publicOnly" );
settings.remove( key + "/geometryColumnsOnly" );
settings.remove( key + "/estimatedMetadata" );
settings.remove( key + "/saveUsername" );
settings.remove( key + "/savePassword" );
settings.remove( key + "/save" );
@@ -352,6 +357,11 @@ QString QgsPgSourceSelect::layerURI( const QModelIndex &index )
uri += QString( " key=\"%1\"" ).arg( pkColumnName );
}

if ( mUseEstimatedMetadata )
{
uri += QString( " estimatedmetadata=true" );
}

uri += QString( " table=\"%1\".\"%2\" (%3) sql=%4" )
.arg( schemaName ).arg( tableName )
.arg( geomColumnName )
@@ -419,7 +429,7 @@ void QgsPgSourceSelect::on_btnConnect_clicked()

bool searchPublicOnly = settings.value( key + "/publicOnly" ).toBool();
bool searchGeometryColumnsOnly = settings.value( key + "/geometryColumnsOnly" ).toBool();

mUseEstimatedMetadata = settings.value( key + "/estimatedMetadata" ).toBool();
// Need to escape the password to allow for single quotes and backslashes

QgsDebugMsg( "Connection info: " + uri.connectionInfo() );
@@ -562,7 +572,7 @@ void QgsPgSourceSelect::addSearchGeometryColumn( const QString &schema, const QS
if ( mColumnTypeThread == NULL )
{
mColumnTypeThread = new QgsGeomColumnTypeThread();
mColumnTypeThread->setConnInfo( m_privConnInfo );
mColumnTypeThread->setConnInfo( m_privConnInfo, mUseEstimatedMetadata );
}
mColumnTypeThread->addGeometryColumn( schema, table, column );
}
@@ -794,9 +804,10 @@ void QgsPgSourceSelect::setSearchExpression( const QString& regexp )
{
}

void QgsGeomColumnTypeThread::setConnInfo( QString s )
void QgsGeomColumnTypeThread::setConnInfo( QString conninfo, bool useEstimatedMetadata )
{
mConnInfo = s;
mConnInfo = conninfo;
mUseEstimatedMetadata = useEstimatedMetadata;
}

void QgsGeomColumnTypeThread::addGeometryColumn( QString schema, QString table, QString column )
@@ -828,8 +839,19 @@ void QgsGeomColumnTypeThread::getLayerTypes()
" when geometrytype(%1) IN ('LINESTRING','MULTILINESTRING') THEN 'LINESTRING'"
" when geometrytype(%1) IN ('POLYGON','MULTIPOLYGON') THEN 'POLYGON'"
" end "
"from "
"\"%2\".\"%3\"" ).arg( "\"" + columns[i] + "\"" ).arg( schemas[i] ).arg( tables[i] );
"from " ).arg( "\"" + columns[i] + "\"" );
if ( mUseEstimatedMetadata )
{
query += QString( "(select %1 from %2 where %1 is not null limit %3) as t" )
.arg( "\"" + columns[i] + "\"" )
.arg( "\"" + schemas[i] + "\".\"" + tables[i] + "\"" )
.arg( sGeomTypeSelectLimit );
}
else
{
query += "\"" + schemas[i] + "\".\"" + tables[i] + "\"";
}

PGresult* gresult = PQexec( pd, query.toUtf8() );
QString type;
if ( PQresultStatus( gresult ) == PGRES_TUPLES_OK )
@@ -154,11 +154,6 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsPgSourceSelectBase
typedef QPair<QString, QString> geomPair;
typedef QList<geomPair> geomCol;

bool getGeometryColumnInfo( PGconn *pd,
geomCol& details,
bool searchGeometryColumnsOnly,
bool searchPublicOnly );

/**Inserts information about the spatial tables into mTableModel*/
bool getTableInfo( PGconn *pg, bool searchGeometryColumnsOnly, bool searchPublicOnly );

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

void setConnInfo( QString s );
void setConnInfo( QString s, bool useEstimatedMetadata );
void addGeometryColumn( QString schema, QString table, QString column );

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

private:
QString mConnInfo;
bool mUseEstimatedMetadata;
bool mStopped;
std::vector<QString> schemas, tables, columns;
};
@@ -291,6 +291,7 @@ QDomDocument QgsManageConnectionsDialog::savePgConnections( const QStringList &c
el.setAttribute( "port", settings.value( path + "/port", "" ).toString() );
el.setAttribute( "database", settings.value( path + "/database", "" ).toString() );
el.setAttribute( "sslmode", settings.value( path + "/sslmode", "1" ).toString() );
el.setAttribute( "estimatedMetadata", settings.value( path + "/estimatedMetadata", "0" ).toString() );

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

@@ -415,9 +416,10 @@ void QgsManageConnectionsDialog::loadPgConnections( const QDomDocument &doc, con
settings.setValue( "/port", child.attribute( "port" ) );
settings.setValue( "/database", child.attribute( "database" ) );
settings.setValue( "/sslmode", child.attribute( "sslmode" ) );
settings.setValue( "/saveUsername", child.attribute( "saveUsername" ) );
settings.setValue( "/estimatedMetadata", child.attribute( "estimatedMetadata" ) );
settings.setValue( "/saveUsername", child.attribute( "saveUsername" ) );
settings.setValue( "/username", child.attribute( "username" ) );
settings.setValue( "/savePassword", child.attribute( "savePassword" ) );
settings.setValue( "/savePassword", child.attribute( "savePassword" ) );
settings.setValue( "/password", child.attribute( "password" ) );
settings.endGroup();

@@ -23,12 +23,12 @@
#include <QStringList>
#include <QRegExp>

QgsDataSourceURI::QgsDataSourceURI() : mSSLmode( SSLprefer ), mKeyColumn( "" )
QgsDataSourceURI::QgsDataSourceURI() : mSSLmode( SSLprefer ), mKeyColumn( "" ), mUseEstimatedMetadata( false )
{
// do nothing
}

QgsDataSourceURI::QgsDataSourceURI( QString uri ) : mSSLmode( SSLprefer ), mKeyColumn( "" )
QgsDataSourceURI::QgsDataSourceURI( QString uri ) : mSSLmode( SSLprefer ), mKeyColumn( "" ), mUseEstimatedMetadata( false )
{
int i = 0;
while ( i < uri.length() )
@@ -108,6 +108,10 @@ QgsDataSourceURI::QgsDataSourceURI( QString uri ) : mSSLmode( SSLprefer ), mKeyC
{
mKeyColumn = pval;
}
else if ( pname == "estimatedmetadata" )
{
mUseEstimatedMetadata = pval == "true";
}
else if ( pname == "service" )
{
QgsDebugMsg( "service keyword ignored" );
@@ -281,6 +285,17 @@ void QgsDataSourceURI::setKeyColumn( QString column )
mKeyColumn = column;
}


void QgsDataSourceURI::setUseEstimatedMetadata( bool theFlag )
{
mUseEstimatedMetadata = theFlag;
}

bool QgsDataSourceURI::useEstimatedMetadata() const
{
return mUseEstimatedMetadata;
}

void QgsDataSourceURI::setSql( QString sql )
{
mSql = sql;
@@ -419,6 +434,11 @@ QString QgsDataSourceURI::uri() const
theUri += QString( " key='%1'" ).arg( escape( mKeyColumn ) );
}

if ( mUseEstimatedMetadata )
{
theUri += QString( " estimatedmetadata=true" );
}

theUri += QString( " table=%1 (%2) sql=%3" )
.arg( quotedTablename() )
.arg( mGeometryColumn )
@@ -85,6 +85,11 @@ class CORE_EXPORT QgsDataSourceURI
QString sql() const;
QString geometryColumn() const;

//! set use Estimated Metadata
// added in 1.5
void setUseEstimatedMetadata( bool theFlag );
bool useEstimatedMetadata() const;

void clearSchema();
void setSql( QString sql );

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

#endif //QGSDATASOURCEURI_H

0 comments on commit ab9e926

Please sign in to comment.
You can’t perform that action at this time.