Skip to content
Permalink
Browse files
[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 22223973344879312919cab636b183c3eb502d4e
@@ -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:

/**
@@ -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);
@@ -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
@@ -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 );

@@ -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
*/
@@ -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();
}
@@ -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:

/**
@@ -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,
@@ -22,7 +22,6 @@
#include "qgsmaplayer.h"
#include "qgslogger.h"


//
// Static calls to enforce singleton behaviour
//
@@ -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;
@@ -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
@@ -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
@@ -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
*/
@@ -1,4 +1,4 @@
/* **************************************************************************
/***************************************************************************
qgsrasterlayer.cpp - description
-------------------
begin : Sat Jun 22 2002
@@ -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 )
@@ -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)" );
@@ -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 );

@@ -138,6 +138,7 @@ int QgsWFSData::getWFSData()
}
}

XML_ParserFree( p );
return 0;
}

@@ -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 )
@@ -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:
@@ -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 );

@@ -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
@@ -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
@@ -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:

0 comments on commit 2222397

Please sign in to comment.