863 lines
36 KiB
C++
863 lines
36 KiB
C++
#include "MeasureAnalysisProjectModel.h"
|
|
#include "AnalysisTypeDefine.h"
|
|
#include "GlobalDefine.h"
|
|
#include <QFile>
|
|
#include <QDir>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
|
|
|
|
void MeasureAnalysisProjectModel::SetProjectDir(const QString& project_dir)
|
|
{
|
|
this->_project_dir = project_dir;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModel::SetProjectName(const QString& project_name)
|
|
{
|
|
this->_project_name = project_name;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModel::SetSpectrumType(MeasureAnalysisProjectModel::SpectrumType spec_type)
|
|
{
|
|
this->_spec_type = spec_type;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModel::SetIsStdSource(bool is_std_source)
|
|
{
|
|
this->_is_std_source = is_std_source;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModel::SetDescriptionInfo(const QString& description_info)
|
|
{
|
|
this->_description_info = description_info;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModel::SetMeasurePresetTime(ulong measure_preset_time)
|
|
{
|
|
this->_measure_preset_time = measure_preset_time;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModel::SetConformTimeWin(uint conform_time_win)
|
|
{
|
|
this->_conform_time_win = conform_time_win;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModel::SetIsMeasureComplete(bool is_measure_complete)
|
|
{
|
|
this->_is_measure_complete = is_measure_complete;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModel::SetMeasureDeviceParamsCfgFilename(const QString& filename)
|
|
{
|
|
this->_measure_device_params_cfg_filename = filename;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModel::SetEneryScaleFilename(const QString& filename)
|
|
{
|
|
this->_enery_scale_filename = filename;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModel::SetEfficiencyScaleFilename(const QString& filename)
|
|
{
|
|
this->_efficiency_scale_filename = filename;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModel::SetAllChannelParticleDataFilename(const QString& filename)
|
|
{
|
|
this->_all_channel_particle_data_filename = filename;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModel::SetSortedParticleDataFilename(const QString& filename)
|
|
{
|
|
this->_sorted_particle_data_filename = filename;
|
|
}
|
|
|
|
// void MeasureAnalysisProjectModel::SetChannelParticleDataFilename(uint channel, const QString& filename)
|
|
// {
|
|
// this->_channel_particle_data_filename_list[channel] = filename;
|
|
// }
|
|
|
|
void MeasureAnalysisProjectModel::SetChannelAddressCountDataFilename(uint channel, const QString& filename)
|
|
{
|
|
this->_channel_address_count_data_filename_list[channel] = filename;
|
|
}
|
|
|
|
// void MeasureAnalysisProjectModel::SetAllChannelParticleTotalCountDataFilename(const QString& filename)
|
|
// {
|
|
// this->_all_channel_particle_total_count_data_filename = filename;
|
|
// }
|
|
|
|
void MeasureAnalysisProjectModel::SetChannelEneryCountDataFilename(uint channel, const QString& filename)
|
|
{
|
|
this->_channel_enery_count_data_filename_list[channel] = filename;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModel::SetAllChannelEneryTotalCountDataFilename(const QString& filename)
|
|
{
|
|
this->_all_channel_enery_total_count_data_filename = filename;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModel::SetTimeWinConformParticleData(uint time_win, uint conform_particle_count, const QString& filename)
|
|
{
|
|
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;
|
|
}
|
|
|
|
const QString& MeasureAnalysisProjectModel::GetProjectName() const
|
|
{
|
|
return this->_project_name;
|
|
}
|
|
|
|
MeasureAnalysisProjectModel::SpectrumType MeasureAnalysisProjectModel::GetSpectrumType() const
|
|
{
|
|
return this->_spec_type;
|
|
}
|
|
|
|
bool MeasureAnalysisProjectModel::GetIsStdSource() const
|
|
{
|
|
return this->_is_std_source;
|
|
}
|
|
|
|
const QString& MeasureAnalysisProjectModel::GetDescriptionInfo() const
|
|
{
|
|
return this->_description_info;
|
|
}
|
|
|
|
ulong MeasureAnalysisProjectModel::GetMeasurePresetTime() const
|
|
{
|
|
return this->_measure_preset_time;
|
|
}
|
|
|
|
uint MeasureAnalysisProjectModel::GetConformTimeWin() const
|
|
{
|
|
return this->_conform_time_win;
|
|
}
|
|
|
|
bool MeasureAnalysisProjectModel::GetIsMeasureComplete() const
|
|
{
|
|
return this->_is_measure_complete;
|
|
}
|
|
|
|
const QString& MeasureAnalysisProjectModel::GetMeasureDeviceParamsCfgFilename() const
|
|
{
|
|
return this->_measure_device_params_cfg_filename;
|
|
}
|
|
|
|
const QString& MeasureAnalysisProjectModel::GetEneryScaleFilename() const
|
|
{
|
|
return this->_enery_scale_filename;
|
|
}
|
|
|
|
const QString& MeasureAnalysisProjectModel::GetEfficiencyScaleFilename() const
|
|
{
|
|
return this->_efficiency_scale_filename;
|
|
}
|
|
|
|
const QString& MeasureAnalysisProjectModel::GetAllChannelParticleDataFilename() const
|
|
{
|
|
return this->_all_channel_particle_data_filename;
|
|
}
|
|
|
|
const QString& MeasureAnalysisProjectModel::GetSortAllChannelParticleDataFilename() const
|
|
{
|
|
return this->_sorted_particle_data_filename;
|
|
}
|
|
|
|
// const QMap<uint, QString>& MeasureAnalysisProjectModel::GetChannelParticleDataFilenameList() const
|
|
// {
|
|
// return this->_channel_particle_data_filename_list;
|
|
// }
|
|
|
|
// const QString& MeasureAnalysisProjectModel::GetChannelParticleDataFilename(uint channel) const
|
|
// {
|
|
// return QString(this->_channel_particle_data_filename_list[channel]);
|
|
// }
|
|
|
|
const QMap<uint, QString>& MeasureAnalysisProjectModel::GetChannelAddressCountDataFilenameList() const
|
|
{
|
|
return this->_channel_address_count_data_filename_list;
|
|
}
|
|
|
|
const QString& MeasureAnalysisProjectModel::GetChannelAddressCountDataFilename(uint channel) const
|
|
{
|
|
QString file_name;
|
|
if ( this->_channel_address_count_data_filename_list.contains(channel) ) {
|
|
file_name = this->_channel_address_count_data_filename_list[channel];
|
|
}
|
|
return file_name;
|
|
}
|
|
|
|
// const QString& MeasureAnalysisProjectModel::GetAllChannelParticleTotalCountDataFilename() const
|
|
// {
|
|
// return this->_all_channel_particle_total_count_data_filename;
|
|
// }
|
|
|
|
const QMap<uint, QString>& MeasureAnalysisProjectModel::GetChannelEneryCountDataFilenameList() const
|
|
{
|
|
return this->_channel_enery_count_data_filename_list;
|
|
}
|
|
|
|
const QString& MeasureAnalysisProjectModel::GetChannelEneryCountDataFilename(uint channel) const
|
|
{
|
|
QString file_name;
|
|
if ( this->_channel_enery_count_data_filename_list.contains(channel) ) {
|
|
file_name = this->_channel_enery_count_data_filename_list[channel];
|
|
}
|
|
return file_name;
|
|
}
|
|
|
|
const QString& MeasureAnalysisProjectModel::GetAllChannelEneryTotalCountDataFilename() const
|
|
{
|
|
return this->_all_channel_enery_total_count_data_filename;
|
|
}
|
|
|
|
const QMap<uint, QString>& MeasureAnalysisProjectModel::GetTimeWinConformParticleDataFilenameList(uint time_win) const
|
|
{
|
|
QMap<uint, QString> conform_particle_data;
|
|
if ( this->_time_win_conform_particle_data.contains(time_win) ) {
|
|
conform_particle_data = this->_time_win_conform_particle_data[time_win];
|
|
}
|
|
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;
|
|
// 从json文件加载项目模型
|
|
QFile json_file(this->_project_filename);
|
|
if (!json_file.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
{
|
|
return false;
|
|
}
|
|
QJsonDocument json_doc = QJsonDocument::fromJson(json_file.readAll());
|
|
json_file.close();
|
|
if (json_doc.isNull())
|
|
{
|
|
return false;
|
|
}
|
|
if (!json_doc.isObject())
|
|
{
|
|
return false;
|
|
}
|
|
QJsonObject json_obj = json_doc.object();
|
|
if (!json_obj.contains("ProjectName"))
|
|
{
|
|
return false;
|
|
}
|
|
this->_project_name = json_obj["ProjectName"].toString();
|
|
if (!json_obj.contains("SpectrumType"))
|
|
{
|
|
return false;
|
|
}
|
|
this->_spec_type = (SpectrumType)json_obj["SpectrumType"].toInt();
|
|
if (!json_obj.contains("IsStandardSource"))
|
|
{
|
|
return false;
|
|
}
|
|
this->_is_std_source = json_obj["IsStandardSource"].toBool();
|
|
if (!json_obj.contains("DescriptionInfo"))
|
|
{
|
|
return false;
|
|
}
|
|
this->_description_info = json_obj["DescriptionInfo"].toString();
|
|
if (!json_obj.contains("MeasurePresetTime"))
|
|
{
|
|
return false;
|
|
}
|
|
this->_measure_preset_time = json_obj["MeasurePresetTime"].toInt();
|
|
if (!json_obj.contains("IsMeasureComplete"))
|
|
{
|
|
return false;
|
|
}
|
|
this->_is_measure_complete = json_obj["IsMeasureComplete"].toBool();
|
|
if (!json_obj.contains("ConformTimeWin"))
|
|
{
|
|
return false;
|
|
}
|
|
this->_conform_time_win = json_obj["ConformTimeWin"].toInt();
|
|
|
|
QFileInfo project_fileinfo(project_filename);
|
|
this->_project_dir = project_fileinfo.absoluteDir().absolutePath();
|
|
|
|
auto ProjectAbsFilename = [this](const QString& project_relative_filename){
|
|
QString project_abs_filename;
|
|
if ( !project_relative_filename.isEmpty() ) {
|
|
QDir project_dir(this->_project_dir);
|
|
project_abs_filename = project_dir.filePath(project_relative_filename);
|
|
QFileInfo file_info(project_abs_filename);
|
|
if ( !file_info.exists() ) {
|
|
project_abs_filename.clear();
|
|
}
|
|
}
|
|
return project_abs_filename;
|
|
};
|
|
|
|
this->_measure_device_params_cfg_filename = ProjectAbsFilename(json_obj["MeasureDeviceParamsCfgFilename"].toString());
|
|
this->_enery_scale_filename = ProjectAbsFilename(json_obj["EneryScaleFilename"].toString());
|
|
this->_efficiency_scale_filename = ProjectAbsFilename(json_obj["EfficiencyScaleFilename"].toString());
|
|
|
|
this->_all_channel_particle_data_filename = ProjectAbsFilename(json_obj["AllChannelParticleDataFilename"].toString());
|
|
this->_sorted_particle_data_filename = ProjectAbsFilename(json_obj["SortedParticleDataFilename"].toString());
|
|
|
|
const auto& address_count_data_filename_list = json_obj["ChannelAddressCountDataFilenameList"].toObject().toVariantMap();
|
|
for (auto it = address_count_data_filename_list.constBegin(); it!=address_count_data_filename_list.constEnd(); ++it) {
|
|
uint channel_num = it.key().toUInt();
|
|
this->_channel_address_count_data_filename_list[channel_num] = ProjectAbsFilename(it.value().toString());
|
|
}
|
|
|
|
const auto& enery_count_data_filename_list = json_obj["ChannelEneryCountDataFilenameList"].toObject().toVariantMap();
|
|
for (auto it = enery_count_data_filename_list.constBegin(); it!=enery_count_data_filename_list.constEnd(); ++it) {
|
|
uint channel_num = it.key().toUInt();
|
|
this->_channel_enery_count_data_filename_list[channel_num] = ProjectAbsFilename(it.value().toString());
|
|
}
|
|
|
|
this->_all_channel_enery_total_count_data_filename = ProjectAbsFilename(json_obj["AllChannelEneryTotalCountDataFilename"].toString());
|
|
|
|
const auto& time_win_conform_particle_data = json_obj["TimeWinConformParticleData"].toObject().toVariantMap();
|
|
for (auto it = time_win_conform_particle_data.constBegin(); it!=time_win_conform_particle_data.constEnd(); ++it) {
|
|
uint time_win = it.key().toUInt();
|
|
QMap<uint, QString> conform_particle_data;
|
|
// const auto& conform_particle_data_list = it.value().toObject().toVariantMap();
|
|
// for (auto it2 = conform_particle_data_list.constBegin(); it2!=conform_particle_data_list.constEnd(); ++it2) {
|
|
// uint particle_count = it2.key().toUInt();
|
|
// conform_particle_data[particle_count] = ProjectAbsFilename(it2.value().toString());
|
|
// }
|
|
this->_time_win_conform_particle_data[time_win] = conform_particle_data;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool MeasureAnalysisProjectModel::SaveProjectModel()
|
|
{
|
|
auto ProjectRelativeFilename = [this](const QString& abs_filename){
|
|
QString project_relative_filename;
|
|
if ( !abs_filename.isEmpty() ) {
|
|
QFileInfo file_info(abs_filename);
|
|
if ( file_info.exists() ) {
|
|
QDir project_dir(_project_dir);
|
|
QString project_dir_path = project_dir.absolutePath() + "/";
|
|
QString project_abs_filename = file_info.absoluteFilePath();
|
|
project_relative_filename = project_abs_filename.remove(project_dir_path);
|
|
}
|
|
}
|
|
return project_relative_filename;
|
|
};
|
|
|
|
if (this->_project_filename.isEmpty())
|
|
{
|
|
this->_project_filename = QDir(this->_project_dir).filePath(this->_project_name + QString(".msproject"));;
|
|
}
|
|
// 将项目模型转换为json对象
|
|
QVariantMap project_json_obj_map;
|
|
project_json_obj_map["ProjectName"] = this->_project_name;
|
|
project_json_obj_map["SpectrumType"] = this->_spec_type;
|
|
project_json_obj_map["IsStandardSource"] = this->_is_std_source;
|
|
project_json_obj_map["DescriptionInfo"] = this->_description_info;
|
|
project_json_obj_map["MeasurePresetTime"] = int(this->_measure_preset_time);
|
|
project_json_obj_map["IsMeasureComplete"] = this->_is_measure_complete;
|
|
project_json_obj_map["ConformTimeWin"] = this->_conform_time_win;
|
|
|
|
project_json_obj_map["MeasureDeviceParamsCfgFilename"] = ProjectRelativeFilename(this->_measure_device_params_cfg_filename);
|
|
project_json_obj_map["EneryScaleFilename"] = ProjectRelativeFilename(this->_enery_scale_filename);
|
|
project_json_obj_map["EfficiencyScaleFilename"] = ProjectRelativeFilename(this->_efficiency_scale_filename);
|
|
|
|
project_json_obj_map["AllChannelParticleDataFilename"] = ProjectRelativeFilename(this->_all_channel_particle_data_filename);
|
|
project_json_obj_map["SortedParticleDataFilename"] = ProjectRelativeFilename(this->_sorted_particle_data_filename);
|
|
|
|
QVariantMap channel_address_count_data_filename_list;
|
|
for (auto it = this->_channel_address_count_data_filename_list.constBegin(); it != this->_channel_address_count_data_filename_list.constEnd(); ++it) {
|
|
channel_address_count_data_filename_list[QString::number(it.key())] = ProjectRelativeFilename(it.value());
|
|
}
|
|
project_json_obj_map["ChannelAddressCountDataFilenameList"] = channel_address_count_data_filename_list;
|
|
|
|
QVariantMap channel_enery_count_data_filename_list;
|
|
for (auto it = this->_channel_enery_count_data_filename_list.constBegin(); it != this->_channel_enery_count_data_filename_list.constEnd(); ++it) {
|
|
channel_enery_count_data_filename_list[QString::number(it.key())] = ProjectRelativeFilename(it.value());
|
|
}
|
|
project_json_obj_map["ChannelEneryCountDataFilenameList"] = channel_enery_count_data_filename_list;
|
|
|
|
project_json_obj_map["AllChannelEneryTotalCountDataFilename"] = ProjectRelativeFilename(this->_all_channel_enery_total_count_data_filename);
|
|
|
|
QVariantMap time_win_conform_particle_data;
|
|
for (auto it = this->_time_win_conform_particle_data.constBegin(); it != this->_time_win_conform_particle_data.constEnd(); ++it) {
|
|
QVariantMap conform_particle_data;
|
|
for (auto it2 = it.value().constBegin(); it2 != it.value().constEnd(); ++it2) {
|
|
conform_particle_data[QString::number(it2.key())] = ProjectRelativeFilename(it2.value());
|
|
}
|
|
time_win_conform_particle_data[QString::number(it.key())] = conform_particle_data;
|
|
}
|
|
project_json_obj_map["TimeWinConformParticleData"] = time_win_conform_particle_data;
|
|
|
|
// 将项目模型保存到json文件
|
|
QJsonDocument json_doc = QJsonDocument::fromVariant(project_json_obj_map);
|
|
QFile json_file(this->_project_filename);
|
|
if (!json_file.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
{
|
|
return false;
|
|
}
|
|
json_file.write(json_doc.toJson());
|
|
json_file.close();
|
|
return true;
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
/* MeasureAnalysisProjectModelList */
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
enum ColumnType {
|
|
NameColumn,
|
|
StatusColumn
|
|
};
|
|
|
|
MeasureAnalysisProjectModelList* MeasureAnalysisProjectModelList::_s_instance { nullptr };
|
|
|
|
MeasureAnalysisProjectModelList* MeasureAnalysisProjectModelList::Instance()
|
|
{
|
|
if (!_s_instance) {
|
|
_s_instance = new MeasureAnalysisProjectModelList();
|
|
}
|
|
return _s_instance;
|
|
}
|
|
|
|
MeasureAnalysisProjectModelList::~MeasureAnalysisProjectModelList()
|
|
{
|
|
const auto& models_list = _project_models.values();
|
|
for (auto it=models_list.constBegin(); it!=models_list.constEnd(); ++it) {
|
|
auto& model = *it;
|
|
model->SaveProjectModel();
|
|
}
|
|
}
|
|
|
|
void MeasureAnalysisProjectModelList::AddProjectModel(MeasureAnalysisProjectModel* model)
|
|
{
|
|
const QString& project_name = model->GetProjectName();
|
|
_project_models[project_name] = model;
|
|
intiProjectNodeStruce(model);
|
|
SetCurrentProjectModel(project_name);
|
|
model->SaveProjectModel();
|
|
}
|
|
|
|
bool MeasureAnalysisProjectModelList::RmProjectModel(const QString& project_name)
|
|
{
|
|
if (!_project_node_items.contains(project_name)) {
|
|
return false;
|
|
}
|
|
const QMap<QString, QStandardItem*> item_nodes = _project_node_items[project_name];
|
|
if (!item_nodes.contains(project_name) ) {
|
|
return false;
|
|
}
|
|
QStandardItem* project_item = item_nodes[project_name];
|
|
if (project_item) {
|
|
if (!this->RemoveNode(project_item)) {
|
|
return false;
|
|
}
|
|
}
|
|
if (_project_models.contains(project_name)) {
|
|
delete _project_models[project_name];
|
|
_project_models.remove(project_name);
|
|
}
|
|
const auto& project_model = _project_models.first();
|
|
if (project_model) {
|
|
const QString& project_name = project_model->GetProjectName();
|
|
SetCurrentProjectModel(project_name);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
MeasureAnalysisProjectModel* MeasureAnalysisProjectModelList::GetProjectModel(const QString& project_name)
|
|
{
|
|
if (_project_models.contains(project_name)) {
|
|
return _project_models[project_name];
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
MeasureAnalysisProjectModel* MeasureAnalysisProjectModelList::GetCurrentProjectModel()
|
|
{
|
|
return _current_project_model;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModelList::SetCurrentProjectModel(const QString& project_name)
|
|
{
|
|
if (_project_models.contains(project_name)) {
|
|
_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<QString, QStandardItem*> item_nodes = it.value();
|
|
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 ) {
|
|
font.setBold(true);
|
|
} else {
|
|
font.setBold(false);
|
|
}
|
|
project_item->setFont(font);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
MeasureAnalysisProjectModelList::MeasureAnalysisProjectModelList(QObject* parent)
|
|
: QStandardItemModel(parent)
|
|
, _current_project_model(nullptr)
|
|
{
|
|
setColumnCount(2);
|
|
setHeaderData(NameColumn, Qt::Horizontal, QStringLiteral(u"项名"));
|
|
setHeaderData(StatusColumn, Qt::Horizontal, QStringLiteral(u"状态"));
|
|
}
|
|
|
|
QStandardItem* MeasureAnalysisProjectModelList::GetItemFromIndex(const QModelIndex& index) const
|
|
{
|
|
QModelIndex nameIndex = index.sibling(index.row(), NameColumn);
|
|
return itemFromIndex(nameIndex);
|
|
}
|
|
|
|
QStandardItem* MeasureAnalysisProjectModelList::AddChildNode(
|
|
QStandardItem* parent_item, const QString& node_name, const QString& status,
|
|
const QVariant& user_data, bool is_fixed)
|
|
{
|
|
if (!parent_item)
|
|
return nullptr;
|
|
|
|
QStandardItem* name_item = new QStandardItem(node_name);
|
|
name_item->setData(user_data, NodeType);
|
|
name_item->setData(is_fixed, Fixed);
|
|
|
|
QStandardItem* status_item = new QStandardItem(status);
|
|
|
|
QList<QStandardItem*> row_items;
|
|
row_items << name_item << status_item;
|
|
parent_item->appendRow(row_items);
|
|
|
|
return name_item;
|
|
}
|
|
|
|
bool MeasureAnalysisProjectModelList::RemoveNode(QStandardItem* item)
|
|
{
|
|
if (!item)
|
|
return false;
|
|
if (item->column() == NameColumn && item->data(Fixed).toBool())
|
|
return false;
|
|
const QString& project_name = item->data(ProjectName).toString();
|
|
if (AnalysisType::Project == item->data(NodeType).value<AnalysisType>()) {
|
|
QStandardItem* root_item = invisibleRootItem();
|
|
root_item->removeRow(item->row());
|
|
_project_node_items.remove(project_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;
|
|
}
|
|
|
|
void MeasureAnalysisProjectModelList::SetNodeUserData(QStandardItem* item, const QVariant& data)
|
|
{
|
|
if (item && item->column() == NameColumn)
|
|
item->setData(data, NodeType);
|
|
}
|
|
|
|
QVariant MeasureAnalysisProjectModelList::GetNodeUserData(QStandardItem* item, UserDataType data_type) const
|
|
{
|
|
return (item && item->column() == NameColumn) ? item->data(data_type) : QVariant();
|
|
}
|
|
|
|
void MeasureAnalysisProjectModelList::SetNodeStatus(QStandardItem* item, const QString& status)
|
|
{
|
|
if (!item || item->column() != NameColumn)
|
|
return;
|
|
QStandardItem* status_item = item->parent()
|
|
? item->parent()->child(item->row(), StatusColumn)
|
|
: invisibleRootItem()->child(item->row(), StatusColumn);
|
|
if (status_item) {
|
|
status_item->setText(status);
|
|
}
|
|
}
|
|
|
|
QString MeasureAnalysisProjectModelList::GetNodeStatus(QStandardItem* item) const
|
|
{
|
|
if (!item || item->column() != NameColumn)
|
|
return QString();
|
|
QStandardItem* status_item = item->parent()
|
|
? item->parent()->child(item->row(), StatusColumn)
|
|
: invisibleRootItem()->child(item->row(), StatusColumn);
|
|
return status_item ? status_item->text() : QString();
|
|
}
|
|
|
|
void MeasureAnalysisProjectModelList::onChannelAddressCountProcessFinished(const QString& project_name)
|
|
{
|
|
if (this->_project_models.contains(project_name)) {
|
|
auto pro_model = this->_project_models[project_name];
|
|
const QMap<uint, QString>& filename_list = pro_model->GetChannelAddressCountDataFilenameList();
|
|
|
|
QString status = QStringLiteral(u"无效");
|
|
if (!filename_list.isEmpty()) {
|
|
status = QStringLiteral(u"有效");
|
|
}
|
|
|
|
auto& node_map = this->_project_node_items[project_name];
|
|
const QString& adrr_count_item_name = QStringLiteral(u"道址计数");
|
|
if (node_map.contains(adrr_count_item_name)) {
|
|
auto adrr_count_item = node_map[adrr_count_item_name];
|
|
this->SetNodeStatus(adrr_count_item, status);
|
|
|
|
for (auto it = filename_list.begin(); it != filename_list.end(); ++it) {
|
|
uint ch_num = it.key();
|
|
QString item_name = QStringLiteral(u"通道%1道址计数").arg(ch_num);
|
|
const QVariant& analys_type = QVariant::fromValue(AnalysisType::AddressCountData);
|
|
QStandardItem* node_item = AddChildNode(adrr_count_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_item->setData(ch_num, ChannelNum);
|
|
node_map[item_name] = node_item;
|
|
}
|
|
}
|
|
|
|
const QString& adrr_count_spec_item_name = QStringLiteral(u"道址计数谱");
|
|
if (node_map.contains(adrr_count_spec_item_name)) {
|
|
auto adrr_count_spec_item = node_map[adrr_count_spec_item_name];
|
|
this->SetNodeStatus(adrr_count_spec_item, status);
|
|
}
|
|
|
|
pro_model->SaveProjectModel();
|
|
}
|
|
}
|
|
|
|
void MeasureAnalysisProjectModelList::intiProjectNodeStruce(MeasureAnalysisProjectModel* pro_model)
|
|
{
|
|
if (!pro_model) {
|
|
return;
|
|
}
|
|
|
|
QMap<QString, QStandardItem*> node_map;
|
|
QStandardItem* root_item = invisibleRootItem();
|
|
|
|
const QString& project_name = pro_model->GetProjectName();
|
|
QString status = pro_model->GetIsMeasureComplete() ? QStringLiteral(u"测量完成") : QStringLiteral(u"未测量");
|
|
QVariant analys_type = QVariant::fromValue(AnalysisType::Project);
|
|
QStandardItem* project_item = AddChildNode(root_item, project_name, status, analys_type, false);
|
|
project_item->setData(project_name, ProjectName);
|
|
node_map[project_name] = project_item;
|
|
|
|
// 测量控制
|
|
QString item_name = QStringLiteral(u"测量控制");
|
|
QStandardItem* measure_ctrl_item = AddChildNode(project_item, item_name, QString(), QVariant(), true);
|
|
measure_ctrl_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = measure_ctrl_item;
|
|
|
|
if (!pro_model->GetIsMeasureComplete()) {
|
|
const QString& measure_device_params_cfg_filename = pro_model->GetMeasureDeviceParamsCfgFilename();
|
|
status = measure_device_params_cfg_filename.isEmpty() ? QStringLiteral(u"未配置") : QStringLiteral(u"已配置");
|
|
analys_type = QVariant::fromValue(AnalysisType::DeviceParamsCfg);
|
|
item_name = QStringLiteral(u"设备配置参数");
|
|
QStandardItem* node_item = AddChildNode(measure_ctrl_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
}
|
|
|
|
status = pro_model->GetEneryScaleFilename().isEmpty() ? QStringLiteral(u"未配置") : QStringLiteral(u"已配置");
|
|
analys_type = QVariant::fromValue(AnalysisType::EnergyScale);
|
|
item_name = QStringLiteral(u"能量刻度");
|
|
QStandardItem* node_item = AddChildNode(measure_ctrl_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
status = pro_model->GetEfficiencyScaleFilename().isEmpty() ? QStringLiteral(u"未配置") : QStringLiteral(u"已配置");
|
|
analys_type = QVariant::fromValue(AnalysisType::EfficiencyScale);
|
|
item_name = QStringLiteral(u"效率刻度");
|
|
node_item = AddChildNode(measure_ctrl_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
// 分析数据
|
|
item_name = QStringLiteral(u"分析数据");
|
|
QStandardItem* analysis_data_item = AddChildNode(project_item, item_name, QString(), QVariant(), true);
|
|
analysis_data_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
status = pro_model->GetAllChannelParticleDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效");
|
|
analys_type = QVariant::fromValue(AnalysisType::ParticleData);
|
|
item_name = QStringLiteral(u"测量粒子数据");
|
|
node_item = AddChildNode(analysis_data_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
item_name = QStringLiteral(u"道址计数");
|
|
const auto& ch_addr_count_data_filename_list = pro_model->GetChannelAddressCountDataFilenameList();
|
|
status = ch_addr_count_data_filename_list.isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效");
|
|
node_item = AddChildNode(analysis_data_item, item_name, status, QVariant(), true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
QStandardItem* adrr_count_item = node_item;
|
|
for (auto it = ch_addr_count_data_filename_list.begin(); it != ch_addr_count_data_filename_list.end(); ++it) {
|
|
uint ch_num = it.key();
|
|
QString item_name = QStringLiteral(u"通道%1道址计数").arg(ch_num);
|
|
const QVariant& analys_type = QVariant::fromValue(AnalysisType::AddressCountData);
|
|
QStandardItem* node_item = AddChildNode(adrr_count_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_item->setData(ch_num, ChannelNum);
|
|
node_map[item_name] = node_item;
|
|
}
|
|
|
|
item_name = QStringLiteral(u"能量计数");
|
|
status = pro_model->GetAllChannelEneryTotalCountDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效");
|
|
analys_type = QVariant::fromValue(AnalysisType::EnergyCountData);
|
|
node_item = AddChildNode(analysis_data_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
QStandardItem* enery_count_item = node_item;
|
|
const auto& ch_enery_count_data_filename_list = pro_model->GetChannelEneryCountDataFilenameList();
|
|
for (auto it = ch_enery_count_data_filename_list.begin(); it != ch_enery_count_data_filename_list.end(); ++it) {
|
|
uint ch_num = it.key();
|
|
QString item_name = QStringLiteral(u"通道%1能量计数").arg(ch_num);
|
|
const QVariant& analys_type = QVariant::fromValue(AnalysisType::EnergyCountData);
|
|
QStandardItem* node_item = AddChildNode(enery_count_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_item->setData(ch_num, ChannelNum);
|
|
node_map[item_name] = node_item;
|
|
}
|
|
|
|
uint conform_time_win = pro_model->GetConformTimeWin();
|
|
status = pro_model->GetTimeWinConformParticleDataFilenameList(conform_time_win).isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效");
|
|
analys_type = QVariant::fromValue(AnalysisType::CoincidenceParticleEnergyData);
|
|
item_name = QStringLiteral(u"符合粒子数据[%1ns]").arg(conform_time_win);
|
|
node_item = AddChildNode(analysis_data_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
// 交互分析
|
|
item_name = QStringLiteral(u"交互分析");
|
|
QStandardItem* interactive_analysis_item = AddChildNode(project_item, item_name, QString(), QVariant(), true);
|
|
interactive_analysis_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = interactive_analysis_item;
|
|
|
|
status = pro_model->GetChannelAddressCountDataFilenameList().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效");
|
|
analys_type = QVariant::fromValue(AnalysisType::AddressCountSpectrumView);
|
|
item_name = QStringLiteral(u"道址计数谱");
|
|
node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
status = pro_model->GetChannelEneryCountDataFilenameList().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效");
|
|
analys_type = QVariant::fromValue(AnalysisType::EneryCountSpectrumView);
|
|
item_name = QStringLiteral(u"通道能量计数谱");
|
|
node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
status = pro_model->GetAllChannelEneryTotalCountDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效");
|
|
analys_type = QVariant::fromValue(AnalysisType::EneryCountSpectrumView);
|
|
item_name = QStringLiteral(u"能量计数谱");
|
|
node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
status = pro_model->GetSortAllChannelParticleDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效");
|
|
analys_type = QVariant::fromValue(AnalysisType::CountingRateView);
|
|
item_name = QStringLiteral(u"计数率分析");
|
|
node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
status = pro_model->GetAllChannelEneryTotalCountDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效");
|
|
analys_type = QVariant::fromValue(AnalysisType::EnergyPeakFitView);
|
|
item_name = QStringLiteral(u"峰拟合分析");
|
|
node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
status = pro_model->GetAllChannelEneryTotalCountDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效");
|
|
analys_type = QVariant::fromValue(AnalysisType::NuclideAnalysisView);
|
|
item_name = QStringLiteral(u"核素分析");
|
|
node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
status = pro_model->GetSortAllChannelParticleDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效");
|
|
analys_type = QVariant::fromValue(AnalysisType::ParticleInTimeView);
|
|
item_name = QStringLiteral(u"粒子入射时间分析");
|
|
node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
status = pro_model->GetSortAllChannelParticleDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效");
|
|
analys_type = QVariant::fromValue(AnalysisType::ParticleTimeDiffView);
|
|
item_name = QStringLiteral(u"粒子时间差分析");
|
|
node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
status = pro_model->GetTimeWinConformParticleDataFilenameList(conform_time_win).isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效");
|
|
analys_type = QVariant::fromValue(AnalysisType::CoincidenceEventTimeView);
|
|
item_name = QStringLiteral(u"符合事件时间分析");
|
|
node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
analys_type = QVariant::fromValue(AnalysisType::CoincidenceParticleEnergySpectrumView);
|
|
item_name = QStringLiteral(u"符合能谱[%1ns]").arg(conform_time_win);
|
|
node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
analys_type = QVariant::fromValue(AnalysisType::AntiCoincidenceSpectrumView);
|
|
item_name = QStringLiteral(u"反符合能谱[%1ns]").arg(conform_time_win);
|
|
node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
analys_type = QVariant::fromValue(AnalysisType::CoincidenceParticleEnergySpectrum2DView);
|
|
item_name = QStringLiteral(u"二维符合能谱[%1ns]").arg(conform_time_win);
|
|
node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
analys_type = QVariant::fromValue(AnalysisType::CoincidenceParticleEnergySpectrum3DView);
|
|
item_name = QStringLiteral(u"三维符合能谱[%1ns]").arg(conform_time_win);
|
|
node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true);
|
|
node_item->setData(project_name, ProjectName);
|
|
node_map[item_name] = node_item;
|
|
|
|
_project_node_items[project_name] = node_map;
|
|
|
|
LOG_INFO(QStringLiteral(u"测量分析项目\"%1\"创建成功.").arg(project_name));
|
|
if (!pro_model->GetIsMeasureComplete()) {
|
|
if (pro_model->GetMeasureDeviceParamsCfgFilename().isEmpty()) {
|
|
LOG_WARN(QStringLiteral(u"测量分析项目\"%1\"测量设备参数未配置!").arg(project_name));
|
|
}
|
|
}
|
|
if (pro_model->GetEneryScaleFilename().isEmpty()) {
|
|
LOG_WARN(QStringLiteral(u"测量分析项目\"%1\"能量刻度未配置!").arg(project_name));
|
|
}
|
|
if (pro_model->GetEfficiencyScaleFilename().isEmpty()) {
|
|
LOG_WARN(QStringLiteral(u"测量分析项目\"%1\"效率刻度未配置!").arg(project_name));
|
|
}
|
|
}
|