Skip to content

Commit 979e0ca

Browse files
authored
Merge pull request #1 from GispoCoding/architecture_planning
Architecture planning
2 parents ae9a890 + 17cb25e commit 979e0ca

12 files changed

+356
-5
lines changed

arho_feature_template/core/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from __future__ import annotations
2+
3+
from dataclasses import dataclass
4+
from typing import TYPE_CHECKING, Sequence
5+
6+
if TYPE_CHECKING:
7+
from qgis.core import QgsVectorLayer
8+
from qgis.gui import QgsDoubleSpinBox, QgsSpinBox
9+
from qgis.PyQt.QtGui import QIcon
10+
from qgis.PyQt.QtWidgets import QLineEdit
11+
12+
13+
@dataclass
14+
class FeatureAttribute:
15+
name: str
16+
display_name: str
17+
feature_attribte_group: str
18+
# attribute_layer: QgsMapLayer # Is this correct type?
19+
additional_information: str
20+
input_field_type: QLineEdit | QgsSpinBox | QgsDoubleSpinBox | None
21+
modifiable: bool = False
22+
hidden: bool = False
23+
24+
25+
@dataclass
26+
class FeatureTemplate:
27+
name: str
28+
description: str
29+
feature_layer: QgsVectorLayer
30+
feature_attributes: Sequence[FeatureAttribute]
31+
display_icon: QIcon | None = None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from __future__ import annotations
2+
3+
import json
4+
from typing import TYPE_CHECKING, Sequence
5+
6+
if TYPE_CHECKING:
7+
from os import PathLike
8+
9+
from arho_feature_template.core.feature_template import FeatureTemplate
10+
11+
12+
class FeatureTemplateLibrary:
13+
"""Class for storing FeatureTemplates and loading them from a JSON (or other conf. file)."""
14+
15+
def __init__(self, json_path: str | PathLike):
16+
self.templates = []
17+
library_dict = self.read_json(json_path)
18+
self.build_templates(library_dict)
19+
20+
def read_json(self, json_path: str | PathLike) -> dict:
21+
self.source_json = json_path
22+
with open(json_path) as f:
23+
return json.load(f)
24+
25+
def build_templates(self, library_dict: dict):
26+
templates = []
27+
28+
_templates_raw = library_dict["templates"]
29+
# for template_raw in templates_raw:
30+
## ... build FeatureTemplate from dict here, in FeatureTemplate class or elsewhere?
31+
# template = FeatureTemplate()
32+
# templates.append(template)
33+
self.templates = templates
34+
35+
def get_templates(self) -> Sequence[FeatureTemplate]:
36+
return self.templates

arho_feature_template/core/forms/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from arho_feature_template.core.feature_template import FeatureTemplate
2+
from arho_feature_template.core.forms.feature_attribute_form import FeatureAttributeForm
3+
4+
5+
class AddFeatureForm(FeatureAttributeForm):
6+
"""Dialog for filling and saving attribute data that opens when a new feature has been digitized."""
7+
8+
def __init__(self, feature_template: FeatureTemplate):
9+
super().__init__(feature_template)
10+
11+
def _init_feature_attributes(self):
12+
# for feature_attribute in self.feature_template.feature_attributes:
13+
# # Create the form here, add rows with labels and input fields
14+
pass
15+
16+
def save(self):
17+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from importlib import resources
2+
3+
from qgis.PyQt import uic
4+
from qgis.PyQt.QtWidgets import QDialog
5+
6+
from arho_feature_template.core.feature_template import FeatureTemplate
7+
8+
ui_path = resources.files(__package__) / "feature_attribute_form.ui"
9+
FormClass, _ = uic.loadUiType(ui_path)
10+
11+
class FeatureAttributeForm(QDialog, FormClass):
12+
"""Parent class for feature forms for adding and modifying feature attribute data."""
13+
14+
def __init__(self, feature_template: FeatureTemplate):
15+
super().__init__()
16+
self.setupUi(self)
17+
self.feature_template = feature_template
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>Dialog</class>
4+
<widget class="QDialog" name="Dialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>640</width>
10+
<height>480</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Dialog</string>
15+
</property>
16+
<widget class="QDialogButtonBox" name="buttonBox">
17+
<property name="geometry">
18+
<rect>
19+
<x>10</x>
20+
<y>440</y>
21+
<width>621</width>
22+
<height>32</height>
23+
</rect>
24+
</property>
25+
<property name="orientation">
26+
<enum>Qt::Horizontal</enum>
27+
</property>
28+
<property name="standardButtons">
29+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
30+
</property>
31+
</widget>
32+
</widget>
33+
<resources/>
34+
<connections>
35+
<connection>
36+
<sender>buttonBox</sender>
37+
<signal>accepted()</signal>
38+
<receiver>Dialog</receiver>
39+
<slot>accept()</slot>
40+
<hints>
41+
<hint type="sourcelabel">
42+
<x>248</x>
43+
<y>254</y>
44+
</hint>
45+
<hint type="destinationlabel">
46+
<x>157</x>
47+
<y>274</y>
48+
</hint>
49+
</hints>
50+
</connection>
51+
<connection>
52+
<sender>buttonBox</sender>
53+
<signal>rejected()</signal>
54+
<receiver>Dialog</receiver>
55+
<slot>reject()</slot>
56+
<hints>
57+
<hint type="sourcelabel">
58+
<x>316</x>
59+
<y>260</y>
60+
</hint>
61+
<hint type="destinationlabel">
62+
<x>286</x>
63+
<y>274</y>
64+
</hint>
65+
</hints>
66+
</connection>
67+
</connections>
68+
</ui>

arho_feature_template/core/panels/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from importlib import resources
2+
3+
from qgis.PyQt import uic
4+
from qgis.PyQt.QtWidgets import QWidget
5+
6+
from arho_feature_template.core.feature_template_library import FeatureTemplateLibrary
7+
8+
ui_path = resources.files(__package__) / "template_library_panel.ui"
9+
FormClass, _ = uic.loadUiType(ui_path)
10+
11+
class TemplateLibraryPanel(QWidget, FormClass):
12+
"""Dock widget for selecting a feature template."""
13+
14+
def __init__(self, feature_template_library: FeatureTemplateLibrary):
15+
super().__init__()
16+
self.setupUi(self)
17+
self.initialize_from_library(feature_template_library)
18+
19+
def initialize_from_library(self, feature_template_library: FeatureTemplateLibrary):
20+
# Initialization logic
21+
self.library = feature_template_library
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>Form</class>
4+
<widget class="QWidget" name="Form">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>640</width>
10+
<height>480</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Form</string>
15+
</property>
16+
</widget>
17+
<resources/>
18+
<connections/>
19+
</ui>

arho_feature_template/plugin.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
from typing import Callable
44

5-
from qgis.PyQt.QtCore import QCoreApplication, QTranslator
5+
from qgis.gui import QgsDockWidget
6+
from qgis.PyQt.QtCore import QCoreApplication, Qt, QTranslator
67
from qgis.PyQt.QtGui import QIcon
78
from qgis.PyQt.QtWidgets import QAction, QWidget
89
from qgis.utils import iface
910

11+
from arho_feature_template.core.feature_template_library import FeatureTemplateLibrary
12+
from arho_feature_template.core.panels.template_library_panel import TemplateLibraryPanel
1013
from arho_feature_template.qgis_plugin_tools.tools.custom_logging import setup_logger, teardown_logger
1114
from arho_feature_template.qgis_plugin_tools.tools.i18n import setup_translation
12-
from arho_feature_template.qgis_plugin_tools.tools.resources import plugin_name
15+
from arho_feature_template.qgis_plugin_tools.tools.resources import plugin_name, resources_path
1316

17+
LIBRARY_JSON = resources_path("asemakaava-template-library-test.json")
1418

1519
class Plugin:
1620
"""QGIS Plugin Implementation."""
@@ -33,6 +37,9 @@ def __init__(self) -> None:
3337
self.actions: list[QAction] = []
3438
self.menu = Plugin.name
3539

40+
# Create and initialize default feature template library
41+
self.active_library = FeatureTemplateLibrary(LIBRARY_JSON)
42+
3643
def add_action(
3744
self,
3845
icon_path: str,
@@ -107,7 +114,7 @@ def initGui(self) -> None: # noqa N802
107114
text=Plugin.name,
108115
callback=self.run,
109116
parent=iface.mainWindow(),
110-
add_to_toolbar=False,
117+
add_to_toolbar=True,
111118
)
112119

113120
def onClosePlugin(self) -> None: # noqa N802
@@ -121,5 +128,9 @@ def unload(self) -> None:
121128
teardown_logger(Plugin.name)
122129

123130
def run(self) -> None:
124-
"""Run method that performs all the real work"""
125-
print("Hello QGIS plugin") # noqa: T201
131+
self.feature_template_dock= QgsDockWidget()
132+
self.add_feature_panel = TemplateLibraryPanel(self.active_library)
133+
self.feature_template_dock.setWidget(self.add_feature_panel)
134+
self.feature_template_dock.setWindowTitle("ARHO") # NOTE: Placeholder name
135+
136+
iface.addDockWidget(Qt.RightDockWidgetArea, self.feature_template_dock)

0 commit comments

Comments
 (0)