diff --git a/src/DataProcessWorkPool.cpp b/src/DataProcessWorkPool.cpp index b50e793..ce3ae56 100644 --- a/src/DataProcessWorkPool.cpp +++ b/src/DataProcessWorkPool.cpp @@ -11,6 +11,10 @@ #include #include #include +#include +#include +#include +#include "DataCalcProcess/FindPeaksBySvd.h" using namespace DataProcessWorkPool; using namespace io; @@ -40,7 +44,7 @@ QObject* DataProcessTask::GetFinishedNotifier() const bool DataProcessTask::IsValidSetWorkParameters() const { - return !GetProjectName().isEmpty(); + return !(this->_project_name.isEmpty()); } void DataProcessTask::StartTask() @@ -75,7 +79,7 @@ const QString& ParticleDataTask::GetAllChannelParticleDataFilename() const bool ParticleDataTask::IsValidSetWorkParameters() const { - return (!GetAllChannelParticleDataFilename().isEmpty()) && (!DataProcessTask::IsValidSetWorkParameters()); + return (!GetAllChannelParticleDataFilename().isEmpty()) && DataProcessTask::IsValidSetWorkParameters(); } bool ParticleDataTask::processTask() @@ -543,3 +547,78 @@ bool ParticleDataSortTask::processEveryChannelParticleData() return ret_ok; } + +void AutoFindPeaksTask::SetAnalysisType(AnalysisType analysis_type) +{ + this->_analysis_type = analysis_type; +} + +void AutoFindPeaksTask::SetDataFileList(const QMap &data_files_set) +{ + this->_data_files_set = data_files_set; +} + +void AutoFindPeaksTask::SetResultDir(const QString &result_dir) +{ + this->_result_dir = result_dir; +} + +void AutoFindPeaksTask::SetFindPeakSetpWinWidth(int step_win_width) +{ + this->_step_win_width = step_win_width; +} + +bool AutoFindPeaksTask::IsValidSetWorkParameters() const +{ + return (!this->_data_files_set.isEmpty()) && (!this->_result_dir.isEmpty()) && DataProcessTask::IsValidSetWorkParameters(); +} + +bool AutoFindPeaksTask::processTask() +{ + QString result_filename = QDir(this->_result_dir).filePath("AutoFindPeaksResult.csv"); + std::ofstream out_file(QStrToSysPath(result_filename)); + std::string channel_str = QString(QStringLiteral(u"通道")).toStdString(); + std::string addr_str = QString(QStringLiteral(u"峰位")).toStdString(); + std::string left_addr_str = QString(QStringLiteral(u"左边界")).toStdString(); + std::string lright_addr_str = QString(QStringLiteral(u"右边界")).toStdString(); + std::string width_str = QString(QStringLiteral(u"峰宽")).toStdString(); + out_file << channel_str << "," << addr_str << "," << left_addr_str << "," << lright_addr_str << "," << width_str << "\n"; + + for (auto it = this->_data_files_set.begin(); it != this->_data_files_set.end(); ++it) { + const QString& debug = QStringLiteral(u"自动寻峰%1").arg(it.key()); + LOG_DEBUG(debug); + + std::string channel = it.key().toStdString(); + arma::mat data; + const std::string data_filename = QStrToSysPath(it.value().toString()); + if (!data.load(data_filename, arma::csv_ascii)) { + QString error = QString(QStringLiteral(u"%1自动寻峰数据文件%2加载异常!")).arg(it.key()).arg(it.value().toString()); + LOG_WARN(error); + continue; + } + FindPeaksBySvd peak_svd; + std::vector peak_info_vec = peak_svd.FindPeaks(data.col(1), this->_step_win_width); + if (!peak_info_vec.empty()) { + for(auto peak_info : peak_info_vec) { + int addr = data.at(peak_info.pos, 0); + int left = data.at(peak_info.left, 0); + int right = data.at(peak_info.left + peak_info.width, 0); + int width = peak_info.width; + out_file << channel << "," << addr << "," << left << "," << right << "," << width << "\n"; + } + } else { + const QString& error = QStringLiteral(u"%1自动寻峰异常!").arg(it.key()); + LOG_WARN(error); + } + } + + const QString& project_name = GetProjectName(); + MeasureAnalysisProjectModel* project_model = ProjectList::Instance()->GetProjectModel(project_name); + if (project_model == nullptr) { + return false; + } else { + project_model->SetAnalysisCustomData(this->_analysis_type, QString("AutoFindPeaksResult"), result_filename); + } + + return true; +} diff --git a/src/DataProcessWorkPool.h b/src/DataProcessWorkPool.h index c11179b..7277117 100644 --- a/src/DataProcessWorkPool.h +++ b/src/DataProcessWorkPool.h @@ -4,6 +4,9 @@ #include #include #include +#include "AnalysisTypeDefine.h" +#include +#include namespace DataProcessWorkPool { @@ -18,7 +21,7 @@ namespace DataProcessWorkPool virtual bool IsValidSetWorkParameters() const; void StartTask(); - virtual void run() override; + virtual void run() override final; private: virtual bool processTask() = 0; @@ -35,7 +38,7 @@ namespace DataProcessWorkPool void SetAllChannelParticleDataFilename(const QString& all_channel_particle_data_filename); const QString& GetAllChannelParticleDataFilename() const; - virtual bool IsValidSetWorkParameters() const; + virtual bool IsValidSetWorkParameters() const override; private: virtual bool processTask() final; @@ -80,12 +83,28 @@ namespace DataProcessWorkPool void SetSortedResultDir(const QString& sorted_result_dir); const QString& GetSortedResultDir() const; - virtual bool IsValidSetWorkParameters() const; + virtual bool IsValidSetWorkParameters() const override; private: virtual bool processEveryChannelParticleData() override; private: QString _sorted_result_dir; }; + + class AutoFindPeaksTask : public DataProcessTask { + public: + void SetAnalysisType(AnalysisType analysis_type); + void SetDataFileList(const QMap& data_files_set); + void SetResultDir(const QString& result_dir); + void SetFindPeakSetpWinWidth(int step_win_width); + virtual bool IsValidSetWorkParameters() const override; + private: + virtual bool processTask() override; + private: + AnalysisType _analysis_type; + QMap _data_files_set; + QString _result_dir; + int _step_win_width = 7; + }; } #endif // DATAPROCESSWORKPOOL_H diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 836bb15..e6a9e52 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -52,17 +52,17 @@ void MainWindow::OutputInfo(OutputInfoType out_type, const QString& ouput_info) .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")) .arg(list_str_out_type.at(int(out_type))) .arg(ouput_info); - QTextCharFormat cur_fmt, fmt; - fmt.setForeground(QBrush(list_color_out_type.at(out_type))); + // QTextCharFormat cur_fmt, fmt; + // fmt.setForeground(QBrush(list_color_out_type.at(out_type))); _s_mutex_info_output.lock(); - cur_fmt = _s_plain_edit_info_output->currentCharFormat(); - _s_plain_edit_info_output->mergeCurrentCharFormat(fmt); + // cur_fmt = _s_plain_edit_info_output->currentCharFormat(); + // _s_plain_edit_info_output->mergeCurrentCharFormat(fmt); _s_plain_edit_info_output->appendPlainText(ouput_text); - _s_plain_edit_info_output->setCurrentCharFormat(cur_fmt); - QScrollBar* scrollbar = _s_plain_edit_info_output->verticalScrollBar(); - if (scrollbar) { - scrollbar->setSliderPosition(scrollbar->maximum()); - } + // _s_plain_edit_info_output->setCurrentCharFormat(cur_fmt); + // QScrollBar* scrollbar = _s_plain_edit_info_output->verticalScrollBar(); + // if (scrollbar) { + // scrollbar->setSliderPosition(scrollbar->maximum()); + // } _s_plain_edit_info_output->update(); _s_mutex_info_output.unlock(); } diff --git a/src/MeasureAnalysisDataTableView.cpp b/src/MeasureAnalysisDataTableView.cpp index 3a02ca1..ee1642c 100644 --- a/src/MeasureAnalysisDataTableView.cpp +++ b/src/MeasureAnalysisDataTableView.cpp @@ -20,6 +20,11 @@ MeasureAnalysisDataTableView::MeasureAnalysisDataTableView(QWidget* parent) layout->addWidget(_tableView); } +void MeasureAnalysisDataTableView::InitViewWorkspace(const QString &project_name) +{ + Q_UNUSED(project_name); +} + void MeasureAnalysisDataTableView::SetAnalyzeDataFilename(const QMap &data_files_set) { if (data_files_set.isEmpty()) { diff --git a/src/MeasureAnalysisDataTableView.h b/src/MeasureAnalysisDataTableView.h index d489107..f3edbf9 100644 --- a/src/MeasureAnalysisDataTableView.h +++ b/src/MeasureAnalysisDataTableView.h @@ -16,6 +16,7 @@ class MeasureAnalysisDataTableView : public MeasureAnalysisView public: MeasureAnalysisDataTableView(QWidget *parent = nullptr); + virtual void InitViewWorkspace(const QString& project_name) override final; virtual void SetAnalyzeDataFilename(const QMap& data_files_set); private: diff --git a/src/MeasureAnalysisParticleCountPlotView.cpp b/src/MeasureAnalysisParticleCountPlotView.cpp index ddd172f..70c7fdf 100644 --- a/src/MeasureAnalysisParticleCountPlotView.cpp +++ b/src/MeasureAnalysisParticleCountPlotView.cpp @@ -15,6 +15,13 @@ #include #include #include +#include "MeasureAnalysisProjectModel.h" +#include +#include "DataProcessWorkPool.h" +#include +#include +#include +#include MeasureAnalysisParticleCountPlotView::MeasureAnalysisParticleCountPlotView(QWidget* parent) : MeasureAnalysisView { parent } @@ -31,6 +38,24 @@ MeasureAnalysisParticleCountPlotView::MeasureAnalysisParticleCountPlotView(QWidg setupMenu(); } +void MeasureAnalysisParticleCountPlotView::InitViewWorkspace(const QString &project_name) +{ + if (project_name.isEmpty()) { + return; + } + auto project_model = ProjectList::Instance()->GetProjectModel(project_name); + if ( !project_model ) { + return; + } + QDir project_dir(project_model->GetProjectDir()); + QString workspace = project_dir.filePath("AddressCountSpectrumView"); + if ( QDir(workspace).exists() ) { + this->_workspace = workspace; + } else if (project_dir.mkpath(workspace) ) { + this->_workspace = workspace; + } +} + void MeasureAnalysisParticleCountPlotView::SetAnalyzeDataFilename(const QMap& data_files_set) { auto extractNumber = [](const QString& str) { @@ -54,6 +79,7 @@ void MeasureAnalysisParticleCountPlotView::SetAnalyzeDataFilename(const QMap_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); + QMenu* menu_find_peaks = this->_menu->addMenu(QStringLiteral(u"寻峰")); + QAction* action_find_peaks_result = menu_find_peaks->addAction(QStringLiteral(u"寻峰结果")); + action_find_peaks_result->setObjectName("manual_find_peaks"); + connect(action_find_peaks_result, &QAction::triggered, this, &MeasureAnalysisParticleCountPlotView::onFindPeaksResult); + QAction* action_auto_find_peaks = menu_find_peaks->addAction(QStringLiteral(u"自动寻峰")); + action_auto_find_peaks->setObjectName("auto_find_peaks"); + connect(action_auto_find_peaks, &QAction::triggered, this, &MeasureAnalysisParticleCountPlotView::onAutoFindPeaks); + QAction* action_manual_find_peaks = menu_find_peaks->addAction(QStringLiteral(u"手动寻峰")); + action_manual_find_peaks->setObjectName("manual_find_peaks"); + connect(action_auto_find_peaks, &QAction::triggered, this, &MeasureAnalysisParticleCountPlotView::onManualFindPeaks); 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); @@ -116,6 +149,7 @@ void MeasureAnalysisParticleCountPlotView::loadDataFromFile(const QString& data_ int address; int particle_count; QVector x, y; + while (reader.read_row(address, particle_count)) { x.push_back(address); y.push_back(particle_count); @@ -125,73 +159,203 @@ void MeasureAnalysisParticleCountPlotView::loadDataFromFile(const QString& data_ QwtPlotCurve* curve = new QwtPlotCurve(data_name); curve->setSamples(x, y); _plot->AddCurve(curve); - LOG_DEBUG(data_name); +} + +void MeasureAnalysisParticleCountPlotView::onAutoFindPeaksFinished(const QString &project_name) +{ + Q_UNUSED(project_name); + onFindPeaksResult(); } 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 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(); + if (!_curve_show_setting_dlg) { + _curve_show_setting_dlg = new QDialog(this, Qt::Dialog | Qt::WindowCloseButtonHint); + _curve_show_setting_dlg->setWindowTitle(QString(QStringLiteral(u"选择%1曲线显示").arg(this->_plot->title().text()))); + _curve_show_setting_dlg->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + _curve_show_setting_dlg->setWindowModality(Qt::WindowModal); + _curve_show_setting_dlg->setModal(false); + QVBoxLayout* layout = new QVBoxLayout(_curve_show_setting_dlg); + // 自动计算多列排布 + QMap 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(); }); - 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); + 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(); + layout->addLayout(button_layout); + layout->addLayout(checkbox_layout); + } + _curve_show_setting_dlg->show(); +} + +void MeasureAnalysisParticleCountPlotView::onFindPeaksResult() +{ + if (!_find_peaks_result_dlg) { + const QString& peaks_result_filename = QDir(this->_workspace).filePath("AutoFindPeaksResult.csv"); + + _find_peaks_result_dlg = new QDialog(this, Qt::Dialog | Qt::WindowCloseButtonHint); + _find_peaks_result_dlg->setWindowTitle(QString(QStringLiteral(u"寻峰结果"))); + _find_peaks_result_dlg->setWindowModality(Qt::WindowModal); + _find_peaks_result_dlg->setModal(false); + + QLabel* filter_channel_label = new QLabel(QString(QStringLiteral(u"筛选通道:"))); + QComboBox* filter_channel_combo_box = new QComboBox(); + filter_channel_combo_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + filter_channel_combo_box->addItem(QString(QStringLiteral(u"所有通道"))); + for (QwtPlotCurve* curve : this->_plot->GetCurveList()) { + filter_channel_combo_box->addItem(curve->title().text()); + } + QHBoxLayout* filter_channel_layout = new QHBoxLayout(); + filter_channel_layout->addWidget(filter_channel_label); + filter_channel_layout->addWidget(filter_channel_combo_box); + // filter_channel_layout->addStretch(); + + const QString& channel_col_name = QString(QStringLiteral(u"通道")); + const QString& peak_pos_col_name = QString(QStringLiteral(u"峰位")); + const QString& left_bound_col_name = QString(QStringLiteral(u"左边界")); + const QString& right_bound_col_name = QString(QStringLiteral(u"右边界")); + const QString& peak_width_col_name = QString(QStringLiteral(u"峰宽")); + QTableWidget* peaks_result_table = new QTableWidget(); + peaks_result_table->setColumnCount(5); + peaks_result_table->setHorizontalHeaderLabels({ + channel_col_name, peak_pos_col_name, left_bound_col_name, right_bound_col_name, peak_width_col_name + }); + peaks_result_table->setSelectionBehavior(QAbstractItemView::SelectRows); + peaks_result_table->setSelectionMode(QAbstractItemView::SingleSelection); + // 使用csv.h从peaks_result_filename CSV文件读取数据 + io::CSVReader< + 5, + io::trim_chars<' ', '\t'>, + io::double_quote_escape<',', '"'>, + io::throw_on_overflow, + io::empty_line_comment + > reader(QStrToSysPath(peaks_result_filename)); + reader.read_header(io::ignore_extra_column, + channel_col_name.toStdString(), + peak_pos_col_name.toStdString(), + left_bound_col_name.toStdString(), + right_bound_col_name.toStdString(), + peak_width_col_name.toStdString() + ); + std::string ch_name; int peak_pos; int left_bound, right_bound, peak_width; + while (reader.read_row(ch_name, peak_pos, left_bound, right_bound, peak_width)) + { + if (!ch_name.empty()) { + int row = peaks_result_table->rowCount(); + peaks_result_table->insertRow(row); + peaks_result_table->setItem(row, 0, new QTableWidgetItem(QString::fromStdString(ch_name))); + peaks_result_table->setItem(row, 1, new QTableWidgetItem(QString::number(peak_pos))); + peaks_result_table->setItem(row, 2, new QTableWidgetItem(QString::number(left_bound))); + peaks_result_table->setItem(row, 3, new QTableWidgetItem(QString::number(right_bound))); + peaks_result_table->setItem(row, 4, new QTableWidgetItem(QString::number(peak_width))); + } + } + connect(filter_channel_combo_box, &QComboBox::currentTextChanged, this, [this, peaks_result_table](const QString& text){ + auto row_count = peaks_result_table->rowCount(); + if (text == QString(QStringLiteral(u"所有通道"))) { + for (int i = 0; i < row_count - 1; i++) { + peaks_result_table->setRowHidden(i, false); + } + } else { + for (int i = row_count - 1; i >= 0 ; i--) { + const QString& channel = peaks_result_table->item(i, 0)->text(); + bool is_hidden = text == channel ? false : true; + peaks_result_table->setRowHidden(i, is_hidden); + } + } + }); + + QVBoxLayout* layout = new QVBoxLayout(_find_peaks_result_dlg); + layout->addLayout(filter_channel_layout); + layout->addWidget(peaks_result_table); + } + _find_peaks_result_dlg->show(); } void MeasureAnalysisParticleCountPlotView::onAutoFindPeaks() +{ + QDialog set_find_peak_step_win_width_dlg(this, Qt::Dialog | Qt::WindowCloseButtonHint); + set_find_peak_step_win_width_dlg.setWindowTitle(QString(QStringLiteral(u"设置自动寻峰步宽"))); + + QLabel* set_step_width_label = new QLabel(QString(QStringLiteral(u"自动寻峰步宽:"))); + QSpinBox * spinbox_set_step_width = new QSpinBox(); + spinbox_set_step_width->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + QVBoxLayout* layout_input = new QVBoxLayout(); + layout_input->addWidget(set_step_width_label); + layout_input->addWidget(spinbox_set_step_width); + + QPushButton* btn_ok = new QPushButton(QStringLiteral(u"确认")); + connect(btn_ok, &QPushButton::clicked, &set_find_peak_step_win_width_dlg, &QDialog::accept); + QPushButton* btn_cancel = new QPushButton(QStringLiteral(u"取消")); + connect(btn_ok, &QPushButton::clicked, &set_find_peak_step_win_width_dlg, &QDialog::reject); + QHBoxLayout* layout_btns = new QHBoxLayout(); + layout_btns->addStretch(); + layout_btns->addWidget(btn_ok); + layout_btns->addWidget(btn_cancel); + + QHBoxLayout* layout = new QHBoxLayout(&set_find_peak_step_win_width_dlg); + layout->addLayout(layout_input); + layout->addLayout(layout_btns); + + if (QDialog::Accepted == set_find_peak_step_win_width_dlg.exec() ) { + int step_width = spinbox_set_step_width->value(); + const QString& project_name = GetProjectName(); + auto auto_find_peaks_task = new DataProcessWorkPool::AutoFindPeaksTask; + auto_find_peaks_task->SetAnalysisType(this->GetAnalyzeType()); + auto_find_peaks_task->SetDataFileList(this->_data_files_set_ptr); + auto_find_peaks_task->SetFindPeakSetpWinWidth(step_width); + auto_find_peaks_task->SetResultDir(this->_workspace); + auto_find_peaks_task->SetFinishedNotifier(this, "onAutoFindPeaksFinished", project_name); + auto_find_peaks_task->StartTask(); + } + +} + +void MeasureAnalysisParticleCountPlotView::onManualFindPeaks() { } diff --git a/src/MeasureAnalysisParticleCountPlotView.h b/src/MeasureAnalysisParticleCountPlotView.h index c9b043b..d111290 100644 --- a/src/MeasureAnalysisParticleCountPlotView.h +++ b/src/MeasureAnalysisParticleCountPlotView.h @@ -5,6 +5,7 @@ #include #include "MeasureAnalysisView.h" +class QDialog; class QMenu; class CustomQwtPlot; @@ -14,22 +15,30 @@ class MeasureAnalysisParticleCountPlotView : public MeasureAnalysisView public: MeasureAnalysisParticleCountPlotView(QWidget *parent = nullptr); + virtual void InitViewWorkspace(const QString& project_name) override final; virtual void SetAnalyzeDataFilename(const QMap& data_files_set); private: void setupMenu(); void setupPlot(); void loadDataFromFile(const QString &data_name, const QString& filename); - +private slots: + void onAutoFindPeaksFinished(const QString& project_name); private slots: void onCurveShowSetting(); + void onFindPeaksResult(); void onAutoFindPeaks(); + void onManualFindPeaks(); void onEneryScale(); void onPlotConfigure(); private: + QString _workspace; CustomQwtPlot* _plot = nullptr; QMenu* _menu = nullptr; + QDialog* _curve_show_setting_dlg = nullptr; + QMap _data_files_set_ptr; + QDialog* _find_peaks_result_dlg = nullptr; }; #endif // MEASUREANALYSISPARTICLECOUNTPLOTVIEW_H diff --git a/src/MeasureAnalysisProjectModel.cpp b/src/MeasureAnalysisProjectModel.cpp index 052025e..cb620ee 100644 --- a/src/MeasureAnalysisProjectModel.cpp +++ b/src/MeasureAnalysisProjectModel.cpp @@ -102,6 +102,11 @@ void MeasureAnalysisProjectModel::SetTimeWinConformParticleData(uint time_win, u this->_time_win_conform_particle_data[time_win][conform_particle_count] = filename; } +void MeasureAnalysisProjectModel::SetAnalysisCustomData(AnalysisType analysis_type, const QString &data_item_name, const QString &data_filename) +{ + this->_analysis_custom_data_set[analysis_type][data_item_name] = data_filename; +} + const QString& MeasureAnalysisProjectModel::GetProjectDir() const { return this->_project_dir; @@ -224,6 +229,11 @@ const QMap& MeasureAnalysisProjectModel::GetTimeWinConformParticl return conform_particle_data; } +const QString &MeasureAnalysisProjectModel::GetAnalysisCustomData(AnalysisType analysis_type, const QString &data_item_name) +{ + return this->_analysis_custom_data_set.value(analysis_type).value(data_item_name); +} + bool MeasureAnalysisProjectModel::LoadProjectModel(const QString& project_filename) { this->_project_filename = project_filename; @@ -406,7 +416,6 @@ bool MeasureAnalysisProjectModel::SaveProjectModel() } - ////////////////////////////////////////////////////////////////////////////////////////// /* MeasureAnalysisProjectModelList */ ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/MeasureAnalysisProjectModel.h b/src/MeasureAnalysisProjectModel.h index a8bd215..48a5950 100644 --- a/src/MeasureAnalysisProjectModel.h +++ b/src/MeasureAnalysisProjectModel.h @@ -4,6 +4,7 @@ #include #include #include +#include "AnalysisTypeDefine.h" class MeasureAnalysisProjectModel { @@ -40,6 +41,8 @@ public: void SetTimeWinConformParticleData(uint time_win, uint conform_particle_count, const QString& filename); + void SetAnalysisCustomData(AnalysisType analysis_type, const QString& data_item_name, const QString& data_filename); + const QString& GetProjectDir() const; const QString& GetProjectName() const; SpectrumType GetSpectrumType() const; @@ -68,6 +71,8 @@ public: const QMap& GetTimeWinConformParticleDataFilenameList(uint time_win) const; + const QString& GetAnalysisCustomData(AnalysisType analysis_type, const QString& data_item_name); + private: QString _project_dir; QString _project_name; @@ -95,6 +100,8 @@ private: QMap > _time_win_conform_particle_data; + QMap > _analysis_custom_data_set; + public: bool LoadProjectModel(const QString& project_filename); bool SaveProjectModel(); diff --git a/src/MeasureAnalysisTreeView.cpp b/src/MeasureAnalysisTreeView.cpp index ff0c176..6ce53f8 100644 --- a/src/MeasureAnalysisTreeView.cpp +++ b/src/MeasureAnalysisTreeView.cpp @@ -64,6 +64,8 @@ void MeasureAnalysisTreeView::onNodeDoubleClicked(const QModelIndex& index) data_files_set[QStringLiteral(u"粒子数据")] = file_name; MeasureAnalysisView* view = MeasureAnalysisView::NewAnalyzeView(analysis_type); if ( view ) { + view->InitViewWorkspace(project_name); + view->SetProjectName(project_name); const auto& view_name = QStringLiteral(u"%1 [%2]").arg(item_text).arg(project_name); view->SetViewName(view_name); view->SetViewDescription(view_name); @@ -85,6 +87,8 @@ void MeasureAnalysisTreeView::onNodeDoubleClicked(const QModelIndex& index) data_files_set[QStringLiteral(u"通道%1道址计数").arg(ch_num)] = file_name; MeasureAnalysisView* view = MeasureAnalysisView::NewAnalyzeView(analysis_type); if ( view ) { + view->InitViewWorkspace(project_name); + view->SetProjectName(project_name); const auto& view_name = QStringLiteral(u"%1 [%2]").arg(item_text).arg(project_name); view->SetViewName(view_name); view->SetViewDescription(view_name); @@ -105,7 +109,7 @@ void MeasureAnalysisTreeView::onNodeDoubleClicked(const QModelIndex& index) for(auto ch_num : ch_num_list) { auto file_name = file_name_list[ch_num]; if ( !file_name.isEmpty() ) { - data_files_set[QStringLiteral(u"通道%1道址计数").arg(ch_num)] = file_name; + data_files_set[QStringLiteral(u"通道%1").arg(ch_num)] = file_name; } } MeasureAnalysisView* view = nullptr; @@ -113,6 +117,8 @@ void MeasureAnalysisTreeView::onNodeDoubleClicked(const QModelIndex& index) view = _item_views[item]; } else { view = MeasureAnalysisView::NewAnalyzeView(analysis_type); + view->InitViewWorkspace(project_name); + view->SetProjectName(project_name); const auto& view_name = QStringLiteral(u"%1 [%2]").arg(item_text).arg(project_name); view->SetViewName(view_name); view->SetViewDescription(view_name); diff --git a/src/MeasureAnalysisView.cpp b/src/MeasureAnalysisView.cpp index 8d7eed6..1503c62 100644 --- a/src/MeasureAnalysisView.cpp +++ b/src/MeasureAnalysisView.cpp @@ -106,6 +106,16 @@ MeasureAnalysisView::MeasureAnalysisView(QWidget* parent) _analysis_type = AnalysisType::None; } +void MeasureAnalysisView::SetProjectName(const QString &project_name) +{ + _project_name = project_name; +} + +const QString &MeasureAnalysisView::GetProjectName() const +{ + return _project_name; +} + AnalysisType MeasureAnalysisView::GetAnalyzeType() { return _analysis_type; diff --git a/src/MeasureAnalysisView.h b/src/MeasureAnalysisView.h index 9b88de8..0ec0265 100644 --- a/src/MeasureAnalysisView.h +++ b/src/MeasureAnalysisView.h @@ -25,6 +25,8 @@ public: explicit MeasureAnalysisView(QWidget* parent = nullptr); + void SetProjectName(const QString& project_name); + const QString& GetProjectName() const; AnalysisType GetAnalyzeType(); bool IsDeleteOnClose(); ViewType GetViewType(); @@ -32,6 +34,7 @@ public: void SetViewDescription(const QString& description); const QString& GetViewName() const; const QString& GetViewDescription() const; + virtual void InitViewWorkspace(const QString& project_name) = 0; virtual void SetAnalyzeDataFilename(const QMap& data_files_set) = 0; protected: @@ -40,6 +43,7 @@ protected: void setViewType(ViewType view_type); private: + QString _project_name; bool _delete_on_close = true; AnalysisType _analysis_type = AnalysisType::None; ViewType _view_type = ViewType::None;