@@ -73,8 +73,6 @@ void QgsVectorLayerSaveAsDialog::setup()
7373{
7474 setupUi ( this );
7575 connect ( mFormatComboBox , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , &QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
76- connect ( leFilename, &QLineEdit::textChanged, this , &QgsVectorLayerSaveAsDialog::leFilename_textChanged );
77- connect ( browseFilename, &QPushButton::clicked, this , &QgsVectorLayerSaveAsDialog::browseFilename_clicked );
7876 connect ( mCrsSelector , &QgsProjectionSelectionWidget::crsChanged, this , &QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged );
7977 connect ( mSymbologyExportComboBox , static_cast <void ( QComboBox::* )( const QString & )>( &QComboBox::currentIndexChanged ), this , &QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged );
8078 connect ( mGeometryTypeComboBox , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , &QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged );
@@ -139,6 +137,24 @@ void QgsVectorLayerSaveAsDialog::setup()
139137 mExtentGroupBox ->setCheckable ( true );
140138 mExtentGroupBox ->setChecked ( false );
141139 mExtentGroupBox ->setCollapsed ( true );
140+
141+ mFilename ->setStorageMode ( QgsFileWidget::SaveFile );
142+ mFilename ->setDialogTitle ( tr ( " Select layer as..." ) );
143+ mFilename ->setDefaultRoot ( settings.value ( QStringLiteral ( " UI/lastVectorFileFilterDir" ), QDir::homePath () ).toString () );
144+ mFilename ->setConfirmOverwrite ( false );
145+ connect ( mFilename , &QgsFileWidget::fileChanged, this , [ = ]( const QString & filePath )
146+ {
147+ QgsSettings settings;
148+ QFileInfo tmplFileInfo ( filePath );
149+ settings.setValue ( QStringLiteral ( " UI/lastVectorFileFilterDir" ), tmplFileInfo.absolutePath () );
150+ if ( !filePath.isEmpty () && leLayername->isEnabled () )
151+ {
152+ QFileInfo fileInfo ( filePath );
153+ leLayername->setText ( fileInfo.baseName () );
154+ }
155+ buttonBox->button ( QDialogButtonBox::Ok )->setEnabled (
156+ !filePath.isEmpty () && QFileInfo ( filePath ).absoluteDir ().exists () );
157+ } );
142158}
143159
144160QList<QPair<QLabel *, QWidget *> > QgsVectorLayerSaveAsDialog::createControls ( const QMap<QString, QgsVectorFileWriter::Option *> &options )
@@ -352,8 +368,9 @@ void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
352368{
353369 Q_UNUSED ( idx );
354370
355- browseFilename->setEnabled ( true );
356- leFilename->setEnabled ( true );
371+ mFilename ->setEnabled ( true );
372+ mFilename ->setFilter ( QgsVectorFileWriter::filterForDriver ( format () ) );
373+
357374 bool selectAllFields = true ;
358375 bool fieldsAsDisplayedValues = false ;
359376
@@ -379,9 +396,9 @@ void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
379396 if ( !leLayername->isEnabled () )
380397 leLayername->setText ( QString () );
381398 else if ( leLayername->text ().isEmpty () &&
382- !leFilename-> text ().isEmpty () )
399+ !mFilename -> filePath ().isEmpty () )
383400 {
384- QString layerName = QFileInfo ( leFilename-> text () ).baseName ();
401+ QString layerName = QFileInfo ( mFilename -> filePath () ).baseName ();
385402 leLayername->setText ( layerName );
386403 }
387404
@@ -626,30 +643,6 @@ void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *
626643 mReplaceRawFieldValuesStateChangedSlotEnabled = true ;
627644}
628645
629- void QgsVectorLayerSaveAsDialog::leFilename_textChanged ( const QString &text )
630- {
631- buttonBox->button ( QDialogButtonBox::Ok )->setEnabled (
632- !text.isEmpty () && QFileInfo ( text ).absoluteDir ().exists () );
633-
634- if ( leLayername->isEnabled () )
635- {
636- QString layerName = QFileInfo ( text ).baseName ();
637- leLayername->setText ( layerName );
638- }
639- }
640-
641- void QgsVectorLayerSaveAsDialog::browseFilename_clicked ()
642- {
643- QgsSettings settings;
644- QString dirName = leFilename->text ().isEmpty () ? settings.value ( QStringLiteral ( " UI/lastVectorFileFilterDir" ), QDir::homePath () ).toString () : leFilename->text ();
645- QString filterString = QgsVectorFileWriter::filterForDriver ( format () );
646- QString outputFile = QFileDialog::getSaveFileName ( nullptr , tr ( " Save layer as..." ), dirName, filterString, nullptr , QFileDialog::DontConfirmOverwrite );
647- if ( !outputFile.isNull () )
648- {
649- leFilename->setText ( outputFile );
650- }
651- }
652-
653646void QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged ( const QgsCoordinateReferenceSystem &crs )
654647{
655648 mCRS = crs.srsid ();
@@ -658,7 +651,7 @@ void QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged( const QgsCoordinateRef
658651
659652QString QgsVectorLayerSaveAsDialog::filename () const
660653{
661- return leFilename-> text ();
654+ return mFilename -> filePath ();
662655}
663656
664657QString QgsVectorLayerSaveAsDialog::layername () const
0 commit comments