Skip to content

Commit

Permalink
Fix for bug 2142: rasters saved without extension
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@12245 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 24, 2009
1 parent 48a80c7 commit 849546b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/plugins/interpolation/qgsinterpolationdialog.cpp
Expand Up @@ -116,6 +116,13 @@ void QgsInterpolationDialog::on_buttonBox_accepted()
return;
}

//add .asc suffix if the user did not provider it already
QString suffix = theFileInfo.suffix();
if ( suffix.isEmpty() )
{
fileName.append( ".asc" );
}

int nLayers = mLayersTreeWidget->topLevelItemCount();
QList< QgsInterpolator::LayerData > inputLayerList;

Expand Down
Expand Up @@ -60,6 +60,31 @@ QgsRasterTerrainAnalysisDialog::QgsRasterTerrainAnalysisDialog( QgisInterface* i
if ( CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, FALSE ) )
{
mOutputFormatComboBox->addItem( GDALGetDriverLongName( driver ), QVariant( GDALGetDriverShortName( driver ) ) );

//store the driver shortnames and the corresponding extensions
//(just in case the user does not give an extension for the output file name)
int index = 0;
while (( driverMetadata ) && driverMetadata[index] != 0 )
{
QStringList metadataTokens = QString( driverMetadata[index] ).split( "=", QString::SkipEmptyParts );
if ( metadataTokens.size() < 1 )
{
break;
}

if ( metadataTokens[0] == "DMD_EXTENSION" )
{
if ( metadataTokens.size() < 2 )
{
++index;
continue;
}
mDriverExtensionMap.insert( QString( GDALGetDriverShortName( driver ) ), metadataTokens[1] );
break;
}
++index;
}

}
}
}
Expand Down Expand Up @@ -107,7 +132,29 @@ QString QgsRasterTerrainAnalysisDialog::selectedDriverKey() const

QString QgsRasterTerrainAnalysisDialog::selectedOuputFilePath() const
{
return mOutputLayerLineEdit->text();
QString outputFileName = mOutputLayerLineEdit->text();
QFileInfo fileInfo( outputFileName );
QString suffix = fileInfo.suffix();
if ( !suffix.isEmpty() )
{
return outputFileName;
}

//add the file format extension if the user did not specify it
int index = mOutputFormatComboBox->currentIndex();
if ( index == -1 )
{
return outputFileName;
}

QString driverShortName = mOutputFormatComboBox->itemData( index ).toString();
QMap<QString, QString>::const_iterator it = mDriverExtensionMap.find( driverShortName );
if ( it == mDriverExtensionMap.constEnd() )
{
return outputFileName;
}

return ( outputFileName + "." + it.value() );
}

bool QgsRasterTerrainAnalysisDialog::addLayerToProject() const
Expand Down
Expand Up @@ -42,6 +42,9 @@ class QgsRasterTerrainAnalysisDialog: public QDialog, private Ui::QgsRasterTerra

private:
QgisInterface* mIface;

/**Stores relation between driver name and extension*/
QMap<QString, QString> mDriverExtensionMap;
};

#endif // QGSRASTERTERRAINANALYSISDIALOG_H

0 comments on commit 849546b

Please sign in to comment.