[QGIS Commit] r8694 - in trunk/qgis/src: app core/raster
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Jun 30 12:03:41 EDT 2008
Author: warmerdam
Date: 2008-06-30 12:03:41 -0400 (Mon, 30 Jun 2008)
New Revision: 8694
Modified:
trunk/qgis/src/app/qgisapp.cpp
trunk/qgis/src/core/raster/qgsrasterlayer.cpp
trunk/qgis/src/core/raster/qgsrasterlayer.h
Log:
improve error propagation for raster open errors (#1040)
Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp 2008-06-30 14:36:54 UTC (rev 8693)
+++ trunk/qgis/src/app/qgisapp.cpp 2008-06-30 16:03:41 UTC (rev 8694)
@@ -3126,6 +3126,7 @@
bool QgisApp::openLayer(const QString & fileName)
{
QFileInfo fileInfo(fileName);
+
// try to load it as raster
QgsMapLayer* ok = NULL;
CPLPushErrorHandler(CPLQuietErrorHandler);
@@ -5323,7 +5324,9 @@
myIterator != theFileNameQStringList.end();
++myIterator)
{
- if (QgsRasterLayer::isValidRasterFileName(*myIterator))
+ QString errMsg;
+
+ if (QgsRasterLayer::isValidRasterFileName(*myIterator,errMsg))
{
QFileInfo myFileInfo(*myIterator);
// get the directory the .adf file was in
@@ -5356,6 +5359,10 @@
if(guiWarning)
{
QString msg(*myIterator + tr(" is not a supported raster data source"));
+
+ if( errMsg.size() > 0 )
+ msg += "\n" + errMsg;
+
QMessageBox::critical(this, tr("Unsupported Data Source"), msg);
}
returnValue = false;
Modified: trunk/qgis/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.cpp 2008-06-30 14:36:54 UTC (rev 8693)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.cpp 2008-06-30 16:03:41 UTC (rev 8694)
@@ -255,22 +255,28 @@
/** This helper checks to see whether the filename appears to be a valid raster file name */
-bool QgsRasterLayer::isValidRasterFileName(QString const & theFileNameQString)
+bool QgsRasterLayer::isValidRasterFileName(QString const & theFileNameQString,
+ QString & retErrMsg )
{
GDALDatasetH myDataset;
registerGdalDrivers();
+ CPLErrorReset();
+
//open the file using gdal making sure we have handled locale properly
myDataset = GDALOpen( QFile::encodeName(theFileNameQString).constData(), GA_ReadOnly );
if( myDataset == NULL )
{
+ if( CPLGetLastErrorNo() != CPLE_OpenFailed )
+ retErrMsg = CPLGetLastErrorMsg();
return false;
}
else if( GDALGetRasterCount( myDataset ) == 0 )
{
GDALClose( myDataset );
myDataset = NULL;
+ retErrMsg = "This raster file has no bands and is invalid as a raster layer.";
return false;
}
else
@@ -280,7 +286,15 @@
}
}
+bool QgsRasterLayer::isValidRasterFileName(QString const & theFileNameQString)
+{
+ QString retErrMsg;
+
+ return isValidRasterFileName( theFileNameQString, retErrMsg);
+}
+
+
//////////////////////////////////////////////////////////
//
// Non Static methods now....
Modified: trunk/qgis/src/core/raster/qgsrasterlayer.h
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.h 2008-06-30 14:36:54 UTC (rev 8693)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.h 2008-06-30 16:03:41 UTC (rev 8694)
@@ -189,7 +189,12 @@
static void registerGdalDrivers();
/** This helper checks to see whether the filename appears to be a valid
- raster file name */
+ raster file name. If the filename looks like it could be valid,
+ but some sort of error occurs in processing the file, the error is
+ returned in retError. */
+ static bool isValidRasterFileName(const QString & theFileNameQString,
+ QString &retError );
+
static bool isValidRasterFileName(const QString & theFileNameQString);
//
More information about the QGIS-commit
mailing list