fix connection dialogs (apply/fix #2217, #2231, #2232)

git-svn-id: http://svn.osgeo.org/qgis/trunk@12390 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
jef 2009-12-09 21:35:43 +00:00
parent 0c462e875c
commit 80c1cf326c
10 changed files with 136 additions and 94 deletions

View File

@ -37,12 +37,13 @@ class QgsNewOgrConnection : public QDialog, private Ui::QgsNewOgrConnectionBase
~QgsNewOgrConnection();
//! Tests the connection using the parameters supplied
void testConnection();
//! Saves the connection to ~/.qt/qgisrc
void saveConnection();
public slots:
void accept();
void on_btnConnect_clicked();
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
private:
QString mOriginalConnName;
};
#endif // QGSNEWOGRCONNECTIONBASE_H

View File

@ -150,20 +150,19 @@ QString QgsOpenVectorLayerDialog::dataSourceType()
void QgsOpenVectorLayerDialog::addNewConnection()
{
QgsNewOgrConnection *nc = new QgsNewOgrConnection( this );
if ( nc->exec() )
{
populateConnectionList();
}
nc->exec();
delete nc;
populateConnectionList();
}
void QgsOpenVectorLayerDialog::editConnection()
{
QgsNewOgrConnection *nc = new QgsNewOgrConnection( this, cmbDatabaseTypes->currentText(), cmbConnections->currentText() );
nc->exec();
delete nc;
if ( nc->exec() )
{
nc->saveConnection();
}
populateConnectionList();
}
void QgsOpenVectorLayerDialog::deleteConnection()
@ -309,12 +308,22 @@ void QgsOpenVectorLayerDialog::on_buttonSelectSrc_clicked()
//********************auto connected slots *****************/
void QgsOpenVectorLayerDialog::on_buttonBox_accepted()
void QgsOpenVectorLayerDialog::accept()
{
QSettings settings;
QgsDebugMsg( "dialog button accepted" );
if ( radioSrcDatabase->isChecked() )
{
if ( !settings.contains( "/" + cmbDatabaseTypes->currentText()
+ "/connections/" + cmbConnections->currentText()
+ "/host" ) )
{
QMessageBox::information( this,
tr( "Add vector layer" ),
tr( "No database selected." ) );
return;
}
mDataSources.clear();
QString baseKey = "/" + cmbDatabaseTypes->currentText() + "/connections/";
baseKey += cmbConnections->currentText();
@ -340,16 +349,39 @@ void QgsOpenVectorLayerDialog::on_buttonBox_accepted()
}
else if ( radioSrcProtocol->isChecked() )
{
if ( protocolURI->text().isEmpty() )
{
QMessageBox::information( this,
tr( "Add vector layer" ),
tr( "No protocol URI entered." ) );
return;
}
mDataSources.clear();
mDataSources.append( createProtocolURI(
cmbProtocolTypes->currentText(),
protocolURI->text()
) );
}
else if ( radioSrcFile->isChecked() && inputSrcDataset->text().isEmpty() )
{
QMessageBox::information( this,
tr( "Add vector layer" ),
tr( "No layers selected." ) );
return;
}
else if ( radioSrcDirectory->isChecked() && inputSrcDataset->text().isEmpty() )
{
QMessageBox::information( this,
tr( "Add vector layer" ),
tr( "No directory selected." ) );
return;
}
// Save the used encoding
settings.setValue( "/UI/encoding", encoding() );
accept();
QDialog::accept();
}
void QgsOpenVectorLayerDialog::on_radioSrcFile_toggled( bool checked )

View File

@ -73,7 +73,8 @@ class QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerD
//! Sets the selected connection
void setSelectedConnection();
void on_buttonBox_accepted();
void accept();
void on_buttonSelectSrc_clicked();
void on_radioSrcFile_toggled( bool checked );
void on_radioSrcDirectory_toggled( bool checked );

View File

@ -2106,19 +2106,17 @@ void QgisApp::about()
.arg( QGis::QGIS_VERSION )
.arg( QGis::QGIS_SVN_VERSION );
#ifdef HAVE_POSTGRESQL
versionString += tr( " This copy of QGIS has been built with PostgreSQL support." );
#else
versionString += tr( " This copy of QGIS has been built without PostgreSQL support." );
#endif
#ifdef HAVE_SPATIALITE
#ifdef HAVE_SPATIALITE
versionString += tr( "\nThis copy of QGIS has been built with SpatiaLite support." );
#else
versionString += tr( "\nThis copy of QGIS has been built without SpatiaLite support." );
#endif
versionString += tr( "\nThis binary was compiled against Qt %1,"
"and is currently running against Qt %2" )
.arg( QT_VERSION_STR )
@ -2399,16 +2397,16 @@ void QgisApp::loadOGRSublayers( QString layertype, QString uri, QStringList list
}
/** This helper checks to see whether the file name appears to be a valid vector file name */
bool QgisApp::isValidVectorFileName( QString theFileNameQString )
bool QgisApp::isValidShapeFileName( QString theFileNameQString )
{
return ( theFileNameQString.toLower().endsWith( ".shp" ) );
return theFileNameQString.endsWith( ".shp", Qt::CaseInsensitive );
}
/** Overloaded of the above function provided for convenience that takes a qstring pointer */
bool QgisApp::isValidVectorFileName( QString * theFileNameQString )
bool QgisApp::isValidShapeFileName( QString * theFileNameQString )
{
//dereference and delegate
return isValidVectorFileName( *theFileNameQString );
return isValidShapeFileName( *theFileNameQString );
}
#ifndef HAVE_POSTGRESQL
@ -2524,7 +2522,6 @@ void QgisApp::addSpatiaLiteLayer()
QStringList::Iterator it = tables.begin();
while ( it != tables.end() )
{
// normalizing the layer name
QString layername = *it;
layername = layername.mid( 1 );
@ -2736,13 +2733,28 @@ void QgisApp::newVectorLayer()
openFileDialog->selectFilter( lastUsedFilter );
}
if ( openFileDialog->exec() != QDialog::Accepted )
int res;
while (( res = openFileDialog->exec() ) == QDialog::Accepted )
{
fileName = openFileDialog->selectedFiles().first();
if ( fileformat == "ESRI Shapefile" && !isValidShapeFileName( fileName ) )
{
QMessageBox::information( this,
tr( "New Shapefile" ),
tr( "Shapefiles must end on .shp" ) );
continue;
}
break;
}
if ( res == QDialog::Rejected )
{
delete openFileDialog;
return;
}
fileName = openFileDialog->selectedFiles().first();
enc = openFileDialog->encoding();
// If the file exists, delete it otherwise we'll end up loading that
@ -2751,9 +2763,6 @@ void QgisApp::newVectorLayer()
// with a linestring file).
if ( fileformat == "ESRI Shapefile" )
{
if ( !fileName.endsWith( ".shp", Qt::CaseInsensitive ) )
fileName += ".shp";
QgsVectorFileWriter::deleteShapeFile( fileName );
}
else
@ -3505,7 +3514,8 @@ void QgisApp::deleteSelected( QgsMapLayer *layer )
if ( !layer )
{
QMessageBox::information( this, tr( "No Layer Selected" ),
QMessageBox::information( this,
tr( "No Layer Selected" ),
tr( "To delete features, you must select a vector layer in the legend" ) );
return;
}
@ -3513,7 +3523,8 @@ void QgisApp::deleteSelected( QgsMapLayer *layer )
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( !vlayer )
{
QMessageBox::information( this, tr( "No Vector Layer Selected" ),
QMessageBox::information( this,
tr( "No Vector Layer Selected" ),
tr( "Deleting features only works on vector layers" ) );
return;
}
@ -3957,7 +3968,7 @@ void QgisApp::editCut( QgsMapLayer * layerContainingSelection )
if ( selectionVectorLayer != 0 )
{
QgsFeatureList features = selectionVectorLayer->selectedFeatures();
clipboard()->replaceWithCopyOf( selectionVectorLayer->dataProvider()->fields(), features );
clipboard()->replaceWithCopyOf( selectionVectorLayer->pendingFields(), features );
clipboard()->setCRS( selectionVectorLayer->srs() );
selectionVectorLayer->beginEditCommand( tr( "Features cut" ) );
selectionVectorLayer->deleteSelectedFeatures();
@ -3986,14 +3997,14 @@ void QgisApp::editCopy( QgsMapLayer * layerContainingSelection )
if ( selectionVectorLayer != 0 )
{
QgsFeatureList features = selectionVectorLayer->selectedFeatures();
clipboard()->replaceWithCopyOf( selectionVectorLayer->dataProvider()->fields(), features );
clipboard()->replaceWithCopyOf( selectionVectorLayer->pendingFields(), features );
clipboard()->setCRS( selectionVectorLayer->srs() );
}
}
}
void QgisApp::editPaste( QgsMapLayer * destinationLayer )
void QgisApp::editPaste( QgsMapLayer *destinationLayer )
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
{

View File

@ -690,10 +690,10 @@ class QgisApp : public QMainWindow
*/
bool addRasterLayer( QgsRasterLayer * theRasterLayer );
//@todo We should move these next two into vector layer class
/** This helper checks to see whether the file name appears to be a valid vector file name */
bool isValidVectorFileName( QString theFileNameQString );
/** This helper checks to see whether the file name appears to be a valid shape file name */
bool isValidShapeFileName( QString theFileNameQString );
/** Overloaded version of the above function provided for convenience that takes a qstring pointer */
bool isValidVectorFileName( QString * theFileNameQString );
bool isValidShapeFileName( QString * theFileNameQString );
/** add this file to the recently opened/saved projects list
* pass settings by reference since creating more than one
* instance simultaneously results in data loss.

View File

@ -79,7 +79,39 @@ QgsNewConnection::QgsNewConnection( QWidget *parent, const QString& connName, Qt
/** Autoconnected SLOTS **/
void QgsNewConnection::accept()
{
saveConnection();
QSettings settings;
QString baseKey = "/PostgreSQL/connections/";
settings.setValue( baseKey + "selected", txtName->text() );
// warn if entry was renamed to an existing connection
if (( mOriginalConnName.isNull() || mOriginalConnName != txtName->text() ) &&
settings.contains( baseKey + txtName->text() + "/host" ) &&
QMessageBox::question( this,
tr( "Save connection" ),
tr( "Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
{
return;
}
// on rename delete the original entry first
if ( !mOriginalConnName.isNull() && mOriginalConnName != txtName->text() )
{
settings.remove( baseKey + mOriginalConnName );
}
baseKey += txtName->text();
settings.setValue( baseKey + "/host", txtHost->text() );
settings.setValue( baseKey + "/database", txtDatabase->text() );
settings.setValue( baseKey + "/port", txtPort->text() );
settings.setValue( baseKey + "/username", txtUsername->text() );
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : "" );
settings.setValue( baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked() );
settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() );
settings.setValue( baseKey + "/save", chkStorePassword->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/sslmode", cbxSSLmode->currentIndex() );
QDialog::accept();
}
@ -122,40 +154,3 @@ void QgsNewConnection::testConnection()
// free pg connection resources
PQfinish( pd );
}
void QgsNewConnection::saveConnection()
{
QSettings settings;
QString baseKey = "/PostgreSQL/connections/";
settings.setValue( baseKey + "selected", txtName->text() );
//delete original entry first
if ( !mOriginalConnName.isNull() && mOriginalConnName != txtName->text() )
{
settings.remove( baseKey + mOriginalConnName );
}
baseKey += txtName->text();
settings.setValue( baseKey + "/host", txtHost->text() );
settings.setValue( baseKey + "/database", txtDatabase->text() );
settings.setValue( baseKey + "/port", txtPort->text() );
settings.setValue( baseKey + "/username", txtUsername->text() );
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : "" );
settings.setValue( baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked() );
settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() );
settings.setValue( baseKey + "/save", chkStorePassword->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/sslmode", cbxSSLmode->currentIndex() );
}
#if 0
void QgsNewConnection::saveConnection()
{
QSettings settings;
QString baseKey = "/PostgreSQL/connections/";
baseKey += txtName->text();
settings.setValue( baseKey + "/host", txtHost->text() );
settings.setValue( baseKey + "/database", txtDatabase->text() );
settings.setValue( baseKey + "/username", txtUsername->text() );
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : "" );
accept();
}
#endif

View File

@ -34,8 +34,6 @@ class QgsNewConnection : public QDialog, private Ui::QgsNewConnectionBase
~QgsNewConnection();
//! Tests the connection using the parameters supplied
void testConnection();
//! Saves the connection to ~/.qt/qgisrc
void saveConnection();
public slots:
void accept();
void on_btnConnect_clicked();

View File

@ -18,6 +18,7 @@
#include "qgsnewhttpconnection.h"
#include "qgscontexthelp.h"
#include <QSettings>
#include <QMessageBox>
QgsNewHttpConnection::QgsNewHttpConnection(
QWidget *parent, const QString& baseKey, const QString& connName, Qt::WFlags fl ):
@ -54,12 +55,24 @@ void QgsNewHttpConnection::accept()
QString key = mBaseKey + txtName->text();
QString credentialsKey = "/Qgis/WMS/" + txtName->text();
//delete original entry first
// warn if entry was renamed to an existing connection
if (( mOriginalConnName.isNull() || mOriginalConnName != txtName->text() ) &&
settings.contains( key + "/url" ) &&
QMessageBox::question( this,
tr( "Save connection" ),
tr( "Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
{
return;
}
// on rename delete original entry first
if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
{
settings.remove( mBaseKey + mOriginalConnName );
settings.remove( "/Qgis/WMS/" + mOriginalConnName );
}
settings.setValue( key + "/url", txtUrl->text().trimmed() );
settings.setValue( credentialsKey + "/username", txtUserName->text() );
settings.setValue( credentialsKey + "/password", txtPassword->text() );

View File

@ -93,10 +93,9 @@ void QgsPgSourceSelect::on_btnNew_clicked()
{
QgsNewConnection *nc = new QgsNewConnection( this );
if ( nc->exec() )
{
populateConnectionList();
}
nc->exec();
populateConnectionList();
}
// Slot for deleting an existing connection
void QgsPgSourceSelect::on_btnDelete_clicked()
@ -134,10 +133,8 @@ void QgsPgSourceSelect::on_btnEdit_clicked()
{
QgsNewConnection *nc = new QgsNewConnection( this, cmbConnections->currentText() );
if ( nc->exec() )
{
nc->saveConnection();
}
nc->exec();
populateConnectionList();
}

View File

@ -120,21 +120,15 @@ void QgsSpit::populateConnectionList()
void QgsSpit::newConnection()
{
QgsNewConnection *nc = new QgsNewConnection( this );
if ( nc->exec() )
{
populateConnectionList();
}
nc->exec();
delete nc;
}
void QgsSpit::editConnection()
{
QgsNewConnection *nc = new QgsNewConnection( this, cmbConnections->currentText() );
if ( nc->exec() )
{
nc->saveConnection();
}
nc->exec();
delete nc;
}
void QgsSpit::removeConnection()