2025-05-23 10:30:52 +08:00
|
|
|
|
#include "ctExtraInfoDlg.h"
|
|
|
|
|
|
#include "ui_ctExtraInfoDlg.h"
|
|
|
|
|
|
#include "baseProperty.h"
|
|
|
|
|
|
#include "basePropertyManager.h"
|
|
|
|
|
|
#include <QButtonGroup>
|
|
|
|
|
|
#include <QJsonArray>
|
2025-11-05 18:14:31 +08:00
|
|
|
|
#include <QJsonDocument>
|
2026-01-16 18:40:46 +08:00
|
|
|
|
#include <QMenu>
|
2025-05-23 10:30:52 +08:00
|
|
|
|
|
|
|
|
|
|
CtExtraInfoDlg::CtExtraInfoDlg(QWidget *parent)
|
|
|
|
|
|
: BaseContentDlg(parent)
|
|
|
|
|
|
, ui(new Ui::ctExtraInfoDlg)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
_stateGroup_ct = new QButtonGroup(this);
|
|
|
|
|
|
_stateGroup_ct->addButton(ui->rb_tpt_ct,1);
|
|
|
|
|
|
_stateGroup_ct->addButton(ui->rb_zst_ct,0);
|
|
|
|
|
|
|
|
|
|
|
|
connect(ui->btn_add_ct,&QPushButton::clicked,this,&CtExtraInfoDlg::onAddClicked);
|
2026-01-16 18:40:46 +08:00
|
|
|
|
|
|
|
|
|
|
ui->tb_ct->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
|
|
|
|
_count = 1;
|
|
|
|
|
|
|
|
|
|
|
|
ui->tb_ct->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
|
connect(ui->tb_ct, &QTableWidget::customContextMenuRequested, this, &CtExtraInfoDlg::onTableCustomContextMenuRequested);
|
2025-05-23 10:30:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CtExtraInfoDlg::~CtExtraInfoDlg()
|
|
|
|
|
|
{
|
|
|
|
|
|
delete ui;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CtExtraInfoDlg::createGroupView(groupStateInfo infos)
|
|
|
|
|
|
{
|
|
|
|
|
|
for(auto& info:infos.info) {
|
|
|
|
|
|
propertyContentInfo inf;
|
2026-01-09 17:43:58 +08:00
|
|
|
|
inf.proTag = info.tagName;
|
2025-05-23 10:30:52 +08:00
|
|
|
|
inf.proName = info.name;
|
|
|
|
|
|
inf.proType = info.type;
|
2026-01-09 17:43:58 +08:00
|
|
|
|
_mapPro.insert(info.tagName,inf);
|
2025-05-23 10:30:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QMap<QString,propertyStateInfo> CtExtraInfoDlg::getPropertyValue(BaseProperty* pPro)
|
|
|
|
|
|
{
|
|
|
|
|
|
QMap<QString,propertyStateInfo> map;
|
|
|
|
|
|
|
|
|
|
|
|
for(auto &pro:_mapPro)
|
|
|
|
|
|
{
|
|
|
|
|
|
propertyStateInfo info;
|
2026-01-09 17:43:58 +08:00
|
|
|
|
info.tagName = pro.proTag;
|
2025-05-23 10:30:52 +08:00
|
|
|
|
info.type = pro.proType;
|
|
|
|
|
|
info.name = pro.proName;
|
2026-01-09 17:43:58 +08:00
|
|
|
|
if(info.name == "额定电流(A)" || info.tagName == "in_a") //此处应为类型名
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
info.defaultValue = ui->le_ratedCurrent->text();
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "工频耐压(V/1min)" || info.tagName == "uac_v_1min")
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
info.defaultValue = ui->le_pfwv_ct->text();
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "冲击耐压(V)" || info.tagName == "uimp_v")
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
info.defaultValue = ui->le_iwv_ct->text();
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "动稳定电流(A)" || info.tagName == "dsc_a")
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
info.defaultValue = ui->le_dsc_ct->text();
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "仪表保安系数" || info.tagName == "fs")
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
info.defaultValue = ui->le_isf->text();
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "热稳定电流(A)" || info.tagName == "ith_a")
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
info.defaultValue = ui->le_sttc->text();
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "额定频率(Hz)" || info.tagName == "fn_hz")
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
info.defaultValue = ui->le_rf_ct->text();
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "相数" || info.tagName == "phase_num")
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
if(ui->rb_tpt_ct->isChecked())
|
|
|
|
|
|
info.defaultValue = 1;
|
|
|
|
|
|
else
|
|
|
|
|
|
info.defaultValue = 0;
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "CT绕组" || info.tagName == "ct_winding")
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
QJsonObject object;
|
|
|
|
|
|
QJsonArray arr;
|
2026-01-16 18:40:46 +08:00
|
|
|
|
for(auto &info:_mapCT)
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
QJsonObject obj;
|
2026-01-16 18:40:46 +08:00
|
|
|
|
obj["index"] = info.index;
|
|
|
|
|
|
obj["scope"] = info.scope;
|
|
|
|
|
|
obj["accuracy"] = info.accuracy;
|
|
|
|
|
|
obj["volume"] = info.volume;
|
|
|
|
|
|
obj["ratio"] = info.ratio;
|
|
|
|
|
|
obj["polarity"] = info.polarity;
|
2025-05-23 10:30:52 +08:00
|
|
|
|
arr.push_back(obj);
|
|
|
|
|
|
}
|
|
|
|
|
|
object["winding"] = arr;
|
|
|
|
|
|
info.defaultValue = object;
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
map.insert(pro.proTag,info);
|
2025-05-23 10:30:52 +08:00
|
|
|
|
}
|
2025-07-22 20:00:46 +08:00
|
|
|
|
pPro->setDataChanged(true);
|
2025-05-23 10:30:52 +08:00
|
|
|
|
return map;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CtExtraInfoDlg::setPropertyValue(QVariant var)
|
|
|
|
|
|
{
|
2025-11-05 18:14:31 +08:00
|
|
|
|
QMap<QString,propertyStateInfo> map = var.value<QMap<QString,propertyStateInfo>>();
|
|
|
|
|
|
for(auto &info:map)
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
2026-01-09 17:43:58 +08:00
|
|
|
|
if(info.name == "额定电流(A)" || info.tagName == "in_a") //此处应为类型名
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
2025-11-05 18:14:31 +08:00
|
|
|
|
ui->le_ratedCurrent->setText(QString::number(info.defaultValue.toDouble()));
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "工频耐压(V/1min)" || info.tagName == "uac_v_1min")
|
2025-11-05 18:14:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
ui->le_pfwv_ct->setText(QString::number(info.defaultValue.toDouble()));
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "冲击耐压(V)" || info.tagName == "uimp_v")
|
2025-11-05 18:14:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
ui->le_iwv_ct->setText(QString::number(info.defaultValue.toDouble()));
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "动稳定电流(A)" || info.tagName == "dsc_a")
|
2025-11-05 18:14:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
ui->le_dsc_ct->setText(QString::number(info.defaultValue.toDouble()));
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "仪表保安系数" || info.tagName == "fs")
|
2025-11-05 18:14:31 +08:00
|
|
|
|
{
|
2025-12-25 09:03:35 +08:00
|
|
|
|
if(info.defaultValue.toString() == "null")
|
|
|
|
|
|
ui->le_isf->setText(0);
|
|
|
|
|
|
ui->le_isf->setText(QString::number(info.defaultValue.toDouble()));
|
2025-11-05 18:14:31 +08:00
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "热稳定电流(A)" || info.tagName == "ith_a")
|
2025-11-05 18:14:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
ui->le_sttc->setText(QString::number(info.defaultValue.toDouble()));
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "额定频率(Hz)" || info.tagName == "fn_hz")
|
2025-11-05 18:14:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
ui->le_rf_ct->setText(QString::number(info.defaultValue.toDouble()));
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "相数" || info.tagName == "phase_num")
|
2025-11-05 18:14:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
if(info.defaultValue.toInt() == 1)
|
|
|
|
|
|
ui->rb_tpt_ct->setChecked(true);
|
|
|
|
|
|
else
|
|
|
|
|
|
ui->rb_zst_ct->setChecked(true);
|
|
|
|
|
|
}
|
2026-01-09 17:43:58 +08:00
|
|
|
|
else if(info.name == "CT绕组" || info.tagName == "ct_winding")
|
2025-11-05 18:14:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
QString jsonString = info.defaultValue.toString();
|
|
|
|
|
|
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonString.toUtf8().data());
|
|
|
|
|
|
QJsonObject jsonObject = jsonDocument.object();
|
|
|
|
|
|
|
|
|
|
|
|
QJsonObject object = jsonObject;
|
|
|
|
|
|
QJsonArray arr = object["winding"].toArray();
|
|
|
|
|
|
for (QJsonValueRef jsonObj : arr)
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
2025-11-05 18:14:31 +08:00
|
|
|
|
QJsonObject node = jsonObj.toObject();
|
2026-01-16 18:40:46 +08:00
|
|
|
|
int index = node["index"].toInt();
|
|
|
|
|
|
QString sRatioRange = node["scope"].toString();
|
|
|
|
|
|
QString sAccuracy = node["accuracy"].toString();
|
|
|
|
|
|
QString sVolume = node["volume"].toString();
|
|
|
|
|
|
double dRatio = node["ratio"].toDouble();
|
|
|
|
|
|
bool bPolarity = node["polarity"].toBool();
|
|
|
|
|
|
|
|
|
|
|
|
addTableRow(sRatioRange,sAccuracy,sVolume,dRatio,bPolarity,index);
|
2025-05-23 10:30:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CtExtraInfoDlg::onAddClicked()
|
|
|
|
|
|
{
|
2026-01-16 18:40:46 +08:00
|
|
|
|
QString sRatioRange = ui->le_tr_range_ct->text();
|
|
|
|
|
|
QString sAccuracy= ui->le_ac_ct->text();
|
|
|
|
|
|
QString sVolume = ui->le_slc_ct->text();
|
|
|
|
|
|
double dRatio = ui->le_tr_ct->text().toDouble();
|
|
|
|
|
|
bool bPolarity = ui->cb_polarity->checkState();
|
|
|
|
|
|
int index = -1;
|
|
|
|
|
|
if(ui->rb_zst_ct->isChecked())
|
|
|
|
|
|
index = 0;
|
|
|
|
|
|
addTableRow(sRatioRange,sAccuracy,sVolume,dRatio,bPolarity,index);
|
2025-05-23 10:30:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-16 18:40:46 +08:00
|
|
|
|
void CtExtraInfoDlg::onTableCustomContextMenuRequested(const QPoint &pos) {
|
|
|
|
|
|
QModelIndex index = ui->tb_ct->indexAt(pos);
|
|
|
|
|
|
if (!index.isValid()) {
|
|
|
|
|
|
return;
|
2025-05-23 10:30:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-16 18:40:46 +08:00
|
|
|
|
int row = index.row();
|
|
|
|
|
|
|
|
|
|
|
|
// 创建右键菜单
|
|
|
|
|
|
QMenu menu(this);
|
|
|
|
|
|
QAction *deleteAction = menu.addAction("删除此行");
|
|
|
|
|
|
|
|
|
|
|
|
// 连接删除操作
|
|
|
|
|
|
connect(deleteAction, &QAction::triggered, this, [this, row]() {
|
|
|
|
|
|
deleteRowWithReindex(row);
|
|
|
|
|
|
updateLables();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
menu.exec(ui->tb_ct->viewport()->mapToGlobal(pos));
|
|
|
|
|
|
}
|
|
|
|
|
|
void CtExtraInfoDlg::addTableRow(QString sRatioRange,QString sAccuracy,QString sVolume,double dRatio,bool bPolarity,int index)
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
2026-01-16 18:40:46 +08:00
|
|
|
|
if(_mapCT.contains(QString::number(index)))
|
2025-05-23 10:30:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CtExtraInfo info;
|
2026-01-16 18:40:46 +08:00
|
|
|
|
if(index == -1){ //缺省id时新建,否则加载
|
|
|
|
|
|
info.index = _count;
|
2025-05-23 10:30:52 +08:00
|
|
|
|
_count += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else{
|
2026-01-16 18:40:46 +08:00
|
|
|
|
info.index = index;
|
2025-05-23 10:30:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int row = ui->tb_ct->rowCount();
|
|
|
|
|
|
ui->tb_ct->insertRow(row);
|
|
|
|
|
|
|
2026-01-16 18:40:46 +08:00
|
|
|
|
//index
|
|
|
|
|
|
QTableWidgetItem *item = new QTableWidgetItem(QString::number(info.index));
|
|
|
|
|
|
item->setData(Qt::UserRole,info.index);
|
2025-05-23 10:30:52 +08:00
|
|
|
|
ui->tb_ct->setItem(row, 0, item);
|
|
|
|
|
|
|
2026-01-16 18:40:46 +08:00
|
|
|
|
//变比范围
|
|
|
|
|
|
ui->tb_ct->setItem(row, 1, new QTableWidgetItem(sRatioRange));
|
|
|
|
|
|
|
|
|
|
|
|
//精度等级
|
|
|
|
|
|
ui->tb_ct->setItem(row, 2, new QTableWidgetItem(sAccuracy));
|
|
|
|
|
|
|
|
|
|
|
|
//二次负载容量
|
|
|
|
|
|
ui->tb_ct->setItem(row, 3, new QTableWidgetItem(sVolume));
|
|
|
|
|
|
|
|
|
|
|
|
//变比
|
|
|
|
|
|
ui->tb_ct->setItem(row, 4, new QTableWidgetItem(QString::number(dRatio)));
|
|
|
|
|
|
|
|
|
|
|
|
//极性
|
|
|
|
|
|
ui->tb_ct->setItem(row, 5, new QTableWidgetItem(QString::number(bPolarity? 1 : -1)));
|
|
|
|
|
|
|
|
|
|
|
|
info.scope = sRatioRange;
|
|
|
|
|
|
info.accuracy = sAccuracy;
|
|
|
|
|
|
info.volume = sVolume;
|
|
|
|
|
|
info.ratio = dRatio;
|
|
|
|
|
|
info.polarity = bPolarity? 1 : -1;
|
|
|
|
|
|
_mapCT.insert(QString::number(info.index),info);
|
|
|
|
|
|
|
|
|
|
|
|
updateLables();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CtExtraInfoDlg::updateShowLabel(QStringList lst)
|
|
|
|
|
|
{
|
|
|
|
|
|
_curLabels = lst;
|
|
|
|
|
|
ui->label_title_ct->setText(_curLabels.join(" "));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CtExtraInfoDlg::updateLables()
|
|
|
|
|
|
{
|
|
|
|
|
|
QStringList lst; //更新显示标签
|
|
|
|
|
|
for(auto& info:_mapCT){
|
|
|
|
|
|
QString sLabel = info.scope+" "+info.accuracy+" "+info.volume;
|
|
|
|
|
|
lst.append(sLabel);
|
|
|
|
|
|
}
|
|
|
|
|
|
updateShowLabel(lst);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CtExtraInfoDlg::deleteRowWithReindex(int row) {
|
|
|
|
|
|
// 1. 获取要删除的ID
|
|
|
|
|
|
QTableWidgetItem* pFirstItem = ui->tb_ct->item(row, 0);
|
|
|
|
|
|
if (!pFirstItem) return;
|
|
|
|
|
|
|
|
|
|
|
|
int deletedId = pFirstItem->data(Qt::UserRole).toInt();
|
|
|
|
|
|
QString deletedKey = QString::number(deletedId);
|
2025-11-05 18:14:31 +08:00
|
|
|
|
|
2026-01-16 18:40:46 +08:00
|
|
|
|
// 2. 从表格中删除行
|
|
|
|
|
|
ui->tb_ct->removeRow(row);
|
2025-11-05 18:14:31 +08:00
|
|
|
|
|
2026-01-16 18:40:46 +08:00
|
|
|
|
// 3. 从_mapCT中删除对应项
|
|
|
|
|
|
if (_mapCT.contains(deletedKey)) {
|
|
|
|
|
|
_mapCT.remove(deletedKey);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 重新排序和更新index
|
|
|
|
|
|
reorderMapAndUpdateIndices(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CtExtraInfoDlg::reorderMapAndUpdateIndices(int startRow) {
|
|
|
|
|
|
int totalRows = ui->tb_ct->rowCount();
|
|
|
|
|
|
|
|
|
|
|
|
// 遍历从startRow开始的所有行
|
|
|
|
|
|
for (int row = startRow; row < totalRows; ++row) {
|
|
|
|
|
|
QTableWidgetItem* idItem = ui->tb_ct->item(row, 0);
|
|
|
|
|
|
if (!idItem) continue;
|
2025-05-23 10:30:52 +08:00
|
|
|
|
|
2026-01-16 18:40:46 +08:00
|
|
|
|
int currentId = idItem->data(Qt::UserRole).toInt();
|
|
|
|
|
|
QString currentKey = QString::number(currentId);
|
2025-05-23 10:30:52 +08:00
|
|
|
|
|
2026-01-16 18:40:46 +08:00
|
|
|
|
// 计算新的ID和索引
|
|
|
|
|
|
int newId = row + 1; // 新的ID
|
|
|
|
|
|
int newIndex = row + 1; // 新的索引
|
2025-05-23 10:30:52 +08:00
|
|
|
|
|
2026-01-16 18:40:46 +08:00
|
|
|
|
if (_mapCT.contains(currentKey)) {
|
|
|
|
|
|
// 获取并更新数据
|
|
|
|
|
|
CtExtraInfo info = _mapCT[currentKey];
|
|
|
|
|
|
info.index = newIndex;
|
2025-05-23 10:30:52 +08:00
|
|
|
|
|
2026-01-16 18:40:46 +08:00
|
|
|
|
// 从旧位置移除
|
|
|
|
|
|
_mapCT.remove(currentKey);
|
|
|
|
|
|
|
|
|
|
|
|
// 添加到新位置
|
|
|
|
|
|
QString newKey = QString::number(newId);
|
|
|
|
|
|
_mapCT[newKey] = info;
|
|
|
|
|
|
|
|
|
|
|
|
// 更新表格显示
|
|
|
|
|
|
idItem->setText(QString::number(newId));
|
|
|
|
|
|
idItem->setData(Qt::UserRole, newId);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-05-23 10:30:52 +08:00
|
|
|
|
}
|