Class: QgsMapHitTest

class qgis.core.QgsMapHitTest(settings: QgsMapSettings, polygon: QgsGeometry = QgsGeometry(), layerFilterExpression: Dict[str, str] = {})

Bases: sip.wrapper

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

QgsMapHitTest(settings: QgsMapSettings, layerFilterExpression: Dict[str, str]) Constructor version used with only expressions to filter symbols (no extent or polygon intersection)

QgsMapHitTest(QgsMapHitTest)

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.

Methods

legendKeyVisible

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

run

Runs the map hit test

symbolVisible

Tests whether a symbol is visible for a specified layer.

legendKeyVisible(self, ruleKey: str, layer: QgsVectorLayer)bool

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

Parameters
  • ruleKey (str) – legend rule key

  • layer (QgsVectorLayer) – vector layer

See also

symbolVisible()

New in version 2.14.

Return type

bool

run(self)

Runs the map hit test

symbolVisible(self, symbol: QgsSymbol, layer: QgsVectorLayer)bool

Tests whether a symbol is visible for a specified layer.

Parameters

New in version 2.12.

Return type

bool