mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
[ui] use qgsfilewidget in the save vector as dialog
This commit is contained in:
parent
38c96fe373
commit
09e830bf08
@ -73,8 +73,6 @@ void QgsVectorLayerSaveAsDialog::setup()
|
||||
{
|
||||
setupUi( this );
|
||||
connect( mFormatComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
|
||||
connect( leFilename, &QLineEdit::textChanged, this, &QgsVectorLayerSaveAsDialog::leFilename_textChanged );
|
||||
connect( browseFilename, &QPushButton::clicked, this, &QgsVectorLayerSaveAsDialog::browseFilename_clicked );
|
||||
connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged );
|
||||
connect( mSymbologyExportComboBox, static_cast<void ( QComboBox::* )( const QString & )>( &QComboBox::currentIndexChanged ), this, &QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged );
|
||||
connect( mGeometryTypeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged );
|
||||
@ -139,6 +137,24 @@ void QgsVectorLayerSaveAsDialog::setup()
|
||||
mExtentGroupBox->setCheckable( true );
|
||||
mExtentGroupBox->setChecked( false );
|
||||
mExtentGroupBox->setCollapsed( true );
|
||||
|
||||
mFilename->setStorageMode( QgsFileWidget::SaveFile );
|
||||
mFilename->setDialogTitle( tr( "Select layer as..." ) );
|
||||
mFilename->setDefaultRoot( settings.value( QStringLiteral( "UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString() );
|
||||
mFilename->setConfirmOverwrite( false );
|
||||
connect( mFilename, &QgsFileWidget::fileChanged, this, [ = ]( const QString & filePath )
|
||||
{
|
||||
QgsSettings settings;
|
||||
QFileInfo tmplFileInfo( filePath );
|
||||
settings.setValue( QStringLiteral( "UI/lastVectorFileFilterDir" ), tmplFileInfo.absolutePath() );
|
||||
if ( !filePath.isEmpty() && leLayername->isEnabled() )
|
||||
{
|
||||
QFileInfo fileInfo( filePath );
|
||||
leLayername->setText( fileInfo.baseName() );
|
||||
}
|
||||
buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
|
||||
!filePath.isEmpty() && QFileInfo( filePath ).absoluteDir().exists() );
|
||||
} );
|
||||
}
|
||||
|
||||
QList<QPair<QLabel *, QWidget *> > QgsVectorLayerSaveAsDialog::createControls( const QMap<QString, QgsVectorFileWriter::Option *> &options )
|
||||
@ -352,8 +368,9 @@ void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
|
||||
{
|
||||
Q_UNUSED( idx );
|
||||
|
||||
browseFilename->setEnabled( true );
|
||||
leFilename->setEnabled( true );
|
||||
mFilename->setEnabled( true );
|
||||
mFilename->setFilter( QgsVectorFileWriter::filterForDriver( format() ) );
|
||||
|
||||
bool selectAllFields = true;
|
||||
bool fieldsAsDisplayedValues = false;
|
||||
|
||||
@ -379,9 +396,9 @@ void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
|
||||
if ( !leLayername->isEnabled() )
|
||||
leLayername->setText( QString() );
|
||||
else if ( leLayername->text().isEmpty() &&
|
||||
!leFilename->text().isEmpty() )
|
||||
!mFilename->filePath().isEmpty() )
|
||||
{
|
||||
QString layerName = QFileInfo( leFilename->text() ).baseName();
|
||||
QString layerName = QFileInfo( mFilename->filePath() ).baseName();
|
||||
leLayername->setText( layerName );
|
||||
}
|
||||
|
||||
@ -626,30 +643,6 @@ void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *
|
||||
mReplaceRawFieldValuesStateChangedSlotEnabled = true;
|
||||
}
|
||||
|
||||
void QgsVectorLayerSaveAsDialog::leFilename_textChanged( const QString &text )
|
||||
{
|
||||
buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
|
||||
!text.isEmpty() && QFileInfo( text ).absoluteDir().exists() );
|
||||
|
||||
if ( leLayername->isEnabled() )
|
||||
{
|
||||
QString layerName = QFileInfo( text ).baseName();
|
||||
leLayername->setText( layerName );
|
||||
}
|
||||
}
|
||||
|
||||
void QgsVectorLayerSaveAsDialog::browseFilename_clicked()
|
||||
{
|
||||
QgsSettings settings;
|
||||
QString dirName = leFilename->text().isEmpty() ? settings.value( QStringLiteral( "UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString() : leFilename->text();
|
||||
QString filterString = QgsVectorFileWriter::filterForDriver( format() );
|
||||
QString outputFile = QFileDialog::getSaveFileName( nullptr, tr( "Save layer as..." ), dirName, filterString, nullptr, QFileDialog::DontConfirmOverwrite );
|
||||
if ( !outputFile.isNull() )
|
||||
{
|
||||
leFilename->setText( outputFile );
|
||||
}
|
||||
}
|
||||
|
||||
void QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs )
|
||||
{
|
||||
mCRS = crs.srsid();
|
||||
@ -658,7 +651,7 @@ void QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged( const QgsCoordinateRef
|
||||
|
||||
QString QgsVectorLayerSaveAsDialog::filename() const
|
||||
{
|
||||
return leFilename->text();
|
||||
return mFilename->filePath();
|
||||
}
|
||||
|
||||
QString QgsVectorLayerSaveAsDialog::layername() const
|
||||
|
@ -126,8 +126,6 @@ class GUI_EXPORT QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVec
|
||||
private slots:
|
||||
|
||||
void mFormatComboBox_currentIndexChanged( int idx );
|
||||
void leFilename_textChanged( const QString &text );
|
||||
void browseFilename_clicked();
|
||||
void mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs );
|
||||
void showHelp();
|
||||
void mSymbologyExportComboBox_currentIndexChanged( const QString &text );
|
||||
|
@ -31,22 +31,12 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLineEdit" name="leFilename">
|
||||
<widget class="QgsFileWidget" name="mFilename">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QPushButton" name="browseFilename">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
@ -57,7 +47,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2" colspan="2">
|
||||
<item row="0" column="2">
|
||||
<widget class="QComboBox" name="mFormatComboBox"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
@ -66,11 +56,11 @@
|
||||
<string>File name</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>leFilename</cstring>
|
||||
<cstring>mFilename</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2" colspan="2">
|
||||
<item row="3" column="2">
|
||||
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector" native="true">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
@ -83,11 +73,11 @@
|
||||
<string>Layer name</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>leFilename</cstring>
|
||||
<cstring>leLayername</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2" colspan="2">
|
||||
<item row="2" column="2">
|
||||
<widget class="QLineEdit" name="leLayername">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
@ -468,11 +458,16 @@
|
||||
<extends>QWidget</extends>
|
||||
<header>qgsscalewidget.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QgsFileWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>qgsfilewidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>mFormatComboBox</tabstop>
|
||||
<tabstop>leFilename</tabstop>
|
||||
<tabstop>browseFilename</tabstop>
|
||||
<tabstop>mFilename</tabstop>
|
||||
<tabstop>leLayername</tabstop>
|
||||
<tabstop>mCrsSelector</tabstop>
|
||||
<tabstop>scrollArea</tabstop>
|
||||
|
Loading…
x
Reference in New Issue
Block a user