diff --git a/src/DataProcessWorkPool.cpp b/src/DataProcessWorkPool.cpp index 50faab5..b50e793 100644 --- a/src/DataProcessWorkPool.cpp +++ b/src/DataProcessWorkPool.cpp @@ -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) diff --git a/src/DataProcessWorkPool.h b/src/DataProcessWorkPool.h index 21a0b30..c11179b 100644 --- a/src/DataProcessWorkPool.h +++ b/src/DataProcessWorkPool.h @@ -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 diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index c5143ff..836bb15 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -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); + } } } diff --git a/src/MeasureAnalysisParticleCountPlotView.cpp b/src/MeasureAnalysisParticleCountPlotView.cpp index 5485d01..ddd172f 100644 --- a/src/MeasureAnalysisParticleCountPlotView.cpp +++ b/src/MeasureAnalysisParticleCountPlotView.cpp @@ -9,6 +9,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include 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& data_files_set) @@ -47,6 +56,26 @@ void MeasureAnalysisParticleCountPlotView::SetAnalyzeDataFilename(const QMapsetContextMenuPolicy(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 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() +{ + +} diff --git a/src/MeasureAnalysisParticleCountPlotView.h b/src/MeasureAnalysisParticleCountPlotView.h index 68ffbbd..c9b043b 100644 --- a/src/MeasureAnalysisParticleCountPlotView.h +++ b/src/MeasureAnalysisParticleCountPlotView.h @@ -5,6 +5,7 @@ #include #include "MeasureAnalysisView.h" +class QMenu; class CustomQwtPlot; class MeasureAnalysisParticleCountPlotView : public MeasureAnalysisView @@ -16,11 +17,19 @@ public: 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 onCurveShowSetting(); + void onAutoFindPeaks(); + void onEneryScale(); + void onPlotConfigure(); + private: - CustomQwtPlot* _plot { nullptr }; + CustomQwtPlot* _plot = nullptr; + QMenu* _menu = nullptr; }; #endif // MEASUREANALYSISPARTICLECOUNTPLOTVIEW_H diff --git a/src/MeasureAnalysisProjectModel.cpp b/src/MeasureAnalysisProjectModel.cpp index 3ba2e0a..052025e 100644 --- a/src/MeasureAnalysisProjectModel.cpp +++ b/src/MeasureAnalysisProjectModel.cpp @@ -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 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 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,19 +551,20 @@ bool MeasureAnalysisProjectModelList::RemoveNode(QStandardItem* item) return false; const QString& project_name = item->data(ProjectName).toString(); if (AnalysisType::Project == item->data(NodeType).value()) { + QStandardItem* root_item = invisibleRootItem(); + root_item->removeRow(item->row()); _project_node_items.remove(project_name); - delete item; - return true; - } - QStandardItem* parent_item = item->parent(); - if (!parent_item) { - return false; - } - parent_item->removeRow(item->row()); - const QString& node_name = item->text(); - if (_project_node_items.contains(project_name)) { - if (_project_node_items[project_name].contains(node_name)) { - _project_node_items[project_name].remove(node_name); + } else { + QStandardItem* parent_item = item->parent(); + if (!parent_item) { + return false; + } + parent_item->removeRow(item->row()); + const QString& node_name = item->text(); + if (_project_node_items.contains(project_name)) { + if (_project_node_items[project_name].contains(node_name)) { + _project_node_items[project_name].remove(node_name); + } } } return true; diff --git a/src/MeasureAnalysisProjectModel.h b/src/MeasureAnalysisProjectModel.h index 28b347d..a8bd215 100644 --- a/src/MeasureAnalysisProjectModel.h +++ b/src/MeasureAnalysisProjectModel.h @@ -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(); diff --git a/src/src.pro b/src/src.pro index a67937f..567ea2a 100644 --- a/src/src.pro +++ b/src/src.pro @@ -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