From 1abc136cb916b4e365759334b9d94181b99eec52 Mon Sep 17 00:00:00 2001 From: Damiano Lombardi Date: Wed, 8 Nov 2023 11:23:30 +0100 Subject: [PATCH] Remove redundant interlis_mode and use only db_action_type --- QgisModelBaker/gui/panel/db_config_panel.py | 2 -- QgisModelBaker/gui/panel/gpkg_config_panel.py | 19 +++++++++++---- .../gui/panel/mssql_config_panel.py | 21 +++++++++-------- QgisModelBaker/gui/panel/pg_config_panel.py | 23 ++++++++----------- 4 files changed, 36 insertions(+), 29 deletions(-) diff --git a/QgisModelBaker/gui/panel/db_config_panel.py b/QgisModelBaker/gui/panel/db_config_panel.py index 9536e1686..2a55a01f8 100644 --- a/QgisModelBaker/gui/panel/db_config_panel.py +++ b/QgisModelBaker/gui/panel/db_config_panel.py @@ -34,7 +34,6 @@ class AbstractQWidgetMeta(ABCMeta, type(QWidget)): class DbConfigPanel(QWidget, metaclass=AbstractQWidgetMeta): """Panel where users fill out connection parameters to database. This is a abstract class. - :ivar bool interlis_mode: Value that determines whether the config panel is displayed with messages or fields interlis. :cvar notify_fields_modified: Signal that is called when any field is modified. :type notify_field_modified: pyqtSignal(str) """ @@ -49,7 +48,6 @@ def __init__(self, parent: QWidget, db_action_type: DbActionType): """ QWidget.__init__(self, parent) self._db_action_type = db_action_type - self.interlis_mode = False @abstractmethod def _show_panel(self): diff --git a/QgisModelBaker/gui/panel/gpkg_config_panel.py b/QgisModelBaker/gui/panel/gpkg_config_panel.py index dcfb17ab1..ee26a799e 100644 --- a/QgisModelBaker/gui/panel/gpkg_config_panel.py +++ b/QgisModelBaker/gui/panel/gpkg_config_panel.py @@ -15,6 +15,8 @@ * * ***************************************************************************/ """ +import logging + from qgis.PyQt.QtCore import pyqtSignal from qgis.PyQt.QtGui import QValidator @@ -35,7 +37,6 @@ class GpkgConfigPanel(DbConfigPanel, WIDGET_UI): """Panel where users fill out connection parameters to Geopackage database. - :ivar bool interlis_mode: Value that determines whether the config panel is displayed with messages or fields interlis. :cvar notify_fields_modified: Signal that is called when any field is modified. :type notify_field_modified: pyqtSignal(str) """ @@ -65,7 +66,10 @@ def __init__(self, parent, db_action_type): self.gpkg_file_line_edit.textChanged.connect(self.notify_fields_modified) def _show_panel(self): - if self.interlis_mode or self._db_action_type == DbActionType.IMPORT_DATA: + if ( + self._db_action_type == DbActionType.GENERATE + or self._db_action_type == DbActionType.IMPORT_DATA + ): validator = self.gpkgSaveFileValidator file_selector = make_save_file_selector( self.gpkg_file_line_edit, @@ -74,17 +78,22 @@ def _show_panel(self): extensions=["." + ext for ext in self.ValidExtensions], dont_confirm_overwrite=True, ) - else: + elif self._db_action_type == DbActionType.EXPORT: validator = self.gpkgOpenFileValidator file_selector = make_file_selector( self.gpkg_file_line_edit, title=self.tr("Open GeoPackage database file"), file_filter=self.tr("GeoPackage Database (*.gpkg *.GPKG)"), ) + else: + logging.error(f"Unknown action type: {self._db_action_type}") + try: self.gpkg_file_browse_button.clicked.disconnect() - except: - pass + except Exception as exception: + logging.error( + f"Can't disconnect gpkg_file_browse_button signal: {exception}" + ) self.gpkg_file_line_edit.setValidator(validator) self.gpkg_file_line_edit.textChanged.emit(self.gpkg_file_line_edit.text()) diff --git a/QgisModelBaker/gui/panel/mssql_config_panel.py b/QgisModelBaker/gui/panel/mssql_config_panel.py index b65f31db3..8b3f75a61 100644 --- a/QgisModelBaker/gui/panel/mssql_config_panel.py +++ b/QgisModelBaker/gui/panel/mssql_config_panel.py @@ -15,6 +15,8 @@ * * ***************************************************************************/ """ +import logging + from qgis.PyQt.QtCore import pyqtSignal from QgisModelBaker.libs.modelbaker.utils.globals import DbActionType @@ -73,19 +75,20 @@ def __init__(self, parent, db_action_type): self.mssql_password_line_edit.textChanged.connect(self.notify_fields_modified) def _show_panel(self): - if self.interlis_mode: + if self._db_action_type == DbActionType.GENERATE: self.mssql_schema_line_edit.setPlaceholderText( self.tr("[Leave empty to create a default schema]") ) + elif self._db_action_type == DbActionType.IMPORT_DATA: + self.mssql_schema_line_edit.setPlaceholderText( + self.tr("[Leave empty to import data into a default schema]") + ) + elif self._db_action_type == DbActionType.EXPORT: + self.mssql_schema_line_edit.setPlaceholderText( + self.tr("[Enter a valid schema]") + ) else: - if self._db_action_type == DbActionType.IMPORT_DATA: - self.mssql_schema_line_edit.setPlaceholderText( - self.tr("[Leave empty to import data into a default schema]") - ) - else: - self.mssql_schema_line_edit.setPlaceholderText( - self.tr("[Enter a valid schema]") - ) + logging.error(f"Unknown action type: {self._db_action_type}") def get_fields(self, configuration): configuration.dbhost = self.mssql_host_line_edit.text().strip() diff --git a/QgisModelBaker/gui/panel/pg_config_panel.py b/QgisModelBaker/gui/panel/pg_config_panel.py index afddfd412..b229257f1 100644 --- a/QgisModelBaker/gui/panel/pg_config_panel.py +++ b/QgisModelBaker/gui/panel/pg_config_panel.py @@ -16,6 +16,7 @@ ***************************************************************************/ """ +import logging from enum import IntEnum from qgis.PyQt.QtCore import Qt, pyqtSignal @@ -36,7 +37,6 @@ class PgConfigPanel(DbConfigPanel, WIDGET_UI): """Panel where users fill out connection parameters to Postgres/Postgis database. - :ivar bool interlis_mode: Value that determines whether the config panel is displayed with messages or fields interlis. :cvar notify_fields_modified: Signal that is called when any field is modified. :type notify_field_modified: pyqtSignal(str) """ @@ -75,16 +75,6 @@ def __init__(self, parent, db_action_type): ) ) - if ( - self._db_action_type == DbActionType.GENERATE - or self._db_action_type == DbActionType.IMPORT_DATA - ): - self.pg_schema_line_edit.setPlaceholderText(self.tr("Schema Name")) - elif self._db_action_type == DbActionType.EXPORT: - self.pg_schema_line_edit.setPlaceholderText( - self.tr("[Enter a valid schema]") - ) - # define validators self.validators = Validators() nonEmptyValidator = NonEmptyStringValidator() @@ -169,13 +159,20 @@ def __init__(self, parent, db_action_type): Qt.ToolTipRole, ) + self._show_panel() + def _show_panel(self): - if self.interlis_mode or self._db_action_type == DbActionType.IMPORT_DATA: + if ( + self._db_action_type == DbActionType.GENERATE + or self._db_action_type == DbActionType.IMPORT_DATA + ): self.pg_schema_line_edit.setPlaceholderText(self.tr("Schema Name")) - else: + elif self._db_action_type == DbActionType.EXPORT: self.pg_schema_line_edit.setPlaceholderText( self.tr("[Enter a valid schema]") ) + else: + logging.error(f"Unknown action type: {self._db_action_type}") def get_fields(self, configuration):