Skip to content
Permalink
Browse files
Fix for bug 2142: rasters saved without extension
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12245 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 24, 2009
1 parent 93467e4 commit c404848bb453ae0ac1f6988c6752909d1b0e1f0a
@@ -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;

@@ -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;
}

}
}
}
@@ -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
@@ -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 c404848

Please sign in to comment.