diff --git a/src/MeasureAnalysisTreeView.cpp b/src/MeasureAnalysisTreeView.cpp index 0e76c30..a7becfc 100644 --- a/src/MeasureAnalysisTreeView.cpp +++ b/src/MeasureAnalysisTreeView.cpp @@ -86,6 +86,13 @@ void MeasureAnalysisTreeView::onNodeDoubleClicked(const QModelIndex& index) view = _item_views[item]; } else { switch(analysis_type) { + case AnalysisType::DeviceParamsCfg: { + MeasureAnalysisProjectModel* project_model = _model->GetProjectModel(project_name); + if (project_model) { + QString file_name = project_model->GetMeasureDeviceParamsCfgFilename(); + data_files_set[QStringLiteral(u"设备参数配置")] = file_name; + } + } break; case AnalysisType::ParticleData: { MeasureAnalysisProjectModel* project_model = _model->GetProjectModel(project_name); if (project_model) { @@ -237,13 +244,6 @@ void MeasureAnalysisTreeView::onNodeDoubleClicked(const QModelIndex& index) } } } break; - case AnalysisType::DeviceParamsCfg: { - MeasureAnalysisProjectModel* project_model = _model->GetProjectModel(project_name); - if (project_model) { - QString file_name = project_model->GetMeasureDeviceParamsCfgFilename(); - data_files_set[QStringLiteral(u"设备参数配置")] = file_name; - } - } break; default: break; } diff --git a/src/MeasureAnalysisView.cpp b/src/MeasureAnalysisView.cpp index a2ba4ec..d0b5373 100644 --- a/src/MeasureAnalysisView.cpp +++ b/src/MeasureAnalysisView.cpp @@ -1,7 +1,7 @@ #include "MeasureAnalysisView.h" #include "ConformityAnalysis.h" #include "CountRateAnalysisView.h" -#include "DeviceConfigView.h" +#include "MeasureDeviceParamsConfigView.h" #include "EnergyCountPeakFitView.h" #include "EnergyCountPlotView.h" #include "MeasureAnalysisDataTableView.h" @@ -19,7 +19,7 @@ MeasureAnalysisView* MeasureAnalysisView::NewAnalyzeView(AnalysisType view_type) // new_view->setDeleteOnClose(true); } break; case AnalysisType::DeviceParamsCfg: { - new_view = new DeviceConfigView; + new_view = new MeasureDeviceParamsConfigView; new_view->setDeleteOnClose(true); } break; case AnalysisType::EnergyScale: { diff --git a/src/MeasureDeviceParamsConfigView/DeviceParamsTableForm.cpp b/src/MeasureDeviceParamsConfigView/DeviceParamsTableForm.cpp new file mode 100644 index 0000000..5fa41d1 --- /dev/null +++ b/src/MeasureDeviceParamsConfigView/DeviceParamsTableForm.cpp @@ -0,0 +1,221 @@ +#include "DeviceParamsTableForm.h" +#include "ui_DeviceParamsTableForm.h" +#include +#include +#include +#include + +DeviceParamsItemDelegate::DeviceParamsItemDelegate(QObject* parent) + : QStyledItemDelegate(parent) +{ +} + +QWidget* DeviceParamsItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + QWidget* editor = nullptr; + int col = index.column(); + switch (col) { + case 1: { // 多道分辨率 + QStringList value_list { "256", "512", "1024", "2048", "4096", "8192", "16384" }; + QComboBox *combobox = new QComboBox(parent); + for (int index = 0; index < value_list.size(); ++index) { + QString value = value_list.at(index); + combobox->addItem(value, value.toInt()); + } + editor = combobox; + } break; + case 2: { // 硬件增益 + QStringList value_list { "1", "2", "4", "8", "16" }; + QComboBox *combobox = new QComboBox(parent); + for (int index = 0; index < value_list.size(); ++index) { + QString value = value_list.at(index); + combobox->addItem(value, index); + } + editor = combobox; + } break; + case 3: { // 软件增益 + QSpinBox* spinbox = new QSpinBox(parent); + spinbox->setRange(1, 2^32-1); + editor = spinbox; + } break; + case 4: { // 时间常数 + QSpinBox* spinbox = new QSpinBox(parent); + spinbox->setRange(1, 100); + editor = spinbox; + } break; + case 5: { // 直流偏移 + QSpinBox* spinbox = new QSpinBox(parent); + spinbox->setRange(-1000, 1000); + editor = spinbox; + } break; + case 6: { // 上升时间 + QSpinBox* spinbox = new QSpinBox(parent); + spinbox->setRange(1, 255); + editor = spinbox; + } break; + case 7: { // 平顶时间 + QSpinBox* spinbox = new QSpinBox(parent); + spinbox->setRange(1, 255); + editor = spinbox; + } break; + case 8: { // 最大能量范围 + QSpinBox* spinbox = new QSpinBox(parent); + spinbox->setRange(0, 99999); + editor = spinbox; + } break; + default: + break; + } + return editor; +} + +void DeviceParamsItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const +{ + QVariant value = index.data(Qt::EditRole); + int col = index.column(); + switch (col) { + case 1: + case 2: { + QComboBox *combo = qobject_cast(editor); + if (combo) { + int idx = combo->findText(value.toString()); + if (idx >= 0) combo->setCurrentIndex(idx); + } + } break; + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: { + QSpinBox *spinbox = qobject_cast(editor); + if (spinbox) { + spinbox->setValue(value.toUInt()); + } + } break; + default: + break; + } +} + +void DeviceParamsItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const +{ + int col = index.column(); + switch (col) { + case 1: + case 2: { + QComboBox *combobox = qobject_cast(editor); + if (combobox) { + model->setData(index, combobox->currentText()); + } + } break; + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: { + QSpinBox *spinbox = qobject_cast(editor); + if (spinbox) { + model->setData(index, spinbox->value()); + } + } break; + default: + break; + } +} + +void DeviceParamsItemDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + editor->setGeometry(option.rect); +} + +bool DeviceParamsItemDelegate::eventFilter(QObject* obj, QEvent* event) +{ + return QStyledItemDelegate::eventFilter(obj, event); +} + +DeviceParamsTableForm::DeviceParamsTableForm(QWidget* parent) + : QWidget(parent) + , ui(new Ui::DeviceParamsTableForm) +{ + 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->setItemDelegate(new DeviceParamsItemDelegate(this)); + + for (int row = 0; row < 32; ++row) { + ui->params_cfg_table->insertRow(row); + const QString& channel_text = QStringLiteral(u"通道%1").arg(row + 1); + 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->setItem(row, 1, new QTableWidgetItem()); + ui->params_cfg_table->setItem(row, 2, new QTableWidgetItem()); + ui->params_cfg_table->setItem(row, 3, new QTableWidgetItem()); + ui->params_cfg_table->setItem(row, 4, new QTableWidgetItem()); + ui->params_cfg_table->setItem(row, 5, new QTableWidgetItem()); + ui->params_cfg_table->setItem(row, 6, new QTableWidgetItem()); + ui->params_cfg_table->setItem(row, 7, new QTableWidgetItem()); + ui->params_cfg_table->setItem(row, 8, new QTableWidgetItem()); + ui->params_cfg_table->setItem(row, 9, new QTableWidgetItem()); + } + + connect(ui->btn_channel_select, &QPushButton::clicked, this, &DeviceParamsTableForm::onCfgChannelSelectBtnClicked); +} + +DeviceParamsTableForm::~DeviceParamsTableForm() +{ + delete ui; +} + +void DeviceParamsTableForm::onCfgChannelSelectBtnClicked() +{ + QDialog cfg_channel_select_dlg(this, Qt::Dialog | Qt::WindowCloseButtonHint); + cfg_channel_select_dlg.setWindowTitle(QString(QStringLiteral(u"设备测量参数配置通道选择"))); + cfg_channel_select_dlg.setWindowModality(Qt::WindowModal); + cfg_channel_select_dlg.setModal(true); + QVBoxLayout* layout = new QVBoxLayout(&cfg_channel_select_dlg); + // 自动计算多列排布 + int num_columns = std::sqrt(32); + if (num_columns == 0) + num_columns = 1; + QVBoxLayout* checkbox_layout = new QVBoxLayout(); + 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); + checkbox_column_layout->addWidget(check_box); + connect(check_box, &QCheckBox::stateChanged, [this, row](int state) { + ui->params_cfg_table->setRowHidden(row, state == Qt::Unchecked); + }); + 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); + // 全选和反选 + QHBoxLayout* button_layout = new QHBoxLayout(); + QPushButton* btn_all_select = new QPushButton(QString(QStringLiteral(u"全选"))); + connect(btn_all_select, &QPushButton::clicked, [this]() { + for (int row = 0; row < 32; ++row) { + ui->params_cfg_table->setRowHidden(row, true); + } + }); + button_layout->addWidget(btn_all_select); + QPushButton* btn_reserve_select = new QPushButton(QString(QStringLiteral(u"反选"))); + connect(btn_reserve_select, &QPushButton::clicked, [this]() { + for (int row = 0; row < 32; ++row) { + ui->params_cfg_table->setRowHidden(row, !ui->params_cfg_table->isRowHidden(row)); + } + }); + button_layout->addWidget(btn_reserve_select); + + layout->addLayout(button_layout); + layout->addLayout(checkbox_layout); + cfg_channel_select_dlg.exec(); +} diff --git a/src/MeasureDeviceParamsConfigView/DeviceParamsTableForm.h b/src/MeasureDeviceParamsConfigView/DeviceParamsTableForm.h new file mode 100644 index 0000000..e338568 --- /dev/null +++ b/src/MeasureDeviceParamsConfigView/DeviceParamsTableForm.h @@ -0,0 +1,44 @@ +#ifndef DEVICEPARAMSTABLEFORM_H +#define DEVICEPARAMSTABLEFORM_H + +#include +#include + +namespace Ui { +class DeviceParamsTableForm; +} + +class DeviceParamsItemDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + explicit DeviceParamsItemDelegate(QObject *parent = nullptr); + + QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + + void setEditorData(QWidget *editor, const QModelIndex &index) const override; + + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; + + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + +protected: + bool eventFilter(QObject *obj, QEvent *event) override; +}; + +class DeviceParamsTableForm : public QWidget +{ + Q_OBJECT + +public: + explicit DeviceParamsTableForm(QWidget *parent = nullptr); + ~DeviceParamsTableForm(); + +private slots: + void onCfgChannelSelectBtnClicked(); + +private: + Ui::DeviceParamsTableForm *ui; +}; + +#endif // DEVICEPARAMSTABLEFORM_H diff --git a/src/MeasureDeviceParamsConfigView/DeviceParamsTableForm.ui b/src/MeasureDeviceParamsConfigView/DeviceParamsTableForm.ui new file mode 100644 index 0000000..73957c2 --- /dev/null +++ b/src/MeasureDeviceParamsConfigView/DeviceParamsTableForm.ui @@ -0,0 +1,105 @@ + + + DeviceParamsTableForm + + + + 0 + 0 + 891 + 474 + + + + Form + + + + + + + + + + 配置通道选择 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 保存 + + + + + + + + + + 通道 + + + + + 道址数 + + + + + 硬件增益 + + + + + 软件增益 + + + + + 时间常数 + + + + + 直流偏移 + + + + + 上升时间 + + + + + 平顶时间 + + + + + 最大能量范围 + + + + + + + + + diff --git a/src/MeasureDeviceParamsConfigView/MeasureDeviceParamsConfigView.cpp b/src/MeasureDeviceParamsConfigView/MeasureDeviceParamsConfigView.cpp new file mode 100644 index 0000000..f4a5eda --- /dev/null +++ b/src/MeasureDeviceParamsConfigView/MeasureDeviceParamsConfigView.cpp @@ -0,0 +1,27 @@ +#include "MeasureDeviceParamsConfigView.h" +#include "DeviceParamsTableForm.h" +#include + +MeasureDeviceParamsConfigView::MeasureDeviceParamsConfigView(QWidget *parent) + : MeasureAnalysisView(parent) +{ + _device_params_table = new DeviceParamsTableForm; + QVBoxLayout* layout = new QVBoxLayout(this); + layout->addWidget(_device_params_table); + layout->setContentsMargins(0, 0, 0, 0); +} + +MeasureDeviceParamsConfigView::~MeasureDeviceParamsConfigView() +{ + +} + +void MeasureDeviceParamsConfigView::InitViewWorkspace(const QString &project_name) +{ + +} + +void MeasureDeviceParamsConfigView::SetAnalyzeDataFilename(const QMap &data_files_set) +{ + +} diff --git a/src/MeasureDeviceParamsConfigView/MeasureDeviceParamsConfigView.h b/src/MeasureDeviceParamsConfigView/MeasureDeviceParamsConfigView.h new file mode 100644 index 0000000..a3d7e93 --- /dev/null +++ b/src/MeasureDeviceParamsConfigView/MeasureDeviceParamsConfigView.h @@ -0,0 +1,24 @@ +#ifndef MEASUREDEVICEPARAMSCONFIGVIEW_H +#define MEASUREDEVICEPARAMSCONFIGVIEW_H + +#include +#include +#include + +class DeviceParamsTableForm; + +class MeasureDeviceParamsConfigView : public MeasureAnalysisView +{ + Q_OBJECT +public: + MeasureDeviceParamsConfigView(QWidget *parent = nullptr); + virtual ~MeasureDeviceParamsConfigView(); + + virtual void InitViewWorkspace(const QString& project_name) override final; + virtual void SetAnalyzeDataFilename(const QMap& data_files_set); + +private: + DeviceParamsTableForm* _device_params_table = nullptr; +}; + +#endif // MEASUREDEVICEPARAMSCONFIGVIEW_H diff --git a/src/src.pro b/src/src.pro index 3338fc7..f6dd284 100644 --- a/src/src.pro +++ b/src/src.pro @@ -42,6 +42,7 @@ INCLUDEPATH += \ $${PWD}/MeasureAnalysisDataTableView \ $${PWD}/ParticleTimeDifferenceView \ $${PWD}/MeasureAnalysisHistoryForm \ + $${PWD}/MeasureDeviceParamsConfigView \ $${PWD}/DeviceParameterConfig @@ -57,6 +58,7 @@ DEPENDPATH += \ $${PWD}/MeasureAnalysisDataTableView \ $${PWD}/ParticleTimeDifferenceView \ $${PWD}/MeasureAnalysisHistoryForm \ + $${PWD}/MeasureDeviceParamsConfigView \ $${PWD}/DeviceParameterConfig @@ -76,6 +78,8 @@ SOURCES += \ MainWindow.cpp \ MeasureAnalysisDataTableView/MeasureAnalysisDataTableView.cpp \ MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.cpp \ + MeasureDeviceParamsConfigView/DeviceParamsTableForm.cpp \ + MeasureDeviceParamsConfigView/MeasureDeviceParamsConfigView.cpp \ ParticleCountPlotView/BatchEnergyScaleDialog.cpp \ ParticleCountPlotView/FindPeaksResultDialog.cpp \ ParticleCountPlotView/ParticleCountPlotView.cpp \ @@ -116,6 +120,8 @@ HEADERS += \ MainWindow.h \ MeasureAnalysisDataTableView/MeasureAnalysisDataTableView.h \ MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.h \ + MeasureDeviceParamsConfigView/DeviceParamsTableForm.h \ + MeasureDeviceParamsConfigView/MeasureDeviceParamsConfigView.h \ ParticleCountPlotView/BatchEnergyScaleDialog.h \ ParticleCountPlotView/FindPeaksResultDialog.h \ ParticleCountPlotView/ParticleCountPlotView.h \ @@ -146,6 +152,7 @@ FORMS += \ EnergyScaleForm.ui \ MainWindow.ui \ MeasureAnalysisHistoryForm/MeasureAnalysisHistoryForm.ui \ + MeasureDeviceParamsConfigView/DeviceParamsTableForm.ui \ ParticleCountPlotView/BatchEnergyScaleDialog.ui \ MeasureDeviceParamsCfgForm.ui \ NewMeasureAnalysisDlg.ui \ diff --git a/style/logo.rc b/style/logo.rc new file mode 100644 index 0000000..c97a35b --- /dev/null +++ b/style/logo.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "logo/logo.ico"