From 13471d93ab464999b90fef5fc14a56be48f3b2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B5=B7?= Date: Fri, 27 Mar 2026 12:01:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B5=8B=E9=87=8F=E5=88=86?= =?UTF-8?q?=E6=9E=90=E5=8E=86=E5=8F=B2=E7=AE=A1=E7=90=86=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MainWindow.cpp | 4 + src/MainWindow.h | 3 + .../MeasureAnalysisHistoryForm.cpp | 81 +++++++++++++++++-- .../MeasureAnalysisHistoryForm.h | 3 + .../MeasureAnalysisHistoryForm.ui | 32 ++++++-- src/MeasureAnalysisProjectModel.cpp | 1 + src/MeasureAnalysisProjectModel.h | 3 + src/NewMeasureAnalysisDlg.cpp | 1 + 8 files changed, 113 insertions(+), 15 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 47a43f4..b84368b 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -118,6 +118,7 @@ void MainWindow::initMainWindow() // Set central widget MeasureAnalysisHistoryForm* measure_analysis_history_form = new MeasureAnalysisHistoryForm; + connect(this, &MainWindow::newProject, measure_analysis_history_form, &MeasureAnalysisHistoryForm::onUpdateNewHistoryProject); CDockWidget* central_dock_widget = _dock_manager->createDockWidget(QStringLiteral(u"测量分析记录")); central_dock_widget->setWidget(measure_analysis_history_form); // central_dock_widget->setFeature(ads::CDockWidget::AllDockWidgetFeatures, true); @@ -156,6 +157,9 @@ void MainWindow::initAction() if (QDialog::Accepted == new_measure_analysis_dlg.exec()) { ProjectList* project_list_model = ProjectList::Instance(); auto project_model = project_list_model->GetCurrentProjectModel(); + + emit newProject(project_model->GetProjectName()); + const QString& all_channel_particle_data_filename = project_model->GetAllChannelParticleDataFilename(); if (!all_channel_particle_data_filename.isEmpty()) { const QString& all_ch_count_dir = project_model->GetProjectDir(); diff --git a/src/MainWindow.h b/src/MainWindow.h index 9176215..33d969f 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -49,6 +49,9 @@ private: void applyStyleSheet(); void closeProject(const QString &project_name); +signals: + void newProject(const QString &project_name); + protected: virtual void closeEvent(QCloseEvent* event) override; diff --git a/src/MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.cpp b/src/MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.cpp index bf0d95d..38d5891 100644 --- a/src/MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.cpp +++ b/src/MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include "GlobalDefine.h" MeasureAnalysisHistoryForm::MeasureAnalysisHistoryForm(QWidget* parent) : QWidget(parent) @@ -11,16 +13,19 @@ MeasureAnalysisHistoryForm::MeasureAnalysisHistoryForm(QWidget* parent) { ui->setupUi(this); + ui->linedit_query->setPlaceholderText(QStringLiteral(u"请输入查询测量分析项目名称的关键字")); + ui->tablew_history->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); ui->tablew_history->horizontalHeader()->setSectionResizeMode( ui->tablew_history->columnCount() - 1, QHeaderView::Stretch); ui->tablew_history->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter); - connect(ui->btn_query, &QPushButton::clicked, this, &MeasureAnalysisHistoryForm::onQueryHistory); + connect(ui->linedit_query, &QLineEdit::textChanged , this, &MeasureAnalysisHistoryForm::onQueryHistory); connect(ui->btn_remove, &QPushButton::clicked, this, &MeasureAnalysisHistoryForm::onRemoveSelectedProject); connect(ui->btn_select_all, &QPushButton::clicked, this, &MeasureAnalysisHistoryForm::onAllSelect); connect(ui->btn_reverse, &QPushButton::clicked, this, &MeasureAnalysisHistoryForm::onReverseSelect); connect(ui->tablew_history, &QTableWidget::cellDoubleClicked, this, &MeasureAnalysisHistoryForm::onTableCellDoubleClicked); + connect(ProjectList::Instance(), &MeasureAnalysisProjectModelList::removedProjectModel, this, &MeasureAnalysisHistoryForm::onUpdateCloseHistoryProject); loadHistoryInfo(); } @@ -64,6 +69,9 @@ void MeasureAnalysisHistoryForm::loadHistoryInfo() ui->tablew_history->setItem(row, 2, new QTableWidgetItem(spectrum_type_name)); const QString& is_std_source = project_model.GetIsStdSource() ? QStringLiteral(u"是") : QStringLiteral(u"否"); ui->tablew_history->setItem(row, 3, new QTableWidgetItem(is_std_source)); + ui->tablew_history->setItem(row, 4, new QTableWidgetItem()); + ui->tablew_history->setItem(row, 5, new QTableWidgetItem()); + ui->tablew_history->setItem(row, 6, new QTableWidgetItem()); ui->tablew_history->setItem(row, 7, new QTableWidgetItem(project_model.GetDescriptionInfo())); } } @@ -72,6 +80,13 @@ void MeasureAnalysisHistoryForm::loadHistoryInfo() void MeasureAnalysisHistoryForm::onQueryHistory() { const QString& query_text = ui->linedit_query->text(); + for (int row = 0; row < ui->tablew_history->rowCount(); ++row) { + QTableWidgetItem* item = ui->tablew_history->item(row, 0); + if (item) { + bool b_match = item->text().contains(query_text); + ui->tablew_history->setRowHidden(row, !b_match); + } + } } void MeasureAnalysisHistoryForm::onAllSelect() @@ -111,16 +126,29 @@ void MeasureAnalysisHistoryForm::onReverseSelect() void MeasureAnalysisHistoryForm::onRemoveSelectedProject() { + QMap selected_project_list; auto row_count = ui->tablew_history->rowCount(); for (int row = row_count - 1; row >= 0; --row) { if (Qt::Checked == ui->tablew_history->item(row, 0)->checkState()) { const QString& project_filename = ui->tablew_history->item(row, 0)->data(Qt::UserRole).toString(); - QFileInfo project_file_info(project_filename); - const QString& project_dir_path = project_file_info.absoluteDir().absolutePath(); - QDir(project_dir_path).removeRecursively(); - ui->tablew_history->removeRow(row); + selected_project_list[row] = project_filename; } } + if (selected_project_list.isEmpty()) { + QMessageBox::information(this, QStringLiteral(u"确认"), QStringLiteral(u"请选择想要删除的测量分析项目!")); + return; + } + if (QMessageBox::No == QMessageBox::question(this, QStringLiteral(u"确认"), QStringLiteral(u"是否删除选择的测量分析项目?"))) { + return; + } + for (int row : selected_project_list.keys()) { + QFileInfo project_file_info(selected_project_list.value(row)); + const QString& project_dir_path = project_file_info.absoluteDir().absolutePath(); + QDir(project_dir_path).removeRecursively(); + QDir(project_dir_path).rmdir(project_dir_path); + ui->tablew_history->removeRow(row); + LOG_INFO(QStringLiteral(u"测量分析项目\"%1\"已经删除.").arg(project_file_info.baseName())); + } } void MeasureAnalysisHistoryForm::onTableCellDoubleClicked(int row, int column) @@ -152,12 +180,51 @@ void MeasureAnalysisHistoryForm::onTableCellDoubleClicked(int row, int column) bool loaded = ProjectList::Instance()->AddProjectModel(model); if (loaded) { item->setCheckState(Qt::Unchecked); - item->setFlags(item->flags() & ~Qt::ItemIsUserCheckable); + item->setFlags(item->flags() & ~(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable)); + int row = item->row(); + for (int col = 1; col < ui->tablew_history->columnCount(); ++col) { + QTableWidgetItem* other_item = ui->tablew_history->item(row, col); + if (other_item) { + other_item->setFlags(other_item->flags() & ~(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable)); + } + } } else { - item->setFlags(item->flags() | Qt::ItemIsUserCheckable); + item->setFlags(item->flags() | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable); + int row = item->row(); + for (int col = 1; col < ui->tablew_history->columnCount(); ++col) { + QTableWidgetItem* other_item = ui->tablew_history->item(row, col); + if (other_item) { + other_item->setFlags(other_item->flags() | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + } + } } } emit openProject(project_filename); } } } + +void MeasureAnalysisHistoryForm::onUpdateCloseHistoryProject(const QString &project_name) +{ + for (int row = 0; row < ui->tablew_history->rowCount(); ++row) { + QTableWidgetItem* item = ui->tablew_history->item(row, 0); + if (item) { + if (project_name == item->text()) { + item->setFlags(item->flags() | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable); + int row = item->row(); + for (int col = 1; col < ui->tablew_history->columnCount(); ++col) { + QTableWidgetItem* other_item = ui->tablew_history->item(row, col); + if (other_item) { + other_item->setFlags(other_item->flags() | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + } + } + } + } + } +} + +void MeasureAnalysisHistoryForm::onUpdateNewHistoryProject(const QString &project_name) +{ + Q_UNUSED(project_name); + loadHistoryInfo(); +} diff --git a/src/MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.h b/src/MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.h index e37ca7d..b7f1fdf 100644 --- a/src/MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.h +++ b/src/MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.h @@ -23,6 +23,9 @@ private slots: void onReverseSelect(); void onRemoveSelectedProject(); void onTableCellDoubleClicked(int row, int column); + void onUpdateCloseHistoryProject(const QString& project_name); +public slots: + void onUpdateNewHistoryProject(const QString& project_name); signals: void openProject(const QString& project_filename); diff --git a/src/MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.ui b/src/MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.ui index 29e3e17..f963ed2 100644 --- a/src/MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.ui +++ b/src/MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.ui @@ -53,20 +53,36 @@ - 模糊查询: + 测量分析查询: - - - - - - 查询 + + + 100 + + + true + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 40 + 20 + + + + @@ -93,7 +109,7 @@ - Qt::NoFocus + Qt::StrongFocus Qt::DefaultContextMenu diff --git a/src/MeasureAnalysisProjectModel.cpp b/src/MeasureAnalysisProjectModel.cpp index fe6eca7..f4757fb 100644 --- a/src/MeasureAnalysisProjectModel.cpp +++ b/src/MeasureAnalysisProjectModel.cpp @@ -517,6 +517,7 @@ bool MeasureAnalysisProjectModelList::RmProjectModel(const QString& project_name const QString& project_name = project_model->GetProjectName(); SetCurrentProjectModel(project_name); } + emit removedProjectModel(project_name); return true; } diff --git a/src/MeasureAnalysisProjectModel.h b/src/MeasureAnalysisProjectModel.h index ad7ad4a..a9c14ea 100644 --- a/src/MeasureAnalysisProjectModel.h +++ b/src/MeasureAnalysisProjectModel.h @@ -146,6 +146,9 @@ private slots: void onCoincidenceProcessFinished(bool ok, const QString& project_name, const QVariant& data); void onEnergyScaleCoincidenceDataFinished(bool ok, const QString& project_name, const QVariant& data); +signals: + void removedProjectModel(const QString& project_name); + private: void intiProjectNodeStruce(MeasureAnalysisProjectModel *pro_model); diff --git a/src/NewMeasureAnalysisDlg.cpp b/src/NewMeasureAnalysisDlg.cpp index d99be93..30a4d39 100644 --- a/src/NewMeasureAnalysisDlg.cpp +++ b/src/NewMeasureAnalysisDlg.cpp @@ -161,6 +161,7 @@ void NewMeasureAnalysisDlg::onNewProjectFromFileFinished(bool ok, const QString& } } else { project_dir.removeRecursively(); + project_dir.rmdir(project_dir_path); const QString& data_file_path = ui->lineEdit_filename->property("data_file_path").toString(); QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"粒子数据%1异常,创建测量分析项目失败!").arg(data_file_path)); }