Skip to content

Commit 09e830b

Browse files
committed
[ui] use qgsfilewidget in the save vector as dialog
1 parent 38c96fe commit 09e830b

3 files changed

Lines changed: 37 additions & 51 deletions

File tree

src/gui/ogr/qgsvectorlayersaveasdialog.cpp

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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

144160
QList<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-
653646
void QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs )
654647
{
655648
mCRS = crs.srsid();
@@ -658,7 +651,7 @@ void QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged( const QgsCoordinateRef
658651

659652
QString QgsVectorLayerSaveAsDialog::filename() const
660653
{
661-
return leFilename->text();
654+
return mFilename->filePath();
662655
}
663656

664657
QString QgsVectorLayerSaveAsDialog::layername() const

src/gui/ogr/qgsvectorlayersaveasdialog.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ class GUI_EXPORT QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVec
126126
private slots:
127127

128128
void mFormatComboBox_currentIndexChanged( int idx );
129-
void leFilename_textChanged( const QString &text );
130-
void browseFilename_clicked();
131129
void mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs );
132130
void showHelp();
133131
void mSymbologyExportComboBox_currentIndexChanged( const QString &text );

src/ui/qgsvectorlayersaveasdialogbase.ui

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,12 @@
3131
</widget>
3232
</item>
3333
<item row="1" column="2">
34-
<widget class="QLineEdit" name="leFilename">
34+
<widget class="QgsFileWidget" name="mFilename">
3535
<property name="enabled">
3636
<bool>false</bool>
3737
</property>
3838
</widget>
3939
</item>
40-
<item row="1" column="3">
41-
<widget class="QPushButton" name="browseFilename">
42-
<property name="enabled">
43-
<bool>false</bool>
44-
</property>
45-
<property name="text">
46-
<string>Browse</string>
47-
</property>
48-
</widget>
49-
</item>
5040
<item row="0" column="0">
5141
<widget class="QLabel" name="label_2">
5242
<property name="text">
@@ -57,7 +47,7 @@
5747
</property>
5848
</widget>
5949
</item>
60-
<item row="0" column="2" colspan="2">
50+
<item row="0" column="2">
6151
<widget class="QComboBox" name="mFormatComboBox"/>
6252
</item>
6353
<item row="1" column="0">
@@ -66,11 +56,11 @@
6656
<string>File name</string>
6757
</property>
6858
<property name="buddy">
69-
<cstring>leFilename</cstring>
59+
<cstring>mFilename</cstring>
7060
</property>
7161
</widget>
7262
</item>
73-
<item row="3" column="2" colspan="2">
63+
<item row="3" column="2">
7464
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector" native="true">
7565
<property name="focusPolicy">
7666
<enum>Qt::StrongFocus</enum>
@@ -83,11 +73,11 @@
8373
<string>Layer name</string>
8474
</property>
8575
<property name="buddy">
86-
<cstring>leFilename</cstring>
76+
<cstring>leLayername</cstring>
8777
</property>
8878
</widget>
8979
</item>
90-
<item row="2" column="2" colspan="2">
80+
<item row="2" column="2">
9181
<widget class="QLineEdit" name="leLayername">
9282
<property name="enabled">
9383
<bool>false</bool>
@@ -468,11 +458,16 @@
468458
<extends>QWidget</extends>
469459
<header>qgsscalewidget.h</header>
470460
</customwidget>
461+
<customwidget>
462+
<class>QgsFileWidget</class>
463+
<extends>QWidget</extends>
464+
<header>qgsfilewidget.h</header>
465+
<container>1</container>
466+
</customwidget>
471467
</customwidgets>
472468
<tabstops>
473469
<tabstop>mFormatComboBox</tabstop>
474-
<tabstop>leFilename</tabstop>
475-
<tabstop>browseFilename</tabstop>
470+
<tabstop>mFilename</tabstop>
476471
<tabstop>leLayername</tabstop>
477472
<tabstop>mCrsSelector</tabstop>
478473
<tabstop>scrollArea</tabstop>

0 commit comments

Comments
 (0)