Skip to content

Commit

Permalink
store validator config file in project variable - basics. Resolves #820
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Sep 25, 2023
1 parent 2a3bbcc commit efcd9ed
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 102 deletions.
44 changes: 37 additions & 7 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,7 @@ 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.config_file_line_edit.text()

self.progress_bar.setValue(20)
validation_result_state = False
Expand Down Expand Up @@ -632,12 +647,27 @@ 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(filename)

def _save_config_file(self):
filename = self.config_file_line_edit.text()

QgsExpressionContextUtils.setProjectVariable(
QgsProject.instance(),
f"validator_config_{self.current_schema_identificator}",
filename,
)

def _load_config_file(self):
filename = QgsExpressionContextUtils.projectScope(
QgsProject.instance()
).variable(f"validator_config_{self.current_schema_identificator}")
self.config_file_line_edit.setText(filename)

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

0 comments on commit efcd9ed

Please sign in to comment.