From a78ef295156e7ac3651b12ebca1318ab979f0f55 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sat, 21 Oct 2023 17:29:32 +0700 Subject: [PATCH 1/2] Get the vector layer pointer _before_ we close the layer properties and unset index --- src/core/layertreemapcanvasbridge.cpp | 7 +++++-- src/qml/LayerTreeItemProperties.qml | 11 ++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/core/layertreemapcanvasbridge.cpp b/src/core/layertreemapcanvasbridge.cpp index def309d62d..ad09bfada3 100644 --- a/src/core/layertreemapcanvasbridge.cpp +++ b/src/core/layertreemapcanvasbridge.cpp @@ -163,6 +163,9 @@ void LayerTreeMapCanvasBridge::mapThemeChanged() void LayerTreeMapCanvasBridge::layerInTrackingChanged( QgsVectorLayer *layer, bool tracking ) { - QgsLayerTreeLayer *nodeLayer = mRoot->findLayer( layer->id() ); - mModel->setLayerInTracking( nodeLayer, tracking ); + if ( layer ) + { + QgsLayerTreeLayer *nodeLayer = mRoot->findLayer( layer->id() ); + mModel->setLayerInTracking( nodeLayer, tracking ); + } } diff --git a/src/qml/LayerTreeItemProperties.qml b/src/qml/LayerTreeItemProperties.qml index d000194b5e..15d15cd104 100644 --- a/src/qml/LayerTreeItemProperties.qml +++ b/src/qml/LayerTreeItemProperties.qml @@ -297,18 +297,19 @@ Popup { icon.source: Theme.getThemeVectorIcon( 'directions_walk_24dp' ) onClicked: { + var layer = layerTree.data(index, FlatLayerTreeModel.VectorLayerPointer) close() - if ( trackingModel.layerInTracking( layerTree.data(index, FlatLayerTreeModel.VectorLayerPointer) ) ) { - trackingModel.stopTracker(layerTree.data(index, FlatLayerTreeModel.VectorLayerPointer)); - displayToast( qsTr( 'Track on layer %1 stopped' ).arg( layerTree.data(index, FlatLayerTreeModel.VectorLayerPointer).name ) ) + if (trackingModel.layerInTracking(layer)) { + trackingModel.stopTracker(layer); + displayToast(qsTr('Track on layer %1 stopped').arg(layer.name)) } else { var tracker; - var idx = projectInfo.restoreTracker(layerTree.data(index, FlatLayerTreeModel.VectorLayerPointer)) + var idx = projectInfo.restoreTracker(layer) if (idx.valid) { tracker = trackings.itemAt(idx.row).tracker } else { - idx = trackingModel.createTracker(layerTree.data(index, FlatLayerTreeModel.VectorLayerPointer)) + idx = trackingModel.createTracker(layer) tracker = trackings.itemAt(idx.row).tracker tracker.visible = itemVisibleCheckBox.checked tracker.minimumDistance = positioningSettings.trackerMinimumDistanceConstraint ? positioningSettings.trackerMinimumDistance : 0 From 780025a2adf832a0f86be5b37ce4df7de6b55c2b Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sat, 21 Oct 2023 17:44:49 +0700 Subject: [PATCH 2/2] When resuming tracking, do not erase the last vertex from the previous session --- src/core/rubberbandmodel.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/rubberbandmodel.cpp b/src/core/rubberbandmodel.cpp index 5dce35d468..450e2f6f21 100644 --- a/src/core/rubberbandmodel.cpp +++ b/src/core/rubberbandmodel.cpp @@ -341,6 +341,9 @@ void RubberbandModel::setDataFromGeometry( QgsGeometry geometry, const QgsCoordi mPointList << pt; } + // insert the last point twice so the resutling rubberband's current coordinate property being modified (by e.g. + // the GNSS position) will not replace the last vertex from the passed geometry + mPointList << pt; mCurrentCoordinateIndex = mPointList.size() - 1;