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

store validator config file in project variable #828

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
68 changes: 62 additions & 6 deletions QgisModelBaker/gui/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from PyQt5.QtGui import QColor, QGuiApplication
from qgis.core import (
QgsApplication,
QgsExpressionContextUtils,
QgsGeometry,
QgsMapLayer,
QgsPointXY,
Expand Down Expand Up @@ -165,9 +166,21 @@ def __init__(self, base_config, iface):
self.auto_pan_button.clicked.connect(self._auto_pan_button_clicked)
self.auto_zoom_button.clicked.connect(self._auto_zoom_button_clicked)

self.validator_config_file_tool_button.clicked.connect(
self._select_validator_config_file
save_config_file_action = QAction(
QgsApplication.getThemeIcon("/mActionFileSave.svg"),
self.tr("Save config file to project..."),
self,
)
save_config_file_action.triggered.connect(self._save_config_file)
self.config_file_tool_button.addAction(save_config_file_action)
load_config_file_action = QAction(
QgsApplication.getThemeIcon("/mActionFileOpen.svg"),
self.tr("Load config file from project..."),
self,
)
load_config_file_action.triggered.connect(self._load_config_file)
self.config_file_tool_button.addAction(load_config_file_action)
self.config_file_tool_button.clicked.connect(self._select_config_file)

def _reset_current_values(self):
self.current_configuration = ValidateConfiguration()
Expand All @@ -179,6 +192,7 @@ def _reset_current_values(self):
self.current_filter_mode = SchemaDataFilterMode.NO_FILTER
self.current_export_models_model = SchemaModelsModel()
self.current_export_models_active = False
self.config_file_line_edit.clear()

def _reset_gui(self):
self._reset_current_values()
Expand Down Expand Up @@ -284,6 +298,9 @@ def set_current_layer(self, layer):

self.filter_data_panel.setup_dialog(self._basket_handling())
self.export_models_panel.setup_dialog(True)

self._load_config_file()

self.setDisabled(False)

def _visibility_changed(self, visible):
Expand Down Expand Up @@ -363,9 +380,10 @@ def _run(self, edited_command=None):
validator.configuration.skip_geometry_errors = (
self.skip_geometry_errors_check_box.isChecked()
)
validator.configuration.valid_config = (
self.validator_config_file_line_edit.text()
validator.configuration.valid_config = self._absolute_path(
self.config_file_line_edit.text()
)
print(validator.configuration.valid_config)
signedav marked this conversation as resolved.
Show resolved Hide resolved

self.progress_bar.setValue(20)
validation_result_state = False
Expand Down Expand Up @@ -632,12 +650,50 @@ def _auto_zoom_button_clicked(self):
if self.auto_zoom_button.isChecked:
self.auto_pan_button.setChecked(False)

def _select_validator_config_file(self):
def _select_config_file(self):
filename, _ = QFileDialog.getOpenFileName(
self, self.tr("Select the validator config file")
)
if filename:
self.validator_config_file_line_edit.setText(filename)
self.config_file_line_edit.setText(self._relative_path(filename))

def _save_config_file(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would name it _save_config_file_path to make it clear that the path to the file is stored, and not the entire file itself.

Maybe in the gui as well.

filename = self.config_file_line_edit.text()

QgsExpressionContextUtils.setProjectVariable(
QgsProject.instance(),
"validator_config",
self._relative_path(filename),
)

def _load_config_file(self):
filename = QgsExpressionContextUtils.projectScope(
QgsProject.instance()
).variable("validator_config")
if filename:
self.config_file_line_edit.setText(self._relative_path(filename))

def _relative_path(self, path):
if (
os.path.isfile(path)
and QgsProject.instance().homePath()
and os.path.isabs(path)
):
# if it's a saved project and the path is not (yet) relative
return os.path.relpath(path, QgsProject.instance().homePath())
else:
return path

def _absolute_path(self, path):
if (
os.path.isfile(path)
and QgsProject.instance().homePath()
and not os.path.isabs(path)
):
# if it's a saved project and the path is not not absolute
return os.path.join(path, QgsProject.instance().homePath(), path)
else:
return path

def _validator_stdout(self, txt):
lines = txt.strip().split("\n")
Expand Down
189 changes: 94 additions & 95 deletions QgisModelBaker/ui/validator.ui
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,100 @@
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QGridLayout" name="gridLayout">
<item row="9" column="0" colspan="2">
<item row="0" column="0">
<widget class="QLabel" name="info_label">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QVBoxLayout" name="filter_layout">
<property name="spacing">
<number>0</number>
</property>
</layout>
</item>
<item row="2" column="0">
<layout class="QVBoxLayout" name="export_models_layout">
<property name="spacing">
<number>0</number>
</property>
</layout>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="skip_geometry_errors_check_box">
<property name="toolTip">
<string>Ignores geometry errors (--skipGeometryErrors) and AREA topology validation (--disableAreaValidation)</string>
</property>
<property name="text">
<string>Skip Geometry Errors</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLineEdit" name="config_file_line_edit">
<property name="toolTip">
<string>ili2db option --validConfig</string>
</property>
<property name="placeholderText">
<string>Validator config file (--validConfig)</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QToolButton" name="config_file_tool_button">
<property name="text">
<string>...</string>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QWidget" name="validation_layout" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="run_button">
<property name="text">
<string>✔</string>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progress_bar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTableView" name="result_table_view"/>
</item>
</layout>
</widget>
</item>
<item row="6" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="error_count_label">
Expand Down Expand Up @@ -94,100 +187,6 @@
</item>
</layout>
</item>
<item row="5" column="0" colspan="2">
<layout class="QVBoxLayout" name="export_models_layout">
<property name="spacing">
<number>0</number>
</property>
</layout>
</item>
<item row="1" column="0" rowspan="4" colspan="2">
<layout class="QVBoxLayout" name="filter_layout">
<property name="spacing">
<number>0</number>
</property>
</layout>
</item>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="skip_geometry_errors_check_box">
<property name="toolTip">
<string>Ignores geometry errors (--skipGeometryErrors) and AREA topology validation (--disableAreaValidation)</string>
</property>
<property name="text">
<string>Skip Geometry Errors</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QWidget" name="validation_layout" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="run_button">
<property name="text">
<string>✔</string>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progress_bar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTableView" name="result_table_view"/>
</item>
</layout>
</widget>
</item>
<item row="7" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="validator_config_file_line_edit">
<property name="toolTip">
<string>ili2db option --validConfig</string>
</property>
<property name="placeholderText">
<string>Validator config file (--validConfig)</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="validator_config_file_tool_button">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="info_label">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down
Loading