Skip to content
Permalink
Browse files

Remove more methods from renderer

  • Loading branch information
pblottiere committed Mar 27, 2019
1 parent dedf0ab commit 0b68762b4d1ef9f6f2fdc6db838ae4df810fadab
@@ -214,6 +214,32 @@ QString QgsWmsRenderContext::layerNickname( const QgsMapLayer &layer ) const
return name;
}

QgsMapLayer *QgsWmsRenderContext::layer( const QString &nickname ) const
{
QgsMapLayer *mlayer = nullptr;

for ( auto layer : mLayersToRender )
{
if ( layerNickname( *layer ).compare( nickname ) == 0 )
{
mlayer = layer;
break;
}
}

return mlayer;
}

bool QgsWmsRenderContext::isValidLayer( const QString &nickname ) const
{
return layer( nickname ) != nullptr;
}

bool QgsWmsRenderContext::isValidGroup( const QString &name ) const
{
return mLayerGroups.contains( name );
}

void QgsWmsRenderContext::initNicknameLayers()
{
for ( QgsMapLayer *ml : mProject->mapLayers() )
@@ -158,6 +158,22 @@ namespace QgsWms
*/
QString layerNickname( const QgsMapLayer &layer ) const;

/**
* Returns the layer corresponding to the nickname, or a nullptr if not
* found or if the layer do not need to be rendered.
*/
QgsMapLayer *layer( const QString &nickname ) const;

/**
* Returns true if the layer has to be rendered, false otherwise.
*/
bool isValidLayer( const QString &nickname ) const;

/**
* Returns true if \a name is a group.
*/
bool isValidGroup( const QString &name ) const;

/**
* Returns default dots per mm according to the current configuration.
*/
@@ -124,17 +124,13 @@ namespace QgsWms

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

initRestrictedLayers();
initNicknameLayers();
}

QgsRenderer::~QgsRenderer()
{
removeTemporaryLayers();
}


QImage *QgsRenderer::getLegendGraphics()
{
// check parameters
@@ -599,12 +595,13 @@ namespace QgsWms
QList<QgsMapLayer *> layerSet;
for ( auto layer : cMapParams.mLayers )
{
if ( ! mNicknameLayers.contains( layer.mNickname ) )
QgsMapLayer *mlayer = mContext.layer( layer.mNickname );

if ( ! mlayer )
{
continue;
}

QgsMapLayer *mlayer = mNicknameLayers[ layer.mNickname ];
setLayerStyle( mlayer, layer.mStyle );
layerSet << mlayer;
}
@@ -1285,12 +1282,12 @@ namespace QgsWms
break;
}
}
if ( !validLayer && !mNicknameLayers.contains( queryLayer ) && !mLayerGroups.contains( queryLayer ) )
if ( !validLayer && !mContext.isValidLayer( queryLayer ) && !mContext.isValidGroup( queryLayer ) )
{
QString msg = QObject::tr( "Layer '%1' not found" ).arg( queryLayer );
throw QgsBadRequestException( QStringLiteral( "LayerNotDefined" ), msg );
}
else if ( ( validLayer && !queryableLayer ) || ( !validLayer && mLayerGroups.contains( queryLayer ) ) )
else if ( ( validLayer && !queryableLayer ) || ( !validLayer && mContext.isValidGroup( queryLayer ) ) )
{
QString msg = QObject::tr( "Layer '%1' is not queryable" ).arg( queryLayer );
throw QgsBadRequestException( QStringLiteral( "LayerNotQueryable" ), msg );
@@ -2422,100 +2419,6 @@ namespace QgsWms
return ( mapSettings.mapToLayerCoordinates( ml, mapRectangle ) );
}


void QgsRenderer::initRestrictedLayers()
{
mRestrictedLayers.clear();

// get name of restricted layers/groups in project
QStringList restricted = QgsServerProjectUtils::wmsRestrictedLayers( *mProject );

// extract restricted layers from excluded groups
QStringList restrictedLayersNames;
QgsLayerTreeGroup *root = mProject->layerTreeRoot();

for ( const QString &l : restricted )
{
QgsLayerTreeGroup *group = root->findGroup( l );
if ( group )
{
QList<QgsLayerTreeLayer *> groupLayers = group->findLayers();
for ( QgsLayerTreeLayer *treeLayer : groupLayers )
{
restrictedLayersNames.append( treeLayer->name() );
}
}
else
{
restrictedLayersNames.append( l );
}
}

// build output with names, ids or short name according to the configuration
QList<QgsLayerTreeLayer *> layers = root->findLayers();
for ( QgsLayerTreeLayer *layer : layers )
{
if ( restrictedLayersNames.contains( layer->name() ) )
{
mRestrictedLayers.append( mContext.layerNickname( *layer->layer() ) );
}
}
}

void QgsRenderer::initNicknameLayers()
{
for ( QgsMapLayer *ml : mProject->mapLayers() )
{
mNicknameLayers[ mContext.layerNickname( *ml ) ] = ml;
}

// init groups
const QString rootName { QgsServerProjectUtils::wmsRootName( *mProject ) };
const QgsLayerTreeGroup *root = mProject->layerTreeRoot();
initLayerGroupsRecursive( root, rootName.isEmpty() ? mProject->title() : rootName );
}

void QgsRenderer::initLayerGroupsRecursive( const QgsLayerTreeGroup *group, const QString &groupName )
{
if ( !groupName.isEmpty() )
{
mLayerGroups[groupName] = QList<QgsMapLayer *>();
for ( QgsLayerTreeLayer *layer : group->findLayers() )
{
mLayerGroups[groupName].append( layer->layer() );
}
}

for ( const QgsLayerTreeNode *child : group->children() )
{
if ( child->nodeType() == QgsLayerTreeNode::NodeGroup )
{
QString name = child->customProperty( QStringLiteral( "wmsShortName" ) ).toString();

if ( name.isEmpty() )
name = child->name();

initLayerGroupsRecursive( static_cast<const QgsLayerTreeGroup *>( child ), name );

}
}
}

/*QString QgsRenderer::layerNickname( const QgsMapLayer &layer ) const
{
QString name = layer.shortName();
if ( QgsServerProjectUtils::wmsUseLayerIds( *mProject ) )
{
name = layer.id();
}
else if ( name.isEmpty() )
{
name = layer.name();
}
return name;
}*/

QList<QgsMapLayer *> QgsRenderer::highlightLayers( QList<QgsWmsParametersHighlightLayer> params )
{
QList<QgsMapLayer *> highlightLayers;
@@ -114,20 +114,12 @@ namespace QgsWms

private:

// Init the restricted layers with nicknames
void initRestrictedLayers();

// Build and returns highlight layers
QList<QgsMapLayer *> highlightLayers( QList<QgsWmsParametersHighlightLayer> params );

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

// Init a map with nickname for layers' project
void initNicknameLayers();

void initLayerGroupsRecursive( const QgsLayerTreeGroup *group, const QString &groupName );

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

@@ -301,9 +293,6 @@ namespace QgsWms

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

0 comments on commit 0b68762

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