222 lines
7.6 KiB
C++
222 lines
7.6 KiB
C++
|
|
#include "DeviceParamsTableForm.h"
|
||
|
|
#include "ui_DeviceParamsTableForm.h"
|
||
|
|
#include <QComboBox>
|
||
|
|
#include <QDialog>
|
||
|
|
#include <QCheckBox>
|
||
|
|
#include <QSpinBox>
|
||
|
|
|
||
|
|
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<QComboBox*>(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<QSpinBox*>(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<QComboBox*>(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<QSpinBox*>(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();
|
||
|
|
}
|