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

Angle snapping tolerance functionality #5945

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
29 changes: 26 additions & 3 deletions src/qml/CoordinateLocator.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Item {
property bool snapToCommonAngles: false
property bool snappingIsRelative: false
property real snappingAngleDegrees: 45.0
property real snappingTolerance: 1

/**
* Overrides any possibility for the user to modify the coordinate.
Expand Down Expand Up @@ -392,6 +393,28 @@ Item {
flashAnimation.start();
}

/** Function to get the multiplier based on the selected tolerance
*
* - Narrow tolerance (index 0) divides by 2.
* - Normal tolerance (index 1) keeps unchanged.
* - Large tolerance (index 2) multiplies by 4.
*/
function getToleranceMultiplier() {
switch (snappingTolerance) {
case 0 // Narrow
:
return 0.5;
case 1 // Normal
:
return 1;
case 2 // Large
:
return 4;
default:
return 1;
}
}

/**
* Computes the possible common angle
*
Expand All @@ -406,9 +429,9 @@ Item {
if (!rubberbandModel) {
return;
}
const MINIMAL_PIXEL_DISTANCE_TRESHOLD = 20;
const SOFT_CONSTRAINT_TOLERANCE_DEGREES = 20;
const SOFT_CONSTRAINT_TOLERANCE_PIXEL = 40;
const MINIMAL_PIXEL_DISTANCE_TRESHOLD = 20 * getToleranceMultiplier();
const SOFT_CONSTRAINT_TOLERANCE_DEGREES = 20 * getToleranceMultiplier();
const SOFT_CONSTRAINT_TOLERANCE_PIXEL = 40 * getToleranceMultiplier();
const rubberbandPointsCount = rubberbandModel.vertexCount;
const targetPoint = mapCanvas.mapSettings.coordinateToScreen(forwardMode ? rubberbandModel.firstCoordinate : rubberbandModel.lastCoordinate);
const minimumDigitizedPoints = forwardMode ? 3 : 2;
Expand Down
147 changes: 128 additions & 19 deletions src/qml/qgismobileapp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,7 @@ ApplicationWindow {
coordinateLocator.snapToCommonAngles = settings.valueBool("/QField/Digitizing/SnapToCommonAngleIsEnabled", false);
coordinateLocator.snappingIsRelative = settings.valueBool("/QField/Digitizing/SnapToCommonAngleIsRelative", true);
coordinateLocator.snappingAngleDegrees = settings.valueInt("/QField/Digitizing/SnapToCommonAngleDegrees", 45);
coordinateLocator.snappingTolerance = settings.valueInt("/QField/Digitizing/SnappingTolerance", 1);
}

Menu {
Expand All @@ -1721,31 +1722,139 @@ ApplicationWindow {
width: parent.width
}

Repeater {
// list of common angles to snap to
Text {
text: qsTr("Snapping to every")
color: Theme.mainTextColor
font: Theme.defaultFont
leftPadding: 8
}

Item {
width: 1
height: 8
}

ListView {
id: angles
height: 35
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: 4
spacing: 3
orientation: ListView.Horizontal
model: [10, 15, 30, 45, 90]
delegate: MenuItem {
required property int modelData
delegate: Rectangle {
width: (angles.width - ((angles.count - 1) * angles.spacing)) / angles.count
height: width
radius: width / 2
color: selected ? Theme.mainColor : "transparent"
enabled: !selected

property bool selected: modelData === coordinateLocator.snappingAngleDegrees

Text {
text: qsTr("%1°").arg(modelData)
font: parent.selected ? Theme.strongTipFont : Theme.tipFont
anchors.centerIn: parent
color: Theme.mainTextColor
}

text: qsTr("Snap every %1°").arg(modelData)
Ripple {
clip: true
anchors.fill: parent
clipRadius: width / 2
pressed: angleMouseArea.pressed
anchor: parent
active: angleMouseArea.pressed
color: "#22aaaaaa"
}

font: Theme.defaultFont
height: 48
leftPadding: Theme.menuItemCheckLeftPadding
MouseArea {
id: angleMouseArea
anchors.fill: parent
onClicked: {
if (parent.selected) {
return;
}
coordinateLocator.snapToCommonAngles = true;
coordinateLocator.snappingAngleDegrees = modelData;
settings.setValue("/QField/Digitizing/SnapToCommonAngleDegrees", coordinateLocator.snappingAngleDegrees);
displayToast(qsTr("Snap to %1° angle turned on").arg(modelData));
snapToCommonAngleMenu.close();
}
}
}
}

checkable: true
checked: modelData === coordinateLocator.snappingAngleDegrees
enabled: modelData !== coordinateLocator.snappingAngleDegrees
Item {
width: 1
height: 8
}

Text {
text: qsTr("Snapping tolerance")
color: Theme.mainTextColor
font: Theme.defaultFont
leftPadding: 8
}

Item {
width: 1
height: 8
}

ListView {
id: tolorences
height: 35
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: 4
spacing: 3
orientation: ListView.Horizontal
model: [qsTr("Narrow"), qsTr("Normal"), qsTr("Large")]

delegate: Rectangle {
width: (tolorences.width - (tolorences.spacing * (tolorences.count - 1))) / tolorences.count
height: 35
radius: 4
color: selected ? Theme.mainColor : "transparent"
enabled: !selected

property bool selected: index === coordinateLocator.snappingTolerance

Text {
text: modelData
font: parent.selected ? Theme.strongTipFont : Theme.tipFont
anchors.centerIn: parent
color: Theme.mainTextColor
elide: Text.ElideRight
width: parent.width
horizontalAlignment: Text.AlignHCenter
}

Ripple {
clip: true
anchors.fill: parent
clipRadius: 4
pressed: tolerancesMouseArea.pressed
anchor: parent
active: tolerancesMouseArea.pressed
color: "#22aaaaaa"
}

onTriggered: {
if (!checked) {
return;
MouseArea {
id: tolerancesMouseArea
anchors.fill: parent
onClicked: {
if (parent.selected) {
return;
}
coordinateLocator.snapToCommonAngles = true;
coordinateLocator.snappingTolerance = index;
settings.setValue("/QField/Digitizing/SnappingTolerance", coordinateLocator.snappingTolerance);
displayToast(qsTr("Snappin tolerance setted to %1").arg(modelData));
snapToCommonAngleMenu.close();
}
coordinateLocator.snapToCommonAngles = true;
coordinateLocator.snappingAngleDegrees = modelData;
settings.setValue("/QField/Digitizing/SnapToCommonAngleDegrees", coordinateLocator.snappingAngleDegrees);
displayToast(qsTr("Snap to %1° angle turned on").arg(modelData));
snapToCommonAngleMenu.close();
}
}
}
Expand Down
Loading