17
17
18
18
#include " qgsnewvectorlayerdialog.h"
19
19
#include " qgsapplication.h"
20
+ #include " qgsfilewidget.h"
20
21
#include " qgis.h"
21
22
#include " qgslogger.h"
22
23
#include " qgscoordinatereferencesystem.h"
@@ -35,10 +36,9 @@ QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WindowFla
35
36
: QDialog( parent, fl )
36
37
{
37
38
setupUi ( this );
39
+
38
40
connect ( mAddAttributeButton , &QToolButton::clicked, this , &QgsNewVectorLayerDialog::mAddAttributeButton_clicked );
39
41
connect ( mRemoveAttributeButton , &QToolButton::clicked, this , &QgsNewVectorLayerDialog::mRemoveAttributeButton_clicked );
40
- connect ( mFileNameEdit , &QLineEdit::textChanged, this , &QgsNewVectorLayerDialog::checkOk );
41
- connect ( mBrowseFileName , &QToolButton::clicked, this , &QgsNewVectorLayerDialog::selectFileName );
42
42
connect ( mFileFormatComboBox , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , &QgsNewVectorLayerDialog::mFileFormatComboBox_currentIndexChanged );
43
43
connect ( mTypeBox , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , &QgsNewVectorLayerDialog::mTypeBox_currentIndexChanged );
44
44
connect ( buttonBox, &QDialogButtonBox::helpRequested, this , &QgsNewVectorLayerDialog::showHelp );
@@ -100,6 +100,18 @@ QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WindowFla
100
100
101
101
mAddAttributeButton ->setEnabled ( false );
102
102
mRemoveAttributeButton ->setEnabled ( false );
103
+
104
+ mFileName ->setStorageMode ( QgsFileWidget::SaveFile );
105
+ mFileName ->setFilter ( QgsVectorFileWriter::filterForDriver ( mFileFormatComboBox ->currentData ( Qt::UserRole ).toString () ) );
106
+ mFileName ->setDialogTitle ( tr ( " Select Layer as..." ) );
107
+ mFileName ->setDefaultRoot ( settings.value ( QStringLiteral ( " UI/lastVectorFileFilterDir" ), QDir::homePath () ).toString () );
108
+ connect ( mFileName , &QgsFileWidget::fileChanged, this , [ = ]
109
+ {
110
+ QgsSettings settings;
111
+ QFileInfo tmplFileInfo ( mFileName ->filePath () );
112
+ settings.setValue ( QStringLiteral ( " UI/lastVectorFileFilterDir" ), tmplFileInfo.absolutePath () );
113
+ checkOk ();
114
+ } );
103
115
}
104
116
105
117
QgsNewVectorLayerDialog::~QgsNewVectorLayerDialog ()
@@ -224,29 +236,14 @@ void QgsNewVectorLayerDialog::selectionChanged()
224
236
mRemoveAttributeButton ->setDisabled ( mAttributeView ->selectedItems ().isEmpty () );
225
237
}
226
238
227
- void QgsNewVectorLayerDialog::selectFileName ()
228
- {
229
- QString fileformat = mFileFormatComboBox ->currentData ( Qt::UserRole ).toString ();
230
- QgsSettings settings;
231
- QString lastUsedDir = settings.value ( QStringLiteral ( " UI/lastVectorFileFilterDir" ), QDir::homePath () ).toString ();
232
- QString filterString = QgsVectorFileWriter::filterForDriver ( fileformat );
233
- QString fileName = QFileDialog::getSaveFileName ( nullptr , tr ( " Save Layer as..." ), lastUsedDir, filterString );
234
- if ( fileName.isEmpty () )
235
- return ;
236
-
237
- if ( fileformat == QLatin1String ( " ESRI Shapefile" ) && !fileName.endsWith ( QLatin1String ( " .shp" ), Qt::CaseInsensitive ) )
238
- fileName += QLatin1String ( " .shp" );
239
- mFileNameEdit ->setText ( fileName );
240
- }
241
-
242
239
QString QgsNewVectorLayerDialog::filename () const
243
240
{
244
- return mFileNameEdit -> text ();
241
+ return mFileName -> filePath ();
245
242
}
246
243
247
244
void QgsNewVectorLayerDialog::checkOk ()
248
245
{
249
- bool ok = ( !mFileNameEdit -> text ().isEmpty () && mAttributeView ->topLevelItemCount () > 0 );
246
+ bool ok = ( !mFileName -> filePath ().isEmpty () && mAttributeView ->topLevelItemCount () > 0 );
250
247
mOkButton ->setEnabled ( ok );
251
248
}
252
249
@@ -271,6 +268,8 @@ QString QgsNewVectorLayerDialog::runAndCreateLayer( QWidget *parent, QString *pE
271
268
QgsSettings settings;
272
269
QString filterString = QgsVectorFileWriter::filterForDriver ( fileformat );
273
270
QString fileName = geomDialog.filename ();
271
+ if ( fileformat == QLatin1String ( " ESRI Shapefile" ) && !fileName.endsWith ( QLatin1String ( " .shp" ), Qt::CaseInsensitive ) )
272
+ fileName += QLatin1String ( " .shp" );
274
273
275
274
settings.setValue ( QStringLiteral ( " UI/lastVectorFileFilterDir" ), QFileInfo ( fileName ).absolutePath () );
276
275
settings.setValue ( QStringLiteral ( " UI/encoding" ), enc );
0 commit comments