Skip to content
Permalink
Browse files

Add main loop to configure layers

  • Loading branch information
pblottiere committed Mar 27, 2019
1 parent 365e01a commit ec062235551b88f86d599acaf7c196aaab5f32d0
Showing with 109 additions and 1 deletion.
  1. +96 −0 src/server/services/wms/qgswmsrenderer.cpp
  2. +13 −1 src/server/services/wms/qgswmsrenderer.h
@@ -130,6 +130,22 @@ namespace QgsWms
initNicknameLayers();
}

QgsRenderer::QgsRenderer( const QgsWmsRenderContext &context )
: mContext( context )
{
#ifdef HAVE_SERVER_PYTHON_PLUGINS
mAccessControl = mContext.accessControl();
#endif

mProject = mContext.project();

mWmsParameters = mContext.parameters();
mWmsParameters.dump();

initRestrictedLayers();
initNicknameLayers();
}

QgsRenderer::~QgsRenderer()
{
removeTemporaryLayers();
@@ -3436,4 +3452,84 @@ namespace QgsWms
return mWmsParameters.widthAsInt();
}

void QgsRenderer::configureLayers( QList<QgsMapLayer *> &layers, QgsMapSettings *settings )
{
const bool useSld = !mContext.parameters().sldBody().isEmpty();

for ( auto layer : layers )
{
const QgsWmsParametersLayer param = mContext.parameters( *layer );

if ( param.mNickname.isEmpty() )
{
continue;
}

if ( useSld )
{
setLayerSld( layer, mContext.sld( *layer ) );
}
else
{
setLayerStyle( layer, mContext.style( *layer ) );
}

if ( mContext.testFlag( QgsWmsRenderContext::UseOpacity ) )
{
setLayerOpacity( layer, param.mOpacity );
}

if ( mContext.testFlag( QgsWmsRenderContext::UseFilter ) )
{
setLayerFilter( layer, param.mFilter );
}

if ( mContext.testFlag( QgsWmsRenderContext::UseSelection ) )
{
setLayerSelection( layer, param.mSelection );
}

if ( settings && mContext.updateExtent() )
{
updateExtent( layer, *settings );
}

if ( mContext.testFlag( QgsWmsRenderContext::SetAccessControl ) )
{
setLayerAccessControlFilter( layer );
}
}

if ( mContext.testFlag( QgsWmsRenderContext::AddHighlightLayers ) )
{
layers = highlightLayers( mWmsParameters.highlightLayersParameters() ) << layers;
}

if ( mContext.testFlag( QgsWmsRenderContext::AddExternalLayers ) )
{
layers = externalLayers( mWmsParameters.externalLayersParameters() ) << layers;
}
}

void QgsRenderer::setLayerStyle( QgsMapLayer *layer, const QString &style ) const
{
if ( style.isEmpty() )
{
return;
}

bool rc = layer->styleManager()->setCurrentStyle( style );
if ( ! rc )
{
throw QgsMapServiceException( QStringLiteral( "StyleNotDefined" ),
QStringLiteral( "Style \"%1\" does not exist for layer \"%2\"" ).arg( style, layer->name() ) );
}
}

void QgsRenderer::setLayerSld( QgsMapLayer *layer, const QDomElement &sld ) const
{
QString err;
layer->readSld( sld, err );
layer->setCustomProperty( "readSLD", true );
}
} // namespace QgsWms
@@ -22,6 +22,7 @@

#include "qgsserversettings.h"
#include "qgswmsparameters.h"
#include "qgswmsrendercontext.h"
#include "qgsfeaturefilter.h"
#include <QDomDocument>
#include <QMap>
@@ -69,6 +70,8 @@ namespace QgsWms
const QgsProject *project,
const QgsWmsParameters &parameters );

QgsRenderer( const QgsWmsRenderContext &context );

~QgsRenderer();

/**
@@ -313,18 +316,27 @@ namespace QgsWms

const QgsWmsParameters &mWmsParameters;

void configureLayers( QList<QgsMapLayer *> &layers, QgsMapSettings *settings = nullptr );

void setLayerStyle( QgsMapLayer *layer, const QString &style ) const;

void setLayerSld( QgsMapLayer *layer, const QDomElement &sld ) const;

QgsWmsParameters mWmsParameters;

#ifdef HAVE_SERVER_PYTHON_PLUGINS
//! The access control helper
QgsAccessControl *mAccessControl = nullptr;
#endif
QgsFeatureFilter mFeatureFilter;

const QgsServerSettings &mSettings;
QgsServerSettings mSettings;
const QgsProject *mProject = nullptr;
QStringList mRestrictedLayers;
QMap<QString, QgsMapLayer *> mNicknameLayers;
QMap<QString, QList<QgsMapLayer *> > mLayerGroups;
QList<QgsMapLayer *> mTemporaryLayers;
QgsWmsRenderContext mContext;
};

} // namespace QgsWms

0 comments on commit ec06223

Please sign in to comment.
You can’t perform that action at this time.