Skip to content

Commit

Permalink
Update snap geometry edits sample (#1752)
Browse files Browse the repository at this point in the history
  • Loading branch information
har13205 authored Sep 28, 2024
1 parent 9e2eeec commit 5ed8827
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
7 changes: 5 additions & 2 deletions CppSamples/EditData/SnapGeometryEdits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A field worker can create new features by editing and snapping the vertices of a

To create a geometry, press the create button to choose the geometry type you want to create (i.e. points, multipoints, polyline, or polygon) and interactively tap and drag on the map view to create the geometry.

To configure snapping, press the snap settings button to enable or disable snapping and choose which snap sources to snap to.
Snap settings can be configured by enabling and disabling snapping, feature snapping, geometry guides and snap sources.

To interactively snap a vertex to a feature or graphic, ensure that snapping is enabled for the relevant snap source and move the mouse pointer or drag a vertex to nearby an existing feature or graphic. When the pointer is close to that existing geoelement, the edit position will be adjusted to coincide with (or snap to), edges and vertices of its geometry. Click or release the touch pointer to place the vertex at the snapped location.

Expand All @@ -31,7 +31,8 @@ To save your edits, press the save button.
3. Create a `GeometryEditor` and connect it to the map view.
4. Call `syncSourceSettings` after the map's operational layers are loaded and the geometry editor connected to the map view.
5. Set `SnapSettings.isEnabled` and `SnapSourceSettings.isEnabled` to true for the `SnapSource` of interest.
6. Start the geometry editor with a `GeometryType`.
6. Toggle geometry guides using `SnapSettings.IsGeometryGuidesEnabled` and feature snapping using `SnapSettings.IsFeatureSnappingEnabled`.
7. Start the geometry editor with a `GeometryType`.

## Relevant API

Expand All @@ -57,6 +58,8 @@ To snap to polygon and polyline layers, the recommended approach is to set the `

Snapping can be used during interactive edits that move existing vertices using the `VertexTool` or `ReticleVertexTool`. When adding new vertices, snapping also works with a hover event (such as a mouse move without a mouse button press). Using the `ReticleVertexTool` to add and move vertices allows users of touch screen devices to clearly see the visual cues for snapping.

Geometry guides are enabled by default when snapping is enabled. These allow for snapping to a point coinciding with, parallel to, perpendicular to or extending an existing geometry.

## Tags

edit, feature, geometry editor, graphics, layers, map, snapping
12 changes: 12 additions & 0 deletions CppSamples/EditData/SnapGeometryEdits/SnapGeometryEdits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ void SnapGeometryEdits::snappingEnabledStatus(bool snappingCheckedState)
m_geometryEditor->snapSettings()->setEnabled(snappingCheckedState);
}

// Toggles geometry guides using the enabled state from the snap settings
void SnapGeometryEdits::geometryGuidesEnabledStatus(bool geometryGuidesCheckedState)
{
m_geometryEditor->snapSettings()->setGeometryGuidesEnabled(geometryGuidesCheckedState);
}

// Toggles feature snapping using the enabled state from the snap settings
void SnapGeometryEdits::featureSnappingEnabledStatus(bool featureSnappingCheckedState)
{
m_geometryEditor->snapSettings()->setFeatureSnappingEnabled(featureSnappingCheckedState);
}

// Starts the GeometryEditor using the selected geometry type
void SnapGeometryEdits::startEditor(GeometryEditorMode geometryEditorMode)
{
Expand Down
2 changes: 2 additions & 0 deletions CppSamples/EditData/SnapGeometryEdits/SnapGeometryEdits.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class SnapGeometryEdits : public QObject
Q_INVOKABLE void deleteSelection();
Q_INVOKABLE void editorUndo();
Q_INVOKABLE void snappingEnabledStatus(bool checkedValue);
Q_INVOKABLE void geometryGuidesEnabledStatus(bool checkedValue);
Q_INVOKABLE void featureSnappingEnabledStatus(bool checkedValue);
Q_INVOKABLE void displaySnapSources();
Q_INVOKABLE void enableAllLayersInSection(const QString& section);

Expand Down
56 changes: 54 additions & 2 deletions CppSamples/EditData/SnapGeometryEdits/SnapGeometryEdits.qml
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,18 @@ Item {
}
}

RowLayout {
ColumnLayout {
Layout.minimumWidth: optionPanel.width
Layout.minimumHeight: 35
spacing: 0
Rectangle {
Layout.alignment: Qt.AlignLeft
Layout.minimumWidth: snapSourceView.width - (snapSourceView.anchors.margins / 2)
Layout.minimumHeight: 35
color: "#E9DFEA"

Text {
text: qsTr("Enabled")
text: qsTr("Snapping enabled")
font.pixelSize: 15
anchors {
left: parent.left
Expand All @@ -250,6 +251,57 @@ Item {
onCheckedChanged: snapGeometryEditsSampleModel.snappingEnabledStatus(checked)
}
}
Rectangle {
Layout.alignment: Qt.AlignLeft
Layout.minimumWidth: snapSourceView.width - (snapSourceView.anchors.margins / 2)
Layout.minimumHeight: 35
color: "#E9DFEA"

Text {
text: qsTr("Geometry guides")
font.pixelSize: 15
anchors {
left: parent.left
margins: 10
verticalCenter: parent.verticalCenter
}
}

Switch {
anchors {
right: parent.right
margins: 10
verticalCenter: parent.verticalCenter
}
onCheckedChanged: snapGeometryEditsSampleModel.geometryGuidesEnabledStatus(checked)
}
}
Rectangle {
Layout.alignment: Qt.AlignLeft
Layout.minimumWidth: snapSourceView.width - (snapSourceView.anchors.margins / 2)
Layout.minimumHeight: 35
color: "#E9DFEA"


Text {
text: qsTr("Feature snapping")
font.pixelSize: 15
anchors {
left: parent.left
margins: 10
verticalCenter: parent.verticalCenter
}
}

Switch {
anchors {
right: parent.right
margins: 10
verticalCenter: parent.verticalCenter
}
onCheckedChanged: snapGeometryEditsSampleModel.featureSnappingEnabledStatus(checked)
}
}
}
}

Expand Down

0 comments on commit 5ed8827

Please sign in to comment.