20
20
#include < QDialogButtonBox>
21
21
#include < QFileInfo>
22
22
#include < QFileDialog>
23
+ #include < QMessageBox>
23
24
24
25
#include " qgssettings.h"
25
26
#include " qgisapp.h"
@@ -62,7 +63,6 @@ QgsDwgImportDialog::QgsDwgImportDialog( QWidget *parent, Qt::WindowFlags f )
62
63
connect ( buttonBox, &QDialogButtonBox::helpRequested, this , &QgsDwgImportDialog::showHelp );
63
64
64
65
QgsSettings s;
65
- leDatabase->setText ( s.value ( QStringLiteral ( " /DwgImport/lastDatabase" ), " " ).toString () );
66
66
cbExpandInserts->setChecked ( s.value ( QStringLiteral ( " /DwgImport/lastExpandInserts" ), true ).toBool () );
67
67
cbMergeLayers->setChecked ( s.value ( QStringLiteral ( " /DwgImport/lastMergeLayers" ), false ).toBool () );
68
68
cbUseCurves->setChecked ( s.value ( QStringLiteral ( " /DwgImport/lastUseCurves" ), true ).toBool () );
@@ -88,7 +88,6 @@ QgsDwgImportDialog::QgsDwgImportDialog( QWidget *parent, Qt::WindowFlags f )
88
88
QgsDwgImportDialog::~QgsDwgImportDialog ()
89
89
{
90
90
QgsSettings s;
91
- s.setValue ( QStringLiteral ( " /DwgImport/lastDatabase" ), leDatabase->text () );
92
91
s.setValue ( QStringLiteral ( " /DwgImport/lastExpandInserts" ), cbExpandInserts->isChecked () );
93
92
s.setValue ( QStringLiteral ( " /DwgImport/lastMergeLayers" ), cbMergeLayers->isChecked () );
94
93
s.setValue ( QStringLiteral ( " /DwgImport/lastUseCurves" ), cbUseCurves->isChecked () );
@@ -124,11 +123,31 @@ void QgsDwgImportDialog::updateUI()
124
123
125
124
void QgsDwgImportDialog::pbBrowseDatabase_clicked ()
126
125
{
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 () );
128
128
QString filename = QFileDialog::getSaveFileName ( this , tr ( " Specify GeoPackage database" ), dir, tr ( " GeoPackage database" ) + " (*.gpkg *.GPKG)" , nullptr , QFileDialog::DontConfirmOverwrite );
129
129
if ( filename.isEmpty () )
130
130
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
+
132
151
updateUI ();
133
152
}
134
153
0 commit comments