Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace calls to deprecated method
  • Loading branch information
mhugent committed Mar 31, 2016
1 parent 19120f4 commit 6c6e983
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 39 deletions.
85 changes: 46 additions & 39 deletions src/server/qgswmsconfigparser.cpp
Expand Up @@ -48,7 +48,7 @@ QgsWMSConfigParser::~QgsWMSConfigParser()
QgsComposition* QgsWMSConfigParser::createPrintComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, const QMap< QString, QString >& parameterMap ) const
{
QStringList highlightLayers;
createPrintComposition( composerTemplate, mapRenderer, parameterMap, highlightLayers );
return createPrintComposition( composerTemplate, mapRenderer, parameterMap, highlightLayers );
}

QgsComposition* QgsWMSConfigParser::createPrintComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, const QMap< QString, QString >& parameterMap, QStringList& highlightLayers ) const
Expand Down Expand Up @@ -200,9 +200,9 @@ QgsComposition* QgsWMSConfigParser::createPrintComposition( const QString& compo
QList< QgsComposerLegend* >::iterator legendIt = composerLegends.begin();
for ( ; legendIt != composerLegends.end(); ++legendIt )
{
if (( *legendIt )->model()->autoUpdate() )
if (( *legendIt )->autoUpdateModel() )
{
( *legendIt )->model()->setLayerSet( bkLayerSet );
setLayerIdsToLegendModel(( *legendIt )->modelV2(), bkLayerSet, currentMap->scale() );
}
}

Expand Down Expand Up @@ -232,43 +232,8 @@ QgsComposition* QgsWMSConfigParser::createPrintComposition( const QString& compo

// get model and layer tree root of the legend
QgsLegendModelV2* model = currentLegend->modelV2();
QgsLayerTreeGroup* root = model->rootGroup();


// get layerIds find in the layer tree root
QStringList layerIds = root->findLayerIds();
// get map layerIds
QStringList layerSet = map->layerSet();

// get map scale
double scale = map->scale();

// Q_FOREACH layer find in the layer tree
// remove it if the layer id is not in map layerIds
Q_FOREACH ( const QString& layerId, layerIds )
{
QgsLayerTreeLayer* nodeLayer = root->findLayer( layerId );
if ( !nodeLayer )
{
continue;
}
if ( !layerSet.contains( layerId ) )
{
qobject_cast<QgsLayerTreeGroup*>( nodeLayer->parent() )->removeChildNode( nodeLayer );
}
else
{
QgsMapLayer* layer = nodeLayer->layer();
if ( layer->hasScaleBasedVisibility() )
{
if ( layer->minimumScale() > scale )
qobject_cast<QgsLayerTreeGroup*>( nodeLayer->parent() )->removeChildNode( nodeLayer );
else if ( layer->maximumScale() < scale )
qobject_cast<QgsLayerTreeGroup*>( nodeLayer->parent() )->removeChildNode( nodeLayer );
}
}
}
root->removeChildrenGroupWithoutLayers();
setLayerIdsToLegendModel( model, layerSet, map->scale() );
}
}

Expand Down Expand Up @@ -572,3 +537,45 @@ void QgsWMSConfigParser::removeHighlightLayers( const QStringList& layerIds )
QgsMapLayerRegistry::instance()->removeMapLayers( QStringList() << *idIt );
}
}

void QgsWMSConfigParser::setLayerIdsToLegendModel( QgsLegendModelV2* model, const QStringList& layerSet, double scale )
{
if ( !model )
{
return;
}

// get model and layer tree root of the legend
QgsLayerTreeGroup* root = model->rootGroup();


// get layerIds find in the layer tree root
QStringList layerIds = root->findLayerIds();

// Q_FOREACH layer find in the layer tree
// remove it if the layer id is not in map layerIds
Q_FOREACH ( const QString& layerId, layerIds )
{
QgsLayerTreeLayer* nodeLayer = root->findLayer( layerId );
if ( !nodeLayer )
{
continue;
}
if ( !layerSet.contains( layerId ) )
{
qobject_cast<QgsLayerTreeGroup*>( nodeLayer->parent() )->removeChildNode( nodeLayer );
}
else
{
QgsMapLayer* layer = nodeLayer->layer();
if ( layer->hasScaleBasedVisibility() )
{
if ( layer->minimumScale() > scale )
qobject_cast<QgsLayerTreeGroup*>( nodeLayer->parent() )->removeChildNode( nodeLayer );
else if ( layer->maximumScale() < scale )
qobject_cast<QgsLayerTreeGroup*>( nodeLayer->parent() )->removeChildNode( nodeLayer );
}
}
}
root->removeChildrenGroupWithoutLayers();
}
3 changes: 3 additions & 0 deletions src/server/qgswmsconfigparser.h
Expand Up @@ -26,6 +26,7 @@ class QgsComposerLegend;
class QgsComposerMap;
class QgsComposition;
class QgsMapLayer;
class QgsLegendModelV2;


class SERVER_EXPORT QgsWMSConfigParser
Expand Down Expand Up @@ -154,6 +155,8 @@ class SERVER_EXPORT QgsWMSConfigParser
static QgsVectorLayer* createHighlightLayer( int i, const QString& crsString, QgsGeometry* geom, const QString& labelString, const QStringList& labelSizeSplit, const QStringList& labelColorSplit,
const QStringList& labelWeightSplit, const QStringList& labelFontSplit, const QStringList& labelBufferSizeSplit,
const QStringList& labelBufferColorSplit );

static void setLayerIdsToLegendModel( QgsLegendModelV2* model, const QStringList& layerIds, double scale );
};

#endif // QGSWMSCONFIGPARSER_H

0 comments on commit 6c6e983

Please sign in to comment.