From 91a5e30917b732d282de181b8e36dd0ce0a5d3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B5=B7?= Date: Wed, 4 Mar 2026 16:17:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=81=93=E5=9D=80=E8=AE=A1?= =?UTF-8?q?=E6=95=B0=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DataProcessWorkPool.cpp | 24 +++++----- src/MeasureAnalysisDataTableView.cpp | 4 +- src/MeasureAnalysisDataTableView.h | 2 +- src/MeasureAnalysisParticleCountPlotView.cpp | 4 +- src/MeasureAnalysisParticleCountPlotView.h | 2 +- src/MeasureAnalysisProjectModel.cpp | 16 +++---- src/MeasureAnalysisProjectModel.h | 6 +-- src/MeasureAnalysisTree.cpp | 49 ++++++++++++++++---- src/MeasureAnalysisTree.h | 5 ++ src/MeasureAnalysisTreeItem.cpp | 4 +- src/MeasureAnalysisView.h | 2 +- 11 files changed, 75 insertions(+), 43 deletions(-) diff --git a/src/DataProcessWorkPool.cpp b/src/DataProcessWorkPool.cpp index 6636a89..12833e1 100644 --- a/src/DataProcessWorkPool.cpp +++ b/src/DataProcessWorkPool.cpp @@ -208,7 +208,7 @@ bool EveryChannelParticleCountDataTask::processEveryChannelParticleData() QMap> channel_address_counts; // 通道号 -> 地址 -> 计数 // 统计所有通道的粒子计数(不同板卡号通道号相同道址) - QMap all_channel_address_counts; // 地址 -> 计数 + // QMap all_channel_address_counts; // 地址 -> 计数 std::string board_id_str = QString(QStringLiteral(u"板卡号")).toStdString(); std::string channel_id_str = QString(QStringLiteral(u"通道号")).toStdString(); @@ -239,7 +239,7 @@ bool EveryChannelParticleCountDataTask::processEveryChannelParticleData() channel_address_counts[channel_num][address]++; // 统计所有通道的粒子计数 - all_channel_address_counts[address]++; + // all_channel_address_counts[address]++; } // 写入每个通道的粒子计数数据(优化:使用一次打开文件,批量写入) @@ -274,16 +274,16 @@ bool EveryChannelParticleCountDataTask::processEveryChannelParticleData() channel_file_streams.clear(); // 写入所有通道的粒子计数数据 - all_channel_total_count_filename = all_ch_count_output_dir.filePath("AllChannelParticleTotalCountData.csv"); - std::ofstream all_channel_out(QStrToSysPath(all_channel_total_count_filename)); - all_channel_out << QString(QStringLiteral(u"道址")).toStdString() << "," << QString(QStringLiteral(u"计数")).toStdString() << std::endl; + // all_channel_total_count_filename = all_ch_count_output_dir.filePath("AllChannelParticleTotalCountData.csv"); + // std::ofstream all_channel_out(QStrToSysPath(all_channel_total_count_filename)); + // all_channel_out << QString(QStringLiteral(u"道址")).toStdString() << "," << QString(QStringLiteral(u"计数")).toStdString() << std::endl; - for (auto address_it = all_channel_address_counts.begin(); address_it != all_channel_address_counts.end(); ++address_it) { - uint address = address_it.key(); - uint count = address_it.value(); - all_channel_out << address << "," << count << std::endl; - } - all_channel_out.close(); + // for (auto address_it = all_channel_address_counts.begin(); address_it != all_channel_address_counts.end(); ++address_it) { + // uint address = address_it.key(); + // uint count = address_it.value(); + // all_channel_out << address << "," << count << std::endl; + // } + // all_channel_out.close(); } catch (const std::runtime_error& e) { QString error = QString(QStringLiteral(u"处理%1发生运行时异常:%2")).arg(all_channel_particle_data_filename).arg(e.what()); @@ -309,7 +309,7 @@ bool EveryChannelParticleCountDataTask::processEveryChannelParticleData() project_model->SetChannelParticleCountDataFilename(it.key(), it.value()); } // 更新项目模型中的所有通道粒子总计数数据文件名 - project_model->SetAllChannelParticleTotalCountDataFilename(all_channel_total_count_filename); + // project_model->SetAllChannelParticleTotalCountDataFilename(all_channel_total_count_filename); } return ret_ok; diff --git a/src/MeasureAnalysisDataTableView.cpp b/src/MeasureAnalysisDataTableView.cpp index 3bdec42..d9034c9 100644 --- a/src/MeasureAnalysisDataTableView.cpp +++ b/src/MeasureAnalysisDataTableView.cpp @@ -20,12 +20,12 @@ MeasureAnalysisDataTableView::MeasureAnalysisDataTableView(QWidget* parent) layout->addWidget(_tableView); } -void MeasureAnalysisDataTableView::SetAnalyzeDataFilename(const QMap &data_files_set) +void MeasureAnalysisDataTableView::SetAnalyzeDataFilename(const QMap &data_files_set) { if (data_files_set.isEmpty()) { return; } - auto csv_ddata_source = std::make_shared(data_files_set.first()); + auto csv_ddata_source = std::make_shared(data_files_set.first().toString()); if (!csv_ddata_source->isValid()) { return; } diff --git a/src/MeasureAnalysisDataTableView.h b/src/MeasureAnalysisDataTableView.h index fa75753..d489107 100644 --- a/src/MeasureAnalysisDataTableView.h +++ b/src/MeasureAnalysisDataTableView.h @@ -16,7 +16,7 @@ class MeasureAnalysisDataTableView : public MeasureAnalysisView public: MeasureAnalysisDataTableView(QWidget *parent = nullptr); - virtual void SetAnalyzeDataFilename(const QMap& data_files_set); + virtual void SetAnalyzeDataFilename(const QMap& data_files_set); private: // 私有成员变量 diff --git a/src/MeasureAnalysisParticleCountPlotView.cpp b/src/MeasureAnalysisParticleCountPlotView.cpp index f90be70..11b39bf 100644 --- a/src/MeasureAnalysisParticleCountPlotView.cpp +++ b/src/MeasureAnalysisParticleCountPlotView.cpp @@ -12,10 +12,10 @@ MeasureAnalysisParticleCountPlotView::MeasureAnalysisParticleCountPlotView(QWidg _custom_plot->setGeometry(0, 0, this->width(), this->height()); } -void MeasureAnalysisParticleCountPlotView::SetAnalyzeDataFilename(const QMap& data_files_set) +void MeasureAnalysisParticleCountPlotView::SetAnalyzeDataFilename(const QMap &data_files_set) { for (auto it = data_files_set.begin(); it != data_files_set.end(); ++it) { - loadDataFromFile(it.value()); + loadDataFromFile(it.value().toString()); } } diff --git a/src/MeasureAnalysisParticleCountPlotView.h b/src/MeasureAnalysisParticleCountPlotView.h index dab8e9d..322a190 100644 --- a/src/MeasureAnalysisParticleCountPlotView.h +++ b/src/MeasureAnalysisParticleCountPlotView.h @@ -13,7 +13,7 @@ class MeasureAnalysisParticleCountPlotView : public MeasureAnalysisView public: MeasureAnalysisParticleCountPlotView(QWidget *parent = nullptr); - virtual void SetAnalyzeDataFilename(const QMap& data_files_set); + virtual void SetAnalyzeDataFilename(const QMap& data_files_set); private: void setupCustomPlot(); diff --git a/src/MeasureAnalysisProjectModel.cpp b/src/MeasureAnalysisProjectModel.cpp index 1ee19ca..92ac6d4 100644 --- a/src/MeasureAnalysisProjectModel.cpp +++ b/src/MeasureAnalysisProjectModel.cpp @@ -75,10 +75,10 @@ void MeasureAnalysisProjectModel::SetChannelParticleCountDataFilename(uint chann this->_channel_particle_count_data_filename_list[channel] = filename; } -void MeasureAnalysisProjectModel::SetAllChannelParticleTotalCountDataFilename(const QString& filename) -{ - this->_all_channel_particle_total_count_data_filename = filename; -} +// void MeasureAnalysisProjectModel::SetAllChannelParticleTotalCountDataFilename(const QString& filename) +// { +// this->_all_channel_particle_total_count_data_filename = filename; +// } void MeasureAnalysisProjectModel::SetTimeWinConformParticleData(uint time_win, uint conform_particle_count, const QString& filename) { @@ -170,10 +170,10 @@ const QString& MeasureAnalysisProjectModel::GetChannelParticleCountDataFilename( return this->_channel_particle_count_data_filename_list[channel]; } -const QString& MeasureAnalysisProjectModel::GetAllChannelParticleTotalCountDataFilename() const -{ - return this->_all_channel_particle_total_count_data_filename; -} +// const QString& MeasureAnalysisProjectModel::GetAllChannelParticleTotalCountDataFilename() const +// { +// return this->_all_channel_particle_total_count_data_filename; +// } const QString& MeasureAnalysisProjectModel::GetTimeWinConformParticleDataFilename(uint time_win, uint conform_particle_count) const { diff --git a/src/MeasureAnalysisProjectModel.h b/src/MeasureAnalysisProjectModel.h index 4abd221..28dd00b 100644 --- a/src/MeasureAnalysisProjectModel.h +++ b/src/MeasureAnalysisProjectModel.h @@ -32,7 +32,7 @@ public: void SetSortedParticleDataFilename(const QString& filename); void SetChannelParticleDataFilename(uint channel, const QString& filename); void SetChannelParticleCountDataFilename(uint channel, const QString& filename); - void SetAllChannelParticleTotalCountDataFilename(const QString& filename); + // void SetAllChannelParticleTotalCountDataFilename(const QString& filename); void SetTimeWinConformParticleData(uint time_win, uint conform_particle_count, const QString& filename); const QString& GetProjectDir() const; @@ -52,7 +52,7 @@ public: const QString& GetChannelParticleDataFilename(uint channel) const; const QMap& GetChannelParticleCountDataFilenameList() const; const QString& GetChannelParticleCountDataFilename(uint channel) const; - const QString& GetAllChannelParticleTotalCountDataFilename() const; + // const QString& GetAllChannelParticleTotalCountDataFilename() const; const QString& GetTimeWinConformParticleDataFilename(uint time_win, uint conform_particle_count) const; private: @@ -74,7 +74,7 @@ private: QString _sorted_particle_data_filename; QMap _channel_particle_data_filename_list; QMap _channel_particle_count_data_filename_list; - QString _all_channel_particle_total_count_data_filename; + // QString _all_channel_particle_total_count_data_filename; QMap _time_win_conform_particle_data; }; diff --git a/src/MeasureAnalysisTree.cpp b/src/MeasureAnalysisTree.cpp index 43b2e6a..425771a 100644 --- a/src/MeasureAnalysisTree.cpp +++ b/src/MeasureAnalysisTree.cpp @@ -118,6 +118,7 @@ void TreeWidget::SetConnectActions(MeasureAnalysisActions* const actions_analyze }); connect(actions_analyze, &MeasureAnalysisActions::addMeasureAnalysisProject, [this]() { + }); connect(actions_analyze, &MeasureAnalysisActions::rmMeasureAnalysisProject, [this]() { removeAnalyzeItem(); @@ -126,6 +127,7 @@ void TreeWidget::SetConnectActions(MeasureAnalysisActions* const actions_analyze }); connect(actions_analyze, &MeasureAnalysisActions::addAnalyzeView, [this]() { + }); connect(actions_analyze, &MeasureAnalysisActions::rmAnalyzeView, [this]() { @@ -146,11 +148,14 @@ void TreeWidget::AddProjectModel(MeasureAnalysisProjectModel* model) TreeItem* tree_item_analyze_data_group = new_item->GetAnalyzeDataGroupItem(); if (tree_item_analyze_data_group) { const QString& all_ch_particle_data_filename = model->GetAllChannelParticleDataFilename(); + QMap data_files_set; + data_files_set[QStringLiteral(u"测量粒子数据")] = all_ch_particle_data_filename; + TreeItem* new_item_particle_data = new TreeItem; new_item_particle_data->SetName(QStringLiteral(u"测量粒子数据")); new_item_particle_data->SetType(TreeItemType::ParticleData); new_item_particle_data->SetDescription(all_ch_particle_data_filename); - new_item_particle_data->setData(0, Qt::UserRole, all_ch_particle_data_filename); + new_item_particle_data->setData(0, Qt::UserRole, data_files_set); tree_item_analyze_data_group->insertChild(0, new_item_particle_data); this->expandItem(tree_item_analyze_data_group); } @@ -215,23 +220,29 @@ void TreeWidget::onFinishedParticleCountData(const QString& project_name) if (project_model) { TreeItem* tree_item_analyze_data_group = tree_item_analyze->GetAnalyzeDataGroupItem(); if (tree_item_analyze_data_group) { - const QString& all_ch_count_filename = project_model->GetAllChannelParticleTotalCountDataFilename(); + // const QString& all_ch_count_filename = project_model->GetAllChannelParticleTotalCountDataFilename(); + // QMap data_files_set; + // data_files_set[QStringLiteral(u"所有通道道址计数数据")] = all_ch_count_filename; + TreeItem* new_item_all_ch_count = new TreeItem; - new_item_all_ch_count->SetName(QStringLiteral(u"粒子计数数据")); - new_item_all_ch_count->SetType(TreeItemType::ParticleData); - new_item_all_ch_count->SetDescription(all_ch_count_filename); - new_item_all_ch_count->setData(0, Qt::UserRole, all_ch_count_filename); + new_item_all_ch_count->SetName(QStringLiteral(u"道址计数数据组")); + new_item_all_ch_count->SetType(TreeItemType::AnalyzeDataGroup); + new_item_all_ch_count->SetDescription(QStringLiteral(u"道址计数数据组,子节点包含所有通道道址的计数数据")); + // new_item_all_ch_count->setData(0, Qt::UserRole, data_files_set); tree_item_analyze_data_group->addChild(new_item_all_ch_count); auto ch_particle_count_filename_list = project_model->GetChannelParticleCountDataFilenameList(); for (auto it = ch_particle_count_filename_list.begin(); it != ch_particle_count_filename_list.end(); ++it) { uint ch_num = it.key(); const QString& ch_count_filename = it.value(); + QMap data_files_set; + data_files_set[QStringLiteral(u"通道%1道址计数数据").arg(ch_num)] = ch_count_filename; + TreeItem* new_item_every_ch_count_data = new TreeItem; - new_item_every_ch_count_data->SetName(QStringLiteral(u"通道%1粒子计数数据").arg(ch_num)); + new_item_every_ch_count_data->SetName(QStringLiteral(u"通道%1道址计数数据").arg(ch_num)); new_item_every_ch_count_data->SetType(TreeItemType::ParticleData); new_item_every_ch_count_data->SetDescription(ch_count_filename); - new_item_every_ch_count_data->setData(0, Qt::UserRole, ch_count_filename); + new_item_every_ch_count_data->setData(0, Qt::UserRole, data_files_set); new_item_all_ch_count->addChild(new_item_every_ch_count_data); } this->expandItem(tree_item_analyze_data_group); @@ -268,7 +279,7 @@ void TreeWidget::removeAnalyzeItem() auto current_item = this->currentItem(); if (current_item) { const QString& text_title = QStringLiteral(u"删除确认"); - const QString& text_msg = QStringLiteral(u"是否确定删除分析项\"%1\"?").arg(current_item->text(0)); + const QString& text_msg = QStringLiteral(u"是否确定删除\"%1\"?").arg(current_item->text(0)); if (QMessageBox::Yes == QMessageBox::question(nullptr, text_title, text_msg)) { TreeItem* tree_item = dynamic_cast(this->currentItem()); if (tree_item) { @@ -301,4 +312,22 @@ void TreeWidget::removeTreeItem(QTreeWidgetItem* const item) delete item; } -} // namespace MeasureAnalysisTree +} + +MeasureAnalysisTree::TreeMeasureAnalysisProjectItem *MeasureAnalysisTree::TreeWidget::getProjectItem(TreeItem *item) +{ + if (item) { + TreeItemType item_type = item->GetType(); + if (TreeItemType::MeasureAnalysisProject == item_type) { + return dynamic_cast(item); + } + } else { + item = dynamic_cast(item->parent()); + if (item) { + return getProjectItem(item); + } + } + return nullptr; +} + +// namespace MeasureAnalysisTree diff --git a/src/MeasureAnalysisTree.h b/src/MeasureAnalysisTree.h index 13b4e93..a75739a 100644 --- a/src/MeasureAnalysisTree.h +++ b/src/MeasureAnalysisTree.h @@ -12,6 +12,7 @@ namespace MeasureAnalysisTree { class MeasureAnalysisActions; class TreeAnalyzeItem; class TreeItem; +class TreeMeasureAnalysisProjectItem; class TreeWidget : public QTreeWidget { Q_OBJECT @@ -23,6 +24,10 @@ public: void SetConnectActions(MeasureAnalysisActions* const actions_analyze); void AddProjectModel(MeasureAnalysisProjectModel* model); +private: + TreeMeasureAnalysisProjectItem* getProjectItem(TreeItem* item); + + private slots: // void onFinishedSeparateEveryChannelParticleData(const QString& project_name); void onFinishedParticleSortData(const QString& project_name); diff --git a/src/MeasureAnalysisTreeItem.cpp b/src/MeasureAnalysisTreeItem.cpp index f30a17a..915dee2 100644 --- a/src/MeasureAnalysisTreeItem.cpp +++ b/src/MeasureAnalysisTreeItem.cpp @@ -65,9 +65,7 @@ void TreeItem::NewAnalyzeView(const QString &name, const QString &description, c this->_ptr_analyze_view = MeasureAnalysisView::NewAnalyzeView(view_type_text); this->_ptr_analyze_view->SetViewName(name); this->_ptr_analyze_view->SetViewDescription(description); - const QString& data_filename = this->data(0, Qt::UserRole).toString(); - QMap data_files_set; - data_files_set[name] = data_filename; + const QMap& data_files_set = this->data(0, Qt::UserRole).toMap(); this->_ptr_analyze_view->SetAnalyzeDataFilename(data_files_set); } diff --git a/src/MeasureAnalysisView.h b/src/MeasureAnalysisView.h index eb29e05..9d0fd19 100644 --- a/src/MeasureAnalysisView.h +++ b/src/MeasureAnalysisView.h @@ -38,7 +38,7 @@ public: void SetViewDescription(const QString& description); const QString& GetViewName() const; const QString& GetViewDescription() const; - virtual void SetAnalyzeDataFilename(const QMap& data_files_set) = 0; + virtual void SetAnalyzeDataFilename(const QMap& data_files_set) = 0; protected: void setAnalyzeViewType(ViewType type);