完成maptool的功能:

1、工具在工具栏中的状态管理;
2、工具在mapcavas中的图标管理;
3、工具在多tab切换时的管理;
4、MapToolSpectral添加十字叉,显示点击位置;
This commit is contained in:
tangchao0503
2026-03-13 11:12:00 +08:00
parent 741e0e6734
commit 1c7780eb14
7 changed files with 142 additions and 99 deletions

View File

@ -45,7 +45,6 @@ Mapcavas::Mapcavas(QWidget* pParent) :QGraphicsView(pParent)
m_translateSpeed = 1.0;
m_bMouseTranslate = false;
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFrameShape(QFrame::NoFrame);
@ -136,29 +135,9 @@ void Mapcavas::mousePressEvent(QMouseEvent *event)
if (m_mapTool)
{
m_mapTool->canvasMousePressEvent(event);
QGraphicsView::mousePressEvent(event);
return;
}
// Legacy fallback when no tool is set
if (event->button()==Qt::LeftButton)
{
m_bMouseTranslate = true;
m_lastMousePos = event->pos();
const QPointF scenePt = mapToScene(m_lastMousePos);
const int x = static_cast<int>(std::floor(scenePt.x()));
const int y = static_cast<int>(std::floor(scenePt.y()));
if (m_rasterLayer && m_rasterLayer->isValidPixel(x, y))
{
QVector<double> wavelengths;
QVector<double> spectrum;
if (m_rasterLayer->readPixelSpectrum(x, y, wavelengths, spectrum))
{
emit leftMouseButtonPressed(x, y, wavelengths, spectrum);
}
}
}
QGraphicsView::mousePressEvent(event);
}
@ -167,16 +146,10 @@ void Mapcavas::mouseMoveEvent(QMouseEvent *event)
if (m_mapTool)
{
m_mapTool->canvasMouseMoveEvent(event);
QGraphicsView::mousePressEvent(event);
return;
}
// Legacy fallback
if (m_bMouseTranslate){
QPointF mouseDelta = mapToScene(event->pos()) - mapToScene(m_lastMousePos);
translate(mouseDelta.x(),mouseDelta.y());
}
m_lastMousePos = event->pos();
QGraphicsView::mousePressEvent(event);
}
@ -185,11 +158,10 @@ void Mapcavas::mouseReleaseEvent(QMouseEvent *event)
if (m_mapTool)
{
m_mapTool->canvasMouseReleaseEvent(event);
QGraphicsView::mouseReleaseEvent(event);
return;
}
// Legacy fallback
m_bMouseTranslate = false;
QGraphicsView::mouseReleaseEvent(event);
}