Skip to content
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

Muokkauksia tallenna kaava -lomakkeeseen #86

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 21 additions & 32 deletions arho_feature_template/gui/serialize_plan.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,39 @@
from __future__ import annotations

from importlib import resources
from typing import TYPE_CHECKING

from qgis.PyQt import uic
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox, QFileDialog, QLineEdit, QPushButton
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox

if TYPE_CHECKING:
from qgis.gui import QgsFileWidget


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


class SerializePlan(QDialog, FormClass): # type: ignore
plan_outline_path_edit: QLineEdit
plan_path_edit: QLineEdit
plan_outline_select_button: QPushButton
plan_select_button: QPushButton
plan_outline_file: QgsFileWidget
plan_file: QgsFileWidget
button_box: QDialogButtonBox

def __init__(self):
super().__init__()
self.setupUi(self)

self.plan_outline_select_button.clicked.connect(self.select_plan_outline_file)
self.plan_select_button.clicked.connect(self.select_plan_file)

# Disable Save button initially
self.buttonBox.button(QDialogButtonBox.Save).setEnabled(False)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)

def select_plan_outline_file(self):
file_path, _ = QFileDialog.getSaveFileName(
self, "Valitse kaavan ulkorajan tallennuspolku", "", "JSON Files (*.json)"
)
if file_path:
self.plan_outline_path_edit.setText(file_path)
self.check_inputs()

def select_plan_file(self):
file_path, _ = QFileDialog.getSaveFileName(self, "Valitse kaavan tallennuspolku", "", "JSON Files (*.json)")
if file_path:
self.plan_path_edit.setText(file_path)
self.check_inputs()
self.plan_outline_file.fileChanged.connect(self.check_inputs)
self.plan_file.fileChanged.connect(self.check_inputs)
self.setMaximumHeight(107) # Lock height
self.check_inputs()

def check_inputs(self):
# Enable Save button if both text fields have paths
if self.plan_outline_path_edit.text() and self.plan_path_edit.text():
self.buttonBox.button(QDialogButtonBox.Save).setEnabled(True)
"""Enables ok/save button only if both file paths are defined."""
if self.plan_outline_file.filePath() and self.plan_file.filePath():
self.button_box.button(QDialogButtonBox.Ok).setEnabled(True)
else:
self.buttonBox.button(QDialogButtonBox.Save).setEnabled(False)
self.button_box.button(QDialogButtonBox.Ok).setEnabled(False)

def get_paths(self):
return self.plan_outline_path_edit.text(), self.plan_path_edit.text()
def get_paths(self) -> tuple[str, str]:
return self.plan_outline_file.filePath(), self.plan_file.filePath()
184 changes: 111 additions & 73 deletions arho_feature_template/gui/serialize_plan.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,84 +6,122 @@
<rect>
<x>0</x>
<y>0</y>
<width>558</width>
<height>193</height>
<width>519</width>
<height>107</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>Tallenna kaava JSON</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>20</x>
<y>150</y>
<width>521</width>
<height>32</height>
</rect>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>521</width>
<height>120</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="plan_outline_label">
<property name="text">
<string>Kaavan ulkorajan tallennuspolku:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="plan_outline_path_edit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="plan_outline_select_button">
<property name="text">
<string>Valitse...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="plan_label">
<property name="text">
<string>Kaavan tallennuspolku:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="plan_path_edit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="plan_select_button">
<property name="text">
<string>Valitse...</string>
</property>
</widget>
</item>
</layout>
</widget>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="plan_outline_label">
<property name="text">
<string>Kaavan ulkorajan tallennuspolku</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsFileWidget" name="plan_outline_file">
<property name="dialogTitle">
<string>Valitse kaavan ulkorajan tallennuspolku</string>
</property>
<property name="filter">
<string>JSON Files (*.json)</string>
</property>
<property name="storageMode">
<enum>QgsFileWidget::SaveFile</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="plan_label">
<property name="text">
<string>Kaavan tallennuspolku</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsFileWidget" name="plan_file">
<property name="dialogTitle">
<string>Valitse kaavan tallennuspolku</string>
</property>
<property name="filter">
<string>JSON Files (*.json)</string>
</property>
<property name="storageMode">
<enum>QgsFileWidget::SaveFile</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="button_box">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsFileWidget</class>
<extends>QWidget</extends>
<header>qgsfilewidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
<connections>
<connection>
<sender>button_box</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>247</x>
<y>85</y>
</hint>
<hint type="destinationlabel">
<x>247</x>
<y>53</y>
</hint>
</hints>
</connection>
<connection>
<sender>button_box</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>247</x>
<y>85</y>
</hint>
<hint type="destinationlabel">
<x>247</x>
<y>53</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Loading