diff --git a/felt/core/workspaces_model.py b/felt/core/workspaces_model.py index 7a59164..bb65900 100644 --- a/felt/core/workspaces_model.py +++ b/felt/core/workspaces_model.py @@ -18,7 +18,8 @@ Qt, QAbstractItemModel, QObject, - QModelIndex + QModelIndex, + pyqtSignal ) from qgis.PyQt.QtNetwork import ( QNetworkReply @@ -37,6 +38,8 @@ class WorkspacesModel(QAbstractItemModel): UrlRole = Qt.UserRole + 2 IdRole = Qt.UserRole + 4 + no_workspaces_found = pyqtSignal() + def __init__(self, parent: Optional[QObject] = None): super().__init__(parent) @@ -81,6 +84,9 @@ def _reply_finished(self, reply: QNetworkReply): self.endInsertRows() + if not self.workspaces: + self.no_workspaces_found.emit() + # Qt model interface # pylint: disable=missing-docstring,unused-argument diff --git a/felt/gui/create_map_dialog.py b/felt/gui/create_map_dialog.py index ca41066..c463eda 100644 --- a/felt/gui/create_map_dialog.py +++ b/felt/gui/create_map_dialog.py @@ -233,6 +233,7 @@ def upload_raster_as_styled_toggled(): # pylint: enable=import-outside-toplevel self.maps_widget = RecentMapsWidget() self.workspace_combo = WorkspacesComboBox() + self.workspace_combo.no_workspaces_found.connect(self._no_workspace) self.workspace_combo.workspace_changed.connect(self._workspace_changed) self.workspace_combo.setFixedHeight( int(QFontMetrics(self.workspace_combo.font()).height() * 1.5) @@ -322,8 +323,21 @@ def _fatal_error(self, error: str): self.error_label.setText(error) self.button_box.button(QDialogButtonBox.Ok).deleteLater() - def _validate_initial(self): + def _no_workspace(self): + """ + Called when no workspaces are available + """ + self._fatal_error( + self.tr("You don’t have edit access for any workspaces. " + "Ask your workspace admin for edit access, " + "or create your own workspace." + ) + ) + def _validate_initial(self): + """ + Performs an initial one-time validated of the environment + """ error: Optional[str] = None export_layers = self.layers if self.layers else \ diff --git a/felt/gui/workspaces_combo.py b/felt/gui/workspaces_combo.py index 0309ff3..b2ebcd5 100644 --- a/felt/gui/workspaces_combo.py +++ b/felt/gui/workspaces_combo.py @@ -23,11 +23,13 @@ class WorkspacesComboBox(QComboBox): """ workspace_changed = pyqtSignal(str) + no_workspaces_found = pyqtSignal() def __init__(self, parent: Optional[QWidget] = None): super().__init__(parent) self._model = WorkspacesModel(self) + self._model.no_workspaces_found.connect(self.no_workspaces_found) self.setModel(self._model) self.currentIndexChanged.connect(self._index_changed)