From d8dc3670afceeccef76e80dc315c8227e0171763 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Thu, 20 Apr 2023 14:42:58 +0700 Subject: [PATCH] Insure a non-averaged position vertex is added when accepting geometry upon hitting the accept/confirm button --- src/qml/DigitizingToolbar.qml | 68 +++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/src/qml/DigitizingToolbar.qml b/src/qml/DigitizingToolbar.qml index f138e064a5..a3630a5e1d 100644 --- a/src/qml/DigitizingToolbar.qml +++ b/src/qml/DigitizingToolbar.qml @@ -40,6 +40,12 @@ VisibilityFadingRow { target: rubberbandModel function onVertexCountChanged() { + var extraVertexNeed = coordinateLocator && coordinateLocator.positionLocked + && positioningSettings.averagedPositioning + && positioningSettings.averagedPositioningMinimumCount > 1 + ? 1 + : 0 + // set geometry valid if (Number( rubberbandModel ? rubberbandModel.geometryType : 0 ) === 0) { @@ -48,12 +54,12 @@ VisibilityFadingRow { else if (Number( rubberbandModel.geometryType ) === 1) { // Line: at least 2 points - geometryValid = rubberbandModel.vertexCount > 1 + geometryValid = rubberbandModel.vertexCount > 1 + extraVertexNeed } else if (Number( rubberbandModel.geometryType ) === 2) { // Polygon: at least 3 points - geometryValid = rubberbandModel.vertexCount > 2 + geometryValid = rubberbandModel.vertexCount > 2 + extraVertexNeed } else { @@ -115,7 +121,6 @@ VisibilityFadingRow { bgcolor: Theme.mainColor onClicked: { - rubberbandModel.frozen = true confirm() } } @@ -179,6 +184,7 @@ VisibilityFadingRow { ] transitions: [ Transition { NumberAnimation { property: "opacity"; duration: 200 } } ] + property bool lastAdditionAveraged: false property bool averagedPositionPressAndHeld: false property bool averagedPositionAutoRelease: false Connections { @@ -223,11 +229,12 @@ VisibilityFadingRow { positionSource.averagedPosition = false; return; } + + lastAdditionAveraged = true + addVertex() if (Number(rubberbandModel.geometryType) === Qgis.GeometryType.Point || Number(rubberbandModel.geometryType) === Qgis.GeometryType.Null) { confirm() - } else { - addVertex() } positionSource.averagedPosition = false; } @@ -240,30 +247,31 @@ VisibilityFadingRow { } onClicked: { - if (!checkAccuracyRequirement()) { - return; - } - - if (coordinateLocator && coordinateLocator.positionLocked && - positioningSettings.averagedPositioning && - (positioningSettings.averagedPositioningMinimumCount > 1 - || !positioningSettings.averagedPositioningAutomaticStop)) { - if (!positionSource.averagedPosition) { - averagedPositionAutoRelease = true; - positionSource.averagedPosition = true; - } else { - addVertexButton.averagedPositionPressAndHeld = true; - addVertexButton.released() - } - return; - } + if (!checkAccuracyRequirement()) { + return; + } - if (Number(rubberbandModel.geometryType) === Qgis.GeometryType.Point || - Number(rubberbandModel.geometryType) === Qgis.GeometryType.Null) { - confirm() + if (coordinateLocator && coordinateLocator.positionLocked && + positioningSettings.averagedPositioning && + (positioningSettings.averagedPositioningMinimumCount > 1 + || !positioningSettings.averagedPositioningAutomaticStop)) { + if (!positionSource.averagedPosition) { + averagedPositionAutoRelease = true; + positionSource.averagedPosition = true; } else { - addVertex() + addVertexButton.averagedPositionPressAndHeld = true; + addVertexButton.released() } + return; + } + + lastAdditionAveraged = false + if (Number(rubberbandModel.geometryType) === Qgis.GeometryType.Point || + Number(rubberbandModel.geometryType) === Qgis.GeometryType.Null) { + confirm() + } else { + addVertex() + } } } @@ -325,7 +333,13 @@ VisibilityFadingRow { } function confirm() { - digitizingLogger.addCoordinate( coordinateLocator.currentCoordinate ) + rubberbandModel.frozen = true + if (addVertexButton.lastAdditionAveraged) { + rubberbandModel.removeVertex(); + } else { + digitizingLogger.addCoordinate( coordinateLocator.currentCoordinate ) + } + confirmed() } }