Skip to content
Permalink
Browse files

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
  • Loading branch information
m-kuhn committed Aug 29, 2015
1 parent 812b012 commit aeeca48ac92df662443d69e5fa0c41983e1f3e54
@@ -320,6 +320,8 @@ class QgsVectorDataProvider : QgsDataProvider
*/
virtual QgsTransaction* transaction() const;

virtual void forceReload();

protected:
void clearMinMaxCache();
void fillMinMaxCache();
@@ -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();
@@ -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" )
@@ -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();

0 comments on commit aeeca48

Please sign in to comment.
You can’t perform that action at this time.