226 lines
9.3 KiB
C++
226 lines
9.3 KiB
C++
#include "NewMeasureAnalysisDlg.h"
|
|
#include "ui_NewMeasureAnalysisDlg.h"
|
|
#include "MeasureAnalysisProjectModel.h"
|
|
#include <QDir>
|
|
#include <QMessageBox>
|
|
#include <QFileDialog>
|
|
#include <QFileInfo>
|
|
#include <QTimer>
|
|
#include "DataProcessWorkPool.h"
|
|
|
|
NewMeasureAnalysisDlg::NewMeasureAnalysisDlg(QWidget *parent)
|
|
: QDialog(parent)
|
|
, ui(new Ui::NewMeasureAnalysisDlg)
|
|
{
|
|
ui->setupUi(this);
|
|
initialization();
|
|
|
|
this->_task_wait_timer = new QTimer(this);
|
|
this->_task_wait_timer->setInterval(200);
|
|
connect(this->_task_wait_timer, &QTimer::timeout, [this](){
|
|
int progress = ui->progressBar->value();
|
|
if ( progress >= ui->progressBar->maximum() )
|
|
progress = 0;
|
|
ui->progressBar->setValue(progress + 10);
|
|
});
|
|
}
|
|
|
|
NewMeasureAnalysisDlg::~NewMeasureAnalysisDlg()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void NewMeasureAnalysisDlg::initialization()
|
|
{
|
|
ui->progressBar->setVisible(false);
|
|
|
|
QRegExp rx(R"(^[^\\/:*?"<>|]+$)");
|
|
QValidator *validator = new QRegExpValidator(rx, this);
|
|
ui->lineEdit_name->setValidator(validator);
|
|
|
|
ui->rbtn_sample_spec->setChecked(true);
|
|
connect(ui->rbtn_sample_spec, &QRadioButton::toggled, [this](bool checked){
|
|
ui->label_is_std_source->setEnabled(checked);
|
|
ui->checkBox_is_std_source->setEnabled(checked);
|
|
});
|
|
ui->label_is_std_source->setEnabled(true);
|
|
ui->checkBox_is_std_source->setEnabled(true);
|
|
|
|
ui->checkBox_file_data->setChecked(false);
|
|
ui->label_filename->setEnabled(false);
|
|
ui->lineEdit_filename->setEnabled(false);
|
|
ui->btn_filename->setEnabled(false);
|
|
connect(ui->checkBox_file_data, &QCheckBox::toggled, [this](bool checked){
|
|
ui->label_filename->setEnabled(checked);
|
|
ui->lineEdit_filename->setEnabled(checked);
|
|
ui->btn_filename->setEnabled(checked);
|
|
|
|
ui->spinBox_measure_preset_time->setEnabled(!checked);
|
|
ui->spinBox_conform_time->setEnabled(!checked);
|
|
});
|
|
|
|
connect(ui->btn_filename, &QPushButton::clicked, [this](){
|
|
const QString& filename = QFileDialog::getOpenFileName(this, QStringLiteral(u"选择粒子数据文件"), QString(), QStringLiteral(u"CSV (*.csv);;GVF (*.gvf)"));
|
|
if (filename.isEmpty()) {
|
|
return;
|
|
}
|
|
QFileInfo file_info(filename);
|
|
if (file_info.size() == 0) {
|
|
QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"选择的粒子数据文件为空文件!"));
|
|
return;
|
|
}
|
|
ui->lineEdit_filename->setText(file_info.fileName());
|
|
ui->lineEdit_filename->setProperty("data_file_path", filename);
|
|
});
|
|
|
|
ui->btn_ok->setEnabled(false);
|
|
auto turnStackPageBtnState = [this](){
|
|
int last_stack_index = ui->stackedWidget->count() - 1;
|
|
int current_stack_index = ui->stackedWidget->currentIndex();
|
|
if ( current_stack_index > 0 ) {
|
|
ui->btn_previous_step->setEnabled(true);
|
|
} else {
|
|
ui->btn_previous_step->setEnabled(false);
|
|
}
|
|
if ( current_stack_index < last_stack_index ) {
|
|
ui->btn_next_step->setEnabled(true);
|
|
ui->btn_ok->setEnabled(false);
|
|
} else {
|
|
ui->btn_next_step->setEnabled(false);
|
|
ui->btn_ok->setEnabled(true);
|
|
}
|
|
};
|
|
|
|
ui->btn_previous_step->setEnabled(false);
|
|
connect(ui->btn_previous_step, &QPushButton::clicked, [turnStackPageBtnState, this](){
|
|
int current_stack_index = ui->stackedWidget->currentIndex();
|
|
if ( current_stack_index > 0 ) {
|
|
--current_stack_index;
|
|
}
|
|
ui->stackedWidget->setCurrentIndex(current_stack_index);
|
|
turnStackPageBtnState();
|
|
});
|
|
|
|
ui->btn_next_step->setEnabled(true);
|
|
connect(ui->btn_next_step, &QPushButton::clicked, [turnStackPageBtnState, this](){
|
|
int last_stack_index = ui->stackedWidget->count() - 1;
|
|
int current_stack_index = ui->stackedWidget->currentIndex();
|
|
if ( current_stack_index < last_stack_index ) {
|
|
++current_stack_index;
|
|
}
|
|
ui->stackedWidget->setCurrentIndex(current_stack_index);
|
|
turnStackPageBtnState();
|
|
});
|
|
|
|
connect(ui->btn_cancel, &QPushButton::clicked, this, &NewMeasureAnalysisDlg::reject);
|
|
}
|
|
|
|
void NewMeasureAnalysisDlg::newProject(const QString& particle_data_filename)
|
|
{
|
|
const QString& project_name = ui->lineEdit_name->text();
|
|
QString projects_dir_path = QDir(qApp->applicationDirPath()).filePath("Projects");
|
|
QDir projects_dir(projects_dir_path);
|
|
QString project_dir_path = projects_dir.filePath(project_name);
|
|
|
|
bool is_std_source = ui->checkBox_is_std_source->isChecked();
|
|
ulong measure_preset_time = ui->spinBox_measure_preset_time->value();
|
|
uint conform_time_win = ui->spinBox_conform_time->value();
|
|
QString description_info = ui->plainTextEdit_description->toPlainText();
|
|
MeasureAnalysisProjectModel::SpectrumType spec_type = MeasureAnalysisProjectModel::SpectrumType::None;
|
|
if (ui->rbtn_sample_spec->isChecked()) {
|
|
spec_type = MeasureAnalysisProjectModel::SpectrumType::Sample;
|
|
} else if (ui->rbtn_background_spec->isChecked()) {
|
|
spec_type = MeasureAnalysisProjectModel::SpectrumType::Background;
|
|
}
|
|
bool is_measure_complete = true;
|
|
MeasureAnalysisProjectModel* model = new MeasureAnalysisProjectModel;
|
|
model->SetProjectDir(project_dir_path);
|
|
model->SetProjectName(project_name);
|
|
model->SetSpectrumType(spec_type);
|
|
model->SetIsStdSource(is_std_source);
|
|
model->SetMeasurePresetTime(measure_preset_time);
|
|
model->SetConformTimeWin(conform_time_win);
|
|
model->SetDescriptionInfo(description_info);
|
|
model->SetAllChannelParticleDataFilename(particle_data_filename);
|
|
model->SetIsMeasureComplete(is_measure_complete);
|
|
ProjectList::Instance()->AddProjectModel(model);
|
|
NewMeasureAnalysisDlg::accept();
|
|
}
|
|
|
|
void NewMeasureAnalysisDlg::onNewProjectFromFileFinished(bool ok, const QString& project_name, const QVariant &data)
|
|
{
|
|
QString projects_dir_path = QDir(qApp->applicationDirPath()).filePath("Projects");
|
|
QDir projects_dir(projects_dir_path);
|
|
QString project_dir_path = projects_dir.filePath(project_name);
|
|
QDir project_dir(project_dir_path);
|
|
if (ok) {
|
|
QString all_channel_particle_data_filename = data.toString();
|
|
QFileInfo data_file_info(all_channel_particle_data_filename);
|
|
if ( data_file_info.exists(all_channel_particle_data_filename) ) {
|
|
this->newProject(all_channel_particle_data_filename);
|
|
}
|
|
} else {
|
|
project_dir.removeRecursively();
|
|
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));
|
|
}
|
|
this->_task_wait_timer->stop();
|
|
ui->progressBar->setVisible(false);
|
|
|
|
ui->stackedWidget->setEnabled(true);
|
|
ui->label_note->setEnabled(true);
|
|
ui->plainTextEdit_description->setEnabled(true);
|
|
ui->btn_previous_step->setEnabled(true);
|
|
ui->btn_next_step->setEnabled(true);
|
|
ui->btn_ok->setEnabled(true);
|
|
}
|
|
|
|
void NewMeasureAnalysisDlg::on_btn_ok_clicked()
|
|
{
|
|
const QString& project_name = ui->lineEdit_name->text();
|
|
if (project_name.isEmpty()) {
|
|
QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"请输入测量分析名称!"));
|
|
return;
|
|
}
|
|
QString projects_dir_path = QDir(qApp->applicationDirPath()).filePath("Projects");
|
|
QDir projects_dir(projects_dir_path);
|
|
QString project_dir_path = projects_dir.filePath(project_name);
|
|
QDir project_dir(project_dir_path);
|
|
if (project_dir.exists()) {
|
|
QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"测量分析名称已存在,请重新输入!"));
|
|
return;
|
|
}
|
|
project_dir.mkpath(project_dir_path);
|
|
if ( ui->checkBox_file_data->isChecked() ) {
|
|
const QString& data_file_path = ui->lineEdit_filename->property("data_file_path").toString();
|
|
if (data_file_path.isEmpty()) {
|
|
QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"请选择粒子数据文件!"));
|
|
return;
|
|
}
|
|
auto separate_task = new DataProcessWorkPool::ParticleDataSortTask;
|
|
separate_task->SetAllChannelParticleDataFilename(data_file_path);
|
|
separate_task->SetSortedResultDir(project_dir_path);
|
|
separate_task->SetFinishedNotifier(this, "onNewProjectFromFileFinished", project_name);
|
|
separate_task->StartTask();
|
|
|
|
ui->stackedWidget->setEnabled(false);
|
|
ui->label_note->setEnabled(false);
|
|
ui->plainTextEdit_description->setEnabled(false);
|
|
ui->btn_previous_step->setEnabled(false);
|
|
ui->btn_next_step->setEnabled(false);
|
|
ui->btn_ok->setEnabled(false);
|
|
|
|
ui->progressBar->setVisible(true);
|
|
this->_task_wait_timer->start();
|
|
} else {
|
|
this->newProject();
|
|
}
|
|
|
|
// const QString& result_data_dir = QDir(project_model->GetProjectDir()).filePath("EveryChannelParticleData");
|
|
// auto separate_task = new DataProcessWorkPool::EveryChannelParticleDataSeparateTask;
|
|
// separate_task->SetAllChannelParticleDataFilename(project_model->GetAllChannelParticleDataFilename());
|
|
// separate_task->SetResultDataDir(result_data_dir);
|
|
// separate_task->SetFinishedNotifier(this->_tree_measure_analysis, "onFinishedSeparateEveryChannelParticleData", project_name);
|
|
// separate_task->StartTask();
|
|
}
|