@@ -48,14 +48,15 @@ QgsPgNewConnection::QgsPgNewConnection( QWidget *parent, const QString& connName
48
48
QSettings settings;
49
49
50
50
QString key = " /PostgreSQL/connections/" + connName;
51
+ txtService->setText ( settings.value ( key + " /service" ).toString () );
51
52
txtHost->setText ( settings.value ( key + " /host" ).toString () );
52
- txtDatabase->setText ( settings.value ( key + " /database" ).toString () );
53
53
QString port = settings.value ( key + " /port" ).toString ();
54
54
if ( port.length () == 0 )
55
55
{
56
56
port = " 5432" ;
57
57
}
58
58
txtPort->setText ( port );
59
+ txtDatabase->setText ( settings.value ( key + " /database" ).toString () );
59
60
cb_publicSchemaOnly->setChecked ( settings.value ( key + " /publicOnly" , false ).toBool () );
60
61
cb_geometryColumnsOnly->setChecked ( settings.value ( key + " /geometrycolumnsOnly" , false ).toBool () );
61
62
cb_allowGeometrylessTables->setChecked ( settings.value ( key + " /allowGeometrylessTables" , false ).toBool () );
@@ -102,7 +103,8 @@ void QgsPgNewConnection::accept()
102
103
103
104
// warn if entry was renamed to an existing connection
104
105
if (( mOriginalConnName .isNull () || mOriginalConnName != txtName->text () ) &&
105
- settings.contains ( baseKey + txtName->text () + " /host" ) &&
106
+ ( settings.contains ( baseKey + txtName->text () + " /service" ) ||
107
+ settings.contains ( baseKey + txtName->text () + " /host" ) ) &&
106
108
QMessageBox::question ( this ,
107
109
tr ( " Save connection" ),
108
110
tr ( " Should the existing connection %1 be overwritten?" ).arg ( txtName->text () ),
@@ -119,9 +121,10 @@ void QgsPgNewConnection::accept()
119
121
}
120
122
121
123
baseKey += txtName->text ();
124
+ settings.setValue ( baseKey + " /service" , txtService->text () );
122
125
settings.setValue ( baseKey + " /host" , txtHost->text () );
123
- settings.setValue ( baseKey + " /database" , txtDatabase->text () );
124
126
settings.setValue ( baseKey + " /port" , txtPort->text () );
127
+ settings.setValue ( baseKey + " /database" , txtDatabase->text () );
125
128
settings.setValue ( baseKey + " /username" , chkStoreUsername->isChecked () ? txtUsername->text () : " " );
126
129
settings.setValue ( baseKey + " /password" , chkStorePassword->isChecked () ? txtPassword->text () : " " );
127
130
settings.setValue ( baseKey + " /publicOnly" , cb_publicSchemaOnly->isChecked () );
@@ -160,9 +163,18 @@ QgsPgNewConnection::~QgsPgNewConnection()
160
163
void QgsPgNewConnection::testConnection ()
161
164
{
162
165
QgsDataSourceURI uri;
163
- uri.setConnection ( txtHost->text (), txtPort->text (), txtDatabase->text (),
164
- txtUsername->text (), txtPassword->text (),
165
- ( QgsDataSourceURI::SSLmode ) cbxSSLmode->itemData ( cbxSSLmode->currentIndex () ).toInt () );
166
+ if ( !txtService->text ().isEmpty () )
167
+ {
168
+ uri.setConnection ( txtService->text (), txtDatabase->text (),
169
+ txtUsername->text (), txtPassword->text (),
170
+ ( QgsDataSourceURI::SSLmode ) cbxSSLmode->itemData ( cbxSSLmode->currentIndex () ).toInt () );
171
+ }
172
+ else
173
+ {
174
+ uri.setConnection ( txtHost->text (), txtPort->text (), txtDatabase->text (),
175
+ txtUsername->text (), txtPassword->text (),
176
+ ( QgsDataSourceURI::SSLmode ) cbxSSLmode->itemData ( cbxSSLmode->currentIndex () ).toInt () );
177
+ }
166
178
QString conninfo = uri.connectionInfo ();
167
179
QgsDebugMsg ( " PQconnectdb(\" " + conninfo + " \" );" );
168
180
0 commit comments