Skip to content

Commit

Permalink
Allow appending layers to existing spatialite in its create layer dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Dec 8, 2017
1 parent 11c1f3a commit 1ea83e2
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/app/qgsnewspatialitelayerdialog.cpp
Expand Up @@ -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;
Expand All @@ -138,6 +138,7 @@ void QgsNewSpatialiteLayerDialog::toolButtonNewDatabase_clicked()

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

createDb();
}

Expand All @@ -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 );
}

Expand Down Expand Up @@ -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;
Expand Down

2 comments on commit 1ea83e2

@nirvn
Copy link
Contributor Author

@nirvn nirvn commented on 1ea83e2 Dec 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Contributor

@elpaso elpaso commented on 1ea83e2 Dec 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.