diff --git a/python/core/qgsvectordataprovider.sip b/python/core/qgsvectordataprovider.sip index 57d62c8fee5..662f630a0c4 100644 --- a/python/core/qgsvectordataprovider.sip +++ b/python/core/qgsvectordataprovider.sip @@ -320,6 +320,8 @@ class QgsVectorDataProvider : QgsDataProvider */ virtual QgsTransaction* transaction() const; + virtual void forceReload(); + protected: void clearMinMaxCache(); void fillMinMaxCache(); diff --git a/src/core/qgsvectordataprovider.h b/src/core/qgsvectordataprovider.h index 93df50adf7b..0518558d41c 100644 --- a/src/core/qgsvectordataprovider.h +++ b/src/core/qgsvectordataprovider.h @@ -371,6 +371,15 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider */ virtual QgsTransaction* transaction() const { return 0; } + /** + * Forces a reload of the underlying datasource if the provider implements this + * method. + * In particular on the OGR provider, a pooled connection will be invalidated. + * This forces QGIS to reopen a file or connection. + * This can be required if the underlying file is replaced. + */ + virtual void forceReload() {} + protected: void clearMinMaxCache(); void fillMinMaxCache(); diff --git a/src/providers/ogr/qgsogrprovider.cpp b/src/providers/ogr/qgsogrprovider.cpp index d759b3774cd..c849b5a79c2 100644 --- a/src/providers/ogr/qgsogrprovider.cpp +++ b/src/providers/ogr/qgsogrprovider.cpp @@ -2439,6 +2439,11 @@ QByteArray QgsOgrProvider::quotedIdentifier( QByteArray field ) return QgsOgrUtils::quotedIdentifier( field, ogrDriverName ); } +void QgsOgrProvider::forceReload() +{ + QgsOgrConnPool::instance()->invalidateConnections( filePath() ); +} + QByteArray QgsOgrUtils::quotedIdentifier( QByteArray field, const QString& ogrDriverName ) { if ( ogrDriverName == "MySQL" ) diff --git a/src/providers/ogr/qgsogrprovider.h b/src/providers/ogr/qgsogrprovider.h index 4a35280c430..a88869451f0 100644 --- a/src/providers/ogr/qgsogrprovider.h +++ b/src/providers/ogr/qgsogrprovider.h @@ -263,6 +263,13 @@ class QgsOgrProvider : public QgsVectorDataProvider QByteArray quotedIdentifier( QByteArray field ); + /** + * A forced reload invalidates the underlying connection. + * E.g. in case a shapefile is replaced, the old file will be closed + * and the new file will be opened. + */ + void forceReload(); + protected: /** Loads fields from input file to member attributeFields */ void loadFields();