Skip to content

Commit aeeca48

Browse files
committedAug 29, 2015
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
1 parent 812b012 commit aeeca48

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed
 

‎python/core/qgsvectordataprovider.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ class QgsVectorDataProvider : QgsDataProvider
320320
*/
321321
virtual QgsTransaction* transaction() const;
322322

323+
virtual void forceReload();
324+
323325
protected:
324326
void clearMinMaxCache();
325327
void fillMinMaxCache();

‎src/core/qgsvectordataprovider.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,15 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
371371
*/
372372
virtual QgsTransaction* transaction() const { return 0; }
373373

374+
/**
375+
* Forces a reload of the underlying datasource if the provider implements this
376+
* method.
377+
* In particular on the OGR provider, a pooled connection will be invalidated.
378+
* This forces QGIS to reopen a file or connection.
379+
* This can be required if the underlying file is replaced.
380+
*/
381+
virtual void forceReload() {}
382+
374383
protected:
375384
void clearMinMaxCache();
376385
void fillMinMaxCache();

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,6 +2439,11 @@ QByteArray QgsOgrProvider::quotedIdentifier( QByteArray field )
24392439
return QgsOgrUtils::quotedIdentifier( field, ogrDriverName );
24402440
}
24412441

2442+
void QgsOgrProvider::forceReload()
2443+
{
2444+
QgsOgrConnPool::instance()->invalidateConnections( filePath() );
2445+
}
2446+
24422447
QByteArray QgsOgrUtils::quotedIdentifier( QByteArray field, const QString& ogrDriverName )
24432448
{
24442449
if ( ogrDriverName == "MySQL" )

‎src/providers/ogr/qgsogrprovider.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@ class QgsOgrProvider : public QgsVectorDataProvider
263263

264264
QByteArray quotedIdentifier( QByteArray field );
265265

266+
/**
267+
* A forced reload invalidates the underlying connection.
268+
* E.g. in case a shapefile is replaced, the old file will be closed
269+
* and the new file will be opened.
270+
*/
271+
void forceReload();
272+
266273
protected:
267274
/** Loads fields from input file to member attributeFields */
268275
void loadFields();

0 commit comments

Comments
 (0)
Please sign in to comment.