Skip to content
Permalink
Browse files
add log messages to OGR provider
  • Loading branch information
jef-n committed Nov 26, 2011
1 parent 414729c commit 7c40bf38a193f8e80c0312a44ba8bba14f5d06e8
Showing with 46 additions and 48 deletions.
  1. +3 −2 src/providers/ogr/qgsogrdataitems.cpp
  2. +43 −46 src/providers/ogr/qgsogrprovider.cpp
@@ -16,6 +16,7 @@
#include "qgsogrdataitems.h"

#include "qgslogger.h"
#include "qgsmessagelog.h"

#include <QFileInfo>
#include <QTextStream>
@@ -93,7 +94,7 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
}
else
{
QgsDebugMsg( "Couldn't open file " + layerName + ".prj" );
QgsMessageLog::logMessage( tr( "Couldn't open file %1.prj" ).arg( layerName ), tr( "OGR" ) );
return false;
}
OSRDestroySpatialReference( hSRS );
@@ -109,7 +110,7 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
}
else
{
QgsDebugMsg( "Couldn't open file " + layerName + ".qpj" );
QgsMessageLog::logMessage( tr( "Couldn't open file %1.qpj" ).arg( layerName ), tr( "OGR" ) );
return false;
}

@@ -17,6 +17,7 @@ email : sherman at mrcc.com

#include "qgsogrprovider.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"

#define CPL_SUPRESS_CPLUSPLUS
#include <gdal.h> // to collect version information
@@ -58,7 +59,8 @@ class QgsCPLErrorHandler
{
static void CPL_STDCALL showError( CPLErr errClass, int errNo, const char *msg )
{
QgsLogger::warning( QString( "OGR[%1] error %2: %3" ).arg( errClass ).arg( errNo ).arg( msg ) );
if ( errNo != OGRERR_NONE )
QgsMessageLog::logMessage( QObject::tr( "OGR[%1] error %2: %3" ).arg( errClass ).arg( errNo ).arg( msg ), QObject::tr( "OGR" ) );
}

public:
@@ -189,13 +191,14 @@ QgsVectorLayerImport::ImportError QgsOgrProvider::createEmptyLayer(


QgsOgrProvider::QgsOgrProvider( QString const & uri )
: QgsVectorDataProvider( uri ),
ogrDataSource( 0 ),
extent_( 0 ),
ogrLayer( 0 ),
ogrOrigLayer( 0 ),
ogrDriver( 0 ),
featuresCounted( -1 )
: QgsVectorDataProvider( uri )
, ogrDataSource( 0 )
, extent_( 0 )
, ogrLayer( 0 )
, ogrOrigLayer( 0 )
, ogrDriver( 0 )
, valid( false )
, featuresCounted( -1 )
{
QgsCPLErrorHandler handler;

@@ -272,14 +275,13 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
//TODO is in read-only mode, otherwise edit ops will fail
//TODO: capabilities() should now reflect this; need to test.
}

if ( ogrDataSource )
{

QgsDebugMsg( "Data source is valid" );
QgsDebugMsg( "OGR Driver was " + QString( OGR_Dr_GetName( ogrDriver ) ) );

valid = true;

ogrDriverName = OGR_Dr_GetName( ogrDriver );

// We get the layer which was requested by the uri. The layername
@@ -294,20 +296,14 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
}

ogrLayer = ogrOrigLayer;
if (ogrLayer != NULL )
if ( ogrLayer )
{
setSubsetString( mSubsetString );
}
else
{
valid = false;
valid = setSubsetString( mSubsetString );
}
}
else
{
QgsLogger::critical( "Data source is invalid" );
QgsLogger::critical( QString::fromUtf8( CPLGetLastErrorMsg() ) );
valid = false;
QgsMessageLog::logMessage( tr( "Data source is invalid (%1)" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ), tr( "OGR" ) );
}

// FIXME: sync with app/qgsnewvectorlayerdialog.cpp
@@ -426,10 +422,11 @@ QString QgsOgrProvider::subsetString()
QStringList QgsOgrProvider::subLayers() const
{
QStringList theList = QStringList();
if ( ! valid )
if ( !valid )
{
return theList;
}

for ( unsigned int i = 0; i < layerCount() ; i++ )
{
QString theLayerName = FROM8( OGR_FD_GetName( OGR_L_GetLayerDefn( OGR_DS_GetLayer( ogrDataSource, i ) ) ) );
@@ -630,7 +627,7 @@ bool QgsOgrProvider::nextFeature( QgsFeature& feature )

if ( !valid )
{
QgsLogger::warning( "Read attempt on an invalid shapefile data source" );
QgsMessageLog::logMessage( tr( "Read attempt on an invalid shapefile data source" ), tr( "OGR" ) );
return false;
}

@@ -994,15 +991,15 @@ bool QgsOgrProvider::addFeature( QgsFeature& f )
break;

default:
QgsLogger::warning( "QgsOgrProvider::addFeature, no type found" );
QgsMessageLog::logMessage( tr( "type %1 for attribute %2 not found" ).arg( type ).arg( targetAttributeId ), tr( "OGR" ) );
break;
}
}
}

if ( OGR_L_CreateFeature( ogrLayer, feature ) != OGRERR_NONE )
{
QgsLogger::warning( "Writing of the feature failed" );
QgsMessageLog::logMessage( tr( "Writing of the feature %1 failed" ).arg( f.id() ), tr( "OGR" ) );
returnValue = false;
}
else
@@ -1059,7 +1056,7 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
type = OFTString;
break;
default:
QgsLogger::warning( QString( "QgsOgrProvider::addAttributes, type %1 not found" ).arg( iter->typeName() ) );
QgsMessageLog::logMessage( tr( "type %1 for field %2 not found" ).arg( iter->typeName() ).arg( iter->name() ), tr( "OGR" ) );
returnvalue = false;
continue;
}
@@ -1070,7 +1067,7 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )

if ( OGR_L_CreateField( ogrLayer, fielddefn, true ) != OGRERR_NONE )
{
QgsLogger::warning( "QgsOgrProvider.cpp: writing of field failed" );
QgsMessageLog::logMessage( tr( "writing of field %1 failed" ).arg( iter->name() ), tr( "OGR" ) );
returnvalue = false;
}
OGR_Fld_Destroy( fielddefn );
@@ -1090,7 +1087,7 @@ bool QgsOgrProvider::deleteAttributes( const QgsAttributeIds &attributes )
{
if ( OGR_L_DeleteField( ogrLayer, attr ) != OGRERR_NONE )
{
QgsDebugMsg( "Failed to delete attribute " + QString::number( attr ) );
QgsMessageLog::logMessage( tr( "Failed to delete attribute %1" ).arg( attr ), tr( "OGR" ) );
res = false;
}
}
@@ -1119,15 +1116,15 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr

if ( FID_TO_NUMBER( fid ) > std::numeric_limits<long>::max() )
{
QgsLogger::warning( "QgsOgrProvider::changeAttributeValues, feature id too large for OGR" );
QgsMessageLog::logMessage( tr( "Feature id %1 too large for OGR" ).arg( fid ), tr( "OGR" ) );
continue;
}

OGRFeatureH of = OGR_L_GetFeature( ogrLayer, static_cast<long>( FID_TO_NUMBER( fid ) ) );

if ( !of )
{
QgsLogger::warning( "QgsOgrProvider::changeAttributeValues, Cannot read feature, cannot change attributes" );
QgsMessageLog::logMessage( tr( "Feature %1 for attribute update not found." ).arg( fid ), tr( "OGR" ) );
continue;
}

@@ -1140,7 +1137,7 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
OGRFieldDefnH fd = OGR_F_GetFieldDefnRef( of, f );
if ( !fd )
{
QgsLogger::warning( "QgsOgrProvider::changeAttributeValues, Field " + QString::number( f ) + " doesn't exist" );
QgsMessageLog::logMessage( tr( "Field %1 of feature %2 doesn't exist." ).arg( f ).arg( fid ), tr( "OGR" ) );
continue;
}

@@ -1165,7 +1162,7 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
OGR_F_SetFieldString( of, f, mEncoding->fromUnicode( it2->toString() ).constData() );
break;
default:
QgsLogger::warning( "QgsOgrProvider::changeAttributeValues, Unknown field type, cannot change attribute" );
QgsMessageLog::logMessage( tr( "Type %1 of attribute %2 of feature %3 unknown." ).arg( type ).arg( fid ).arg( f ), tr( "OGR" ) );
break;
}
}
@@ -1174,7 +1171,7 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
OGRErr res;
if (( res = OGR_L_SetFeature( ogrLayer, of ) ) != OGRERR_NONE )
{
QgsLogger::warning( "QgsOgrProvider::changeAttributeValues, setting the feature failed: " + QString::number( res ) );
QgsMessageLog::logMessage( tr( "Update of Feature %1 failed: %2" ).arg( fid ).arg( res ), tr( "OGR" ) );
}
}

@@ -1194,14 +1191,14 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
{
if ( FID_TO_NUMBER( it.key() ) > std::numeric_limits<long>::max() )
{
QgsLogger::warning( "QgsOgrProvider::changeGeometryValues, fid too large for OGR" );
QgsMessageLog::logMessage( tr( "Feature id %1 too large for OGR" ).arg( it.key() ), tr( "OGR" ) );
continue;
}

theOGRFeature = OGR_L_GetFeature( ogrLayer, static_cast<long>( FID_TO_NUMBER( it.key() ) ) );
if ( !theOGRFeature )
{
QgsLogger::warning( "QgsOgrProvider::changeGeometryValues, cannot find feature" );
QgsMessageLog::logMessage( tr( "Feature %1 not found for geometry update." ).arg( it.key() ), tr( "OGR" ) );
continue;
}

@@ -1211,22 +1208,22 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
&theNewGeometry,
it->wkbSize() ) != OGRERR_NONE )
{
QgsLogger::warning( "QgsOgrProvider::changeGeometryValues, error while creating new OGRGeometry" );
QgsMessageLog::logMessage( tr( "Creation of new geometry for feature %1 failed." ).arg( it.key() ), tr( "OGR" ) );
OGR_G_DestroyGeometry( theNewGeometry );
theNewGeometry = 0;
continue;
}

if ( !theNewGeometry )
{
QgsLogger::warning( "QgsOgrProvider::changeGeometryValues, new geometry is NULL" );
QgsMessageLog::logMessage( tr( "Newly created geometry for feature % is null." ).arg( it.key() ), tr( "OGR" ) );
continue;
}

//set the new geometry
if (( res = OGR_F_SetGeometryDirectly( theOGRFeature, theNewGeometry ) ) != OGRERR_NONE )
{
QgsLogger::warning( "QgsOgrProvider::changeGeometryValues, error while replacing geometry: " + QString::number( res ) );
QgsMessageLog::logMessage( tr( "Geometry update for feature %1 failed: %2" ).arg( it.key() ).arg( res ), tr( "OGR" ) );
OGR_G_DestroyGeometry( theNewGeometry );
theNewGeometry = 0;
continue;
@@ -1235,7 +1232,7 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )

if (( res = OGR_L_SetFeature( ogrLayer, theOGRFeature ) ) != OGRERR_NONE )
{
QgsLogger::warning( "QgsOgrProvider::changeGeometryValues, error while setting feature: " + QString::number( res ) );
QgsMessageLog::logMessage( tr( "Update of feature %1 failed: %2" ).arg( it.key() ).arg( res ), tr( "OGR" ) );
OGR_G_DestroyGeometry( theNewGeometry );
theNewGeometry = 0;
continue;
@@ -1317,7 +1314,7 @@ bool QgsOgrProvider::deleteFeature( QgsFeatureId id )
{
if ( FID_TO_NUMBER( id ) > std::numeric_limits<long>::max() )
{
QgsDebugMsg( "id too large for OGR" );
QgsMessageLog::logMessage( tr( "id %1 too large for OGR" ).arg( id ), tr( "OGR" ) );
return false;
}

@@ -1425,7 +1422,7 @@ int QgsOgrProvider::capabilities() const

if ( mAttributeFields.size() == 0 )
{
QgsDebugMsg( "OGR doesn't handle shapefile without attributes well, ie. missing DBFs" );
QgsMessageLog::logMessage( tr( "Shapefiles without attribute are considered read-only." ), tr( "OGR" ) );
ability &= ~( AddFeatures | DeleteFeatures | ChangeAttributeValues | AddAttributes | DeleteAttributes );
}

@@ -1519,7 +1516,7 @@ QString createFilters( QString type )

if ( !driver )
{
QgsLogger::warning( "unable to get driver " + QString::number( i ) );
QgsMessageLog::logMessage( QObject::tr( "Unable to get driver %1" ).arg( i ), QObject::tr( "OGR" ) );
continue;
}

@@ -1705,7 +1702,7 @@ QString createFilters( QString type )
{
// NOP, we don't know anything about the current driver
// with regards to a proper file filter string
QgsDebugMsg( "fileVectorFilters, unknown driver: " + driverName );
QgsDebugMsg( QString( "Unknown driver %1 for file filters." ).arg( driverName ) );
}

} // each loaded GDAL driver
@@ -1874,7 +1871,7 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
QString name = fldIt->first.left( 10 );
if ( fieldNames.contains( name ) )
{
QgsDebugMsg( QString( "duplicate field (10 significant characters): %1" ).arg( name ) );
QgsMessageLog::logMessage( QObject::tr( "Duplicate field (10 significant characters): %1" ).arg( name ), QObject::tr( "OGR" ) );
return false;
}
fieldNames << name;
@@ -1938,7 +1935,7 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
break;
default:
{
QgsDebugMsg( QString( "Unknown vector type of: %1" ).arg(( int )( vectortype ) ) );
QgsMessageLog::logMessage( QObject::tr( "Unknown vector type of %1" ).arg(( int )( vectortype ) ), QObject::tr( "OGR" ) );
return false;
break;
}
@@ -2008,7 +2005,7 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,

if ( OGR_L_CreateField( layer, field, true ) != OGRERR_NONE )
{
QgsLogger::warning( "creation of field failed" );
QgsMessageLog::logMessage( QObject::tr( "creation of field %1 failed" ).arg( it->first ), QObject::tr( "OGR" ) );
}
}

@@ -2026,7 +2023,7 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
}
else
{
QgsDebugMsg( "Couldn't open file " + layerName + ".qpj" );
QgsMessageLog::logMessage( QObject::tr( "Couldn't create file %1.qpj" ).arg( layerName ), QObject::tr( "OGR" ) );
}
}

@@ -2042,7 +2039,7 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,

QgsCoordinateReferenceSystem QgsOgrProvider::crs()
{
QgsDebugMsg( "entering." );
QgsDebugMsg( "Entering." );

QgsCoordinateReferenceSystem srs;

0 comments on commit 7c40bf3

Please sign in to comment.