Skip to content

Commit

Permalink
More flexible limit of layer number in qgis server depending on numbe…
Browse files Browse the repository at this point in the history
…r of layers in project. Fixes bug #3502

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15707 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 15, 2011
1 parent 9fec25b commit 6129c4e
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/mapserver/qgsconfigcache.cpp
Expand Up @@ -17,6 +17,7 @@

#include "qgsconfigcache.h"
#include "qgsmapserverlogger.h"
#include "qgsmslayercache.h"
#include "qgsprojectparser.h"
#include "qgssldparser.h"

Expand All @@ -35,17 +36,25 @@ QgsConfigCache::~QgsConfigCache()

QgsConfigParser* QgsConfigCache::searchConfiguration( const QString& filePath )
{
QgsConfigParser* p = 0;
QMap<QString, QgsConfigParser*>::const_iterator configIt = mCachedConfigurations.find( filePath );
if ( configIt == mCachedConfigurations.constEnd() )
{
QgsMSDebugMsg( "Create new configuration" );
return insertConfiguration( filePath );
p = insertConfiguration( filePath );
}
else
{
QgsMSDebugMsg( "Return configuration from cache" );
return configIt.value();
p = configIt.value();
}

if ( p )
{
//there could be more layers in a project than allowed by the cache per default
QgsMSLayerCache::instance()->setProjectMaxLayers( p->numberOfLayers() );
}
return p;
}

QgsConfigParser* QgsConfigCache::insertConfiguration( const QString& filePath )
Expand Down
3 changes: 3 additions & 0 deletions src/mapserver/qgsconfigparser.h
Expand Up @@ -44,6 +44,9 @@ class QgsConfigParser
If no layers/style are found, an empty list is returned*/
virtual QList<QgsMapLayer*> mapLayerFromStyle( const QString& layerName, const QString& styleName, bool allowCaching = true ) const = 0;

/**Returns number of layers in configuration*/
virtual int numberOfLayers() const = 0;

/**Fills a layer and a style list. The two list have the same number of entries and the style and the layer at a position belong together (similar to the HTTP parameters 'Layers' and 'Styles'. Returns 0 in case of success*/
virtual int layersAndStyles( QStringList& layers, QStringList& styles ) const = 0;

Expand Down
6 changes: 3 additions & 3 deletions src/mapserver/qgsmslayercache.cpp
Expand Up @@ -20,7 +20,7 @@
#include "qgsmapserverlogger.h"

//maximum number of layers in the cache (and upper limit for layers in one published project)
#define MAX_N_LAYERS 100
#define DEFAULT_MAX_N_LAYERS 50

QgsMSLayerCache* QgsMSLayerCache::mInstance = 0;

Expand Down Expand Up @@ -52,7 +52,7 @@ QgsMSLayerCache::~QgsMSLayerCache()
void QgsMSLayerCache::insertLayer( const QString& url, const QString& layerName, QgsMapLayer* layer, const QList<QString>& tempFiles )
{
QgsMSDebugMsg( "inserting layer" );
if ( mEntries.size() > MAX_N_LAYERS ) //force cache layer examination after 10 inserted layers
if ( mEntries.size() > std::max( DEFAULT_MAX_N_LAYERS, mProjectMaxLayers ) ) //force cache layer examination after 10 inserted layers
{
updateEntries();
}
Expand Down Expand Up @@ -102,7 +102,7 @@ QgsMapLayer* QgsMSLayerCache::searchLayer( const QString& url, const QString& la
void QgsMSLayerCache::updateEntries()
{
QgsMSDebugMsg( "updateEntries" );
int entriesToDelete = mEntries.size() - MAX_N_LAYERS;
int entriesToDelete = mEntries.size() - std::max( DEFAULT_MAX_N_LAYERS, mProjectMaxLayers );
if ( entriesToDelete < 1 )
{
return;
Expand Down
7 changes: 7 additions & 0 deletions src/mapserver/qgsmslayercache.h
Expand Up @@ -51,6 +51,10 @@ class QgsMSLayerCache
@return a pointer to the layer or 0 if no such layer*/
QgsMapLayer* searchLayer( const QString& url, const QString& layerName );

int projectsMaxLayers() const { return mProjectMaxLayers; }

void setProjectMaxLayers( int n ) { mProjectMaxLayers = n; }

protected:
/**Protected singleton constructor*/
QgsMSLayerCache();
Expand All @@ -70,6 +74,9 @@ class QgsMSLayerCache
url is used several time in a request. It ensures that different layer instances are created for different
layer names*/
QHash<QPair<QString, QString>, QgsMSLayerCacheEntry> mEntries;

/**Maximum number of layers in the cache, overrides DEFAULT_MAX_N_LAYERS if larger*/
int mProjectMaxLayers;
};

#endif
6 changes: 6 additions & 0 deletions src/mapserver/qgsprojectparser.cpp
Expand Up @@ -47,6 +47,12 @@ QgsProjectParser::~QgsProjectParser()
delete mXMLDoc;
}

int QgsProjectParser::numberOfLayers() const
{
QList<QDomElement> layerElems = projectLayerElements();
return layerElems.size();
}

void QgsProjectParser::layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
{
QList<QDomElement> layerElems = projectLayerElements();
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgsprojectparser.h
Expand Up @@ -38,6 +38,8 @@ class QgsProjectParser: public QgsConfigParser
/**Adds layer and style specific capabilities elements to the parent node. This includes the individual layers and styles, their description, native CRS, bounding boxes, etc.*/
virtual void layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;

int numberOfLayers() const;

/**Returns one or possibly several maplayers for a given layer name and style. If no layers/style are found, an empty list is returned*/
virtual QList<QgsMapLayer*> mapLayerFromStyle( const QString& lName, const QString& styleName, bool allowCaching = true ) const;

Expand Down
17 changes: 17 additions & 0 deletions src/mapserver/qgssldparser.cpp
Expand Up @@ -142,6 +142,23 @@ QgsSLDParser::~QgsSLDParser()
delete mXMLDoc;
}

int QgsSLDParser::numberOfLayers() const
{
if ( !mXMLDoc )
{
return 0;
}

QDomElement sldElem = mXMLDoc->documentElement().toElement();
if ( sldElem.isNull() )
{
return 0;
}
QDomNodeList userLayerList = sldElem.elementsByTagName( "UserLayer" );
QDomNodeList namedLayerList = sldElem.elementsByTagName( "NamedLayer" );
return ( userLayerList.size() + namedLayerList.size() );
}

void QgsSLDParser::layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
{
//iterate over all <UserLayer> nodes
Expand Down
3 changes: 3 additions & 0 deletions src/mapserver/qgssldparser.h
Expand Up @@ -57,6 +57,9 @@ class QgsSLDParser: public QgsConfigParser
/**Adds layer and style specific capabilities elements to the parent node. This includes the individual layers and styles, their description, native CRS, bounding boxes, etc.*/
void layersAndStylesCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;

/**Returns number of layers in configuration*/
int numberOfLayers() const;

/**Returns one or possibly several maplayers for a given layer name and style. If no layers/style are found, an empty list is returned*/
QList<QgsMapLayer*> mapLayerFromStyle( const QString& layerName, const QString& styleName, bool allowCaching = true ) const;

Expand Down

0 comments on commit 6129c4e

Please sign in to comment.