mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-09 00:05:52 -04:00
Merge pull request #5818 from nirvn/filewidget_fest
Use QgsFileWidget in several dialogs
This commit is contained in:
commit
7e0c149b0c
@ -31,6 +31,7 @@ class QgsFileWidget : QWidget
|
|||||||
GetFile,
|
GetFile,
|
||||||
GetDirectory,
|
GetDirectory,
|
||||||
GetMultipleFiles,
|
GetMultipleFiles,
|
||||||
|
SaveFile,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum RelativeStorage
|
enum RelativeStorage
|
||||||
@ -97,6 +98,19 @@ returns the filters used for QDialog.getOpenFileName
|
|||||||
\param filter Only files that match the given filter are shown, it may be an empty string. If you want multiple filters, separate them with ';;',
|
\param filter Only files that match the given filter are shown, it may be an empty string. If you want multiple filters, separate them with ';;',
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
void setConfirmOverwrite( bool confirmOverwrite );
|
||||||
|
%Docstring
|
||||||
|
Sets whether a confirmation to overwrite an existing file will appear.
|
||||||
|
By default, a confirmation will appear.
|
||||||
|
\param confirmOverwrite If set to true, an overwrite confirmation will be shown
|
||||||
|
%End
|
||||||
|
|
||||||
|
bool confirmOverwrite() const;
|
||||||
|
%Docstring
|
||||||
|
Returns whether a confirmation will be shown when overwriting an existing file
|
||||||
|
:rtype: bool
|
||||||
|
%End
|
||||||
|
|
||||||
bool fileWidgetButtonVisible() const;
|
bool fileWidgetButtonVisible() const;
|
||||||
%Docstring
|
%Docstring
|
||||||
determines if the tool button is shown
|
determines if the tool button is shown
|
||||||
|
@ -73,8 +73,6 @@ void QgsVectorLayerSaveAsDialog::setup()
|
|||||||
{
|
{
|
||||||
setupUi( this );
|
setupUi( this );
|
||||||
connect( mFormatComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
|
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( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged );
|
||||||
connect( mSymbologyExportComboBox, static_cast<void ( QComboBox::* )( const QString & )>( &QComboBox::currentIndexChanged ), this, &QgsVectorLayerSaveAsDialog::mSymbologyExportComboBox_currentIndexChanged );
|
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 );
|
connect( mGeometryTypeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorLayerSaveAsDialog::mGeometryTypeComboBox_currentIndexChanged );
|
||||||
@ -139,6 +137,24 @@ void QgsVectorLayerSaveAsDialog::setup()
|
|||||||
mExtentGroupBox->setCheckable( true );
|
mExtentGroupBox->setCheckable( true );
|
||||||
mExtentGroupBox->setChecked( false );
|
mExtentGroupBox->setChecked( false );
|
||||||
mExtentGroupBox->setCollapsed( true );
|
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 )
|
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 );
|
Q_UNUSED( idx );
|
||||||
|
|
||||||
browseFilename->setEnabled( true );
|
mFilename->setEnabled( true );
|
||||||
leFilename->setEnabled( true );
|
mFilename->setFilter( QgsVectorFileWriter::filterForDriver( format() ) );
|
||||||
|
|
||||||
bool selectAllFields = true;
|
bool selectAllFields = true;
|
||||||
bool fieldsAsDisplayedValues = false;
|
bool fieldsAsDisplayedValues = false;
|
||||||
|
|
||||||
@ -379,9 +396,9 @@ void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
|
|||||||
if ( !leLayername->isEnabled() )
|
if ( !leLayername->isEnabled() )
|
||||||
leLayername->setText( QString() );
|
leLayername->setText( QString() );
|
||||||
else if ( leLayername->text().isEmpty() &&
|
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 );
|
leLayername->setText( layerName );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -626,30 +643,6 @@ void QgsVectorLayerSaveAsDialog::mAttributeTable_itemChanged( QTableWidgetItem *
|
|||||||
mReplaceRawFieldValuesStateChangedSlotEnabled = true;
|
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 )
|
void QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs )
|
||||||
{
|
{
|
||||||
mCRS = crs.srsid();
|
mCRS = crs.srsid();
|
||||||
@ -658,7 +651,7 @@ void QgsVectorLayerSaveAsDialog::mCrsSelector_crsChanged( const QgsCoordinateRef
|
|||||||
|
|
||||||
QString QgsVectorLayerSaveAsDialog::filename() const
|
QString QgsVectorLayerSaveAsDialog::filename() const
|
||||||
{
|
{
|
||||||
return leFilename->text();
|
return mFilename->filePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsVectorLayerSaveAsDialog::layername() const
|
QString QgsVectorLayerSaveAsDialog::layername() const
|
||||||
|
@ -126,8 +126,6 @@ class GUI_EXPORT QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVec
|
|||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void mFormatComboBox_currentIndexChanged( int idx );
|
void mFormatComboBox_currentIndexChanged( int idx );
|
||||||
void leFilename_textChanged( const QString &text );
|
|
||||||
void browseFilename_clicked();
|
|
||||||
void mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs );
|
void mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs );
|
||||||
void showHelp();
|
void showHelp();
|
||||||
void mSymbologyExportComboBox_currentIndexChanged( const QString &text );
|
void mSymbologyExportComboBox_currentIndexChanged( const QString &text );
|
||||||
|
@ -262,6 +262,17 @@ void QgsFileWidget::openFileDialog()
|
|||||||
title = !mDialogTitle.isEmpty() ? mDialogTitle : tr( "Select a directory" );
|
title = !mDialogTitle.isEmpty() ? mDialogTitle : tr( "Select a directory" );
|
||||||
fileName = QFileDialog::getExistingDirectory( this, title, QFileInfo( oldPath ).absoluteFilePath(), QFileDialog::ShowDirsOnly );
|
fileName = QFileDialog::getExistingDirectory( this, title, QFileInfo( oldPath ).absoluteFilePath(), QFileDialog::ShowDirsOnly );
|
||||||
break;
|
break;
|
||||||
|
case SaveFile:
|
||||||
|
title = !mDialogTitle.isEmpty() ? mDialogTitle : tr( "Create or select a file" );
|
||||||
|
if ( !confirmOverwrite() )
|
||||||
|
{
|
||||||
|
fileName = QFileDialog::getSaveFileName( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter, nullptr, QFileDialog::DontConfirmOverwrite );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fileName = QFileDialog::getSaveFileName( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter );
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fileName.isEmpty() && fileNames.isEmpty( ) )
|
if ( fileName.isEmpty() && fileNames.isEmpty( ) )
|
||||||
@ -283,6 +294,7 @@ void QgsFileWidget::openFileDialog()
|
|||||||
switch ( mStorageMode )
|
switch ( mStorageMode )
|
||||||
{
|
{
|
||||||
case GetFile:
|
case GetFile:
|
||||||
|
case SaveFile:
|
||||||
settings.setValue( QStringLiteral( "UI/lastFileNameWidgetDir" ), QFileInfo( fileName ).absolutePath() );
|
settings.setValue( QStringLiteral( "UI/lastFileNameWidgetDir" ), QFileInfo( fileName ).absolutePath() );
|
||||||
break;
|
break;
|
||||||
case GetDirectory:
|
case GetDirectory:
|
||||||
|
@ -65,6 +65,7 @@ class GUI_EXPORT QgsFileWidget : public QWidget
|
|||||||
GetFile, //! Select a single file
|
GetFile, //! Select a single file
|
||||||
GetDirectory, //! Select a directory
|
GetDirectory, //! Select a directory
|
||||||
GetMultipleFiles, //! Select multiple files
|
GetMultipleFiles, //! Select multiple files
|
||||||
|
SaveFile, //! Select a single new or pre-existing file
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -120,6 +121,18 @@ class GUI_EXPORT QgsFileWidget : public QWidget
|
|||||||
*/
|
*/
|
||||||
void setFilter( const QString &filter );
|
void setFilter( const QString &filter );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether a confirmation to overwrite an existing file will appear.
|
||||||
|
* By default, a confirmation will appear.
|
||||||
|
* \param confirmOverwrite If set to true, an overwrite confirmation will be shown
|
||||||
|
*/
|
||||||
|
void setConfirmOverwrite( bool confirmOverwrite ) { mConfirmOverwrite = confirmOverwrite; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether a confirmation will be shown when overwriting an existing file
|
||||||
|
*/
|
||||||
|
bool confirmOverwrite() const { return mConfirmOverwrite; }
|
||||||
|
|
||||||
//! determines if the tool button is shown
|
//! determines if the tool button is shown
|
||||||
bool fileWidgetButtonVisible() const;
|
bool fileWidgetButtonVisible() const;
|
||||||
//! determines if the tool button is shown
|
//! determines if the tool button is shown
|
||||||
@ -173,6 +186,7 @@ class GUI_EXPORT QgsFileWidget : public QWidget
|
|||||||
QString mDialogTitle;
|
QString mDialogTitle;
|
||||||
QString mFilter;
|
QString mFilter;
|
||||||
QString mDefaultRoot;
|
QString mDefaultRoot;
|
||||||
|
bool mConfirmOverwrite = true;
|
||||||
StorageMode mStorageMode = GetFile;
|
StorageMode mStorageMode = GetFile;
|
||||||
RelativeStorage mRelativeStorage = Absolute;
|
RelativeStorage mRelativeStorage = Absolute;
|
||||||
|
|
||||||
|
@ -51,8 +51,6 @@ QgsNewGeoPackageLayerDialog::QgsNewGeoPackageLayerDialog( QWidget *parent, Qt::W
|
|||||||
connect( mRemoveAttributeButton, &QToolButton::clicked, this, &QgsNewGeoPackageLayerDialog::mRemoveAttributeButton_clicked );
|
connect( mRemoveAttributeButton, &QToolButton::clicked, this, &QgsNewGeoPackageLayerDialog::mRemoveAttributeButton_clicked );
|
||||||
connect( mFieldTypeBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsNewGeoPackageLayerDialog::mFieldTypeBox_currentIndexChanged );
|
connect( mFieldTypeBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsNewGeoPackageLayerDialog::mFieldTypeBox_currentIndexChanged );
|
||||||
connect( mGeometryTypeBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsNewGeoPackageLayerDialog::mGeometryTypeBox_currentIndexChanged );
|
connect( mGeometryTypeBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsNewGeoPackageLayerDialog::mGeometryTypeBox_currentIndexChanged );
|
||||||
connect( mSelectDatabaseButton, &QToolButton::clicked, this, &QgsNewGeoPackageLayerDialog::mSelectDatabaseButton_clicked );
|
|
||||||
connect( mDatabaseEdit, &QLineEdit::textChanged, this, &QgsNewGeoPackageLayerDialog::mDatabaseEdit_textChanged );
|
|
||||||
connect( mTableNameEdit, &QLineEdit::textChanged, this, &QgsNewGeoPackageLayerDialog::mTableNameEdit_textChanged );
|
connect( mTableNameEdit, &QLineEdit::textChanged, this, &QgsNewGeoPackageLayerDialog::mTableNameEdit_textChanged );
|
||||||
connect( mTableNameEdit, &QLineEdit::textEdited, this, &QgsNewGeoPackageLayerDialog::mTableNameEdit_textEdited );
|
connect( mTableNameEdit, &QLineEdit::textEdited, this, &QgsNewGeoPackageLayerDialog::mTableNameEdit_textEdited );
|
||||||
connect( mLayerIdentifierEdit, &QLineEdit::textEdited, this, &QgsNewGeoPackageLayerDialog::mLayerIdentifierEdit_textEdited );
|
connect( mLayerIdentifierEdit, &QLineEdit::textEdited, this, &QgsNewGeoPackageLayerDialog::mLayerIdentifierEdit_textEdited );
|
||||||
@ -102,12 +100,29 @@ QgsNewGeoPackageLayerDialog::QgsNewGeoPackageLayerDialog( QWidget *parent, Qt::W
|
|||||||
connect( mFieldNameEdit, &QLineEdit::textChanged, this, &QgsNewGeoPackageLayerDialog::fieldNameChanged );
|
connect( mFieldNameEdit, &QLineEdit::textChanged, this, &QgsNewGeoPackageLayerDialog::fieldNameChanged );
|
||||||
connect( mAttributeView, &QTreeWidget::itemSelectionChanged, this, &QgsNewGeoPackageLayerDialog::selectionChanged );
|
connect( mAttributeView, &QTreeWidget::itemSelectionChanged, this, &QgsNewGeoPackageLayerDialog::selectionChanged );
|
||||||
connect( mTableNameEdit, &QLineEdit::textChanged, this, &QgsNewGeoPackageLayerDialog::checkOk );
|
connect( mTableNameEdit, &QLineEdit::textChanged, this, &QgsNewGeoPackageLayerDialog::checkOk );
|
||||||
connect( mDatabaseEdit, &QLineEdit::textChanged, this, &QgsNewGeoPackageLayerDialog::checkOk );
|
|
||||||
|
|
||||||
mAddAttributeButton->setEnabled( false );
|
mAddAttributeButton->setEnabled( false );
|
||||||
mRemoveAttributeButton->setEnabled( false );
|
mRemoveAttributeButton->setEnabled( false );
|
||||||
|
|
||||||
mCheckBoxCreateSpatialIndex->setChecked( true );
|
mCheckBoxCreateSpatialIndex->setChecked( true );
|
||||||
|
|
||||||
|
mDatabase->setStorageMode( QgsFileWidget::SaveFile );
|
||||||
|
mDatabase->setFilter( tr( "GeoPackage" ) + " (*.gpkg)" );
|
||||||
|
mDatabase->setDialogTitle( tr( "Select Existing or Create a New GeoPackage Database File..." ) );
|
||||||
|
mDatabase->setDefaultRoot( settings.value( QStringLiteral( "UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString() );
|
||||||
|
mDatabase->setConfirmOverwrite( false );
|
||||||
|
connect( mDatabase, &QgsFileWidget::fileChanged, this, [ = ]( const QString & filePath )
|
||||||
|
{
|
||||||
|
QgsSettings settings;
|
||||||
|
QFileInfo tmplFileInfo( filePath );
|
||||||
|
settings.setValue( QStringLiteral( "UI/lastVectorFileFilterDir" ), tmplFileInfo.absolutePath() );
|
||||||
|
if ( !filePath.isEmpty() && !mTableNameEdited )
|
||||||
|
{
|
||||||
|
QFileInfo fileInfo( filePath );
|
||||||
|
mTableNameEdit->setText( fileInfo.baseName() );
|
||||||
|
}
|
||||||
|
checkOk();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsNewGeoPackageLayerDialog::~QgsNewGeoPackageLayerDialog()
|
QgsNewGeoPackageLayerDialog::~QgsNewGeoPackageLayerDialog()
|
||||||
@ -123,10 +138,7 @@ void QgsNewGeoPackageLayerDialog::setCrs( const QgsCoordinateReferenceSystem &cr
|
|||||||
|
|
||||||
void QgsNewGeoPackageLayerDialog::lockDatabasePath()
|
void QgsNewGeoPackageLayerDialog::lockDatabasePath()
|
||||||
{
|
{
|
||||||
mDatabaseEdit->setReadOnly( true );
|
mDatabase->setReadOnly( true );
|
||||||
mSelectDatabaseButton->hide();
|
|
||||||
mSelectDatabaseButton->deleteLater();
|
|
||||||
mSelectDatabaseButton = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsNewGeoPackageLayerDialog::mFieldTypeBox_currentIndexChanged( int )
|
void QgsNewGeoPackageLayerDialog::mFieldTypeBox_currentIndexChanged( int )
|
||||||
@ -150,34 +162,6 @@ void QgsNewGeoPackageLayerDialog::mGeometryTypeBox_currentIndexChanged( int )
|
|||||||
mCrsSelector->setEnabled( isSpatial );
|
mCrsSelector->setEnabled( isSpatial );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsNewGeoPackageLayerDialog::mSelectDatabaseButton_clicked()
|
|
||||||
{
|
|
||||||
QString fileName = QFileDialog::getSaveFileName( this, tr( "Select existing or create new GeoPackage Database File" ),
|
|
||||||
QDir::homePath(),
|
|
||||||
tr( "GeoPackage" ) + " (*.gpkg)",
|
|
||||||
nullptr,
|
|
||||||
QFileDialog::DontConfirmOverwrite );
|
|
||||||
|
|
||||||
if ( fileName.isEmpty() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( !fileName.endsWith( QLatin1String( ".gpkg" ), Qt::CaseInsensitive ) )
|
|
||||||
{
|
|
||||||
fileName += QLatin1String( ".gpkg" );
|
|
||||||
}
|
|
||||||
|
|
||||||
mDatabaseEdit->setText( fileName );
|
|
||||||
}
|
|
||||||
|
|
||||||
void QgsNewGeoPackageLayerDialog::mDatabaseEdit_textChanged( const QString &text )
|
|
||||||
{
|
|
||||||
if ( !text.isEmpty() && !mTableNameEdited )
|
|
||||||
{
|
|
||||||
QFileInfo fileInfo( text );
|
|
||||||
mTableNameEdit->setText( fileInfo.baseName() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QgsNewGeoPackageLayerDialog::mTableNameEdit_textChanged( const QString &text )
|
void QgsNewGeoPackageLayerDialog::mTableNameEdit_textChanged( const QString &text )
|
||||||
{
|
{
|
||||||
mTableNameEdited = !text.isEmpty();
|
mTableNameEdited = !text.isEmpty();
|
||||||
@ -201,7 +185,7 @@ void QgsNewGeoPackageLayerDialog::mLayerIdentifierEdit_textEdited( const QString
|
|||||||
|
|
||||||
void QgsNewGeoPackageLayerDialog::checkOk()
|
void QgsNewGeoPackageLayerDialog::checkOk()
|
||||||
{
|
{
|
||||||
bool ok = !mDatabaseEdit->text().isEmpty() &&
|
bool ok = !mDatabase->filePath().isEmpty() &&
|
||||||
!mTableNameEdit->text().isEmpty();
|
!mTableNameEdit->text().isEmpty();
|
||||||
mOkButton->setEnabled( ok );
|
mOkButton->setEnabled( ok );
|
||||||
}
|
}
|
||||||
@ -258,7 +242,10 @@ void QgsNewGeoPackageLayerDialog::buttonBox_rejected()
|
|||||||
|
|
||||||
bool QgsNewGeoPackageLayerDialog::apply()
|
bool QgsNewGeoPackageLayerDialog::apply()
|
||||||
{
|
{
|
||||||
QString fileName( mDatabaseEdit->text() );
|
QString fileName( mDatabase->filePath() );
|
||||||
|
if ( !fileName.endsWith( QLatin1String( ".gpkg" ), Qt::CaseInsensitive ) )
|
||||||
|
fileName += QLatin1String( ".gpkg" );
|
||||||
|
|
||||||
bool createNewDb = false;
|
bool createNewDb = false;
|
||||||
|
|
||||||
if ( QFile( fileName ).exists( fileName ) )
|
if ( QFile( fileName ).exists( fileName ) )
|
||||||
@ -490,7 +477,7 @@ bool QgsNewGeoPackageLayerDialog::apply()
|
|||||||
}
|
}
|
||||||
hDS.reset();
|
hDS.reset();
|
||||||
|
|
||||||
QString uri( QStringLiteral( "%1|layername=%2" ).arg( mDatabaseEdit->text(), tableName ) );
|
QString uri( QStringLiteral( "%1|layername=%2" ).arg( fileName, tableName ) );
|
||||||
QString userVisiblelayerName( layerIdentifier.isEmpty() ? tableName : layerIdentifier );
|
QString userVisiblelayerName( layerIdentifier.isEmpty() ? tableName : layerIdentifier );
|
||||||
QgsVectorLayer *layer = new QgsVectorLayer( uri, userVisiblelayerName, QStringLiteral( "ogr" ) );
|
QgsVectorLayer *layer = new QgsVectorLayer( uri, userVisiblelayerName, QStringLiteral( "ogr" ) );
|
||||||
if ( layer->isValid() )
|
if ( layer->isValid() )
|
||||||
|
@ -54,13 +54,13 @@ class GUI_EXPORT QgsNewGeoPackageLayerDialog: public QDialog, private Ui::QgsNew
|
|||||||
* Returns the database path
|
* Returns the database path
|
||||||
* \since QGIS 3.0
|
* \since QGIS 3.0
|
||||||
*/
|
*/
|
||||||
QString databasePath() const { return mDatabaseEdit->text(); }
|
QString databasePath() const { return mDatabase->filePath(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the initial database \a path
|
* Sets the initial database \a path
|
||||||
* \since QGIS 3.0
|
* \since QGIS 3.0
|
||||||
*/
|
*/
|
||||||
void setDatabasePath( const QString &path ) { mDatabaseEdit->setText( path ); }
|
void setDatabasePath( const QString &path ) { mDatabase->setFilePath( path ); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the database path widgets to a locked and read-only mode.
|
* Sets the database path widgets to a locked and read-only mode.
|
||||||
@ -82,8 +82,6 @@ class GUI_EXPORT QgsNewGeoPackageLayerDialog: public QDialog, private Ui::QgsNew
|
|||||||
void mRemoveAttributeButton_clicked();
|
void mRemoveAttributeButton_clicked();
|
||||||
void mFieldTypeBox_currentIndexChanged( int index );
|
void mFieldTypeBox_currentIndexChanged( int index );
|
||||||
void mGeometryTypeBox_currentIndexChanged( int index );
|
void mGeometryTypeBox_currentIndexChanged( int index );
|
||||||
void mSelectDatabaseButton_clicked();
|
|
||||||
void mDatabaseEdit_textChanged( const QString &text );
|
|
||||||
void mTableNameEdit_textChanged( const QString &text );
|
void mTableNameEdit_textChanged( const QString &text );
|
||||||
void mTableNameEdit_textEdited( const QString &text );
|
void mTableNameEdit_textEdited( const QString &text );
|
||||||
void mLayerIdentifierEdit_textEdited( const QString &text );
|
void mLayerIdentifierEdit_textEdited( const QString &text );
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include "qgsnewvectorlayerdialog.h"
|
#include "qgsnewvectorlayerdialog.h"
|
||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
|
#include "qgsfilewidget.h"
|
||||||
#include "qgis.h"
|
#include "qgis.h"
|
||||||
#include "qgslogger.h"
|
#include "qgslogger.h"
|
||||||
#include "qgscoordinatereferencesystem.h"
|
#include "qgscoordinatereferencesystem.h"
|
||||||
@ -35,10 +36,9 @@ QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WindowFla
|
|||||||
: QDialog( parent, fl )
|
: QDialog( parent, fl )
|
||||||
{
|
{
|
||||||
setupUi( this );
|
setupUi( this );
|
||||||
|
|
||||||
connect( mAddAttributeButton, &QToolButton::clicked, this, &QgsNewVectorLayerDialog::mAddAttributeButton_clicked );
|
connect( mAddAttributeButton, &QToolButton::clicked, this, &QgsNewVectorLayerDialog::mAddAttributeButton_clicked );
|
||||||
connect( mRemoveAttributeButton, &QToolButton::clicked, this, &QgsNewVectorLayerDialog::mRemoveAttributeButton_clicked );
|
connect( mRemoveAttributeButton, &QToolButton::clicked, this, &QgsNewVectorLayerDialog::mRemoveAttributeButton_clicked );
|
||||||
connect( mFileNameEdit, &QLineEdit::textChanged, this, &QgsNewVectorLayerDialog::checkOk );
|
|
||||||
connect( mBrowseFileName, &QToolButton::clicked, this, &QgsNewVectorLayerDialog::selectFileName );
|
|
||||||
connect( mFileFormatComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsNewVectorLayerDialog::mFileFormatComboBox_currentIndexChanged );
|
connect( mFileFormatComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsNewVectorLayerDialog::mFileFormatComboBox_currentIndexChanged );
|
||||||
connect( mTypeBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsNewVectorLayerDialog::mTypeBox_currentIndexChanged );
|
connect( mTypeBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsNewVectorLayerDialog::mTypeBox_currentIndexChanged );
|
||||||
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsNewVectorLayerDialog::showHelp );
|
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsNewVectorLayerDialog::showHelp );
|
||||||
@ -100,6 +100,18 @@ QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WindowFla
|
|||||||
|
|
||||||
mAddAttributeButton->setEnabled( false );
|
mAddAttributeButton->setEnabled( false );
|
||||||
mRemoveAttributeButton->setEnabled( false );
|
mRemoveAttributeButton->setEnabled( false );
|
||||||
|
|
||||||
|
mFileName->setStorageMode( QgsFileWidget::SaveFile );
|
||||||
|
mFileName->setFilter( QgsVectorFileWriter::filterForDriver( mFileFormatComboBox->currentData( Qt::UserRole ).toString() ) );
|
||||||
|
mFileName->setDialogTitle( tr( "Select Layer as..." ) );
|
||||||
|
mFileName->setDefaultRoot( settings.value( QStringLiteral( "UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString() );
|
||||||
|
connect( mFileName, &QgsFileWidget::fileChanged, this, [ = ]
|
||||||
|
{
|
||||||
|
QgsSettings settings;
|
||||||
|
QFileInfo tmplFileInfo( mFileName->filePath() );
|
||||||
|
settings.setValue( QStringLiteral( "UI/lastVectorFileFilterDir" ), tmplFileInfo.absolutePath() );
|
||||||
|
checkOk();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsNewVectorLayerDialog::~QgsNewVectorLayerDialog()
|
QgsNewVectorLayerDialog::~QgsNewVectorLayerDialog()
|
||||||
@ -224,29 +236,14 @@ void QgsNewVectorLayerDialog::selectionChanged()
|
|||||||
mRemoveAttributeButton->setDisabled( mAttributeView->selectedItems().isEmpty() );
|
mRemoveAttributeButton->setDisabled( mAttributeView->selectedItems().isEmpty() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsNewVectorLayerDialog::selectFileName()
|
|
||||||
{
|
|
||||||
QString fileformat = mFileFormatComboBox->currentData( Qt::UserRole ).toString();
|
|
||||||
QgsSettings settings;
|
|
||||||
QString lastUsedDir = settings.value( QStringLiteral( "UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString();
|
|
||||||
QString filterString = QgsVectorFileWriter::filterForDriver( fileformat );
|
|
||||||
QString fileName = QFileDialog::getSaveFileName( nullptr, tr( "Save Layer as..." ), lastUsedDir, filterString );
|
|
||||||
if ( fileName.isEmpty() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( fileformat == QLatin1String( "ESRI Shapefile" ) && !fileName.endsWith( QLatin1String( ".shp" ), Qt::CaseInsensitive ) )
|
|
||||||
fileName += QLatin1String( ".shp" );
|
|
||||||
mFileNameEdit->setText( fileName );
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QgsNewVectorLayerDialog::filename() const
|
QString QgsNewVectorLayerDialog::filename() const
|
||||||
{
|
{
|
||||||
return mFileNameEdit->text();
|
return mFileName->filePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsNewVectorLayerDialog::checkOk()
|
void QgsNewVectorLayerDialog::checkOk()
|
||||||
{
|
{
|
||||||
bool ok = ( !mFileNameEdit->text().isEmpty() && mAttributeView->topLevelItemCount() > 0 );
|
bool ok = ( !mFileName->filePath().isEmpty() && mAttributeView->topLevelItemCount() > 0 );
|
||||||
mOkButton->setEnabled( ok );
|
mOkButton->setEnabled( ok );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,6 +268,8 @@ QString QgsNewVectorLayerDialog::runAndCreateLayer( QWidget *parent, QString *pE
|
|||||||
QgsSettings settings;
|
QgsSettings settings;
|
||||||
QString filterString = QgsVectorFileWriter::filterForDriver( fileformat );
|
QString filterString = QgsVectorFileWriter::filterForDriver( fileformat );
|
||||||
QString fileName = geomDialog.filename();
|
QString fileName = geomDialog.filename();
|
||||||
|
if ( fileformat == QLatin1String( "ESRI Shapefile" ) && !fileName.endsWith( QLatin1String( ".shp" ), Qt::CaseInsensitive ) )
|
||||||
|
fileName += QLatin1String( ".shp" );
|
||||||
|
|
||||||
settings.setValue( QStringLiteral( "UI/lastVectorFileFilterDir" ), QFileInfo( fileName ).absolutePath() );
|
settings.setValue( QStringLiteral( "UI/lastVectorFileFilterDir" ), QFileInfo( fileName ).absolutePath() );
|
||||||
settings.setValue( QStringLiteral( "UI/encoding" ), enc );
|
settings.setValue( QStringLiteral( "UI/encoding" ), enc );
|
||||||
|
@ -67,7 +67,6 @@ class GUI_EXPORT QgsNewVectorLayerDialog: public QDialog, private Ui::QgsNewVect
|
|||||||
void setCrs( const QgsCoordinateReferenceSystem &crs );
|
void setCrs( const QgsCoordinateReferenceSystem &crs );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void selectFileName();
|
|
||||||
void mAddAttributeButton_clicked();
|
void mAddAttributeButton_clicked();
|
||||||
void mRemoveAttributeButton_clicked();
|
void mRemoveAttributeButton_clicked();
|
||||||
void mFileFormatComboBox_currentIndexChanged( int index );
|
void mFileFormatComboBox_currentIndexChanged( int index );
|
||||||
|
@ -44,8 +44,6 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterLayer *rasterLa
|
|||||||
{
|
{
|
||||||
setupUi( this );
|
setupUi( this );
|
||||||
connect( mRawModeRadioButton, &QRadioButton::toggled, this, &QgsRasterLayerSaveAsDialog::mRawModeRadioButton_toggled );
|
connect( mRawModeRadioButton, &QRadioButton::toggled, this, &QgsRasterLayerSaveAsDialog::mRawModeRadioButton_toggled );
|
||||||
connect( mBrowseButton, &QPushButton::clicked, this, &QgsRasterLayerSaveAsDialog::mBrowseButton_clicked );
|
|
||||||
connect( mSaveAsLineEdit, &QLineEdit::textChanged, this, &QgsRasterLayerSaveAsDialog::mSaveAsLineEdit_textChanged );
|
|
||||||
connect( mFormatComboBox, static_cast<void ( QComboBox::* )( const QString & )>( &QComboBox::currentIndexChanged ), this, &QgsRasterLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
|
connect( mFormatComboBox, static_cast<void ( QComboBox::* )( const QString & )>( &QComboBox::currentIndexChanged ), this, &QgsRasterLayerSaveAsDialog::mFormatComboBox_currentIndexChanged );
|
||||||
connect( mResolutionRadioButton, &QRadioButton::toggled, this, &QgsRasterLayerSaveAsDialog::mResolutionRadioButton_toggled );
|
connect( mResolutionRadioButton, &QRadioButton::toggled, this, &QgsRasterLayerSaveAsDialog::mResolutionRadioButton_toggled );
|
||||||
connect( mOriginalResolutionPushButton, &QPushButton::clicked, this, &QgsRasterLayerSaveAsDialog::mOriginalResolutionPushButton_clicked );
|
connect( mOriginalResolutionPushButton, &QPushButton::clicked, this, &QgsRasterLayerSaveAsDialog::mOriginalResolutionPushButton_clicked );
|
||||||
@ -161,6 +159,59 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterLayer *rasterLa
|
|||||||
|
|
||||||
QgsSettings settings;
|
QgsSettings settings;
|
||||||
restoreGeometry( settings.value( QStringLiteral( "Windows/RasterLayerSaveAs/geometry" ) ).toByteArray() );
|
restoreGeometry( settings.value( QStringLiteral( "Windows/RasterLayerSaveAs/geometry" ) ).toByteArray() );
|
||||||
|
|
||||||
|
if ( mTileModeCheckBox->isChecked() )
|
||||||
|
{
|
||||||
|
mFilename->setStorageMode( QgsFileWidget::GetDirectory );
|
||||||
|
mFilename->setDialogTitle( tr( "Select output directory" ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mFilename->setStorageMode( QgsFileWidget::SaveFile );
|
||||||
|
mFilename->setDialogTitle( tr( "Select output file" ) );
|
||||||
|
}
|
||||||
|
mFilename->setDefaultRoot( settings.value( QStringLiteral( "UI/lastRasterFileDir" ), QDir::homePath() ).toString() );
|
||||||
|
connect( mFilename, &QgsFileWidget::fileChanged, this, [ = ]( const QString & filePath )
|
||||||
|
{
|
||||||
|
QgsSettings settings;
|
||||||
|
QFileInfo tmplFileInfo( filePath );
|
||||||
|
settings.setValue( QStringLiteral( "UI/lastRasterFileDir" ), tmplFileInfo.absolutePath() );
|
||||||
|
|
||||||
|
if ( mTileModeCheckBox->isChecked() )
|
||||||
|
{
|
||||||
|
QString fileName = filePath;
|
||||||
|
Q_FOREVER
|
||||||
|
{
|
||||||
|
// TODO: would not it be better to select .vrt file instead of directory?
|
||||||
|
//fileName = QFileDialog::getSaveFileName( this, tr( "Select output file" ), QString(), tr( "VRT" ) + " (*.vrt *.VRT)" );
|
||||||
|
if ( fileName.isEmpty() )
|
||||||
|
break; // canceled
|
||||||
|
|
||||||
|
// Check if directory is empty
|
||||||
|
QDir dir( fileName );
|
||||||
|
QString baseName = QFileInfo( fileName ).baseName();
|
||||||
|
QStringList filters;
|
||||||
|
filters << QStringLiteral( "%1.*" ).arg( baseName );
|
||||||
|
QStringList files = dir.entryList( filters );
|
||||||
|
if ( files.isEmpty() )
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ( QMessageBox::warning( this, tr( "Warning" ),
|
||||||
|
tr( "The directory %1 contains files which will be overwritten: %2" ).arg( dir.absolutePath(), files.join( QStringLiteral( ", " ) ) ),
|
||||||
|
QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Ok )
|
||||||
|
break;
|
||||||
|
|
||||||
|
fileName = QFileDialog::getExistingDirectory( this, tr( "Select output directory" ), tmplFileInfo.absolutePath() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QPushButton *okButton = mButtonBox->button( QDialogButtonBox::Ok );
|
||||||
|
if ( !okButton )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
okButton->setEnabled( tmplFileInfo.absoluteDir().exists() );
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsRasterLayerSaveAsDialog::~QgsRasterLayerSaveAsDialog()
|
QgsRasterLayerSaveAsDialog::~QgsRasterLayerSaveAsDialog()
|
||||||
@ -241,84 +292,6 @@ void QgsRasterLayerSaveAsDialog::setValidators()
|
|||||||
mMaximumSizeYLineEdit->setValidator( new QIntValidator( this ) );
|
mMaximumSizeYLineEdit->setValidator( new QIntValidator( this ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsRasterLayerSaveAsDialog::mBrowseButton_clicked()
|
|
||||||
{
|
|
||||||
QString fileName;
|
|
||||||
|
|
||||||
QgsSettings settings;
|
|
||||||
QString dirName = mSaveAsLineEdit->text().isEmpty() ? settings.value( QStringLiteral( "UI/lastRasterFileDir" ), QDir::homePath() ).toString() : mSaveAsLineEdit->text();
|
|
||||||
|
|
||||||
if ( mTileModeCheckBox->isChecked() )
|
|
||||||
{
|
|
||||||
Q_FOREVER
|
|
||||||
{
|
|
||||||
// TODO: would not it be better to select .vrt file instead of directory?
|
|
||||||
fileName = QFileDialog::getExistingDirectory( this, tr( "Select output directory" ), dirName );
|
|
||||||
//fileName = QFileDialog::getSaveFileName( this, tr( "Select output file" ), QString(), tr( "VRT" ) + " (*.vrt *.VRT)" );
|
|
||||||
|
|
||||||
if ( fileName.isEmpty() )
|
|
||||||
break; // canceled
|
|
||||||
|
|
||||||
// Check if directory is empty
|
|
||||||
QDir dir( fileName );
|
|
||||||
QString baseName = QFileInfo( fileName ).baseName();
|
|
||||||
QStringList filters;
|
|
||||||
filters << QStringLiteral( "%1.*" ).arg( baseName );
|
|
||||||
QStringList files = dir.entryList( filters );
|
|
||||||
if ( files.isEmpty() )
|
|
||||||
break;
|
|
||||||
|
|
||||||
if ( QMessageBox::warning( this, tr( "Warning" ),
|
|
||||||
tr( "The directory %1 contains files which will be overwritten: %2" ).arg( dir.absolutePath(), files.join( QStringLiteral( ", " ) ) ),
|
|
||||||
QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Ok )
|
|
||||||
break;
|
|
||||||
|
|
||||||
fileName.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QStringList extensions = QgsRasterFileWriter::extensionsForFormat( outputFormat() );
|
|
||||||
QString filter;
|
|
||||||
QString defaultExt;
|
|
||||||
if ( extensions.empty() )
|
|
||||||
filter = tr( "All files (*.*)" );
|
|
||||||
else
|
|
||||||
{
|
|
||||||
filter = QStringLiteral( "%1 (*.%2);;%3" ).arg( mFormatComboBox->currentText(),
|
|
||||||
extensions.join( QStringLiteral( " *." ) ),
|
|
||||||
tr( "All files (*.*)" ) );
|
|
||||||
defaultExt = extensions.at( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
fileName = QFileDialog::getSaveFileName( this, tr( "Select output file" ), dirName, filter );
|
|
||||||
|
|
||||||
// ensure the user never omits the extension from the file name
|
|
||||||
QFileInfo fi( fileName );
|
|
||||||
if ( !fileName.isEmpty() && fi.suffix().isEmpty() )
|
|
||||||
{
|
|
||||||
fileName += '.' + defaultExt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !fileName.isEmpty() )
|
|
||||||
{
|
|
||||||
mSaveAsLineEdit->setText( fileName );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QgsRasterLayerSaveAsDialog::mSaveAsLineEdit_textChanged( const QString &text )
|
|
||||||
{
|
|
||||||
QPushButton *okButton = mButtonBox->button( QDialogButtonBox::Ok );
|
|
||||||
if ( !okButton )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
okButton->setEnabled( QFileInfo( text ).absoluteDir().exists() );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void QgsRasterLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( const QString & )
|
void QgsRasterLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( const QString & )
|
||||||
{
|
{
|
||||||
//gdal-specific
|
//gdal-specific
|
||||||
@ -327,6 +300,18 @@ void QgsRasterLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( const QStr
|
|||||||
mCreateOptionsWidget->setFormat( outputFormat() );
|
mCreateOptionsWidget->setFormat( outputFormat() );
|
||||||
mCreateOptionsWidget->update();
|
mCreateOptionsWidget->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList extensions = QgsRasterFileWriter::extensionsForFormat( outputFormat() );
|
||||||
|
QString filter;
|
||||||
|
if ( extensions.empty() )
|
||||||
|
filter = tr( "All files (*.*)" );
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filter = QStringLiteral( "%1 (*.%2);;%3" ).arg( mFormatComboBox->currentText(),
|
||||||
|
extensions.join( QStringLiteral( " *." ) ),
|
||||||
|
tr( "All files (*.*)" ) );
|
||||||
|
}
|
||||||
|
mFilename->setFilter( filter );
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsRasterLayerSaveAsDialog::nColumns() const
|
int QgsRasterLayerSaveAsDialog::nColumns() const
|
||||||
@ -371,7 +356,22 @@ bool QgsRasterLayerSaveAsDialog::addToCanvas() const
|
|||||||
|
|
||||||
QString QgsRasterLayerSaveAsDialog::outputFileName() const
|
QString QgsRasterLayerSaveAsDialog::outputFileName() const
|
||||||
{
|
{
|
||||||
return mSaveAsLineEdit->text();
|
QStringList extensions = QgsRasterFileWriter::extensionsForFormat( outputFormat() );
|
||||||
|
QString defaultExt;
|
||||||
|
if ( !extensions.empty() )
|
||||||
|
{
|
||||||
|
defaultExt = extensions.at( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure the user never omits the extension from the file name
|
||||||
|
QString fileName = mFilename->filePath();
|
||||||
|
QFileInfo fi( fileName );
|
||||||
|
if ( !fileName.isEmpty() && fi.suffix().isEmpty() )
|
||||||
|
{
|
||||||
|
fileName += '.' + defaultExt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsRasterLayerSaveAsDialog::outputFormat() const
|
QString QgsRasterLayerSaveAsDialog::outputFormat() const
|
||||||
@ -398,8 +398,7 @@ void QgsRasterLayerSaveAsDialog::hideFormat()
|
|||||||
void QgsRasterLayerSaveAsDialog::hideOutput()
|
void QgsRasterLayerSaveAsDialog::hideOutput()
|
||||||
{
|
{
|
||||||
mSaveAsLabel->hide();
|
mSaveAsLabel->hide();
|
||||||
mSaveAsLineEdit->hide();
|
mFilename->hide();
|
||||||
mBrowseButton->hide();
|
|
||||||
QPushButton *okButton = mButtonBox->button( QDialogButtonBox::Ok );
|
QPushButton *okButton = mButtonBox->button( QDialogButtonBox::Ok );
|
||||||
if ( okButton )
|
if ( okButton )
|
||||||
{
|
{
|
||||||
@ -710,10 +709,14 @@ void QgsRasterLayerSaveAsDialog::mTileModeCheckBox_toggled( bool toggled )
|
|||||||
|
|
||||||
// Show / hide tile options
|
// Show / hide tile options
|
||||||
mTilesGroupBox->show();
|
mTilesGroupBox->show();
|
||||||
|
mFilename->setStorageMode( QgsFileWidget::GetDirectory );
|
||||||
|
mFilename->setDialogTitle( tr( "Select output directory" ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mTilesGroupBox->hide();
|
mTilesGroupBox->hide();
|
||||||
|
mFilename->setStorageMode( QgsFileWidget::SaveFile );
|
||||||
|
mFilename->setDialogTitle( tr( "Select output file" ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,8 +90,6 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void mRawModeRadioButton_toggled( bool );
|
void mRawModeRadioButton_toggled( bool );
|
||||||
void mBrowseButton_clicked();
|
|
||||||
void mSaveAsLineEdit_textChanged( const QString &text );
|
|
||||||
void mFormatComboBox_currentIndexChanged( const QString &text );
|
void mFormatComboBox_currentIndexChanged( const QString &text );
|
||||||
void mResolutionRadioButton_toggled( bool ) { toggleResolutionSize(); }
|
void mResolutionRadioButton_toggled( bool ) { toggleResolutionSize(); }
|
||||||
void mOriginalResolutionPushButton_clicked() { setOriginalResolution(); }
|
void mOriginalResolutionPushButton_clicked() { setOriginalResolution(); }
|
||||||
|
@ -149,7 +149,7 @@
|
|||||||
<item row="1" column="2">
|
<item row="1" column="2">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="mDatabaseEdit">
|
<widget class="QgsFileWidget" name="mDatabase">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@ -161,16 +161,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QToolButton" name="mSelectDatabaseButton">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string><html><head/><body><p>Select an existing or create a new database</p></body></html></string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>…</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="3" column="0">
|
||||||
@ -478,11 +468,16 @@
|
|||||||
<header>qgsscrollarea.h</header>
|
<header>qgsscrollarea.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>QgsFileWidget</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>qgsfilewidget.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>scrollArea</tabstop>
|
<tabstop>scrollArea</tabstop>
|
||||||
<tabstop>mDatabaseEdit</tabstop>
|
<tabstop>mDatabase</tabstop>
|
||||||
<tabstop>mSelectDatabaseButton</tabstop>
|
|
||||||
<tabstop>mTableNameEdit</tabstop>
|
<tabstop>mTableNameEdit</tabstop>
|
||||||
<tabstop>mLayerIdentifierEdit</tabstop>
|
<tabstop>mLayerIdentifierEdit</tabstop>
|
||||||
<tabstop>mLayerDescriptionEdit</tabstop>
|
<tabstop>mLayerDescriptionEdit</tabstop>
|
||||||
|
@ -279,23 +279,23 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLineEdit" name="mFileNameEdit"/>
|
<widget class="QgsFileWidget" name="mFileName"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1" colspan="2">
|
<item row="1" column="1">
|
||||||
<widget class="QComboBox" name="mFileEncoding">
|
<widget class="QComboBox" name="mFileEncoding">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1" colspan="2">
|
<item row="2" column="1">
|
||||||
<widget class="QComboBox" name="mFileFormatComboBox">
|
<widget class="QComboBox" name="mFileFormatComboBox">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1" colspan="2">
|
<item row="3" column="1">
|
||||||
<widget class="QComboBox" name="mGeometryTypeBox">
|
<widget class="QComboBox" name="mGeometryTypeBox">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
@ -305,20 +305,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="1" colspan="2">
|
<item row="4" column="1">
|
||||||
<widget class="QCheckBox" name="mGeometryWithZCheckBox">
|
<widget class="QCheckBox" name="mGeometryWithZCheckBox">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Include Z dimension</string>
|
<string>Include Z dimension</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="2">
|
|
||||||
<widget class="QToolButton" name="mBrowseFileName">
|
|
||||||
<property name="text">
|
|
||||||
<string>...</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@ -331,9 +324,15 @@
|
|||||||
<header location="global">qgsprojectionselectionwidget.h</header>
|
<header location="global">qgsprojectionselectionwidget.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>QgsFileWidget</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>qgsfilewidget.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>mFileNameEdit</tabstop>
|
<tabstop>mFileName</tabstop>
|
||||||
<tabstop>mFileEncoding</tabstop>
|
<tabstop>mFileEncoding</tabstop>
|
||||||
<tabstop>mFileFormatComboBox</tabstop>
|
<tabstop>mFileFormatComboBox</tabstop>
|
||||||
<tabstop>mGeometryTypeBox</tabstop>
|
<tabstop>mGeometryTypeBox</tabstop>
|
||||||
|
@ -107,28 +107,15 @@ datasets with maximum width and height specified below.</string>
|
|||||||
<string>Save as</string>
|
<string>Save as</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy">
|
<property name="buddy">
|
||||||
<cstring>mSaveAsLineEdit</cstring>
|
<cstring>mFilename</cstring>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="mSaveAsLineEdit">
|
<widget class="QgsFileWidget" name="mFilename">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="mBrowseButton">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Browse...</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@ -717,14 +704,19 @@ datasets with maximum width and height specified below.</string>
|
|||||||
<header>qgsrasterpyramidsoptionswidget.h</header>
|
<header>qgsrasterpyramidsoptionswidget.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>QgsFileWidget</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>qgsfilewidget.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>mRawModeRadioButton</tabstop>
|
<tabstop>mRawModeRadioButton</tabstop>
|
||||||
<tabstop>mRenderedModeRadioButton</tabstop>
|
<tabstop>mRenderedModeRadioButton</tabstop>
|
||||||
<tabstop>mFormatComboBox</tabstop>
|
<tabstop>mFormatComboBox</tabstop>
|
||||||
<tabstop>mTileModeCheckBox</tabstop>
|
<tabstop>mTileModeCheckBox</tabstop>
|
||||||
<tabstop>mSaveAsLineEdit</tabstop>
|
<tabstop>mFilename</tabstop>
|
||||||
<tabstop>mBrowseButton</tabstop>
|
|
||||||
<tabstop>mCrsSelector</tabstop>
|
<tabstop>mCrsSelector</tabstop>
|
||||||
<tabstop>mAddToCanvas</tabstop>
|
<tabstop>mAddToCanvas</tabstop>
|
||||||
<tabstop>mScrollArea</tabstop>
|
<tabstop>mScrollArea</tabstop>
|
||||||
|
@ -31,22 +31,12 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="2">
|
<item row="1" column="2">
|
||||||
<widget class="QLineEdit" name="leFilename">
|
<widget class="QgsFileWidget" name="mFilename">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -57,7 +47,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="2" colspan="2">
|
<item row="0" column="2">
|
||||||
<widget class="QComboBox" name="mFormatComboBox"/>
|
<widget class="QComboBox" name="mFormatComboBox"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
@ -66,11 +56,11 @@
|
|||||||
<string>File name</string>
|
<string>File name</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy">
|
<property name="buddy">
|
||||||
<cstring>leFilename</cstring>
|
<cstring>mFilename</cstring>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="2" colspan="2">
|
<item row="3" column="2">
|
||||||
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector" native="true">
|
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector" native="true">
|
||||||
<property name="focusPolicy">
|
<property name="focusPolicy">
|
||||||
<enum>Qt::StrongFocus</enum>
|
<enum>Qt::StrongFocus</enum>
|
||||||
@ -83,11 +73,11 @@
|
|||||||
<string>Layer name</string>
|
<string>Layer name</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy">
|
<property name="buddy">
|
||||||
<cstring>leFilename</cstring>
|
<cstring>leLayername</cstring>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="2" colspan="2">
|
<item row="2" column="2">
|
||||||
<widget class="QLineEdit" name="leLayername">
|
<widget class="QLineEdit" name="leLayername">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
@ -468,11 +458,16 @@
|
|||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>qgsscalewidget.h</header>
|
<header>qgsscalewidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>QgsFileWidget</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>qgsfilewidget.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>mFormatComboBox</tabstop>
|
<tabstop>mFormatComboBox</tabstop>
|
||||||
<tabstop>leFilename</tabstop>
|
<tabstop>mFilename</tabstop>
|
||||||
<tabstop>browseFilename</tabstop>
|
|
||||||
<tabstop>leLayername</tabstop>
|
<tabstop>leLayername</tabstop>
|
||||||
<tabstop>mCrsSelector</tabstop>
|
<tabstop>mCrsSelector</tabstop>
|
||||||
<tabstop>scrollArea</tabstop>
|
<tabstop>scrollArea</tabstop>
|
||||||
|
@ -63,7 +63,7 @@ class TestPyQgsNewGeoPackageLayerDialog(unittest.TestCase):
|
|||||||
dialog = QgsNewGeoPackageLayerDialog()
|
dialog = QgsNewGeoPackageLayerDialog()
|
||||||
dialog.setProperty("hideDialogs", True)
|
dialog.setProperty("hideDialogs", True)
|
||||||
|
|
||||||
mDatabaseEdit = dialog.findChild(QLineEdit, "mDatabaseEdit")
|
mDatabase = dialog.findChild(QLineEdit, "mDatabase")
|
||||||
buttonBox = dialog.findChild(QDialogButtonBox, "buttonBox")
|
buttonBox = dialog.findChild(QDialogButtonBox, "buttonBox")
|
||||||
ok_button = buttonBox.button(QDialogButtonBox.Ok)
|
ok_button = buttonBox.button(QDialogButtonBox.Ok)
|
||||||
mTableNameEdit = dialog.findChild(QLineEdit, "mTableNameEdit")
|
mTableNameEdit = dialog.findChild(QLineEdit, "mTableNameEdit")
|
||||||
@ -86,7 +86,7 @@ class TestPyQgsNewGeoPackageLayerDialog(unittest.TestCase):
|
|||||||
self.assertFalse(ok_button.isEnabled())
|
self.assertFalse(ok_button.isEnabled())
|
||||||
|
|
||||||
dbname = os.path.join(self.basetestpath, 'test.gpkg')
|
dbname = os.path.join(self.basetestpath, 'test.gpkg')
|
||||||
mDatabaseEdit.setText(dbname)
|
mDatabase.setFilePath(dbname)
|
||||||
self.assertEqual(mTableNameEdit.text(), 'test')
|
self.assertEqual(mTableNameEdit.text(), 'test')
|
||||||
self.assertEqual(mLayerIdentifierEdit.text(), 'test')
|
self.assertEqual(mLayerIdentifierEdit.text(), 'test')
|
||||||
self.assertTrue(ok_button.isEnabled())
|
self.assertTrue(ok_button.isEnabled())
|
||||||
@ -261,7 +261,7 @@ class TestPyQgsNewGeoPackageLayerDialog(unittest.TestCase):
|
|||||||
QgsProject.instance().removeAllMapLayers()
|
QgsProject.instance().removeAllMapLayers()
|
||||||
|
|
||||||
# Try invalid path
|
# Try invalid path
|
||||||
mDatabaseEdit.setText('/this/is/invalid/test.gpkg')
|
mDatabase.setFilePath('/this/is/invalid/test.gpkg')
|
||||||
self.accepted = False
|
self.accepted = False
|
||||||
QTest.mouseClick(ok_button, Qt.LeftButton)
|
QTest.mouseClick(ok_button, Qt.LeftButton)
|
||||||
self.assertFalse(self.accepted)
|
self.assertFalse(self.accepted)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user