Skip to content

Commit

Permalink
Clear filter when a new project is loaded or created
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Kröger committed Sep 21, 2023
1 parent 9ed1a8c commit 245bac7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def connectSignals(self):
# the layer filter will happen before the data is actually requested, at least for PostGIS
QgsProject.instance().layersAdded.connect(self.onLayersAdded)

# to clear the filter when the project is cleared (e.g. a new project is loaded or created)
QgsProject.instance().cleared.connect(self.onProjectCleared)

def disconnectSignals(self):
QgsProject.instance().layersAdded.disconnect(self.onLayersAdded)

Expand All @@ -49,6 +52,13 @@ def onLayersAdded(self, layers: Iterable[QgsMapLayer]):
self.setFilterFromLayer(layer)
return

def onProjectCleared(self):
"""Removes the filter if one is active.
This prevents filters from staying active when the user loads another project or creates a new one.
"""
self.removeFilter()

def setFilterFromLayer(self, layer):
filterDefinition = FilterDefinition.fromFilterString(layer.subsetString())
self.currentFilter = filterDefinition
Expand Down
4 changes: 3 additions & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name=Räumlicher Filter
qgisMinimumVersion=3.22
description=Spatial filters for PostGIS, GeoPackage and Spatialite layers
description[de]=Räumliche Filter für PostGIS-, GeoPackage- und Spatialite-Layer
version=1.4
version=1.5
author=WhereGroup GmbH (Peter Gipper, Mathias Gröbe, Johannes Kröger)
[email protected]

Expand All @@ -17,6 +17,8 @@ hasProcessingProvider=no
tags=python, filter, vector, postgis, performance

changelog=
Version 1.5:
- Clear filter when a new project is loaded or created
Version 1.4:
- Add padding when zooming to filter geometry (thanks pathmapper!)
- Add plugin name to messages in message bar
Expand Down

0 comments on commit 245bac7

Please sign in to comment.