Skip to content

Commit

Permalink
[ui] use qgsfilewidget in the save vector as dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Dec 7, 2017
1 parent 38c96fe commit 09e830b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 51 deletions.
55 changes: 24 additions & 31 deletions src/gui/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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;

Expand All @@ -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 );
}

Expand Down Expand Up @@ -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();
Expand All @@ -658,7 +651,7 @@ void QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged( const QgsCoordinateRef

QString QgsVectorLayerSaveAsDialog::filename() const
{
return leFilename->text();
return mFilename->filePath();
}

QString QgsVectorLayerSaveAsDialog::layername() const
Expand Down
2 changes: 0 additions & 2 deletions src/gui/ogr/qgsvectorlayersaveasdialog.h
Expand Up @@ -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 );
Expand Down
31 changes: 13 additions & 18 deletions src/ui/qgsvectorlayersaveasdialogbase.ui
Expand Up @@ -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">
Expand All @@ -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">
Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 09e830b

Please sign in to comment.