Skip to content

Commit

Permalink
Merge pull request #46992 from pblottiere/envi_saveas
Browse files Browse the repository at this point in the history
Fix output filename when a raster is saved in a format without extension
  • Loading branch information
pblottiere committed Jan 26, 2022
2 parents fd00dd4 + 7d6b3f1 commit dbbf8da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/gui/qgsrasterlayersaveasdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ QString QgsRasterLayerSaveAsDialog::outputFileName() const

// ensure the user never omits the extension from the file name
QFileInfo fi( fileName );
if ( !fileName.isEmpty() && fi.suffix().isEmpty() )
if ( !fileName.isEmpty() && fi.suffix().isEmpty() && !defaultExt.isEmpty() )
{
fileName += '.' + defaultExt;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/src/gui/testqgsrasterlayersaveasdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class TestQgsRasterLayerSaveAsDialog : public QObject
void init(); // will be called before each testfunction is executed.
void cleanup(); // will be called after every testfunction.
void outputLayerExists();
void filenameWhenNoExtension();

private:

Expand Down Expand Up @@ -146,6 +147,24 @@ QString TestQgsRasterLayerSaveAsDialog::prepareDb()
return tmpFile.fileName( );
}

void TestQgsRasterLayerSaveAsDialog::filenameWhenNoExtension()
{
// Try to add a raster layer to the DB
const QString dataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
const QString rasterPath { dataDir + "/landsat.tif" };

QgsRasterLayer rl( rasterPath, QStringLiteral( "my_raster" ) );
QVERIFY( rl.isValid() );

QgsRasterLayerSaveAsDialog d( &rl, rl.dataProvider(), rl.extent(), rl.crs(), rl.crs() );
d.mFormatComboBox->setCurrentIndex( d.mFormatComboBox->findData( QStringLiteral( "ENVI" ) ) );
QCOMPARE( d.mFormatComboBox->currentData().toString(), QString( "ENVI" ) );

const QString filename = "filename_without_extension";
d.mFilename->setFilePath( filename );
QCOMPARE( d.outputFileName(), filename );
}

QGSTEST_MAIN( TestQgsRasterLayerSaveAsDialog )

#include "testqgsrasterlayersaveasdialog.moc"

0 comments on commit dbbf8da

Please sign in to comment.