本文整理汇总了C++中GraphEdge::label方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphEdge::label方法的具体用法?C++ GraphEdge::label怎么用?C++ GraphEdge::label使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphEdge
的用法示例。
在下文中一共展示了GraphEdge::label方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateGeometry
//void GraphEdge::adjust()
void GraphEdge::updateGeometry()
{
if (!sourceNode_ || !destNode_) return;
//sourceNode_->adjustSize();
//destNode_->adjustSize();
// line from center of sourceNode_ to center of destNode_
QRectF sSBR (sourceNode_->sceneBoundingRect());
QRectF dSBR (destNode_->sceneBoundingRect());
QLineF centerline(sSBR.center(), dSBR.center());
// set the source and destination points
if(!sSBR.intersects(dSBR)) {
QPointF po;
if(QLineF::BoundedIntersection == centerline.intersect(QLineF(sSBR.topLeft(), sSBR.topRight()), &po)) sourcePoint = po;
else if(QLineF::BoundedIntersection == centerline.intersect(QLineF(sSBR.bottomRight(), sSBR.topRight()), &po)) sourcePoint = po;
else if(QLineF::BoundedIntersection == centerline.intersect(QLineF(sSBR.bottomLeft(), sSBR.bottomRight()), &po)) sourcePoint = po;
else if(QLineF::BoundedIntersection == centerline.intersect(QLineF(sSBR.topLeft(), sSBR.bottomLeft()), &po)) sourcePoint = po;
if(QLineF::BoundedIntersection == centerline.intersect(QLineF(dSBR.topLeft(), dSBR.topRight()), &po)) destPoint = po;
else if(QLineF::BoundedIntersection == centerline.intersect(QLineF(dSBR.bottomRight(), dSBR.topRight()), &po)) destPoint = po;
else if(QLineF::BoundedIntersection == centerline.intersect(QLineF(dSBR.bottomLeft(), dSBR.bottomRight()), &po)) destPoint = po;
else if(QLineF::BoundedIntersection == centerline.intersect(QLineF(dSBR.topLeft(), dSBR.bottomLeft()), &po)) destPoint = po;
} else {
sourcePoint = destPoint = (sSBR.bottomLeft().y() < dSBR.bottomLeft().y()) ? sSBR.bottomLeft() : dSBR.bottomLeft();
}
QLineF line(sourcePoint, destPoint);
// set label centered in the middle of the arrow
QRectF label (label_->boundingRect());
label.translate(line.pointAt(0.5));
if(sourcePoint != destPoint) label.translate(-label.width()/2, -label.height()/2);
// avoid overlapping
bool overlapped;
while(true) {
overlapped = false;
Graph *graph = reinterpret_cast<Graph *>(scene());
if(!graph) break;
Edges::const_iterator i = graph->edges_.constBegin();
while (i != graph->edges_.constEnd()) {
GraphEdge *e = i.value();
if(e != this && e->label()->geometry().intersects(label)) {
label.moveTo(label.x(), label.y() + 1 + e->label()->geometry().intersected(label).height());
overlapped = true;
}
++i;
}
// node overlapping
Nodes::const_iterator j = graph->nodes_.constBegin();
while (j != graph->nodes_.constEnd()) {
GraphNode *n = j.value();
if(n->geometry().intersects(label)) {
label.moveTo(label.x(), label.y() + 1 + n->geometry().intersected(label).height());
overlapped = true;
}
++j;
}
if(!overlapped) break;
};
label_->setGeometry(label);
labelRect_ = label;
prepareGeometryChange();
QGraphicsLayoutItem::updateGeometry();
}