使用maptools管理maptool
This commit is contained in:
@ -11,6 +11,7 @@
|
|||||||
#include "MapTool.h"
|
#include "MapTool.h"
|
||||||
#include "MapToolPan.h"
|
#include "MapToolPan.h"
|
||||||
#include "MapToolSpectral.h"
|
#include "MapToolSpectral.h"
|
||||||
|
#include "MapTools.h"
|
||||||
|
|
||||||
HPPA* HPPA::s_instance = nullptr;
|
HPPA* HPPA::s_instance = nullptr;
|
||||||
|
|
||||||
@ -89,8 +90,6 @@ HPPA::HPPA(QWidget* parent)
|
|||||||
ui.splitter->setStretchFactor(1, 1);
|
ui.splitter->setStretchFactor(1, 1);
|
||||||
ui.splitter->setStretchFactor(2, 3);*/
|
ui.splitter->setStretchFactor(2, 3);*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
initMenubarToolbar();
|
initMenubarToolbar();
|
||||||
initMapTools();
|
initMapTools();
|
||||||
//光谱仪操作
|
//光谱仪操作
|
||||||
@ -242,7 +241,6 @@ sizePolicy1.setHeightForWidth(graphicsView_delete->sizePolicy().hasHeightForWidt
|
|||||||
|
|
||||||
auto* g2 = m_LayerTreeModel->addGroup(m_LayerTreeModel->root(), "Vector");
|
auto* g2 = m_LayerTreeModel->addGroup(m_LayerTreeModel->root(), "Vector");
|
||||||
//model->addLayer(g2, "Rivers");
|
//model->addLayer(g2, "Rivers");
|
||||||
|
|
||||||
m_layerTreeView = new LayerTreeView();
|
m_layerTreeView = new LayerTreeView();
|
||||||
m_layerTreeView->setMenuProvider(new LayerTreeViewMenuProvider(m_layerTreeView));
|
m_layerTreeView->setMenuProvider(new LayerTreeViewMenuProvider(m_layerTreeView));
|
||||||
m_layerTreeView->setModel(m_LayerTreeModel);
|
m_layerTreeView->setModel(m_LayerTreeModel);
|
||||||
@ -1009,15 +1007,15 @@ void HPPA::initPanelToolbar()
|
|||||||
|
|
||||||
void HPPA::initMapTools()
|
void HPPA::initMapTools()
|
||||||
{
|
{
|
||||||
// Make the actions checkable
|
|
||||||
ui.mActionPan->setCheckable(true);
|
ui.mActionPan->setCheckable(true);
|
||||||
ui.mActionSpectral->setCheckable(true);
|
ui.mActionSpectral->setCheckable(true);
|
||||||
|
|
||||||
// Create tools (canvas will be set per-tab, tools are re-applied on tab switch)
|
m_mapTools = new MapTools(this);
|
||||||
// We don't create per-canvas tools here; instead we create shared tool instances
|
m_mapTools->mapToolPan()->setAction(ui.mActionPan);
|
||||||
// and re-apply them when the tab changes.
|
m_mapTools->mapToolSpectral()->setAction(ui.mActionSpectral);
|
||||||
m_mapToolPan = nullptr;
|
|
||||||
m_mapToolSpectral = nullptr;
|
connect(m_mapTools->mapToolSpectral(), SIGNAL(spectralClicked(int,int,QVector<double>,QVector<double>)),
|
||||||
|
this, SLOT(onLeftMouseButtonPressed(int,int,QVector<double>,QVector<double>)));
|
||||||
|
|
||||||
connect(ui.mActionPan, SIGNAL(triggered()), this, SLOT(onMapToolPanTriggered()));
|
connect(ui.mActionPan, SIGNAL(triggered()), this, SLOT(onMapToolPanTriggered()));
|
||||||
connect(ui.mActionSpectral, SIGNAL(triggered()), this, SLOT(onMapToolSpectralTriggered()));
|
connect(ui.mActionSpectral, SIGNAL(triggered()), this, SLOT(onMapToolSpectralTriggered()));
|
||||||
@ -1030,22 +1028,24 @@ void HPPA::onMapToolPanTriggered()
|
|||||||
{
|
{
|
||||||
// Find the current Mapcavas
|
// Find the current Mapcavas
|
||||||
QWidget* currentWidget = m_imageViewerTabWidget->currentWidget();
|
QWidget* currentWidget = m_imageViewerTabWidget->currentWidget();
|
||||||
if (!currentWidget) return;
|
if (!currentWidget)
|
||||||
|
{
|
||||||
|
ui.mActionPan->setChecked(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QList<Mapcavas*> canvases = currentWidget->findChildren<Mapcavas*>();
|
QList<Mapcavas*> canvases = currentWidget->findChildren<Mapcavas*>();
|
||||||
if (canvases.isEmpty()) return;
|
if (canvases.isEmpty()) return;
|
||||||
|
|
||||||
Mapcavas* canvas = canvases[0];
|
Mapcavas* canvas = canvases[0];
|
||||||
|
|
||||||
// Clean up old tool
|
// Set canvas on shared tool and activate
|
||||||
delete m_mapToolPan;
|
m_mapTools->setMapcavas(canvas);
|
||||||
m_mapToolPan = new MapToolPan(canvas, this);
|
|
||||||
m_mapToolPan->setAction(ui.mActionPan);
|
|
||||||
|
|
||||||
// Uncheck the other action
|
// Uncheck the other action
|
||||||
ui.mActionSpectral->setChecked(false);
|
ui.mActionSpectral->setChecked(false);
|
||||||
|
|
||||||
canvas->setMapTool(m_mapToolPan);
|
canvas->setMapTool(m_mapTools->mapToolPan());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HPPA::onMapToolSpectralTriggered()
|
void HPPA::onMapToolSpectralTriggered()
|
||||||
@ -1059,19 +1059,13 @@ void HPPA::onMapToolSpectralTriggered()
|
|||||||
|
|
||||||
Mapcavas* canvas = canvases[0];
|
Mapcavas* canvas = canvases[0];
|
||||||
|
|
||||||
// Clean up old tool
|
// Set canvas on shared tool and activate
|
||||||
delete m_mapToolSpectral;
|
m_mapTools->setMapcavas(canvas);
|
||||||
m_mapToolSpectral = new MapToolSpectral(canvas, this);
|
|
||||||
m_mapToolSpectral->setAction(ui.mActionSpectral);
|
|
||||||
|
|
||||||
// Uncheck the other action
|
// Uncheck the other action
|
||||||
ui.mActionPan->setChecked(false);
|
ui.mActionPan->setChecked(false);
|
||||||
|
|
||||||
// Connect spectral signal to existing slot
|
canvas->setMapTool(m_mapTools->mapToolSpectral());
|
||||||
connect(m_mapToolSpectral, SIGNAL(spectralClicked(int,int,QVector<double>,QVector<double>)),
|
|
||||||
this, SLOT(onLeftMouseButtonPressed(int,int,QVector<double>,QVector<double>)));
|
|
||||||
|
|
||||||
canvas->setMapTool(m_mapToolSpectral);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
@ -1353,21 +1347,15 @@ void HPPA::onTabWidgetCurrentChanged(int index)//代码新建一个tab,会调
|
|||||||
|
|
||||||
// Re-apply the current map tool to the new canvas
|
// Re-apply the current map tool to the new canvas
|
||||||
Mapcavas* canvas = currentImageViewer[0];
|
Mapcavas* canvas = currentImageViewer[0];
|
||||||
|
m_mapTools->setMapcavas(canvas);
|
||||||
|
|
||||||
if (ui.mActionPan->isChecked())
|
if (ui.mActionPan->isChecked())
|
||||||
{
|
{
|
||||||
delete m_mapToolPan;
|
canvas->setMapTool(m_mapTools->mapToolPan());
|
||||||
m_mapToolPan = new MapToolPan(canvas, this);
|
|
||||||
m_mapToolPan->setAction(ui.mActionPan);
|
|
||||||
canvas->setMapTool(m_mapToolPan);
|
|
||||||
}
|
}
|
||||||
else if (ui.mActionSpectral->isChecked())
|
else if (ui.mActionSpectral->isChecked())
|
||||||
{
|
{
|
||||||
delete m_mapToolSpectral;
|
canvas->setMapTool(m_mapTools->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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1932,9 +1920,9 @@ void HPPA::onPlotHyperspectralImageRgbImage(int fileNumber, int frameNumber, QSt
|
|||||||
//cv::imwrite(rgbFilePathStrech, rgbImageStretched);
|
//cv::imwrite(rgbFilePathStrech, rgbImageStretched);
|
||||||
|
|
||||||
//创建需要显示的图像--qt版本
|
//创建需要显示的图像--qt版本
|
||||||
//QRect CuttedRect = m_Imager->getRgbImage()->m_QRgbImage->rect();//先获取image整个rect
|
//QRect CuttedRect = m_Imager->getRgbImage()->m_matRgbImage->rect();//先获取image整个rect
|
||||||
//CuttedRect.setHeight(m_Imager->getFrameCounter() - 1);//裁剪rect
|
//CuttedRect.setHeight(m_Imager->getFrameCounter() - 1);//裁剪rect
|
||||||
//QImage CuttedImage = m_Imager->getRgbImage()->m_QRgbImage->copy(CuttedRect);
|
//QImage CuttedImage = m_Imager->getRgbImage()->m_matRgbImage->copy(CuttedRect);
|
||||||
|
|
||||||
//currentImageViewer[0]->SetImage(&QPixmap::fromImage(CuttedImage));//绘制图像
|
//currentImageViewer[0]->SetImage(&QPixmap::fromImage(CuttedImage));//绘制图像
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,6 +65,7 @@
|
|||||||
#include "MapTool.h"
|
#include "MapTool.h"
|
||||||
#include "MapToolPan.h"
|
#include "MapToolPan.h"
|
||||||
#include "MapToolSpectral.h"
|
#include "MapToolSpectral.h"
|
||||||
|
#include "MapTools.h"
|
||||||
|
|
||||||
#define PI 3.1415926
|
#define PI 3.1415926
|
||||||
|
|
||||||
@ -279,8 +280,7 @@ private:
|
|||||||
MapLayerStore* m_MapLayerStore = nullptr;
|
MapLayerStore* m_MapLayerStore = nullptr;
|
||||||
|
|
||||||
// Map tools
|
// Map tools
|
||||||
MapToolPan* m_mapToolPan = nullptr;
|
MapTools* m_mapTools = nullptr;
|
||||||
MapToolSpectral* m_mapToolSpectral = nullptr;
|
|
||||||
void initMapTools();
|
void initMapTools();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
|||||||
@ -126,6 +126,7 @@
|
|||||||
<ClCompile Include="MapLayerStore.cpp" />
|
<ClCompile Include="MapLayerStore.cpp" />
|
||||||
<ClCompile Include="MapTool.cpp" />
|
<ClCompile Include="MapTool.cpp" />
|
||||||
<ClCompile Include="MapToolPan.cpp" />
|
<ClCompile Include="MapToolPan.cpp" />
|
||||||
|
<ClCompile Include="MapTools.cpp" />
|
||||||
<ClCompile Include="MapToolSpectral.cpp" />
|
<ClCompile Include="MapToolSpectral.cpp" />
|
||||||
<ClCompile Include="OneMotorControl.cpp" />
|
<ClCompile Include="OneMotorControl.cpp" />
|
||||||
<ClCompile Include="path_tc.cpp" />
|
<ClCompile Include="path_tc.cpp" />
|
||||||
@ -211,6 +212,7 @@
|
|||||||
<QtMoc Include="MapTool.h" />
|
<QtMoc Include="MapTool.h" />
|
||||||
<QtMoc Include="MapToolPan.h" />
|
<QtMoc Include="MapToolPan.h" />
|
||||||
<QtMoc Include="MapToolSpectral.h" />
|
<QtMoc Include="MapToolSpectral.h" />
|
||||||
|
<QtMoc Include="MapTools.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" />
|
||||||
|
|||||||
@ -187,6 +187,9 @@
|
|||||||
<ClCompile Include="MapToolSpectral.cpp">
|
<ClCompile Include="MapToolSpectral.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="MapTools.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtMoc Include="fileOperation.h">
|
<QtMoc Include="fileOperation.h">
|
||||||
@ -300,6 +303,9 @@
|
|||||||
<QtMoc Include="MapTool.h">
|
<QtMoc Include="MapTool.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</QtMoc>
|
</QtMoc>
|
||||||
|
<QtMoc Include="MapTools.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</QtMoc>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="imageProcessor.h">
|
<ClInclude Include="imageProcessor.h">
|
||||||
|
|||||||
@ -3,9 +3,8 @@
|
|||||||
#include "ImageViewer.h"
|
#include "ImageViewer.h"
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
|
||||||
MapTool::MapTool(Mapcavas* canvas, QObject* parent)
|
MapTool::MapTool(QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_canvas(canvas)
|
|
||||||
, m_cursor(Qt::ArrowCursor)
|
, m_cursor(Qt::ArrowCursor)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -28,6 +27,19 @@ void MapTool::setAction(QAction* action)
|
|||||||
m_action = action;
|
m_action = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapTool::setMapcavas(Mapcavas* canvas)
|
||||||
|
{
|
||||||
|
if (m_canvas == canvas)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m_isActive && m_canvas)
|
||||||
|
{
|
||||||
|
deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_canvas = canvas;
|
||||||
|
}
|
||||||
|
|
||||||
Mapcavas* MapTool::canvas() const
|
Mapcavas* MapTool::canvas() const
|
||||||
{
|
{
|
||||||
return m_canvas;
|
return m_canvas;
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QCursor>
|
#include <QCursor>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QAction>
|
||||||
|
|
||||||
class Mapcavas;
|
class Mapcavas;
|
||||||
class QAction;
|
class QAction;
|
||||||
@ -20,7 +21,7 @@ public:
|
|||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(Flags, Flag)
|
Q_DECLARE_FLAGS(Flags, Flag)
|
||||||
|
|
||||||
MapTool(Mapcavas* canvas, QObject* parent = nullptr);
|
MapTool(QObject* parent = nullptr);
|
||||||
virtual ~MapTool();
|
virtual ~MapTool();
|
||||||
|
|
||||||
virtual Flags flags() const { return NoFlags; }
|
virtual Flags flags() const { return NoFlags; }
|
||||||
@ -28,6 +29,7 @@ public:
|
|||||||
QAction* action() const;
|
QAction* action() const;
|
||||||
void setAction(QAction* action);
|
void setAction(QAction* action);
|
||||||
|
|
||||||
|
void setMapcavas(Mapcavas* canvas);
|
||||||
Mapcavas* canvas() const;
|
Mapcavas* canvas() const;
|
||||||
|
|
||||||
virtual void setCursor(const QCursor& cursor);
|
virtual void setCursor(const QCursor& cursor);
|
||||||
@ -47,8 +49,10 @@ signals:
|
|||||||
void activated();
|
void activated();
|
||||||
void deactivated();
|
void deactivated();
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
Mapcavas* m_canvas = nullptr;
|
Mapcavas* m_canvas = nullptr;
|
||||||
|
|
||||||
|
private:
|
||||||
QAction* m_action = nullptr;
|
QAction* m_action = nullptr;
|
||||||
QCursor m_cursor;
|
QCursor m_cursor;
|
||||||
bool m_isActive = false;
|
bool m_isActive = false;
|
||||||
|
|||||||
@ -4,8 +4,8 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
|
|
||||||
MapToolPan::MapToolPan(Mapcavas* canvas, QObject* parent)
|
MapToolPan::MapToolPan(QObject* parent)
|
||||||
: MapTool(canvas, parent)
|
: MapTool(parent)
|
||||||
{
|
{
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ class MapToolPan : public MapTool
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MapToolPan(Mapcavas* canvas, QObject* parent = nullptr);
|
MapToolPan(QObject* parent = nullptr);
|
||||||
~MapToolPan();
|
~MapToolPan();
|
||||||
|
|
||||||
void activate() override;
|
void activate() override;
|
||||||
|
|||||||
@ -5,8 +5,8 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
MapToolSpectral::MapToolSpectral(Mapcavas* canvas, QObject* parent)
|
MapToolSpectral::MapToolSpectral(QObject* parent)
|
||||||
: MapTool(canvas, parent)
|
: MapTool(parent)
|
||||||
{
|
{
|
||||||
setCursor(Qt::CrossCursor);
|
setCursor(Qt::CrossCursor);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ class MapToolSpectral : public MapTool
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MapToolSpectral(Mapcavas* canvas, QObject* parent = nullptr);
|
MapToolSpectral(QObject* parent = nullptr);
|
||||||
~MapToolSpectral();
|
~MapToolSpectral();
|
||||||
|
|
||||||
void canvasMousePressEvent(QMouseEvent* e) override;
|
void canvasMousePressEvent(QMouseEvent* e) override;
|
||||||
|
|||||||
44
HPPA/MapTools.cpp
Normal file
44
HPPA/MapTools.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include "stdafx.h"
|
||||||
|
#include "MapTools.h"
|
||||||
|
#include "MapToolPan.h"
|
||||||
|
#include "MapToolSpectral.h"
|
||||||
|
|
||||||
|
MapTools::MapTools(QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
m_mapToolPan = new MapToolPan(this);
|
||||||
|
m_mapToolSpectral = new MapToolSpectral(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
MapTools::~MapTools()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MapToolPan* MapTools::mapToolPan() const
|
||||||
|
{
|
||||||
|
return m_mapToolPan;
|
||||||
|
}
|
||||||
|
|
||||||
|
MapToolSpectral* MapTools::mapToolSpectral() const
|
||||||
|
{
|
||||||
|
return m_mapToolSpectral;
|
||||||
|
}
|
||||||
|
|
||||||
|
MapTool* MapTools::mapTool(Tool tool) const
|
||||||
|
{
|
||||||
|
switch (tool)
|
||||||
|
{
|
||||||
|
case Pan:
|
||||||
|
return m_mapToolPan;
|
||||||
|
case Spectral:
|
||||||
|
return m_mapToolSpectral;
|
||||||
|
default:
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapTools::setMapcavas(Mapcavas* canvas)
|
||||||
|
{
|
||||||
|
m_mapToolPan->setMapcavas(canvas);
|
||||||
|
m_mapToolSpectral->setMapcavas(canvas);
|
||||||
|
}
|
||||||
37
HPPA/MapTools.h
Normal file
37
HPPA/MapTools.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef MAPTOOLS_H
|
||||||
|
#define MAPTOOLS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class MapTool;
|
||||||
|
class MapToolPan;
|
||||||
|
class MapToolSpectral;
|
||||||
|
class Mapcavas;
|
||||||
|
|
||||||
|
class MapTools : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum Tool
|
||||||
|
{
|
||||||
|
Pan,
|
||||||
|
Spectral,
|
||||||
|
};
|
||||||
|
|
||||||
|
MapTools(QObject* parent = nullptr);
|
||||||
|
~MapTools();
|
||||||
|
|
||||||
|
MapToolPan* mapToolPan() const;
|
||||||
|
MapToolSpectral* mapToolSpectral() const;
|
||||||
|
|
||||||
|
MapTool* mapTool(Tool tool) const;
|
||||||
|
|
||||||
|
void setMapcavas(Mapcavas* canvas);
|
||||||
|
|
||||||
|
private:
|
||||||
|
MapToolPan* m_mapToolPan = nullptr;
|
||||||
|
MapToolSpectral* m_mapToolSpectral = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MAPTOOLS_H
|
||||||
Reference in New Issue
Block a user