感兴趣区全局应用

This commit is contained in:
anxinglong 2026-07-10 18:23:33 +08:00
parent ad111584f7
commit e83492e7a9
13 changed files with 356 additions and 82 deletions

View File

@ -62,6 +62,10 @@ TwoDSpectralCompliance::TwoDSpectralCompliance(QWidget* parent)
this->_plot = new CustomQwtPlot(this); this->_plot = new CustomQwtPlot(this);
layout->addWidget(this->_plot); layout->addWidget(this->_plot);
setupPlot(); setupPlot();
_roi = new RegionOfInterest();
connect(_roi, &RegionOfInterest::roiSelected,this, &TwoDSpectralCompliance::slot_roi_data);
createFloatingInfoWidget(); createFloatingInfoWidget();
_busy_indicator = new BusyIndicatorWidget(this); _busy_indicator = new BusyIndicatorWidget(this);
} }
@ -163,6 +167,10 @@ void TwoDSpectralCompliance::setupMenu()
QAction* action_plot_config = this->_menu->addAction(QStringLiteral(u"图表配置")); QAction* action_plot_config = this->_menu->addAction(QStringLiteral(u"图表配置"));
action_plot_config->setObjectName("plot_config"); action_plot_config->setObjectName("plot_config");
connect(action_plot_config, &QAction::triggered, this, &TwoDSpectralCompliance::onActionPlotConfigure); connect(action_plot_config, &QAction::triggered, this, &TwoDSpectralCompliance::onActionPlotConfigure);
QAction* action_roi = this->_menu->addAction(QStringLiteral(u"感兴趣区"));
action_roi->setObjectName("roi");
connect(action_roi,&QAction::triggered,this,&TwoDSpectralCompliance::onActionRoiTriggered);
} }
QVector<EventData> TwoDSpectralCompliance::readCsv(const QStringList& filename) QVector<EventData> TwoDSpectralCompliance::readCsv(const QStringList& filename)
@ -434,6 +442,18 @@ void TwoDSpectralCompliance::updateShowButtonPosition()
} }
} }
QwtPlotMarker *TwoDSpectralCompliance::createVLine(double x, Qt::GlobalColor color, double lineWidth)
{
QwtPlotMarker* marker = new QwtPlotMarker();
marker->setXValue(x);
marker->setLineStyle(QwtPlotMarker::VLine);
QPen pen(color);
pen.setWidthF(lineWidth);
marker->setLinePen(pen);
marker->attach(_plot);
return marker;
}
void TwoDSpectralCompliance::onSelection(const QRectF& rect) void TwoDSpectralCompliance::onSelection(const QRectF& rect)
{ {
// 忽略过小的选区(可能是误点击) // 忽略过小的选区(可能是误点击)
@ -472,6 +492,27 @@ void TwoDSpectralCompliance::onActionPlotConfigure()
} }
void TwoDSpectralCompliance::onActionRoiTriggered()
{
_roi->show();
}
void TwoDSpectralCompliance::slot_roi_data(ROIItem &item)
{
// 第一组起始1、结束1 红色竖线,必须存在才插入,所以一定绘制
createVLine(item.s1, Qt::red, 1.2);
createVLine(item.e1, Qt::red, 1.2);
// 第二组起始2、结束2 有有效数值才绘制,无值跳过
bool secondGroupValid = !(qIsNaN(item.s2) || qIsNaN(item.e2) || (item.s2 == 0 && item.e2 == 0));
if (secondGroupValid)
{
createVLine(item.s2, Qt::blue, 1.2);
createVLine(item.e2, Qt::blue, 1.2);
}
_plot->replot();
}
void TwoDSpectralCompliance:: updateInfoContent() void TwoDSpectralCompliance:: updateInfoContent()
{ {
if (!m_totalEventsEdit) if (!m_totalEventsEdit)

View File

@ -6,6 +6,7 @@
#include <QVector> #include <QVector>
#include <QWidget> #include <QWidget>
#include <QMenu> #include <QMenu>
#include "RegionOfInterest.h"
class CustomQwtPlot; class CustomQwtPlot;
class QwtPlotSpectrogram; class QwtPlotSpectrogram;
class QwtPlotPicker; class QwtPlotPicker;
@ -59,13 +60,15 @@ private:
void updateFloatingWidgetPosition(); void updateFloatingWidgetPosition();
void updateToggleButtonPosition(); void updateToggleButtonPosition();
void updateShowButtonPosition(); void updateShowButtonPosition();
QwtPlotMarker* createVLine(double x, Qt::GlobalColor color, double lineWidth = 1.0); // 创建垂直标记竖线
private slots: private slots:
void showFloatingWidget(); void showFloatingWidget();
void hideFloatingWidget(); void hideFloatingWidget();
void onSelection(const QRectF& rect); void onSelection(const QRectF& rect);
void onActionPlotConfigure(); void onActionPlotConfigure();
void onActionRoiTriggered();
void slot_roi_data(ROIItem& item);
private: private:
Ui::TwoDSpectralCompliance* ui; Ui::TwoDSpectralCompliance* ui;
QMenu* _menu = nullptr; QMenu* _menu = nullptr;
@ -107,6 +110,8 @@ private:
// 保存全局轴范围(用于重置放大) // 保存全局轴范围(用于重置放大)
double m_globalXMin = 0.0, m_globalXMax = 0.0; double m_globalXMin = 0.0, m_globalXMax = 0.0;
double m_globalYMin = 0.0, m_globalYMax = 0.0; double m_globalYMin = 0.0, m_globalYMax = 0.0;
RegionOfInterest *_roi;
}; };
#endif // TWODSPECTRALCOMPLIANCE_H #endif // TWODSPECTRALCOMPLIANCE_H

View File

@ -15,7 +15,7 @@
#include <cstdint> #include <cstdint>
#include <map> #include <map>
#include <vector> #include <vector>
//反符合能谱
AntiConformEnergySpectrumView::AntiConformEnergySpectrumView(QWidget* parent) AntiConformEnergySpectrumView::AntiConformEnergySpectrumView(QWidget* parent)
: MeasureAnalysisView(parent) : MeasureAnalysisView(parent)
{ {
@ -32,6 +32,8 @@ AntiConformEnergySpectrumView::AntiConformEnergySpectrumView(QWidget* parent)
QwtPlotCanvas* canvas = qobject_cast<QwtPlotCanvas*>(_plot->canvas()); QwtPlotCanvas* canvas = qobject_cast<QwtPlotCanvas*>(_plot->canvas());
canvas->setFrameStyle(QFrame::NoFrame); canvas->setFrameStyle(QFrame::NoFrame);
_roi = new RegionOfInterest();
connect(_roi, &RegionOfInterest::roiSelected,this, &AntiConformEnergySpectrumView::slot_roi_data);
QFont font = this->font(); QFont font = this->font();
font.setBold(false); font.setBold(false);
QwtText x_label = QStringLiteral(u"能量(KeV)"); QwtText x_label = QStringLiteral(u"能量(KeV)");
@ -74,6 +76,18 @@ void AntiConformEnergySpectrumView::SetAnalyzeDataFilename(const QMap<QString, Q
} }
} }
QwtPlotMarker *AntiConformEnergySpectrumView::createVLine(double x, Qt::GlobalColor color, double lineWidth)
{
QwtPlotMarker* marker = new QwtPlotMarker();
marker->setXValue(x);
marker->setLineStyle(QwtPlotMarker::VLine);
QPen pen(color);
pen.setWidthF(lineWidth);
marker->setLinePen(pen);
marker->attach(_plot);
return marker;
}
void AntiConformEnergySpectrumView::loadAndProcess() void AntiConformEnergySpectrumView::loadAndProcess()
{ {
_busy_indicator->Start(); _busy_indicator->Start();
@ -132,6 +146,29 @@ void AntiConformEnergySpectrumView::onActionPlotConfigure()
{ {
} }
void AntiConformEnergySpectrumView::onActionRoiTriggered()
{
_roi->show();
}
void AntiConformEnergySpectrumView::slot_roi_data(ROIItem &item)
{
// 第一组起始1、结束1 红色竖线,必须存在才插入,所以一定绘制
createVLine(item.s1, Qt::red, 1.2);
createVLine(item.e1, Qt::red, 1.2);
// 第二组起始2、结束2 有有效数值才绘制,无值跳过
bool secondGroupValid = !(qIsNaN(item.s2) || qIsNaN(item.e2) || (item.s2 == 0 && item.e2 == 0));
if (secondGroupValid)
{
createVLine(item.s2, Qt::blue, 1.2);
createVLine(item.e2, Qt::blue, 1.2);
}
_plot->replot();
}
void AntiConformEnergySpectrumView::showEvent(QShowEvent* e) void AntiConformEnergySpectrumView::showEvent(QShowEvent* e)
{ {
Q_UNUSED(e); Q_UNUSED(e);
@ -156,4 +193,8 @@ void AntiConformEnergySpectrumView::setupMenu()
QAction* action_plot_config = this->_menu->addAction(QStringLiteral(u"图表配置")); QAction* action_plot_config = this->_menu->addAction(QStringLiteral(u"图表配置"));
action_plot_config->setObjectName("plot_config"); action_plot_config->setObjectName("plot_config");
connect(action_plot_config, &QAction::triggered, this, &AntiConformEnergySpectrumView::onActionPlotConfigure); connect(action_plot_config, &QAction::triggered, this, &AntiConformEnergySpectrumView::onActionPlotConfigure);
QAction* action_roi = this->_menu->addAction(QStringLiteral(u"感兴趣区"));
action_roi->setObjectName("roi");
connect(action_roi,&QAction::triggered,this,&AntiConformEnergySpectrumView::onActionRoiTriggered);
} }

View File

@ -2,6 +2,7 @@
#define ANTICONFORMENERGYSPECTRUMVIEW_H #define ANTICONFORMENERGYSPECTRUMVIEW_H
#include "MeasureAnalysisView.h" #include "MeasureAnalysisView.h"
#include "RegionOfInterest.h"
class QMenu; class QMenu;
class CustomQwtPlot; class CustomQwtPlot;
@ -15,6 +16,7 @@ public:
virtual ~AntiConformEnergySpectrumView(); virtual ~AntiConformEnergySpectrumView();
virtual void InitViewWorkspace(const QString& project_name) override final; virtual void InitViewWorkspace(const QString& project_name) override final;
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set) override; virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set) override;
QwtPlotMarker* createVLine(double x, Qt::GlobalColor color, double lineWidth = 1.0); // 创建垂直标记竖线
protected: protected:
virtual void showEvent(QShowEvent* e) override final; virtual void showEvent(QShowEvent* e) override final;
@ -25,13 +27,15 @@ private:
private slots: private slots:
void onActionPlotConfigure(); void onActionPlotConfigure();
void onActionRoiTriggered();
void slot_roi_data(ROIItem& item);
private: private:
QMenu* _menu = nullptr; QMenu* _menu = nullptr;
BusyIndicatorWidget* _busy_indicator = nullptr; BusyIndicatorWidget* _busy_indicator = nullptr;
CustomQwtPlot* _plot = nullptr; CustomQwtPlot* _plot = nullptr;
QwtPlotCurve* _curve = nullptr; QwtPlotCurve* _curve = nullptr;
QString _data_filename; QString _data_filename;
RegionOfInterest *_roi;
}; };
#endif // ANTICONFORMENERGYSPECTRUMVIEW_H #endif // ANTICONFORMENERGYSPECTRUMVIEW_H

View File

@ -15,7 +15,7 @@
#include <cstdint> #include <cstdint>
#include <QPen> #include <QPen>
#include <QMenu> #include <QMenu>
//符合能谱
struct SpectrumData struct SpectrumData
{ {
int event_id; int event_id;
@ -42,6 +42,9 @@ ConformToTheEnergySpectrum::ConformToTheEnergySpectrum(QWidget *parent) :
QwtPlotCanvas* canvas = qobject_cast<QwtPlotCanvas*>(_plot->canvas()); QwtPlotCanvas* canvas = qobject_cast<QwtPlotCanvas*>(_plot->canvas());
canvas->setFrameStyle(QFrame::NoFrame); canvas->setFrameStyle(QFrame::NoFrame);
_roi = new RegionOfInterest();
connect(_roi, &RegionOfInterest::roiSelected,this, &ConformToTheEnergySpectrum::slot_roi_data);
QFont font = this->font(); QFont font = this->font();
font.setBold(false); font.setBold(false);
QwtText x_label = QStringLiteral(u"能量(KeV)"); QwtText x_label = QStringLiteral(u"能量(KeV)");
@ -90,6 +93,18 @@ void ConformToTheEnergySpectrum::SetAnalyzeDataFilename(const QMap<QString, QVar
} }
} }
QwtPlotMarker *ConformToTheEnergySpectrum::createVLine(double x, Qt::GlobalColor color, double lineWidth)
{
QwtPlotMarker* marker = new QwtPlotMarker();
marker->setXValue(x);
marker->setLineStyle(QwtPlotMarker::VLine);
QPen pen(color);
pen.setWidthF(lineWidth);
marker->setLinePen(pen);
marker->attach(_plot);
return marker;
}
void ConformToTheEnergySpectrum::loadAndProcess() void ConformToTheEnergySpectrum::loadAndProcess()
{ {
@ -171,6 +186,27 @@ void ConformToTheEnergySpectrum::onActionPlotConfigure()
} }
void ConformToTheEnergySpectrum::slot_roi_data(ROIItem &item)
{
// 第一组起始1、结束1 红色竖线,必须存在才插入,所以一定绘制
createVLine(item.s1, Qt::red, 1.2);
createVLine(item.e1, Qt::red, 1.2);
// 第二组起始2、结束2 有有效数值才绘制,无值跳过
bool secondGroupValid = !(qIsNaN(item.s2) || qIsNaN(item.e2) || (item.s2 == 0 && item.e2 == 0));
if (secondGroupValid)
{
createVLine(item.s2, Qt::blue, 1.2);
createVLine(item.e2, Qt::blue, 1.2);
}
_plot->replot();
}
void ConformToTheEnergySpectrum::onActionRoiTriggered()
{
_roi->show();
}
void ConformToTheEnergySpectrum::showEvent(QShowEvent *e) void ConformToTheEnergySpectrum::showEvent(QShowEvent *e)
{ {
Q_UNUSED(e); Q_UNUSED(e);
@ -196,6 +232,9 @@ void ConformToTheEnergySpectrum::setupMenu()
action_plot_config->setObjectName("plot_config"); action_plot_config->setObjectName("plot_config");
connect(action_plot_config, &QAction::triggered, this, &ConformToTheEnergySpectrum::onActionPlotConfigure); connect(action_plot_config, &QAction::triggered, this, &ConformToTheEnergySpectrum::onActionPlotConfigure);
QAction* action_roi = this->_menu->addAction(QStringLiteral(u"感兴趣区"));
action_roi->setObjectName("roi");
connect(action_roi,&QAction::triggered,this,&ConformToTheEnergySpectrum::onActionRoiTriggered);
} }

View File

@ -2,7 +2,7 @@
#define CONFORMTOTHEENERGYSPECTRUM_H #define CONFORMTOTHEENERGYSPECTRUM_H
#include "MeasureAnalysisView.h" #include "MeasureAnalysisView.h"
#include "RegionOfInterest.h"
class QMenu; class QMenu;
class CustomQwtPlot; class CustomQwtPlot;
class QwtPlotCurve; class QwtPlotCurve;
@ -16,6 +16,7 @@ public:
virtual ~ConformToTheEnergySpectrum(); virtual ~ConformToTheEnergySpectrum();
virtual void InitViewWorkspace(const QString& project_name) override final; virtual void InitViewWorkspace(const QString& project_name) override final;
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set) override; virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set) override;
QwtPlotMarker* createVLine(double x, Qt::GlobalColor color, double lineWidth = 1.0); // 创建垂直标记竖线
protected: protected:
virtual void showEvent(QShowEvent* e) override final; virtual void showEvent(QShowEvent* e) override final;
@ -26,13 +27,16 @@ private:
private slots: private slots:
void onActionPlotConfigure(); void onActionPlotConfigure();
void slot_roi_data(ROIItem& item);
void onActionRoiTriggered();
private: private:
QMenu* _menu = nullptr; QMenu* _menu = nullptr;
BusyIndicatorWidget* _busy_indicator = nullptr; BusyIndicatorWidget* _busy_indicator = nullptr;
CustomQwtPlot* _plot = nullptr; CustomQwtPlot* _plot = nullptr;
QwtPlotCurve* _curve = nullptr; QwtPlotCurve* _curve = nullptr;
QStringList _data_filenames; QStringList _data_filenames;
RegionOfInterest *_roi;
}; };
#endif // CONFORMTOTHEENERGYSPECTRUM_H #endif // CONFORMTOTHEENERGYSPECTRUM_H

View File

@ -40,7 +40,7 @@
#include "MeasureAnalysisProjectModel.h" #include "MeasureAnalysisProjectModel.h"
#include "BusyIndicator.h" #include "BusyIndicator.h"
//峰拟合分析
QJsonObject PeakFitHistoryItem::toJson() const QJsonObject PeakFitHistoryItem::toJson() const
{ {
QJsonObject obj; QJsonObject obj;
@ -115,10 +115,12 @@ EnergyCountPeakFitView::EnergyCountPeakFitView(QWidget* parent)
this->_plot = new CustomQwtPlot(this); this->_plot = new CustomQwtPlot(this);
layout->addWidget(this->_plot); layout->addWidget(this->_plot);
setupPlot(); setupPlot();
_roi = new RegionOfInterest();
connect(_roi, &RegionOfInterest::roiSelected,this, &EnergyCountPeakFitView::slot_roi_data);
this->_menu = new QMenu(this); this->_menu = new QMenu(this);
setupMenu(); setupMenu();
connect(this, &EnergyCountPeakFitView::newFitResultAdded, this, &EnergyCountPeakFitView::onNewFitResultAdded); connect(this, &EnergyCountPeakFitView::newFitResultAdded, this, &EnergyCountPeakFitView::onNewFitResultAdded);
} }
EnergyCountPeakFitView::~EnergyCountPeakFitView() EnergyCountPeakFitView::~EnergyCountPeakFitView()
@ -185,6 +187,18 @@ void EnergyCountPeakFitView::SetAnalyzeDataFilename(const QMap<QString, QVariant
} }
} }
QwtPlotMarker *EnergyCountPeakFitView::createVLine(double x, Qt::GlobalColor color, double lineWidth)
{
QwtPlotMarker* marker = new QwtPlotMarker();
marker->setXValue(x);
marker->setLineStyle(QwtPlotMarker::VLine);
QPen pen(color);
pen.setWidthF(lineWidth);
marker->setLinePen(pen);
marker->attach(_plot);
return marker;
}
void EnergyCountPeakFitView::setupPlot() void EnergyCountPeakFitView::setupPlot()
{ {
_plot->setCanvasBackground(Qt::white); _plot->setCanvasBackground(Qt::white);
@ -261,6 +275,10 @@ void EnergyCountPeakFitView::setupMenu()
QAction* action_delete_hovered_rect = this->_menu->addAction(QStringLiteral(u"删除当前框选区域")); QAction* action_delete_hovered_rect = this->_menu->addAction(QStringLiteral(u"删除当前框选区域"));
connect(action_delete_hovered_rect, &QAction::triggered, this, &EnergyCountPeakFitView::onActionDeleteHoveredRect); connect(action_delete_hovered_rect, &QAction::triggered, this, &EnergyCountPeakFitView::onActionDeleteHoveredRect);
QAction* action_roi = this->_menu->addAction(QStringLiteral(u"感兴趣区"));
action_roi->setObjectName("roi");
connect(action_roi,&QAction::triggered,this,&EnergyCountPeakFitView::onActionRoiTriggered);
} }
void EnergyCountPeakFitView::loadDataFromFile(const QString& data_name, const QString& filename) void EnergyCountPeakFitView::loadDataFromFile(const QString& data_name, const QString& filename)
@ -1578,3 +1596,24 @@ void EnergyCountPeakFitView::onHistoryDlgClosed()
LOG_DEBUG(QStringLiteral(u"峰拟合结果对话框已关闭")); LOG_DEBUG(QStringLiteral(u"峰拟合结果对话框已关闭"));
} }
void EnergyCountPeakFitView::onActionRoiTriggered()
{
_roi->show();
}
void EnergyCountPeakFitView::slot_roi_data(ROIItem &item)
{
// 第一组起始1、结束1 红色竖线,必须存在才插入,所以一定绘制
createVLine(item.s1, Qt::red, 1.2);
createVLine(item.e1, Qt::red, 1.2);
// 第二组起始2、结束2 有有效数值才绘制,无值跳过
bool secondGroupValid = !(qIsNaN(item.s2) || qIsNaN(item.e2) || (item.s2 == 0 && item.e2 == 0));
if (secondGroupValid)
{
createVLine(item.s2, Qt::blue, 1.2);
createVLine(item.e2, Qt::blue, 1.2);
}
_plot->replot();
}

View File

@ -11,7 +11,7 @@
#include <QwtPickerDragRectMachine> #include <QwtPickerDragRectMachine>
#include <QwtPlotPicker> #include <QwtPlotPicker>
#include <qwt_plot_shapeitem.h> #include <qwt_plot_shapeitem.h>
#include "RegionOfInterest.h"
#include "DataCalcProcess/AdaptiveSimpsonIntegrate.h" #include "DataCalcProcess/AdaptiveSimpsonIntegrate.h"
#include "DataCalcProcess/FindPeaksBySvd.h" #include "DataCalcProcess/FindPeaksBySvd.h"
#include "DataCalcProcess/MathModelDefine.h" #include "DataCalcProcess/MathModelDefine.h"
@ -87,6 +87,7 @@ public:
virtual void InitViewWorkspace(const QString& project_name) override final; virtual void InitViewWorkspace(const QString& project_name) override final;
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set); virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set);
QwtPlotMarker* createVLine(double x, Qt::GlobalColor color, double lineWidth = 1.0); // 创建垂直标记竖线
private: private:
void setupPlot(); void setupPlot();
@ -115,7 +116,8 @@ private slots:
void onNewFitResultAdded(); // 新拟合结果同步刷新槽 void onNewFitResultAdded(); // 新拟合结果同步刷新槽
void onHistoryDlgClosed(); // 历史对话框关闭清理槽 void onHistoryDlgClosed(); // 历史对话框关闭清理槽
void onActionRoiTriggered();
void slot_roi_data(ROIItem& item);
protected: protected:
bool eventFilter(QObject* watched, QEvent* event) override; // 事件过滤器 bool eventFilter(QObject* watched, QEvent* event) override; // 事件过滤器
@ -167,6 +169,9 @@ private:
PlotRectItem* _hoveredRectItem = nullptr; PlotRectItem* _hoveredRectItem = nullptr;
QList<DisplayedCurveRef> _displayedHistoryCurves; QList<DisplayedCurveRef> _displayedHistoryCurves;
QDialog* _historyDlg = nullptr; // 跟踪当前打开的峰拟合结果对话框 QDialog* _historyDlg = nullptr; // 跟踪当前打开的峰拟合结果对话框
RegionOfInterest *_roi;
}; };
#endif // ENERGYCOUNTPEAKFITVIEW_H #endif // ENERGYCOUNTPEAKFITVIEW_H

View File

@ -14,8 +14,8 @@
#include <QPushButton> #include <QPushButton>
#include <QCheckBox> #include <QCheckBox>
#include <QwtScaleDiv> #include <QwtScaleDiv>
#include <QPen>
//能量计数谱
EnergyCountPlotView::EnergyCountPlotView(QWidget *parent) EnergyCountPlotView::EnergyCountPlotView(QWidget *parent)
: MeasureAnalysisView { parent } : MeasureAnalysisView { parent }
{ {
@ -23,6 +23,9 @@ EnergyCountPlotView::EnergyCountPlotView(QWidget *parent)
QHBoxLayout* layout = new QHBoxLayout(this); QHBoxLayout* layout = new QHBoxLayout(this);
this->_plot = new CustomQwtPlot(this); this->_plot = new CustomQwtPlot(this);
_roi = new RegionOfInterest();
connect(_roi, &RegionOfInterest::roiSelected,this, &EnergyCountPlotView::slot_roi_data);
layout->addWidget(this->_plot); layout->addWidget(this->_plot);
setupPlot(); setupPlot();
this->_menu = new QMenu(this); this->_menu = new QMenu(this);
@ -111,6 +114,9 @@ void EnergyCountPlotView::setupMenu()
QAction* action_plot_config = this->_menu->addAction(QStringLiteral(u"图表配置")); QAction* action_plot_config = this->_menu->addAction(QStringLiteral(u"图表配置"));
action_plot_config->setObjectName("plot_config"); action_plot_config->setObjectName("plot_config");
connect(action_plot_config, &QAction::triggered, this, &EnergyCountPlotView::onActionPlotConfigure); connect(action_plot_config, &QAction::triggered, this, &EnergyCountPlotView::onActionPlotConfigure);
QAction* action_roi = this->_menu->addAction(QStringLiteral(u"感兴趣区"));
action_roi->setObjectName("roi");
connect(action_roi,&QAction::triggered,this,&EnergyCountPlotView::onActionRoiTriggered);
} }
void EnergyCountPlotView::loadDataFromFile(const QString &data_name, const QString &filename) void EnergyCountPlotView::loadDataFromFile(const QString &data_name, const QString &filename)
@ -147,6 +153,18 @@ void EnergyCountPlotView::loadDataFromFile(const QString &data_name, const QStri
_plot->AddCurve(curve); _plot->AddCurve(curve);
} }
QwtPlotMarker *EnergyCountPlotView::createVLine(double x, Qt::GlobalColor color, double lineWidth)
{
QwtPlotMarker* marker = new QwtPlotMarker();
marker->setXValue(x);
marker->setLineStyle(QwtPlotMarker::VLine);
QPen pen(color);
pen.setWidthF(lineWidth);
marker->setLinePen(pen);
marker->attach(_plot);
return marker;
}
void EnergyCountPlotView::updateView(const QMap<QString, QVariant>& data_files_set) void EnergyCountPlotView::updateView(const QMap<QString, QVariant>& data_files_set)
{ {
// 清除现有所有曲线 // 清除现有所有曲线
@ -258,3 +276,24 @@ void EnergyCountPlotView::onActionPlotConfigure()
{ {
} }
void EnergyCountPlotView::onActionRoiTriggered()
{
_roi->show();
}
void EnergyCountPlotView::slot_roi_data(ROIItem &item)
{
// 第一组起始1、结束1 红色竖线,必须存在才插入,所以一定绘制
createVLine(item.s1, Qt::red, 1.2);
createVLine(item.e1, Qt::red, 1.2);
// 第二组起始2、结束2 有有效数值才绘制,无值跳过
bool secondGroupValid = !(qIsNaN(item.s2) || qIsNaN(item.e2) || (item.s2 == 0 && item.e2 == 0));
if (secondGroupValid)
{
createVLine(item.s2, Qt::blue, 1.2);
createVLine(item.e2, Qt::blue, 1.2);
}
_plot->replot();
}

View File

@ -4,7 +4,7 @@
#include <QObject> #include <QObject>
#include <QWidget> #include <QWidget>
#include <MeasureAnalysisView.h> #include <MeasureAnalysisView.h>
#include "RegionOfInterest.h"
class QMenu; class QMenu;
class CustomQwtPlot; class CustomQwtPlot;
class CustomQwtPlotXaxisSelector; class CustomQwtPlotXaxisSelector;
@ -25,11 +25,13 @@ private:
void setupPlot(); void setupPlot();
void setupMenu(); void setupMenu();
void loadDataFromFile(const QString &data_name, const QString& filename); void loadDataFromFile(const QString &data_name, const QString& filename);
QwtPlotMarker* createVLine(double x, Qt::GlobalColor color, double lineWidth = 1.0); // 创建垂直标记竖线
private slots: private slots:
void onActionCurveShowSetting(); void onActionCurveShowSetting();
void onActionPlotConfigure(); void onActionPlotConfigure();
void onActionRoiTriggered();
void slot_roi_data(ROIItem& item);
private: private:
CustomQwtPlot* _plot = nullptr; CustomQwtPlot* _plot = nullptr;
QMenu* _menu = nullptr; QMenu* _menu = nullptr;
@ -37,6 +39,7 @@ private:
CustomQwtPlotXaxisSelector* _data_selector = nullptr; CustomQwtPlotXaxisSelector* _data_selector = nullptr;
double _x_max = 0.0f; double _x_max = 0.0f;
double _y_max = 0.0f; double _y_max = 0.0f;
RegionOfInterest *_roi;
}; };
#endif // ENERGYCOUNTPLOTVIEW_H #endif // ENERGYCOUNTPLOTVIEW_H

View File

@ -19,9 +19,10 @@ RegionOfInterest::RegionOfInterest(QWidget *parent)
, m_tempEndMarker(nullptr) , m_tempEndMarker(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);
this->_plot = new CustomQwtPlot(this); // this->_plot = new CustomQwtPlot(this);
ui->layout_Curve->addWidget(_plot); // ui->layout_Curve->addWidget(_plot);
setupPlot(); // setupPlot();
ui->widget->hide();
ui->tableWidget->setColumnCount(6); ui->tableWidget->setColumnCount(6);
QStringList headers = {"序号","描述文本", "起始1", "结束1", "起始2", "结束2"}; QStringList headers = {"序号","描述文本", "起始1", "结束1", "起始2", "结束2"};
ui->tableWidget->verticalHeader()->setVisible(false); ui->tableWidget->verticalHeader()->setVisible(false);
@ -185,7 +186,7 @@ void RegionOfInterest::on_pBtn_insert_clicked()
m_roiList.append(newRoi); m_roiList.append(newRoi);
// 刷新绘图竖线 // 刷新绘图竖线
refreshROILines(); // refreshROILines();
saveAllRoiToJson(); saveAllRoiToJson();
} }
@ -225,7 +226,7 @@ void RegionOfInterest::on_pBtn_update_clicked()
break; break;
} }
} }
refreshROILines(); // refreshROILines();
saveAllRoiToJson(); saveAllRoiToJson();
} }
@ -243,7 +244,7 @@ void RegionOfInterest::on_pBtn_clear_clicked()
{ {
ui->tableWidget->setRowCount(0); ui->tableWidget->setRowCount(0);
m_roiList.clear(); // 清空数据缓存 m_roiList.clear(); // 清空数据缓存
refreshROILines(); // 清除所有竖线 // refreshROILines(); // 清除所有竖线
saveAllRoiToJson(); saveAllRoiToJson();
} }
} }
@ -264,78 +265,83 @@ void RegionOfInterest::on_tableWidget_cellClicked(int row, int col)
ui->lineEdit_end1->setText(e1); ui->lineEdit_end1->setText(e1);
ui->lineEdit_start2->setText(s2); ui->lineEdit_start2->setText(s2);
ui->lineEdit_end2->setText(e2); ui->lineEdit_end2->setText(e2);
if(row >= 0 && row < m_roiList.size())
{
emit roiSelected(m_roiList[row]);
}
} }
bool RegionOfInterest::eventFilter(QObject *obj, QEvent *event) bool RegionOfInterest::eventFilter(QObject *obj, QEvent *event)
{ {
// 只处理绘图画布的鼠标事件 // 只处理绘图画布的鼠标事件
if (obj == _plot->canvas()) // if (obj == _plot->canvas())
{ // {
QMouseEvent* mouseEv = dynamic_cast<QMouseEvent*>(event); // QMouseEvent* mouseEv = dynamic_cast<QMouseEvent*>(event);
if (!mouseEv) // if (!mouseEv)
return QWidget::eventFilter(obj, event); // return QWidget::eventFilter(obj, event);
// 鼠标按下 // // 鼠标按下
if (event->type() == QEvent::MouseButtonPress) // if (event->type() == QEvent::MouseButtonPress)
{ // {
m_bMouseSelect = true; // m_bMouseSelect = true;
m_selectStartX = _plot->invTransform(QwtPlot::xBottom, mouseEv->pos().x()); // m_selectStartX = _plot->invTransform(QwtPlot::xBottom, mouseEv->pos().x());
// 创建临时虚线标记 // // 创建临时虚线标记
QPen dashPen(Qt::red); // QPen dashPen(Qt::red);
dashPen.setStyle(Qt::DashLine); // dashPen.setStyle(Qt::DashLine);
dashPen.setWidthF(1.5); // dashPen.setWidthF(1.5);
m_tempStartMarker = new QwtPlotMarker(); // m_tempStartMarker = new QwtPlotMarker();
m_tempStartMarker->setXValue(m_selectStartX); // m_tempStartMarker->setXValue(m_selectStartX);
m_tempStartMarker->setLineStyle(QwtPlotMarker::VLine); // m_tempStartMarker->setLineStyle(QwtPlotMarker::VLine);
m_tempStartMarker->setLinePen(dashPen); // m_tempStartMarker->setLinePen(dashPen);
m_tempStartMarker->attach(_plot); // m_tempStartMarker->attach(_plot);
m_tempEndMarker = new QwtPlotMarker(); // m_tempEndMarker = new QwtPlotMarker();
m_tempEndMarker->setXValue(m_selectStartX); // m_tempEndMarker->setXValue(m_selectStartX);
m_tempEndMarker->setLineStyle(QwtPlotMarker::VLine); // m_tempEndMarker->setLineStyle(QwtPlotMarker::VLine);
m_tempEndMarker->setLinePen(dashPen); // m_tempEndMarker->setLinePen(dashPen);
m_tempEndMarker->attach(_plot); // m_tempEndMarker->attach(_plot);
_plot->replot(); // _plot->replot();
} // }
// 鼠标移动:实时更新结束竖线位置 // // 鼠标移动:实时更新结束竖线位置
else if (event->type() == QEvent::MouseMove && m_bMouseSelect) // else if (event->type() == QEvent::MouseMove && m_bMouseSelect)
{ // {
m_selectEndX = _plot->invTransform(QwtPlot::xBottom, mouseEv->pos().x()); // m_selectEndX = _plot->invTransform(QwtPlot::xBottom, mouseEv->pos().x());
m_tempEndMarker->setXValue(m_selectEndX); // m_tempEndMarker->setXValue(m_selectEndX);
_plot->replot(); // _plot->replot();
} // }
// 鼠标松开 // // 鼠标松开
else if (event->type() == QEvent::MouseButtonRelease) // else if (event->type() == QEvent::MouseButtonRelease)
{ // {
if (!m_bMouseSelect) // if (!m_bMouseSelect)
return QWidget::eventFilter(obj, event); // return QWidget::eventFilter(obj, event);
m_bMouseSelect = false; // m_bMouseSelect = false;
m_selectEndX = _plot->invTransform(QwtPlot::xBottom, mouseEv->pos().x()); // m_selectEndX = _plot->invTransform(QwtPlot::xBottom, mouseEv->pos().x());
// 销毁临时虚线 // // 销毁临时虚线
if(m_tempStartMarker) // if(m_tempStartMarker)
{ // {
m_tempStartMarker->detach(); // m_tempStartMarker->detach();
delete m_tempStartMarker; // delete m_tempStartMarker;
m_tempStartMarker = nullptr; // m_tempStartMarker = nullptr;
} // }
if(m_tempEndMarker) // if(m_tempEndMarker)
{ // {
m_tempEndMarker->detach(); // m_tempEndMarker->detach();
delete m_tempEndMarker; // delete m_tempEndMarker;
m_tempEndMarker = nullptr; // m_tempEndMarker = nullptr;
} // }
_plot->replot(); // _plot->replot();
double s = qMin(m_selectStartX, m_selectEndX); // double s = qMin(m_selectStartX, m_selectEndX);
double e = qMax(m_selectStartX, m_selectEndX); // double e = qMax(m_selectStartX, m_selectEndX);
// 回填到起始1、结束1输入框 // // 回填到起始1、结束1输入框
ui->lineEdit_start1->setText(QString::number(s, 'f', 2)); // ui->lineEdit_start1->setText(QString::number(s, 'f', 2));
ui->lineEdit_end1->setText(QString::number(e, 'f', 2)); // ui->lineEdit_end1->setText(QString::number(e, 'f', 2));
} // }
} // }
return QWidget::eventFilter(obj, event); return QWidget::eventFilter(obj, event);
} }
@ -389,6 +395,41 @@ void RegionOfInterest::loadROIFromFile()
ui->tableWidget->setItem(row, 4, new QTableWidgetItem(s2Str)); ui->tableWidget->setItem(row, 4, new QTableWidgetItem(s2Str));
ui->tableWidget->setItem(row, 5, new QTableWidgetItem(e2Str)); ui->tableWidget->setItem(row, 5, new QTableWidgetItem(e2Str));
} }
refreshROILines(); // refreshROILines();
}
void RegionOfInterest::on_pBtn_delete_clicked()
{
int curRow = ui->tableWidget->currentRow();
if(curRow < 0)
{
QMessageBox::information(this,"提示","请选中要删除的行!");
return;
}
int ret = QMessageBox::question(this,"确认","是否删除当前选中ROI",QMessageBox::Yes|QMessageBox::No);
if(ret != QMessageBox::Yes) return;
int targetSeq = curRow + 1;
// 从内存列表移除
for(auto it = m_roiList.begin(); it != m_roiList.end();)
{
if(it->rowNo == targetSeq)
{
it = m_roiList.erase(it);
break;
}
++it;
}
// 删除表格行
ui->tableWidget->removeRow(curRow);
// 重新刷新序号
for(int r=0; r<ui->tableWidget->rowCount(); r++)
{
int newSeq = r+1;
ui->tableWidget->item(r,0)->setText(QString::number(newSeq));
m_roiList[r].rowNo = newSeq;
}
saveAllRoiToJson();
} }

View File

@ -20,6 +20,9 @@ struct ROIItem
double s2, e2; // 第二组区间起始2、结束2 double s2, e2; // 第二组区间起始2、结束2
}; };
Q_DECLARE_METATYPE(ROIItem)
class RegionOfInterest : public QWidget class RegionOfInterest : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -46,6 +49,9 @@ private slots:
void on_tableWidget_cellClicked(int row, int col); void on_tableWidget_cellClicked(int row, int col);
void on_pBtn_delete_clicked();
signals:
void roiSelected(ROIItem& item);
private: private:
Ui::RegionOfInterest *ui; Ui::RegionOfInterest *ui;
CustomQwtPlot* _plot = nullptr; CustomQwtPlot* _plot = nullptr;

View File

@ -95,6 +95,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="pBtn_delete">
<property name="text">
<string>删除</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>