Skip to content

Commit f5b10ba

Browse files
committedJan 21, 2015
Merge pull request #1752 from mhugo/fix_11948
Test for write access mode for editing capabilities
2 parents 678f1ab + 3ce5275 commit f5b10ba

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed
 

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
268268
, valid( false )
269269
, featuresCounted( -1 )
270270
, mDataModified( false )
271+
, mWriteAccess( false )
271272
{
272273
QgsCPLErrorHandler handler;
273274

@@ -368,7 +369,11 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
368369
if ( !openReadOnly )
369370
ogrDataSource = OGROpen( TO8F( mFilePath ), true, &ogrDriver );
370371

371-
if ( !ogrDataSource )
372+
if ( ogrDataSource )
373+
{
374+
mWriteAccess = true;
375+
}
376+
else
372377
{
373378
QgsDebugMsg( "OGR failed to opened in update mode, trying in read-only mode" );
374379

@@ -1446,19 +1451,19 @@ int QgsOgrProvider::capabilities() const
14461451
ability |= QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
14471452
}
14481453

1449-
if ( OGR_L_TestCapability( ogrLayer, "SequentialWrite" ) )
1454+
if ( mWriteAccess && OGR_L_TestCapability( ogrLayer, "SequentialWrite" ) )
14501455
// true if the CreateFeature() method works for this layer.
14511456
{
14521457
ability |= QgsVectorDataProvider::AddFeatures;
14531458
}
14541459

1455-
if ( OGR_L_TestCapability( ogrLayer, "DeleteFeature" ) )
1460+
if ( mWriteAccess && OGR_L_TestCapability( ogrLayer, "DeleteFeature" ) )
14561461
// true if this layer can delete its features
14571462
{
14581463
ability |= DeleteFeatures;
14591464
}
14601465

1461-
if ( OGR_L_TestCapability( ogrLayer, "RandomWrite" ) )
1466+
if ( mWriteAccess && OGR_L_TestCapability( ogrLayer, "RandomWrite" ) )
14621467
// true if the SetFeature() method is operational on this layer.
14631468
{
14641469
// TODO According to http://shapelib.maptools.org/ (Shapefile C Library V1.2)
@@ -1506,12 +1511,12 @@ int QgsOgrProvider::capabilities() const
15061511
}
15071512
#endif
15081513

1509-
if ( OGR_L_TestCapability( ogrLayer, "CreateField" ) )
1514+
if ( mWriteAccess && OGR_L_TestCapability( ogrLayer, "CreateField" ) )
15101515
{
15111516
ability |= AddAttributes;
15121517
}
15131518

1514-
if ( OGR_L_TestCapability( ogrLayer, "DeleteField" ) )
1519+
if ( mWriteAccess && OGR_L_TestCapability( ogrLayer, "DeleteField" ) )
15151520
{
15161521
ability |= DeleteAttributes;
15171522
}

‎src/providers/ogr/qgsogrprovider.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ class QgsOgrProvider : public QgsVectorDataProvider
344344
OGRLayerH setSubsetString( OGRLayerH layer, OGRDataSourceH ds );
345345

346346
friend class QgsOgrFeatureSource;
347+
348+
/** whether the file is opened in write mode*/
349+
bool mWriteAccess;
347350
};
348351

349352

0 commit comments

Comments
 (0)
Please sign in to comment.