diff --git a/geocatbridge/servers/models/geoserver.py b/geocatbridge/servers/models/geoserver.py index 36ba821..33f3a09 100644 --- a/geocatbridge/servers/models/geoserver.py +++ b/geocatbridge/servers/models/geoserver.py @@ -972,13 +972,6 @@ def workspaceExists(self): url = f"{self.apiUrl}/workspaces.json" return self._exists(url, "workspace", self.workspace) - def willDeleteLayersOnPublication(self, to_publish: List[str]): - """ Checks if any of the layer names of the given QGIS layer IDs already exist on the server workspace. """ - if self.workspaceExists(): - # If the set of selected QGIS layers is NOT disjoint with the layers on the server, layers will be deleted! - return not frozenset(listLayerNames(to_publish)).isdisjoint(self.layerNames().keys()) - return False - def datastoreExists(self, name): url = f"{self.apiUrl}/workspaces/{self.workspace}/datastores.json" return self._exists(url, "dataStore", name) diff --git a/geocatbridge/servers/views/geoserver.py b/geocatbridge/servers/views/geoserver.py index 67cdf96..cc8c6ed 100644 --- a/geocatbridge/servers/views/geoserver.py +++ b/geocatbridge/servers/views/geoserver.py @@ -1,9 +1,10 @@ +import time from functools import partial from itertools import chain from requests import HTTPError from typing import Optional -from qgis.PyQt.QtWidgets import QHBoxLayout +from qgis.PyQt.QtWidgets import QHBoxLayout, QProgressDialog from geocatbridge.servers.bases import ServerWidgetBase from geocatbridge.servers.models.gs_storage import GeoserverStorage @@ -177,7 +178,7 @@ def updateDbServersCombo(self, managed_by_geoserver: bool, init_value=None): this value can be set immediately as the only available and selected item. Doing so prevents a full refresh of GeoServer datastores. """ - def addGeoserverPgDatastores(current_db_: str, worker_result): + def _addGeoserverPgDatastores(current_db_: str, worker_result): if worker_result: # Worker result might be a list of lists, so we should flatten it datastores = list(chain.from_iterable(worker_result)) @@ -221,10 +222,11 @@ def addGeoserverPgDatastores(current_db_: str, worker_result): pg_dialog = self.parent.getProgressDialog("Retrieving PostGIS datastores...", len(workspaces), self.dsThread.requestInterruption) self.dsWorker.progress.connect(pg_dialog.setValue) - self.dsWorker.results.connect(partial(addGeoserverPgDatastores, current_db)) + self.dsWorker.finished.connect(pg_dialog.close) + self.dsWorker.results.connect(partial(_addGeoserverPgDatastores, current_db)) self.dsWorker.start() except Exception as e: - msg = f'Failed to retrieve datastores for {getattr(server, "serverName", self.txtGeoserverName.text())}' # noqa + msg = f'Failed to retrieve datastores for {getattr(server, "serverName", self.txtGeoserverName.text())}' if isinstance(e, HTTPError) and e.response.status_code == 401: msg = f'{msg}: please check credentials' else: diff --git a/geocatbridge/ui/publishwidget.py b/geocatbridge/ui/publishwidget.py index 6276ba2..6c6a1ac 100644 --- a/geocatbridge/ui/publishwidget.py +++ b/geocatbridge/ui/publishwidget.py @@ -629,6 +629,7 @@ def _testServer(srv: manager.bases.ServerBase, combo: QComboBox) -> bool: for err in errors: self.showErrorBar("Error", err) return False + combo.setStyleSheet('') # reset default style return True def _testServers() -> tuple[manager.bases.DataCatalogServerBase, manager.bases.MetaCatalogServerBase]: diff --git a/geocatbridge/utils/feedback.py b/geocatbridge/utils/feedback.py index 64c0e4b..c4d1c7c 100644 --- a/geocatbridge/utils/feedback.py +++ b/geocatbridge/utils/feedback.py @@ -185,8 +185,14 @@ def getProgressDialog(self, label, max_length, callback=None) -> QProgressDialog :param callback: Callback function to be executed when the user presses "Cancel". :return: A QProgressDialog instance. """ - pg_dialog = QProgressDialog(label, self.translate("Cancel"), 0, max_length, - self if isinstance(self, QWidget) else None) + if not isinstance(self, QWidget): + raise ValueError("A QWidget parent instance is required to show a progress dialog.") + pg_dialog = QProgressDialog(self, QtCore.Qt.WindowType.Popup) + pg_dialog.setLabelText(label) + pg_dialog.setAutoReset(False) + pg_dialog.setAutoClose(False) + pg_dialog.setCancelButtonText(self.tr("Cancel")) + pg_dialog.setRange(0, max_length) pg_dialog.canceled.connect(callback, type=QtCore.Qt.DirectConnection) # noqa pg_dialog.setWindowModality(QtCore.Qt.WindowModal) pg_dialog.setWindowTitle(getAppName()) diff --git a/geocatbridge/utils/gui.py b/geocatbridge/utils/gui.py index 689c5d0..aac088a 100644 --- a/geocatbridge/utils/gui.py +++ b/geocatbridge/utils/gui.py @@ -81,16 +81,13 @@ class BackgroundWorker(QtCore.QObject): finished = QtCore.pyqtSignal() results = QtCore.pyqtSignal(list) - def __init__(self): - super().__init__() - def _run(self, func: Callable, items: Iterable): results_ = [] try: if isgenerator(items): # Flatten generators into a tuple items = tuple(items) - for step, item in enumerate(items): + for step, item in enumerate(items, 1): self.progress.emit(step) try: results_.append(func(item)) @@ -100,6 +97,8 @@ def _run(self, func: Callable, items: Iterable): results_.append(e) if self.thread().isInterruptionRequested(): break + # Tiny delay so user can see the progress bar at 100% + self.thread().msleep(100) finally: self.results.emit(results_) self.finished.emit()