Skip to content
Permalink
Browse files

Add method to build layer tree

  • Loading branch information
pblottiere committed Apr 2, 2019
1 parent bc72ff2 commit 46746a3713623e63f0bcbf170919cd7584e8fe41
@@ -18,6 +18,10 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgslayertree.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayerfeaturecounter.h"

#include "qgswmsutils.h"
#include "qgswmsserviceexception.h"
#include "qgswmsgetlegendgraphics.h"
@@ -124,5 +128,50 @@ namespace QgsWms
QStringLiteral( "BBOX parameter cannot be combined with RULE." ) );
}
}

QgsLayerTreeModel *legendModel( const QgsWmsRenderContext &context, QgsLayerTree &tree )
{
const QgsWmsParameters parameters = context.parameters();

std::unique_ptr<QgsLayerTreeModel> model( new QgsLayerTreeModel( &tree ) );
return model.release();
}

QgsLayerTree *layerTree( const QgsWmsRenderContext &context )
{
std::unique_ptr<QgsLayerTree> tree;

QList<QgsVectorLayerFeatureCounter *> counters;
for ( QgsMapLayer *ml : context.layersToRender() )
{
QgsLayerTreeLayer *lt = tree->addLayer( ml );

// name
if ( !ml->title().isEmpty() )
lt->setName( ml->title() );

//show feature count
const bool showFeatureCount = context.parameters().showFeatureCountAsBool();
const QString property = QStringLiteral( "showFeatureCount" );
lt->setCustomProperty( property, showFeatureCount );

if ( ml->type() != QgsMapLayerType::VectorLayer || !showFeatureCount )
continue;

QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
QgsVectorLayerFeatureCounter *counter = vl->countSymbolFeatures();
if ( !counter )
continue;

counters.append( counter );
}

for ( QgsVectorLayerFeatureCounter *counter : counters )
{
counter->waitForFinished();
}

return tree.release();
}
} // namespace QgsWms

@@ -18,6 +18,9 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgslayertreemodel.h"

#include "qgswmsrendercontext.h"

namespace QgsWms
{
@@ -30,8 +33,8 @@ namespace QgsWms
QgsServerResponse &response );

void checkParameters( const QgsWmsParameters &parameters );
} // namespace QgsWms



QgsLayerTreeModel *legendModel( const QgsWmsRenderContext &context, QgsLayerTree &tree );

QgsLayerTree *layerTree( const QgsWmsRenderContext &context );
} // namespace QgsWms

0 comments on commit 46746a3

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