Skip to content

Commit

Permalink
Remove redundant interlis_mode and use only db_action_type
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed Nov 8, 2023
1 parent c019aea commit 12a8468
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
2 changes: 0 additions & 2 deletions QgisModelBaker/gui/panel/db_config_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""
Expand All @@ -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):
Expand Down
19 changes: 14 additions & 5 deletions QgisModelBaker/gui/panel/gpkg_config_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* *
***************************************************************************/
"""
import logging

from qgis.PyQt.QtCore import pyqtSignal
from qgis.PyQt.QtGui import QValidator

Expand All @@ -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)
"""
Expand Down Expand Up @@ -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,
Expand All @@ -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())
Expand Down
21 changes: 12 additions & 9 deletions QgisModelBaker/gui/panel/mssql_config_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* *
***************************************************************************/
"""
import logging

from qgis.PyQt.QtCore import pyqtSignal

from QgisModelBaker.libs.modelbaker.utils.globals import DbActionType
Expand Down Expand Up @@ -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()
Expand Down
29 changes: 14 additions & 15 deletions QgisModelBaker/gui/panel/pg_config_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/
"""

import logging
from enum import IntEnum

from qgis.PyQt.QtCore import Qt, pyqtSignal
Expand All @@ -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)
"""
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -169,13 +159,22 @@ 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:
self.pg_schema_line_edit.setPlaceholderText(self.tr("Schema Name"))
else:
self.pg_schema_line_edit.setPlaceholderText(
if (
self._db_action_type == DbActionType.GENERATE
or self._db_action_type == DbActionType.IMPORT_DATA
):
self.pg_schema_combo_box.setEditable(True)
self.pg_schema_combo_box.setPlaceholderText(self.tr("Schema Name"))
elif self._db_action_type == DbActionType.EXPORT:
self.pg_schema_combo_box.setEditable(False)
self.pg_schema_combo_box.setPlaceholderText(
self.tr("[Enter a valid schema]")
)
else:
logging.error(f"Unknown action type: {self._db_action_type}")

def get_fields(self, configuration):

Expand Down

0 comments on commit 12a8468

Please sign in to comment.