diff --git a/pg_service_parser/conf/service_settings.py b/pg_service_parser/conf/service_settings.py index 8511c56..ccf89d8 100644 --- a/pg_service_parser/conf/service_settings.py +++ b/pg_service_parser/conf/service_settings.py @@ -1,12 +1,22 @@ # Settings available for manual addition # See https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS SERVICE_SETTINGS = { - "host": "localhost", - "port": "5432", - "dbname": "test", - "user": "", - "password": "", - "passfile": "", + "host": {"default": "localhost", "description": "Name of host to connect to."}, + "port": {"default": "5432", "description": "Port number to connect to at the server host."}, + "dbname": {"default": "test", "description": "The database name."}, + "user": {"default": "", "description": "PostgreSQL user name to connect as."}, + "password": { + "default": "", + "description": "Password to be used if the server demands password authentication.", + }, + "sslmode": { + "default": "", + "description": "This option determines whether or with what priority a secure SSL TCP/IP connection will be negotiated with the server.", + }, + "passfile": { + "default": "", + "description": "Specifies the name of the file used to store passwords.", + }, } # Settings to initialize new files diff --git a/pg_service_parser/core/item_models.py b/pg_service_parser/core/item_models.py index f4191d2..5de0b65 100644 --- a/pg_service_parser/core/item_models.py +++ b/pg_service_parser/core/item_models.py @@ -1,6 +1,8 @@ from qgis.PyQt.QtCore import QAbstractTableModel, QModelIndex, Qt, pyqtSignal from qgis.PyQt.QtGui import QColorConstants, QFont +from pg_service_parser.conf.service_settings import SERVICE_SETTINGS + class ServiceConfigModel(QAbstractTableModel): KEY_COL = 0 @@ -13,6 +15,7 @@ def __init__(self, service_name: str, service_config: dict): self.__service_name = service_name self.__model_data = service_config self.__original_data = service_config.copy() + self.__settings_data = SERVICE_SETTINGS # Read-only dict with further info about settings self.__dirty = False def rowCount(self, parent=QModelIndex()): @@ -24,7 +27,7 @@ def columnCount(self, parent=QModelIndex()): def index_to_setting_key(self, index): return list(self.__model_data.keys())[index.row()] - def add_settings(self, settings: dict): + def add_settings(self, settings: dict[str, str]): self.beginInsertRows(QModelIndex(), self.rowCount(), self.rowCount() + len(settings) - 1) self.__model_data.update(settings) self.__set_dirty_status(True) @@ -55,6 +58,13 @@ def data(self, index, role=Qt.ItemDataRole.DisplayRole): return key elif index.column() == self.VALUE_COL: return self.__model_data[key] + elif role == Qt.ItemDataRole.ToolTipRole: + if index.column() == self.KEY_COL: + return ( + self.__settings_data[key].get("description", None) + if key in self.__settings_data + else None + ) elif role == Qt.ItemDataRole.EditRole and index.column() == self.VALUE_COL: return self.__model_data[key] elif role == Qt.ItemDataRole.FontRole: diff --git a/pg_service_parser/gui/dlg_pg_service.py b/pg_service_parser/gui/dlg_pg_service.py index c4f55d1..d0eae50 100644 --- a/pg_service_parser/gui/dlg_pg_service.py +++ b/pg_service_parser/gui/dlg_pg_service.py @@ -211,7 +211,9 @@ def __add_settings_clicked(self): dlg.exec() if dlg.settings_to_add: - settings = {k: v for k, v in SERVICE_SETTINGS.items() if k in dlg.settings_to_add} + settings = { + k: v["default"] for k, v in SERVICE_SETTINGS.items() if k in dlg.settings_to_add + } self.__edit_model.add_settings(settings) @pyqtSlot() diff --git a/pg_service_parser/gui/dlg_service_settings.py b/pg_service_parser/gui/dlg_service_settings.py index e74d591..ad6eeab 100644 --- a/pg_service_parser/gui/dlg_service_settings.py +++ b/pg_service_parser/gui/dlg_service_settings.py @@ -1,5 +1,5 @@ -from qgis.PyQt.QtCore import pyqtSlot -from qgis.PyQt.QtWidgets import QDialog +from qgis.PyQt.QtCore import Qt, pyqtSlot +from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox, QListWidgetItem from pg_service_parser.conf.service_settings import SERVICE_SETTINGS from pg_service_parser.utils import get_ui_class @@ -9,16 +9,33 @@ class ServiceSettingsDialog(QDialog, DIALOG_UI): - def __init__(self, parent, settings_to_hide: list[str]): + def __init__(self, parent, used_settings: list[str]): QDialog.__init__(self, parent) self.setupUi(self) + self.lstSettings.itemSelectionChanged.connect(self.__selection_changed) self.buttonBox.accepted.connect(self.__accepted) - settings = set(SERVICE_SETTINGS.keys()) - set(settings_to_hide) - self.lstSettings.addItems(settings) + self.__selection_changed() # Initialize button status + + # Load data + for setting, data in SERVICE_SETTINGS.items(): + item = QListWidgetItem(setting) + if setting in used_settings: + item.setFlags(item.flags() & ~Qt.ItemIsSelectable & ~Qt.ItemIsEnabled) + if data.get("description", None): + item.setToolTip(data["description"]) + + self.lstSettings.addItem(item) + self.settings_to_add = [] + @pyqtSlot() + def __selection_changed(self): + self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( + bool(self.lstSettings.selectedItems()) + ) + @pyqtSlot() def __accepted(self): self.settings_to_add = [item.text() for item in self.lstSettings.selectedItems()]