Skip to content

Commit 2891a2b

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. Clear active_plan_id in clear_all_filters() Set active_plan_id in update_selected_plan-function instead. - Move setting active_plan_id to update_selected_plan() - Removed "Vahvista kaava" button for now, it will be created properly later. - Removed settings button from toolbar.
1 parent 4f44818 commit 2891a2b

File tree

4 files changed

+13
-26
lines changed

4 files changed

+13
-26
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/plugin.py

+1-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from qgis.PyQt.QtCore import QCoreApplication, Qt, QTranslator
66
from qgis.PyQt.QtGui import QIcon
7-
from qgis.PyQt.QtWidgets import QAction, QMessageBox, QWidget
7+
from qgis.PyQt.QtWidgets import QAction, QWidget
88
from qgis.utils import iface
99

1010
from arho_feature_template.core.feature_template_library import FeatureTemplater, TemplateGeometryDigitizeMapTool
@@ -13,7 +13,6 @@
1313
from arho_feature_template.qgis_plugin_tools.tools.custom_logging import setup_logger, teardown_logger
1414
from arho_feature_template.qgis_plugin_tools.tools.i18n import setup_translation
1515
from arho_feature_template.qgis_plugin_tools.tools.resources import plugin_name
16-
from arho_feature_template.utils.misc_utils import get_active_plan_id, get_lambda_settings
1716

1817
if TYPE_CHECKING:
1918
from qgis.gui import QgisInterface, QgsMapTool
@@ -164,15 +163,6 @@ def initGui(self) -> None: # noqa N802
164163
add_to_toolbar=True,
165164
)
166165

167-
self.validate_plan_action = self.add_action(
168-
"",
169-
text="Vahvista kaava",
170-
triggered_callback=self.validate_plan,
171-
add_to_menu=True,
172-
add_to_toolbar=True,
173-
status_tip="Vahvista kaava",
174-
)
175-
176166
self.plugin_settings_action = self.add_action(
177167
"",
178168
text="Asetukset",
@@ -192,17 +182,6 @@ def add_new_plan(self):
192182
def load_existing_land_use_plan(self):
193183
self.plan_manager.load_land_use_plan()
194184

195-
def validate_plan(self):
196-
"""Validate the plan."""
197-
lambda_host, lambda_port = get_lambda_settings()
198-
199-
# Testing.
200-
QMessageBox.information(
201-
None,
202-
"Lambda asetukset",
203-
f"Lambdan isäntä: {lambda_host}\nLambdan portti: {lambda_port}\nAktiivinen kaava: {active_plan}",
204-
)
205-
206185
def open_settings(self):
207186
"""Open the plugin settings dialog."""
208187
settings = PluginSettings()

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)