[QGIS Commit] r12390 - in trunk/qgis/src: app app/ogr plugins/spit
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Wed Dec 9 16:35:45 EST 2009
Author: jef
Date: 2009-12-09 16:35:43 -0500 (Wed, 09 Dec 2009)
New Revision: 12390
Modified:
trunk/qgis/src/app/ogr/qgsnewogrconnection.h
trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.cpp
trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.h
trunk/qgis/src/app/qgisapp.cpp
trunk/qgis/src/app/qgisapp.h
trunk/qgis/src/app/qgsnewconnection.cpp
trunk/qgis/src/app/qgsnewconnection.h
trunk/qgis/src/app/qgsnewhttpconnection.cpp
trunk/qgis/src/app/qgspgsourceselect.cpp
trunk/qgis/src/plugins/spit/qgsspit.cpp
Log:
fix connection dialogs (apply/fix #2217, #2231, #2232)
Modified: trunk/qgis/src/app/ogr/qgsnewogrconnection.h
===================================================================
--- trunk/qgis/src/app/ogr/qgsnewogrconnection.h 2009-12-09 19:58:22 UTC (rev 12389)
+++ trunk/qgis/src/app/ogr/qgsnewogrconnection.h 2009-12-09 21:35:43 UTC (rev 12390)
@@ -37,12 +37,13 @@
~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
Modified: trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.cpp
===================================================================
--- trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.cpp 2009-12-09 19:58:22 UTC (rev 12389)
+++ trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.cpp 2009-12-09 21:35:43 UTC (rev 12390)
@@ -150,20 +150,19 @@
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 @@
//********************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 @@
}
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 )
Modified: trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.h
===================================================================
--- trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.h 2009-12-09 19:58:22 UTC (rev 12389)
+++ trunk/qgis/src/app/ogr/qgsopenvectorlayerdialog.h 2009-12-09 21:35:43 UTC (rev 12390)
@@ -73,7 +73,8 @@
//! 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 );
Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp 2009-12-09 19:58:22 UTC (rev 12389)
+++ trunk/qgis/src/app/qgisapp.cpp 2009-12-09 21:35:43 UTC (rev 12390)
@@ -2106,19 +2106,17 @@
.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
-
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 @@
}
/** 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 @@
QStringList::Iterator it = tables.begin();
while ( it != tables.end() )
{
-
// normalizing the layer name
QString layername = *it;
layername = layername.mid( 1 );
@@ -2736,13 +2733,28 @@
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 @@
// with a linestring file).
if ( fileformat == "ESRI Shapefile" )
{
- if ( !fileName.endsWith( ".shp", Qt::CaseInsensitive ) )
- fileName += ".shp";
-
QgsVectorFileWriter::deleteShapeFile( fileName );
}
else
@@ -3505,7 +3514,8 @@
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 @@
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 @@
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 @@
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() )
{
Modified: trunk/qgis/src/app/qgisapp.h
===================================================================
--- trunk/qgis/src/app/qgisapp.h 2009-12-09 19:58:22 UTC (rev 12389)
+++ trunk/qgis/src/app/qgisapp.h 2009-12-09 21:35:43 UTC (rev 12390)
@@ -690,10 +690,10 @@
*/
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.
Modified: trunk/qgis/src/app/qgsnewconnection.cpp
===================================================================
--- trunk/qgis/src/app/qgsnewconnection.cpp 2009-12-09 19:58:22 UTC (rev 12389)
+++ trunk/qgis/src/app/qgsnewconnection.cpp 2009-12-09 21:35:43 UTC (rev 12390)
@@ -79,7 +79,39 @@
/** 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 @@
// 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
Modified: trunk/qgis/src/app/qgsnewconnection.h
===================================================================
--- trunk/qgis/src/app/qgsnewconnection.h 2009-12-09 19:58:22 UTC (rev 12389)
+++ trunk/qgis/src/app/qgsnewconnection.h 2009-12-09 21:35:43 UTC (rev 12390)
@@ -34,8 +34,6 @@
~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();
Modified: trunk/qgis/src/app/qgsnewhttpconnection.cpp
===================================================================
--- trunk/qgis/src/app/qgsnewhttpconnection.cpp 2009-12-09 19:58:22 UTC (rev 12389)
+++ trunk/qgis/src/app/qgsnewhttpconnection.cpp 2009-12-09 21:35:43 UTC (rev 12390)
@@ -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 @@
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() );
Modified: trunk/qgis/src/app/qgspgsourceselect.cpp
===================================================================
--- trunk/qgis/src/app/qgspgsourceselect.cpp 2009-12-09 19:58:22 UTC (rev 12389)
+++ trunk/qgis/src/app/qgspgsourceselect.cpp 2009-12-09 21:35:43 UTC (rev 12390)
@@ -93,10 +93,9 @@
{
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 @@
{
QgsNewConnection *nc = new QgsNewConnection( this, cmbConnections->currentText() );
- if ( nc->exec() )
- {
- nc->saveConnection();
- }
+ nc->exec();
+
populateConnectionList();
}
Modified: trunk/qgis/src/plugins/spit/qgsspit.cpp
===================================================================
--- trunk/qgis/src/plugins/spit/qgsspit.cpp 2009-12-09 19:58:22 UTC (rev 12389)
+++ trunk/qgis/src/plugins/spit/qgsspit.cpp 2009-12-09 21:35:43 UTC (rev 12390)
@@ -120,21 +120,15 @@
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()
More information about the QGIS-commit
mailing list