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

src/core/qgsvectorlayer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,14 @@ void QgsVectorLayer::drawRendererV2Levels( QgsRenderContext& rendererContext, bo
888888
stopRendererV2( rendererContext, selRenderer );
889889
}
890890

891+
void QgsVectorLayer::reload()
892+
{
893+
if ( mDataProvider )
894+
{
895+
mDataProvider->reloadData();
896+
}
897+
}
898+
891899
bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
892900
{
893901
//set update threshold before each draw to make sure the current setting is picked up

src/core/qgsvectorlayer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
380380
QgsSnappingResult > & snappingResults,
381381
QgsSnapper::SnappingType snap_to );
382382

383+
/**Synchronises with changes in the datasource
384+
@note added in version 1.6*/
385+
virtual void reload();
386+
383387
/** Draws the layer
384388
* @return false if an error occurred during drawing
385389
*/

src/core/raster/qgsrasterlayer.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* **************************************************************************
1+
/***************************************************************************
22
qgsrasterlayer.cpp - description
33
-------------------
44
begin : Sat Jun 22 2002
@@ -824,7 +824,7 @@ const QgsRasterBandStats QgsRasterLayer::bandStatistics( int theBandNo )
824824
continue; // NULL
825825
}
826826

827-
myRasterBandStats.sum += myValue;
827+
myRasterBandStats.sum += myValue;
828828
++myRasterBandStats.elementCount;
829829
//only use this element if we have a non null element
830830
if ( myFirstIterationFlag )
@@ -1385,6 +1385,14 @@ const QgsRasterDataProvider* QgsRasterLayer::dataProvider() const
13851385
return mDataProvider;
13861386
}
13871387

1388+
void QgsRasterLayer::reload()
1389+
{
1390+
if ( mDataProvider )
1391+
{
1392+
mDataProvider->reloadData();
1393+
}
1394+
}
1395+
13881396
bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
13891397
{
13901398
QgsDebugMsg( "entered. (renderContext)" );

src/core/raster/qgsrasterlayer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
471471
/** Returns the data provider in a const-correct manner */
472472
const QgsRasterDataProvider* dataProvider() const;
473473

474+
/**Synchronises with changes in the datasource
475+
@note added in version 1.6*/
476+
virtual void reload();
477+
474478
/** \brief This is called when the view on the raster layer needs to be redrawn */
475479
bool draw( QgsRenderContext& rendererContext );
476480

src/providers/wfs/qgswfsdata.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ int QgsWFSData::getWFSData()
138138
}
139139
}
140140

141+
XML_ParserFree( p );
141142
return 0;
142143
}
143144

src/providers/wfs/qgswfsprovider.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,36 @@ QgsWFSProvider::QgsWFSProvider( const QString& uri )
5252
mFeatureCount( 0 ),
5353
mValid( true )
5454
{
55-
mSpatialIndex = new QgsSpatialIndex;
56-
if ( getFeature( uri ) == 0 )
55+
mSpatialIndex = 0;
56+
reloadData();
57+
if ( mValid )
5758
{
58-
mValid = true;
5959
getLayerCapabilities();
60-
61-
//set spatial filter to the whole extent
62-
//select(mExtent, false); //MH TODO: fix this in provider0_9-branch
63-
}
64-
else
65-
{
66-
mValid = false;
6760
}
6861
}
6962

7063
QgsWFSProvider::~QgsWFSProvider()
64+
{
65+
deleteData();
66+
delete mSpatialIndex;
67+
}
68+
69+
void QgsWFSProvider::reloadData()
70+
{
71+
deleteData();
72+
delete mSpatialIndex;
73+
mSpatialIndex = new QgsSpatialIndex;
74+
mValid = !getFeature( dataSourceUri() );
75+
}
76+
77+
void QgsWFSProvider::deleteData()
7178
{
7279
mSelectedFeatures.clear();
7380
for ( int i = 0; i < mFeatures.size(); i++ )
81+
{
7482
delete mFeatures[i];
83+
}
7584
mFeatures.clear();
76-
delete mSpatialIndex;
7785
}
7886

7987
void QgsWFSProvider::copyFeature( QgsFeature* f, QgsFeature& feature, bool fetchGeometry, QgsAttributeList fetchAttributes )
@@ -626,6 +634,7 @@ bool QgsWFSProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
626634

627635
int QgsWFSProvider::describeFeatureType( const QString& uri, QString& geometryAttribute, QgsFieldMap& fields )
628636
{
637+
fields.clear();
629638
switch ( mEncoding )
630639
{
631640
case QgsWFSProvider::GET:

src/providers/wfs/qgswfsprovider.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ class QgsWFSProvider: public QgsVectorDataProvider
136136
*/
137137
virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
138138

139+
/**Reloads the data from the the source. Needs to be implemented by providers with data caches to
140+
synchronize with changes in the data source*/
141+
virtual void reloadData();
142+
139143
signals:
140144
void dataReadProgressMessage( QString message );
141145

@@ -282,6 +286,8 @@ class QgsWFSProvider: public QgsVectorDataProvider
282286
void appendSupportedOperations( const QDomElement& operationsElem, int& capabilities ) const;
283287
/**Shows a message box with the exception string (or does nothing if the xml document is not an exception)*/
284288
void handleException( const QDomDocument& serverResponse ) const;
289+
290+
void deleteData();
285291
};
286292

287293
#endif

src/providers/wms/qgswmsprovider.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,6 +2813,11 @@ QString QgsWmsProvider::description() const
28132813
return WMS_DESCRIPTION;
28142814
} // QgsWmsProvider::description()
28152815

2816+
void QgsWmsProvider::reloadData()
2817+
{
2818+
delete cachedImage;
2819+
cachedImage = 0;
2820+
}
28162821

28172822
/**
28182823
* Class factory to return a pointer to a newly created

src/providers/wms/qgswmsprovider.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,10 @@ class QgsWmsProvider : public QgsRasterDataProvider
616616
*/
617617
QString description() const;
618618

619+
/**Reloads the data from the the source. Needs to be implemented by providers with data caches to
620+
synchronize with changes in the data source*/
621+
virtual void reloadData();
622+
619623

620624
signals:
621625

0 commit comments

Comments
 (0)