添加粒子道址计数谱曲线选择控制

This commit is contained in:
徐海 2026-03-09 21:57:26 +08:00
parent 34b78ac310
commit 5c6ebf26fb
8 changed files with 218 additions and 70 deletions

View File

@ -15,60 +15,72 @@
using namespace DataProcessWorkPool;
using namespace io;
void ParticleDataTask::SetAllChannelParticleDataFilename(const QString& all_channel_particle_data_filename)
{
this->_all_channel_particle_data_filename = all_channel_particle_data_filename;
}
void ParticleDataTask::SetFinishedNotifier(QObject* finished_notifier, const char* finished_process, const QString& project_name)
void DataProcessTask::SetFinishedNotifier(QObject* finished_notifier, const char* finished_process, const QString& project_name)
{
this->_finished_notifier = finished_notifier;
this->_finished_notifier_process = finished_process;
this->_project_name = project_name;
}
const QString& DataProcessTask::GetProjectName() const
{
return this->_project_name;
}
const char* DataProcessTask::GetFinishedNotifierProcess() const
{
return this->_finished_notifier_process;
}
QObject* DataProcessTask::GetFinishedNotifier() const
{
return this->_finished_notifier;
}
bool DataProcessTask::IsValidSetWorkParameters() const
{
return !GetProjectName().isEmpty();
}
void DataProcessTask::StartTask()
{
QThreadPool::globalInstance()->start(this);
}
void DataProcessTask::run()
{
if (!IsValidSetWorkParameters()) {
return;
}
if (!processTask()) {
return;
}
if ((GetFinishedNotifier() != nullptr) && (GetFinishedNotifierProcess() != nullptr)) {
QMetaObject::invokeMethod(_finished_notifier, _finished_notifier_process, Qt::QueuedConnection, Q_ARG(QString, _project_name));
}
}
void ParticleDataTask::SetAllChannelParticleDataFilename(const QString& all_channel_particle_data_filename)
{
this->_all_channel_particle_data_filename = all_channel_particle_data_filename;
}
const QString& ParticleDataTask::GetAllChannelParticleDataFilename() const
{
return this->_all_channel_particle_data_filename;
}
const QString& ParticleDataTask::GetProjectName() const
{
return this->_project_name;
}
const char* ParticleDataTask::GetFinishedNotifierProcess() const
{
return this->_finished_notifier_process;
}
QObject* ParticleDataTask::GetFinishedNotifier() const
{
return this->_finished_notifier;
}
bool ParticleDataTask::IsValidSetWorkParameters() const
{
return (!GetAllChannelParticleDataFilename().isEmpty()) && (!GetProjectName().isEmpty());
return (!GetAllChannelParticleDataFilename().isEmpty()) && (!DataProcessTask::IsValidSetWorkParameters());
}
void ParticleDataTask::StartTask()
bool ParticleDataTask::processTask()
{
QThreadPool::globalInstance()->start(this);
}
void ParticleDataTask::run()
{
if (!IsValidSetWorkParameters()) {
return;
}
if (!processEveryChannelParticleData()) {
return;
}
if ((GetFinishedNotifier() != nullptr) && (GetFinishedNotifierProcess() != nullptr)) {
QMetaObject::invokeMethod(_finished_notifier, _finished_notifier_process, Qt::QueuedConnection, Q_ARG(QString, _project_name));
}
return processEveryChannelParticleData();
}
void EveryChannelParticleDataSeparateTask::SetResultDataDir(const QString& result_data_dir)

View File

@ -7,13 +7,10 @@
namespace DataProcessWorkPool
{
class ParticleDataTask : public QRunnable
class DataProcessTask : public QRunnable
{
public:
void SetAllChannelParticleDataFilename(const QString& all_channel_particle_data_filename);
void SetFinishedNotifier(QObject* finished_notifier, const char* finished_process, const QString& project_name);
const QString& GetAllChannelParticleDataFilename() const;
const QString& GetProjectName() const;
const char* GetFinishedNotifierProcess() const;
QObject* GetFinishedNotifier() const;
@ -24,13 +21,28 @@ namespace DataProcessWorkPool
virtual void run() override;
private:
virtual bool processTask() = 0;
private:
QObject* _finished_notifier { nullptr };
const char* _finished_notifier_process { nullptr };
QString _project_name;
};
class ParticleDataTask : public DataProcessTask
{
public:
void SetAllChannelParticleDataFilename(const QString& all_channel_particle_data_filename);
const QString& GetAllChannelParticleDataFilename() const;
virtual bool IsValidSetWorkParameters() const;
private:
virtual bool processTask() final;
virtual bool processEveryChannelParticleData() = 0;
private:
QString _all_channel_particle_data_filename;
QObject* _finished_notifier { nullptr };
const char* _finished_notifier_process { nullptr };
QString _project_name;
};
class EveryChannelParticleDataSeparateTask : public ParticleDataTask

View File

@ -210,7 +210,10 @@ void MainWindow::initAction()
auto result = QMessageBox::question(this, title, text, QMessageBox::Yes | QMessageBox::No);
if (QMessageBox::Yes == result) {
project_model->SaveProjectModel();
ProjectList::Instance()->RmProjectModel(project_name);
if(ProjectList::Instance()->RmProjectModel(project_name)) {
const QString& info_text = QStringLiteral(u"测试分析项\"%1\"已关闭.").arg(project_name);
LOG_INFO(info_text);
}
}
}

View File

@ -9,6 +9,12 @@
#include <QwtLegend>
#include <QwtPlotCanvas>
#include <QwtPlotCurve>
#include <QMenu>
#include <QAction>
#include <QCheckBox>
#include <QDialog>
#include <QwtText>
#include <QPushButton>
MeasureAnalysisParticleCountPlotView::MeasureAnalysisParticleCountPlotView(QWidget* parent)
: MeasureAnalysisView { parent }
@ -16,10 +22,13 @@ MeasureAnalysisParticleCountPlotView::MeasureAnalysisParticleCountPlotView(QWidg
this->setViewType(PlotFrame);
QHBoxLayout* layout = new QHBoxLayout(this);
_plot = new CustomQwtPlot(this);
layout->addWidget(_plot);
this->_plot = new CustomQwtPlot(this);
layout->addWidget(this->_plot);
setupPlot();
this->_menu = new QMenu(this);
setupMenu();
}
void MeasureAnalysisParticleCountPlotView::SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set)
@ -47,6 +56,26 @@ void MeasureAnalysisParticleCountPlotView::SetAnalyzeDataFilename(const QMap<QSt
}
}
void MeasureAnalysisParticleCountPlotView::setupMenu()
{
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &MeasureAnalysisParticleCountPlotView::customContextMenuRequested, this, [this](const QPoint &pos){
this->_menu->exec(this->mapToGlobal(pos));
});
QAction* action_set_curve_show = this->_menu->addAction(QStringLiteral(u"选择曲线"));
action_set_curve_show->setObjectName("curve_show_setting");
connect(action_set_curve_show, &QAction::triggered, this, &MeasureAnalysisParticleCountPlotView::onCurveShowSetting);
QAction* action_find_peaks = this->_menu->addAction(QStringLiteral(u"自动寻峰"));
action_find_peaks->setObjectName("auto_find_peaks");
connect(action_find_peaks, &QAction::triggered, this, &MeasureAnalysisParticleCountPlotView::onAutoFindPeaks);
QAction* action_set_energy_scale = this->_menu->addAction(QStringLiteral(u"能量刻度"));
action_set_energy_scale->setObjectName("energy_scale");
connect(action_set_energy_scale, &QAction::triggered, this, &MeasureAnalysisParticleCountPlotView::onEneryScale);
QAction* action_plot_config = this->_menu->addAction(QStringLiteral(u"图表配置"));
action_plot_config->setObjectName("plot_config");
connect(action_plot_config, &QAction::triggered, this, &MeasureAnalysisParticleCountPlotView::onPlotConfigure);
}
void MeasureAnalysisParticleCountPlotView::setupPlot()
{
_plot->setTitle(QString(QStringLiteral(u"粒子计数谱")));
@ -98,3 +127,81 @@ void MeasureAnalysisParticleCountPlotView::loadDataFromFile(const QString& data_
_plot->AddCurve(curve);
LOG_DEBUG(data_name);
}
void MeasureAnalysisParticleCountPlotView::onCurveShowSetting()
{
QDialog curve_show_setting_dlg(nullptr, Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint);
curve_show_setting_dlg.setWindowTitle(QString(QStringLiteral(u"选择曲线")));
curve_show_setting_dlg.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
curve_show_setting_dlg.setWindowModality(Qt::NonModal);
curve_show_setting_dlg.setModal(false);
QVBoxLayout layout(&curve_show_setting_dlg);
// 自动计算多列排布
QMap<QwtPlotCurve*, QCheckBox*> curve_checkbox_map;
int num_columns = std::sqrt(this->_plot->GetCurveList().size());
if (num_columns == 0) num_columns = 1;
QVBoxLayout* checkbox_layout = new QVBoxLayout();
QHBoxLayout* checkbox_column_layout = new QHBoxLayout();
for (QwtPlotCurve* curve : this->_plot->GetCurveList()) {
QCheckBox* check_box = new QCheckBox(curve->title().text());
check_box->setChecked(curve->isVisible());
checkbox_column_layout->addWidget(check_box);
connect(check_box, &QCheckBox::stateChanged, this, [curve](int state){
curve->setVisible(state == Qt::Checked);
curve->plot()->replot();
});
curve_checkbox_map[curve] = check_box;
if (checkbox_column_layout->count() >= num_columns) {
checkbox_layout->addLayout(checkbox_column_layout);
checkbox_column_layout = new QHBoxLayout();
}
}
if (checkbox_column_layout->count() < num_columns) {
checkbox_column_layout->addStretch();
}
checkbox_layout->addLayout(checkbox_column_layout);
// 全选和反选
auto curveCheckboxUpdate = [this, curve_checkbox_map](){
for (QwtPlotCurve* curve : this->_plot->GetCurveList()) {
curve_checkbox_map[curve]->setChecked(curve->isVisible());
}
};
QHBoxLayout* button_layout = new QHBoxLayout();
QPushButton* btn_all_select = new QPushButton(QString(QStringLiteral(u"全选")));
connect(btn_all_select, &QPushButton::clicked, this, [this, curveCheckboxUpdate](){
for (QwtPlotCurve* curve : this->_plot->GetCurveList()) {
curve->setVisible(true);
}
curveCheckboxUpdate();
this->_plot->replot();
});
button_layout->addWidget(btn_all_select);
QPushButton* btn_reserve_select = new QPushButton(QString(QStringLiteral(u"反选")));
connect(btn_reserve_select, &QPushButton::clicked, this, [this, curveCheckboxUpdate](){
for (QwtPlotCurve* curve : this->_plot->GetCurveList()) {
curve->setVisible(!curve->isVisible());
}
curveCheckboxUpdate();
this->_plot->replot();
});
button_layout->addWidget(btn_reserve_select);
layout.addLayout(button_layout);
layout.addLayout(checkbox_layout);
curve_show_setting_dlg.exec();
}
void MeasureAnalysisParticleCountPlotView::onAutoFindPeaks()
{
}
void MeasureAnalysisParticleCountPlotView::onEneryScale()
{
}
void MeasureAnalysisParticleCountPlotView::onPlotConfigure()
{
}

View File

@ -5,6 +5,7 @@
#include <QWidget>
#include "MeasureAnalysisView.h"
class QMenu;
class CustomQwtPlot;
class MeasureAnalysisParticleCountPlotView : public MeasureAnalysisView
@ -16,11 +17,19 @@ public:
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set);
private:
void setupMenu();
void setupPlot();
void loadDataFromFile(const QString &data_name, const QString& filename);
private slots:
void onCurveShowSetting();
void onAutoFindPeaks();
void onEneryScale();
void onPlotConfigure();
private:
CustomQwtPlot* _plot { nullptr };
CustomQwtPlot* _plot = nullptr;
QMenu* _menu = nullptr;
};
#endif // MEASUREANALYSISPARTICLECOUNTPLOTVIEW_H

View File

@ -444,18 +444,20 @@ void MeasureAnalysisProjectModelList::AddProjectModel(MeasureAnalysisProjectMode
model->SaveProjectModel();
}
void MeasureAnalysisProjectModelList::RmProjectModel(const QString& project_name)
bool MeasureAnalysisProjectModelList::RmProjectModel(const QString& project_name)
{
if (!_project_node_items.contains(project_name)) {
return;
return false;
}
const QMap<QString, QStandardItem*> item_nodes = _project_node_items[project_name];
if (!item_nodes.contains(project_name) ) {
return;
return false;
}
QStandardItem* project_item = item_nodes[project_name];
if (project_item) {
this->RemoveNode(project_item);
if (!this->RemoveNode(project_item)) {
return false;
}
}
if (_project_models.contains(project_name)) {
delete _project_models[project_name];
@ -466,8 +468,7 @@ void MeasureAnalysisProjectModelList::RmProjectModel(const QString& project_name
const QString& project_name = project_model->GetProjectName();
SetCurrentProjectModel(project_name);
}
const QString& info_text = QStringLiteral(u"测试分析项\"%1\"已关闭.").arg(project_name);
LOG_INFO(info_text);
return true;
}
MeasureAnalysisProjectModel* MeasureAnalysisProjectModelList::GetProjectModel(const QString& project_name)
@ -489,9 +490,10 @@ void MeasureAnalysisProjectModelList::SetCurrentProjectModel(const QString& proj
_current_project_model = _project_models[project_name];
for (auto it = _project_node_items.constBegin(); it!=_project_node_items.constEnd(); ++it) {
const QString& temp_project_name = it.key();
const QMap<QString, QStandardItem*> item_nodes = it.value();
if ( item_nodes.contains(project_name) ) {
QStandardItem* project_item = item_nodes[project_name];
if ( item_nodes.contains(temp_project_name) ) {
QStandardItem* project_item = item_nodes[temp_project_name];
if (project_item) {
QFont font = project_item->font();
if ( it.key() == project_name ) {
@ -549,10 +551,10 @@ bool MeasureAnalysisProjectModelList::RemoveNode(QStandardItem* item)
return false;
const QString& project_name = item->data(ProjectName).toString();
if (AnalysisType::Project == item->data(NodeType).value<AnalysisType>()) {
QStandardItem* root_item = invisibleRootItem();
root_item->removeRow(item->row());
_project_node_items.remove(project_name);
delete item;
return true;
}
} else {
QStandardItem* parent_item = item->parent();
if (!parent_item) {
return false;
@ -564,6 +566,7 @@ bool MeasureAnalysisProjectModelList::RemoveNode(QStandardItem* item)
_project_node_items[project_name].remove(node_name);
}
}
}
return true;
}

View File

@ -121,7 +121,7 @@ public:
virtual ~MeasureAnalysisProjectModelList();
void AddProjectModel(MeasureAnalysisProjectModel* model);
void RmProjectModel(const QString& project_name);
bool RmProjectModel(const QString& project_name);
MeasureAnalysisProjectModel* GetProjectModel(const QString& project_name);
MeasureAnalysisProjectModel* GetCurrentProjectModel();

View File

@ -23,6 +23,8 @@ include($${PROJECT_DIR}/3rdlib/QtAdvancedDockingSystem/ads.pri)
include($${PROJECT_DIR}/3rdlib/csv/csv.pri)
include($${PROJECT_DIR}/3rdlib/qwt/qwt.pri)
include(DataCalcProcess/DataCalcProcess.pri)
DESTDIR = $${BUILD_BIN}
OBJECTS_DIR = $${BUILD_OBJ}/$${TARGET}/objs
MOC_DIR = $${BUILD_MOC}/$${TARGET}/moc