Skip to content

Commit 98a8e8b

Browse files
committed
fixes to serialize/save plan form
1 parent 97947dc commit 98a8e8b

File tree

2 files changed

+132
-105
lines changed

2 files changed

+132
-105
lines changed
+21-32
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,39 @@
1+
from __future__ import annotations
2+
13
from importlib import resources
4+
from typing import TYPE_CHECKING
25

36
from qgis.PyQt import uic
4-
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox, QFileDialog, QLineEdit, QPushButton
7+
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox
8+
9+
if TYPE_CHECKING:
10+
from qgis.gui import QgsFileWidget
11+
512

613
ui_path = resources.files(__package__) / "serialize_plan.ui"
714
FormClass, _ = uic.loadUiType(ui_path)
815

916

1017
class SerializePlan(QDialog, FormClass): # type: ignore
11-
plan_outline_path_edit: QLineEdit
12-
plan_path_edit: QLineEdit
13-
plan_outline_select_button: QPushButton
14-
plan_select_button: QPushButton
18+
plan_outline_file: QgsFileWidget
19+
plan_file: QgsFileWidget
20+
button_box: QDialogButtonBox
1521

1622
def __init__(self):
1723
super().__init__()
1824
self.setupUi(self)
1925

20-
self.plan_outline_select_button.clicked.connect(self.select_plan_outline_file)
21-
self.plan_select_button.clicked.connect(self.select_plan_file)
22-
23-
# Disable Save button initially
24-
self.buttonBox.button(QDialogButtonBox.Save).setEnabled(False)
25-
self.buttonBox.accepted.connect(self.accept)
26-
self.buttonBox.rejected.connect(self.reject)
27-
28-
def select_plan_outline_file(self):
29-
file_path, _ = QFileDialog.getSaveFileName(
30-
self, "Valitse kaavan ulkorajan tallennuspolku", "", "JSON Files (*.json)"
31-
)
32-
if file_path:
33-
self.plan_outline_path_edit.setText(file_path)
34-
self.check_inputs()
35-
36-
def select_plan_file(self):
37-
file_path, _ = QFileDialog.getSaveFileName(self, "Valitse kaavan tallennuspolku", "", "JSON Files (*.json)")
38-
if file_path:
39-
self.plan_path_edit.setText(file_path)
40-
self.check_inputs()
26+
self.plan_outline_file.fileChanged.connect(self.check_inputs)
27+
self.plan_file.fileChanged.connect(self.check_inputs)
28+
self.setMaximumHeight(107) # Lock height
29+
self.check_inputs()
4130

4231
def check_inputs(self):
43-
# Enable Save button if both text fields have paths
44-
if self.plan_outline_path_edit.text() and self.plan_path_edit.text():
45-
self.buttonBox.button(QDialogButtonBox.Save).setEnabled(True)
32+
"""Enables ok/save button only if both file paths are defined."""
33+
if self.plan_outline_file.filePath() and self.plan_file.filePath():
34+
self.button_box.button(QDialogButtonBox.Ok).setEnabled(True)
4635
else:
47-
self.buttonBox.button(QDialogButtonBox.Save).setEnabled(False)
36+
self.button_box.button(QDialogButtonBox.Ok).setEnabled(False)
4837

49-
def get_paths(self):
50-
return self.plan_outline_path_edit.text(), self.plan_path_edit.text()
38+
def get_paths(self) -> tuple[str, str]:
39+
return self.plan_outline_file.filePath(), self.plan_file.filePath()

arho_feature_template/gui/serialize_plan.ui

+111-73
Original file line numberDiff line numberDiff line change
@@ -6,84 +6,122 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>558</width>
10-
<height>193</height>
9+
<width>519</width>
10+
<height>107</height>
1111
</rect>
1212
</property>
13+
<property name="sizePolicy">
14+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
15+
<horstretch>0</horstretch>
16+
<verstretch>0</verstretch>
17+
</sizepolicy>
18+
</property>
19+
<property name="maximumSize">
20+
<size>
21+
<width>16777215</width>
22+
<height>16777215</height>
23+
</size>
24+
</property>
1325
<property name="windowTitle">
1426
<string>Tallenna kaava JSON</string>
1527
</property>
16-
<widget class="QDialogButtonBox" name="buttonBox">
17-
<property name="geometry">
18-
<rect>
19-
<x>20</x>
20-
<y>150</y>
21-
<width>521</width>
22-
<height>32</height>
23-
</rect>
24-
</property>
25-
<property name="standardButtons">
26-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
27-
</property>
28-
<property name="centerButtons">
29-
<bool>true</bool>
30-
</property>
31-
</widget>
32-
<widget class="QWidget" name="layoutWidget">
33-
<property name="geometry">
34-
<rect>
35-
<x>20</x>
36-
<y>20</y>
37-
<width>521</width>
38-
<height>120</height>
39-
</rect>
40-
</property>
41-
<layout class="QGridLayout" name="gridLayout">
42-
<item row="0" column="0">
43-
<widget class="QLabel" name="plan_outline_label">
44-
<property name="text">
45-
<string>Kaavan ulkorajan tallennuspolku:</string>
46-
</property>
47-
</widget>
48-
</item>
49-
<item row="0" column="1">
50-
<widget class="QLineEdit" name="plan_outline_path_edit">
51-
<property name="readOnly">
52-
<bool>true</bool>
53-
</property>
54-
</widget>
55-
</item>
56-
<item row="0" column="2">
57-
<widget class="QPushButton" name="plan_outline_select_button">
58-
<property name="text">
59-
<string>Valitse...</string>
60-
</property>
61-
</widget>
62-
</item>
63-
<item row="1" column="0">
64-
<widget class="QLabel" name="plan_label">
65-
<property name="text">
66-
<string>Kaavan tallennuspolku:</string>
67-
</property>
68-
</widget>
69-
</item>
70-
<item row="1" column="1">
71-
<widget class="QLineEdit" name="plan_path_edit">
72-
<property name="readOnly">
73-
<bool>true</bool>
74-
</property>
75-
</widget>
76-
</item>
77-
<item row="1" column="2">
78-
<widget class="QPushButton" name="plan_select_button">
79-
<property name="text">
80-
<string>Valitse...</string>
81-
</property>
82-
</widget>
83-
</item>
84-
</layout>
85-
</widget>
28+
<layout class="QVBoxLayout" name="verticalLayout">
29+
<item>
30+
<layout class="QFormLayout" name="formLayout">
31+
<item row="0" column="0">
32+
<widget class="QLabel" name="plan_outline_label">
33+
<property name="text">
34+
<string>Kaavan ulkorajan tallennuspolku</string>
35+
</property>
36+
</widget>
37+
</item>
38+
<item row="0" column="1">
39+
<widget class="QgsFileWidget" name="plan_outline_file">
40+
<property name="dialogTitle">
41+
<string>Valitse kaavan ulkorajan tallennuspolku</string>
42+
</property>
43+
<property name="filter">
44+
<string>JSON Files (*.json)</string>
45+
</property>
46+
<property name="storageMode">
47+
<enum>QgsFileWidget::SaveFile</enum>
48+
</property>
49+
</widget>
50+
</item>
51+
<item row="1" column="0">
52+
<widget class="QLabel" name="plan_label">
53+
<property name="text">
54+
<string>Kaavan tallennuspolku</string>
55+
</property>
56+
</widget>
57+
</item>
58+
<item row="1" column="1">
59+
<widget class="QgsFileWidget" name="plan_file">
60+
<property name="dialogTitle">
61+
<string>Valitse kaavan tallennuspolku</string>
62+
</property>
63+
<property name="filter">
64+
<string>JSON Files (*.json)</string>
65+
</property>
66+
<property name="storageMode">
67+
<enum>QgsFileWidget::SaveFile</enum>
68+
</property>
69+
</widget>
70+
</item>
71+
</layout>
72+
</item>
73+
<item>
74+
<widget class="QDialogButtonBox" name="button_box">
75+
<property name="standardButtons">
76+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
77+
</property>
78+
<property name="centerButtons">
79+
<bool>false</bool>
80+
</property>
81+
</widget>
82+
</item>
83+
</layout>
8684
</widget>
85+
<customwidgets>
86+
<customwidget>
87+
<class>QgsFileWidget</class>
88+
<extends>QWidget</extends>
89+
<header>qgsfilewidget.h</header>
90+
</customwidget>
91+
</customwidgets>
8792
<resources/>
88-
<connections/>
93+
<connections>
94+
<connection>
95+
<sender>button_box</sender>
96+
<signal>accepted()</signal>
97+
<receiver>Dialog</receiver>
98+
<slot>accept()</slot>
99+
<hints>
100+
<hint type="sourcelabel">
101+
<x>247</x>
102+
<y>85</y>
103+
</hint>
104+
<hint type="destinationlabel">
105+
<x>247</x>
106+
<y>53</y>
107+
</hint>
108+
</hints>
109+
</connection>
110+
<connection>
111+
<sender>button_box</sender>
112+
<signal>rejected()</signal>
113+
<receiver>Dialog</receiver>
114+
<slot>reject()</slot>
115+
<hints>
116+
<hint type="sourcelabel">
117+
<x>247</x>
118+
<y>85</y>
119+
</hint>
120+
<hint type="destinationlabel">
121+
<x>247</x>
122+
<y>53</y>
123+
</hint>
124+
</hints>
125+
</connection>
126+
</connections>
89127
</ui>

0 commit comments

Comments
 (0)