Skip to content

Commit

Permalink
[georef] Don't allow overwriting input raster (fix #3804)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 21, 2015
1 parent cb34348 commit f3d032a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions src/plugins/georeferencer/qgstransformsettingsdialog.cpp
Expand Up @@ -29,7 +29,7 @@
QgsTransformSettingsDialog::QgsTransformSettingsDialog( const QString &raster, const QString &output,
int countGCPpoints, QWidget *parent )
: QDialog( parent )
, mModifiedRaster( raster )
, mSourceRasterFile( raster )
, mCountGCPpoints( countGCPpoints )
{
setupUi( this );
Expand Down Expand Up @@ -159,12 +159,19 @@ void QgsTransformSettingsDialog::accept()
{
//if the file path is relative, make it relative to the raster file directory
QString outputRasterName = leOutputRaster->text();
QFileInfo rasterFileInfo( mModifiedRaster );
QFileInfo rasterFileInfo( mSourceRasterFile );
QFileInfo outputFileInfo( rasterFileInfo.absoluteDir(), outputRasterName );

if ( outputFileInfo.fileName().isEmpty() || !outputFileInfo.dir().exists() )
{
QMessageBox::warning( this, tr( "Info" ), tr( "Invalid output file name" ) );
QMessageBox::warning( this, tr( "Destination Raster" ), tr( "Invalid output file name." ) );
leOutputRaster->setFocus();
return;
}
if ( outputFileInfo.filePath() == mSourceRasterFile )
{
//can't overwrite input file
QMessageBox::warning( this, tr( "Destination Raster" ), tr( "Input raster can not be overwritten." ) );
leOutputRaster->setFocus();
return;
}
Expand Down Expand Up @@ -193,10 +200,14 @@ void QgsTransformSettingsDialog::accept()

void QgsTransformSettingsDialog::on_tbnOutputRaster_clicked()
{
QString selectedFile = generateModifiedRasterFileName( mModifiedRaster );
QString rasterFileName = QFileDialog::getSaveFileName( this, tr( "Save raster" ),
selectedFile, "GeoTIFF (*.tif *.tiff *.TIF *.TIFF)" );
QString selectedFile = leOutputRaster->text();
if ( selectedFile.isEmpty() )
{
selectedFile = generateModifiedRasterFileName( mSourceRasterFile );
}

QString rasterFileName = QFileDialog::getSaveFileName( this, tr( "Destination Raster" ),
selectedFile, "GeoTIFF (*.tif *.tiff *.TIF *.TIFF)" );
if ( rasterFileName.isEmpty() )
return;

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/georeferencer/qgstransformsettingsdialog.h
Expand Up @@ -53,7 +53,7 @@ class QgsTransformSettingsDialog : public QDialog, private Ui::QgsTransformSetti
bool checkGCPpoints( int count, int &minGCPpoints );
QString generateModifiedRasterFileName( const QString &raster );

QString mModifiedRaster;
QString mSourceRasterFile;

int mCountGCPpoints;

Expand Down

0 comments on commit f3d032a

Please sign in to comment.