Skip to content

Commit

Permalink
Empty config file entry in layer cache for sld layers
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent authored and jef-n committed May 17, 2012
1 parent f4c21a1 commit 30d270f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/mapserver/qgshostedrdsbuilder.cpp
Expand Up @@ -67,7 +67,7 @@ QgsMapLayer* QgsHostedRDSBuilder::createMapLayer( const QDomElement& elem,
rl = new QgsRasterLayer( uri, layerNameFromUri( uri ) );
if ( allowCaching )
{
QgsMSLayerCache::instance()->insertLayer( uri, layerName, rl, "" /*todo: add project file path*/ );
QgsMSLayerCache::instance()->insertLayer( uri, layerName, rl );
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/mapserver/qgshostedvdsbuilder.cpp
Expand Up @@ -75,7 +75,7 @@ QgsMapLayer* QgsHostedVDSBuilder::createMapLayer( const QDomElement& elem,

if ( allowCaching )
{
QgsMSLayerCache::instance()->insertLayer( uri, layerName, ml, "" /*todo: add project file path*/ );
QgsMSLayerCache::instance()->insertLayer( uri, layerName, ml );
}
else
{
Expand Down
38 changes: 22 additions & 16 deletions src/mapserver/qgsmslayercache.cpp
Expand Up @@ -75,15 +75,18 @@ void QgsMSLayerCache::insertLayer( const QString& url, const QString& layerName,
mEntries.insert( urlLayerPair, newEntry );

//update config file map
QHash< QString, int >::iterator configIt = mConfigFiles.find( configFile );
if ( configIt == mConfigFiles.end() )
if ( !configFile.isEmpty() )
{
mConfigFiles.insert( configFile, 1 );
mFileSystemWatcher.addPath( configFile );
}
else
{
mConfigFiles[configFile] = configIt.value() + 1; //increment reference counter
QHash< QString, int >::iterator configIt = mConfigFiles.find( configFile );
if ( configIt == mConfigFiles.end() )
{
mConfigFiles.insert( configFile, 1 );
mFileSystemWatcher.addPath( configFile );
}
else
{
mConfigFiles[configFile] = configIt.value() + 1; //increment reference counter
}
}
}

Expand Down Expand Up @@ -190,14 +193,17 @@ void QgsMSLayerCache::freeEntryRessources( QgsMSLayerCacheEntry& entry )
}

//counter
int configFileCount = mConfigFiles[entry.configFile];
if ( configFileCount < 2 )
if ( !entry.configFile.isEmpty() )
{
mConfigFiles.remove( entry.configFile );
mFileSystemWatcher.removePath( entry.configFile );
}
else
{
mConfigFiles[entry.configFile] = configFileCount - 1;
int configFileCount = mConfigFiles[entry.configFile];
if ( configFileCount < 2 )
{
mConfigFiles.remove( entry.configFile );
mFileSystemWatcher.removePath( entry.configFile );
}
else
{
mConfigFiles[entry.configFile] = configFileCount - 1;
}
}
}
3 changes: 2 additions & 1 deletion src/mapserver/qgsmslayercache.h
Expand Up @@ -48,8 +48,9 @@ class QgsMSLayerCache: public QObject
/**Inserts a new layer into the cash
@param url the layer datasource
@param layerName the layer name (to distinguish between different layers in a request using the same datasource
@param configFile path of the config file (to invalidate entries if file changes). Can be empty (e.g. layers from sld)
@param tempFiles some layers have temporary files. The cash makes sure they are removed when removing the layer from the cash*/
void insertLayer( const QString& url, const QString& layerName, QgsMapLayer* layer, const QString& configFile, const QList<QString>& tempFiles = QList<QString>() );
void insertLayer( const QString& url, const QString& layerName, QgsMapLayer* layer, const QString& configFile = QString(), const QList<QString>& tempFiles = QList<QString>() );
/**Searches for the layer with the given url.
@return a pointer to the layer or 0 if no such layer*/
QgsMapLayer* searchLayer( const QString& url, const QString& layerName );
Expand Down
6 changes: 3 additions & 3 deletions src/mapserver/qgsremoteowsbuilder.cpp
Expand Up @@ -115,7 +115,7 @@ QgsMapLayer* QgsRemoteOWSBuilder::createMapLayer(
{
if ( allowCaching )
{
QgsMSLayerCache::instance()->insertLayer( url, layerName, result, "" /*todo: add project file path*/ );
QgsMSLayerCache::instance()->insertLayer( url, layerName, result );
}
else
{
Expand Down Expand Up @@ -215,7 +215,7 @@ QgsRasterLayer* QgsRemoteOWSBuilder::wmsLayerFromUrl( const QString& url, const
//insert into cache
if ( allowCaching )
{
QgsMSLayerCache::instance()->insertLayer( url, layerName, result, "" /*todo: add project file path*/ );
QgsMSLayerCache::instance()->insertLayer( url, layerName, result );
}
else
{
Expand Down Expand Up @@ -414,7 +414,7 @@ QgsVectorLayer* QgsRemoteOWSBuilder::sosLayer( const QDomElement& remoteOWSElem,
{
if ( allowCaching )
{
QgsMSLayerCache::instance()->insertLayer( providerUrl, layerName, sosLayer, "" /*todo: add project file path*/ );
QgsMSLayerCache::instance()->insertLayer( providerUrl, layerName, sosLayer );
}
else
{
Expand Down

0 comments on commit 30d270f

Please sign in to comment.