2020#include < QDialogButtonBox>
2121#include < QFileInfo>
2222#include < QFileDialog>
23+ #include < QMessageBox>
2324
2425#include " qgssettings.h"
2526#include " qgisapp.h"
@@ -62,7 +63,6 @@ QgsDwgImportDialog::QgsDwgImportDialog( QWidget *parent, Qt::WindowFlags f )
6263 connect ( buttonBox, &QDialogButtonBox::helpRequested, this , &QgsDwgImportDialog::showHelp );
6364
6465 QgsSettings s;
65- leDatabase->setText ( s.value ( QStringLiteral ( " /DwgImport/lastDatabase" ), " " ).toString () );
6666 cbExpandInserts->setChecked ( s.value ( QStringLiteral ( " /DwgImport/lastExpandInserts" ), true ).toBool () );
6767 cbMergeLayers->setChecked ( s.value ( QStringLiteral ( " /DwgImport/lastMergeLayers" ), false ).toBool () );
6868 cbUseCurves->setChecked ( s.value ( QStringLiteral ( " /DwgImport/lastUseCurves" ), true ).toBool () );
@@ -88,7 +88,6 @@ QgsDwgImportDialog::QgsDwgImportDialog( QWidget *parent, Qt::WindowFlags f )
8888QgsDwgImportDialog::~QgsDwgImportDialog ()
8989{
9090 QgsSettings s;
91- s.setValue ( QStringLiteral ( " /DwgImport/lastDatabase" ), leDatabase->text () );
9291 s.setValue ( QStringLiteral ( " /DwgImport/lastExpandInserts" ), cbExpandInserts->isChecked () );
9392 s.setValue ( QStringLiteral ( " /DwgImport/lastMergeLayers" ), cbMergeLayers->isChecked () );
9493 s.setValue ( QStringLiteral ( " /DwgImport/lastUseCurves" ), cbUseCurves->isChecked () );
@@ -124,11 +123,31 @@ void QgsDwgImportDialog::updateUI()
124123
125124void QgsDwgImportDialog::pbBrowseDatabase_clicked ()
126125{
127- QString dir ( leDatabase->text ().isEmpty () ? QDir::homePath () : QFileInfo ( leDatabase->text () ).canonicalPath () );
126+ QgsSettings s;
127+ QString dir ( s.value ( QStringLiteral ( " /DwgImport/lastDirDatabase" ), QDir::homePath () ).toString () );
128128 QString filename = QFileDialog::getSaveFileName ( this , tr ( " Specify GeoPackage database" ), dir, tr ( " GeoPackage database" ) + " (*.gpkg *.GPKG)" , nullptr , QFileDialog::DontConfirmOverwrite );
129129 if ( filename.isEmpty () )
130130 return ;
131- leDatabase->setText ( filename );
131+
132+ QFileInfo fi ( filename );
133+ if ( fi.exists () && ( QMessageBox::question ( this ,
134+ tr ( " File exists" ),
135+ tr ( " The file already exists. Do you want to overwrite the existing file?" ),
136+ QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel ) )
137+ {
138+ leDatabase->clear ();
139+ return ;
140+ }
141+ else
142+ {
143+
144+ if ( !( filename.endsWith ( " .gpkg" ) || filename.endsWith ( " .GPKG" ) ) )
145+ filename.append ( " .gpkg" );
146+
147+ leDatabase->setText ( filename );
148+ s.setValue ( QStringLiteral ( " /DwgImport/lastDirDatabase" ), QFileInfo ( filename ).canonicalPath () );
149+ }
150+
132151 updateUI ();
133152}
134153
0 commit comments