修复点击显示光谱功能的问题:打开一副影像后,点击显示光谱出现十字架,然后移除图层后,再打开图层就会出现问题
This commit is contained in:
@ -1570,16 +1570,7 @@ void HPPA::onOpenImg()
|
|||||||
QFileInfo fi(uri);
|
QFileInfo fi(uri);
|
||||||
QString baseName = fi.completeBaseName();
|
QString baseName = fi.completeBaseName();
|
||||||
|
|
||||||
RasterLayer* rl = new RasterLayer(baseName, uri);
|
addLayer(baseName, uri, true);
|
||||||
|
|
||||||
auto* layerNode = new LayerTreeLayer(rl);
|
|
||||||
m_LayerTreeModel->addLayer(m_RasterGroup, layerNode);
|
|
||||||
|
|
||||||
QWidget* mapcavasContainer = onCreateTab(baseName);
|
|
||||||
if (m_MapLayerStore) m_MapLayerStore->addLayer(rl, mapcavasContainer);
|
|
||||||
QList<Mapcavas*> mapcavas = mapcavasContainer->findChildren<Mapcavas*>();
|
|
||||||
mapcavas[0]->setLayers(rl);
|
|
||||||
mapcavas[0]->freshmap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HPPA::onconnect()
|
void HPPA::onconnect()
|
||||||
@ -2025,23 +2016,26 @@ void WorkerThread3::run()
|
|||||||
void HPPA::onLayerCreatedFromFile(const QString& baseName, const QString& filePath, int fileIndex)
|
void HPPA::onLayerCreatedFromFile(const QString& baseName, const QString& filePath, int fileIndex)
|
||||||
{
|
{
|
||||||
if (!m_LayerTreeModel || !m_RasterGroup) return;
|
if (!m_LayerTreeModel || !m_RasterGroup) return;
|
||||||
|
addLayer(baseName, filePath, false);
|
||||||
|
}
|
||||||
|
|
||||||
QWidget* mapcavasContainer = onCreateTab(baseName);
|
void HPPA::addLayer(const QString& baseName, const QString& filePath,bool refresh)
|
||||||
|
{
|
||||||
// Create MapLayer first and attach it to a LayerTreeLayerNode
|
// Create MapLayer first and attach it to a LayerTreeLayerNode
|
||||||
RasterLayer* ml = new RasterLayer(baseName, filePath);
|
RasterLayer* ml = new RasterLayer(baseName, filePath);
|
||||||
|
|
||||||
|
auto* layerNode = new LayerTreeLayer(ml);
|
||||||
|
LayerTreeNode* node = m_LayerTreeModel->addLayer(m_RasterGroup, layerNode);
|
||||||
|
|
||||||
|
QWidget* mapcavasContainer = onCreateTab(baseName);
|
||||||
if (m_MapLayerStore) m_MapLayerStore->addLayer(ml, mapcavasContainer);
|
if (m_MapLayerStore) m_MapLayerStore->addLayer(ml, mapcavasContainer);
|
||||||
QList<Mapcavas*> mapcavas = mapcavasContainer->findChildren<Mapcavas*>();
|
QList<Mapcavas*> mapcavas = mapcavasContainer->findChildren<Mapcavas*>();
|
||||||
mapcavas[0]->setLayers(ml);
|
mapcavas[0]->setLayers(ml);
|
||||||
|
|
||||||
auto* layerNode = new LayerTreeLayer(ml);
|
if (refresh)
|
||||||
LayerTreeNode* node = m_LayerTreeModel->addLayer(m_RasterGroup, layerNode);
|
{
|
||||||
LayerTreeLayer* lnode = dynamic_cast<LayerTreeLayer*>(node);
|
mapcavas[0]->freshmap();
|
||||||
if (!lnode) return;
|
}
|
||||||
|
|
||||||
// layerNode already holds the MapLayer pointer from constructor
|
|
||||||
|
|
||||||
qDebug() << "LayerFileCreated -> created layer:" << baseName << "path:" << filePath << "index:" << fileIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HPPA::onLayerTreeSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
|
void HPPA::onLayerTreeSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
|
||||||
|
|||||||
@ -341,6 +341,7 @@ public Q_SLOTS:
|
|||||||
void onCreated3DModelPlantPhenotype();
|
void onCreated3DModelPlantPhenotype();
|
||||||
void onCreated3DModelOneMotor();
|
void onCreated3DModelOneMotor();
|
||||||
|
|
||||||
|
void addLayer(const QString& baseName, const QString& filePath, bool refresh);
|
||||||
void onLayerCreatedFromFile(const QString& baseName, const QString& filePath, int fileIndex);
|
void onLayerCreatedFromFile(const QString& baseName, const QString& filePath, int fileIndex);
|
||||||
void removeLayerByTreeIndex();
|
void removeLayerByTreeIndex();
|
||||||
void removeAllLayersInRasterGroup();
|
void removeAllLayersInRasterGroup();
|
||||||
|
|||||||
@ -103,6 +103,50 @@ bool Mapcavas::HasImage()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mapcavas::updateCrosshair(double sceneX, double sceneY)
|
||||||
|
{
|
||||||
|
QPen pen(Qt::red, 2.0);
|
||||||
|
pen.setCosmetic(true); // constant screen-width regardless of zoom
|
||||||
|
|
||||||
|
if (!m_hLine)
|
||||||
|
{
|
||||||
|
m_hLine = m_qtGraphicsScene->addLine(0, 0, 0, 0, pen);
|
||||||
|
m_hLine->setZValue(1e9);
|
||||||
|
}
|
||||||
|
if (!m_vLine)
|
||||||
|
{
|
||||||
|
m_vLine = m_qtGraphicsScene->addLine(0, 0, 0, 0, pen);
|
||||||
|
m_vLine->setZValue(1e9);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_hLine->setPen(pen);
|
||||||
|
m_vLine->setPen(pen);
|
||||||
|
|
||||||
|
m_hLine->setLine(sceneX - m_CrosshairHalfLen, sceneY,
|
||||||
|
sceneX + m_CrosshairHalfLen, sceneY);
|
||||||
|
m_vLine->setLine(sceneX, sceneY - m_CrosshairHalfLen,
|
||||||
|
sceneX, sceneY + m_CrosshairHalfLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mapcavas::removeCrosshair()
|
||||||
|
{
|
||||||
|
if (m_hLine)
|
||||||
|
{
|
||||||
|
if (m_hLine->scene())
|
||||||
|
m_hLine->scene()->removeItem(m_hLine);
|
||||||
|
delete m_hLine;
|
||||||
|
m_hLine = nullptr;
|
||||||
|
}
|
||||||
|
if (m_vLine)
|
||||||
|
{
|
||||||
|
if (m_vLine->scene())
|
||||||
|
m_vLine->scene()->removeItem(m_vLine);
|
||||||
|
delete m_vLine;
|
||||||
|
m_vLine = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Mapcavas::wheelEvent(QWheelEvent *event)
|
void Mapcavas::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
// Always let the tool have a chance first
|
// Always let the tool have a chance first
|
||||||
|
|||||||
@ -29,6 +29,9 @@ public:
|
|||||||
bool HasImage();
|
bool HasImage();
|
||||||
void ensureSceneVisible();
|
void ensureSceneVisible();
|
||||||
|
|
||||||
|
void updateCrosshair(double sceneX, double sceneY);
|
||||||
|
void removeCrosshair();
|
||||||
|
|
||||||
void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
|
void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
|
||||||
void scaling(qreal scaleFactor);
|
void scaling(qreal scaleFactor);
|
||||||
|
|
||||||
@ -71,6 +74,10 @@ private:
|
|||||||
QPoint m_lastMousePos; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>λ<EFBFBD><CEBB>
|
QPoint m_lastMousePos; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>λ<EFBFBD><CEBB>
|
||||||
qreal m_scale; // <20><><EFBFBD><EFBFBD>ֵ
|
qreal m_scale; // <20><><EFBFBD><EFBFBD>ֵ
|
||||||
|
|
||||||
|
double m_CrosshairHalfLen = 10.0;
|
||||||
|
QGraphicsLineItem* m_hLine = nullptr; // horizontal line
|
||||||
|
QGraphicsLineItem* m_vLine = nullptr; // vertical line
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void leftMouseButtonPressed(int, int, QVector<double>, QVector<double>);
|
void leftMouseButtonPressed(int, int, QVector<double>, QVector<double>);
|
||||||
|
|||||||
@ -34,7 +34,7 @@ void MapTool::setMapcavas(Mapcavas* canvas)
|
|||||||
|
|
||||||
if (m_isActive && m_canvas)
|
if (m_isActive && m_canvas)
|
||||||
{
|
{
|
||||||
deactivate();
|
//deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_canvas = canvas;
|
m_canvas = canvas;
|
||||||
|
|||||||
@ -8,8 +8,6 @@
|
|||||||
#include <QPen>
|
#include <QPen>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
const double MapToolSpectral::CrosshairHalfLen = 10.0;
|
|
||||||
|
|
||||||
MapToolSpectral::MapToolSpectral(QObject* parent)
|
MapToolSpectral::MapToolSpectral(QObject* parent)
|
||||||
: MapTool(parent)
|
: MapTool(parent)
|
||||||
{
|
{
|
||||||
@ -18,7 +16,6 @@ MapToolSpectral::MapToolSpectral(QObject* parent)
|
|||||||
|
|
||||||
MapToolSpectral::~MapToolSpectral()
|
MapToolSpectral::~MapToolSpectral()
|
||||||
{
|
{
|
||||||
//removeCrosshair();//不需要在析构函数中调用removeCrosshair(),因为当MapToolSpectral被销毁时,它的canvas()也会被销毁,crosshair的scene也会被销毁,所以crosshair会自动被删除,不会造成内存泄漏。
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapToolSpectral::activate()
|
void MapToolSpectral::activate()
|
||||||
@ -28,7 +25,7 @@ void MapToolSpectral::activate()
|
|||||||
|
|
||||||
void MapToolSpectral::deactivate()
|
void MapToolSpectral::deactivate()
|
||||||
{
|
{
|
||||||
removeCrosshair();
|
canvas()->removeCrosshair();
|
||||||
MapTool::deactivate();
|
MapTool::deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +45,7 @@ void MapToolSpectral::canvasMousePressEvent(QMouseEvent* e)
|
|||||||
if (rl && rl->isValidPixel(x, y))
|
if (rl && rl->isValidPixel(x, y))
|
||||||
{
|
{
|
||||||
// Place crosshair at pixel center
|
// Place crosshair at pixel center
|
||||||
updateCrosshair(x + 0.5, y + 0.5);
|
canvas()->updateCrosshair(x + 0.5, y + 0.5);
|
||||||
|
|
||||||
QVector<double> wavelengths;
|
QVector<double> wavelengths;
|
||||||
QVector<double> spectrum;
|
QVector<double> spectrum;
|
||||||
@ -58,51 +55,3 @@ void MapToolSpectral::canvasMousePressEvent(QMouseEvent* e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapToolSpectral::updateCrosshair(double sceneX, double sceneY)
|
|
||||||
{
|
|
||||||
if (!canvas() || !canvas()->scene())
|
|
||||||
return;
|
|
||||||
|
|
||||||
QGraphicsScene* scene = canvas()->scene();
|
|
||||||
|
|
||||||
QPen pen(Qt::red, 2.0);
|
|
||||||
pen.setCosmetic(true); // constant screen-width regardless of zoom
|
|
||||||
|
|
||||||
if (!m_hLine)
|
|
||||||
{
|
|
||||||
m_hLine = scene->addLine(0, 0, 0, 0, pen);
|
|
||||||
m_hLine->setZValue(1e9);
|
|
||||||
}
|
|
||||||
if (!m_vLine)
|
|
||||||
{
|
|
||||||
m_vLine = scene->addLine(0, 0, 0, 0, pen);
|
|
||||||
m_vLine->setZValue(1e9);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_hLine->setPen(pen);
|
|
||||||
m_vLine->setPen(pen);
|
|
||||||
|
|
||||||
m_hLine->setLine(sceneX - CrosshairHalfLen, sceneY,
|
|
||||||
sceneX + CrosshairHalfLen, sceneY);
|
|
||||||
m_vLine->setLine(sceneX, sceneY - CrosshairHalfLen,
|
|
||||||
sceneX, sceneY + CrosshairHalfLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MapToolSpectral::removeCrosshair()
|
|
||||||
{
|
|
||||||
if (m_hLine)
|
|
||||||
{
|
|
||||||
if (m_hLine->scene())
|
|
||||||
m_hLine->scene()->removeItem(m_hLine);
|
|
||||||
delete m_hLine;
|
|
||||||
m_hLine = nullptr;
|
|
||||||
}
|
|
||||||
if (m_vLine)
|
|
||||||
{
|
|
||||||
if (m_vLine->scene())
|
|
||||||
m_vLine->scene()->removeItem(m_vLine);
|
|
||||||
delete m_vLine;
|
|
||||||
m_vLine = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -23,13 +23,6 @@ signals:
|
|||||||
void spectralClicked(int x, int y, QVector<double> wavelengths, QVector<double> spectrum);
|
void spectralClicked(int x, int y, QVector<double> wavelengths, QVector<double> spectrum);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateCrosshair(double sceneX, double sceneY);
|
|
||||||
void removeCrosshair();
|
|
||||||
|
|
||||||
QGraphicsLineItem* m_hLine = nullptr; // horizontal line
|
|
||||||
QGraphicsLineItem* m_vLine = nullptr; // vertical line
|
|
||||||
|
|
||||||
static const double CrosshairHalfLen;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAPTOOLSPECTRAL_H
|
#endif // MAPTOOLSPECTRAL_H
|
||||||
|
|||||||
Reference in New Issue
Block a user