Skip to content

Commit

Permalink
Add error page to dialog, move unsaved edits error to share dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 11, 2023
1 parent 083aedd commit f404147
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
32 changes: 31 additions & 1 deletion felt/gui/create_map_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
)
from .workspaces_combo import WorkspacesComboBox
from ..core import (
LayerExporter,
LayerSupport,
MapUploaderTask,
Map
)
Expand Down Expand Up @@ -309,9 +311,37 @@ def upload_raster_as_styled_toggled():
)

self.started = False
self._validate()
self._validate_initial()
self.maps_widget.filter_line_edit().setFocus()

def _fatal_error(self, error: str):
"""
Called when a fatal error which prevents sharing occurs
"""
self.stacked_widget.setCurrentIndex(2)
self.error_label.setText(error)
self.button_box.button(QDialogButtonBox.Ok).deleteLater()

def _validate_initial(self):

error: Optional[str] = None

export_layers = self.layers if self.layers else \
QgsProject.instance().mapLayers().values()
for layer in export_layers:
support, reason = LayerExporter.can_export_layer(layer)
if support == LayerSupport.UnsavedEdits:
error = self.tr(
'Layer "{}" has unsaved changes. Please save '
'the layer before sharing to Felt.').format(
layer.name())
break

if error:
self._fatal_error(error)
else:
self._validate()

def _workspace_changed(self, workspace_id: str):
"""
Called when the selected workspace is changed
Expand Down
14 changes: 0 additions & 14 deletions felt/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,6 @@ def _create_map_authorized(self,
self._create_map_dialog.raise_()
return

export_layers = layers if layers else \
QgsProject.instance().mapLayers().values()
for layer in export_layers:
support, reason = LayerExporter.can_export_layer(layer)
if support == LayerSupport.UnsavedEdits:
QMessageBox.warning(
self.iface.mainWindow(),
self.tr('Share to Felt'),
self.tr(
'Layer "{}" has unsaved changes. Please save '
'the layer before sharing to Felt.').format(
layer.name()))
return

def _cleanup_dialog(_dialog):
"""
Remove references to outdated dialogs
Expand Down
20 changes: 20 additions & 0 deletions felt/ui/create_map.ui
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,26 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page_3">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="error_label">
<property name="text">
<string>TextLabel</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextBrowserInteraction</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
Expand Down

0 comments on commit f404147

Please sign in to comment.