197 lines
5.7 KiB
C++
197 lines
5.7 KiB
C++
#include <QHeaderView>
|
||
#include <QMenu>
|
||
#include "diagramEditor/wizardBayContentDlg.h"
|
||
#include "diagramEditor/diagramEditorWizard.h"
|
||
#include "diagramEditor/diagramEditorBaseBlock.h"
|
||
#include "diagramEditor/diagramEditorStructContainer.h"
|
||
#include "diagramEditor/diagramEditorBaySettingDlg.h"
|
||
|
||
WizardBayContentDlg::WizardBayContentDlg(QWidget *parent)
|
||
: QTableWidget(parent)
|
||
,_pWizard(nullptr)
|
||
{
|
||
initial();
|
||
}
|
||
|
||
WizardBayContentDlg::~WizardBayContentDlg()
|
||
{
|
||
}
|
||
|
||
void WizardBayContentDlg::initial()
|
||
{
|
||
_curLevel = 0;
|
||
QStringList headerText;
|
||
headerText<<"间隔名称"<<"间隔类型"<<"连接对象";
|
||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||
setSelectionMode(QAbstractItemView::SingleSelection);
|
||
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||
setColumnCount(headerText.count());
|
||
setHorizontalHeaderLabels(headerText);
|
||
horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||
verticalHeader()->setVisible(false);
|
||
connect(this, &QTableWidget::customContextMenuRequested, this, &WizardBayContentDlg::onIndexRbtnClicked);
|
||
}
|
||
|
||
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()
|
||
{
|
||
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.getOpposite(pItem->getName()).sName;
|
||
info.lstBindObj.append(sOpposite);
|
||
}
|
||
}
|
||
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){
|
||
auto pDlg = _pWizard->getBaySettingDlg();
|
||
if(pDlg)
|
||
pDlg->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));
|
||
}
|