maptool:
报错,没实现;
This commit is contained in:
105
HPPA/HPPA.cpp
105
HPPA/HPPA.cpp
@ -8,6 +8,9 @@
|
|||||||
#include "HPPA.h"
|
#include "HPPA.h"
|
||||||
#include "RasterLayer.h"
|
#include "RasterLayer.h"
|
||||||
#include "LayerTreeLayerNode.h"
|
#include "LayerTreeLayerNode.h"
|
||||||
|
#include "MapTool.h"
|
||||||
|
#include "MapToolPan.h"
|
||||||
|
#include "MapToolSpectral.h"
|
||||||
|
|
||||||
HPPA* HPPA::s_instance = nullptr;
|
HPPA* HPPA::s_instance = nullptr;
|
||||||
|
|
||||||
@ -89,9 +92,7 @@ HPPA::HPPA(QWidget* parent)
|
|||||||
|
|
||||||
|
|
||||||
initMenubarToolbar();
|
initMenubarToolbar();
|
||||||
|
initMapTools();
|
||||||
|
|
||||||
|
|
||||||
//光谱仪操作
|
//光谱仪操作
|
||||||
m_Imager = nullptr;
|
m_Imager = nullptr;
|
||||||
m_RecordState = 0;
|
m_RecordState = 0;
|
||||||
@ -122,6 +123,7 @@ HPPA::HPPA(QWidget* parent)
|
|||||||
//connect(ui.graphicsView->imager, SIGNAL(leftMouseButtonPressed(int, int)), this, SLOT(onimagerSimulatorMove(int, int)));
|
//connect(ui.graphicsView->imager, SIGNAL(leftMouseButtonPressed(int, int)), this, SLOT(onimagerSimulatorMove(int, int)));
|
||||||
|
|
||||||
initPanelToolbar();
|
initPanelToolbar();
|
||||||
|
initMapTools();
|
||||||
setDockNestingEnabled(true);
|
setDockNestingEnabled(true);
|
||||||
connect(this->ui.action_about, SIGNAL(triggered()), this, SLOT(onAbout()));
|
connect(this->ui.action_about, SIGNAL(triggered()), this, SLOT(onAbout()));
|
||||||
connect(this->ui.mActionOneMotorScenario, SIGNAL(triggered()), this, SLOT(createOneMotorScenario()));
|
connect(this->ui.mActionOneMotorScenario, SIGNAL(triggered()), this, SLOT(createOneMotorScenario()));
|
||||||
@ -142,7 +144,6 @@ HPPA::HPPA(QWidget* parent)
|
|||||||
border-bottom-right-radius: 10px;
|
border-bottom-right-radius: 10px;
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
|
||||||
//TOC
|
//TOC
|
||||||
CustomDockWidgetBase* dock_layers = new CustomDockWidgetBase(QString::fromLocal8Bit("layers"), this);
|
CustomDockWidgetBase* dock_layers = new CustomDockWidgetBase(QString::fromLocal8Bit("layers"), this);
|
||||||
dock_layers->setObjectName("mDockLayers");
|
dock_layers->setObjectName("mDockLayers");
|
||||||
@ -819,7 +820,7 @@ void HPPA::createActionGroups()
|
|||||||
}
|
}
|
||||||
else if (lastSelectedAction == "mActionCorning_410")
|
else if (lastSelectedAction == "mActionCorning_410")
|
||||||
{
|
{
|
||||||
ui.mActionCorning_410->setChecked(true);
|
ui.mActionCorning_410->setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1006,6 +1007,73 @@ void HPPA::initPanelToolbar()
|
|||||||
mToolbarMenu->addAction(ui.mainToolBar->toggleViewAction());
|
mToolbarMenu->addAction(ui.mainToolBar->toggleViewAction());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HPPA::initMapTools()
|
||||||
|
{
|
||||||
|
// Make the actions checkable
|
||||||
|
ui.mActionPan->setCheckable(true);
|
||||||
|
ui.mActionSpectral->setCheckable(true);
|
||||||
|
|
||||||
|
// Create tools (canvas will be set per-tab, tools are re-applied on tab switch)
|
||||||
|
// We don't create per-canvas tools here; instead we create shared tool instances
|
||||||
|
// and re-apply them when the tab changes.
|
||||||
|
m_mapToolPan = nullptr;
|
||||||
|
m_mapToolSpectral = nullptr;
|
||||||
|
|
||||||
|
connect(ui.mActionPan, SIGNAL(triggered()), this, SLOT(onMapToolPanTriggered()));
|
||||||
|
connect(ui.mActionSpectral, SIGNAL(triggered()), this, SLOT(onMapToolSpectralTriggered()));
|
||||||
|
|
||||||
|
// Default tool: pan
|
||||||
|
ui.mActionPan->trigger();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HPPA::onMapToolPanTriggered()
|
||||||
|
{
|
||||||
|
// Find the current Mapcavas
|
||||||
|
QWidget* currentWidget = m_imageViewerTabWidget->currentWidget();
|
||||||
|
if (!currentWidget) return;
|
||||||
|
|
||||||
|
QList<Mapcavas*> canvases = currentWidget->findChildren<Mapcavas*>();
|
||||||
|
if (canvases.isEmpty()) return;
|
||||||
|
|
||||||
|
Mapcavas* canvas = canvases[0];
|
||||||
|
|
||||||
|
// Clean up old tool
|
||||||
|
delete m_mapToolPan;
|
||||||
|
m_mapToolPan = new MapToolPan(canvas, this);
|
||||||
|
m_mapToolPan->setAction(ui.mActionPan);
|
||||||
|
|
||||||
|
// Uncheck the other action
|
||||||
|
ui.mActionSpectral->setChecked(false);
|
||||||
|
|
||||||
|
canvas->setMapTool(m_mapToolPan);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HPPA::onMapToolSpectralTriggered()
|
||||||
|
{
|
||||||
|
// Find the current Mapcavas
|
||||||
|
QWidget* currentWidget = m_imageViewerTabWidget->currentWidget();
|
||||||
|
if (!currentWidget) return;
|
||||||
|
|
||||||
|
QList<Mapcavas*> canvases = currentWidget->findChildren<Mapcavas*>();
|
||||||
|
if (canvases.isEmpty()) return;
|
||||||
|
|
||||||
|
Mapcavas* canvas = canvases[0];
|
||||||
|
|
||||||
|
// Clean up old tool
|
||||||
|
delete m_mapToolSpectral;
|
||||||
|
m_mapToolSpectral = new MapToolSpectral(canvas, this);
|
||||||
|
m_mapToolSpectral->setAction(ui.mActionSpectral);
|
||||||
|
|
||||||
|
// Uncheck the other action
|
||||||
|
ui.mActionPan->setChecked(false);
|
||||||
|
|
||||||
|
// Connect spectral signal to existing slot
|
||||||
|
connect(m_mapToolSpectral, SIGNAL(spectralClicked(int,int,QVector<double>,QVector<double>)),
|
||||||
|
this, SLOT(onLeftMouseButtonPressed(int,int,QVector<double>,QVector<double>)));
|
||||||
|
|
||||||
|
canvas->setMapTool(m_mapToolSpectral);
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
void HPPA::createScenarioActionGroup()
|
void HPPA::createScenarioActionGroup()
|
||||||
{
|
{
|
||||||
@ -1282,6 +1350,25 @@ void HPPA::onTabWidgetCurrentChanged(int index)//代码新建一个tab,会调
|
|||||||
//先disconnect然后再connect,否则每次切换一次都会connect一次,会累积connect很多次!
|
//先disconnect然后再connect,否则每次切换一次都会connect一次,会累积connect很多次!
|
||||||
disconnect(currentImageViewer[0], SIGNAL(leftMouseButtonPressed(int,int,QVector<double>,QVector<double>)), this, SLOT(onLeftMouseButtonPressed(int,int,QVector<double>,QVector<double>)));
|
disconnect(currentImageViewer[0], SIGNAL(leftMouseButtonPressed(int,int,QVector<double>,QVector<double>)), this, SLOT(onLeftMouseButtonPressed(int,int,QVector<double>,QVector<double>)));
|
||||||
connect(currentImageViewer[0], SIGNAL(leftMouseButtonPressed(int,int,QVector<double>,QVector<double>)), this, SLOT(onLeftMouseButtonPressed(int,int,QVector<double>,QVector<double>)));
|
connect(currentImageViewer[0], SIGNAL(leftMouseButtonPressed(int,int,QVector<double>,QVector<double>)), this, SLOT(onLeftMouseButtonPressed(int,int,QVector<double>,QVector<double>)));
|
||||||
|
|
||||||
|
// Re-apply the current map tool to the new canvas
|
||||||
|
Mapcavas* canvas = currentImageViewer[0];
|
||||||
|
if (ui.mActionPan->isChecked())
|
||||||
|
{
|
||||||
|
delete m_mapToolPan;
|
||||||
|
m_mapToolPan = new MapToolPan(canvas, this);
|
||||||
|
m_mapToolPan->setAction(ui.mActionPan);
|
||||||
|
canvas->setMapTool(m_mapToolPan);
|
||||||
|
}
|
||||||
|
else if (ui.mActionSpectral->isChecked())
|
||||||
|
{
|
||||||
|
delete m_mapToolSpectral;
|
||||||
|
m_mapToolSpectral = new MapToolSpectral(canvas, this);
|
||||||
|
m_mapToolSpectral->setAction(ui.mActionSpectral);
|
||||||
|
connect(m_mapToolSpectral, SIGNAL(spectralClicked(int,int,QVector<double>,QVector<double>)),
|
||||||
|
this, SLOT(onLeftMouseButtonPressed(int,int,QVector<double>,QVector<double>)));
|
||||||
|
canvas->setMapTool(m_mapToolSpectral);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HPPA::onActionOpenDirectory()
|
void HPPA::onActionOpenDirectory()
|
||||||
@ -1564,10 +1651,10 @@ void HPPA::onconnect()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox;
|
||||||
msgBox.setText(QString::fromLocal8Bit("请选择相机!"));
|
msgBox.setText(QString::fromLocal8Bit("请选择相机!"));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Imager->moveToThread(m_RecordThread);
|
m_Imager->moveToThread(m_RecordThread);
|
||||||
@ -1758,7 +1845,7 @@ void HPPA::onDark()
|
|||||||
QString checkedName = checked->objectName();
|
QString checkedName = checked->objectName();
|
||||||
if (checkedName == "mAction_is_no_motor" || checkedName == "mAction_RobotArm")
|
if (checkedName == "mAction_is_no_motor" || checkedName == "mAction_RobotArm")
|
||||||
{
|
{
|
||||||
emit RecordDarlSignal();
|
emit RecordDarlSignal();
|
||||||
}
|
}
|
||||||
else if (checkedName == "mAction_1AxisMotor")
|
else if (checkedName == "mAction_1AxisMotor")
|
||||||
{
|
{
|
||||||
|
|||||||
12
HPPA/HPPA.h
12
HPPA/HPPA.h
@ -62,6 +62,10 @@
|
|||||||
#include "LayerTreeView.h"
|
#include "LayerTreeView.h"
|
||||||
#include "LayerTreeViewMenuProvider.h"
|
#include "LayerTreeViewMenuProvider.h"
|
||||||
|
|
||||||
|
#include "MapTool.h"
|
||||||
|
#include "MapToolPan.h"
|
||||||
|
#include "MapToolSpectral.h"
|
||||||
|
|
||||||
#define PI 3.1415926
|
#define PI 3.1415926
|
||||||
|
|
||||||
QT_CHARTS_USE_NAMESPACE//QChartView 使用 需要加宏, 否则无法使用
|
QT_CHARTS_USE_NAMESPACE//QChartView 使用 需要加宏, 否则无法使用
|
||||||
@ -274,6 +278,11 @@ private:
|
|||||||
|
|
||||||
MapLayerStore* m_MapLayerStore = nullptr;
|
MapLayerStore* m_MapLayerStore = nullptr;
|
||||||
|
|
||||||
|
// Map tools
|
||||||
|
MapToolPan* m_mapToolPan = nullptr;
|
||||||
|
MapToolSpectral* m_mapToolSpectral = nullptr;
|
||||||
|
void initMapTools();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void onPlotHyperspectralImageRgbImage(int fileNumber, int frameNumber, QString filePath);
|
void onPlotHyperspectralImageRgbImage(int fileNumber, int frameNumber, QString filePath);
|
||||||
void PlotSpectral(int state);
|
void PlotSpectral(int state);
|
||||||
@ -338,6 +347,9 @@ public Q_SLOTS:
|
|||||||
|
|
||||||
void onLayerTreeSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
|
void onLayerTreeSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
|
||||||
void onBandSelectionChanged(double rWave, double gWave, double bWave);
|
void onBandSelectionChanged(double rWave, double gWave, double bWave);
|
||||||
|
|
||||||
|
void onMapToolPanTriggered();
|
||||||
|
void onMapToolSpectralTriggered();
|
||||||
signals:
|
signals:
|
||||||
void StartFocusSignal();
|
void StartFocusSignal();
|
||||||
void StartRecordSignal();
|
void StartRecordSignal();
|
||||||
|
|||||||
@ -124,6 +124,9 @@
|
|||||||
<ClCompile Include="LayerTreeViewMenuProvider.cpp" />
|
<ClCompile Include="LayerTreeViewMenuProvider.cpp" />
|
||||||
<ClCompile Include="MapLayer.cpp" />
|
<ClCompile Include="MapLayer.cpp" />
|
||||||
<ClCompile Include="MapLayerStore.cpp" />
|
<ClCompile Include="MapLayerStore.cpp" />
|
||||||
|
<ClCompile Include="MapTool.cpp" />
|
||||||
|
<ClCompile Include="MapToolPan.cpp" />
|
||||||
|
<ClCompile Include="MapToolSpectral.cpp" />
|
||||||
<ClCompile Include="OneMotorControl.cpp" />
|
<ClCompile Include="OneMotorControl.cpp" />
|
||||||
<ClCompile Include="path_tc.cpp" />
|
<ClCompile Include="path_tc.cpp" />
|
||||||
<ClCompile Include="PowerControl.cpp" />
|
<ClCompile Include="PowerControl.cpp" />
|
||||||
@ -205,6 +208,9 @@
|
|||||||
<QtMoc Include="MapLayerStore.h" />
|
<QtMoc Include="MapLayerStore.h" />
|
||||||
<ClInclude Include="LayerTreeView.h" />
|
<ClInclude Include="LayerTreeView.h" />
|
||||||
<QtMoc Include="LayerTreeViewMenuProvider.h" />
|
<QtMoc Include="LayerTreeViewMenuProvider.h" />
|
||||||
|
<ClInclude Include="MapTool.h" />
|
||||||
|
<ClInclude Include="MapToolPan.h" />
|
||||||
|
<ClInclude Include="MapToolSpectral.h" />
|
||||||
<ClInclude Include="RasterDataProvider.h" />
|
<ClInclude Include="RasterDataProvider.h" />
|
||||||
<ClInclude Include="RasterRenderer.h" />
|
<ClInclude Include="RasterRenderer.h" />
|
||||||
<ClInclude Include="utility_tc.h" />
|
<ClInclude Include="utility_tc.h" />
|
||||||
|
|||||||
@ -178,6 +178,15 @@
|
|||||||
<ClCompile Include="imageControl.cpp">
|
<ClCompile Include="imageControl.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="MapTool.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="MapToolPan.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="MapToolSpectral.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtMoc Include="fileOperation.h">
|
<QtMoc Include="fileOperation.h">
|
||||||
@ -323,6 +332,15 @@
|
|||||||
<ClInclude Include="LayerTreeView.h">
|
<ClInclude Include="LayerTreeView.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="MapTool.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="MapToolPan.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="MapToolSpectral.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtUic Include="FocusDialog.ui">
|
<QtUic Include="FocusDialog.ui">
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "ImageViewer.h"
|
#include "ImageViewer.h"
|
||||||
#include "RasterLayer.h"
|
#include "RasterLayer.h"
|
||||||
|
#include "MapTool.h"
|
||||||
|
|
||||||
|
|
||||||
#define VIEW_CENTER viewport()->rect().center()
|
#define VIEW_CENTER viewport()->rect().center()
|
||||||
@ -105,6 +106,12 @@ bool Mapcavas::HasImage()
|
|||||||
|
|
||||||
void Mapcavas::wheelEvent(QWheelEvent *event)
|
void Mapcavas::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
|
// Always let the tool have a chance first
|
||||||
|
if (m_mapTool)
|
||||||
|
{
|
||||||
|
m_mapTool->canvasWheelEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
if (HasImage())
|
if (HasImage())
|
||||||
{
|
{
|
||||||
QPointF oldPos = mapToScene(event->pos());
|
QPointF oldPos = mapToScene(event->pos());
|
||||||
@ -126,6 +133,13 @@ void Mapcavas::scaling(qreal scaleFactor)
|
|||||||
|
|
||||||
void Mapcavas::mousePressEvent(QMouseEvent *event)
|
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)
|
if (event->button()==Qt::LeftButton)
|
||||||
{
|
{
|
||||||
m_bMouseTranslate = true;
|
m_bMouseTranslate = true;
|
||||||
@ -150,6 +164,13 @@ void Mapcavas::mousePressEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
void Mapcavas::mouseMoveEvent(QMouseEvent *event)
|
void Mapcavas::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
if (m_mapTool)
|
||||||
|
{
|
||||||
|
m_mapTool->canvasMouseMoveEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Legacy fallback
|
||||||
if (m_bMouseTranslate){
|
if (m_bMouseTranslate){
|
||||||
QPointF mouseDelta = mapToScene(event->pos()) - mapToScene(m_lastMousePos);
|
QPointF mouseDelta = mapToScene(event->pos()) - mapToScene(m_lastMousePos);
|
||||||
translate(mouseDelta.x(),mouseDelta.y());
|
translate(mouseDelta.x(),mouseDelta.y());
|
||||||
@ -161,12 +182,25 @@ void Mapcavas::mouseMoveEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
void Mapcavas::mouseReleaseEvent(QMouseEvent *event)
|
void Mapcavas::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
if (m_mapTool)
|
||||||
|
{
|
||||||
|
m_mapTool->canvasMouseReleaseEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Legacy fallback
|
||||||
m_bMouseTranslate = false;
|
m_bMouseTranslate = false;
|
||||||
QGraphicsView::mouseReleaseEvent(event);
|
QGraphicsView::mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mapcavas::mouseDoubleClickEvent(QMouseEvent *event)
|
void Mapcavas::mouseDoubleClickEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
|
if (m_mapTool)
|
||||||
|
{
|
||||||
|
m_mapTool->canvasMouseDoubleClickEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QGraphicsView::mouseDoubleClickEvent(event);
|
QGraphicsView::mouseDoubleClickEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,3 +282,41 @@ void Mapcavas::freshmap(const RasterLayer::RenderParams& params)
|
|||||||
QPixmap pm = QPixmap::fromImage(img);
|
QPixmap pm = QPixmap::fromImage(img);
|
||||||
SetImage(&pm);
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@ -6,6 +6,8 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include "RasterLayer.h"
|
#include "RasterLayer.h"
|
||||||
|
|
||||||
|
class MapTool;
|
||||||
|
|
||||||
class Mapcavas : public QGraphicsView
|
class Mapcavas : public QGraphicsView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -49,6 +51,11 @@ public:
|
|||||||
|
|
||||||
RasterLayer* rasterLayer() const;
|
RasterLayer* rasterLayer() const;
|
||||||
|
|
||||||
|
// MapTool management
|
||||||
|
void setMapTool(MapTool* tool);
|
||||||
|
void unsetMapTool(MapTool* tool);
|
||||||
|
MapTool* mapTool() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QGraphicsScene *m_qtGraphicsScene;
|
QGraphicsScene *m_qtGraphicsScene;
|
||||||
private:
|
private:
|
||||||
@ -56,6 +63,7 @@ private:
|
|||||||
QLabel *m_framNumberLabel;//<2F><>ʾʵʱ<CAB5>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>
|
QLabel *m_framNumberLabel;//<2F><>ʾʵʱ<CAB5>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>
|
||||||
|
|
||||||
RasterLayer* m_rasterLayer = nullptr; // associated raster layer
|
RasterLayer* m_rasterLayer = nullptr; // associated raster layer
|
||||||
|
MapTool* m_mapTool = nullptr; // current active map tool
|
||||||
|
|
||||||
qreal m_translateSpeed; // ƽ<><C6BD><EFBFBD>ٶ<EFBFBD>
|
qreal m_translateSpeed; // ƽ<><C6BD><EFBFBD>ٶ<EFBFBD>
|
||||||
qreal m_zoomDelta; // <20><><EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD>
|
qreal m_zoomDelta; // <20><><EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|||||||
98
HPPA/MapTool.cpp
Normal file
98
HPPA/MapTool.cpp
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#include "stdafx.h"
|
||||||
|
#include "MapTool.h"
|
||||||
|
#include "ImageViewer.h"
|
||||||
|
#include <QAction>
|
||||||
|
|
||||||
|
MapTool::MapTool(Mapcavas* canvas, QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_canvas(canvas)
|
||||||
|
, m_cursor(Qt::ArrowCursor)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MapTool::~MapTool()
|
||||||
|
{
|
||||||
|
if (m_canvas && m_canvas->mapTool() == this)
|
||||||
|
{
|
||||||
|
m_canvas->unsetMapTool(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction* MapTool::action() const
|
||||||
|
{
|
||||||
|
return m_action;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapTool::setAction(QAction* action)
|
||||||
|
{
|
||||||
|
m_action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mapcavas* MapTool::canvas() const
|
||||||
|
{
|
||||||
|
return m_canvas;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapTool::setCursor(const QCursor& cursor)
|
||||||
|
{
|
||||||
|
m_cursor = cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
QCursor MapTool::cursor() const
|
||||||
|
{
|
||||||
|
return m_cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapTool::activate()
|
||||||
|
{
|
||||||
|
if (m_canvas)
|
||||||
|
{
|
||||||
|
m_canvas->viewport()->setCursor(m_cursor);
|
||||||
|
}
|
||||||
|
if (m_action)
|
||||||
|
{
|
||||||
|
m_action->setChecked(true);
|
||||||
|
}
|
||||||
|
m_isActive = true;
|
||||||
|
emit activated();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapTool::deactivate()
|
||||||
|
{
|
||||||
|
if (m_action)
|
||||||
|
{
|
||||||
|
m_action->setChecked(false);
|
||||||
|
}
|
||||||
|
m_isActive = false;
|
||||||
|
emit deactivated();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MapTool::isActive() const
|
||||||
|
{
|
||||||
|
return m_isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapTool::canvasMousePressEvent(QMouseEvent* e)
|
||||||
|
{
|
||||||
|
Q_UNUSED(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapTool::canvasMouseReleaseEvent(QMouseEvent* e)
|
||||||
|
{
|
||||||
|
Q_UNUSED(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapTool::canvasMouseMoveEvent(QMouseEvent* e)
|
||||||
|
{
|
||||||
|
Q_UNUSED(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapTool::canvasMouseDoubleClickEvent(QMouseEvent* e)
|
||||||
|
{
|
||||||
|
Q_UNUSED(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapTool::canvasWheelEvent(QWheelEvent* e)
|
||||||
|
{
|
||||||
|
Q_UNUSED(e);
|
||||||
|
}
|
||||||
64
HPPA/MapTool.h
Normal file
64
HPPA/MapTool.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#ifndef MAPTOOL_H
|
||||||
|
#define MAPTOOL_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QCursor>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
class Mapcavas;
|
||||||
|
class QAction;
|
||||||
|
|
||||||
|
class MapTool : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum Flag
|
||||||
|
{
|
||||||
|
NoFlags = 0,
|
||||||
|
Transient = 1 << 1,
|
||||||
|
};
|
||||||
|
Q_DECLARE_FLAGS(Flags, Flag)
|
||||||
|
|
||||||
|
MapTool(Mapcavas* canvas, QObject* parent = nullptr);
|
||||||
|
virtual ~MapTool();
|
||||||
|
|
||||||
|
virtual Flags flags() const { return NoFlags; }
|
||||||
|
|
||||||
|
// Associated action <20>C used to auto-check / uncheck when tool is activated / deactivated
|
||||||
|
QAction* action() const;
|
||||||
|
void setAction(QAction* action);
|
||||||
|
|
||||||
|
// Canvas this tool operates on
|
||||||
|
Mapcavas* canvas() const;
|
||||||
|
|
||||||
|
// Cursor shown when tool is active
|
||||||
|
virtual void setCursor(const QCursor& cursor);
|
||||||
|
QCursor cursor() const;
|
||||||
|
|
||||||
|
// Lifecycle
|
||||||
|
virtual void activate();
|
||||||
|
virtual void deactivate();
|
||||||
|
bool isActive() const;
|
||||||
|
|
||||||
|
// Mouse event handlers <20>C return true if event was handled
|
||||||
|
virtual void canvasMousePressEvent(QMouseEvent* e);
|
||||||
|
virtual void canvasMouseReleaseEvent(QMouseEvent* e);
|
||||||
|
virtual void canvasMouseMoveEvent(QMouseEvent* e);
|
||||||
|
virtual void canvasMouseDoubleClickEvent(QMouseEvent* e);
|
||||||
|
virtual void canvasWheelEvent(QWheelEvent* e);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void activated();
|
||||||
|
void deactivated();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Mapcavas* m_canvas = nullptr;
|
||||||
|
QAction* m_action = nullptr;
|
||||||
|
QCursor m_cursor;
|
||||||
|
bool m_isActive = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(MapTool::Flags)
|
||||||
|
|
||||||
|
#endif // MAPTOOL_H
|
||||||
61
HPPA/MapToolPan.cpp
Normal file
61
HPPA/MapToolPan.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "stdafx.h"
|
||||||
|
#include "MapToolPan.h"
|
||||||
|
#include "ImageViewer.h"
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
|
||||||
|
MapToolPan::MapToolPan(Mapcavas* canvas, QObject* parent)
|
||||||
|
: MapTool(canvas, parent)
|
||||||
|
{
|
||||||
|
setCursor(Qt::OpenHandCursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapToolPan::activate()
|
||||||
|
{
|
||||||
|
MapTool::activate();
|
||||||
|
if (canvas())
|
||||||
|
{
|
||||||
|
canvas()->setDragMode(QGraphicsView::NoDrag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapToolPan::deactivate()
|
||||||
|
{
|
||||||
|
m_dragging = false;
|
||||||
|
MapTool::deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapToolPan::canvasMousePressEvent(QMouseEvent* e)
|
||||||
|
{
|
||||||
|
if (e->button() == Qt::LeftButton)
|
||||||
|
{
|
||||||
|
m_dragging = true;
|
||||||
|
m_lastPos = e->pos();
|
||||||
|
if (canvas())
|
||||||
|
{
|
||||||
|
canvas()->viewport()->setCursor(Qt::ClosedHandCursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapToolPan::canvasMouseMoveEvent(QMouseEvent* e)
|
||||||
|
{
|
||||||
|
if (m_dragging && canvas())
|
||||||
|
{
|
||||||
|
QPointF delta = canvas()->mapToScene(e->pos()) - canvas()->mapToScene(m_lastPos);
|
||||||
|
canvas()->translate(delta.x(), delta.y());
|
||||||
|
m_lastPos = e->pos();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapToolPan::canvasMouseReleaseEvent(QMouseEvent* e)
|
||||||
|
{
|
||||||
|
if (e->button() == Qt::LeftButton)
|
||||||
|
{
|
||||||
|
m_dragging = false;
|
||||||
|
if (canvas())
|
||||||
|
{
|
||||||
|
canvas()->viewport()->setCursor(Qt::OpenHandCursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
26
HPPA/MapToolPan.h
Normal file
26
HPPA/MapToolPan.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef MAPTOOLPAN_H
|
||||||
|
#define MAPTOOLPAN_H
|
||||||
|
|
||||||
|
#include "MapTool.h"
|
||||||
|
#include <QPoint>
|
||||||
|
|
||||||
|
class MapToolPan : public MapTool
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
MapToolPan(Mapcavas* canvas, QObject* parent = nullptr);
|
||||||
|
|
||||||
|
void activate() override;
|
||||||
|
void deactivate() override;
|
||||||
|
|
||||||
|
void canvasMousePressEvent(QMouseEvent* e) override;
|
||||||
|
void canvasMouseMoveEvent(QMouseEvent* e) override;
|
||||||
|
void canvasMouseReleaseEvent(QMouseEvent* e) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_dragging = false;
|
||||||
|
QPoint m_lastPos;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MAPTOOLPAN_H
|
||||||
36
HPPA/MapToolSpectral.cpp
Normal file
36
HPPA/MapToolSpectral.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include "stdafx.h"
|
||||||
|
#include "MapToolSpectral.h"
|
||||||
|
#include "ImageViewer.h"
|
||||||
|
#include "RasterLayer.h"
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
MapToolSpectral::MapToolSpectral(Mapcavas* canvas, QObject* parent)
|
||||||
|
: MapTool(canvas, parent)
|
||||||
|
{
|
||||||
|
setCursor(Qt::CrossCursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapToolSpectral::canvasMousePressEvent(QMouseEvent* e)
|
||||||
|
{
|
||||||
|
if (e->button() != Qt::LeftButton)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!canvas())
|
||||||
|
return;
|
||||||
|
|
||||||
|
const QPointF scenePt = canvas()->mapToScene(e->pos());
|
||||||
|
const int x = static_cast<int>(std::floor(scenePt.x()));
|
||||||
|
const int y = static_cast<int>(std::floor(scenePt.y()));
|
||||||
|
|
||||||
|
RasterLayer* rl = canvas()->rasterLayer();
|
||||||
|
if (rl && rl->isValidPixel(x, y))
|
||||||
|
{
|
||||||
|
QVector<double> wavelengths;
|
||||||
|
QVector<double> spectrum;
|
||||||
|
if (rl->readPixelSpectrum(x, y, wavelengths, spectrum))
|
||||||
|
{
|
||||||
|
emit spectralClicked(x, y, wavelengths, spectrum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
HPPA/MapToolSpectral.h
Normal file
20
HPPA/MapToolSpectral.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef MAPTOOLSPECTRAL_H
|
||||||
|
#define MAPTOOLSPECTRAL_H
|
||||||
|
|
||||||
|
#include "MapTool.h"
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
class MapToolSpectral : public MapTool
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
MapToolSpectral(Mapcavas* canvas, QObject* parent = nullptr);
|
||||||
|
|
||||||
|
void canvasMousePressEvent(QMouseEvent* e) override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void spectralClicked(int x, int y, QVector<double> wavelengths, QVector<double> spectrum);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MAPTOOLSPECTRAL_H
|
||||||
Reference in New Issue
Block a user