Skip to content

Commit ee46cd3

Browse files
committed
Add settings button for defining lambda address.
Added settings button, where user can change the lambda-address.
1 parent 54ac1e0 commit ee46cd3

File tree

4 files changed

+138
-1
lines changed

4 files changed

+138
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from importlib import resources
2+
3+
from qgis.PyQt import uic
4+
from qgis.PyQt.QtCore import QSettings
5+
from qgis.PyQt.QtWidgets import QDialog
6+
7+
ui_path = resources.files(__package__) / "plugin_settings.ui"
8+
FormClass, _ = uic.loadUiType(ui_path)
9+
10+
11+
class PluginSettings(QDialog, FormClass): # type: ignore
12+
def __init__(self, parent=None):
13+
super().__init__(parent)
14+
15+
self.setupUi(self)
16+
17+
self.saveButton.clicked.connect(self.save_settings)
18+
19+
self.load_settings()
20+
21+
def load_settings(self):
22+
"""Load settings from QSettings with default values."""
23+
settings = QSettings("ArhoFeatureTemplate")
24+
25+
lambda_host = settings.value("lambda_host", "localhost")
26+
lambda_port = settings.value("lambda_port", "5435")
27+
28+
self.hostInput.setText(lambda_host)
29+
self.portInput.setText(lambda_port)
30+
31+
def save_settings(self):
32+
"""Save settings to QSettings."""
33+
settings = QSettings("ArhoFeatureTemplate")
34+
settings.setValue("lambda_host", self.hostInput.text())
35+
settings.setValue("lambda_port", self.portInput.text())
36+
37+
self.accept()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>PluginSettings</class>
4+
<widget class="QDialog" name="PluginSettings">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>300</width>
10+
<height>150</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Asetukset</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="verticalLayout">
17+
<item>
18+
<widget class="QLabel" name="labelHost">
19+
<property name="text">
20+
<string>Lambdan isäntä:</string>
21+
</property>
22+
</widget>
23+
</item>
24+
<item>
25+
<widget class="QLineEdit" name="hostInput"/>
26+
</item>
27+
<item>
28+
<widget class="QLabel" name="labelPort">
29+
<property name="text">
30+
<string>Lambdan portti:</string>
31+
</property>
32+
</widget>
33+
</item>
34+
<item>
35+
<widget class="QLineEdit" name="portInput"/>
36+
</item>
37+
<item>
38+
<widget class="QPushButton" name="saveButton">
39+
<property name="text">
40+
<string>Tallenna asetukset</string>
41+
</property>
42+
</widget>
43+
</item>
44+
</layout>
45+
</widget>
46+
<resources/>
47+
<connections/>
48+
</ui>

arho_feature_template/plugin.py

+37-1
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44

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

1010
from arho_feature_template.core.feature_template_library import FeatureTemplater, TemplateGeometryDigitizeMapTool
1111
from arho_feature_template.core.plan_manager import PlanManager
12+
from arho_feature_template.gui.plugin_settings import PluginSettings
1213
from arho_feature_template.qgis_plugin_tools.tools.custom_logging import setup_logger, teardown_logger
1314
from arho_feature_template.qgis_plugin_tools.tools.i18n import setup_translation
1415
from arho_feature_template.qgis_plugin_tools.tools.resources import plugin_name
1516

17+
# 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
19+
1620
if TYPE_CHECKING:
1721
from qgis.gui import QgisInterface, QgsMapTool
1822

@@ -162,6 +166,24 @@ def initGui(self) -> None: # noqa N802
162166
add_to_toolbar=True,
163167
)
164168

169+
self.validate_plan_action = self.add_action(
170+
"",
171+
text="Vahvista kaava",
172+
triggered_callback=self.validate_plan,
173+
add_to_menu=True,
174+
add_to_toolbar=True,
175+
status_tip="Vahvista kaava",
176+
)
177+
178+
self.plugin_settings_action = self.add_action(
179+
"",
180+
text="Asetukset",
181+
triggered_callback=self.open_settings,
182+
add_to_menu=True,
183+
add_to_toolbar=True,
184+
status_tip="Säädä pluginin asetuksia",
185+
)
186+
165187
def on_map_tool_changed(self, new_tool: QgsMapTool, old_tool: QgsMapTool) -> None: # noqa: ARG002
166188
if not isinstance(new_tool, TemplateGeometryDigitizeMapTool):
167189
self.template_dock_action.setChecked(False)
@@ -172,6 +194,20 @@ def add_new_plan(self):
172194
def load_existing_land_use_plan(self):
173195
self.plan_manager.load_land_use_plan()
174196

197+
def validate_plan(self):
198+
"""Validate the plan."""
199+
lambda_host, lambda_port = get_lambda_settings()
200+
201+
# Testing.
202+
QMessageBox.information(None, "Lambda Settings", f"Lambda Host: {lambda_host}\nLambda Port: {lambda_port}")
203+
# print(f"Hard Coded Lambda Host: {hc_lambda_host}")
204+
# print(f"Hard Coded Lambda Port: {hc_lambda_port}")
205+
206+
def open_settings(self):
207+
"""Open the plugin settings dialog."""
208+
settings = PluginSettings()
209+
settings.exec_()
210+
175211
def unload(self) -> None:
176212
"""Removes the plugin menu item and icon from QGIS GUI."""
177213
for action in self.actions:

arho_feature_template/utils/misc_utils.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import os
22

33
from qgis.core import QgsProject, QgsVectorLayer
4+
from qgis.PyQt.QtCore import QSettings
45
from qgis.PyQt.QtWidgets import QMessageBox
56

67
PLUGIN_PATH = os.path.dirname(os.path.dirname(__file__))
8+
# LAMBDA_HOST = "localhost"
9+
# LAMBDA_PORT = 5435
710

811

912
def check_layer_changes() -> bool:
@@ -55,3 +58,16 @@ def handle_unsaved_changes() -> bool:
5558
if not commit_all_layer_changes():
5659
return False
5760
return True
61+
62+
63+
def get_lambda_settings():
64+
"""Retrieve Lambda settings, using defaults if not set."""
65+
settings = QSettings("ArhoFeatureTemplate")
66+
lambda_host = settings.value("lambda_host", "localhost")
67+
lambda_port = settings.value("lambda_port", "5435")
68+
return lambda_host, lambda_port
69+
70+
71+
# def get_lambda_address():
72+
# """Returns lambda address."""
73+
# return LAMBDA_HOST, LAMBDA_PORT

0 commit comments

Comments
 (0)