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.
project/Src/command_center/ui/simple_map_view.py

71 lines
3.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# -*- coding: utf-8 -*-
# File: simple_map_view.py
# Purpose: 定义地图视图标签页,继承自 BaseMapView主要负责威胁点的交互。
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton, QFileDialog
from PyQt5.QtGui import QPixmap, QPainter, QPen, QColor
from PyQt5.QtCore import Qt, pyqtSignal, QPointF
from .base_map_view import BaseMapView
class SimpleMapView(BaseMapView):
# 当威胁点变化时发出信号,便于主程序联动路径规划
threat_points_changed = pyqtSignal(list)
def __init__(self, map_data_model):
super().__init__(map_data_model)
self.add_threat_point_mode = False
self.init_additional_ui()
# Force re-connection of load map action in case it was overwritten
if hasattr(self, 'load_map_action'):
print("SimpleMapView: Forcing re-connection of load_map_action")
try:
self.load_map_action.triggered.disconnect()
except TypeError: # No connections exist
pass
self.load_map_action.triggered.connect(self.load_map_image)
else:
print("SimpleMapView: Warning - load_map_action not found in base class?")
def init_additional_ui(self):
# 添加威胁点标记按钮
self.threat_point_btn = QPushButton("标记威胁点")
self.threat_point_btn.setCheckable(True)
self.threat_point_btn.clicked.connect(self.toggle_threat_point_mode)
# 将按钮添加到布局中
layout = self.layout()
if layout:
layout.addWidget(self.threat_point_btn)
else:
print("Error: Layout not found in SimpleMapView") # Error handling
def toggle_threat_point_mode(self):
print("SimpleMapView: toggle_threat_point_mode called") # Debug print
is_checked = self.threat_point_btn.isChecked()
print(f"SimpleMapView: threat_point_btn isChecked: {is_checked}")
self.add_threat_point_mode = is_checked
print(f"SimpleMapView: self.add_threat_point_mode set to: {self.add_threat_point_mode}")
if self.add_threat_point_mode:
self.threat_point_btn.setText("取消标记")
else:
self.threat_point_btn.setText("标记威胁点")
def handle_map_click(self, map_point: QPointF):
"""Handles clicks forwarded from BaseMapView."""
print(f"SimpleMapView: handle_map_click called, mode: {self.add_threat_point_mode}") # Debug print
if self.add_threat_point_mode:
img_x = int(map_point.x())
img_y = int(map_point.y())
print(f"SimpleMapView: Adding threat point at ({img_x}, {img_y})") # Debug print
# 添加威胁点到数据模型
self.map_data_model.add_threat_point((img_x, img_y))
# Emit signal (optional, BaseMapView already emits on data change)
# self.threat_points_changed.emit(self.map_data_model.threat_points)
# Remove the old mousePressEvent if it exists
# def mousePressEvent(self, event): # <--- REMOVE THIS METHOD
# pass
# load_map_image and update_map are now handled by BaseMapView
# We might need specific update logic here in the future if SimpleMapView
# needs drawing beyond what BaseMapView provides.