2026-03-26 19:07:49 +08:00
|
|
|
#ifndef ENERGYCOUNTPEAKFITVIEW_H
|
|
|
|
|
#define ENERGYCOUNTPEAKFITVIEW_H
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
#include <MeasureAnalysisView.h>
|
2026-04-15 18:17:16 +08:00
|
|
|
#include <QwtPlotPicker>
|
|
|
|
|
#include <QwtPickerDragRectMachine>
|
|
|
|
|
#include <QRubberBand> // 新增
|
|
|
|
|
#include <qwt_plot_shapeitem.h> // 新增
|
2026-04-20 18:02:41 +08:00
|
|
|
#include "PeakFitParamsDialog.h"
|
|
|
|
|
|
|
|
|
|
#include "DataCalcProcess/FindPeaksBySvd.h"
|
|
|
|
|
#include "DataCalcProcess/NolinearLeastSquaresCurveFit.h"
|
|
|
|
|
#include "DataCalcProcess/AdaptiveSimpsonIntegrate.h"
|
|
|
|
|
#include "DataCalcProcess/MathModelDefine.h"
|
|
|
|
|
|
|
|
|
|
struct PeakFitResult
|
|
|
|
|
{
|
|
|
|
|
double center; // 峰中心能量 (keV)
|
|
|
|
|
double amplitude; // 高斯振幅
|
|
|
|
|
double sigma; // 高斯宽度
|
|
|
|
|
double fwhm; // 半高宽 = sigma * 2.355
|
|
|
|
|
double area; // 峰面积(积分)
|
|
|
|
|
double baseline; // 常数项 C
|
|
|
|
|
double sigmoidH; // Sigmoid 项高度 H
|
|
|
|
|
double sigmoidW; // Sigmoid 项宽度 W
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-26 19:07:49 +08:00
|
|
|
|
2026-04-15 18:17:16 +08:00
|
|
|
class PlotRectItem; // 前向声明
|
2026-03-26 19:07:49 +08:00
|
|
|
class QMenu;
|
|
|
|
|
class CustomQwtPlot;
|
|
|
|
|
class CustomQwtPlotXaxisSelector;
|
2026-04-15 18:17:16 +08:00
|
|
|
class QwtPlotPicker;
|
|
|
|
|
class QwtPlotCurve;
|
2026-04-20 18:02:41 +08:00
|
|
|
|
2026-03-26 19:07:49 +08:00
|
|
|
class EnergyCountPeakFitView : public MeasureAnalysisView
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
EnergyCountPeakFitView(QWidget *parent = nullptr);
|
|
|
|
|
virtual ~EnergyCountPeakFitView();
|
|
|
|
|
|
|
|
|
|
virtual void InitViewWorkspace(const QString& project_name) override final;
|
|
|
|
|
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void setupPlot();
|
|
|
|
|
void setupMenu();
|
|
|
|
|
void loadDataFromFile(const QString &data_name, const QString& filename);
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void onActionCurveShowSetting();
|
|
|
|
|
void onActionPlotConfigure();
|
2026-04-15 18:17:16 +08:00
|
|
|
void clearAllSelectionRects();
|
2026-04-20 18:02:41 +08:00
|
|
|
void clearFitCurves(); // 清除所有拟合曲线
|
|
|
|
|
|
2026-04-15 18:17:16 +08:00
|
|
|
protected:
|
|
|
|
|
bool eventFilter(QObject* watched, QEvent* event) override; // 事件过滤器
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void startSelection(const QPoint& pos);
|
|
|
|
|
void updateSelection(const QPoint& pos);
|
|
|
|
|
void finishSelection();
|
|
|
|
|
void addSelectionRect(const QRectF& plotRect);
|
|
|
|
|
|
2026-04-20 18:02:41 +08:00
|
|
|
QList<PeakFitResult> performPeakFitting(const QVector<double>& x, const QVector<double>& y, const arma::vec* userP0 = nullptr);
|
|
|
|
|
// 根据拟合参数生成曲线
|
|
|
|
|
QwtPlotCurve* createFitCurve(const PeakFitResult& result, double xMin, double xMax, const QString& name);
|
2026-03-26 19:07:49 +08:00
|
|
|
private:
|
|
|
|
|
CustomQwtPlot* _plot = nullptr;
|
|
|
|
|
QMenu* _menu = nullptr;
|
|
|
|
|
QDialog* _curve_show_setting_dlg = nullptr;
|
|
|
|
|
CustomQwtPlotXaxisSelector* _data_selector = nullptr;
|
2026-04-15 18:17:16 +08:00
|
|
|
// 手动框选状态
|
|
|
|
|
bool _isSelecting = false;
|
|
|
|
|
QPoint _selectionStart;
|
|
|
|
|
QRubberBand* _rubberBand = nullptr; // 原生橡皮筋
|
|
|
|
|
QList<PlotRectItem*> _selectionRectItems;
|
|
|
|
|
|
|
|
|
|
QwtPlotCurve* _fittedCurve = nullptr; // 显示拟合结果的曲线
|
|
|
|
|
|
2026-04-20 18:02:41 +08:00
|
|
|
// 存储当前显示的拟合曲线,用于清除
|
|
|
|
|
QList<QwtPlotCurve*> _fitCurves;
|
2026-04-15 18:17:16 +08:00
|
|
|
|
2026-03-26 19:07:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // ENERGYCOUNTPEAKFITVIEW_H
|