Skip to content

Commit

Permalink
Implement a feature-based geometry lock mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Dec 2, 2023
1 parent 89756ba commit 52180ff
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 11 deletions.
38 changes: 35 additions & 3 deletions qfieldsync/gui/map_layer_config_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import os

from libqfieldsync.layer import LayerSource
from qgis.core import QgsMapLayer, QgsProject
from qgis.core import QgsMapLayer, QgsProject, QgsProperty, QgsPropertyDefinition
from qgis.gui import QgsMapLayerConfigWidget, QgsMapLayerConfigWidgetFactory
from qgis.PyQt.QtWidgets import QLabel
from qgis.PyQt.uic import loadUiType
Expand Down Expand Up @@ -55,6 +55,8 @@ def supportLayerPropertiesDialog(self):


class MapLayerConfigWidget(QgsMapLayerConfigWidget, WidgetUi):
PROPERTY_GEOMETRY_LOCKED = 1

def __init__(self, layer, canvas, parent):
super(MapLayerConfigWidget, self).__init__(layer, canvas, parent)
self.setupUi(self)
Expand All @@ -72,8 +74,35 @@ def __init__(self, layer, canvas, parent):
self.layer_source.action,
)

self.isGeometryLockedCheckBox.setEnabled(self.layer_source.can_lock_geometry)
self.isGeometryLockedCheckBox.setChecked(self.layer_source.is_geometry_locked)
if layer.type() == QgsMapLayer.VectorLayer:
prop = QgsProperty.fromExpression(
self.layer_source.geometry_locked_expression
)
prop.setActive(self.layer_source.is_geometry_locked_expression_active)
prop_definition = QgsPropertyDefinition(
"is_geometry_locked",
QgsPropertyDefinition.DataType.DataTypeBoolean,
"Geometry Locked",
"",
)
self.isGeometryLockedDDButton.init(
MapLayerConfigWidget.PROPERTY_GEOMETRY_LOCKED,
prop,
prop_definition,
None,
False,
)
self.isGeometryLockedDDButton.setVectorLayer(layer)

self.isGeometryLockedCheckBox.setEnabled(
self.layer_source.can_lock_geometry
)
self.isGeometryLockedCheckBox.setChecked(
self.layer_source.is_geometry_locked
)
else:
self.isGeometryLockedDDButton.setVisible(False)
self.isGeometryLockedCheckBox.setVisible(False)

self.attachmentNamingTable = AttachmentNamingTableWidget()
self.attachmentNamingTable.addLayerFields(self.layer_source)
Expand Down Expand Up @@ -122,6 +151,9 @@ def apply(self):
self.cableLayerActionComboBox.currentIndex()
)
self.layer_source.is_geometry_locked = self.isGeometryLockedCheckBox.isChecked()
prop = self.isGeometryLockedDDButton.toProperty()
self.layer_source.is_geometry_locked_expression_active = prop.isActive()
self.layer_source.geometry_locked_expression = prop.asExpression()
self.attachmentNamingTable.syncLayerSourceValues()
self.relationshipConfigurationTable.syncLayerSourceValues()

Expand Down
47 changes: 39 additions & 8 deletions qfieldsync/ui/map_layer_config_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,51 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="isGeometryLockedCheckBox">
<property name="toolTip">
<string>When enabled, this option disables adding and deleting features, as well as modifying the geometries of existing features.</string>
</property>
<property name="text">
<string>Lock geometries</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="isGeometryLockedCheckBox">
<property name="toolTip">
<string>When enabled, this option disables adding and deleting features, as well as modifying the geometries of existing features.</string>
</property>
<property name="text">
<string>Lock geometries</string>
</property>
</widget>
</item>
<item>
<widget class="QgsPropertyOverrideButton" name="isGeometryLockedDDButton">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cableLayerActionComboBox"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsPropertyOverrideButton</class>
<extends>QToolButton</extends>
<header>qgspropertyoverridebutton.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

0 comments on commit 52180ff

Please sign in to comment.