Open tylerchism opened 3 weeks ago
I've noticed this problem also. Your recreation of the issue from QGIS first principals here really highlights the issue. I'd like to know if this is actually a bug or if there is just a simple line of code which is missing which would sidestep this issue...
What is the bug or the crash?
vertex tool activated for a single polygon in one layer will sometimes trigger vertex highlighting with mouse hover activated for separate polygon in separate layer. The "correct" polygon does not respond to vertex clicks. The "wrong" polygon responds to vertex clicks, but the clicks activate a random vertex of the "correct" polygon.
A bare bones test script has been provided to reproduce this issue.
Steps to reproduce the issue
Remove existing layers for a clean environment
QgsProject.instance().removeAllMapLayers()
Create a temporary polygon layer
polygon_layer = QgsVectorLayer("Polygon?crs=EPSG:4326", "Test Polygons", "memory") pr = polygon_layer.dataProvider()
Add an ID field
pr.addAttributes([QgsField("id", QVariant.Int)]) polygon_layer.updateFields()
Define two polygons
polygon1 = QgsFeature() polygon1.setFields(polygon_layer.fields()) polygon1.setAttribute("id", 1) polygon1.setGeometry(QgsGeometry.fromPolygonXY([[QgsPointXY(-10, -10), QgsPointXY(0, -10), QgsPointXY(0, 0), QgsPointXY(-10, 0), QgsPointXY(-10, -10)]]))
polygon2 = QgsFeature() polygon2.setFields(polygon_layer.fields()) polygon2.setAttribute("id", 2) polygon2.setGeometry(QgsGeometry.fromPolygonXY([[QgsPointXY(10, 10), QgsPointXY(20, 10), QgsPointXY(20, 20), QgsPointXY(10, 20), QgsPointXY(10, 10)]]))
Add polygons to the layer
pr.addFeatures([polygon1, polygon2]) polygon_layer.updateExtents()
Add the layer to the project
QgsProject.instance().addMapLayer(polygon_layer)
Custom Map Tool
class RightClickEditTool(QgsMapTool): def init(self, canvas): super().init(canvas) self.canvas = canvas self.tmp_layer = None self.previous_tmp_layer = None
Instantiate and activate the custom map tool
canvas = iface.mapCanvas() edit_tool = RightClickEditTool(canvas) canvas.setMapTool(edit_tool)