Skip to content

Commit

Permalink
[ux] Add tooltips with official PostgreSQL description to setting key…
Browse files Browse the repository at this point in the history
…s on Edit tab and on Settings dialog.
  • Loading branch information
gacarrillor committed Jul 8, 2024
1 parent 268a5a7 commit de41bb9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
23 changes: 16 additions & 7 deletions pg_service_parser/conf/service_settings.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 11 additions & 1 deletion pg_service_parser/core/item_models.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()):
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion pg_service_parser/gui/dlg_pg_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion pg_service_parser/gui/dlg_service_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit de41bb9

Please sign in to comment.