提问人:nospec 提问时间:11/16/2023 最后编辑:nospec 更新时间:11/16/2023 访问量:30
如何在带有自定义 QgsMapCanvas 的 pyqgis 插件中使用 iface.actionVertexTool()?
How to use iface.actionVertexTool() in a pyqgis plugin with custom QgsMapCanvas?
问:
我需要在我的 pyqgis 插件中编辑实例化为的功能。我已经启用了捕捉选项并通过 python 代码触发了顶点工具,但除了光标更改为 之外,当它悬停在要在自定义上编辑的图层上时,什么也没发生。没有类似于 的。我觉得这可能不合适,因为这可能仅适用于 ,但我可以进行更正。QgsMapCanvas
self.canvas
CrossCursor
QgsMapCanvas
QgsActionVertexTool
QgsActionPan
iface.actionVertexTool()
QgisInterface()
这是代码。
from qgis.core import QgsSnappingConfig, QgsTolerance, QgsMapLayer
from qgis.gui import QgsMapTool
from qgis.utils import iface
from .feedback import Feedback
class GeoManipulation():
def __init__(self, canvas, project, view, console, button):
super().__init__()
self.canvas = canvas
self.project = project
self.view = view
self.console_out = console
self.gm_edit_button = button
self.setSnapConfig()
self.vertexEditor()
def setSnapConfig(self):
snap_config = QgsSnappingConfig()
snap_config.setEnabled(True)
snap_config.setMode(snap_config.SnappingMode.AllLayers)
snap_config.setType(snap_config.Vertex)
snap_config.setTolerance(12)
snap_config.setUnits(QgsTolerance.Pixels)
snap_config.setIntersectionSnapping(True)
snap_config.setSelfSnapping(True)
self.project.setTopologicalEditing(True)
self.project.setSnappingConfig(snap_config)
def vertexEditor(self):
self.cur_lyr = self.view.currentLayer()
vertex_action = iface.actionVertexTool()
vertex_tool = QgsMapTool(self.canvas)
vertex_tool.setAction(vertex_action)
self.canvas.setMapTool(vertex_tool)
if self.gm_edit_button.isChecked():
if self.cur_lyr == None or self.cur_lyr.type() != QgsMapLayer.VectorLayer:
Feedback().error(self.console_out, "Please Select an Asset Layer")
self.gm_edit_button.setChecked(False)
else:
print(self.cur_lyr)
self.cur_lyr.startEditing()
# vertex_action.trigger()
vertex_tool.activate()
else:
Feedback().success(self.console_out, "Edits to Current Layer Successfully Saved")
self.cur_lyr.commitChanges()
vertex_tool.deactivate()
我也尝试过,但没有用。QgsMapToolEdit
答: 暂无答案
评论