Skip to content
Permalink
Browse files

Allow appending layers to existing spatialite in its create layer dialog

  • Loading branch information
nirvn committed Dec 8, 2017
1 parent 11c1f3a commit 1ea83e227f82f9fa7b2ca96559563ff67093eeda
Showing with 25 additions and 3 deletions.
  1. +25 −3 src/app/qgsnewspatialitelayerdialog.cpp
@@ -126,7 +126,7 @@ void QgsNewSpatialiteLayerDialog::toolButtonNewDatabase_clicked()
{
QString fileName = QFileDialog::getSaveFileName( this, tr( "New SpatiaLite Database File" ),
QDir::homePath(),
tr( "SpatiaLite" ) + " (*.sqlite *.db *.sqlite3 *.db3 *.s3db)" );
tr( "SpatiaLite" ) + " (*.sqlite *.db *.sqlite3 *.db3 *.s3db)", nullptr, QFileDialog::DontConfirmOverwrite );

if ( fileName.isEmpty() )
return;
@@ -138,6 +138,7 @@ void QgsNewSpatialiteLayerDialog::toolButtonNewDatabase_clicked()

mDatabaseComboBox->insertItem( 0, fileName );
mDatabaseComboBox->setCurrentIndex( 0 );

createDb();
}

@@ -149,8 +150,7 @@ QString QgsNewSpatialiteLayerDialog::selectedType() const
void QgsNewSpatialiteLayerDialog::checkOk()
{
bool created = !leLayerName->text().isEmpty() &&
( checkBoxPrimaryKey->isChecked() || mAttributeView->topLevelItemCount() > 0 ) &&
createDb();
( checkBoxPrimaryKey->isChecked() || mAttributeView->topLevelItemCount() > 0 );
mOkButton->setEnabled( created );
}

@@ -251,6 +251,28 @@ bool QgsNewSpatialiteLayerDialog::createDb()
return false;

QFile newDb( dbPath );
if ( newDb.exists() )
{
QMessageBox msgBox;
msgBox.setIcon( QMessageBox::Question );
msgBox.setWindowTitle( tr( "The File Already Exists." ) );
msgBox.setText( tr( "Do you want to overwrite the existing file with a new database or add a new layer to it?" ) );
QPushButton *overwriteButton = msgBox.addButton( tr( "Overwrite" ), QMessageBox::ActionRole );
QPushButton *addNewLayerButton = msgBox.addButton( tr( "Add new layer" ), QMessageBox::ActionRole );
msgBox.setStandardButtons( QMessageBox::Cancel );
msgBox.setDefaultButton( addNewLayerButton );
int ret = msgBox.exec();
if ( ret == QMessageBox::Cancel )
{
return false;
}

if ( msgBox.clickedButton() == overwriteButton )
{
newDb.remove();
}
}

if ( !newDb.exists() )
{
QString errCause;

2 comments on commit 1ea83e2

@nirvn

This comment has been minimized.

Copy link
Contributor Author

@nirvn nirvn replied Dec 8, 2017

@elpaso , is there a way to trigger a connection change signal here for the browser panel to refresh the available connections under the spatialite node?

@elpaso

This comment has been minimized.

Copy link
Contributor

@elpaso elpaso replied Dec 8, 2017

I think that the best way to do it is to make a connection (in the caller scope) to QgisApp::connectionsChanged that would take care of updating the browser (and possibly/eventually update other parts of te UI).

Please sign in to comment.
You can’t perform that action at this time.