|
18 | 18 | * (at your option) any later version. *
|
19 | 19 | * *
|
20 | 20 | ***************************************************************************/
|
| 21 | +#include "qgslayertree.h" |
| 22 | +#include "qgsvectorlayer.h" |
| 23 | +#include "qgsvectorlayerfeaturecounter.h" |
| 24 | + |
21 | 25 | #include "qgswmsutils.h"
|
22 | 26 | #include "qgswmsserviceexception.h"
|
23 | 27 | #include "qgswmsgetlegendgraphics.h"
|
@@ -124,5 +128,50 @@ namespace QgsWms
|
124 | 128 | QStringLiteral( "BBOX parameter cannot be combined with RULE." ) );
|
125 | 129 | }
|
126 | 130 | }
|
| 131 | + |
| 132 | + QgsLayerTreeModel *legendModel( const QgsWmsRenderContext &context, QgsLayerTree &tree ) |
| 133 | + { |
| 134 | + const QgsWmsParameters parameters = context.parameters(); |
| 135 | + |
| 136 | + std::unique_ptr<QgsLayerTreeModel> model( new QgsLayerTreeModel( &tree ) ); |
| 137 | + return model.release(); |
| 138 | + } |
| 139 | + |
| 140 | + QgsLayerTree *layerTree( const QgsWmsRenderContext &context ) |
| 141 | + { |
| 142 | + std::unique_ptr<QgsLayerTree> tree; |
| 143 | + |
| 144 | + QList<QgsVectorLayerFeatureCounter *> counters; |
| 145 | + for ( QgsMapLayer *ml : context.layersToRender() ) |
| 146 | + { |
| 147 | + QgsLayerTreeLayer *lt = tree->addLayer( ml ); |
| 148 | + |
| 149 | + // name |
| 150 | + if ( !ml->title().isEmpty() ) |
| 151 | + lt->setName( ml->title() ); |
| 152 | + |
| 153 | + //show feature count |
| 154 | + const bool showFeatureCount = context.parameters().showFeatureCountAsBool(); |
| 155 | + const QString property = QStringLiteral( "showFeatureCount" ); |
| 156 | + lt->setCustomProperty( property, showFeatureCount ); |
| 157 | + |
| 158 | + if ( ml->type() != QgsMapLayerType::VectorLayer || !showFeatureCount ) |
| 159 | + continue; |
| 160 | + |
| 161 | + QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml ); |
| 162 | + QgsVectorLayerFeatureCounter *counter = vl->countSymbolFeatures(); |
| 163 | + if ( !counter ) |
| 164 | + continue; |
| 165 | + |
| 166 | + counters.append( counter ); |
| 167 | + } |
| 168 | + |
| 169 | + for ( QgsVectorLayerFeatureCounter *counter : counters ) |
| 170 | + { |
| 171 | + counter->waitForFinished(); |
| 172 | + } |
| 173 | + |
| 174 | + return tree.release(); |
| 175 | + } |
127 | 176 | } // namespace QgsWms
|
128 | 177 |
|
0 commit comments