-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Class drafting, added JSON for testing
- Loading branch information
Showing
7 changed files
with
252 additions
and
5 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from qgis.PyQt.QtWidgets import QDialog | ||
|
||
from arho_feature_template.core.feature_template import FeatureTemplate | ||
|
||
|
||
class AddFeatureForm(QDialog): | ||
"""Dialog for filling and saving attribute data that opens when a new feature has been digitized.""" | ||
|
||
def __init__(self, feature_template: FeatureTemplate): | ||
self.feature_template = 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
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 # noqa F401 | ||
|
||
|
||
# class AddFeaturePanel(QWidget, load_ui("add_feature_panel.ui")): # NOTE: UI file does not exist yet | ||
class AddFeaturePanel(QWidget): | ||
"""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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
name: str | ||
description: str | ||
feature_layer: QgsVectorLayer | ||
feature_attributes: Sequence[FeatureAttribute] | ||
display_icon: QIcon | None = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
arho_feature_template/resources/asemakaava-template-library-test.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} | ||
] | ||
} |