#include "connection.h" #include Connection::Connection(Item* from, Item::AnchorType fromType, Item* to, Item::AnchorType toType, QGraphicsItem* parent) : QGraphicsLineItem(parent), from_(from), to_(to), fromType_(fromType), toType_(toType) { setZValue(-1); // 在图元之下 setPen(QPen(Qt::black, 2)); from_->addConnection(this); to_->addConnection(this); updatePosition(); } void Connection::updatePosition() { setLine(QLineF(from_->anchorPos(fromType_), to_->anchorPos(toType_))); }