2025-07-31 19:38:06 +08:00
|
|
|
#include <QPainter>
|
|
|
|
|
#include "diagramEditor/editItems.h"
|
2025-08-15 18:21:20 +08:00
|
|
|
#include "diagramEditor/diagramEditorBaseBlock.h"
|
2025-07-31 19:38:06 +08:00
|
|
|
|
|
|
|
|
EditBaseItem::EditBaseItem(QGraphicsItem *parent)
|
2025-08-06 20:10:10 +08:00
|
|
|
: QGraphicsWidget(parent)
|
|
|
|
|
,_pBlock(nullptr)
|
2025-07-31 19:38:06 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
EditBaseItem::~EditBaseItem()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-26 18:50:21 +08:00
|
|
|
QString EditBaseItem::getEditState()
|
|
|
|
|
{
|
|
|
|
|
QString str;
|
|
|
|
|
if(_pBlock){
|
|
|
|
|
bool state = _pBlock->getEditState();
|
|
|
|
|
if(state)
|
|
|
|
|
str = "已编辑";
|
|
|
|
|
else
|
|
|
|
|
str = "未编辑";
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 19:38:06 +08:00
|
|
|
QPainterPath EditBaseItem::shape()
|
|
|
|
|
{
|
|
|
|
|
QPainterPath path;
|
|
|
|
|
path.addRect(m_boundingRect);
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-15 18:21:20 +08:00
|
|
|
void EditBaseItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "Element double-clicked!";
|
|
|
|
|
emit itemDbClicked(_pBlock);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 19:38:06 +08:00
|
|
|
/********************bus*********************/
|
|
|
|
|
EditBusItem::EditBusItem(QGraphicsItem *parent)
|
|
|
|
|
: EditBaseItem(parent)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
EditBusItem::~EditBusItem()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-08 17:47:31 +08:00
|
|
|
void EditBusItem::setGeometry(const QRectF &rect)
|
|
|
|
|
{
|
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
|
|
QGraphicsWidget::setGeometry(rect);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 19:38:06 +08:00
|
|
|
void EditBusItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
|
|
|
|
{
|
|
|
|
|
painter->fillRect(m_boundingRect,Qt::black);
|
2025-08-06 20:10:10 +08:00
|
|
|
painter->drawText(QPointF(-10,0),sName);
|
2025-07-31 19:38:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************Bay*********************/
|
|
|
|
|
|
|
|
|
|
EditBayItem::EditBayItem(QGraphicsItem *parent)
|
|
|
|
|
: EditBaseItem(parent)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
EditBayItem::~EditBayItem()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-26 18:50:21 +08:00
|
|
|
QString EditBayItem::getShowType()
|
|
|
|
|
{
|
|
|
|
|
QString str;
|
|
|
|
|
if(_pBlock){
|
|
|
|
|
auto pBay = dynamic_cast<DiagramEditorBayBlock*>(_pBlock.data());
|
|
|
|
|
if(pBay){
|
|
|
|
|
BayType tpe = pBay->getBayType();
|
|
|
|
|
switch (tpe) {
|
|
|
|
|
case BayType::busSectionBay:
|
|
|
|
|
str = "分段间隔";
|
|
|
|
|
break;
|
|
|
|
|
case BayType::busCouplerBay:
|
|
|
|
|
str = "母联间隔";
|
|
|
|
|
break;
|
|
|
|
|
case BayType::ptBay:
|
|
|
|
|
str = "PT间隔";
|
|
|
|
|
break;
|
|
|
|
|
case BayType::incomingBay:
|
|
|
|
|
str = "进线间隔";
|
|
|
|
|
break;
|
|
|
|
|
case BayType::outcomingBay:
|
|
|
|
|
str = "出线间隔";
|
|
|
|
|
break;
|
|
|
|
|
case BayType::compensationBay:
|
|
|
|
|
str = "无功补偿间隔";
|
|
|
|
|
break;
|
|
|
|
|
case BayType::bypassBay:
|
|
|
|
|
str = "旁路间隔";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 19:38:06 +08:00
|
|
|
void EditBayItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
|
|
|
|
{
|
2025-09-26 18:50:21 +08:00
|
|
|
Q_UNUSED(option);
|
|
|
|
|
Q_UNUSED(widget);
|
|
|
|
|
|
2025-08-06 20:10:10 +08:00
|
|
|
painter->setPen(QColor(220,220,230));
|
2025-07-31 19:38:06 +08:00
|
|
|
painter->drawRect(m_boundingRect);
|
2025-08-06 20:10:10 +08:00
|
|
|
painter->drawText(QPointF(-10,0),sName);
|
2025-09-26 18:50:21 +08:00
|
|
|
|
|
|
|
|
painter->setFont(QFont("Arial", 12));
|
|
|
|
|
painter->setPen(Qt::cyan);
|
|
|
|
|
|
|
|
|
|
QString str1 = "类型:"+getShowType();
|
|
|
|
|
QString str2 = "状态:"+getEditState();
|
|
|
|
|
QString text = str1+"\n"+str2;
|
|
|
|
|
|
|
|
|
|
QTextOption op;
|
|
|
|
|
op.setAlignment(Qt::AlignCenter);
|
|
|
|
|
painter->drawText(boundingRect(), text, op);
|
2025-07-31 19:38:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************trans*********************/
|
|
|
|
|
|
|
|
|
|
EditTransItem::EditTransItem(QGraphicsItem *parent)
|
|
|
|
|
: EditBaseItem(parent)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
EditTransItem::~EditTransItem()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-26 18:50:21 +08:00
|
|
|
QString EditTransItem::getShowType()
|
|
|
|
|
{
|
|
|
|
|
QString str;
|
|
|
|
|
if(_pBlock){
|
|
|
|
|
auto pTrans = dynamic_cast<DiagramEditorTransformerBlock*>(_pBlock.data());
|
|
|
|
|
if(pTrans){
|
|
|
|
|
TransformerType tpe = pTrans->getTransType();
|
|
|
|
|
switch (tpe) {
|
|
|
|
|
case TransformerType::twoWinding:
|
|
|
|
|
str = "两绕组变压器";
|
|
|
|
|
break;
|
|
|
|
|
case TransformerType::threeWinding:
|
|
|
|
|
str = "三绕组变压器";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 19:38:06 +08:00
|
|
|
void EditTransItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
|
|
|
|
{
|
2025-09-26 18:50:21 +08:00
|
|
|
Q_UNUSED(option);
|
|
|
|
|
Q_UNUSED(widget);
|
|
|
|
|
|
2025-08-06 20:10:10 +08:00
|
|
|
painter->setPen(QColor(180,235,155));
|
|
|
|
|
painter->drawRect(m_boundingRect);
|
|
|
|
|
painter->drawText(QPointF(-10,0),sName);
|
2025-09-26 18:50:21 +08:00
|
|
|
|
|
|
|
|
painter->setFont(QFont("Arial", 12));
|
|
|
|
|
painter->setPen(Qt::cyan);
|
|
|
|
|
|
|
|
|
|
QString str1 = "类型:"+getShowType();
|
|
|
|
|
QString str2 = "状态:"+getEditState();
|
|
|
|
|
QString text = str1+"\n"+str2;
|
|
|
|
|
|
|
|
|
|
QTextOption op;
|
|
|
|
|
op.setAlignment(Qt::AlignCenter);
|
|
|
|
|
painter->drawText(boundingRect(), text, op);
|
2025-07-31 19:38:06 +08:00
|
|
|
}
|
2025-08-08 17:47:31 +08:00
|
|
|
|
|
|
|
|
/********************连线*********************/
|
|
|
|
|
|
|
|
|
|
EditLineItem::EditLineItem(QGraphicsItem *parent)
|
|
|
|
|
: EditBaseItem(parent)
|
|
|
|
|
{
|
|
|
|
|
m_boundingRect = QRectF();
|
|
|
|
|
m_lstPoints.push_back(QPointF()); //起点
|
|
|
|
|
m_lstPoints.push_back(QPointF()); //终点
|
|
|
|
|
_curLine = QPoint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EditLineItem::~EditLineItem()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditLineItem::setStartPoint(const QPointF& p)
|
|
|
|
|
{
|
|
|
|
|
int n = m_lstPoints.size();
|
|
|
|
|
if(n)
|
|
|
|
|
{
|
|
|
|
|
if(n >2)
|
|
|
|
|
{
|
|
|
|
|
if(m_lstPoints[0].x() == m_lstPoints[1].x()) //相邻点在垂直方向,水平移动,否则垂直移动
|
|
|
|
|
{
|
|
|
|
|
m_lstPoints[1].setX(p.x());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_lstPoints[1].setY(p.y());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_lstPoints[0] = p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void EditLineItem::setEndPoint(const QPointF& p)
|
|
|
|
|
{
|
|
|
|
|
int n = m_lstPoints.size();
|
|
|
|
|
if(n)
|
|
|
|
|
{
|
|
|
|
|
if(n >2)
|
|
|
|
|
{
|
|
|
|
|
if(m_lstPoints[n-1].x() == m_lstPoints[n-2].x()) //相邻点在垂直方向,水平移动,否则垂直移动
|
|
|
|
|
{
|
|
|
|
|
m_lstPoints[n-2].setX(p.x());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_lstPoints[n-2].setY(p.y());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_lstPoints[n-1] = p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPainterPath EditLineItem::shape() const
|
|
|
|
|
{
|
|
|
|
|
QPainterPath path;
|
|
|
|
|
path.addPath(m_pointsBoundingRect);
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditLineItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
|
|
|
|
{
|
|
|
|
|
painter->setPen(Qt::black);
|
|
|
|
|
|
|
|
|
|
painter->drawPath(m_points);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditLineItem::calculatePath(int nSeg)
|
|
|
|
|
{
|
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
m_points.clear();
|
|
|
|
|
m_pointsBoundingRect.clear();
|
|
|
|
|
|
|
|
|
|
if(m_lstPoints.size() == 2 && (m_lstPoints.first().x() != m_lstPoints.last().x()) && (m_lstPoints.first().y() != m_lstPoints.last().y()))
|
|
|
|
|
{
|
|
|
|
|
if(nSeg == 2)
|
|
|
|
|
{
|
|
|
|
|
/*if(m_lstPoints.first().y() < m_lstPoints.last().y())
|
|
|
|
|
m_lstPoints.insert(1,QPointF(m_lstPoints.first().x(),m_lstPoints.last().y()));
|
|
|
|
|
else
|
|
|
|
|
m_lstPoints.insert(1,QPointF(m_lstPoints.last().x(),m_lstPoints.first().y()));*/
|
|
|
|
|
m_lstPoints.insert(1,QPointF(m_lstPoints.last().x(),m_lstPoints.first().y()));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const QPointF p1 = m_lstPoints.first();
|
|
|
|
|
const QPointF p2 = m_lstPoints.last();
|
|
|
|
|
|
|
|
|
|
const qreal dx = (p2.x() - p1.x()) / 3;
|
|
|
|
|
const qreal dy = (p2.y() - p1.y()) / 3;
|
|
|
|
|
m_lstPoints.insert(1, QPointF(p1.x(), p1.y() + dy));
|
|
|
|
|
m_lstPoints.insert(2, QPointF(p2.x(), p1.y() + dy));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_points.moveTo(m_lstPoints.first());
|
|
|
|
|
QPointF pLast = m_lstPoints.first();
|
|
|
|
|
for(int i = 1;i <m_lstPoints.size();++i)
|
|
|
|
|
{
|
|
|
|
|
m_points.lineTo(m_lstPoints[i]);
|
|
|
|
|
m_pointsBoundingRect.addRect(QRectF(QPointF(pLast.x()-1,pLast.y()-1),QPointF(m_lstPoints[i].x()+1,m_lstPoints[i].y()+1)));
|
|
|
|
|
pLast = m_lstPoints[i];
|
|
|
|
|
}
|
|
|
|
|
m_boundingRect = m_points.boundingRect();
|
|
|
|
|
}
|