188 lines
5.6 KiB
C++
188 lines
5.6 KiB
C++
|
|
#include <QButtonGroup>
|
||
|
|
#include <QJsonArray>
|
||
|
|
#include <QMutableListIterator>
|
||
|
|
#include <QMenu>
|
||
|
|
#include "bayInfoDlg.h"
|
||
|
|
#include "ui_bayInfoDlg.h"
|
||
|
|
#include "baseProperty.h"
|
||
|
|
#include "basePropertyManager.h"
|
||
|
|
#include "measureSettingDlg.h"
|
||
|
|
#include "dataBase.h"
|
||
|
|
|
||
|
|
BayInfoDlg::BayInfoDlg(QWidget *parent)
|
||
|
|
: BaseContentDlg(parent)
|
||
|
|
, ui(new Ui::bayInfoDlg)
|
||
|
|
,_measureDlg(nullptr)
|
||
|
|
{
|
||
|
|
ui->setupUi(this);
|
||
|
|
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
|
||
|
|
initial();
|
||
|
|
}
|
||
|
|
|
||
|
|
BayInfoDlg::~BayInfoDlg()
|
||
|
|
{
|
||
|
|
delete ui;
|
||
|
|
}
|
||
|
|
|
||
|
|
void BayInfoDlg::initial()
|
||
|
|
{
|
||
|
|
setUi();
|
||
|
|
connect(ui->btn_add,&QPushButton::clicked,this,&BayInfoDlg::onAddClicked);
|
||
|
|
connect(ui->tableWidget_local, &QTableWidget::customContextMenuRequested, this, &BayInfoDlg::onIndexRbtnClicked);
|
||
|
|
}
|
||
|
|
|
||
|
|
void BayInfoDlg::createGroupView(groupStateInfo infos)
|
||
|
|
{
|
||
|
|
for(auto& info:infos.info) {
|
||
|
|
propertyContentInfo inf;
|
||
|
|
inf.proName = info.name;
|
||
|
|
inf.proType = info.type;
|
||
|
|
_mapPro.insert(info.name,inf);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
QMap<QString,propertyStateInfo> BayInfoDlg::getPropertyValue(BaseProperty* pPro)
|
||
|
|
{
|
||
|
|
QMap<QString,propertyStateInfo> map;
|
||
|
|
|
||
|
|
pPro->setMeasurement(_mapMeasure);
|
||
|
|
return map;
|
||
|
|
}
|
||
|
|
|
||
|
|
void BayInfoDlg::setPropertyValue(QVariant var)
|
||
|
|
{
|
||
|
|
BaseProperty* pPro = static_cast<BaseProperty*>(var.value<void*>());
|
||
|
|
if(pPro)
|
||
|
|
{
|
||
|
|
QList<measureAttributeType> lstType = DataBase::GetInstance()->getMeasureAttributeTypes();
|
||
|
|
auto map = pPro->getMeasurement();
|
||
|
|
|
||
|
|
/*QMutableListIterator<measureAttributeType> it(lstType);
|
||
|
|
while(it.hasNext()){ //设置可用属性
|
||
|
|
if(map.contains(it.next().name)){
|
||
|
|
it.remove();
|
||
|
|
}
|
||
|
|
}*/
|
||
|
|
_validType = lstType;
|
||
|
|
|
||
|
|
ui->tableWidget_local->clearContents(); //清空列表
|
||
|
|
for(auto& info:map){
|
||
|
|
addMeasure(info);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
void BayInfoDlg::setUi()
|
||
|
|
{
|
||
|
|
QStringList headerText;
|
||
|
|
headerText<<"TAG"<<"名称"<<"设备"<<"端子"<<"类型"<<"SIZE";
|
||
|
|
ui->tableWidget_local->setContextMenuPolicy(Qt::CustomContextMenu);
|
||
|
|
ui->tableWidget_local->setSelectionMode(QAbstractItemView::SingleSelection);
|
||
|
|
ui->tableWidget_local->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||
|
|
ui->tableWidget_local->setColumnCount(headerText.count());
|
||
|
|
ui->tableWidget_local->setHorizontalHeaderLabels(headerText);
|
||
|
|
ui->tableWidget_local->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||
|
|
ui->tableWidget_local->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||
|
|
ui->tableWidget_local->setStyleSheet(
|
||
|
|
"QTableWidget::item {"
|
||
|
|
" padding: 5px;" // 可选:增加内边距
|
||
|
|
" white-space: pre-wrap;" // 关键:保留空白符并允许自动换行
|
||
|
|
"}"
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
void BayInfoDlg::addMeasure(MeasurementInfo info)
|
||
|
|
{
|
||
|
|
if(_mapMeasure.contains(info.name))
|
||
|
|
return;
|
||
|
|
int row = ui->tableWidget_local->rowCount();
|
||
|
|
ui->tableWidget_local->insertRow(row);
|
||
|
|
|
||
|
|
QTableWidgetItem* tagItem = new QTableWidgetItem(info.tag);
|
||
|
|
ui->tableWidget_local->setItem(row, 0, tagItem);
|
||
|
|
|
||
|
|
QTableWidgetItem* nameItem = new QTableWidgetItem(info.name);
|
||
|
|
ui->tableWidget_local->setItem(row, 1, nameItem);
|
||
|
|
|
||
|
|
QTableWidgetItem* deviceItem = new QTableWidgetItem(info.equipment);
|
||
|
|
ui->tableWidget_local->setItem(row, 2, deviceItem);
|
||
|
|
|
||
|
|
QTableWidgetItem* channelItem = new QTableWidgetItem(info.channel);
|
||
|
|
ui->tableWidget_local->setItem(row, 3, channelItem);
|
||
|
|
|
||
|
|
QTableWidgetItem* typeItem = new QTableWidgetItem(info.type);
|
||
|
|
ui->tableWidget_local->setItem(row, 4, typeItem);
|
||
|
|
|
||
|
|
QTableWidgetItem* sizeItem = new QTableWidgetItem(QString::number(info.size));
|
||
|
|
ui->tableWidget_local->setItem(row, 5, sizeItem);
|
||
|
|
|
||
|
|
_mapMeasure.insert(info.name,info);
|
||
|
|
for(int i = 0;i < _validType.size();++i){
|
||
|
|
if(_validType.at(i).name == info.name){ //可用类型中移除该类型
|
||
|
|
_validType.removeAt(i);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void BayInfoDlg::onAddClicked()
|
||
|
|
{
|
||
|
|
if(_measureDlg == nullptr){
|
||
|
|
_measureDlg = new MeasureSettingDlg(this);
|
||
|
|
_measureDlg->setBay(this);
|
||
|
|
}
|
||
|
|
_measureDlg->showDlg();
|
||
|
|
}
|
||
|
|
|
||
|
|
void BayInfoDlg::onDeleteClicked()
|
||
|
|
{
|
||
|
|
// 获取当前选中的索引
|
||
|
|
QModelIndexList selectedIndexes = ui->tableWidget_local->selectionModel()->selectedRows();
|
||
|
|
if (selectedIndexes.isEmpty()) {
|
||
|
|
return; // 没有选中任何行
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取当前选中的第一项索引
|
||
|
|
QModelIndex index = selectedIndexes.first();
|
||
|
|
if (!index.isValid()) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
QModelIndex indexName = index.sibling(index.row(),1);
|
||
|
|
QString sName = indexName.data().toString();
|
||
|
|
if(_mapMeasure.contains(sName)){
|
||
|
|
MeasurementInfo info = _mapMeasure.take(sName);
|
||
|
|
measureAttributeType typ;
|
||
|
|
typ.name = info.name;
|
||
|
|
typ.tag = info.tag;
|
||
|
|
_validType.append(typ);
|
||
|
|
}
|
||
|
|
|
||
|
|
int currentRow = ui->tableWidget_local->currentRow();
|
||
|
|
if (currentRow == -1) {
|
||
|
|
return; // 没有选中行
|
||
|
|
}
|
||
|
|
|
||
|
|
ui->tableWidget_local->removeRow(currentRow);
|
||
|
|
}
|
||
|
|
|
||
|
|
void BayInfoDlg::onIndexRbtnClicked(const QPoint &pos)
|
||
|
|
{
|
||
|
|
// 获取当前点击的位置对应的索引
|
||
|
|
QModelIndex index = ui->tableWidget_local->indexAt(pos);
|
||
|
|
if (!index.isValid()) {
|
||
|
|
return; // 如果点击的是空白区域,直接返回
|
||
|
|
}
|
||
|
|
|
||
|
|
QMenu menu;
|
||
|
|
QAction *deleteAction = new QAction("移除量测", this);
|
||
|
|
menu.addAction(deleteAction);
|
||
|
|
|
||
|
|
// 连接删除菜单项的触发信号与槽函数
|
||
|
|
connect(deleteAction, &QAction::triggered, this, &BayInfoDlg::onDeleteClicked);
|
||
|
|
|
||
|
|
// 在点击位置显示菜单
|
||
|
|
menu.exec(ui->tableWidget_local->mapToGlobal(pos));
|
||
|
|
}
|