@@ -281,6 +281,7 @@ bool QgsSpatiaLiteSourceSelect::newConnection( QWidget* parent )
281
281
QFileInfo myFI ( myFile );
282
282
QString myPath = myFI.path ();
283
283
QString myName = myFI.fileName ();
284
+ QString savedName = myFI.fileName ();
284
285
QString baseKey = " /SpatiaLite/connections/" ;
285
286
286
287
// TODO: keep the test
@@ -290,19 +291,24 @@ bool QgsSpatiaLiteSourceSelect::newConnection( QWidget* parent )
290
291
// OK, this one is a valid SpatiaLite DB
291
292
// closeSpatiaLiteDb( handle );
292
293
293
- // if there is already a connection with this name, warn user (#9404) and do nothing
294
- // ideally, user should be able to change item name so that several sqlite files with same name can co-exist
295
- if ( ! settings.value ( baseKey + myName + " /sqlitepath" , " " ).toString ().isEmpty () )
294
+ // if there is already a connection with this name, ask for a new name
295
+ while ( ! settings.value ( baseKey + savedName + " /sqlitepath" , " " ).toString ().isEmpty () )
296
296
{
297
- QMessageBox::critical ( parent, tr ( " Error" ), tr ( " Cannot add connection '%1' : a connection with the same name already exists." ).arg ( myName ) );
298
- return false ;
297
+ bool ok;
298
+ savedName = QInputDialog::getText ( NULL , tr ( " Cannot add connection '%1'" ).arg ( myName ) ,
299
+ tr ( " A connection with the same name already exists,\n please provide a new name:" ), QLineEdit::Normal,
300
+ " " , &ok );
301
+ if ( !ok || savedName.isEmpty () )
302
+ {
303
+ return false ;
304
+ }
299
305
}
300
306
301
307
// Persist last used SpatiaLite dir
302
308
settings.setValue ( " /UI/lastSpatiaLiteDir" , myPath );
303
309
// inserting this SQLite DB path
304
- settings.setValue ( baseKey + " selected" , myName );
305
- settings.setValue ( baseKey + myName + " /sqlitepath" , myFI.canonicalFilePath () );
310
+ settings.setValue ( baseKey + " selected" , savedName );
311
+ settings.setValue ( baseKey + savedName + " /sqlitepath" , myFI.canonicalFilePath () );
306
312
return true ;
307
313
}
308
314
0 commit comments