Skip to content

Commit 4cf2df5

Browse files
Mtk112LKajan
authored andcommitted
Store active plan's id to a ProjectVariable.
Store plan's id to a ProjectVariable when creating new plan or opening existing plan. Clear active_plan_id in clear_all_filters()
1 parent d5e5cf8 commit 4cf2df5

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

arho_feature_template/core/plan_manager.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from qgis.core import QgsProject, QgsVectorLayer
1+
from qgis.core import QgsExpressionContextUtils, QgsProject, QgsVectorLayer
22
from qgis.PyQt.QtWidgets import QDialog, QMessageBox
33
from qgis.utils import iface
44

@@ -95,7 +95,8 @@ def load_land_use_plan(self):
9595
update_selected_plan(plan)
9696

9797
def clear_all_filters(self):
98-
"""Clear filters for all vector layers in the project."""
98+
"""Clear active_plan_id and filters for all vector layers in the project."""
99+
QgsExpressionContextUtils.setProjectVariable(QgsProject.instance(), "active_plan_id", None)
99100
for layer in QgsProject.instance().mapLayers().values():
100101
if isinstance(layer, QgsVectorLayer):
101102
layer.setSubsetString("")

arho_feature_template/core/update_plan.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dataclasses import dataclass
22

3-
from qgis.core import QgsMapLayer, QgsProject, QgsVectorLayer
3+
from qgis.core import QgsExpressionContextUtils, QgsMapLayer, QgsProject, QgsVectorLayer
44
from qgis.utils import iface
55

66

@@ -24,6 +24,7 @@ class LandUsePlan:
2424
def update_selected_plan(new_plan: LandUsePlan):
2525
"""Update the project layers based on the selected land use plan."""
2626
plan_id = new_plan.id
27+
QgsExpressionContextUtils.setProjectVariable(QgsProject.instance(), "active_plan_id", plan_id)
2728

2829
for layer_name, field_name in LAYER_PLAN_ID_MAP.items():
2930
# Set the filter on each layer using the plan_id

arho_feature_template/utils/misc_utils.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
from qgis.core import QgsProject, QgsVectorLayer
3+
from qgis.core import QgsExpressionContextUtils, QgsProject, QgsVectorLayer
44
from qgis.PyQt.QtCore import QSettings
55
from qgis.PyQt.QtWidgets import QMessageBox
66

@@ -58,6 +58,12 @@ def handle_unsaved_changes() -> bool:
5858
return True
5959

6060

61+
def get_active_plan_id():
62+
"""Retrieve the active plan ID stored as a project variable."""
63+
# return QgsExpressionContextUtils.projectScope(QgsProject.instance(), "active_plan_id")
64+
return QgsExpressionContextUtils.projectScope(QgsProject.instance()).variable("active_plan_id")
65+
66+
6167
def get_lambda_settings():
6268
"""Retrieve Lambda settings, using defaults if not set."""
6369
settings = QSettings("ArhoFeatureTemplate")

0 commit comments

Comments
 (0)