maptool:

报错,没实现;
This commit is contained in:
tangchao0503
2026-03-11 18:09:38 +08:00
parent ece7a34bfb
commit 0b2744656b
12 changed files with 517 additions and 9 deletions

View File

@ -7,6 +7,7 @@
#include "ImageViewer.h"
#include "RasterLayer.h"
#include "MapTool.h"
#define VIEW_CENTER viewport()->rect().center()
@ -105,6 +106,12 @@ bool Mapcavas::HasImage()
void Mapcavas::wheelEvent(QWheelEvent *event)
{
// Always let the tool have a chance first
if (m_mapTool)
{
m_mapTool->canvasWheelEvent(event);
}
if (HasImage())
{
QPointF oldPos = mapToScene(event->pos());
@ -126,6 +133,13 @@ void Mapcavas::scaling(qreal scaleFactor)
void Mapcavas::mousePressEvent(QMouseEvent *event)
{
if (m_mapTool)
{
m_mapTool->canvasMousePressEvent(event);
return;
}
// Legacy fallback when no tool is set
if (event->button()==Qt::LeftButton)
{
m_bMouseTranslate = true;
@ -150,6 +164,13 @@ void Mapcavas::mousePressEvent(QMouseEvent *event)
void Mapcavas::mouseMoveEvent(QMouseEvent *event)
{
if (m_mapTool)
{
m_mapTool->canvasMouseMoveEvent(event);
return;
}
// Legacy fallback
if (m_bMouseTranslate){
QPointF mouseDelta = mapToScene(event->pos()) - mapToScene(m_lastMousePos);
translate(mouseDelta.x(),mouseDelta.y());
@ -161,12 +182,25 @@ void Mapcavas::mouseMoveEvent(QMouseEvent *event)
void Mapcavas::mouseReleaseEvent(QMouseEvent *event)
{
if (m_mapTool)
{
m_mapTool->canvasMouseReleaseEvent(event);
return;
}
// Legacy fallback
m_bMouseTranslate = false;
QGraphicsView::mouseReleaseEvent(event);
}
void Mapcavas::mouseDoubleClickEvent(QMouseEvent *event)
{
if (m_mapTool)
{
m_mapTool->canvasMouseDoubleClickEvent(event);
return;
}
QGraphicsView::mouseDoubleClickEvent(event);
}
@ -248,3 +282,41 @@ void Mapcavas::freshmap(const RasterLayer::RenderParams& params)
QPixmap pm = QPixmap::fromImage(img);
SetImage(&pm);
}
// MapTool management
void Mapcavas::setMapTool(MapTool* tool)
{
if (m_mapTool)
{
m_mapTool->deactivate();
}
m_mapTool = tool;
if (m_mapTool)
{
// Disable built-in drag mode so the tool controls everything
setDragMode(QGraphicsView::NoDrag);
m_mapTool->activate();
}
else
{
// Restore legacy drag mode when no tool
setDragMode(QGraphicsView::ScrollHandDrag);
}
}
void Mapcavas::unsetMapTool(MapTool* tool)
{
if (m_mapTool && m_mapTool == tool)
{
m_mapTool->deactivate();
m_mapTool = nullptr;
setDragMode(QGraphicsView::ScrollHandDrag);
}
}
MapTool* Mapcavas::mapTool() const
{
return m_mapTool;
}