|
| 1 | +"""Dialog for DXF export edition.""" |
| 2 | +from typing import Dict, Optional |
| 3 | + |
| 4 | +from qgis.core import QgsMapLayerProxyModel |
| 5 | +from qgis.PyQt.QtWidgets import QWidget |
| 6 | + |
| 7 | +from lizmap.definitions.definitions import LwcVersions |
| 8 | +from lizmap.definitions.dxf_export import DxfExportDefinitions |
| 9 | +from lizmap.forms.base_edition_dialog import BaseEditionDialog |
| 10 | +from lizmap.toolbelt.i18n import tr |
| 11 | +from lizmap.toolbelt.resources import load_ui |
| 12 | + |
| 13 | +CLASS = load_ui('ui_form_dxf_export.ui') |
| 14 | + |
| 15 | + |
| 16 | +class DxfExportEditionDialog(BaseEditionDialog, CLASS): |
| 17 | + |
| 18 | + def __init__( |
| 19 | + self, |
| 20 | + parent: Optional[QWidget] = None, |
| 21 | + unicity: Optional[Dict[str, str]] = None, |
| 22 | + lwc_version: Optional[LwcVersions] = None, |
| 23 | + ): |
| 24 | + super().__init__(parent, unicity, lwc_version) |
| 25 | + self.setupUi(self) |
| 26 | + self.config = DxfExportDefinitions() |
| 27 | + |
| 28 | + # Layer configuration |
| 29 | + self.config.add_layer_widget('layerId', self.layer) |
| 30 | + self.config.add_layer_widget('enabled', self.enabled) |
| 31 | + |
| 32 | + self.config.add_layer_label('layerId', self.label_layer) |
| 33 | + self.config.add_layer_label('enabled', self.label_enabled) |
| 34 | + |
| 35 | + # Set layer filter to only show vector layers |
| 36 | + self.layer.setFilters(QgsMapLayerProxyModel.Filter.VectorLayer) |
| 37 | + self.layer.layerChanged.connect(self.check_layer_wfs) |
| 38 | + |
| 39 | + self.setup_ui() |
| 40 | + self.check_layer_wfs() |
| 41 | + |
| 42 | + def check_layer_wfs(self): |
| 43 | + """When the layer has changed in the combobox, check if the layer is published as WFS.""" |
| 44 | + layer = self.layer.currentLayer() |
| 45 | + if not layer: |
| 46 | + self.show_error(tr('A layer is mandatory.')) |
| 47 | + return |
| 48 | + |
| 49 | + not_in_wfs = self.is_layer_in_wfs(layer) |
| 50 | + self.show_error(not_in_wfs) |
| 51 | + |
| 52 | + def validate(self) -> Optional[str]: |
| 53 | + upstream = super().validate() |
| 54 | + if upstream: |
| 55 | + return upstream |
| 56 | + |
| 57 | + layer = self.layer.currentLayer() |
| 58 | + not_in_wfs = self.is_layer_in_wfs(layer) |
| 59 | + if not_in_wfs: |
| 60 | + return not_in_wfs |
| 61 | + |
| 62 | + return None |
0 commit comments