Skip to content

Commit

Permalink
Add main loop to configure layers
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Mar 27, 2019
1 parent 365e01a commit ec06223
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
96 changes: 96 additions & 0 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
14 changes: 13 additions & 1 deletion src/server/services/wms/qgswmsrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

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

QgsRenderer( const QgsWmsRenderContext &context );

~QgsRenderer();

/**
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ec06223

Please sign in to comment.