-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alustava arkkitehtuurisuunnitelma #1
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING, Sequence | ||
|
||
if TYPE_CHECKING: | ||
from qgis.core import QgsMapLayer, QgsVectorLayer | ||
from qgis.gui import QgsDoubleSpinBox, QgsSpinBox | ||
from qgis.PyQt.QtGui import QIcon | ||
from qgis.PyQt.QtWidgets import QLineEdit | ||
|
||
|
||
@dataclass | ||
class FeatureAttribute: | ||
name: str | ||
display_name: str | ||
feature_attribte_group: str | ||
attribute_layer: QgsMapLayer # Is this correct type? | ||
additional_information: str | ||
input_field_type: QLineEdit | QgsSpinBox | QgsDoubleSpinBox | None | ||
modifiable: bool = False | ||
hidden: bool = False | ||
|
||
|
||
@dataclass | ||
class FeatureTemplate: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now missing possible child features. But that's totally fine for now! Let's first try to get this working with the most simple one feature case. Probably the library config should be updated accordingly. |
||
name: str | ||
description: str | ||
feature_layer: QgsVectorLayer | ||
feature_attributes: Sequence[FeatureAttribute] | ||
display_icon: QIcon | None = None |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from typing import TYPE_CHECKING, Sequence | ||
|
||
if TYPE_CHECKING: | ||
from os import PathLike | ||
|
||
from arho_feature_template.core.feature_template import FeatureTemplate | ||
|
||
|
||
class FeatureTemplateLibrary: | ||
"""Class for storing FeatureTemplates and loading them from a JSON (or other conf. file).""" | ||
|
||
def __init__(self, json_path: str | PathLike): | ||
self.templates = [] | ||
library_dict = self.read_json(json_path) | ||
self.build_templates(library_dict) | ||
|
||
def read_json(self, json_path: str | PathLike) -> dict: | ||
self.source_json = json_path | ||
with open(json_path) as f: | ||
return json.load(f) | ||
|
||
def build_templates(self, library_dict: dict): | ||
templates = [] | ||
|
||
_templates_raw = library_dict["templates"] | ||
# for template_raw in templates_raw: | ||
## ... build FeatureTemplate from dict here, in FeatureTemplate class or elsewhere? | ||
# template = FeatureTemplate() | ||
# templates.append(template) | ||
self.templates = templates | ||
|
||
def get_templates(self) -> Sequence[FeatureTemplate]: | ||
return self.templates |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from arho_feature_template.core.feature_template import FeatureTemplate | ||
from arho_feature_template.core.forms.feature_attribute_form import FeatureAttributeForm | ||
|
||
|
||
class AddFeatureForm(FeatureAttributeForm): | ||
"""Dialog for filling and saving attribute data that opens when a new feature has been digitized.""" | ||
|
||
def __init__(self, feature_template: FeatureTemplate): | ||
super().__init__(feature_template) | ||
|
||
def _init_feature_attributes(self): | ||
# for feature_attribute in self.feature_template.feature_attributes: | ||
# # Create the form here, add rows with labels and input fields | ||
pass | ||
|
||
def save(self): | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from qgis.PyQt.QtWidgets import QDialog | ||
|
||
from arho_feature_template.core.feature_template import FeatureTemplate | ||
from arho_feature_template.qgis_plugin_tools.tools.resources import load_ui | ||
|
||
|
||
class FeatureAttributeForm(QDialog, load_ui("feature_attribute_form.ui")): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of using the I would to suggest something like this: from importlib import resources
from qgis.PyQt import uic
ui_path = resources.files() / "feature_attribute_form.ui" # files() without arguments looks resources adjacent to the caller module
FormClass, _ = uic.loadUiType(ui_path)
class FeatureAttributeForm(QDialog, FormClass):
... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have strong preference for the UI loading, but I like the idea that the ui files are next to the python module. Changed to this (but gave |
||
"""Parent class for feature forms for adding and modifying feature attribute data.""" | ||
|
||
def __init__(self, feature_template: FeatureTemplate): | ||
super().__init__() | ||
self.setupUi(self) | ||
self.feature_template = feature_template |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from qgis.PyQt.QtWidgets import QWidget | ||
|
||
from arho_feature_template.core.feature_template_library import FeatureTemplateLibrary | ||
from arho_feature_template.qgis_plugin_tools.tools.resources import load_ui | ||
|
||
|
||
class AddFeaturePanel(QWidget, load_ui("add_feature_panel.ui")): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rename to something like |
||
"""Dock widget for selecting a feature template.""" | ||
|
||
def __init__(self, feature_template_library: FeatureTemplateLibrary): | ||
super().__init__() | ||
self.setupUi(self) | ||
self.initialize_from_library(feature_template_library) | ||
|
||
def initialize_from_library(self, feature_template_library: FeatureTemplateLibrary): | ||
# Initialization logic | ||
self.library = feature_template_library |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
{ | ||
"version": 1, | ||
"name": "Asemakaava-kaavamääräyskirjasto", | ||
"templates": [ | ||
{ | ||
"name": "Asuin-, liike- ja toimistorakennusten alue", | ||
"description": "Aluella kuvataan ...", | ||
"feature": { | ||
"layer": "land_use_area", | ||
"fields": [ | ||
{ | ||
"field": "name" | ||
}, | ||
{ | ||
"field": "type_of_underground_id", | ||
"value": 1 | ||
} | ||
], | ||
"children": [ | ||
{ | ||
"layer": "plan_requlation_group", | ||
"fields": [ | ||
{ | ||
"field": "name", | ||
"value": "Asuin-, liike- ja toimistorakennusten alue", | ||
"allow_user_input": false | ||
} | ||
], | ||
"children": [ | ||
{ | ||
"layer": "plan_requlation", | ||
"fields": [ | ||
{ | ||
"field": "type_of_plan_regulation_id", | ||
"value": "asumisenAlue", | ||
"hidden": true | ||
} | ||
], | ||
"children": { | ||
"layer": "additional_information_of_plan_regulation", | ||
"fields": [ | ||
{ | ||
"field": "type_of_additional_information_id", | ||
"value": "paakayttotarkoitus", | ||
"hidden": true | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"layer": "plan_requlation", | ||
"fields": [ | ||
{ | ||
"field": "type_of_plan_regulation_id", | ||
"value": "liikerakennustenAlue", | ||
"hidden": true | ||
} | ||
], | ||
"children": { | ||
"layer": "additional_information_of_plan_regulation", | ||
"fields": [ | ||
{ | ||
"field": "type_of_additional_information_id", | ||
"value": "paakayttotarkoitus", | ||
"hidden": true | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"layer": "plan_requlation", | ||
"fields": [ | ||
{ | ||
"field": "type_of_plan_regulation_id", | ||
"value": "toimitilojenAlue", | ||
"hidden": true | ||
} | ||
], | ||
"children": { | ||
"layer": "additional_information_of_plan_regulation", | ||
"fields": [ | ||
{ | ||
"field": "type_of_additional_information_id", | ||
"value": "paakayttotarkoitus", | ||
"hidden": true | ||
} | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"layer": "plan_requlation_group", | ||
"fields": [ | ||
{ | ||
"field": "name", | ||
"value": "Korttelin numero", | ||
"allow_user_input": false | ||
} | ||
], | ||
"children": [ | ||
{ | ||
"layer": "plan_requlation", | ||
"fields": [ | ||
{ | ||
"field": "type_of_plan_regulation_id", | ||
"value": "korttelinNumero" | ||
}, | ||
{ | ||
"field": "numeric_value", | ||
"required": true | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "Asuinrakennusten alue", | ||
"description": "Asuinrakennusten alue ...", | ||
"fields": [ | ||
{ | ||
"field": "", | ||
"required": true | ||
} | ||
] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Form</class> | ||
<widget class="QWidget" name="Form"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>640</width> | ||
<height>480</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Form</string> | ||
</property> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Dialog</class> | ||
<widget class="QDialog" name="Dialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>640</width> | ||
<height>480</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Dialog</string> | ||
</property> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>440</y> | ||
<width>621</width> | ||
<height>32</height> | ||
</rect> | ||
</property> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
</property> | ||
</widget> | ||
</widget> | ||
<resources/> | ||
<connections> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>accepted()</signal> | ||
<receiver>Dialog</receiver> | ||
<slot>accept()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>248</x> | ||
<y>254</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>157</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>rejected()</signal> | ||
<receiver>Dialog</receiver> | ||
<slot>reject()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>316</x> | ||
<y>260</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>286</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
</connections> | ||
</ui> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be read at form rendering time from the layer settings.