[QGIS Commit] r12245 - in trunk/qgis/src/plugins: interpolation raster_terrain_analysis

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Nov 24 16:00:33 EST 2009


Author: mhugent
Date: 2009-11-24 16:00:32 -0500 (Tue, 24 Nov 2009)
New Revision: 12245

Modified:
   trunk/qgis/src/plugins/interpolation/qgsinterpolationdialog.cpp
   trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.cpp
   trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.h
Log:
Fix for bug 2142: rasters saved without extension

Modified: trunk/qgis/src/plugins/interpolation/qgsinterpolationdialog.cpp
===================================================================
--- trunk/qgis/src/plugins/interpolation/qgsinterpolationdialog.cpp	2009-11-24 20:18:28 UTC (rev 12244)
+++ trunk/qgis/src/plugins/interpolation/qgsinterpolationdialog.cpp	2009-11-24 21:00:32 UTC (rev 12245)
@@ -116,6 +116,13 @@
     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;
 

Modified: trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.cpp	2009-11-24 20:18:28 UTC (rev 12244)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.cpp	2009-11-24 21:00:32 UTC (rev 12245)
@@ -60,6 +60,31 @@
       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::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

Modified: trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.h	2009-11-24 20:18:28 UTC (rev 12244)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.h	2009-11-24 21:00:32 UTC (rev 12245)
@@ -42,6 +42,9 @@
 
   private:
     QgisInterface* mIface;
+
+    /**Stores relation between driver name and extension*/
+    QMap<QString, QString> mDriverExtensionMap;
 };
 
 #endif // QGSRASTERTERRAINANALYSISDIALOG_H



More information about the QGIS-commit mailing list