diff --git a/pg_service_parser/conf/service_settings.py b/pg_service_parser/conf/service_settings.py index 5ca1b13..ccf89d8 100644 --- a/pg_service_parser/conf/service_settings.py +++ b/pg_service_parser/conf/service_settings.py @@ -1,13 +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": "", - "sslmode": "", + "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 077c782..ad6eeab 100644 --- a/pg_service_parser/gui/dlg_service_settings.py +++ b/pg_service_parser/gui/dlg_service_settings.py @@ -19,10 +19,12 @@ def __init__(self, parent, used_settings: list[str]): self.__selection_changed() # Initialize button status # Load data - for setting in SERVICE_SETTINGS.keys(): + 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)