228 lines
7.1 KiB
C++
228 lines
7.1 KiB
C++
#include "ctExtraInfoDlg.h"
|
||
#include "ui_ctExtraInfoDlg.h"
|
||
#include "baseProperty.h"
|
||
#include "basePropertyManager.h"
|
||
#include <QButtonGroup>
|
||
#include <QJsonArray>
|
||
|
||
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);
|
||
_count = 0;
|
||
}
|
||
|
||
CtExtraInfoDlg::~CtExtraInfoDlg()
|
||
{
|
||
delete ui;
|
||
}
|
||
|
||
void CtExtraInfoDlg::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> CtExtraInfoDlg::getPropertyValue(BaseProperty* pPro)
|
||
{
|
||
QMap<QString,propertyStateInfo> map;
|
||
|
||
for(auto &pro:_mapPro)
|
||
{
|
||
propertyStateInfo info;
|
||
info.type = pro.proType;
|
||
info.name = pro.proName;
|
||
if(info.name == "额定电流(A)" || info.name == "in_a") //此处应为类型名
|
||
{
|
||
info.defaultValue = ui->le_ratedCurrent->text();
|
||
}
|
||
else if(info.name == "工频耐压(V/1min)" || info.name == "uac_v_1min")
|
||
{
|
||
info.defaultValue = ui->le_pfwv_ct->text();
|
||
}
|
||
else if(info.name == "冲击耐压(V)" || info.name == "uimp_v")
|
||
{
|
||
info.defaultValue = ui->le_iwv_ct->text();
|
||
}
|
||
else if(info.name == "动稳定电流(A)" || info.name == "dsc_a")
|
||
{
|
||
info.defaultValue = ui->le_dsc_ct->text();
|
||
}
|
||
else if(info.name == "仪表保安系数" || info.name == "fs")
|
||
{
|
||
info.defaultValue = ui->le_isf->text();
|
||
}
|
||
else if(info.name == "热稳定电流(A)" || info.name == "ith_a")
|
||
{
|
||
info.defaultValue = ui->le_sttc->text();
|
||
}
|
||
else if(info.name == "额定频率(Hz)" || info.name == "fn_hz")
|
||
{
|
||
info.defaultValue = ui->le_rf_ct->text();
|
||
}
|
||
else if(info.name == "相数" || info.name == "phase_num")
|
||
{
|
||
if(ui->rb_tpt_ct->isChecked())
|
||
info.defaultValue = 1;
|
||
else
|
||
info.defaultValue = 0;
|
||
}
|
||
else if(info.name == "CT绕组" || info.name == "ct_winding")
|
||
{
|
||
QJsonObject object;
|
||
QJsonArray arr;
|
||
for(auto info:_mapCT)
|
||
{
|
||
QJsonObject obj;
|
||
obj["id"] = info.id;
|
||
obj["transformationRatio"] = info.transRatio;
|
||
obj["accuracyClass"] = info.accuracyClass;
|
||
obj["secondaryLoadCapacity"] = info.secondaryLoadCapacity;
|
||
arr.push_back(obj);
|
||
}
|
||
object["winding"] = arr;
|
||
info.defaultValue = object;
|
||
}
|
||
map.insert(pro.proName,info);
|
||
}
|
||
pPro->setDataChanged(true);
|
||
return map;
|
||
}
|
||
|
||
void CtExtraInfoDlg::setPropertyValue(QVariant var)
|
||
{
|
||
BaseProperty* pPro = static_cast<BaseProperty*>(var.value<void*>());
|
||
if(pPro)
|
||
{
|
||
QMap<QString,propertyStateInfo> map = var.value<QMap<QString,propertyStateInfo>>();
|
||
for(auto &info:map)
|
||
{
|
||
if(info.name == "额定电流") //此处应为类型名
|
||
{
|
||
ui->le_ratedCurrent->setText(QString::number(info.defaultValue.toDouble()));
|
||
}
|
||
else if(info.name == "工频耐压")
|
||
{
|
||
ui->le_pfwv_ct->setText(QString::number(info.defaultValue.toDouble()));
|
||
}
|
||
else if(info.name == "冲击耐压")
|
||
{
|
||
ui->le_iwv_ct->setText(QString::number(info.defaultValue.toDouble()));
|
||
}
|
||
else if(info.name == "动稳定电流")
|
||
{
|
||
ui->le_dsc_ct->setText(QString::number(info.defaultValue.toDouble()));
|
||
}
|
||
else if(info.name == "仪表保安系数")
|
||
{
|
||
ui->le_isf->setText(info.defaultValue.toString());
|
||
}
|
||
else if(info.name == "短时热电流")
|
||
{
|
||
ui->le_sttc->setText(QString::number(info.defaultValue.toDouble()));
|
||
}
|
||
else if(info.name == "额定频率")
|
||
{
|
||
ui->le_rf_ct->setText(QString::number(info.defaultValue.toDouble()));
|
||
}
|
||
else if(info.name == "相数")
|
||
{
|
||
if(info.defaultValue.toInt() == 1)
|
||
ui->rb_tpt_ct->setChecked(true);
|
||
else
|
||
ui->rb_zst_ct->setChecked(true);
|
||
}
|
||
else if(info.name == "ct绕组")
|
||
{
|
||
QJsonObject object = info.defaultValue.toJsonObject();
|
||
QJsonArray arr = object["winding"].toArray();
|
||
for (QJsonValueRef jsonObj : arr)
|
||
{
|
||
QJsonObject node = jsonObj.toObject();
|
||
int id = node["id"].toInt();
|
||
QString sTr = node["transformationRatio"].toString();
|
||
QString sAr = node["accuracyClass"].toString();
|
||
QString sSlc = node["secondaryLoadCapacity"].toString();
|
||
|
||
addTableRow(sTr,sAr,sSlc,id);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void CtExtraInfoDlg::onAddClicked()
|
||
{
|
||
QString sTr = ui->le_tr_ct->text();
|
||
QString sAr = ui->le_ac_ct->text();
|
||
QString sSlc = ui->le_slc_ct->text();
|
||
addTableRow(sTr,sAr,sSlc);
|
||
}
|
||
|
||
void CtExtraInfoDlg::onDeleteClicked()
|
||
{
|
||
QPushButton *btn = qobject_cast<QPushButton*>(sender());
|
||
if (btn) {
|
||
// 获取按钮在表格中的位置
|
||
QModelIndex index = ui->tb_ct->indexAt(btn->pos());
|
||
if (index.isValid()) {
|
||
QTableWidgetItem* pFirstItem = ui->tb_ct->item(index.row(),0);
|
||
int id = pFirstItem->data(Qt::UserRole).toInt();
|
||
_mapCT.remove(QString::number(id));
|
||
ui->tb_ct->removeRow(index.row());
|
||
}
|
||
}
|
||
}
|
||
|
||
void CtExtraInfoDlg::addTableRow(QString sTr,QString sAr,QString sSlc,int id)
|
||
{
|
||
if(_mapCT.contains(QString::number(id)))
|
||
{
|
||
return;
|
||
}
|
||
|
||
CtExtraInfo info;
|
||
if(id == -1){ //缺省id时新建,否则加载
|
||
info.id = _count;
|
||
_count += 1;
|
||
}
|
||
else{
|
||
info.id = id;
|
||
}
|
||
|
||
int row = ui->tb_ct->rowCount();
|
||
ui->tb_ct->insertRow(row);
|
||
|
||
// 变比(输入框)
|
||
QTableWidgetItem *item = new QTableWidgetItem(sTr);
|
||
item->setData(Qt::UserRole,info.id);
|
||
ui->tb_ct->setItem(row, 0, item);
|
||
|
||
// 精度等级(下拉框)
|
||
ui->tb_ct->setItem(row, 1, new QTableWidgetItem(sAr));
|
||
|
||
// 二次负载容量(输入框)
|
||
ui->tb_ct->setItem(row, 2, new QTableWidgetItem(sSlc));
|
||
|
||
|
||
// 删除按钮
|
||
QPushButton *deleteBtn = new QPushButton("删除");
|
||
connect(deleteBtn, &QPushButton::clicked, this, &CtExtraInfoDlg::onDeleteClicked);
|
||
ui->tb_ct->setCellWidget(row, 3, deleteBtn);
|
||
|
||
info.transRatio = sTr;
|
||
info.accuracyClass = sAr;
|
||
info.secondaryLoadCapacity = sSlc;
|
||
_mapCT.insert(QString::number(info.id),info);
|
||
}
|