Skip to content

Commit 80c1cf3

Browse files
author
jef
committedDec 9, 2009
fix connection dialogs (apply/fix #2217, #2231, #2232)
git-svn-id: http://svn.osgeo.org/qgis/trunk@12390 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 0c462e8 commit 80c1cf3

10 files changed

+136
-94
lines changed
 

‎src/app/ogr/qgsnewogrconnection.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ class QgsNewOgrConnection : public QDialog, private Ui::QgsNewOgrConnectionBase
3737
~QgsNewOgrConnection();
3838
//! Tests the connection using the parameters supplied
3939
void testConnection();
40-
//! Saves the connection to ~/.qt/qgisrc
41-
void saveConnection();
4240
public slots:
4341
void accept();
4442
void on_btnConnect_clicked();
4543
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
44+
45+
private:
46+
QString mOriginalConnName;
4647
};
4748

4849
#endif // QGSNEWOGRCONNECTIONBASE_H

‎src/app/ogr/qgsopenvectorlayerdialog.cpp

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,19 @@ QString QgsOpenVectorLayerDialog::dataSourceType()
150150
void QgsOpenVectorLayerDialog::addNewConnection()
151151
{
152152
QgsNewOgrConnection *nc = new QgsNewOgrConnection( this );
153-
if ( nc->exec() )
154-
{
155-
populateConnectionList();
156-
}
153+
nc->exec();
154+
delete nc;
155+
156+
populateConnectionList();
157157
}
158158

159159
void QgsOpenVectorLayerDialog::editConnection()
160160
{
161161
QgsNewOgrConnection *nc = new QgsNewOgrConnection( this, cmbDatabaseTypes->currentText(), cmbConnections->currentText() );
162+
nc->exec();
163+
delete nc;
162164

163-
if ( nc->exec() )
164-
{
165-
nc->saveConnection();
166-
}
165+
populateConnectionList();
167166
}
168167

169168
void QgsOpenVectorLayerDialog::deleteConnection()
@@ -309,12 +308,22 @@ void QgsOpenVectorLayerDialog::on_buttonSelectSrc_clicked()
309308

310309

311310
//********************auto connected slots *****************/
312-
void QgsOpenVectorLayerDialog::on_buttonBox_accepted()
311+
void QgsOpenVectorLayerDialog::accept()
313312
{
314313
QSettings settings;
315314
QgsDebugMsg( "dialog button accepted" );
316315
if ( radioSrcDatabase->isChecked() )
317316
{
317+
if ( !settings.contains( "/" + cmbDatabaseTypes->currentText()
318+
+ "/connections/" + cmbConnections->currentText()
319+
+ "/host" ) )
320+
{
321+
QMessageBox::information( this,
322+
tr( "Add vector layer" ),
323+
tr( "No database selected." ) );
324+
return;
325+
}
326+
318327
mDataSources.clear();
319328
QString baseKey = "/" + cmbDatabaseTypes->currentText() + "/connections/";
320329
baseKey += cmbConnections->currentText();
@@ -340,16 +349,39 @@ void QgsOpenVectorLayerDialog::on_buttonBox_accepted()
340349
}
341350
else if ( radioSrcProtocol->isChecked() )
342351
{
352+
if ( protocolURI->text().isEmpty() )
353+
{
354+
QMessageBox::information( this,
355+
tr( "Add vector layer" ),
356+
tr( "No protocol URI entered." ) );
357+
return;
358+
}
359+
343360
mDataSources.clear();
344361
mDataSources.append( createProtocolURI(
345362
cmbProtocolTypes->currentText(),
346363
protocolURI->text()
347364
) );
348365
}
366+
else if ( radioSrcFile->isChecked() && inputSrcDataset->text().isEmpty() )
367+
{
368+
QMessageBox::information( this,
369+
tr( "Add vector layer" ),
370+
tr( "No layers selected." ) );
371+
return;
372+
}
373+
else if ( radioSrcDirectory->isChecked() && inputSrcDataset->text().isEmpty() )
374+
{
375+
QMessageBox::information( this,
376+
tr( "Add vector layer" ),
377+
tr( "No directory selected." ) );
378+
return;
379+
}
380+
349381
// Save the used encoding
350382
settings.setValue( "/UI/encoding", encoding() );
351383

352-
accept();
384+
QDialog::accept();
353385
}
354386

355387
void QgsOpenVectorLayerDialog::on_radioSrcFile_toggled( bool checked )

‎src/app/ogr/qgsopenvectorlayerdialog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerD
7373
//! Sets the selected connection
7474
void setSelectedConnection();
7575

76-
void on_buttonBox_accepted();
76+
void accept();
77+
7778
void on_buttonSelectSrc_clicked();
7879
void on_radioSrcFile_toggled( bool checked );
7980
void on_radioSrcDirectory_toggled( bool checked );

‎src/app/qgisapp.cpp

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,19 +2106,17 @@ void QgisApp::about()
21062106
.arg( QGis::QGIS_VERSION )
21072107
.arg( QGis::QGIS_SVN_VERSION );
21082108
#ifdef HAVE_POSTGRESQL
2109-
21102109
versionString += tr( " This copy of QGIS has been built with PostgreSQL support." );
21112110
#else
2112-
21132111
versionString += tr( " This copy of QGIS has been built without PostgreSQL support." );
21142112
#endif
2115-
#ifdef HAVE_SPATIALITE
21162113

2114+
#ifdef HAVE_SPATIALITE
21172115
versionString += tr( "\nThis copy of QGIS has been built with SpatiaLite support." );
21182116
#else
2119-
21202117
versionString += tr( "\nThis copy of QGIS has been built without SpatiaLite support." );
21212118
#endif
2119+
21222120
versionString += tr( "\nThis binary was compiled against Qt %1,"
21232121
"and is currently running against Qt %2" )
21242122
.arg( QT_VERSION_STR )
@@ -2399,16 +2397,16 @@ void QgisApp::loadOGRSublayers( QString layertype, QString uri, QStringList list
23992397
}
24002398

24012399
/** This helper checks to see whether the file name appears to be a valid vector file name */
2402-
bool QgisApp::isValidVectorFileName( QString theFileNameQString )
2400+
bool QgisApp::isValidShapeFileName( QString theFileNameQString )
24032401
{
2404-
return ( theFileNameQString.toLower().endsWith( ".shp" ) );
2402+
return theFileNameQString.endsWith( ".shp", Qt::CaseInsensitive );
24052403
}
24062404

24072405
/** Overloaded of the above function provided for convenience that takes a qstring pointer */
2408-
bool QgisApp::isValidVectorFileName( QString * theFileNameQString )
2406+
bool QgisApp::isValidShapeFileName( QString * theFileNameQString )
24092407
{
24102408
//dereference and delegate
2411-
return isValidVectorFileName( *theFileNameQString );
2409+
return isValidShapeFileName( *theFileNameQString );
24122410
}
24132411

24142412
#ifndef HAVE_POSTGRESQL
@@ -2524,7 +2522,6 @@ void QgisApp::addSpatiaLiteLayer()
25242522
QStringList::Iterator it = tables.begin();
25252523
while ( it != tables.end() )
25262524
{
2527-
25282525
// normalizing the layer name
25292526
QString layername = *it;
25302527
layername = layername.mid( 1 );
@@ -2736,13 +2733,28 @@ void QgisApp::newVectorLayer()
27362733
openFileDialog->selectFilter( lastUsedFilter );
27372734
}
27382735

2739-
if ( openFileDialog->exec() != QDialog::Accepted )
2736+
int res;
2737+
while (( res = openFileDialog->exec() ) == QDialog::Accepted )
2738+
{
2739+
fileName = openFileDialog->selectedFiles().first();
2740+
2741+
if ( fileformat == "ESRI Shapefile" && !isValidShapeFileName( fileName ) )
2742+
{
2743+
QMessageBox::information( this,
2744+
tr( "New Shapefile" ),
2745+
tr( "Shapefiles must end on .shp" ) );
2746+
continue;
2747+
}
2748+
2749+
break;
2750+
}
2751+
2752+
if ( res == QDialog::Rejected )
27402753
{
27412754
delete openFileDialog;
27422755
return;
27432756
}
27442757

2745-
fileName = openFileDialog->selectedFiles().first();
27462758
enc = openFileDialog->encoding();
27472759

27482760
// If the file exists, delete it otherwise we'll end up loading that
@@ -2751,9 +2763,6 @@ void QgisApp::newVectorLayer()
27512763
// with a linestring file).
27522764
if ( fileformat == "ESRI Shapefile" )
27532765
{
2754-
if ( !fileName.endsWith( ".shp", Qt::CaseInsensitive ) )
2755-
fileName += ".shp";
2756-
27572766
QgsVectorFileWriter::deleteShapeFile( fileName );
27582767
}
27592768
else
@@ -3505,15 +3514,17 @@ void QgisApp::deleteSelected( QgsMapLayer *layer )
35053514

35063515
if ( !layer )
35073516
{
3508-
QMessageBox::information( this, tr( "No Layer Selected" ),
3517+
QMessageBox::information( this,
3518+
tr( "No Layer Selected" ),
35093519
tr( "To delete features, you must select a vector layer in the legend" ) );
35103520
return;
35113521
}
35123522

35133523
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer );
35143524
if ( !vlayer )
35153525
{
3516-
QMessageBox::information( this, tr( "No Vector Layer Selected" ),
3526+
QMessageBox::information( this,
3527+
tr( "No Vector Layer Selected" ),
35173528
tr( "Deleting features only works on vector layers" ) );
35183529
return;
35193530
}
@@ -3957,7 +3968,7 @@ void QgisApp::editCut( QgsMapLayer * layerContainingSelection )
39573968
if ( selectionVectorLayer != 0 )
39583969
{
39593970
QgsFeatureList features = selectionVectorLayer->selectedFeatures();
3960-
clipboard()->replaceWithCopyOf( selectionVectorLayer->dataProvider()->fields(), features );
3971+
clipboard()->replaceWithCopyOf( selectionVectorLayer->pendingFields(), features );
39613972
clipboard()->setCRS( selectionVectorLayer->srs() );
39623973
selectionVectorLayer->beginEditCommand( tr( "Features cut" ) );
39633974
selectionVectorLayer->deleteSelectedFeatures();
@@ -3986,14 +3997,14 @@ void QgisApp::editCopy( QgsMapLayer * layerContainingSelection )
39863997
if ( selectionVectorLayer != 0 )
39873998
{
39883999
QgsFeatureList features = selectionVectorLayer->selectedFeatures();
3989-
clipboard()->replaceWithCopyOf( selectionVectorLayer->dataProvider()->fields(), features );
4000+
clipboard()->replaceWithCopyOf( selectionVectorLayer->pendingFields(), features );
39904001
clipboard()->setCRS( selectionVectorLayer->srs() );
39914002
}
39924003
}
39934004
}
39944005

39954006

3996-
void QgisApp::editPaste( QgsMapLayer * destinationLayer )
4007+
void QgisApp::editPaste( QgsMapLayer *destinationLayer )
39974008
{
39984009
if ( mMapCanvas && mMapCanvas->isDrawing() )
39994010
{

‎src/app/qgisapp.h

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

‎src/app/qgsnewconnection.cpp

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,39 @@ QgsNewConnection::QgsNewConnection( QWidget *parent, const QString& connName, Qt
7979
/** Autoconnected SLOTS **/
8080
void QgsNewConnection::accept()
8181
{
82-
saveConnection();
82+
QSettings settings;
83+
QString baseKey = "/PostgreSQL/connections/";
84+
settings.setValue( baseKey + "selected", txtName->text() );
85+
86+
// warn if entry was renamed to an existing connection
87+
if (( mOriginalConnName.isNull() || mOriginalConnName != txtName->text() ) &&
88+
settings.contains( baseKey + txtName->text() + "/host" ) &&
89+
QMessageBox::question( this,
90+
tr( "Save connection" ),
91+
tr( "Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
92+
QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
93+
{
94+
return;
95+
}
96+
97+
// on rename delete the original entry first
98+
if ( !mOriginalConnName.isNull() && mOriginalConnName != txtName->text() )
99+
{
100+
101+
settings.remove( baseKey + mOriginalConnName );
102+
}
103+
104+
baseKey += txtName->text();
105+
settings.setValue( baseKey + "/host", txtHost->text() );
106+
settings.setValue( baseKey + "/database", txtDatabase->text() );
107+
settings.setValue( baseKey + "/port", txtPort->text() );
108+
settings.setValue( baseKey + "/username", txtUsername->text() );
109+
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : "" );
110+
settings.setValue( baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked() );
111+
settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() );
112+
settings.setValue( baseKey + "/save", chkStorePassword->isChecked() ? "true" : "false" );
113+
settings.setValue( baseKey + "/sslmode", cbxSSLmode->currentIndex() );
114+
83115
QDialog::accept();
84116
}
85117

@@ -122,40 +154,3 @@ void QgsNewConnection::testConnection()
122154
// free pg connection resources
123155
PQfinish( pd );
124156
}
125-
126-
void QgsNewConnection::saveConnection()
127-
{
128-
QSettings settings;
129-
QString baseKey = "/PostgreSQL/connections/";
130-
settings.setValue( baseKey + "selected", txtName->text() );
131-
//delete original entry first
132-
if ( !mOriginalConnName.isNull() && mOriginalConnName != txtName->text() )
133-
{
134-
settings.remove( baseKey + mOriginalConnName );
135-
}
136-
baseKey += txtName->text();
137-
settings.setValue( baseKey + "/host", txtHost->text() );
138-
settings.setValue( baseKey + "/database", txtDatabase->text() );
139-
settings.setValue( baseKey + "/port", txtPort->text() );
140-
settings.setValue( baseKey + "/username", txtUsername->text() );
141-
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : "" );
142-
settings.setValue( baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked() );
143-
settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() );
144-
settings.setValue( baseKey + "/save", chkStorePassword->isChecked() ? "true" : "false" );
145-
settings.setValue( baseKey + "/sslmode", cbxSSLmode->currentIndex() );
146-
}
147-
148-
#if 0
149-
void QgsNewConnection::saveConnection()
150-
{
151-
QSettings settings;
152-
QString baseKey = "/PostgreSQL/connections/";
153-
baseKey += txtName->text();
154-
settings.setValue( baseKey + "/host", txtHost->text() );
155-
settings.setValue( baseKey + "/database", txtDatabase->text() );
156-
157-
settings.setValue( baseKey + "/username", txtUsername->text() );
158-
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : "" );
159-
accept();
160-
}
161-
#endif

‎src/app/qgsnewconnection.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ class QgsNewConnection : public QDialog, private Ui::QgsNewConnectionBase
3434
~QgsNewConnection();
3535
//! Tests the connection using the parameters supplied
3636
void testConnection();
37-
//! Saves the connection to ~/.qt/qgisrc
38-
void saveConnection();
3937
public slots:
4038
void accept();
4139
void on_btnConnect_clicked();

‎src/app/qgsnewhttpconnection.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgsnewhttpconnection.h"
1919
#include "qgscontexthelp.h"
2020
#include <QSettings>
21+
#include <QMessageBox>
2122

2223
QgsNewHttpConnection::QgsNewHttpConnection(
2324
QWidget *parent, const QString& baseKey, const QString& connName, Qt::WFlags fl ):
@@ -54,12 +55,24 @@ void QgsNewHttpConnection::accept()
5455
QString key = mBaseKey + txtName->text();
5556
QString credentialsKey = "/Qgis/WMS/" + txtName->text();
5657

57-
//delete original entry first
58+
// warn if entry was renamed to an existing connection
59+
if (( mOriginalConnName.isNull() || mOriginalConnName != txtName->text() ) &&
60+
settings.contains( key + "/url" ) &&
61+
QMessageBox::question( this,
62+
tr( "Save connection" ),
63+
tr( "Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
64+
QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
65+
{
66+
return;
67+
}
68+
69+
// on rename delete original entry first
5870
if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
5971
{
6072
settings.remove( mBaseKey + mOriginalConnName );
6173
settings.remove( "/Qgis/WMS/" + mOriginalConnName );
6274
}
75+
6376
settings.setValue( key + "/url", txtUrl->text().trimmed() );
6477
settings.setValue( credentialsKey + "/username", txtUserName->text() );
6578
settings.setValue( credentialsKey + "/password", txtPassword->text() );

0 commit comments

Comments
 (0)
Please sign in to comment.