diff --git a/definitions/base.py b/definitions/base.py
index ecbf43ac..b32e13d4 100644
--- a/definitions/base.py
+++ b/definitions/base.py
@@ -18,6 +18,7 @@ class InputType(Enum):
Layer = 'Layer'
List = 'List'
SpinBox = 'SpinBox'
+ Text = 'Text'
class BaseDefinitions:
diff --git a/definitions/edition.py b/definitions/edition.py
new file mode 100644
index 00000000..bf0eb743
--- /dev/null
+++ b/definitions/edition.py
@@ -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'
diff --git a/forms/base_edition_dialog.py b/forms/base_edition_dialog.py
index 325b5204..86dc11e6 100644
--- a/forms/base_edition_dialog.py
+++ b/forms/base_edition_dialog.py
@@ -97,6 +97,8 @@ def load_form(self, data: OrderedDict) -> None:
definition['widget'].setCurrentIndex(index)
elif definition['type'] == InputType.SpinBox:
definition['widget'].setValue(value)
+ elif definition['type'] == InputType.Text:
+ definition['widget'].setText(value)
else:
raise Exception('InputType "{}" not implemented'.format(definition['type']))
@@ -127,6 +129,8 @@ def save_form(self) -> OrderedDict:
value = definition['widget'].currentData()
elif definition['type'] == InputType.SpinBox:
value = definition['widget'].value()
+ elif definition['type'] == InputType.Text:
+ value = definition['widget'].text()
else:
raise Exception('InputType "{}" not implemented'.format(definition['type']))
diff --git a/forms/edition_edition.py b/forms/edition_edition.py
new file mode 100644
index 00000000..cec7aad0
--- /dev/null
+++ b/forms/edition_edition.py
@@ -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.'),
+ )
diff --git a/forms/table_manager.py b/forms/table_manager.py
index 9bb2b173..d91bafa2 100644
--- a/forms/table_manager.py
+++ b/forms/table_manager.py
@@ -166,6 +166,10 @@ def _edit_row(self, row, data):
cell.setText(str(value))
cell.setData(Qt.UserRole, value)
+ elif input_type == InputType.Text:
+ cell.setText(value)
+ cell.setData(Qt.UserRole, value)
+
else:
raise Exception('InputType "{}" not implemented'.format(input_type))
@@ -268,12 +272,30 @@ def to_json(self):
layer_data[key] = cell
elif input_type == InputType.List:
layer_data[key] = cell
+ elif input_type == InputType.Text:
+ layer_data[key] = cell
else:
raise Exception('InputType "{}" not implemented'.format(input_type))
if layer_data[key] == '':
layer_data.pop(key)
+ if self.definitions.key() == 'editionLayers':
+ capabilities_keys = ['createFeature', 'modifyAttribute', 'modifyGeometry', 'deleteFeature']
+ layer_data['capabilities'] = {key: layer_data[key] for key in capabilities_keys}
+ for key in capabilities_keys:
+ layer_data.pop(key)
+
+ geometry_type = {
+ 0: 'point',
+ 1: 'line',
+ 2: 'polygon',
+ 3: 'unknown',
+ 4: 'none'
+ }
+ vector_layer = QgsProject.instance().mapLayer(layer_data['layerId'])
+ layer_data['geometryType'] = geometry_type[vector_layer.geometryType()]
+
if export_legacy_single_row:
if self.definitions.key() == 'atlas':
layer_data['atlasEnabled'] = 'True'
@@ -282,7 +304,7 @@ def to_json(self):
data['layers'].append(layer_data)
- if self.definitions.key() in ['locateByLayer', 'loginFilteredLayers', 'tooltipLayers', 'attributeLayers']:
+ if self.definitions.key() in ['locateByLayer', 'loginFilteredLayers', 'tooltipLayers', 'attributeLayers', 'editionLayers']:
result = {}
for i, layer in enumerate(data['layers']):
layer_id = layer.get('layerId')
@@ -334,11 +356,23 @@ def layer_from_order(layers, row):
return new_data
+ @staticmethod
+ def _from_json_legacy_capabilities(data):
+ for layer in data.get('layers'):
+ capabilities = layer.get('capabilities')
+ layer.update(capabilities)
+ layer.pop('capabilities')
+ layer.pop('geometryType')
+ return data
+
def from_json(self, data):
"""Load JSON into the table."""
- if self.definitions.key() in ['locateByLayer', 'loginFilteredLayers', 'tooltipLayers', 'attributeLayers']:
+ if self.definitions.key() in ['locateByLayer', 'loginFilteredLayers', 'tooltipLayers', 'attributeLayers', 'editionLayers']:
data = self._from_json_legacy_order(data)
+ if self.definitions.key() == 'editionLayers':
+ data = self._from_json_legacy_capabilities(data)
+
layers = data.get('layers')
if not layers:
@@ -371,6 +405,8 @@ def from_json(self, data):
layer_data[key] = value
elif definition['type'] == InputType.SpinBox:
layer_data[key] = value
+ elif definition['type'] == InputType.Text:
+ layer_data[key] = value
else:
raise Exception('InputType "{}" not implemented'.format(definition['type']))
else:
diff --git a/lizmap.py b/lizmap.py
index 0935eb8a..1898d9e8 100644
--- a/lizmap.py
+++ b/lizmap.py
@@ -78,7 +78,6 @@
QgsMapLayerModel,
QgsLayerTreeGroup,
QgsLayerTreeLayer,
- QgsWkbTypes,
QgsAttributeEditorField,
QgsAttributeEditorContainer,
QgsApplication,
@@ -86,11 +85,13 @@
from .definitions.atlas import AtlasDefinitions
from .definitions.attribute_table import AttributeTableDefinitions
+from .definitions.edition import EditionDefinitions
from .definitions.filter_by_login import FilterByLoginDefinitions
from .definitions.locate_by_layer import LocateByLayerDefinitions
from .definitions.tooltip import ToolTipDefinitions
from .forms.atlas_edition import AtlasEditionDialog
from .forms.attribute_table_edition import AttributeTableEditionDialog
+from .forms.edition_edition import EditionLayerDialog
from .forms.filter_by_login import FilterByLoginEditionDialog
from .forms.locate_layer_edition import LocateLayerEditionDialog
from .forms.table_manager import TableManager
@@ -105,7 +106,6 @@
from .qgis_plugin_tools.tools.ghost_layers import remove_all_ghost_layers
from .qgis_plugin_tools.tools.version import is_dev_version, version
-from .tools import excluded_providers
LOGGER = logging.getLogger(plugin_name())
@@ -443,12 +443,13 @@ def __init__(self, iface):
'manager': None,
},
'editionLayers': {
- 'tableWidget': self.dlg.twEditionLayerList,
- 'removeButton': self.dlg.btEditionLayerDel,
- 'addButton': self.dlg.btEditionLayerAdd,
- 'cols': ['createFeature', 'modifyAttribute', 'modifyGeometry', 'deleteFeature', 'acl', 'layerId',
- 'order'],
- 'jsonConfig': {}
+ 'tableWidget': self.dlg.edition_table,
+ 'removeButton': self.dlg.remove_edition_layer,
+ 'addButton': self.dlg.add_edition_layer,
+ 'editButton': self.dlg.edit_edition_layer,
+ 'upButton': self.dlg.up_edition_layer,
+ 'downButton': self.dlg.down_edition_layer,
+ 'manager': None,
},
'loginFilteredLayers': {
'tableWidget': self.dlg.table_login_filter,
@@ -569,6 +570,9 @@ def initGui(self):
elif key == 'attributeLayers':
definition = AttributeTableDefinitions()
dialog = AttributeTableEditionDialog
+ elif key == 'editionLayers':
+ definition = EditionDefinitions()
+ dialog = EditionLayerDialog
elif key == 'locateByLayer':
definition = LocateByLayerDefinitions()
dialog = LocateLayerEditionDialog
@@ -615,14 +619,6 @@ def initGui(self):
# Delete layers from table when deleted from registry
self.project.layersRemoved.connect(self.remove_layer_from_table_by_layer_ids)
- # Edition layers
- self.dlg.twEditionLayerList.setColumnHidden(6, True)
- self.dlg.twEditionLayerList.setColumnHidden(7, True)
- self.dlg.twEditionLayerList.horizontalHeader().setStretchLastSection(True)
- self.dlg.liEditionLayer.setFilters(QgsMapLayerProxyModel.VectorLayer)
- self.dlg.liEditionLayer.setExcludedProviders(excluded_providers())
- self.dlg.btEditionLayerAdd.clicked.connect(self.add_layer_to_edition)
-
# Time manager layers
self.dlg.twTimemanager.setColumnHidden(5, True)
self.dlg.twTimemanager.setColumnHidden(6, True)
@@ -1090,72 +1086,6 @@ def display_error(self, message):
message,
QMessageBox.Ok)
- def add_layer_to_edition(self):
- """Add a layer in the list of edition layers."""
- table = self.dlg.twEditionLayerList
- row = table.rowCount()
-
- if row >= self.dlg.liEditionLayer.count():
- self.display_error('Not possible to add again this layer.')
- return
-
- layer = self.dlg.liEditionLayer.currentLayer()
- if not layer:
- self.display_error('Layer is compulsory.')
- return
-
- if not self.check_wfs_is_checked(layer):
- return
-
- layer_name = layer.name()
- layer_id = layer.id()
- create_feature = self.dlg.cbEditionLayerCreate.isChecked()
- modify_attribute = self.dlg.cbEditionLayerModifyAttribute.isChecked()
- modify_geometry = self.dlg.cbEditionLayerModifyGeometry.isChecked()
- delete_feature = self.dlg.cbEditionLayerDeleteFeature.isChecked()
- acl = self.dlg.inEditionLayerAcl.text().strip(' \t')
- # noinspection PyArgumentList
- icon = QgsMapLayerModel.iconForLayer(layer)
-
- # check at least one checkbox is active
- if not create_feature and not modify_attribute and not modify_geometry and not delete_feature:
- self.display_error('At least one action is compulsory.')
- return
-
- # check if layer already added
- for existing_row in range(row):
- item_layer_id = str(table.item(existing_row, 6).text())
- if layer_id == item_layer_id:
- self.display_error('Not possible to add again this layer.')
- return
-
- # 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.dlg,
- tr('Editing Z/M Values'),
- tr('Be careful, editing this layer with Lizmap will set the Z and M to 0.'),
- )
-
- content = [
- layer_name, str(create_feature), str(modify_attribute), str(modify_geometry), str(delete_feature), acl,
- layer_id, str(row)]
-
- table.setRowCount(row + 1)
-
- for i, val in enumerate(content):
- item = QTableWidgetItem(val)
- if i == 0:
- item.setIcon(icon)
- table.setItem(row, i, item)
-
- LOGGER.info('Layer "{}" has been added to the edition tool'.format(layer_id))
-
def add_layer_to_time_manager(self):
"""Add a layer in the list of 'time manager' tool."""
table = self.dlg.twTimemanager
@@ -2164,34 +2094,6 @@ def writeProjectConfigFile(self):
wfsLayersList = self.project.readListEntry('WFSLayers', '')[0]
- # layer(s) for the edition tool
- lblTableWidget = self.dlg.twEditionLayerList
- twRowCount = lblTableWidget.rowCount()
- if twRowCount > 0:
- liz2json["editionLayers"] = dict()
- for row in range(twRowCount):
- # check that the layer is checked in the WFS capabilities
- layerName = lblTableWidget.item(row, 0).text()
- createFeature = lblTableWidget.item(row, 1).text()
- modifyAttribute = lblTableWidget.item(row, 2).text()
- modifyGeometry = lblTableWidget.item(row, 3).text()
- deleteFeature = lblTableWidget.item(row, 4).text()
- acl = lblTableWidget.item(row, 5).text()
- layerId = lblTableWidget.item(row, 6).text()
- layer = self.get_qgis_layer_by_id(layerId)
- geometryType = self.mapQgisGeometryType[layer.geometryType()]
- if layerId in wfsLayersList:
- liz2json["editionLayers"][layerName] = dict()
- liz2json["editionLayers"][layerName]["layerId"] = layerId
- liz2json["editionLayers"][layerName]["geometryType"] = geometryType
- liz2json["editionLayers"][layerName]["capabilities"] = dict()
- liz2json["editionLayers"][layerName]["capabilities"]["createFeature"] = createFeature
- liz2json["editionLayers"][layerName]["capabilities"]["modifyAttribute"] = modifyAttribute
- liz2json["editionLayers"][layerName]["capabilities"]["modifyGeometry"] = modifyGeometry
- liz2json["editionLayers"][layerName]["capabilities"]["deleteFeature"] = deleteFeature
- liz2json["editionLayers"][layerName]["acl"] = acl
- liz2json["editionLayers"][layerName]["order"] = row
-
# list of Lizmap external baselayers
eblTableWidget = self.dlg.twLizmapBaselayers
twRowCount = eblTableWidget.rowCount()
diff --git a/resources/ui/ui_form_edition.ui b/resources/ui/ui_form_edition.ui
new file mode 100644
index 00000000..271e4b61
--- /dev/null
+++ b/resources/ui/ui_form_edition.ui
@@ -0,0 +1,140 @@
+
+
+ Dialog
+
+
+
+ 0
+ 0
+ 417
+ 238
+
+
+
+ Edition layer
+
+
+ -
+
+
-
+
+
+ Layer
+
+
+
+ -
+
+
+ -
+
+
+ Create
+
+
+ true
+
+
+
+ -
+
+
+ Edit attributes
+
+
+
+ -
+
+
+
+
+
+ false
+
+
+
+ -
+
+
+ Edit geometry
+
+
+
+ -
+
+
+ Delete
+
+
+
+ -
+
+
+ Allowed groups
+
+
+
+ -
+
+
+
+
+
+ false
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ QLabel { color : red; }
+
+
+ ERROR
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+
+
+
+
+ QgsMapLayerComboBox
+ QComboBox
+
+
+
+
+
+
diff --git a/resources/ui/ui_lizmap.ui b/resources/ui/ui_lizmap.ui
index 76947107..4d5b787c 100644
--- a/resources/ui/ui_lizmap.ui
+++ b/resources/ui/ui_lizmap.ui
@@ -2490,7 +2490,7 @@ This is different to the map maximum extent (defined in QGIS project properties,
-
-
+
16777215
@@ -2512,132 +2512,44 @@ This is different to the map maximum extent (defined in QGIS project properties,
false
-
-
- Layer
-
-
-
-
- Create
-
-
-
-
- Modify attributes
-
-
-
-
- Modify geometry
-
-
-
-
- Delete
-
-
-
-
- Allowed groups
-
-
-
-
- Layer id
-
-
-
-
- order
-
-
-
-
-
-
-
-
-
-
- 78
- 0
-
-
-
-
- -
-
-
- Create
-
-
-
+
-
-
+
- Modify attributes
+ +
-
-
+
- Modify geometry
+ -
-
-
+
- Delete
+ edit
-
-
+
- Allowed groups
-
-
-
- -
-
-
- Use a comma separated list of Lizmap groups ids to restrict access to this layer editing.
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
-
-
- -
-
-
-
-
-
- Add layer
+ up
-
-
+
- Remove layer
+ down
@@ -4274,15 +4186,9 @@ This is different to the map maximum extent (defined in QGIS project properties,
add_attribute_table_button
remove_attribute_table_button
scrollArea_2
- twEditionLayerList
- liEditionLayer
- cbEditionLayerCreate
- cbEditionLayerModifyAttribute
- cbEditionLayerModifyGeometry
- cbEditionLayerDeleteFeature
- inEditionLayerAcl
- btEditionLayerAdd
- btEditionLayerDel
+ edition_table
+ add_edition_layer
+ remove_edition_layer
scrollArea_8
add_tooltip_button
scrollArea_5
diff --git a/test/test_table_manager.py b/test/test_table_manager.py
index 5a27c1cd..3f1683b7 100644
--- a/test/test_table_manager.py
+++ b/test/test_table_manager.py
@@ -11,6 +11,7 @@
from ..definitions.atlas import AtlasDefinitions
from ..definitions.attribute_table import AttributeTableDefinitions
+from ..definitions.edition import EditionDefinitions
from ..definitions.filter_by_login import FilterByLoginDefinitions
from ..definitions.locate_by_layer import LocateByLayerDefinitions
from ..definitions.tooltip import ToolTipDefinitions
@@ -44,11 +45,11 @@ def test_filter_by_login(self):
None, definitions, None, table, None, None, None, None)
json = {
- "lines": {
- "filterAttribute": "name",
- "filterPrivate": "False",
- "layerId": "{}".format(layer.id()),
- "order": 0
+ 'lines': {
+ 'filterAttribute': 'name',
+ 'filterPrivate': 'False',
+ 'layerId': layer.id(),
+ 'order': 0
}
}
self.assertEqual(table_manager.table.rowCount(), 0)
@@ -58,9 +59,9 @@ def test_filter_by_login(self):
expected = {
'lines': {
- "filterAttribute": "name",
- "filterPrivate": "False",
- 'layerId': '{}'.format(layer.id()),
+ 'filterAttribute': 'name',
+ 'filterPrivate': 'False',
+ 'layerId': layer.id(),
'order': 0
}
}
@@ -84,7 +85,7 @@ def test_tool_tip(self):
'fields': 'id,name',
'displayGeom': 'False',
'colorGeom': '',
- 'layerId': '{}'.format(layer.id()),
+ 'layerId': layer.id(),
'order': 0
}
}
@@ -115,7 +116,7 @@ def test_attribute_table(self):
'pivot': 'False',
'hideAsChild': 'False',
'hideLayer': 'False',
- 'layerId': '{}'.format(layer.id()),
+ 'layerId': layer.id(),
'order': 0
}
}
@@ -125,7 +126,56 @@ def test_attribute_table(self):
data = table_manager.to_json()
self.assertDictEqual(data, json)
- def test_locate_by_layer(self):
+ def test_edition_layer(self):
+ """Test table manager with edition layer."""
+ layer = QgsVectorLayer(plugin_test_data_path('lines.geojson'), 'lines', 'ogr')
+ QgsProject.instance().addMapLayer(layer)
+ self.assertTrue(layer.isValid())
+
+ table = QTableWidget()
+ definitions = EditionDefinitions()
+
+ table_manager = TableManager(
+ None, definitions, None, table, None, None, None, None)
+
+ json = {
+ 'lines': {
+ 'layerId': layer.id(),
+ 'geometryType': 'line',
+ 'capabilities': {
+ 'createFeature': 'True',
+ 'modifyAttribute': 'True',
+ 'modifyGeometry': 'True',
+ 'deleteFeature': 'True'
+ },
+ 'acl': 'edition_group',
+ 'order': 0
+ }
+ }
+ json_legacy = table_manager._from_json_legacy_order(copy.deepcopy(json))
+ json_legacy = table_manager._from_json_legacy_capabilities(json_legacy)
+ expected = {
+ 'layers': [
+ {
+ 'layerId': layer.id(),
+ 'createFeature': 'True',
+ 'modifyAttribute': 'True',
+ 'modifyGeometry': 'True',
+ 'deleteFeature': 'True',
+ 'acl': 'edition_group',
+ 'order': 0
+ },
+ ]
+ }
+ self.assertDictEqual(json_legacy, expected)
+
+ self.assertEqual(table_manager.table.rowCount(), 0)
+ table_manager.from_json(copy.deepcopy(json))
+ self.assertEqual(table_manager.table.rowCount(), 1)
+ data = table_manager.to_json()
+ self.assertDictEqual(data, json)
+
+ def test_locate_by_layer(self):
"""Test table manager with locate by layer."""
layer = QgsVectorLayer(plugin_test_data_path('lines.geojson'), 'lines', 'ogr')
layer_2 = QgsVectorLayer(plugin_test_data_path('lines.geojson'), 'lines_2', 'ogr')
@@ -148,7 +198,7 @@ def test_locate_by_layer(self):
'displayGeom': 'True',
'minLength': 0,
'filterOnLocate': 'False',
- 'layerId': '{}'.format(layer.id()),
+ 'layerId': layer.id(),
'order': 1
},
'lines_2': {
@@ -157,7 +207,7 @@ def test_locate_by_layer(self):
'displayGeom': 'False',
'minLength': 0,
'filterOnLocate': 'True',
- 'layerId': '{}'.format(layer_2.id()),
+ 'layerId': layer_2.id(),
'order': 0
}
}
@@ -172,7 +222,7 @@ def test_locate_by_layer(self):
'displayGeom': 'False',
'minLength': 0,
'filterOnLocate': 'True',
- 'layerId': '{}'.format(layer_2.id()),
+ 'layerId': layer_2.id(),
'order': 0
},
{
@@ -181,7 +231,7 @@ def test_locate_by_layer(self):
'displayGeom': 'True',
'minLength': 0,
'filterOnLocate': 'False',
- 'layerId': '{}'.format(layer.id()),
+ 'layerId': layer.id(),
'order': 1
},
]
@@ -199,7 +249,7 @@ def test_locate_by_layer(self):
'displayGeom': 'False',
'minLength': 0,
'filterOnLocate': 'True',
- 'layerId': '{}'.format(layer_2.id()),
+ 'layerId': layer_2.id(),
'order': 0
},
'lines': {
@@ -208,7 +258,7 @@ def test_locate_by_layer(self):
'displayGeom': 'True',
'minLength': 0,
'filterOnLocate': 'False',
- 'layerId': '{}'.format(layer.id()),
+ 'layerId': layer.id(),
'order': 1
},
}
@@ -269,16 +319,16 @@ def test_table_manager(self):
# JSON from LWC 3.4 and above
layer_1 = {
- "layer": "{}".format(layer.id()),
- "primaryKey": "{}".format(field),
- "displayLayerDescription": "False",
- "featureLabel": "name",
- "sortField": "name",
- "highlightGeometry": "True",
- "zoom": "center",
- "duration": 5,
- "displayPopup": "True",
- "triggerFilter": "True"
+ 'layer': layer.id(),
+ 'primaryKey': field,
+ 'displayLayerDescription': 'False',
+ 'featureLabel': 'name',
+ 'sortField': 'name',
+ 'highlightGeometry': 'True',
+ 'zoom': 'center',
+ 'duration': 5,
+ 'displayPopup': 'True',
+ 'triggerFilter': 'True'
}
json = {
'layers': [
@@ -369,16 +419,16 @@ def test_atlas_missing_json_parameter(self):
json = {
'layers': [
{
- "layer": "{}".format(layer.id()),
- "primaryKey": "id",
- "displayLayerDescription": "False",
- "featureLabel": "name",
- "sortField": "name",
- "highlightGeometry": "True",
- "zoom": "center",
- "duration": 5,
- "displayPopup": "True",
- "triggerFilter": "True"
+ 'layer': layer.id(),
+ 'primaryKey': 'id',
+ 'displayLayerDescription': 'False',
+ 'featureLabel': 'name',
+ 'sortField': 'name',
+ 'highlightGeometry': 'True',
+ 'zoom': 'center',
+ 'duration': 5,
+ 'displayPopup': 'True',
+ 'triggerFilter': 'True'
}
]
}
@@ -412,16 +462,16 @@ def test_table_manager_3_3(self):
definitions._use_single_row = False
json = {
- "atlasEnabled": "True", # Will not be used
- "atlasLayer": "{}".format(layer.id()),
- "atlasPrimaryKey": "{}".format(field),
- "atlasDisplayLayerDescription": "True",
- "atlasFeatureLabel": "inf3_o_t",
- "atlasSortField": "inf3_o_t",
- "atlasZoom": "zoom",
- "atlasShowAtStartup": "True", # will not be used
- "atlasMaxWidth": 25, # will not be used
- "atlasDuration": 5
+ 'atlasEnabled': 'True', # Will not be used
+ 'atlasLayer': layer.id(),
+ 'atlasPrimaryKey': field,
+ 'atlasDisplayLayerDescription': 'True',
+ 'atlasFeatureLabel': 'inf3_o_t',
+ 'atlasSortField': 'inf3_o_t',
+ 'atlasZoom': 'zoom',
+ 'atlasShowAtStartup': 'True', # will not be used
+ 'atlasMaxWidth': 25, # will not be used
+ 'atlasDuration': 5
}
table_manager = TableManager(
@@ -435,16 +485,16 @@ def test_table_manager_3_3(self):
expected = {
'layers': [
{
- "layer": "{}".format(layer.id()),
- "primaryKey": "{}".format(field),
- "displayLayerDescription": "True",
- "featureLabel": "inf3_o_t",
- "sortField": "inf3_o_t",
- "zoom": "zoom",
- "duration": 5,
- "displayPopup": "False", # auto added by the tool
- "highlightGeometry": "False", # auto added by the tool
- "triggerFilter": "False", # auto added by the tool
+ 'layer': layer.id(),
+ 'primaryKey': field,
+ 'displayLayerDescription': 'True',
+ 'featureLabel': 'inf3_o_t',
+ 'sortField': 'inf3_o_t',
+ 'zoom': 'zoom',
+ 'duration': 5,
+ 'displayPopup': 'False', # auto added by the tool
+ 'highlightGeometry': 'False', # auto added by the tool
+ 'triggerFilter': 'False', # auto added by the tool
}
]
}
@@ -456,7 +506,7 @@ def test_table_manager_3_3(self):
expected = {
'atlasEnabled': 'True', # Hard coded for Lizmap 3.3
'atlasMaxWidth': 25, # will not be used
- 'atlasLayer': "{}".format(layer.id()),
+ 'atlasLayer': layer.id(),
'atlasPrimaryKey': 'id',
'atlasDisplayLayerDescription': 'True',
'atlasFeatureLabel': 'inf3_o_t',