Skip to content

Commit 854ce17

Browse files
committed
Merge pull request #2443 from elpaso/bugfix-11794
SQLITE ask for a new name if already exists
2 parents be8c7da + 325f099 commit 854ce17

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/providers/spatialite/qgsspatialitesourceselect.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ bool QgsSpatiaLiteSourceSelect::newConnection( QWidget* parent )
281281
QFileInfo myFI( myFile );
282282
QString myPath = myFI.path();
283283
QString myName = myFI.fileName();
284+
QString savedName = myFI.fileName();
284285
QString baseKey = "/SpatiaLite/connections/";
285286

286287
// TODO: keep the test
@@ -290,19 +291,24 @@ bool QgsSpatiaLiteSourceSelect::newConnection( QWidget* parent )
290291
// OK, this one is a valid SpatiaLite DB
291292
//closeSpatiaLiteDb( handle );
292293

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() )
296296
{
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,\nplease provide a new name:" ), QLineEdit::Normal,
300+
"", &ok );
301+
if ( !ok || savedName.isEmpty() )
302+
{
303+
return false;
304+
}
299305
}
300306

301307
// Persist last used SpatiaLite dir
302308
settings.setValue( "/UI/lastSpatiaLiteDir", myPath );
303309
// 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() );
306312
return true;
307313
}
308314

0 commit comments

Comments
 (0)