You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
3.0 KiB
80 lines
3.0 KiB
from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QLabel,
|
|
QPushButton, QTableWidget, QTableWidgetItem)
|
|
from PyQt5.QtCore import Qt, QPointF
|
|
from .base_map_view import BaseMapView
|
|
|
|
class PathLayerView(BaseMapView):
|
|
def __init__(self, map_data_model):
|
|
super().__init__(map_data_model)
|
|
self.add_path_mode = False
|
|
self.current_path = []
|
|
self.init_additional_ui()
|
|
|
|
def init_additional_ui(self):
|
|
# 创建路径控制按钮
|
|
path_control_layout = QHBoxLayout()
|
|
|
|
self.add_path_btn = QPushButton("添加路径点")
|
|
self.add_path_btn.setCheckable(True)
|
|
self.add_path_btn.clicked.connect(self.toggle_add_path_mode)
|
|
|
|
self.complete_path_btn = QPushButton("完成路径")
|
|
self.complete_path_btn.clicked.connect(self.complete_path)
|
|
self.complete_path_btn.setEnabled(False)
|
|
|
|
self.clear_paths_btn = QPushButton("清除所有路径")
|
|
self.clear_paths_btn.clicked.connect(self.clear_all_paths)
|
|
|
|
path_control_layout.addWidget(self.add_path_btn)
|
|
path_control_layout.addWidget(self.complete_path_btn)
|
|
path_control_layout.addWidget(self.clear_paths_btn)
|
|
|
|
# 将按钮添加到主布局
|
|
layout = self.layout()
|
|
if layout:
|
|
layout.addLayout(path_control_layout)
|
|
else:
|
|
print("Error: Layout not found in PathLayerView")
|
|
|
|
def toggle_add_path_mode(self):
|
|
self.add_path_mode = self.add_path_btn.isChecked()
|
|
if self.add_path_mode:
|
|
self.add_path_btn.setText("取消添加点")
|
|
self.complete_path_btn.setEnabled(bool(self.current_path))
|
|
else:
|
|
self.add_path_btn.setText("添加路径点")
|
|
self.complete_path_btn.setEnabled(False)
|
|
|
|
def complete_path(self):
|
|
if len(self.current_path) > 1:
|
|
# Add a copy to the main data model
|
|
self.map_data_model.paths.append(list(self.current_path))
|
|
self.map_data_model.data_changed.emit()
|
|
self.current_path = []
|
|
self.add_path_mode = False
|
|
self.add_path_btn.setChecked(False)
|
|
self.add_path_btn.setText("添加路径点")
|
|
self.complete_path_btn.setEnabled(False)
|
|
self.update_map()
|
|
|
|
def clear_all_paths(self):
|
|
self.current_path = []
|
|
self.map_data_model.paths = []
|
|
self.map_data_model.data_changed.emit()
|
|
self.update_map()
|
|
|
|
def handle_map_click(self, map_point: QPointF):
|
|
"""Handles clicks forwarded from BaseMapView."""
|
|
if self.add_path_mode:
|
|
img_x = int(map_point.x())
|
|
img_y = int(map_point.y())
|
|
# 添加路径点到当前路径
|
|
self.current_path.append((img_x, img_y))
|
|
self.complete_path_btn.setEnabled(True)
|
|
|
|
print(f"Added path point: {img_x}, {img_y}")
|
|
# self.update_map()
|
|
|
|
# Remove the old mousePressEvent
|
|
# def mousePressEvent(self, event):
|
|
# pass |