Provide a public API for invalidating connections.

QgsVectorDataProvider::forceReload() is the virtual method. It is implemented
in the OGR provider.
See here for reference:
http://gis.stackexchange.com/questions/159950/make-a-qgis-layer-update-from-a-changed-data-source
This commit is contained in:
Matthias Kuhn 2015-08-29 20:50:58 +02:00
parent 812b01238f
commit aeeca48ac9
4 changed files with 23 additions and 0 deletions

View File

@ -320,6 +320,8 @@ class QgsVectorDataProvider : QgsDataProvider
*/
virtual QgsTransaction* transaction() const;
virtual void forceReload();
protected:
void clearMinMaxCache();
void fillMinMaxCache();

View File

@ -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();

View File

@ -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" )

View File

@ -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();