Skip to content

Commit 4f44818

Browse files
committed
Add settings button for defining lambda address.
Added settings button, where user can change the lambda-address. Remove commented out code. Changed lambda default port to 8081 Change lambda default port to 8083. Removed settings button from toolbar.
1 parent 54ac1e0 commit 4f44818

File tree

4 files changed

+131
-1
lines changed

4 files changed

+131
-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,14 +4,16 @@
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
16+
from arho_feature_template.utils.misc_utils import get_active_plan_id, get_lambda_settings
1517

1618
if TYPE_CHECKING:
1719
from qgis.gui import QgisInterface, QgsMapTool
@@ -162,6 +164,24 @@ def initGui(self) -> None: # noqa N802
162164
add_to_toolbar=True,
163165
)
164166

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+
176+
self.plugin_settings_action = self.add_action(
177+
"",
178+
text="Asetukset",
179+
triggered_callback=self.open_settings,
180+
add_to_menu=True,
181+
add_to_toolbar=False,
182+
status_tip="Säädä pluginin asetuksia",
183+
)
184+
165185
def on_map_tool_changed(self, new_tool: QgsMapTool, old_tool: QgsMapTool) -> None: # noqa: ARG002
166186
if not isinstance(new_tool, TemplateGeometryDigitizeMapTool):
167187
self.template_dock_action.setChecked(False)
@@ -172,6 +192,22 @@ def add_new_plan(self):
172192
def load_existing_land_use_plan(self):
173193
self.plan_manager.load_land_use_plan()
174194

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

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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__))
@@ -55,3 +56,11 @@ def handle_unsaved_changes() -> bool:
5556
if not commit_all_layer_changes():
5657
return False
5758
return True
59+
60+
61+
def get_lambda_settings():
62+
"""Retrieve Lambda settings, using defaults if not set."""
63+
settings = QSettings("ArhoFeatureTemplate")
64+
lambda_host = settings.value("lambda_host", "localhost")
65+
lambda_port = settings.value("lambda_port", "8083")
66+
return lambda_host, lambda_port

0 commit comments

Comments
 (0)