Skip to content

Commit 69746f4

Browse files
committed
improvements to regulation group indicators when it is used for other plan features
1 parent ae876a8 commit 69746f4

File tree

5 files changed

+158
-97
lines changed

5 files changed

+158
-97
lines changed

arho_feature_template/gui/components/plan_regulation_group_widget.py

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from __future__ import annotations
22

33
from importlib import resources
4-
from typing import TYPE_CHECKING
4+
from typing import TYPE_CHECKING, cast
55

66
from qgis.core import QgsApplication
77
from qgis.PyQt import uic
88
from qgis.PyQt.QtCore import pyqtSignal
99
from qgis.PyQt.QtGui import QIcon, QPixmap
1010
from qgis.PyQt.QtWidgets import QHBoxLayout, QLabel, QSizePolicy, QWidget
1111

12-
from arho_feature_template.core.models import Proposition, Regulation, RegulationGroup
12+
from arho_feature_template.core.models import PlanFeature, Proposition, Regulation, RegulationGroup
1313
from arho_feature_template.gui.components.plan_proposition_widget import PropositionWidget
1414
from arho_feature_template.gui.components.plan_regulation_widget import RegulationWidget
1515
from arho_feature_template.project.layers.code_layers import PlanRegulationGroupTypeLayer
@@ -29,7 +29,7 @@ class RegulationGroupWidget(QWidget, FormClass): # type: ignore
2929
open_as_form_signal = pyqtSignal(QWidget)
3030
delete_signal = pyqtSignal(QWidget)
3131

32-
def __init__(self, regulation_group: RegulationGroup, layer_name: str):
32+
def __init__(self, regulation_group: RegulationGroup, plan_feature: PlanFeature):
3333
super().__init__()
3434
self.setupUi(self)
3535

@@ -49,8 +49,10 @@ def __init__(self, regulation_group: RegulationGroup, layer_name: str):
4949
self.link_label_icon: QLabel | None = None
5050
self.link_label_text: QLabel | None = None
5151

52+
self.plan_feature = plan_feature
53+
self.layer_name = cast(str, plan_feature.layer_name)
5254
self.from_model(regulation_group)
53-
self.regulation_group.type_code_id = PlanRegulationGroupTypeLayer.get_id_by_feature_layer_name(layer_name)
55+
self.regulation_group.type_code_id = PlanRegulationGroupTypeLayer.get_id_by_feature_layer_name(self.layer_name)
5456

5557
self.edit_btn.setIcon(QIcon(resources_path("icons", "settings.svg")))
5658
self.edit_btn.clicked.connect(lambda: self.open_as_form_signal.emit(self))
@@ -73,11 +75,18 @@ def from_model(self, regulation_group: RegulationGroup):
7375
for proposition in regulation_group.propositions:
7476
self.add_proposition_widget(proposition)
7577

78+
# Remove existing indicators if reinitializing
79+
self.unset_existing_regulation_group_style()
80+
7681
if regulation_group.id_:
77-
# Remove existing indicators if reinitializing
78-
self.unset_existing_regulation_group_style()
79-
# Set indicators that the regulation group exists in the plan already
80-
self.set_existing_regulation_group_style()
82+
other_linked_features_count = len(
83+
RegulationGroupAssociationLayer.get_associations_for_regulation_group_exclude_feature(
84+
cast(str, regulation_group.id_), cast(str, self.plan_feature.id_), self.layer_name
85+
)
86+
)
87+
if other_linked_features_count > 0:
88+
# Set indicators that regulation group exists in the plan already and is assigned for other features
89+
self.set_existing_regulation_group_style(other_linked_features_count)
8190

8291
def add_regulation_widget(self, regulation: Regulation) -> RegulationWidget:
8392
widget = RegulationWidget(regulation=regulation, parent=self.frame)
@@ -103,7 +112,7 @@ def delete_proposition_widget(self, proposition_widget: RegulationWidget):
103112
self.proposition_widgets.remove(proposition_widget)
104113
proposition_widget.deleteLater()
105114

106-
def set_existing_regulation_group_style(self):
115+
def set_existing_regulation_group_style(self, other_linked_features_count: int):
107116
tooltip = (
108117
"Kaavamääräysryhmä on tallennettu kaavaan. Ryhmän tietojen muokkaaminen vaikuttaa muihin "
109118
"kaavakohteisiin, joille ryhmä on lisätty."
@@ -118,10 +127,10 @@ def set_existing_regulation_group_style(self):
118127

119128
self.link_label_text = QLabel()
120129
self.link_label_text.setObjectName("text_label") # Set unique name to avoid style cascading
121-
feat_count = len(
122-
list(RegulationGroupAssociationLayer.get_associations_for_regulation_group(self.regulation_group.id_))
130+
self.link_label_text.setText(
131+
f"Kaavamääräysryhmä on käytössä myös {other_linked_features_count} toisella kaavakohteella"
123132
)
124-
self.link_label_text.setText(f"Kaavamääräysryhmä on käytössä {feat_count} kaavakohteella")
133+
self.link_label_text.setWordWrap(True)
125134
self.link_label_text.setStyleSheet("#text_label { color: #4b8db2; }")
126135
self.link_label_text.setToolTip(tooltip)
127136
layout.addWidget(self.link_label_text)

arho_feature_template/gui/dialogs/plan_feature_form.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from importlib import resources
4-
from typing import TYPE_CHECKING, cast
4+
from typing import TYPE_CHECKING
55

66
from qgis.PyQt import uic
77
from qgis.PyQt.QtCore import Qt
@@ -78,7 +78,6 @@ def __init__(
7878

7979
# Initialize attributes from template
8080
self.plan_feature = plan_feature
81-
self.layer_name = plan_feature.layer_name # Should always have a layer name
8281

8382
if plan_feature.name:
8483
self.feature_name.setText(plan_feature.name)
@@ -105,7 +104,7 @@ def add_selected_plan_regulation_group(self, item: QTreeWidgetItem, column: int)
105104
self.add_plan_regulation_group(regulation_group)
106105

107106
def add_plan_regulation_group(self, definition: RegulationGroup):
108-
regulation_group_widget = RegulationGroupWidget(definition, cast(str, self.layer_name))
107+
regulation_group_widget = RegulationGroupWidget(definition, self.plan_feature)
109108
regulation_group_widget.delete_signal.connect(self.remove_plan_regulation_group)
110109
regulation_group_widget.open_as_form_signal.connect(self.open_plan_regulation_group_form)
111110
self._remove_spacer()
@@ -141,7 +140,7 @@ def into_model(self) -> PlanFeature:
141140
type_of_underground_id=self.feature_type_of_underground.value(),
142141
description=self.feature_description.toPlainText(),
143142
geom=self.plan_feature.geom,
144-
layer_name=self.layer_name,
143+
layer_name=self.plan_feature.layer_name,
145144
regulation_groups=[reg_group_widget.into_model() for reg_group_widget in self.regulation_group_widgets],
146145
id_=self.plan_feature.id_,
147146
)

arho_feature_template/gui/dialogs/plan_regulation_group_form.py

+45-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
from qgis.core import QgsApplication
77
from qgis.PyQt import uic
88
from qgis.PyQt.QtCore import Qt
9-
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox, QTextBrowser, QTreeWidgetItem, QVBoxLayout
9+
from qgis.PyQt.QtGui import QPixmap
10+
from qgis.PyQt.QtWidgets import (
11+
QDialog,
12+
QDialogButtonBox,
13+
QHBoxLayout,
14+
QLabel,
15+
QSizePolicy,
16+
QTextBrowser,
17+
QTreeWidgetItem,
18+
QVBoxLayout,
19+
)
1020

1121
from arho_feature_template.core.models import (
1222
Proposition,
@@ -19,6 +29,8 @@
1929
from arho_feature_template.gui.components.plan_regulation_widget import RegulationWidget
2030
from arho_feature_template.gui.components.tree_with_search_widget import TreeWithSearchWidget
2131
from arho_feature_template.project.layers.code_layers import PlanRegulationGroupTypeLayer
32+
from arho_feature_template.project.layers.plan_layers import RegulationGroupAssociationLayer
33+
from arho_feature_template.qgis_plugin_tools.tools.resources import resources_path
2234

2335
if TYPE_CHECKING:
2436
from qgis.gui import QgsSpinBox
@@ -49,6 +61,8 @@ def __init__(self, regulation_group: RegulationGroup):
4961
self.regulations_layout: QBoxLayout
5062
self.regulation_info: QTextBrowser
5163

64+
self.regulation_group_info_tab: QWidget
65+
5266
self.propositions_layout: QVBoxLayout
5367
self.propositions_scroll_contents: QWidget
5468
self.add_proposition_btn: QPushButton
@@ -90,6 +104,36 @@ def __init__(self, regulation_group: RegulationGroup):
90104
for proposition in self.regulation_group.propositions:
91105
self.add_proposition(proposition)
92106

107+
if self.regulation_group.id_:
108+
feat_count = len(
109+
list(
110+
RegulationGroupAssociationLayer.get_associations_for_regulation_group(
111+
str(self.regulation_group.id_)
112+
)
113+
)
114+
)
115+
tooltip = (
116+
"Kaavamääräysryhmä on tallennettu kaavaan. Ryhmän tietojen muokkaaminen vaikuttaa "
117+
"kaavakohteisiin, joille ryhmä on lisätty."
118+
)
119+
layout = QHBoxLayout()
120+
121+
self.link_label_icon = QLabel()
122+
self.link_label_icon.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
123+
self.link_label_icon.setPixmap(QPixmap(resources_path("icons", "linked_img_small.png")))
124+
self.link_label_icon.setToolTip(tooltip)
125+
layout.addWidget(self.link_label_icon)
126+
127+
self.link_label_text = QLabel()
128+
self.link_label_text.setObjectName("text_label") # Set unique name to avoid style cascading
129+
self.link_label_text.setText(f"Kaavamääräysryhmä on käytössä yhteensä {feat_count} kaavakohteella")
130+
self.link_label_text.setWordWrap(True)
131+
self.link_label_text.setStyleSheet("#text_label { color: #4b8db2; }")
132+
self.link_label_text.setToolTip(tooltip)
133+
layout.addWidget(self.link_label_text)
134+
135+
self.regulation_group_info_tab.layout().insertLayout(1, layout)
136+
93137
def _initalize_regulation_from_config(self, config: RegulationConfig, parent: QTreeWidgetItem | None = None):
94138
item = self.regulations_selection_widget.add_item_to_tree(config.name, config, parent)
95139

arho_feature_template/gui/dialogs/plan_regulation_group_form.ui

+78-80
Original file line numberDiff line numberDiff line change
@@ -25,83 +25,81 @@
2525
</attribute>
2626
<layout class="QVBoxLayout" name="verticalLayout_3">
2727
<item>
28-
<widget class="QScrollArea" name="scrollArea">
29-
<property name="widgetResizable">
30-
<bool>true</bool>
28+
<layout class="QFormLayout" name="formLayout">
29+
<item row="0" column="0">
30+
<widget class="QLabel" name="label_2">
31+
<property name="text">
32+
<string>Otsikko</string>
33+
</property>
34+
</widget>
35+
</item>
36+
<item row="0" column="1">
37+
<widget class="QLineEdit" name="name"/>
38+
</item>
39+
<item row="1" column="0">
40+
<widget class="QLabel" name="label_3">
41+
<property name="text">
42+
<string>Lyhyt nimi</string>
43+
</property>
44+
</widget>
45+
</item>
46+
<item row="1" column="1">
47+
<widget class="QLineEdit" name="short_name"/>
48+
</item>
49+
<item row="2" column="0">
50+
<widget class="QLabel" name="label">
51+
<property name="text">
52+
<string>Ryhmänumero</string>
53+
</property>
54+
</widget>
55+
</item>
56+
<item row="2" column="1">
57+
<widget class="QgsSpinBox" name="group_number">
58+
<property name="specialValueText">
59+
<string>NULL</string>
60+
</property>
61+
<property name="maximum">
62+
<number>999</number>
63+
</property>
64+
<property name="clearValue">
65+
<bool>false</bool>
66+
</property>
67+
</widget>
68+
</item>
69+
<item row="3" column="0">
70+
<widget class="QLabel" name="label_5">
71+
<property name="text">
72+
<string>Värikoodi</string>
73+
</property>
74+
</widget>
75+
</item>
76+
<item row="3" column="1">
77+
<widget class="QLineEdit" name="color_code"/>
78+
</item>
79+
<item row="4" column="0">
80+
<widget class="QLabel" name="label_7">
81+
<property name="text">
82+
<string>Tyyppi</string>
83+
</property>
84+
</widget>
85+
</item>
86+
<item row="4" column="1">
87+
<widget class="CodeComboBox" name="type_of_regulation_group"/>
88+
</item>
89+
</layout>
90+
</item>
91+
<item>
92+
<spacer name="verticalSpacer_3">
93+
<property name="orientation">
94+
<enum>Qt::Vertical</enum>
3195
</property>
32-
<widget class="QWidget" name="scrollAreaWidgetContents">
33-
<property name="geometry">
34-
<rect>
35-
<x>0</x>
36-
<y>0</y>
37-
<width>851</width>
38-
<height>577</height>
39-
</rect>
40-
</property>
41-
<layout class="QFormLayout" name="formLayout">
42-
<item row="0" column="0">
43-
<widget class="QLabel" name="label_2">
44-
<property name="text">
45-
<string>Otsikko</string>
46-
</property>
47-
</widget>
48-
</item>
49-
<item row="0" column="1">
50-
<widget class="QLineEdit" name="name"/>
51-
</item>
52-
<item row="1" column="0">
53-
<widget class="QLabel" name="label_3">
54-
<property name="text">
55-
<string>Lyhyt nimi</string>
56-
</property>
57-
</widget>
58-
</item>
59-
<item row="1" column="1">
60-
<widget class="QLineEdit" name="short_name"/>
61-
</item>
62-
<item row="2" column="0">
63-
<widget class="QLabel" name="label">
64-
<property name="text">
65-
<string>Ryhmänumero</string>
66-
</property>
67-
</widget>
68-
</item>
69-
<item row="3" column="0">
70-
<widget class="QLabel" name="label_5">
71-
<property name="text">
72-
<string>Värikoodi</string>
73-
</property>
74-
</widget>
75-
</item>
76-
<item row="3" column="1">
77-
<widget class="QLineEdit" name="color_code"/>
78-
</item>
79-
<item row="4" column="0">
80-
<widget class="QLabel" name="label_7">
81-
<property name="text">
82-
<string>Tyyppi</string>
83-
</property>
84-
</widget>
85-
</item>
86-
<item row="4" column="1">
87-
<widget class="CodeComboBox" name="type_of_regulation_group"/>
88-
</item>
89-
<item row="2" column="1">
90-
<widget class="QgsSpinBox" name="group_number">
91-
<property name="specialValueText">
92-
<string>NULL</string>
93-
</property>
94-
<property name="maximum">
95-
<number>999</number>
96-
</property>
97-
<property name="clearValue">
98-
<bool>false</bool>
99-
</property>
100-
</widget>
101-
</item>
102-
</layout>
103-
</widget>
104-
</widget>
96+
<property name="sizeHint" stdset="0">
97+
<size>
98+
<width>20</width>
99+
<height>40</height>
100+
</size>
101+
</property>
102+
</spacer>
105103
</item>
106104
</layout>
107105
</widget>
@@ -156,8 +154,8 @@ p, li { white-space: pre-wrap; }
156154
<rect>
157155
<x>0</x>
158156
<y>0</y>
159-
<width>587</width>
160-
<height>577</height>
157+
<width>38</width>
158+
<height>18</height>
161159
</rect>
162160
</property>
163161
<layout class="QVBoxLayout" name="regulations_layout">
@@ -195,8 +193,8 @@ p, li { white-space: pre-wrap; }
195193
<rect>
196194
<x>0</x>
197195
<y>0</y>
198-
<width>851</width>
199-
<height>577</height>
196+
<width>120</width>
197+
<height>49</height>
200198
</rect>
201199
</property>
202200
<layout class="QVBoxLayout" name="propositions_layout">

arho_feature_template/project/layers/plan_layers.py

+11
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,17 @@ def get_associations_for_feature(cls, feature_id: str, layer_name: str) -> Gener
286286
def get_associations_for_regulation_group(cls, group_id: str) -> Generator[QgsFeature]:
287287
return cls.get_features_by_attribute_value("plan_regulation_group_id", group_id)
288288

289+
@classmethod
290+
def get_associations_for_regulation_group_exclude_feature(
291+
cls, group_id: str, excluded_feature_id: str, excluded_feature_layer_name: str
292+
) -> list[QgsFeature]:
293+
attribute = RegulationGroupAssociationLayer.layer_name_to_attribute_map.get(excluded_feature_layer_name)
294+
return [
295+
association
296+
for association in cls.get_associations_for_regulation_group(group_id)
297+
if association[attribute] != excluded_feature_id
298+
]
299+
289300
@classmethod
290301
def get_group_ids_for_feature(cls, feature_id: str, layer_name: str) -> Generator[str]:
291302
attribute = cls.layer_name_to_attribute_map.get(layer_name)

0 commit comments

Comments
 (0)