Skip to content
Permalink
Browse files

Keep external layers ordering. Fixes #35873

  • Loading branch information
pblottiere committed Sep 2, 2020
1 parent 3afe74b commit dc52916b2dd6d4eec5d60f60880a2bc7ebf9c475
@@ -1536,36 +1536,42 @@ namespace QgsWms
{
QString layer = layers[i];

if ( isExternalLayer( layer ) )
continue;

QgsWmsParametersLayer param;
param.mNickname = layer;

if ( i < styles.count() )
param.mStyle = styles[i];
if ( isExternalLayer( layer ) )
{
const QgsWmsParametersExternalLayer extParam = externalLayerParameter( layer );
param.mNickname = extParam.mName;
param.mExternalUri = extParam.mUri;
}
else
{
if ( i < styles.count() )
param.mStyle = styles[i];

if ( i < opacities.count() )
param.mOpacity = opacities[i];
if ( i < opacities.count() )
param.mOpacity = opacities[i];

if ( filters.contains( layer ) )
{
auto it = filters.find( layer );
while ( it != filters.end() && it.key() == layer )
if ( filters.contains( layer ) )
{
param.mFilter.append( it.value() );
++it;
auto it = filters.find( layer );
while ( it != filters.end() && it.key() == layer )
{
param.mFilter.append( it.value() );
++it;
}
}
}

if ( layerSelections.contains( layer ) )
{
QMultiMap<QString, QString>::const_iterator it;
it = layerSelections.constFind( layer );
while ( it != layerSelections.constEnd() && it.key() == layer )
if ( layerSelections.contains( layer ) )
{
param.mSelection << it.value().split( ',' );
++it;
QMultiMap<QString, QString>::const_iterator it;
it = layerSelections.constFind( layer );
while ( it != layerSelections.constEnd() && it.key() == layer )
{
param.mSelection << it.value().split( ',' );
++it;
}
}
}

@@ -1740,14 +1746,14 @@ namespace QgsWms
{
if ( isExternalLayer( layer ) )
{
eParams << externalLayerParameter( layer );
const QgsWmsParametersExternalLayer extParam = externalLayerParameter( layer );
layers << extParam.mName;
}
else
{
layers << layer;
}
}
param.mExternalLayers = eParams;

QStringList styles;
wmsParam = idParameter( QgsWmsParameter::STYLES, mapId );
@@ -53,6 +53,7 @@ namespace QgsWms
QList<QgsWmsParametersFilter> mFilter; // list of filter
QStringList mSelection; // list of string fid
QString mStyle;
QString mExternalUri;
};

struct QgsWmsParametersExternalLayer
@@ -85,7 +86,6 @@ namespace QgsWms
float mGridX = 0;
float mGridY = 0;
QList<QgsWmsParametersLayer> mLayers; // list of layers for this composer map
QList<QgsWmsParametersExternalLayer> mExternalLayers; // list of external layers for this composer map
QList<QgsWmsParametersHighlightLayer> mHighlightLayers; // list of highlight layers for this composer map
};

@@ -17,6 +17,7 @@

#include "qgslayertree.h"

#include "qgsrasterlayer.h"
#include "qgswmsrendercontext.h"
#include "qgswmsserviceexception.h"
#include "qgsserverprojectutils.h"
@@ -31,6 +32,12 @@ QgsWmsRenderContext::QgsWmsRenderContext( const QgsProject *project, QgsServerIn
{
}

QgsWmsRenderContext::~QgsWmsRenderContext()
{
qDeleteAll( mExternalLayers );
mExternalLayers.clear();
}

void QgsWmsRenderContext::setParameters( const QgsWmsParameters &parameters )
{
mParameters = parameters;
@@ -490,7 +497,18 @@ void QgsWmsRenderContext::searchLayersToRenderStyle()
const QString nickname = param.mNickname;
const QString style = param.mStyle;

if ( mNicknameLayers.contains( nickname ) )
if ( ! param.mExternalUri.isEmpty() && ( mFlags & AddExternalLayers ) )
{
std::unique_ptr<QgsMapLayer> layer = qgis::make_unique< QgsRasterLayer >( param.mExternalUri, param.mNickname, QStringLiteral( "wms" ) );

if ( layer->isValid() )
{
// to delete later
mExternalLayers.append( layer.release() );
mLayersToRender.append( mExternalLayers.last() );
}
}
else if ( mNicknameLayers.contains( nickname ) )
{
if ( !style.isEmpty() )
{
@@ -743,23 +761,26 @@ void QgsWmsRenderContext::removeUnwantedLayers()
{
const QString nickname = layerNickname( *layer );

if ( !layerScaleVisibility( nickname ) )
continue;

if ( mRestrictedLayers.contains( nickname ) )
continue;

if ( mFlags & UseWfsLayersOnly )
if ( ! isExternalLayer( nickname ) )
{
if ( layer->type() != QgsMapLayerType::VectorLayer )
{
if ( !layerScaleVisibility( nickname ) )
continue;
}

const QStringList wfsLayers = QgsServerProjectUtils::wfsLayerIds( *mProject );
if ( ! wfsLayers.contains( layer->id() ) )
{
if ( mRestrictedLayers.contains( nickname ) )
continue;

if ( mFlags & UseWfsLayersOnly )
{
if ( layer->type() != QgsMapLayerType::VectorLayer )
{
continue;
}

const QStringList wfsLayers = QgsServerProjectUtils::wfsLayerIds( *mProject );
if ( ! wfsLayers.contains( layer->id() ) )
{
continue;
}
}
}

@@ -769,6 +790,17 @@ void QgsWmsRenderContext::removeUnwantedLayers()
mLayersToRender = layers;
}

bool QgsWmsRenderContext::isExternalLayer( const QString &name ) const
{
for ( const auto &layer : mExternalLayers )
{
if ( layer->name().compare( name ) == 0 )
return true;
}

return false;
}

void QgsWmsRenderContext::checkLayerReadPermissions()
{
#ifdef HAVE_SERVER_PYTHON_PLUGINS
@@ -53,9 +53,9 @@ namespace QgsWms
Q_DECLARE_FLAGS( Flags, Flag )

/**
* Default constructor for QgsWmsRenderContext.
* Destructor for QgsWmsRenderContext.
*/
QgsWmsRenderContext() = default;
~QgsWmsRenderContext();

/**
* Constructor for QgsWmsRenderContext.
@@ -258,6 +258,8 @@ namespace QgsWms

bool layerScaleVisibility( const QString &name ) const;

bool isExternalLayer( const QString &name ) const;

const QgsProject *mProject = nullptr;
QgsServerInterface *mInterface = nullptr;
QgsWmsParameters mParameters;
@@ -277,6 +279,9 @@ namespace QgsWms

QMap<QString, QDomElement> mSlds;
QMap<QString, QString> mStyles;

// list for external layers
QList<QgsMapLayer *> mExternalLayers;
};
};

@@ -604,7 +604,7 @@ namespace QgsWms

if ( !map->keepLayerSet() )
{
if ( cMapParams.mLayers.isEmpty() && cMapParams.mExternalLayers.isEmpty() )
if ( cMapParams.mLayers.isEmpty() )
{
map->setLayers( mapSettings.layers() );
}
@@ -648,7 +648,6 @@ namespace QgsWms
}
}

layerSet << externalLayers( cMapParams.mExternalLayers );
layerSet << highlightLayers( cMapParams.mHighlightLayers );
std::reverse( layerSet.begin(), layerSet.end() );
map->setLayers( layerSet );
@@ -2674,25 +2673,6 @@ namespace QgsWms
return highlightLayers;
}

QList<QgsMapLayer *> QgsRenderer::externalLayers( const QList<QgsWmsParametersExternalLayer> &params )
{
QList<QgsMapLayer *> layers;

for ( const QgsWmsParametersExternalLayer &param : params )
{
std::unique_ptr<QgsMapLayer> layer = qgis::make_unique< QgsRasterLayer >( param.mUri, param.mName, QStringLiteral( "wms" ) );

if ( layer->isValid() )
{
// to delete later
mTemporaryLayers.append( layer.release() );
layers << mTemporaryLayers.last();
}
}

return layers;
}

void QgsRenderer::removeTemporaryLayers()
{
qDeleteAll( mTemporaryLayers );
@@ -3157,11 +3137,6 @@ namespace QgsWms
{
layers = highlightLayers( mWmsParameters.highlightLayersParameters() ) << layers;
}

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

void QgsRenderer::setLayerStyle( QgsMapLayer *layer, const QString &style ) const
@@ -149,9 +149,6 @@ namespace QgsWms
// Build and returns highlight layers
QList<QgsMapLayer *> highlightLayers( QList<QgsWmsParametersHighlightLayer> params );

// Build and returns external layers
QList<QgsMapLayer *> externalLayers( const QList<QgsWmsParametersExternalLayer> &params );

// Rendering step for layers
QPainter *layersRendering( const QgsMapSettings &mapSettings, QImage &image ) const;

@@ -296,7 +293,7 @@ namespace QgsWms

const QgsProject *mProject = nullptr;
QList<QgsMapLayer *> mTemporaryLayers;
QgsWmsRenderContext mContext;
const QgsWmsRenderContext &mContext;
};

} // namespace QgsWms

0 comments on commit dc52916

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