Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[bugfix][ogr] Recompute capabilities when subsetfilter is set
Need to re-open in rw mode if mDynamicWriteAccess
  • Loading branch information
elpaso committed Jan 5, 2018
1 parent dd60fcd commit 3edc547
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -607,7 +607,7 @@ bool QgsOgrProvider::setSubsetString( const QString &theSQL, bool updateFeatureC
invalidateCachedExtent( false );

// Changing the filter may change capabilities
computeCapabilities();
emit capabilitiesNeedUpdate();

emit dataChanged();

Expand Down Expand Up @@ -2186,10 +2186,19 @@ QgsVectorDataProvider::Capabilities QgsOgrProvider::capabilities() const
void QgsOgrProvider::computeCapabilities()
{
QgsVectorDataProvider::Capabilities ability = nullptr;
bool updateModeActivated = false;

// collect abilities reported by OGR
if ( mOgrLayer )
{

// We want the layer in rw mode or capabilities will be wrong
// If mUpdateModeStackDepth > 0, it means that an updateMode is already active and that we have write access
if ( mUpdateModeStackDepth == 0 )
{
updateModeActivated = _enterUpdateMode( true );
}

// Whilst the OGR documentation (e.g. at
// http://www.gdal.org/ogr/classOGRLayer.html#a17) states "The capability
// codes that can be tested are represented as strings, but #defined
Expand Down Expand Up @@ -2318,6 +2327,9 @@ void QgsOgrProvider::computeCapabilities()
}
}

if ( updateModeActivated )
leaveUpdateMode();

mCapabilities = ability;
}

Expand Down Expand Up @@ -4038,6 +4050,13 @@ void QgsOgrProvider::open( OpenMode mode )
}
}

// Connect
if ( mode == OpenModeInitial )
connect( this, &QgsOgrProvider::capabilitiesNeedUpdate, this, [ = ]
{
computeCapabilities();
} );

// For debug/testing purposes
if ( !mValid )
setProperty( "_debug_open_mode", "invalid" );
Expand Down
5 changes: 5 additions & 0 deletions src/providers/ogr/qgsogrprovider.h
Expand Up @@ -309,6 +309,11 @@ class QgsOgrProvider : public QgsVectorDataProvider
void setupProxy();
#endif

signals:

//! Emitted when capabilities need to be re-computed
void capabilitiesNeedUpdate( );

};

/**
Expand Down

0 comments on commit 3edc547

Please sign in to comment.