@@ -607,7 +607,7 @@ bool QgsOgrProvider::setSubsetString( const QString &theSQL, bool updateFeatureC
607
607
invalidateCachedExtent ( false );
608
608
609
609
// Changing the filter may change capabilities
610
- computeCapabilities ();
610
+ emit capabilitiesNeedUpdate ();
611
611
612
612
emit dataChanged ();
613
613
@@ -2186,10 +2186,19 @@ QgsVectorDataProvider::Capabilities QgsOgrProvider::capabilities() const
2186
2186
void QgsOgrProvider::computeCapabilities ()
2187
2187
{
2188
2188
QgsVectorDataProvider::Capabilities ability = nullptr ;
2189
+ bool updateModeActivated = false ;
2189
2190
2190
2191
// collect abilities reported by OGR
2191
2192
if ( mOgrLayer )
2192
2193
{
2194
+
2195
+ // We want the layer in rw mode or capabilities will be wrong
2196
+ // If mUpdateModeStackDepth > 0, it means that an updateMode is already active and that we have write access
2197
+ if ( mUpdateModeStackDepth == 0 )
2198
+ {
2199
+ updateModeActivated = _enterUpdateMode ( true );
2200
+ }
2201
+
2193
2202
// Whilst the OGR documentation (e.g. at
2194
2203
// http://www.gdal.org/ogr/classOGRLayer.html#a17) states "The capability
2195
2204
// codes that can be tested are represented as strings, but #defined
@@ -2318,6 +2327,9 @@ void QgsOgrProvider::computeCapabilities()
2318
2327
}
2319
2328
}
2320
2329
2330
+ if ( updateModeActivated )
2331
+ leaveUpdateMode ();
2332
+
2321
2333
mCapabilities = ability;
2322
2334
}
2323
2335
@@ -4038,6 +4050,13 @@ void QgsOgrProvider::open( OpenMode mode )
4038
4050
}
4039
4051
}
4040
4052
4053
+ // Connect
4054
+ if ( mode == OpenModeInitial )
4055
+ connect ( this , &QgsOgrProvider::capabilitiesNeedUpdate, this , [ = ]
4056
+ {
4057
+ computeCapabilities ();
4058
+ } );
4059
+
4041
4060
// For debug/testing purposes
4042
4061
if ( !mValid )
4043
4062
setProperty ( " _debug_open_mode" , " invalid" );
0 commit comments