Skip to content
Permalink
Browse files

Add basic support for hit test without calling getMap

  • Loading branch information
pblottiere committed Apr 3, 2019
1 parent f482ddf commit ba14e1448a5e6f741ea5bcda130411b4ee7bb390
@@ -127,13 +127,33 @@ namespace QgsWms
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QStringLiteral( "BBOX parameter cannot be combined with RULE." ) );
}

if ( ! parameters.bbox().isEmpty() && parameters.bboxAsRectangle().isEmpty() )
{
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
parameters[QgsWmsParameter::BBOX] );
}
}

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

std::unique_ptr<QgsLayerTreeModel> model( new QgsLayerTreeModel( &tree ) );

if ( context.scaleDenominator() > 0 )
{
model->setLegendFilterByScale( context.scaleDenominator() );
}

// content based legend
if ( ! parameters.bbox().isEmpty() )
{
QgsRenderer renderer( context );
const QgsRenderer::HitTest symbols = renderer.symbols();

// TODO
}

return model.release();
}

@@ -249,6 +249,36 @@ namespace QgsWms
r->stopRender( context );
}

QgsRenderer::HitTest QgsRenderer::symbols()
{
// check size
checkMaximumWidthHeight();

// init layer restorer before doing anything
std::unique_ptr<QgsLayerRestorer> restorer;
restorer.reset( new QgsLayerRestorer( mContext.layers() ) );

// configure layers
QgsMapSettings mapSettings;
QList<QgsMapLayer *> layers = mContext.layersToRender();
configureLayers( layers, &mapSettings );

// create the output image and the painter
std::unique_ptr<QPainter> painter;
std::unique_ptr<QImage> image( createImage() );

// configure map settings (background, DPI, ...)
configureMapSettings( image.get(), mapSettings );

// add layers to map settings
mapSettings.setLayers( layers );

// run hit tests
HitTest symbols;
runHitTest( mapSettings, symbols );

return symbols;
}

QByteArray QgsRenderer::getPrint()
{
@@ -385,7 +415,7 @@ namespace QgsWms
std::unique_ptr<QImage> image( new QImage() );
configureMapSettings( image.get(), mapSettings );

// add layers to map settings (revert order for the rendering)
// add layers to map settings
mapSettings.setLayers( layers );

// configure layout
@@ -751,7 +781,7 @@ namespace QgsWms
// configure map settings (background, DPI, ...)
configureMapSettings( image.get(), mapSettings );

// add layers to map settings (revert order for the rendering)
// add layers to map settings
mapSettings.setLayers( layers );

// rendering step for layers
@@ -83,6 +83,8 @@ namespace QgsWms
typedef QSet<QString> SymbolSet;
typedef QHash<QgsVectorLayer *, SymbolSet> HitTest;

HitTest symbols();

/**
* Returns the map as an image (or NULLPTR in case of error). The caller takes ownership
of the image object). If an instance to existing hit test structure is passed, instead of rendering

0 comments on commit ba14e14

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