From 1c713662e43887ed6ff319005eb22ab2371b886f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Fri, 4 Oct 2024 17:42:20 -0500 Subject: [PATCH] [connections] Code cleanup, pass parent and widget mode to edit connection dialog --- pg_service_parser/core/service_connections.py | 13 +++++++------ pg_service_parser/gui/dlg_pg_service.py | 2 +- pg_service_parser/gui/item_delegates.py | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pg_service_parser/core/service_connections.py b/pg_service_parser/core/service_connections.py index 03069f7..41d798f 100644 --- a/pg_service_parser/core/service_connections.py +++ b/pg_service_parser/core/service_connections.py @@ -5,6 +5,7 @@ ) from qgis.gui import QgsGui from qgis.PyQt.QtCore import QSettings +from qgis.PyQt.QtWidgets import QWidget def get_connections(service: str) -> dict[str, QgsAbstractDatabaseProviderConnection]: @@ -24,7 +25,6 @@ def create_connection(service: str, connection_name: str) -> None: provider = QgsProviderRegistry.instance().providerMetadata("postgres") conn = provider.createConnection(uri, config) provider.saveConnection(conn, connection_name) - # conn.store(name) def remove_connection(connection_name: str) -> None: @@ -32,16 +32,17 @@ def remove_connection(connection_name: str) -> None: provider.deleteConnection(connection_name) -def edit_connection(connection_name: str) -> None: +def edit_connection(connection_name: str, parent: QWidget) -> None: provider = QgsProviderRegistry.instance().providerMetadata("postgres") if connection_name in provider.dbConnections(): pg = QgsGui.sourceSelectProviderRegistry().providerByName("postgres") - w = pg.createDataSourceWidget() + widget = pg.createDataSourceWidget( + parent, widgetMode=QgsProviderRegistry.WidgetMode.Standalone + ) settings = QSettings() - settings.value("PostgreSQL/connections/selected") settings.setValue("PostgreSQL/connections/selected", connection_name) - w.refresh() # To reflect the newly selected connection - w.btnEdit_clicked() + widget.refresh() # To reflect the newly selected connection + widget.btnEdit_clicked() diff --git a/pg_service_parser/gui/dlg_pg_service.py b/pg_service_parser/gui/dlg_pg_service.py index 97b4a5b..b7b9e1a 100644 --- a/pg_service_parser/gui/dlg_pg_service.py +++ b/pg_service_parser/gui/dlg_pg_service.py @@ -345,7 +345,7 @@ def __edit_double_clicked_connection(self, index): def __edit_connection(self, index): connection_name = self.__connection_model.index_to_connection_key(index) - edit_connection(connection_name) + edit_connection(connection_name, self) self.__initialize_service_connections(index) @pyqtSlot() diff --git a/pg_service_parser/gui/item_delegates.py b/pg_service_parser/gui/item_delegates.py index 04767fd..66f1758 100644 --- a/pg_service_parser/gui/item_delegates.py +++ b/pg_service_parser/gui/item_delegates.py @@ -4,7 +4,7 @@ from qgis.PyQt.QtCore import Qt from qgis.PyQt.QtWidgets import QComboBox, QStyledItemDelegate -from pg_service_parser.core.item_models import ServiceConfigModel +from pg_service_parser.core.setting_model import ServiceConfigModel class ServiceConfigDelegate(QStyledItemDelegate):