@@ -1059,6 +1059,30 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
1059
1059
return returnvalue;
1060
1060
}
1061
1061
1062
+ bool QgsOgrProvider::deleteAttributes ( const QgsAttributeIds &attributes )
1063
+ {
1064
+ #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1900
1065
+ bool res = true ;
1066
+ QList<int > attrsLst = attributes.toList ();
1067
+ // sort in descending order
1068
+ qSort ( attrsLst.begin (), attrsLst.end (), qGreater<int >() );
1069
+ foreach ( int attr, attrsLst )
1070
+ {
1071
+ if ( OGR_L_DeleteField ( ogrLayer, attr ) != OGRERR_NONE )
1072
+ {
1073
+ QgsDebugMsg ( " Failed to delete attribute " + QString::number ( attr ) );
1074
+ res = false ;
1075
+ }
1076
+ }
1077
+ loadFields ();
1078
+ return res;
1079
+ #else
1080
+ QgsDebugMsg ( " Deleting fields is supported only from GDAL >= 1.9.0" );
1081
+ return false ;
1082
+ #endif
1083
+ }
1084
+
1085
+
1062
1086
bool QgsOgrProvider::changeAttributeValues ( const QgsChangedAttributesMap & attr_map )
1063
1087
{
1064
1088
if ( attr_map.isEmpty () )
@@ -1362,17 +1386,20 @@ int QgsOgrProvider::capabilities() const
1362
1386
}
1363
1387
#endif
1364
1388
1389
+ if ( OGR_L_TestCapability ( ogrLayer, " CreateField" ) )
1390
+ {
1391
+ ability |= AddAttributes;
1392
+ }
1393
+
1394
+ if ( OGR_L_TestCapability ( ogrLayer, " DeleteField" ) )
1395
+ {
1396
+ ability |= DeleteAttributes;
1397
+ }
1398
+
1365
1399
// OGR doesn't handle shapefiles without attributes, ie. missing DBFs well, fixes #803
1366
1400
if ( ogrDriverName == " ESRI Shapefile" )
1367
1401
{
1368
- #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1260
1369
- // test for Shapefile type and GDAL >= 1.2.6
1370
1402
ability |= CreateSpatialIndex;
1371
- #endif
1372
- #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1600
1373
- // adding attributes was added in GDAL 1.6
1374
- ability |= AddAttributes;
1375
- #endif
1376
1403
ability |= CreateAttributeIndex;
1377
1404
1378
1405
if ( mAttributeFields .size () == 0 )
0 commit comments