769 lines
26 KiB
C++
769 lines
26 KiB
C++
#include <QMessageBox>
|
|
#include <QMenu>
|
|
#include "diagramEditor/diagramEditorTransDetailAddDlg.h"
|
|
#include "diagramEditor/diagramEditorTransDetailSettingDlg.h"
|
|
#include "ui_diagramEditorTransDetailAddDlg.h"
|
|
#include "diagramEditor/diagramEditorBaseBlock.h"
|
|
#include "diagramEditor/diagramEditorWizard.h"
|
|
#include "include/instance/baseTypeManager.h"
|
|
|
|
DiagramEditorTransDetailAddDlg::DiagramEditorTransDetailAddDlg(QWidget *parent)
|
|
: QDialog(parent)
|
|
, ui(new Ui::diagramEditorTransDetailAddDlg)
|
|
,_selectedModel(nullptr)
|
|
,_pParent(nullptr)
|
|
,_bindItemModel(nullptr)
|
|
{
|
|
ui->setupUi(this);
|
|
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
|
|
this->setWindowModality(Qt::WindowModal);
|
|
initial();
|
|
}
|
|
|
|
DiagramEditorTransDetailAddDlg::~DiagramEditorTransDetailAddDlg()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::initial()
|
|
{
|
|
_curMode = 0;
|
|
_curType = 0;
|
|
_selectedModel = new QStandardItemModel(this);
|
|
_selectedModel->setHorizontalHeaderLabels({"分类", "名称", "类型", "关联对象", "引用线路"});
|
|
ui->tableView_selected->setModel(_selectedModel);
|
|
connect(ui->btn_add,&QPushButton::clicked,this,&DiagramEditorTransDetailAddDlg::onAddClicked);
|
|
//connect(ui->btn_delete,&QPushButton::clicked,this,&DiagramEditorBayDetailAddDlg::onDeleteClicked);
|
|
connect(ui->btn_save,&QPushButton::clicked,this,&DiagramEditorTransDetailAddDlg::onSaveClicked);
|
|
connect(ui->btn_ok,&QPushButton::clicked,this,&DiagramEditorTransDetailAddDlg::onOkClicked);
|
|
connect(ui->btn_cancel,&QPushButton::clicked,this,&DiagramEditorTransDetailAddDlg::onCancelClicked);
|
|
connect(ui->cb_category,&QComboBox::currentTextChanged,this,&DiagramEditorTransDetailAddDlg::onCategoryChanged);
|
|
connect(ui->tableView_selected, &QTableView::customContextMenuRequested, this, &DiagramEditorTransDetailAddDlg::onRouteRbtnClicked);
|
|
connect(ui->tableView_items, &QTableView::customContextMenuRequested, this, &DiagramEditorTransDetailAddDlg::onComponentRbtnClicked);
|
|
connect(ui->tableView_items, &QTableView::clicked, this, [this](const QModelIndex &index){
|
|
int row = index.row();
|
|
loadFromModelRow(row);
|
|
});
|
|
|
|
QMap<int,modelType> mapType = BaseTypeManager::getInstance()->getMapType(); //直接添加数据库中的基础类型
|
|
for(auto iter = mapType.begin();iter != mapType.end();++iter){
|
|
int index = ui->cb_type->count();
|
|
ui->cb_type->addItem(iter.value().modelName);
|
|
ui->cb_type->setItemData(index,iter->id,Qt::UserRole); //存放基模id
|
|
ui->cb_type->setItemData(index,iter->graphicElement,Qt::UserRole+1); //存放基础类型
|
|
}
|
|
ui->cb_category->addItem("电气设备",0);
|
|
ui->cb_category->addItem("连接关系",1);
|
|
|
|
ui->tableView_items->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
ui->tableView_items->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
ui->tableView_items->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
ui->tableView_items->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
ui->tableView_items->verticalHeader()->setVisible(false);
|
|
|
|
ui->tableView_selected->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
ui->tableView_selected->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
ui->tableView_selected->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
ui->tableView_selected->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
//ui->tableView_selected->verticalHeader()->setVisible(false);
|
|
|
|
_bindItemModel = new QStandardItemModel(this);
|
|
ui->cb_bindObj->setModel(_bindItemModel);
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::showDlg(int nType)
|
|
{
|
|
if(_pParent){
|
|
_selectedModel->clear();
|
|
_selectedModel->setHorizontalHeaderLabels({"分类", "名称", "类型", "关联对象", "引用线路"});
|
|
updateBindLst();
|
|
show();
|
|
auto pCompo = _pParent->getComponentModel();
|
|
auto pRoute = _pParent->getRouteModels().value(nType);
|
|
int n = pRoute->rowCount();
|
|
ui->le_routeName->setText("线路"+QString::number(n+1));
|
|
ui->tableView_items->setModel(pCompo);
|
|
ui->label->setText("新建线路");
|
|
ui->le_routeName->setReadOnly(true);
|
|
_curMode = 0;
|
|
_curType = nType;
|
|
}
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::showDlg(DiagramEditorRouteInfo info)
|
|
{
|
|
if(_pParent){
|
|
_selectedModel->clear();
|
|
_selectedModel->setHorizontalHeaderLabels({"分类", "名称", "类型", "关联对象", "引用线路"});
|
|
ui->le_routeName->setText(info.sRouteName);
|
|
for(auto& component:info.lstCompo){
|
|
|
|
QStandardItem *itemCate = new QStandardItem();
|
|
QStandardItem *itemName = new QStandardItem();
|
|
QStandardItem *itemType = new QStandardItem();
|
|
QStandardItem *itemObj = new QStandardItem();
|
|
QStandardItem *itemRoute = new QStandardItem();
|
|
|
|
QString sCate;
|
|
QString sType;
|
|
if(component.nCategory == 0){
|
|
sCate = "电气设备";
|
|
sType = BaseTypeManager::getInstance()->getNameById(component.nType);
|
|
}
|
|
else if(component.nCategory == 1){
|
|
sCate = "连接关系";
|
|
if(component.nType == 0){ //连接点暂时写死
|
|
sType = "连接点";
|
|
}
|
|
}
|
|
itemCate->setText(sCate);
|
|
itemName->setText(component.sName);
|
|
itemType->setText(sType);
|
|
itemObj->setText(component.sBindObj);
|
|
itemObj->setData(component.nBindType);
|
|
itemRoute->setText(component.sUsedRoute.join(","));
|
|
|
|
QList<QStandardItem*> lstItems;
|
|
lstItems<<itemCate<<itemName<<itemType<<itemObj<<itemRoute;
|
|
_selectedModel->appendRow(lstItems);
|
|
}
|
|
updateBindLst();
|
|
show();
|
|
ui->label->setText("编辑线路");
|
|
ui->le_routeName->setReadOnly(false);
|
|
_curMode = 1;
|
|
}
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::setComboByData(QComboBox *combo, int data)
|
|
{
|
|
for (int i = 0; i < combo->count(); ++i)
|
|
{
|
|
if (combo->itemData(i).toInt() == data)
|
|
{
|
|
combo->setCurrentIndex(i);
|
|
return;
|
|
}
|
|
}
|
|
combo->setCurrentIndex(-1);
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::setBindObjCombo(QComboBox *combo,
|
|
int bindType,
|
|
const QString &bindParent)
|
|
{
|
|
for (int i = 0; i < combo->count(); ++i)
|
|
{
|
|
if (combo->itemData(i, Qt::UserRole + 1).toInt() == bindType &&
|
|
combo->itemData(i, Qt::UserRole + 3).toString() == bindParent)
|
|
{
|
|
combo->setCurrentIndex(i);
|
|
return;
|
|
}
|
|
}
|
|
combo->setCurrentIndex(-1);
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::syncSelectedModel(
|
|
const QString &deviceName)
|
|
{
|
|
if (!_pParent || !_selectedModel)
|
|
return;
|
|
|
|
auto pMainModel = _pParent->getComponentModel();
|
|
|
|
int mainRow = -1;
|
|
for (int i = 0; i < pMainModel->rowCount(); ++i)
|
|
{
|
|
if (pMainModel->item(i, Col_Name)->text() == deviceName)
|
|
{
|
|
mainRow = i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (mainRow < 0)
|
|
return;
|
|
|
|
for (int i = 0; i < _selectedModel->rowCount(); ++i)
|
|
{
|
|
if (_selectedModel->item(i, Col_Name)->text() != deviceName)
|
|
continue;
|
|
|
|
_selectedModel->item(i, Col_Category)
|
|
->setText(pMainModel->item(mainRow, Col_Category)->text());
|
|
|
|
_selectedModel->item(i, Col_Type)
|
|
->setText(pMainModel->item(mainRow, Col_Type)->text());
|
|
|
|
QStandardItem *mainObj = pMainModel->item(mainRow, Col_BindObj);
|
|
QStandardItem *selObj = _selectedModel->item(i, Col_BindObj);
|
|
|
|
selObj->setText(mainObj->text());
|
|
selObj->setData(mainObj->data(Qt::UserRole + 1), Qt::UserRole + 1);
|
|
selObj->setData(mainObj->data(Qt::UserRole + 3), Qt::UserRole + 3);
|
|
}
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::loadFromModelRow(int row)
|
|
{
|
|
auto pModel = _pParent->getComponentModel();
|
|
if (!pModel) return;
|
|
|
|
ui->le_name->setText(pModel->item(row, Col_Name)->text());
|
|
|
|
setComboByData(ui->cb_category,
|
|
pModel->item(row, Col_Category)->data().toInt());
|
|
|
|
setComboByData(ui->cb_type,
|
|
pModel->item(row, Col_Type)->data().toInt());
|
|
|
|
QStandardItem *objItem = pModel->item(row, Col_BindObj);
|
|
setBindObjCombo(ui->cb_bindObj,
|
|
objItem->data(Qt::UserRole + 1).toInt(),
|
|
objItem->data(Qt::UserRole + 3).toString());
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::updateBindLst()
|
|
{
|
|
_bindItemModel->clear();
|
|
QStandardItem* it = new QStandardItem("无");
|
|
_bindItemModel->appendRow(it);
|
|
DiagramEditorTransformerBlock* pBlock = _pParent->getCurBlock();
|
|
if(pBlock){
|
|
TransformerType typ = pBlock->getTransType();
|
|
if(typ == TransformerType::twoWinding){
|
|
QStandardItem* itemH = new QStandardItem("高压绕组中性点");
|
|
QStandardItem* itemL = new QStandardItem("低压绕组中性点");
|
|
|
|
itemH->setData(3, Qt::UserRole+1);
|
|
itemH->setData(0, Qt::UserRole+2);
|
|
itemH->setData(pBlock->getName(), Qt::UserRole+3);
|
|
_bindItemModel->appendRow(itemH);
|
|
|
|
itemL->setData(3, Qt::UserRole+1);
|
|
itemL->setData(2, Qt::UserRole+2);
|
|
itemL->setData(pBlock->getName(), Qt::UserRole+3);
|
|
_bindItemModel->appendRow(itemL);
|
|
}
|
|
else{ //三绕组
|
|
QStandardItem* itemH = new QStandardItem("高压绕组中性点");
|
|
QStandardItem* itemM = new QStandardItem("中压绕组中性点");
|
|
QStandardItem* itemL = new QStandardItem("低压绕组中性点");
|
|
|
|
itemH->setData(3, Qt::UserRole+1);
|
|
itemH->setData(0, Qt::UserRole+2);
|
|
itemH->setData(pBlock->getName(), Qt::UserRole+3);
|
|
_bindItemModel->appendRow(itemH);
|
|
|
|
itemM->setData(3, Qt::UserRole+1);
|
|
itemM->setData(1, Qt::UserRole+2);
|
|
itemM->setData(pBlock->getName(), Qt::UserRole+3);
|
|
_bindItemModel->appendRow(itemM);
|
|
|
|
itemL->setData(3, Qt::UserRole+1);
|
|
itemL->setData(2, Qt::UserRole+2);
|
|
itemL->setData(pBlock->getName(), Qt::UserRole+3);
|
|
_bindItemModel->appendRow(itemL);
|
|
}
|
|
|
|
QList<QUuid> lstCon = pBlock->getConnect();
|
|
DiagramEditorWizard* pWizard = _pParent->getWizard();
|
|
if(pWizard){
|
|
QMap<QUuid,DiagramEditorBriefConnect> mapCon = pWizard->getConnection();
|
|
for(auto& uid:lstCon){
|
|
if(mapCon.contains(uid)){
|
|
auto con = mapCon.value(uid);
|
|
DiagramEditorConnectType conOp = con.getOpposite(pBlock->getName());
|
|
if(conOp.nType == 3){ //变压器,选择对应进/出线口
|
|
QStandardItem* item = nullptr;
|
|
|
|
if(con.nPara == 0){
|
|
item = new QStandardItem("高压绕组中性点");
|
|
}
|
|
else if(con.nPara == 1){
|
|
item = new QStandardItem("中压绕组中性点");
|
|
}
|
|
else if(con.nPara == 2){
|
|
item = new QStandardItem("低压绕组中性点");
|
|
}
|
|
if(item){
|
|
item->setData(conOp.nType, Qt::UserRole+1);
|
|
item->setData(con.nPara, Qt::UserRole+2);
|
|
item->setData(conOp.sName, Qt::UserRole+3);
|
|
_bindItemModel->appendRow(item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ui->cb_bindObj->setCurrentIndex(0);
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::onAddClicked()
|
|
{
|
|
if (!_pParent || !_selectedModel)
|
|
return;
|
|
|
|
auto pMainModel = _pParent->getComponentModel();
|
|
if (!pMainModel)
|
|
return;
|
|
|
|
// ===== 1. 获取选中行 =====
|
|
QModelIndexList indexes =
|
|
ui->tableView_items->selectionModel()->selectedRows();
|
|
|
|
if (indexes.isEmpty())
|
|
return;
|
|
|
|
QSet<int> rows;
|
|
for (const QModelIndex &idx : indexes)
|
|
rows.insert(idx.row());
|
|
|
|
const QString curRoute = ui->le_routeName->text();
|
|
|
|
// ===== 2. 逐行处理 =====
|
|
for (int row : rows)
|
|
{
|
|
QStandardItem *mainNameItem = pMainModel->item(row, Col_Name);
|
|
if (!mainNameItem)
|
|
continue;
|
|
|
|
const QString deviceName = mainNameItem->text();
|
|
|
|
// ===== 3. 去重校验 =====
|
|
for (int i = 0; i < _selectedModel->rowCount(); ++i)
|
|
{
|
|
if (_selectedModel->item(i, Col_Name)->text() == deviceName)
|
|
{
|
|
QMessageBox::information(
|
|
this,
|
|
QString("提示"),
|
|
QString::fromWCharArray(L"线路中设备已存在")
|
|
);
|
|
return;
|
|
}
|
|
}
|
|
|
|
// ===== 4. 深拷贝主表行 =====
|
|
QList<QStandardItem*> newRow;
|
|
newRow.reserve(Col_Count);
|
|
|
|
for (int col = 0; col < Col_Count; ++col)
|
|
{
|
|
QStandardItem *srcItem = pMainModel->item(row, col);
|
|
if (!srcItem)
|
|
{
|
|
newRow.append(new QStandardItem());
|
|
continue;
|
|
}
|
|
|
|
QStandardItem *newItem = srcItem->clone();
|
|
|
|
// ===== 5. Route 字段特殊处理 =====
|
|
if (col == Col_Route)
|
|
{
|
|
QString routeText = newItem->text();
|
|
|
|
if (!routeText.contains(curRoute))
|
|
{
|
|
if (routeText.isEmpty())
|
|
newItem->setText(curRoute);
|
|
else
|
|
newItem->setText(routeText + "," + curRoute);
|
|
}
|
|
}
|
|
|
|
newRow.append(newItem);
|
|
}
|
|
|
|
_selectedModel->appendRow(newRow);
|
|
}
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::onDeleteClicked()
|
|
{
|
|
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::onSaveClicked()
|
|
{
|
|
// ===== 1. 读取 UI 数据 =====
|
|
const QString sCategory = ui->cb_category->currentText();
|
|
const int nCate = ui->cb_category->currentData().toInt();
|
|
|
|
const QString sName = ui->le_name->text();
|
|
if (sName.isEmpty())
|
|
return;
|
|
|
|
const QString sType = ui->cb_type->currentText();
|
|
const int nType = ui->cb_type->currentData().toInt();
|
|
|
|
const QString sBindObj = ui->cb_bindObj->currentText();
|
|
const int nBindType = ui->cb_bindObj->currentData(Qt::UserRole + 1).toInt();
|
|
const QString sBindParent = ui->cb_bindObj->currentData(Qt::UserRole + 3).toString();
|
|
|
|
if (!_pParent)
|
|
return;
|
|
|
|
auto pModel = _pParent->getComponentModel();
|
|
if (!pModel)
|
|
return;
|
|
|
|
// ===== 2. 查找同名设备 =====
|
|
for (int row = 0; row < pModel->rowCount(); ++row)
|
|
{
|
|
QStandardItem *nameItem = pModel->item(row, Col_Name);
|
|
if (!nameItem)
|
|
continue;
|
|
|
|
if (nameItem->text() != sName)
|
|
continue;
|
|
|
|
// ===== 3. 重名确认 =====
|
|
QMessageBox msgBox;
|
|
msgBox.setText(QString::fromWCharArray(L"提示"));
|
|
msgBox.setInformativeText(QString::fromWCharArray(L"设备名已存在,是否覆盖?"));
|
|
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
if (msgBox.exec() != QMessageBox::Ok)
|
|
return;
|
|
|
|
// ===== 4. 覆盖已有行(完整更新)=====
|
|
pModel->item(row, Col_Category)->setText(sCategory);
|
|
pModel->item(row, Col_Category)->setData(nCate);
|
|
|
|
nameItem->setData(0); // 初始化方向占用
|
|
|
|
QStandardItem *typeItem = pModel->item(row, Col_Type);
|
|
typeItem->setText(sType);
|
|
typeItem->setData(nType);
|
|
|
|
QStandardItem *objItem = pModel->item(row, Col_BindObj);
|
|
objItem->setText(sBindObj);
|
|
objItem->setData(nBindType, Qt::UserRole + 1);
|
|
objItem->setData(sBindParent, Qt::UserRole + 3);
|
|
|
|
syncSelectedModel(sName);
|
|
return;
|
|
}
|
|
|
|
// ===== 5. 新增行 =====
|
|
QList<QStandardItem*> rowItems;
|
|
rowItems.resize(Col_Count);
|
|
|
|
rowItems[Col_Category] = new QStandardItem(sCategory);
|
|
rowItems[Col_Category]->setData(nCate);
|
|
|
|
rowItems[Col_Name] = new QStandardItem(sName);
|
|
rowItems[Col_Name]->setData(0); // 方向占用
|
|
rowItems[Col_Name]->setData(QUuid::createUuid(), Qt::UserRole + 3);
|
|
|
|
rowItems[Col_Type] = new QStandardItem(sType);
|
|
rowItems[Col_Type]->setData(nType);
|
|
|
|
rowItems[Col_BindObj] = new QStandardItem(sBindObj);
|
|
rowItems[Col_BindObj]->setData(nBindType, Qt::UserRole + 1);
|
|
rowItems[Col_BindObj]->setData(sBindParent, Qt::UserRole + 3);
|
|
|
|
rowItems[Col_Route] = new QStandardItem();
|
|
|
|
pModel->appendRow(rowItems);
|
|
|
|
const int newRow = pModel->rowCount() - 1;
|
|
QModelIndex index = pModel->index(newRow, 0);
|
|
|
|
// 设置当前选中项(焦点)
|
|
ui->tableView_items->setCurrentIndex(index);
|
|
|
|
// 滚动到该行
|
|
ui->tableView_items->scrollTo(index, QAbstractItemView::PositionAtCenter);
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::onOkClicked()
|
|
{
|
|
QString sRoute = ui->le_routeName->text();
|
|
auto& mapRoute = _pParent->getTransInfo().mapNeutral[_curType].mapRoute;
|
|
QStringList lstName; //线路的设备列表
|
|
DiagramEditorRouteInfo routeInfo;
|
|
routeInfo.sRouteName = sRoute;
|
|
|
|
int rowCount = _selectedModel->rowCount();
|
|
for(int i = 0;i < rowCount;++i){
|
|
DiagramEditorComponentInfo compoInfo;
|
|
QStandardItem *itemCategory = _selectedModel->item(i, 0);
|
|
QStandardItem *itemName = _selectedModel->item(i, 1);
|
|
QStandardItem *itemType = _selectedModel->item(i, 2);
|
|
QStandardItem *itemBind = _selectedModel->item(i, 3);
|
|
QStandardItem *itemAllRoute = _selectedModel->item(i, 4);
|
|
|
|
QString sCate = itemCategory->text();
|
|
QString sName = itemName->text();
|
|
QString sType = itemType->text();
|
|
QString sBind = itemBind->text();
|
|
int nBindType = itemBind->data().toInt();
|
|
QString sBindParent = itemBind->data(Qt::UserRole+3).toString();
|
|
QString sAllRoute = itemAllRoute->text();
|
|
|
|
int nCate = 0;
|
|
if(sCate == "电气设备")
|
|
nCate = 0;
|
|
else if(sCate == "连接关系")
|
|
nCate = 1;
|
|
|
|
int nType = 0;
|
|
nType = itemType->data().toInt();
|
|
|
|
compoInfo.nCategory = nCate;
|
|
compoInfo.sName = sName;
|
|
compoInfo.nType = nType;
|
|
compoInfo.sBindObj = sBind;
|
|
compoInfo.nBindType = nBindType;
|
|
compoInfo.sBindParent = sBindParent;
|
|
compoInfo.sUsedRoute = sAllRoute.split(",");
|
|
|
|
routeInfo.lstCompo.append(compoInfo);
|
|
lstName.append(sName);
|
|
}
|
|
|
|
QString strCompoNames = lstName.join(",");
|
|
|
|
if(_curMode == 0){
|
|
if(mapRoute.contains(sRoute)){
|
|
QMessageBox::information(NULL, QString("提示"), QString::fromWCharArray(L"线路名重复"));
|
|
return;
|
|
}
|
|
|
|
mapRoute.insert(sRoute,routeInfo); //插入线路到parent存储中
|
|
|
|
QStandardItem *itemRoute = new QStandardItem();
|
|
QStandardItem *itemNames = new QStandardItem();
|
|
itemRoute->setText(sRoute);
|
|
itemNames->setText(strCompoNames);
|
|
|
|
QList<QStandardItem*> lstItems;
|
|
lstItems<<itemRoute<<itemNames;
|
|
|
|
auto pRoute = _pParent->getRouteModels().value(_curType);
|
|
pRoute->appendRow(lstItems);
|
|
}
|
|
else if(_curMode == 1){
|
|
mapRoute[sRoute] = routeInfo;
|
|
auto pRoute = _pParent->getRouteModels().value(_curType);
|
|
int nCount = pRoute->rowCount();
|
|
for(int i = 0;i < rowCount;++i){
|
|
QStandardItem *itemName = pRoute->item(i, 0);
|
|
if(itemName->text() == sRoute){
|
|
QStandardItem *itemRoutes = pRoute->item(i, 1);
|
|
itemRoutes->setText(strCompoNames);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if(_pParent){
|
|
_pParent->showPreview();
|
|
}
|
|
hide();
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::onCancelClicked()
|
|
{
|
|
hide();
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::onCategoryChanged(const QString& str)
|
|
{
|
|
ui->cb_type->clear();
|
|
if(str == "电气设备"){
|
|
QMap<int,modelType> mapType = BaseTypeManager::getInstance()->getMapType(); //直接添加数据库中的基础类型
|
|
for(auto iter = mapType.begin();iter != mapType.end();++iter){
|
|
int index = ui->cb_type->count();
|
|
ui->cb_type->addItem(iter.value().modelName);
|
|
ui->cb_type->setItemData(index,iter->id,Qt::UserRole); //存放基模id
|
|
ui->cb_type->setItemData(index,iter->graphicElement,Qt::UserRole+1); //存放基础类型
|
|
}
|
|
}
|
|
else if(str == "连接关系"){
|
|
ui->cb_type->addItem("连接点",1);
|
|
}
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::onComponentDeleteClicked()
|
|
{
|
|
// 获取当前选中的索引
|
|
QModelIndexList selectedIndexes = ui->tableView_items->selectionModel()->selectedRows();
|
|
if (selectedIndexes.isEmpty()) {
|
|
return; // 没有选中任何行
|
|
}
|
|
|
|
// 获取行号并排序(从大到小删除避免索引变化)
|
|
QList<int> rowsToRemove;
|
|
foreach (const QModelIndex &index, selectedIndexes) {
|
|
rowsToRemove.append(index.row());
|
|
}
|
|
|
|
// 获取当前选中的第一项索引
|
|
QModelIndex index = selectedIndexes.first();
|
|
if (!index.isValid()) {
|
|
return;
|
|
}
|
|
|
|
QModelIndex indexName = index.sibling(index.row(),1);
|
|
QString sName = indexName.data().toString();
|
|
|
|
bool bUsed = false;
|
|
auto& mapRoute = _pParent->getTransInfo().mapNeutral[_curType].mapRoute; //检索所有路线,判断设备占用情况
|
|
for(auto& route:mapRoute){
|
|
QString sRoute = route.sRouteName;
|
|
for(auto& compo:route.lstCompo){
|
|
if(compo.sName == sName){
|
|
bUsed = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
auto pCompoModel = _pParent->getComponentModel();
|
|
if(bUsed){
|
|
QMessageBox msgBox;
|
|
msgBox.setText(QString::fromWCharArray(L"提示"));
|
|
msgBox.setInformativeText(QString::fromWCharArray(L"设备已被使用,是否保存?"));
|
|
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
|
int ret = msgBox.exec();
|
|
|
|
switch (ret) {
|
|
case QMessageBox::Ok: //同步删除所有占用对象
|
|
{
|
|
for(auto& route:mapRoute){
|
|
QString sRoute = route.sRouteName;
|
|
for(int i = 0;i < route.lstCompo.size();++i){
|
|
QString sCompo = route.lstCompo[i].sName;
|
|
if(sCompo == sName){
|
|
route.lstCompo.removeAt(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
//todo:刷新主界面
|
|
|
|
foreach (int row, rowsToRemove) {
|
|
QList<QStandardItem*> rowItems;
|
|
for (int col = 0; col < pCompoModel->columnCount(); ++col) {
|
|
QStandardItem *item = pCompoModel->takeItem(row, col);
|
|
rowItems.append(item);
|
|
}
|
|
qDeleteAll(rowItems); //take的item不释放
|
|
pCompoModel->removeRow(row);
|
|
}
|
|
}
|
|
break;
|
|
case QMessageBox::Cancel:
|
|
// Cancel was clicked
|
|
break;
|
|
default:
|
|
// should never be reached
|
|
break;
|
|
}
|
|
}
|
|
else{
|
|
// 移除行
|
|
foreach (int row, rowsToRemove) {
|
|
QList<QStandardItem*> rowItems;
|
|
for (int col = 0; col < pCompoModel->columnCount(); ++col) {
|
|
QStandardItem *item = pCompoModel->takeItem(row, col);
|
|
rowItems.append(item);
|
|
}
|
|
qDeleteAll(rowItems); //take的item不释放
|
|
pCompoModel->removeRow(row);
|
|
}
|
|
}
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::onComponentRbtnClicked(const QPoint &pos)
|
|
{
|
|
QModelIndex index = ui->tableView_items->indexAt(pos);
|
|
if (!index.isValid()) {
|
|
return; // 如果点击的是空白区域,直接返回
|
|
}
|
|
|
|
QMenu menu;
|
|
QAction *deleteAction = new QAction("删除", this);
|
|
menu.addAction(deleteAction);
|
|
|
|
// 连接删除菜单项的触发信号与槽函数
|
|
connect(deleteAction, &QAction::triggered, this, &DiagramEditorTransDetailAddDlg::onComponentDeleteClicked);
|
|
|
|
// 在点击位置显示菜单
|
|
menu.exec(ui->tableView_items->mapToGlobal(pos));
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::onRouteDeleteClicked()
|
|
{
|
|
// 获取当前选中的索引
|
|
QModelIndexList selectedIndexes = ui->tableView_selected->selectionModel()->selectedRows();
|
|
if (selectedIndexes.isEmpty()) {
|
|
return; // 没有选中任何行
|
|
}
|
|
|
|
// 获取行号并排序(从大到小删除避免索引变化)
|
|
QList<int> rowsToRemove;
|
|
foreach (const QModelIndex &index, selectedIndexes) {
|
|
rowsToRemove.append(index.row());
|
|
}
|
|
|
|
// 获取当前选中的第一项索引
|
|
QModelIndex index = selectedIndexes.first();
|
|
if (!index.isValid()) {
|
|
return;
|
|
}
|
|
|
|
QModelIndex indexName = index.sibling(index.row(),1);
|
|
QString sName = indexName.data().toString();
|
|
|
|
// 移除行
|
|
foreach (int row, rowsToRemove) {
|
|
QList<QStandardItem*> rowItems;
|
|
for (int col = 0; col < _selectedModel->columnCount(); ++col) {
|
|
QStandardItem *item = _selectedModel->takeItem(row, col);
|
|
rowItems.append(item);
|
|
}
|
|
qDeleteAll(rowItems); //take的item不释放
|
|
_selectedModel->removeRow(row);
|
|
}
|
|
|
|
QString sRoute = ui->le_routeName->text();
|
|
auto pCompoModel = _pParent->getComponentModel();
|
|
int rowCount = pCompoModel->rowCount(); //移除设备库占用记录
|
|
for(int i = 0;i < rowCount;++i){
|
|
QStandardItem *itemName = pCompoModel->item(i, 1);
|
|
if(itemName->text() == sName){
|
|
QStandardItem *itemUsed = pCompoModel->item(i, 4);
|
|
QString sUsed = itemUsed->text();
|
|
QStringList lst = sUsed.split(",");
|
|
lst.removeAll(sRoute);
|
|
itemUsed->setText(lst.join(","));
|
|
}
|
|
}
|
|
}
|
|
|
|
void DiagramEditorTransDetailAddDlg::onRouteRbtnClicked(const QPoint &pos)
|
|
{
|
|
QModelIndex index = ui->tableView_selected->indexAt(pos);
|
|
if (!index.isValid()) {
|
|
return; // 如果点击的是空白区域,直接返回
|
|
}
|
|
|
|
QMenu menu;
|
|
QAction *deleteAction = new QAction("移除", this);
|
|
menu.addAction(deleteAction);
|
|
|
|
// 连接删除菜单项的触发信号与槽函数
|
|
connect(deleteAction, &QAction::triggered, this, &DiagramEditorTransDetailAddDlg::onRouteDeleteClicked);
|
|
|
|
// 在点击位置显示菜单
|
|
menu.exec(ui->tableView_selected->mapToGlobal(pos));
|
|
}
|