Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement geofencing settings in the project properties' QField panel #593

Merged
merged 7 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 76 additions & 10 deletions qfieldsync/gui/project_configuration_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ def __init__(self, parent=None):
self.event_eater = EventEater()
self.attachmentDirsListWidget.installEventFilter(self.event_eater)

self.geofencingBehaviorComboBox.addItem(
self.tr("Alert users when inside an area"),
ProjectProperties.GeofencingBehavior.ALERT_INSIDE_AREAS,
)
self.geofencingBehaviorComboBox.addItem(
self.tr("Alert users when outside all areas"),
ProjectProperties.GeofencingBehavior.ALERT_OUTSIDE_AREAS,
)
self.geofencingBehaviorComboBox.addItem(
self.tr("Inform users when entering and leaving an area"),
ProjectProperties.GeofencingBehavior.INFORM_ENTER_LEAVE_AREAS,
)

self.reloadProject()

def reloadProject(self):
Expand Down Expand Up @@ -144,10 +157,16 @@ def reloadProject(self):
self.mapThemeComboBox.addItem(theme)

self.layerComboBox.setFilters(QgsMapLayerProxyModel.RasterLayer)

self.geofencingLayerComboBox.setFilters(QgsMapLayerProxyModel.PolygonLayer)
self.geofencingLayerComboBox.setAllowEmptyLayer(True)

self.digitizingLogsLayerComboBox.setFilters(QgsMapLayerProxyModel.PointLayer)
self.digitizingLogsLayerComboBox.setAllowEmptyLayer(True)

self.__project_configuration = ProjectConfiguration(self.project)

# Base map settings
self.createBaseMapGroupBox.setChecked(
self.__project_configuration.create_base_map
)
Expand All @@ -169,6 +188,27 @@ def reloadProject(self):
)
self.layerComboBox.setLayer(layer)

# Geofencing settings
self.geofencingGroupBox.setChecked(
self.__project_configuration.geofencing_is_active
)

geofencingLayer = QgsProject.instance().mapLayer(
self.__project_configuration.geofencing_layer
)
self.geofencingLayerComboBox.setLayer(geofencingLayer)

self.geofencingBehaviorComboBox.setCurrentIndex(
self.geofencingBehaviorComboBox.findData(
self.__project_configuration.geofencing_behavior
)
)

self.geofencingShouldPreventDigitizingCheckBox.setChecked(
self.__project_configuration.geofencing_should_prevent_digitizing
)

# Advanced settings
digitizingLogsLayer = QgsProject.instance().mapLayer(
self.__project_configuration.digitizing_logs_layer
)
Expand Down Expand Up @@ -229,21 +269,56 @@ def apply(self):
self.cloudLayersConfigWidget.apply()
self.cableLayersConfigWidget.apply()

# Base map settings
self.__project_configuration.create_base_map = (
self.createBaseMapGroupBox.isChecked()
)

if self.singleLayerRadioButton.isChecked():
self.__project_configuration.base_map_type = (
ProjectProperties.BaseMapType.SINGLE_LAYER
)
else:
self.__project_configuration.base_map_type = (
ProjectProperties.BaseMapType.MAP_THEME
)

self.__project_configuration.base_map_theme = (
self.mapThemeComboBox.currentText()
)

# try/pass these because the save button is global for all
# try/pass layer ID fetching because the save button is global for all
# project settings, not only QField
try:
self.__project_configuration.base_map_layer = (
self.layerComboBox.currentLayer().id()
)
except AttributeError:
pass

# Geofencing settings
self.__project_configuration.geofencing_is_active = (
self.geofencingGroupBox.isChecked()
)

try:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a concrete example when we need the try/except? I see it is also 10 lines above, but on this line it seems you handle this with the if/else check for currentLayer() existance.

self.__project_configuration.geofencing_layer = (
self.geofencingLayerComboBox.currentLayer().id()
if self.geofencingLayerComboBox.currentLayer()
else ""
)
except AttributeError:
pass

self.__project_configuration.geofencing_behavior = (
self.geofencingBehaviorComboBox.currentData()
)

self.__project_configuration.geofencing_should_prevent_digitizing = (
self.geofencingShouldPreventDigitizingCheckBox.isChecked()
)

# Advanced settings
try:
self.__project_configuration.digitizing_logs_layer = (
self.digitizingLogsLayerComboBox.currentLayer().id()
Expand All @@ -253,15 +328,6 @@ def apply(self):
except AttributeError:
pass

if self.singleLayerRadioButton.isChecked():
self.__project_configuration.base_map_type = (
ProjectProperties.BaseMapType.SINGLE_LAYER
)
else:
self.__project_configuration.base_map_type = (
ProjectProperties.BaseMapType.MAP_THEME
)

self.__project_configuration.base_map_mupp = float(
self.mapUnitsPerPixel.value()
)
Expand Down
49 changes: 49 additions & 0 deletions qfieldsync/ui/project_configuration_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,55 @@
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="geofencingGroupBox">
<property name="title">
<string>Geofencing</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="geofencingGridLayout" columnstretch="1,3">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="geofencingIntroductionLabel">
<property name="text">
<string>QField provides real-time feedback to users when their device position falls within or outside of areas defined by a selected polygon layer.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="geofencingLayerLabel">
<property name="text">
<string>Geofencing areas layer</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsMapLayerComboBox" name="geofencingLayerComboBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="geofencingBehaviorLabel">
<property name="text">
<string>Geofencing behavior</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="geofencingBehaviorComboBox"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="geofencingShouldPreventDigitizingCheckBox">
<property name="text">
<string>Prevent digitizing when alerting</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="advancedSettingsGroupBox">
<property name="title">
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ future
transifex-client

# NOTE `libqfielsync` version should be defined in the `*.tar.gz` format, not `git+https://` to make `wheel` happy
libqfieldsync @ https://github.com/opengisch/libqfieldsync/archive/c98ef2671aca31c7943d3aa4c69221dbdb157d5a.tar.gz
libqfieldsync @ https://github.com/opengisch/libqfieldsync/archive/61523b5775dd1bccc25abcf4b9c7a266af18c214.tar.gz
Loading