完善测量参数配置视图
This commit is contained in:
parent
ab742c6290
commit
47251ebc70
|
|
@ -707,6 +707,29 @@ void MeasureAnalysisProjectModelList::ApplyEnergyScale(const QString &project_na
|
|||
}
|
||||
}
|
||||
|
||||
void MeasureAnalysisProjectModelList::onDeviceConfigParamsFinished(bool ok, const QString &project_name, const QVariant &data)
|
||||
{
|
||||
Q_UNUSED(data);
|
||||
if ( !ok )
|
||||
return;
|
||||
if (this->_project_models.contains(project_name)) {
|
||||
auto pro_model = this->_project_models[project_name];
|
||||
const QString& device_filename = pro_model->GetMeasureDeviceParamsCfgFilename();
|
||||
bool status_ok = false;
|
||||
QString status = QStringLiteral(u"未配置");
|
||||
if (!device_filename.isEmpty()) {
|
||||
status_ok = true;
|
||||
status = QStringLiteral(u"已配置");
|
||||
}
|
||||
auto& node_map = this->_project_node_items[project_name];
|
||||
const QString& device_config_params_item_name = QStringLiteral(u"设备配置参数");
|
||||
if (node_map.contains(device_config_params_item_name)) {
|
||||
auto device_config_params_item = node_map[device_config_params_item_name];
|
||||
this->SetNodeStatus(device_config_params_item, status, status_ok);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MeasureAnalysisProjectModelList::onChannelAddressCountProcessFinished(bool ok, const QString& project_name, const QVariant &data)
|
||||
{
|
||||
Q_UNUSED(data);
|
||||
|
|
|
|||
|
|
@ -140,6 +140,7 @@ public:
|
|||
void ApplyEnergyScale(const QString& project_name);
|
||||
|
||||
private slots:
|
||||
void onDeviceConfigParamsFinished(bool ok, const QString& project_name, const QVariant& data);
|
||||
void onChannelAddressCountProcessFinished(bool ok, const QString& project_name, const QVariant& data);
|
||||
void onEnergyScaleParticleDataFinished(bool ok, const QString& project_name, const QVariant& data);
|
||||
void onEnergyCountProcessFinished(bool ok, const QString& project_name, const QVariant& data);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "AnalysisTypeDefine.h"
|
||||
#include "QHeaderView"
|
||||
#include "MeasureAnalysisView.h"
|
||||
#include <QDir>
|
||||
|
||||
MeasureAnalysisTreeView::MeasureAnalysisTreeView(QWidget* parent)
|
||||
: QTreeView(parent)
|
||||
|
|
@ -90,7 +91,13 @@ void MeasureAnalysisTreeView::onNodeDoubleClicked(const QModelIndex& index)
|
|||
MeasureAnalysisProjectModel* project_model = _model->GetProjectModel(project_name);
|
||||
if (project_model) {
|
||||
QString file_name = project_model->GetMeasureDeviceParamsCfgFilename();
|
||||
if ( !file_name.isEmpty() ) {
|
||||
data_files_set[QStringLiteral(u"设备参数配置")] = file_name;
|
||||
} else {
|
||||
QDir project_dir(project_model->GetProjectDir());
|
||||
file_name = project_dir.filePath(QStringLiteral(u"设备参数配置.json"));
|
||||
data_files_set[QStringLiteral(u"设备参数配置")] = file_name;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case AnalysisType::ParticleData: {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
#include "DeviceParamsTableForm.h"
|
||||
#include "ui_DeviceParamsTableForm.h"
|
||||
#include "GlobalDefine.h"
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QCheckBox>
|
||||
#include <QSpinBox>
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QMessageBox>
|
||||
|
||||
DeviceParamsItemDelegate::DeviceParamsItemDelegate(QObject* parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
|
|
@ -142,14 +147,21 @@ DeviceParamsTableForm::DeviceParamsTableForm(QWidget* parent)
|
|||
ui->setupUi(this);
|
||||
ui->params_cfg_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
ui->params_cfg_table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
||||
ui->params_cfg_table->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
|
||||
ui->params_cfg_table->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
|
||||
ui->params_cfg_table->setItemDelegate(new DeviceParamsItemDelegate(this));
|
||||
|
||||
for (int row = 0; row < 32; ++row) {
|
||||
int channel_num = row + 1;
|
||||
int board_id = (channel_num - 1) / 4;
|
||||
int channel_id = (channel_num - 1) % 4;
|
||||
QVariantMap channel_info;
|
||||
channel_info["board_id"] = board_id;
|
||||
channel_info["channel_id"] = channel_id;
|
||||
ui->params_cfg_table->insertRow(row);
|
||||
const QString& channel_text = QStringLiteral(u"通道%1").arg(row + 1);
|
||||
const QString& channel_text = QStringLiteral(u"通道%1").arg(channel_num);
|
||||
ui->params_cfg_table->setItem(row, 0, new QTableWidgetItem(channel_text));
|
||||
ui->params_cfg_table->item(row, 0)->setCheckState(Qt::Unchecked);
|
||||
ui->params_cfg_table->item(row, 0)->setData(Qt::UserRole, channel_info);
|
||||
ui->params_cfg_table->setItem(row, 1, new QTableWidgetItem());
|
||||
ui->params_cfg_table->setItem(row, 2, new QTableWidgetItem());
|
||||
ui->params_cfg_table->setItem(row, 3, new QTableWidgetItem());
|
||||
|
|
@ -161,7 +173,11 @@ DeviceParamsTableForm::DeviceParamsTableForm(QWidget* parent)
|
|||
ui->params_cfg_table->setItem(row, 9, new QTableWidgetItem());
|
||||
}
|
||||
|
||||
connect(ui->btn_all_select, &QPushButton::clicked, this, &DeviceParamsTableForm::onAllSelectBtnClicked);
|
||||
connect(ui->btn_reserve_select, &QPushButton::clicked, this, &DeviceParamsTableForm::onReserveSelectBtnClicked);
|
||||
connect(ui->btn_channel_select, &QPushButton::clicked, this, &DeviceParamsTableForm::onCfgChannelSelectBtnClicked);
|
||||
connect(ui->btn_update_to_other, &QPushButton::clicked, this, &DeviceParamsTableForm::onCurrentChannelToOther);
|
||||
connect(ui->btn_save, &QPushButton::clicked, this, &DeviceParamsTableForm::onSaveSelectedChannelConfig);
|
||||
}
|
||||
|
||||
DeviceParamsTableForm::~DeviceParamsTableForm()
|
||||
|
|
@ -169,6 +185,84 @@ DeviceParamsTableForm::~DeviceParamsTableForm()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void DeviceParamsTableForm::SetConfigFilename(const QString& filename)
|
||||
{
|
||||
_config_filename = filename;
|
||||
if ( _config_filename.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
QFile json_file(_config_filename);
|
||||
if (!json_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
return;
|
||||
}
|
||||
QByteArray json_data = json_file.readAll();
|
||||
json_file.close();
|
||||
QJsonDocument json_doc = QJsonDocument::fromJson(json_data);
|
||||
if (json_doc.isNull()) {
|
||||
return;
|
||||
}
|
||||
if (!json_doc.isObject())
|
||||
return;
|
||||
QVariantMap device_config_info = json_doc.object().toVariantMap();
|
||||
if (!device_config_info.contains(QStringLiteral(u"ChannelConfig")))
|
||||
return;
|
||||
QVariantList channel_config_list = device_config_info[QStringLiteral(u"ChannelConfig")].toList();
|
||||
if (channel_config_list.isEmpty())
|
||||
return;
|
||||
for (auto channel_config : channel_config_list) {
|
||||
if (!channel_config.isValid())
|
||||
continue;
|
||||
QVariantMap channel_config_info = channel_config.toMap();
|
||||
if (!channel_config_info.contains("BoardId") || !channel_config_info.contains("ChannelId"))
|
||||
continue;
|
||||
int board_id = channel_config_info["BoardId"].toInt();
|
||||
int channel_id = channel_config_info["ChannelId"].toInt();
|
||||
int row = board_id * 4 + channel_id;
|
||||
if (row >= 32)
|
||||
continue;
|
||||
QVariantMap channel_info;
|
||||
channel_info["board_id"] = board_id;
|
||||
channel_info["channel_id"] = channel_id;
|
||||
ui->params_cfg_table->item(row, 0)->setData(Qt::UserRole, channel_info);
|
||||
if (channel_config_info.contains("AddrCount"))
|
||||
ui->params_cfg_table->item(row, 1)->setText(channel_config_info["AddrCount"].toString());
|
||||
if (channel_config_info.contains("DeviceGain"))
|
||||
ui->params_cfg_table->item(row, 2)->setText(channel_config_info["DeviceGain"].toString());
|
||||
if (channel_config_info.contains("SoftGain"))
|
||||
ui->params_cfg_table->item(row, 3)->setText(channel_config_info["SoftGain"].toString());
|
||||
if (channel_config_info.contains("TimeConst"))
|
||||
ui->params_cfg_table->item(row, 4)->setText(channel_config_info["TimeConst"].toString());
|
||||
if (channel_config_info.contains("DcOffset"))
|
||||
ui->params_cfg_table->item(row, 5)->setText(channel_config_info["DcOffset"].toString());
|
||||
if (channel_config_info.contains("RiseTime"))
|
||||
ui->params_cfg_table->item(row, 6)->setText(channel_config_info["RiseTime"].toString());
|
||||
if (channel_config_info.contains("FlatTime"))
|
||||
ui->params_cfg_table->item(row, 7)->setText(channel_config_info["FlatTime"].toString());
|
||||
if (channel_config_info.contains("MaxEnergy"))
|
||||
ui->params_cfg_table->item(row, 8)->setText(channel_config_info["MaxEnergy"].toString());
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceParamsTableForm::onAllSelectBtnClicked()
|
||||
{
|
||||
for (int row = 0; row < 32; ++row) {
|
||||
if (ui->params_cfg_table->isRowHidden(row))
|
||||
continue;
|
||||
ui->params_cfg_table->item(row, 0)->setCheckState(Qt::Checked);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceParamsTableForm::onReserveSelectBtnClicked()
|
||||
{
|
||||
for (int row = 0; row < 32; ++row) {
|
||||
if (ui->params_cfg_table->isRowHidden(row))
|
||||
continue;
|
||||
auto item = ui->params_cfg_table->item(row, 0);
|
||||
Qt::CheckState check_state = item->checkState() == Qt::Checked ? Qt::Unchecked : Qt::Checked;
|
||||
item->setCheckState(check_state);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceParamsTableForm::onCfgChannelSelectBtnClicked()
|
||||
{
|
||||
QDialog cfg_channel_select_dlg(this, Qt::Dialog | Qt::WindowCloseButtonHint);
|
||||
|
|
@ -184,7 +278,7 @@ void DeviceParamsTableForm::onCfgChannelSelectBtnClicked()
|
|||
QHBoxLayout* checkbox_column_layout = new QHBoxLayout();
|
||||
for (int row = 0; row < 32; ++row) {
|
||||
QCheckBox* check_box = new QCheckBox(QStringLiteral(u"通道%1").arg(row + 1));
|
||||
check_box->setChecked(true);
|
||||
check_box->setChecked(!ui->params_cfg_table->isRowHidden(row));
|
||||
checkbox_column_layout->addWidget(check_box);
|
||||
connect(check_box, &QCheckBox::stateChanged, [this, row](int state) {
|
||||
ui->params_cfg_table->setRowHidden(row, state == Qt::Unchecked);
|
||||
|
|
@ -219,3 +313,65 @@ void DeviceParamsTableForm::onCfgChannelSelectBtnClicked()
|
|||
layout->addLayout(checkbox_layout);
|
||||
cfg_channel_select_dlg.exec();
|
||||
}
|
||||
|
||||
void DeviceParamsTableForm::onCurrentChannelToOther()
|
||||
{
|
||||
int current_row = ui->params_cfg_table->currentRow();
|
||||
for (int row = 0; row < 32; ++row) {
|
||||
if (ui->params_cfg_table->isRowHidden(row))
|
||||
continue;
|
||||
for (int col = 1; col < ui->params_cfg_table->columnCount(); ++col) {
|
||||
const QString& current_value = ui->params_cfg_table->item(current_row, col)->text();
|
||||
ui->params_cfg_table->item(row, col)->setText(current_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceParamsTableForm::onSaveSelectedChannelConfig()
|
||||
{
|
||||
QVariantList device_channel_params_list;
|
||||
for (int row = 0; row < 32; ++row) {
|
||||
if (ui->params_cfg_table->item(row, 0)->checkState() == Qt::Checked) {
|
||||
QVariantMap channel_info = ui->params_cfg_table->item(row, 0)->data(Qt::UserRole).toMap();
|
||||
int board_id = channel_info["board_id"].toInt();
|
||||
int channel_id = channel_info["channel_id"].toInt();
|
||||
int addr_count = ui->params_cfg_table->item(row, 1)->text().toInt();
|
||||
int device_gain = ui->params_cfg_table->item(row, 2)->text().toInt();
|
||||
uint soft_gain = ui->params_cfg_table->item(row, 3)->text().toUInt();
|
||||
int time_const = ui->params_cfg_table->item(row, 4)->text().toInt();
|
||||
int dc_offset = ui->params_cfg_table->item(row, 5)->text().toInt();
|
||||
int rise_time = ui->params_cfg_table->item(row, 6)->text().toInt();
|
||||
int flat_time = ui->params_cfg_table->item(row, 7)->text().toInt();
|
||||
int max_energy = ui->params_cfg_table->item(row, 8)->text().toInt();
|
||||
|
||||
QVariantMap device_channel_params;
|
||||
device_channel_params["BoardId"] = board_id;
|
||||
device_channel_params["ChannelId"] = channel_id;
|
||||
device_channel_params["AddrCount"] = addr_count;
|
||||
device_channel_params["DeviceGain"] = device_gain;
|
||||
device_channel_params["SoftGain"] = soft_gain;
|
||||
device_channel_params["TimeConst"] = time_const;
|
||||
device_channel_params["DcOffset"] = dc_offset;
|
||||
device_channel_params["RiseTime"] = rise_time;
|
||||
device_channel_params["FlatTime"] = flat_time;
|
||||
device_channel_params["MaxEnergy"] = max_energy;
|
||||
device_channel_params_list.append(device_channel_params);
|
||||
}
|
||||
}
|
||||
if (device_channel_params_list.isEmpty()) {
|
||||
QMessageBox::information(this, QStringLiteral(u"提示"), QStringLiteral(u"请选择需要保存的测量设备通道配置参数!"));
|
||||
return;
|
||||
}
|
||||
QVariantMap device_config_info;
|
||||
device_config_info["ChannelConfig"] = device_channel_params_list;
|
||||
QJsonDocument json_doc = QJsonDocument::fromVariant(device_config_info);
|
||||
QFile json_file(this->_config_filename);
|
||||
if (!json_file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
return;
|
||||
}
|
||||
json_file.write(json_doc.toJson());
|
||||
json_file.close();
|
||||
LOG_INFO(QStringLiteral(u"测量设备参数配置保存完成."));
|
||||
|
||||
emit deviceConfigParamsSaved(this->_config_filename);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,11 +34,21 @@ public:
|
|||
explicit DeviceParamsTableForm(QWidget *parent = nullptr);
|
||||
~DeviceParamsTableForm();
|
||||
|
||||
void SetConfigFilename(const QString& filename);
|
||||
|
||||
private slots:
|
||||
void onAllSelectBtnClicked();
|
||||
void onReserveSelectBtnClicked();
|
||||
void onCfgChannelSelectBtnClicked();
|
||||
void onCurrentChannelToOther();
|
||||
void onSaveSelectedChannelConfig();
|
||||
|
||||
signals:
|
||||
void deviceConfigParamsSaved(const QString& filename);
|
||||
|
||||
private:
|
||||
Ui::DeviceParamsTableForm *ui;
|
||||
QString _config_filename;
|
||||
};
|
||||
|
||||
#endif // DEVICEPARAMSTABLEFORM_H
|
||||
|
|
|
|||
|
|
@ -18,6 +18,20 @@
|
|||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_all_select">
|
||||
<property name="text">
|
||||
<string>全选</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_reserve_select">
|
||||
<property name="text">
|
||||
<string>反选</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_channel_select">
|
||||
<property name="text">
|
||||
|
|
@ -25,6 +39,13 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_update_to_other">
|
||||
<property name="text">
|
||||
<string>应用当前通道配置到其他通道</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
|
@ -51,6 +72,12 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="params_cfg_table">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>通道</string>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include "MeasureDeviceParamsConfigView.h"
|
||||
#include "DeviceParamsTableForm.h"
|
||||
#include <QVBoxLayout>
|
||||
#include "MeasureAnalysisProjectModel.h"
|
||||
#include <QFileInfo>
|
||||
|
||||
MeasureDeviceParamsConfigView::MeasureDeviceParamsConfigView(QWidget *parent)
|
||||
: MeasureAnalysisView(parent)
|
||||
|
|
@ -9,6 +11,8 @@ MeasureDeviceParamsConfigView::MeasureDeviceParamsConfigView(QWidget *parent)
|
|||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->addWidget(_device_params_table);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
connect(_device_params_table, &DeviceParamsTableForm::deviceConfigParamsSaved, this, &MeasureDeviceParamsConfigView::onDeviceParamsConfigUpdated);
|
||||
}
|
||||
|
||||
MeasureDeviceParamsConfigView::~MeasureDeviceParamsConfigView()
|
||||
|
|
@ -16,12 +20,38 @@ MeasureDeviceParamsConfigView::~MeasureDeviceParamsConfigView()
|
|||
|
||||
}
|
||||
|
||||
void MeasureDeviceParamsConfigView::InitViewWorkspace(const QString &project_name)
|
||||
void MeasureDeviceParamsConfigView::InitViewWorkspace(const QString& project_name)
|
||||
{
|
||||
|
||||
Q_UNUSED(project_name);
|
||||
}
|
||||
|
||||
void MeasureDeviceParamsConfigView::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data_files_set)
|
||||
{
|
||||
|
||||
const QString& config_filename = data_files_set.value(QStringLiteral(u"设备参数配置"), QString()).toString();
|
||||
_device_params_table->SetConfigFilename(config_filename);
|
||||
_device_config_filename = config_filename;
|
||||
}
|
||||
|
||||
void MeasureDeviceParamsConfigView::onDeviceParamsConfigUpdated()
|
||||
{
|
||||
const QString& project_name = this->GetProjectName();
|
||||
auto project_model = ProjectList::Instance()->GetProjectModel(project_name);
|
||||
if (!project_model) {
|
||||
return;
|
||||
}
|
||||
QFileInfo config_file_info(_device_config_filename);
|
||||
if (!config_file_info.exists())
|
||||
return;
|
||||
if (config_file_info.size() == 0)
|
||||
return;
|
||||
project_model->SetMeasureDeviceParamsCfgFilename(_device_config_filename);
|
||||
QMetaObject::invokeMethod(
|
||||
ProjectList::Instance(),
|
||||
"onDeviceConfigParamsFinished",
|
||||
Qt::AutoConnection,
|
||||
Q_ARG(bool, true),
|
||||
Q_ARG(QString, this->GetProjectName()),
|
||||
Q_ARG(QVariant, _device_config_filename)
|
||||
);
|
||||
project_model->SaveProjectModel();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,12 @@ public:
|
|||
virtual void InitViewWorkspace(const QString& project_name) override final;
|
||||
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set);
|
||||
|
||||
private slots:
|
||||
void onDeviceParamsConfigUpdated();
|
||||
|
||||
private:
|
||||
DeviceParamsTableForm* _device_params_table = nullptr;
|
||||
QString _device_config_filename;
|
||||
};
|
||||
|
||||
#endif // MEASUREDEVICEPARAMSCONFIGVIEW_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user