|
31 | 31 |
|
32 | 32 |
|
33 | 33 | QgsNewOgrConnection::QgsNewOgrConnection( QWidget *parent, const QString& connType, const QString& connName, Qt::WFlags fl )
|
34 |
| - : QDialog( parent, fl ) |
| 34 | + : QDialog( parent, fl ), |
| 35 | + mOriginalConnName( connName ) |
35 | 36 | {
|
36 | 37 | setupUi( this );
|
37 | 38 |
|
@@ -94,24 +95,38 @@ void QgsNewOgrConnection::testConnection()
|
94 | 95 | }
|
95 | 96 | }
|
96 | 97 |
|
97 |
| -void QgsNewOgrConnection::saveConnection() |
| 98 | +/** Autoconnected SLOTS **/ |
| 99 | +void QgsNewOgrConnection::accept() |
98 | 100 | {
|
99 | 101 | QSettings settings;
|
100 | 102 | QString baseKey = "/" + cmbDatabaseTypes->currentText() + "/connections/";
|
101 | 103 | settings.setValue( baseKey + "selected", txtName->text() );
|
| 104 | + |
| 105 | + // warn if entry was renamed to an existing connection |
| 106 | + if (( mOriginalConnName.isNull() || mOriginalConnName != txtName->text() ) && |
| 107 | + settings.contains( baseKey + txtName->text() + "/host" ) && |
| 108 | + QMessageBox::question( this, |
| 109 | + tr( "Save connection" ), |
| 110 | + tr( "Should the existing connection %1 be overwritten?" ).arg( txtName->text() ), |
| 111 | + QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel ) |
| 112 | + { |
| 113 | + return; |
| 114 | + } |
| 115 | + |
| 116 | + // on rename delete original entry first |
| 117 | + if ( !mOriginalConnName.isNull() && mOriginalConnName != txtName->text() ) |
| 118 | + { |
| 119 | + settings.remove( baseKey + mOriginalConnName ); |
| 120 | + } |
| 121 | + |
102 | 122 | baseKey += txtName->text();
|
103 | 123 | settings.setValue( baseKey + "/host", txtHost->text() );
|
104 | 124 | settings.setValue( baseKey + "/database", txtDatabase->text() );
|
105 | 125 | settings.setValue( baseKey + "/port", txtPort->text() );
|
106 | 126 | settings.setValue( baseKey + "/username", txtUsername->text() );
|
107 | 127 | settings.setValue( baseKey + "/password", chkStorePassword->isChecked() ? txtPassword->text() : "" );
|
108 | 128 | settings.setValue( baseKey + "/save", chkStorePassword->isChecked() ? "true" : "false" );
|
109 |
| -} |
110 | 129 |
|
111 |
| -/** Autoconnected SLOTS **/ |
112 |
| -void QgsNewOgrConnection::accept() |
113 |
| -{ |
114 |
| - saveConnection(); |
115 | 130 | QDialog::accept();
|
116 | 131 | }
|
117 | 132 |
|
|
0 commit comments