Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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@14264 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Sep 20, 2010
1 parent 9e9f788 commit 2222397
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 14 deletions.
4 changes: 4 additions & 0 deletions python/core/qgsdataprovider.sip
Expand Up @@ -178,6 +178,10 @@ class QgsDataProvider : QObject
*/
virtual QString fileRasterFilters() const;

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

signals:

/**
Expand Down
4 changes: 4 additions & 0 deletions python/core/qgsmaplayer.sip
Expand Up @@ -70,6 +70,10 @@ public:
*/
const QString & name() const;

/**Synchronises with changes in the datasource
@note added in version 1.6*/
virtual void reload();

/** Render the layer, to be overridden in child classes
*/
virtual bool draw(QgsRenderContext& rendererContext);
Expand Down
4 changes: 4 additions & 0 deletions python/core/qgsmaplayerregistry.sip
Expand Up @@ -67,6 +67,10 @@ public:
*/
void clearAllLayerCaches();

/**Reload all provider data caches (currently used for WFS and WMS providers)
@note: this method was added in QGIS 1.6*/
void reloadAllLayers();

signals:

/** emitted when a layer is removed from the registry
Expand Down
4 changes: 4 additions & 0 deletions python/core/qgsrasterlayer.sip
Expand Up @@ -303,6 +303,10 @@ public:
/** Returns the data provider in a const-correct manner */
//const QgsRasterDataProvider* dataProvider() const;

/**Synchronises with changes in the datasource
@note added in version 1.6*/
virtual void reload();

/** \brief This is called when the view on the raster layer needs to be redrawn */
bool draw( QgsRenderContext& rendererContext );

Expand Down
4 changes: 4 additions & 0 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -333,6 +333,10 @@ public:
int snapWithContext(const QgsPoint& startPoint, double snappingTolerance, QMultiMap<double, QgsSnappingResult>& snappingResults /Out/,
QgsSnapper::SnappingType snap_to);

/**Synchronises with changes in the datasource
@note added in version 1.6*/
virtual void reload();

/** Draws the layer using coordinate transformation
* @return FALSE if an error occurred during drawing
*/
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -4706,6 +4706,8 @@ void QgisApp::refreshMapCanvas()
{
//clear all caches first
QgsMapLayerRegistry::instance()->clearAllLayerCaches();
//reload cached provider data
QgsMapLayerRegistry::instance()->reloadAllLayers();
//then refresh
mMapCanvas->refresh();
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsdataprovider.h
Expand Up @@ -267,6 +267,10 @@ class CORE_EXPORT QgsDataProvider : public QObject
return "";
}

/**Reloads the data from the the source. Needs to be implemented by providers with data caches to
synchronize with changes in the data source*/
virtual void reloadData() {}

signals:

/**
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsmaplayer.h
Expand Up @@ -79,6 +79,10 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
QString const & name() const;

/**Synchronises with changes in the datasource
@note added in version 1.6*/
virtual void reload() {}

/** This is the method that does the actual work of
* drawing the layer onto a paint device.
* @param QgsRenderContext - describes the extents,
Expand Down
14 changes: 13 additions & 1 deletion src/core/qgsmaplayerregistry.cpp
Expand Up @@ -22,7 +22,6 @@
#include "qgsmaplayer.h"
#include "qgslogger.h"


//
// Static calls to enforce singleton behaviour
//
Expand Down Expand Up @@ -128,6 +127,19 @@ void QgsMapLayerRegistry::clearAllLayerCaches()
}
} // QgsMapLayerRegistry::clearAllLayerCaches()

void QgsMapLayerRegistry::reloadAllLayers()
{
QMap<QString, QgsMapLayer *>::iterator it;
for ( it = mMapLayers.begin(); it != mMapLayers.end() ; ++it )
{
QgsMapLayer* layer = it.value();
if ( layer )
{
layer->reload();
}
}
}

QMap<QString, QgsMapLayer*> & QgsMapLayerRegistry::mapLayers()
{
return mMapLayers;
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsmaplayerregistry.h
Expand Up @@ -89,6 +89,11 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject
* @note this method was added in QGIS 1.4
*/
void clearAllLayerCaches();

/**Reload all provider data caches (currently used for WFS and WMS providers)
@note: this method was added in QGIS 1.6*/
void reloadAllLayers();

signals:

/** emitted when a layer is removed from the registry
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -888,6 +888,14 @@ void QgsVectorLayer::drawRendererV2Levels( QgsRenderContext& rendererContext, bo
stopRendererV2( rendererContext, selRenderer );
}

void QgsVectorLayer::reload()
{
if ( mDataProvider )
{
mDataProvider->reloadData();
}
}

bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
{
//set update threshold before each draw to make sure the current setting is picked up
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -380,6 +380,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
QgsSnappingResult > & snappingResults,
QgsSnapper::SnappingType snap_to );

/**Synchronises with changes in the datasource
@note added in version 1.6*/
virtual void reload();

/** Draws the layer
* @return false if an error occurred during drawing
*/
Expand Down
12 changes: 10 additions & 2 deletions src/core/raster/qgsrasterlayer.cpp
@@ -1,4 +1,4 @@
/* **************************************************************************
/***************************************************************************
qgsrasterlayer.cpp - description
-------------------
begin : Sat Jun 22 2002
Expand Down Expand Up @@ -824,7 +824,7 @@ const QgsRasterBandStats QgsRasterLayer::bandStatistics( int theBandNo )
continue; // NULL
}

myRasterBandStats.sum += myValue;
myRasterBandStats.sum += myValue;
++myRasterBandStats.elementCount;
//only use this element if we have a non null element
if ( myFirstIterationFlag )
Expand Down Expand Up @@ -1385,6 +1385,14 @@ const QgsRasterDataProvider* QgsRasterLayer::dataProvider() const
return mDataProvider;
}

void QgsRasterLayer::reload()
{
if ( mDataProvider )
{
mDataProvider->reloadData();
}
}

bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
{
QgsDebugMsg( "entered. (renderContext)" );
Expand Down
4 changes: 4 additions & 0 deletions src/core/raster/qgsrasterlayer.h
Expand Up @@ -471,6 +471,10 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** Returns the data provider in a const-correct manner */
const QgsRasterDataProvider* dataProvider() const;

/**Synchronises with changes in the datasource
@note added in version 1.6*/
virtual void reload();

/** \brief This is called when the view on the raster layer needs to be redrawn */
bool draw( QgsRenderContext& rendererContext );

Expand Down
1 change: 1 addition & 0 deletions src/providers/wfs/qgswfsdata.cpp
Expand Up @@ -138,6 +138,7 @@ int QgsWFSData::getWFSData()
}
}

XML_ParserFree( p );
return 0;
}

Expand Down
31 changes: 20 additions & 11 deletions src/providers/wfs/qgswfsprovider.cpp
Expand Up @@ -52,28 +52,36 @@ QgsWFSProvider::QgsWFSProvider( const QString& uri )
mFeatureCount( 0 ),
mValid( true )
{
mSpatialIndex = new QgsSpatialIndex;
if ( getFeature( uri ) == 0 )
mSpatialIndex = 0;
reloadData();
if ( mValid )
{
mValid = true;
getLayerCapabilities();

//set spatial filter to the whole extent
//select(mExtent, false); //MH TODO: fix this in provider0_9-branch
}
else
{
mValid = false;
}
}

QgsWFSProvider::~QgsWFSProvider()
{
deleteData();
delete mSpatialIndex;
}

void QgsWFSProvider::reloadData()
{
deleteData();
delete mSpatialIndex;
mSpatialIndex = new QgsSpatialIndex;
mValid = !getFeature( dataSourceUri() );
}

void QgsWFSProvider::deleteData()
{
mSelectedFeatures.clear();
for ( int i = 0; i < mFeatures.size(); i++ )
{
delete mFeatures[i];
}
mFeatures.clear();
delete mSpatialIndex;
}

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

int QgsWFSProvider::describeFeatureType( const QString& uri, QString& geometryAttribute, QgsFieldMap& fields )
{
fields.clear();
switch ( mEncoding )
{
case QgsWFSProvider::GET:
Expand Down
6 changes: 6 additions & 0 deletions src/providers/wfs/qgswfsprovider.h
Expand Up @@ -136,6 +136,10 @@ class QgsWFSProvider: public QgsVectorDataProvider
*/
virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );

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

signals:
void dataReadProgressMessage( QString message );

Expand Down Expand Up @@ -282,6 +286,8 @@ class QgsWFSProvider: public QgsVectorDataProvider
void appendSupportedOperations( const QDomElement& operationsElem, int& capabilities ) const;
/**Shows a message box with the exception string (or does nothing if the xml document is not an exception)*/
void handleException( const QDomDocument& serverResponse ) const;

void deleteData();
};

#endif
5 changes: 5 additions & 0 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -2813,6 +2813,11 @@ QString QgsWmsProvider::description() const
return WMS_DESCRIPTION;
} // QgsWmsProvider::description()

void QgsWmsProvider::reloadData()
{
delete cachedImage;
cachedImage = 0;
}

/**
* Class factory to return a pointer to a newly created
Expand Down
4 changes: 4 additions & 0 deletions src/providers/wms/qgswmsprovider.h
Expand Up @@ -616,6 +616,10 @@ class QgsWmsProvider : public QgsRasterDataProvider
*/
QString description() const;

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


signals:

Expand Down

0 comments on commit 2222397

Please sign in to comment.