Skip to content

Commit

Permalink
[FEATURE]: added reload method to map layers and provider interface. …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
mhugent committed Sep 20, 2010
1 parent dd182b6 commit fb4a658
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 fb4a658

Please sign in to comment.