Skip to content

Commit

Permalink
fix connection info passed to QgsGeomColumnTypeThread broken in 6989fc7,
Browse files Browse the repository at this point in the history
hide close and add buttons from PG source select dialog when in embedded mode (e.g. qbrowser)
  • Loading branch information
brushtyler committed Jul 18, 2011
1 parent c4b92a5 commit cddd427
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 19 deletions.
62 changes: 47 additions & 15 deletions src/providers/postgres/qgspgsourceselect.cpp
Expand Up @@ -47,22 +47,35 @@ email : sherman at mrcc.com
// code this parameter is duplicated there.
static const int sGeomTypeSelectLimit = 100;

QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WFlags fl )
: QDialog( parent, fl ), mColumnTypeThread( NULL )
QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WFlags fl, bool managerMode, bool embeddedMode )
: QDialog( parent, fl )
, mManagerMode( managerMode )
, mEmbeddedMode( embeddedMode )
, mColumnTypeThread( NULL )
{
setupUi( this );

if ( mEmbeddedMode )
{
buttonBox->button( QDialogButtonBox::Close )->hide();
}

mAddButton = new QPushButton( tr( "&Add" ) );
buttonBox->addButton( mAddButton, QDialogButtonBox::ActionRole );
connect( mAddButton, SIGNAL( clicked() ), this, SLOT( addTables() ) );
mAddButton->setEnabled( false );

mBuildQueryButton = new QPushButton( tr( "&Build query" ) );
mBuildQueryButton->setToolTip( tr( "Build query" ) );
buttonBox->addButton( mBuildQueryButton, QDialogButtonBox::ActionRole );
connect( mBuildQueryButton, SIGNAL( clicked() ), this, SLOT( buildQuery() ) );
mBuildQueryButton->setDisabled( true );

mAddButton->setEnabled( false );
if ( !mManagerMode )
{
buttonBox->addButton( mAddButton, QDialogButtonBox::ActionRole );
connect( mAddButton, SIGNAL( clicked() ), this, SLOT( addTables() ) );

buttonBox->addButton( mBuildQueryButton, QDialogButtonBox::ActionRole );
connect( mBuildQueryButton, SIGNAL( clicked() ), this, SLOT( buildQuery() ) );
}

populateConnectionList();

mSearchModeComboBox->addItem( tr( "Wildcard" ) );
Expand Down Expand Up @@ -124,8 +137,8 @@ void QgsPgSourceSelect::on_btnNew_clicked()
QgsPgNewConnection *nc = new QgsPgNewConnection( this );
if ( nc->exec() )
{
emit connectionsChanged();
populateConnectionList();
emit connectionsChanged();
}
delete nc;
}
Expand Down Expand Up @@ -155,8 +168,8 @@ void QgsPgSourceSelect::on_btnDelete_clicked()
settings.remove( key + "/save" );
settings.remove( key );

emit connectionsChanged();
populateConnectionList();
emit connectionsChanged();
}

void QgsPgSourceSelect::on_btnSave_clicked()
Expand Down Expand Up @@ -185,8 +198,8 @@ void QgsPgSourceSelect::on_btnEdit_clicked()
QgsPgNewConnection *nc = new QgsPgNewConnection( this, cmbConnections->currentText() );
if ( nc->exec() )
{
emit connectionsChanged();
populateConnectionList();
emit connectionsChanged();
}
delete nc;
}
Expand Down Expand Up @@ -441,10 +454,6 @@ void QgsPgSourceSelect::on_btnConnect_clicked()
bool searchGeometryColumnsOnly = settings.value( key + "/geometryColumnsOnly" ).toBool();
bool allowGeometrylessTables = cbxAllowGeometrylessTables->isChecked();

QgsDebugMsg( "Connection info: " + uri.connectionInfo() );

m_connInfo = uri.connectionInfo();

QVector<QgsPostgresLayerProperty> layers;
if ( pgProvider->supportedLayers( layers, searchGeometryColumnsOnly, searchPublicOnly, allowGeometrylessTables ) )
{
Expand Down Expand Up @@ -553,7 +562,7 @@ void QgsPgSourceSelect::addSearchGeometryColumn( const QString &schema, const QS
if ( mColumnTypeThread == NULL )
{
mColumnTypeThread = new QgsGeomColumnTypeThread();
mColumnTypeThread->setConnInfo( m_privConnInfo, mUseEstimatedMetadata );
mColumnTypeThread->setConnInfo( m_connInfo, mUseEstimatedMetadata );
}
mColumnTypeThread->addGeometryColumn( schema, table, column );
}
Expand Down Expand Up @@ -611,6 +620,29 @@ void QgsGeomColumnTypeThread::getLayerTypes()
mStopped = false;

PGconn *pd = PQconnectdb( mConnInfo.toLocal8Bit() );
// check the connection status
if ( PQstatus( pd ) != CONNECTION_OK )
{
PQfinish( pd );

QgsDataSourceURI uri( mConnInfo );
QString username = uri.username();
QString password = uri.password();

// use cached credentials
bool ok = QgsCredentials::instance()->get( mConnInfo, username, password, QString::fromUtf8( PQerrorMessage( pd ) ) );
if ( !ok )
return;

if ( !username.isEmpty() )
uri.setUsername( username );

if ( !password.isEmpty() )
uri.setPassword( password );

pd = PQconnectdb( uri.connectionInfo().toLocal8Bit() );
}

if ( PQstatus( pd ) == CONNECTION_OK )
{
PQsetClientEncoding( pd, QString( "UNICODE" ).toLocal8Bit() );
Expand Down
9 changes: 7 additions & 2 deletions src/providers/postgres/qgspgsourceselect.h
Expand Up @@ -106,7 +106,7 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
public:

//! Constructor
QgsPgSourceSelect( QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags );
QgsPgSourceSelect( QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags, bool managerMode = false, bool embeddedMode = false );
//! Destructor
~QgsPgSourceSelect();
//! Populate the connection list combo box
Expand Down Expand Up @@ -160,6 +160,12 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
typedef QPair<QString, QString> geomPair;
typedef QList<geomPair> geomCol;

//! Connections manager mode
bool mManagerMode;

//! Embedded mode, without 'Close'
bool mEmbeddedMode;

// queue another query for the thread
void addSearchGeometryColumn( const QString &schema, const QString &table, const QString &column );

Expand All @@ -174,7 +180,6 @@ class QgsPgSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
// Our thread for doing long running queries
QgsGeomColumnTypeThread* mColumnTypeThread;
QString m_connInfo;
QString m_privConnInfo;
QStringList m_selectedTables;
bool mUseEstimatedMetadata;
// Storage for the range of layer type icons
Expand Down
4 changes: 2 additions & 2 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -4100,8 +4100,8 @@ QVector<QgsDataItem*>QgsPGRootItem::createChildren()

QWidget * QgsPGRootItem::paramWidget()
{
QgsPgSourceSelect *select = new QgsPgSourceSelect( 0, 0 );
//connect( select, SIGNAL( connectionsChanged() ), this, SLOT( connectionsChanged() ) );
QgsPgSourceSelect *select = new QgsPgSourceSelect( 0, 0, true, true );
connect( select, SIGNAL( connectionsChanged() ), this, SLOT( connectionsChanged() ) );
return select;
}
void QgsPGRootItem::connectionsChanged()
Expand Down

0 comments on commit cddd427

Please sign in to comment.