#include #include "diagramEditor/editItems.h" #include "diagramEditor/diagramEditorBaseBlock.h" EditBaseItem::EditBaseItem(QGraphicsItem *parent) : QGraphicsWidget(parent) ,_pBlock(nullptr) { } EditBaseItem::~EditBaseItem() { } QString EditBaseItem::getEditState() { QString str; if(_pBlock){ bool state = _pBlock->getEditState(); if(state) str = "已编辑"; else str = "未编辑"; } return str; } QPainterPath EditBaseItem::shape() { QPainterPath path; path.addRect(m_boundingRect); return path; } void EditBaseItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) { qDebug() << "Element double-clicked!"; emit itemDbClicked(_pBlock); } /********************bus*********************/ EditBusItem::EditBusItem(QGraphicsItem *parent) : EditBaseItem(parent) { } EditBusItem::~EditBusItem() { } void EditBusItem::setGeometry(const QRectF &rect) { prepareGeometryChange(); QGraphicsWidget::setGeometry(rect); } void EditBusItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { painter->fillRect(m_boundingRect,Qt::black); painter->drawText(QPointF(-10,0),sName); } /********************Bay*********************/ EditBayItem::EditBayItem(QGraphicsItem *parent) : EditBaseItem(parent) { } EditBayItem::~EditBayItem() { } QString EditBayItem::getShowType() { QString str; if(_pBlock){ auto pBay = dynamic_cast(_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; } void EditBayItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); painter->setPen(QColor(220,220,230)); painter->drawRect(m_boundingRect); painter->drawText(QPointF(-10,0),sName); 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); } /********************trans*********************/ EditTransItem::EditTransItem(QGraphicsItem *parent) : EditBaseItem(parent) { } EditTransItem::~EditTransItem() { } QString EditTransItem::getShowType() { QString str; if(_pBlock){ auto pTrans = dynamic_cast(_pBlock.data()); if(pTrans){ TransformerType tpe = pTrans->getTransType(); switch (tpe) { case TransformerType::twoWinding: str = "两绕组变压器"; break; case TransformerType::threeWinding: str = "三绕组变压器"; break; default: break; } } } return str; } void EditTransItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); painter->setPen(QColor(180,235,155)); painter->drawRect(m_boundingRect); painter->drawText(QPointF(-10,0),sName); 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); } /********************连线*********************/ 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