Skip to content

Commit fb4a658

Browse files
author
mhugent
committed
[FEATURE]: added reload method to map layers and provider interface. Like this, caching providers (currently WMS and WFS) can synchronize with changes in the datasource
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14264 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent dd182b6 commit fb4a658

19 files changed

+110
-14
lines changed

python/core/qgsdataprovider.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ class QgsDataProvider : QObject
178178
*/
179179
virtual QString fileRasterFilters() const;
180180

181+
/**Reloads the data from the the source. Needs to be implemented by providers with data caches to
182+
synchronize with changes in the data source*/
183+
virtual void reloadData();
184+
181185
signals:
182186

183187
/**

python/core/qgsmaplayer.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public:
7070
*/
7171
const QString & name() const;
7272

73+
/**Synchronises with changes in the datasource
74+
@note added in version 1.6*/
75+
virtual void reload();
76+
7377
/** Render the layer, to be overridden in child classes
7478
*/
7579
virtual bool draw(QgsRenderContext& rendererContext);

python/core/qgsmaplayerregistry.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public:
6767
*/
6868
void clearAllLayerCaches();
6969

70+
/**Reload all provider data caches (currently used for WFS and WMS providers)
71+
@note: this method was added in QGIS 1.6*/
72+
void reloadAllLayers();
73+
7074
signals:
7175

7276
/** emitted when a layer is removed from the registry

python/core/qgsrasterlayer.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ public:
303303
/** Returns the data provider in a const-correct manner */
304304
//const QgsRasterDataProvider* dataProvider() const;
305305

306+
/**Synchronises with changes in the datasource
307+
@note added in version 1.6*/
308+
virtual void reload();
309+
306310
/** \brief This is called when the view on the raster layer needs to be redrawn */
307311
bool draw( QgsRenderContext& rendererContext );
308312

python/core/qgsvectorlayer.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ public:
333333
int snapWithContext(const QgsPoint& startPoint, double snappingTolerance, QMultiMap<double, QgsSnappingResult>& snappingResults /Out/,
334334
QgsSnapper::SnappingType snap_to);
335335

336+
/**Synchronises with changes in the datasource
337+
@note added in version 1.6*/
338+
virtual void reload();
339+
336340
/** Draws the layer using coordinate transformation
337341
* @return FALSE if an error occurred during drawing
338342
*/

src/app/qgisapp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4706,6 +4706,8 @@ void QgisApp::refreshMapCanvas()
47064706
{
47074707
//clear all caches first
47084708
QgsMapLayerRegistry::instance()->clearAllLayerCaches();
4709+
//reload cached provider data
4710+
QgsMapLayerRegistry::instance()->reloadAllLayers();
47094711
//then refresh
47104712
mMapCanvas->refresh();
47114713
}

src/core/qgsdataprovider.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ class CORE_EXPORT QgsDataProvider : public QObject
267267
return "";
268268
}
269269

270+
/**Reloads the data from the the source. Needs to be implemented by providers with data caches to
271+
synchronize with changes in the data source*/
272+
virtual void reloadData() {}
273+
270274
signals:
271275

272276
/**

src/core/qgsmaplayer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ class CORE_EXPORT QgsMapLayer : public QObject
7979
*/
8080
QString const & name() const;
8181

82+
/**Synchronises with changes in the datasource
83+
@note added in version 1.6*/
84+
virtual void reload() {}
85+
8286
/** This is the method that does the actual work of
8387
* drawing the layer onto a paint device.
8488
* @param QgsRenderContext - describes the extents,

src/core/qgsmaplayerregistry.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "qgsmaplayer.h"
2323
#include "qgslogger.h"
2424

25-
2625
//
2726
// Static calls to enforce singleton behaviour
2827
//
@@ -128,6 +127,19 @@ void QgsMapLayerRegistry::clearAllLayerCaches()
128127
}
129128
} // QgsMapLayerRegistry::clearAllLayerCaches()
130129

130+
void QgsMapLayerRegistry::reloadAllLayers()
131+
{
132+
QMap<QString, QgsMapLayer *>::iterator it;
133+
for ( it = mMapLayers.begin(); it != mMapLayers.end() ; ++it )
134+
{
135+
QgsMapLayer* layer = it.value();
136+
if ( layer )
137+
{
138+
layer->reload();
139+
}
140+
}
141+
}
142+
131143
QMap<QString, QgsMapLayer*> & QgsMapLayerRegistry::mapLayers()
132144
{
133145
return mMapLayers;

src/core/qgsmaplayerregistry.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject
8989
* @note this method was added in QGIS 1.4
9090
*/
9191
void clearAllLayerCaches();
92+
93+
/**Reload all provider data caches (currently used for WFS and WMS providers)
94+
@note: this method was added in QGIS 1.6*/
95+
void reloadAllLayers();
96+
9297
signals:
9398

9499
/** emitted when a layer is removed from the registry

0 commit comments

Comments
 (0)