DiagramDesigner/diagramCavas/source/diagramEditor/wizardBayContentDlg.cpp

194 lines
5.7 KiB
C++
Raw Normal View History

2025-07-25 19:07:14 +08:00
#include <QHeaderView>
2025-07-29 20:15:18 +08:00
#include <QMenu>
#include "diagramEditor/wizardBayContentDlg.h"
#include "diagramEditor/diagramEditorWizard.h"
#include "diagramEditor/diagramEditorBaseBlock.h"
#include "diagramEditor/diagramEditorStructContainer.h"
#include "diagramEditor/diagramEditorBaySettingDlg.h"
2025-07-25 19:07:14 +08:00
WizardBayContentDlg::WizardBayContentDlg(QWidget *parent)
: QTableWidget(parent)
2025-07-29 20:15:18 +08:00
,_pWizard(nullptr)
2025-07-25 19:07:14 +08:00
{
initial();
}
WizardBayContentDlg::~WizardBayContentDlg()
{
}
void WizardBayContentDlg::initial()
{
2025-07-29 20:15:18 +08:00
_curLevel = 0;
2025-07-25 19:07:14 +08:00
QStringList headerText;
headerText<<"间隔名称"<<"间隔类型"<<"连接对象";
setContextMenuPolicy(Qt::CustomContextMenu);
setSelectionMode(QAbstractItemView::SingleSelection);
setSelectionBehavior(QAbstractItemView::SelectRows);
setColumnCount(headerText.count());
setHorizontalHeaderLabels(headerText);
horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
2025-07-29 20:15:18 +08:00
verticalHeader()->setVisible(false);
connect(this, &QTableWidget::customContextMenuRequested, this, &WizardBayContentDlg::onIndexRbtnClicked);
2025-07-25 19:07:14 +08:00
}
void WizardBayContentDlg::addBay(DiagramEditorWizardBayInfo obj)
{
int row = rowCount();
insertRow(row);
//名称
QTableWidgetItem* nameItem = new QTableWidgetItem(obj.sName);
setItem(row, 0, nameItem);
QString sType;
switch (obj.nType) {//0分段间隔1母联间隔2pt间隔3进线间隔4出线间隔5无功补偿间隔6旁路间隔
case BayType::busSectionBay:
sType = "分段间隔";
break;
case BayType::busCouplerBay:
sType = "母联间隔";
break;
case BayType::ptBay:
sType = "pt间隔";
break;
case BayType::incomingBay:
sType = "进线间隔";
break;
case BayType::outcomingBay:
sType = "出线间隔";
break;
case BayType::compensationBay:
sType = "无功补偿间隔";
break;
case BayType::bypassBay:
sType = "旁路间隔";
break;
default:
break;
}
//类型
QTableWidgetItem* typeItem = new QTableWidgetItem(sType);
setItem(row, 1, typeItem);
// 主接线
QTableWidgetItem* connectItem = new QTableWidgetItem(obj.lstBindObj.join(""));
setItem(row, 2, connectItem);
}
void WizardBayContentDlg::clearData()
{
2025-07-29 20:15:18 +08:00
clearContents();
setRowCount(0);
}
void WizardBayContentDlg::flushData(int nLevel)
{
clearData();
if(_pWizard){
QList<DiagramEditorBaseBlock*> lst = _pWizard->getTargetLevelBlocks(nLevel,2);
for(auto& block:lst){
auto pItem = dynamic_cast<DiagramEditorBayBlock*>(block);
if(pItem){
DiagramEditorWizardBayInfo info;
info.sName = pItem->getName();
info.nType = pItem->getBayType();
auto lstCon = pItem->getConnect(); //获取间隔所连对象的名称
for(auto& conId:lstCon){
if(_pWizard->getConnection().contains(conId)){
auto con = _pWizard->getConnection().value(conId);
QString sOpposite = con.getOppositeName(pItem->getName());
info.lstBindObj.append(sOpposite);
}
}
2025-07-29 20:15:18 +08:00
addBay(info);
}
}
}
_curLevel = nLevel;
}
void WizardBayContentDlg::onDeleteClicked()
{
// 获取当前选中的索引
QModelIndexList selectedIndexes = this->selectionModel()->selectedRows();
if (selectedIndexes.isEmpty()) {
return; // 没有选中任何行
}
// 获取当前选中的第一项索引
QModelIndex index = selectedIndexes.first();
if (!index.isValid()) {
return;
}
QModelIndex indexName = index.sibling(index.row(),0);
QString sName = indexName.data().toString();
if(_pWizard){
bool res = _pWizard->removeBlockByName(_curLevel,2,sName);
if(res){
flushData(_curLevel);
}
else{
return;
}
}
int currentRow = this->currentRow();
if (currentRow == -1) {
return; // 没有选中行
}
this->removeRow(currentRow);
}
void WizardBayContentDlg::onModifyClicked()
{
// 获取当前选中的索引
QModelIndexList selectedIndexes = this->selectionModel()->selectedRows();
if (selectedIndexes.isEmpty()) {
return; // 没有选中任何行
}
// 获取当前选中的第一项索引
QModelIndex index = selectedIndexes.first();
if (!index.isValid()) {
return;
}
QModelIndex indexName = index.sibling(index.row(),0);
QString sName = indexName.data().toString();
if(_pWizard){
DiagramEditorBaseBlock* pBlock = _pWizard->getBlockByName(_curLevel,2,sName);
if(pBlock){
auto pBay = dynamic_cast<DiagramEditorBayBlock*>(pBlock);
if(pBay)
_pWizard->getBaySettingDlg()->showDlg(_curLevel,pBay);
}
}
}
void WizardBayContentDlg::onIndexRbtnClicked(const QPoint &pos)
{
// 获取当前点击的位置对应的索引
QModelIndex index = this->indexAt(pos);
if (!index.isValid()) {
return; // 如果点击的是空白区域,直接返回
}
QMenu menu;
QAction *deleteAction = new QAction("移除间隔", this);
QAction *modifyAction = new QAction("修改间隔", this);
menu.addAction(deleteAction);
menu.addAction(modifyAction);
// 连接删除菜单项的触发信号与槽函数
connect(deleteAction, &QAction::triggered, this, &WizardBayContentDlg::onDeleteClicked);
connect(modifyAction, &QAction::triggered, this, &WizardBayContentDlg::onModifyClicked);
// 在点击位置显示菜单
menu.exec(this->mapToGlobal(pos));
2025-07-25 19:07:14 +08:00
}