Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2443 from elpaso/bugfix-11794
SQLITE ask for a new name if already exists
  • Loading branch information
elpaso committed Nov 12, 2015
2 parents be8c7da + 325f099 commit 854ce17
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/providers/spatialite/qgsspatialitesourceselect.cpp
Expand Up @@ -281,6 +281,7 @@ bool QgsSpatiaLiteSourceSelect::newConnection( QWidget* parent )
QFileInfo myFI( myFile );
QString myPath = myFI.path();
QString myName = myFI.fileName();
QString savedName = myFI.fileName();
QString baseKey = "/SpatiaLite/connections/";

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

// if there is already a connection with this name, warn user (#9404) and do nothing
// ideally, user should be able to change item name so that several sqlite files with same name can co-exist
if ( ! settings.value( baseKey + myName + "/sqlitepath", "" ).toString().isEmpty() )
// if there is already a connection with this name, ask for a new name
while ( ! settings.value( baseKey + savedName + "/sqlitepath", "" ).toString().isEmpty() )
{
QMessageBox::critical( parent, tr( "Error" ), tr( "Cannot add connection '%1' : a connection with the same name already exists." ).arg( myName ) );
return false;
bool ok;
savedName = QInputDialog::getText( NULL , tr( "Cannot add connection '%1'" ).arg( myName ) ,
tr( "A connection with the same name already exists,\nplease provide a new name:" ), QLineEdit::Normal,
"", &ok );
if ( !ok || savedName.isEmpty() )
{
return false;
}
}

// Persist last used SpatiaLite dir
settings.setValue( "/UI/lastSpatiaLiteDir", myPath );
// inserting this SQLite DB path
settings.setValue( baseKey + "selected", myName );
settings.setValue( baseKey + myName + "/sqlitepath", myFI.canonicalFilePath() );
settings.setValue( baseKey + "selected", savedName );
settings.setValue( baseKey + savedName + "/sqlitepath", myFI.canonicalFilePath() );
return true;
}

Expand Down

0 comments on commit 854ce17

Please sign in to comment.