Skip to content

Commit 48cd397

Browse files
committed
use get_active_plan_id util function and implement set_active_plan_id util function
1 parent 800b830 commit 48cd397

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

arho_feature_template/core/plan_manager.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
from typing import TYPE_CHECKING
66

7-
from qgis.core import QgsExpressionContextUtils, QgsProject, QgsVectorLayer, QgsWkbTypes
7+
from qgis.core import QgsProject, QgsVectorLayer, QgsWkbTypes
88
from qgis.gui import QgsMapToolDigitizeFeature
99
from qgis.PyQt.QtWidgets import QDialog, QMessageBox
1010

@@ -55,6 +55,7 @@
5555
get_active_plan_id,
5656
handle_unsaved_changes,
5757
iface,
58+
set_active_plan_id,
5859
)
5960

6061
if TYPE_CHECKING:
@@ -227,8 +228,7 @@ def edit_plan(self):
227228
if not plan_layer:
228229
return
229230

230-
active_plan_id = QgsExpressionContextUtils.projectScope(QgsProject.instance()).variable("active_plan_id")
231-
feature = PlanLayer.get_feature_by_id(active_plan_id, no_geometries=False)
231+
feature = PlanLayer.get_feature_by_id(get_active_plan_id(), no_geometries=False)
232232
if feature is None:
233233
iface.messageBar().pushWarning("", "No active/open plan found!")
234234
return
@@ -328,7 +328,7 @@ def set_active_plan(self, plan_id: str | None):
328328
if previously_in_edit_mode:
329329
plan_layer.rollBack()
330330

331-
QgsExpressionContextUtils.setProjectVariable(QgsProject.instance(), "active_plan_id", plan_id)
331+
set_active_plan_id(plan_id)
332332
for layer in plan_layers:
333333
layer.apply_filter(plan_id)
334334

arho_feature_template/project/layers/plan_layers.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from textwrap import dedent
77
from typing import Any, ClassVar, Generator
88

9-
from qgis.core import QgsExpressionContextUtils, QgsFeature, QgsProject, QgsVectorLayerUtils
9+
from qgis.core import QgsFeature, QgsVectorLayerUtils
1010

1111
from arho_feature_template.core.models import (
1212
AdditionalInformation,
@@ -197,11 +197,7 @@ def feature_from_model(cls, model: RegulationGroup, plan_id: str | None = None)
197197
feature["short_name"] = model.short_name if model.short_name else None
198198
feature["name"] = {LANGUAGE: model.name if model.name else None}
199199
feature["type_of_plan_regulation_group_id"] = model.type_code_id
200-
feature["plan_id"] = (
201-
plan_id
202-
if plan_id
203-
else QgsExpressionContextUtils.projectScope(QgsProject.instance()).variable("active_plan_id")
204-
)
200+
feature["plan_id"] = plan_id if plan_id else get_active_plan_id()
205201
feature["id"] = model.id_ if model.id_ else feature["id"]
206202
return feature
207203

arho_feature_template/utils/misc_utils.py

+5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ def handle_unsaved_changes() -> bool:
8686
return True
8787

8888

89+
def set_active_plan_id(plan_id: str | None):
90+
"""Store the given plan ID as the active plan ID as a project variable."""
91+
QgsExpressionContextUtils.setProjectVariable(QgsProject.instance(), "active_plan_id", plan_id)
92+
93+
8994
def get_active_plan_id():
9095
"""Retrieve the active plan ID stored as a project variable."""
9196
return QgsExpressionContextUtils.projectScope(QgsProject.instance()).variable("active_plan_id")

0 commit comments

Comments
 (0)