-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
462 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Definitions for edition.""" | ||
|
||
from .base import BaseDefinitions, InputType | ||
from ..qgis_plugin_tools.tools.i18n import tr | ||
|
||
__copyright__ = 'Copyright 2020, 3Liz' | ||
__license__ = 'GPL version 3' | ||
__email__ = 'info@3liz.org' | ||
__revision__ = '$Format:%H$' | ||
|
||
|
||
class EditionDefinitions(BaseDefinitions): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self._layer_config['layerId'] = { | ||
'type': InputType.Layer, | ||
'header': tr('Layer'), | ||
'default': None, | ||
'tooltip': tr('The vector layer for the edition.') | ||
} | ||
self._layer_config['createFeature'] = { | ||
'type': InputType.CheckBox, | ||
'header': tr('Create'), | ||
'default': False, | ||
'tooltip': tr('If a new feature can be added.') | ||
} | ||
self._layer_config['modifyAttribute'] = { | ||
'type': InputType.CheckBox, | ||
'header': tr('Edit attributes'), | ||
'default': False, | ||
'tooltip': tr('If attributes can be edited.') | ||
} | ||
self._layer_config['modifyGeometry'] = { | ||
'type': InputType.CheckBox, | ||
'header': tr('Edit geometry'), | ||
'default': False, | ||
'tooltip': tr('If geometry can be edited.') | ||
} | ||
self._layer_config['deleteFeature'] = { | ||
'type': InputType.CheckBox, | ||
'header': tr('Remove'), | ||
'default': False, | ||
'tooltip': tr('If a feature can be removed.') | ||
} | ||
self._layer_config['acl'] = { | ||
'type': InputType.Text, | ||
'header': tr('Groups'), | ||
'default': '', | ||
'tooltip': tr( | ||
'Use a comma separated list of Lizmap groups ids to restrict access ' | ||
'to this layer edition.') | ||
} | ||
|
||
@staticmethod | ||
def primary_keys() -> tuple: | ||
return 'layerId', | ||
|
||
def key(self) -> str: | ||
return 'editionLayers' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
"""Dialog for edition layer edition.""" | ||
|
||
from qgis.PyQt.QtWidgets import QMessageBox | ||
from qgis.core import QgsMapLayerProxyModel, QgsProject, QgsWkbTypes | ||
|
||
from .base_edition_dialog import BaseEditionDialog | ||
from ..definitions.edition import EditionDefinitions | ||
from ..qgis_plugin_tools.tools.i18n import tr | ||
from ..qgis_plugin_tools.tools.resources import load_ui | ||
from ..tools import excluded_providers | ||
|
||
|
||
__copyright__ = 'Copyright 2020, 3Liz' | ||
__license__ = 'GPL version 3' | ||
__email__ = 'info@3liz.org' | ||
__revision__ = '$Format:%H$' | ||
|
||
|
||
CLASS = load_ui('ui_form_edition.ui') | ||
|
||
|
||
class EditionLayerDialog(BaseEditionDialog, CLASS): | ||
|
||
def __init__(self, parent=None, unicity=None): | ||
super().__init__(parent, unicity) | ||
self.setupUi(self) | ||
self.config = EditionDefinitions() | ||
self.config.add_layer_widget('layerId', self.layer) | ||
self.config.add_layer_widget('createFeature', self.create_feature) | ||
self.config.add_layer_widget('modifyAttribute', self.edit_attributes) | ||
self.config.add_layer_widget('modifyGeometry', self.edit_geometry) | ||
self.config.add_layer_widget('deleteFeature', self.delete_feature) | ||
self.config.add_layer_widget('acl', self.allowed_groups) | ||
|
||
self.config.add_layer_label('layerId', self.label_layer) | ||
self.config.add_layer_label('createFeature', self.label_create) | ||
self.config.add_layer_label('modifyAttribute', self.label_edit_attributes) | ||
self.config.add_layer_label('modifyGeometry', self.label_edit_geometry) | ||
self.config.add_layer_label('deleteFeature', self.label_delete) | ||
self.config.add_layer_label('acl', self.label_allowed_groups) | ||
|
||
self.layer.setFilters(QgsMapLayerProxyModel.VectorLayer) | ||
self.layer.setExcludedProviders(excluded_providers()) | ||
|
||
self.setup_ui() | ||
|
||
def validate(self) -> str: | ||
layer = self.layer.currentLayer() | ||
if not layer: | ||
return tr('A layer is compulsory.') | ||
|
||
upstream = super().validate() | ||
if upstream: | ||
return upstream | ||
|
||
wfs_layers_list = QgsProject.instance().readListEntry('WFSLayers', '')[0] | ||
for wfs_layer in wfs_layers_list: | ||
if layer.id() == wfs_layer: | ||
break | ||
else: | ||
msg = tr( | ||
'The layers you have chosen for this tool must be checked in the "WFS Capabilities"\n' | ||
' option of the QGIS Server tab in the "Project Properties" dialog.') | ||
return msg | ||
|
||
create_feature = self.create_feature.isChecked() | ||
modify_attribute = self.edit_attributes.isChecked() | ||
modify_geometry = self.edit_geometry.isChecked() | ||
delete_feature = self.delete_feature.isChecked() | ||
if not create_feature and not modify_attribute and not modify_geometry and not delete_feature: | ||
return tr('At least one action is compulsory.') | ||
|
||
# Check Z or M values which will be lost when editing | ||
geometry_type = layer.wkbType() | ||
# noinspection PyArgumentList | ||
has_m_values = QgsWkbTypes.hasM(geometry_type) | ||
# noinspection PyArgumentList | ||
has_z_values = QgsWkbTypes.hasZ(geometry_type) | ||
if has_z_values or has_m_values: | ||
QMessageBox.warning( | ||
self, | ||
tr('Editing Z/M Values'), | ||
tr('Be careful, editing this layer with Lizmap will set the Z and M to 0.'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.