Skip to content

Commit 54e23b8

Browse files
committed
Store active plan's id to a ProjectVariable.
Store plan's id to a ProjectVariable when creating new plan or opening existing plan.
1 parent ee46cd3 commit 54e23b8

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

arho_feature_template/core/plan_manager.py

+3-1
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

@@ -64,6 +64,7 @@ def feature_added(self):
6464
new_feature = self.kaava_layer.getFeature(new_feature_id)
6565
if new_feature.isValid():
6666
feature_id_value = new_feature["id"]
67+
QgsExpressionContextUtils.setProjectVariable(QgsProject.instance(), "active_plan_id", feature_id_value)
6768
update_selected_plan(LandUsePlan(feature_id_value))
6869
else:
6970
iface.messageBar().pushMessage("Error", "Invalid feature retrieved.", level=3)
@@ -92,6 +93,7 @@ def load_land_use_plan(self):
9293
return
9394

9495
plan = LandUsePlan(selected_plan_id)
96+
QgsExpressionContextUtils.setProjectVariable(QgsProject.instance(), "active_plan_id", selected_plan_id)
9597
update_selected_plan(plan)
9698

9799
def clear_all_filters(self):

arho_feature_template/plugin.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from arho_feature_template.qgis_plugin_tools.tools.resources import plugin_name
1616

1717
# from arho_feature_template.utils.misc_utils import get_lambda_address, get_lambda_settings
18-
from arho_feature_template.utils.misc_utils import get_lambda_settings
18+
from arho_feature_template.utils.misc_utils import get_active_plan_id, get_lambda_settings
1919

2020
if TYPE_CHECKING:
2121
from qgis.gui import QgisInterface, QgsMapTool
@@ -197,9 +197,14 @@ def load_existing_land_use_plan(self):
197197
def validate_plan(self):
198198
"""Validate the plan."""
199199
lambda_host, lambda_port = get_lambda_settings()
200+
active_plan = get_active_plan_id()
200201

201202
# Testing.
202-
QMessageBox.information(None, "Lambda Settings", f"Lambda Host: {lambda_host}\nLambda Port: {lambda_port}")
203+
QMessageBox.information(
204+
None,
205+
"Lambda asetukset",
206+
f"Lambdan isäntä: {lambda_host}\nLambdan portti: {lambda_port}\nAktiivinen kaava: {active_plan}",
207+
)
203208
# print(f"Hard Coded Lambda Host: {hc_lambda_host}")
204209
# print(f"Hard Coded Lambda Port: {hc_lambda_port}")
205210

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

@@ -60,6 +60,12 @@ def handle_unsaved_changes() -> bool:
6060
return True
6161

6262

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

0 commit comments

Comments
 (0)