QgsMapHitTest class

Class that runs a hit test with given map settings.

Based on the hit test it returns which symbols will be visible on the map - this is useful for content based legend.

Public types

using LayerFilterExpression = QMap<QString, QString>
Maps an expression string to a layer id.

Constructors, destructors, conversion operators

QgsMapHitTest(const QgsMapSettings& settings, const QgsGeometry& polygon = QgsGeometry(), const QgsMapHitTest::LayerFilterExpression& layerFilterExpression = QgsMapHitTest::LayerFilterExpression())
QgsMapHitTest(const QgsMapSettings& settings, const QgsMapHitTest::LayerFilterExpression& layerFilterExpression)
Constructor version used with only expressions to filter symbols (no extent or polygon intersection)

Public functions

auto legendKeyVisible(const QString& ruleKey, QgsVectorLayer* layer) const -> bool
Tests whether a given legend key is visible for a specified layer.
void run()
Runs the map hit test.
auto symbolVisible(QgsSymbol* symbol, QgsVectorLayer* layer) const -> bool
Tests whether a symbol is visible for a specified layer.

Function documentation

QgsMapHitTest::QgsMapHitTest(const QgsMapSettings& settings, const QgsGeometry& polygon = QgsGeometry(), const QgsMapHitTest::LayerFilterExpression& layerFilterExpression = QgsMapHitTest::LayerFilterExpression())

Parameters
settings Map settings used to evaluate symbols
polygon Polygon geometry to refine the hit test
layerFilterExpression Expression string for each layer id to evaluate in order to refine the symbol selection

bool QgsMapHitTest::legendKeyVisible(const QString& ruleKey, QgsVectorLayer* layer) const

Tests whether a given legend key is visible for a specified layer.

Parameters
ruleKey legend rule key
layer vector layer

bool QgsMapHitTest::symbolVisible(QgsSymbol* symbol, QgsVectorLayer* layer) const

Tests whether a symbol is visible for a specified layer.

Parameters
symbol symbol to find
layer vector layer