46
46
#include " qgsproperty.h"
47
47
#include " qgslayertree.h"
48
48
#include " qgsguiutils.h"
49
+ #include " qgsfilewidget.h"
49
50
50
51
QgsDwgImportDialog::QgsDwgImportDialog ( QWidget *parent, Qt::WindowFlags f )
51
52
: QDialog( parent, f )
52
53
{
53
54
setupUi ( this );
54
55
connect ( buttonBox, &QDialogButtonBox::accepted, this , &QgsDwgImportDialog::buttonBox_accepted );
55
- connect ( pbBrowseDatabase , &QPushButton::clicked , this , &QgsDwgImportDialog::pbBrowseDatabase_clicked );
56
+ connect ( mDatabaseFileWidget , &QgsFileWidget::fileChanged , this , &QgsDwgImportDialog::mDatabaseFileWidget_textChanged );
56
57
connect ( pbBrowseDrawing, &QPushButton::clicked, this , &QgsDwgImportDialog::pbBrowseDrawing_clicked );
57
58
connect ( pbImportDrawing, &QPushButton::clicked, this , &QgsDwgImportDialog::pbImportDrawing_clicked );
58
59
connect ( pbLoadDatabase, &QPushButton::clicked, this , &QgsDwgImportDialog::pbLoadDatabase_clicked );
59
60
connect ( pbSelectAll, &QPushButton::clicked, this , &QgsDwgImportDialog::pbSelectAll_clicked );
60
61
connect ( pbDeselectAll, &QPushButton::clicked, this , &QgsDwgImportDialog::pbDeselectAll_clicked );
61
- connect ( leDatabase, &QLineEdit::textChanged, this , &QgsDwgImportDialog::leDatabase_textChanged );
62
62
connect ( leLayerGroup, &QLineEdit::textChanged, this , &QgsDwgImportDialog::leLayerGroup_textChanged );
63
63
connect ( buttonBox, &QDialogButtonBox::helpRequested, this , &QgsDwgImportDialog::showHelp );
64
64
65
65
QgsSettings s;
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 () );
69
+ mDatabaseFileWidget ->setDefaultRoot ( s.value ( QStringLiteral ( " /DwgImport/lastDirDatabase" ), QDir::homePath () ).toString () );
69
70
70
71
leDrawing->setReadOnly ( true );
71
72
pbImportDrawing->setHidden ( true );
@@ -100,9 +101,9 @@ void QgsDwgImportDialog::updateUI()
100
101
bool dbReadable = false ;
101
102
bool dwgReadable = false ;
102
103
103
- if ( !leDatabase-> text ().isEmpty () )
104
+ if ( !mDatabaseFileWidget -> filePath ().isEmpty () )
104
105
{
105
- QFileInfo fi ( leDatabase-> text () );
106
+ QFileInfo fi ( mDatabaseFileWidget -> filePath () );
106
107
dbAvailable = fi.exists () ? fi.isWritable () : QFileInfo ( fi.path () ).isWritable ();
107
108
dbReadable = fi.exists () && fi.isReadable ();
108
109
}
@@ -121,39 +122,10 @@ void QgsDwgImportDialog::updateUI()
121
122
buttonBox->button ( QDialogButtonBox::Ok )->setEnabled ( mLayers ->rowCount () > 0 && !leLayerGroup->text ().isEmpty () );
122
123
}
123
124
124
- void QgsDwgImportDialog::pbBrowseDatabase_clicked ( )
125
+ void QgsDwgImportDialog::mDatabaseFileWidget_textChanged ( const QString &filename )
125
126
{
126
127
QgsSettings s;
127
- QString dir ( s.value ( QStringLiteral ( " /DwgImport/lastDirDatabase" ), QDir::homePath () ).toString () );
128
- QString filename = QFileDialog::getSaveFileName ( this , tr ( " Specify GeoPackage database" ), dir, tr ( " GeoPackage database" ) + " (*.gpkg *.GPKG)" , nullptr , QFileDialog::DontConfirmOverwrite );
129
- if ( filename.isEmpty () )
130
- return ;
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
-
151
- updateUI ();
152
- }
153
-
154
- void QgsDwgImportDialog::leDatabase_textChanged ( const QString &text )
155
- {
156
- Q_UNUSED ( text );
128
+ s.setValue ( QStringLiteral ( " /DwgImport/lastDirDatabase" ), QFileInfo ( filename ).canonicalPath () );
157
129
updateUI ();
158
130
}
159
131
@@ -165,7 +137,7 @@ void QgsDwgImportDialog::leLayerGroup_textChanged( const QString &text )
165
137
166
138
void QgsDwgImportDialog::pbLoadDatabase_clicked ()
167
139
{
168
- if ( !QFileInfo::exists ( leDatabase-> text () ) )
140
+ if ( !QFileInfo::exists ( mDatabaseFileWidget -> filePath () ) )
169
141
return ;
170
142
171
143
QgsTemporaryCursorOverride waitCursor ( Qt::BusyCursor );
@@ -174,7 +146,7 @@ void QgsDwgImportDialog::pbLoadDatabase_clicked()
174
146
175
147
QgsVectorLayer::LayerOptions options;
176
148
options.loadDefaultStyle = false ;
177
- std::unique_ptr<QgsVectorLayer> d ( new QgsVectorLayer ( QStringLiteral ( " %1|layername=drawing" ).arg ( leDatabase-> text () ), QStringLiteral ( " layers" ), QStringLiteral ( " ogr" ), options ) );
149
+ std::unique_ptr<QgsVectorLayer> d ( new QgsVectorLayer ( QStringLiteral ( " %1|layername=drawing" ).arg ( mDatabaseFileWidget -> filePath () ), QStringLiteral ( " layers" ), QStringLiteral ( " ogr" ), options ) );
178
150
if ( d && d->isValid () )
179
151
{
180
152
int idxPath = d->fields ().lookupField ( QStringLiteral ( " path" ) );
@@ -209,7 +181,7 @@ void QgsDwgImportDialog::pbLoadDatabase_clicked()
209
181
210
182
lblMessage->setVisible ( lblVisible );
211
183
212
- std::unique_ptr<QgsVectorLayer> l ( new QgsVectorLayer ( QStringLiteral ( " %1|layername=layers" ).arg ( leDatabase-> text () ), QStringLiteral ( " layers" ), QStringLiteral ( " ogr" ), options ) );
184
+ std::unique_ptr<QgsVectorLayer> l ( new QgsVectorLayer ( QStringLiteral ( " %1|layername=layers" ).arg ( mDatabaseFileWidget -> filePath () ), QStringLiteral ( " layers" ), QStringLiteral ( " ogr" ), options ) );
213
185
if ( l && l->isValid () )
214
186
{
215
187
int idxName = l->fields ().lookupField ( QStringLiteral ( " name" ) );
@@ -268,7 +240,7 @@ void QgsDwgImportDialog::pbImportDrawing_clicked()
268
240
{
269
241
QgsTemporaryCursorOverride waitCursor ( Qt::BusyCursor );
270
242
271
- QgsDwgImporter importer ( leDatabase-> text (), mCrsSelector ->crs () );
243
+ QgsDwgImporter importer ( mDatabaseFileWidget -> filePath (), mCrsSelector ->crs () );
272
244
273
245
QString error;
274
246
if ( importer.import ( leDrawing->text (), error, cbExpandInserts->isChecked (), cbUseCurves->isChecked () ) )
@@ -287,7 +259,7 @@ QgsVectorLayer *QgsDwgImportDialog::layer( QgsLayerTreeGroup *layerGroup, const
287
259
{
288
260
QgsVectorLayer::LayerOptions options;
289
261
options.loadDefaultStyle = false ;
290
- QgsVectorLayer *l = new QgsVectorLayer ( QStringLiteral ( " %1|layername=%2" ).arg ( leDatabase-> text (), table ), table, QStringLiteral ( " ogr" ), options );
262
+ QgsVectorLayer *l = new QgsVectorLayer ( QStringLiteral ( " %1|layername=%2" ).arg ( mDatabaseFileWidget -> filePath (), table ), table, QStringLiteral ( " ogr" ), options );
291
263
l->setSubsetString ( QStringLiteral ( " %1space=0 AND block=-1" ).arg ( layerFilter ) );
292
264
293
265
if ( l->featureCount () == 0 )
0 commit comments