forked from qt-creator/qt-creator
QmlDesigner: Fix bounding boxes in flow editor
The calculation of the bounding boxes did not take the new items into account. The new implementation now shares code with the painting. Change-Id: If257dbf4a36e925d71c109e245b7c87c7a5c4017 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -646,17 +646,71 @@ void FormEditorTransitionItem::setDataModelPositionInBaseState(const QPointF &)
|
||||
|
||||
}
|
||||
|
||||
class ResolveConnection
|
||||
{
|
||||
public:
|
||||
ResolveConnection(const QmlItemNode &node) :
|
||||
from({})
|
||||
,to(node.modelNode().bindingProperty("to").resolveToModelNode())
|
||||
,areaNode(ModelNode())
|
||||
{
|
||||
if (node.modelNode().hasBindingProperty("from"))
|
||||
from = node.modelNode().bindingProperty("from").resolveToModelNode();
|
||||
const QmlFlowItemNode to = node.modelNode().bindingProperty("to").resolveToModelNode();
|
||||
|
||||
if (from.isValid()) {
|
||||
for (const QmlFlowActionAreaNode &area : from.flowActionAreas()) {
|
||||
ModelNode target = area.targetTransition();
|
||||
if (target == node.modelNode()) {
|
||||
areaNode = area;
|
||||
} else {
|
||||
const ModelNode decisionNode = area.decisionNodeForTransition(node.modelNode());
|
||||
if (decisionNode.isValid()) {
|
||||
from = decisionNode;
|
||||
areaNode = ModelNode();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (from.modelNode().hasAuxiliaryData("joinConnection"))
|
||||
joinConnection = from.modelNode().auxiliaryData("joinConnection").toBool();
|
||||
} else {
|
||||
if (from == node.rootModelNode()) {
|
||||
isStartLine = true;
|
||||
} else {
|
||||
for (const ModelNode wildcard : QmlFlowViewNode(node.rootModelNode()).wildcards()) {
|
||||
if (wildcard.bindingProperty("target").resolveToModelNode() == node.modelNode()) {
|
||||
from = wildcard;
|
||||
isWildcardLine = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool joinConnection = false;
|
||||
|
||||
bool isStartLine = false;
|
||||
|
||||
bool isWildcardLine = false;
|
||||
|
||||
QmlFlowItemNode from;
|
||||
QmlFlowItemNode to;
|
||||
QmlFlowActionAreaNode areaNode;
|
||||
};
|
||||
|
||||
void FormEditorTransitionItem::updateGeometry()
|
||||
{
|
||||
FormEditorItem::updateGeometry();
|
||||
|
||||
const ModelNode from = qmlItemNode().modelNode().bindingProperty("from").resolveToModelNode();
|
||||
const ModelNode to = qmlItemNode().modelNode().bindingProperty("to").resolveToModelNode();
|
||||
ResolveConnection resolved(qmlItemNode());
|
||||
|
||||
QPointF fromP = QmlItemNode(from).flowPosition();
|
||||
QRectF sizeTo = QmlItemNode(to).instanceBoundingRect();
|
||||
QPointF fromP = QmlItemNode(resolved.from).flowPosition();
|
||||
QRectF sizeTo = resolved.to.instanceBoundingRect();
|
||||
|
||||
QPointF toP = QmlItemNode(to).flowPosition();
|
||||
QPointF toP = QmlItemNode(resolved.to).flowPosition();
|
||||
|
||||
if (QmlItemNode(resolved.to).isFlowDecision())
|
||||
sizeTo = QRectF(0,0,200,200);
|
||||
|
||||
qreal x1 = fromP.x();
|
||||
qreal x2 = toP.x();
|
||||
@@ -923,83 +977,44 @@ void FormEditorTransitionItem::paint(QPainter *painter, const QStyleOptionGraphi
|
||||
if (!qmlItemNode().modelNode().isValid())
|
||||
return;
|
||||
|
||||
if (!(qmlItemNode().modelNode().hasBindingProperty("from")
|
||||
&& qmlItemNode().modelNode().hasBindingProperty("to")))
|
||||
if (!qmlItemNode().modelNode().hasBindingProperty("to"))
|
||||
return;
|
||||
|
||||
painter->save();
|
||||
|
||||
QmlFlowItemNode from = qmlItemNode().modelNode().bindingProperty("from").resolveToModelNode();
|
||||
const QmlFlowItemNode to = qmlItemNode().modelNode().bindingProperty("to").resolveToModelNode();
|
||||
ResolveConnection resolved(qmlItemNode());
|
||||
|
||||
QmlFlowActionAreaNode areaNode = ModelNode();
|
||||
|
||||
bool joinConnection = false;
|
||||
|
||||
bool isStartLine = false;
|
||||
|
||||
bool isWildcardLine = false;
|
||||
|
||||
if (from.isValid()) {
|
||||
for (const QmlFlowActionAreaNode &area : from.flowActionAreas()) {
|
||||
ModelNode target = area.targetTransition();
|
||||
if (target == qmlItemNode().modelNode()) {
|
||||
areaNode = area;
|
||||
} else {
|
||||
const ModelNode decisionNode = area.decisionNodeForTransition(qmlItemNode().modelNode());
|
||||
if (decisionNode.isValid()) {
|
||||
from = decisionNode;
|
||||
areaNode = ModelNode();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (from.modelNode().hasAuxiliaryData("joinConnection"))
|
||||
joinConnection = from.modelNode().auxiliaryData("joinConnection").toBool();
|
||||
} else {
|
||||
if (from == qmlItemNode().rootModelNode()) {
|
||||
isStartLine = true;
|
||||
} else {
|
||||
for (const ModelNode wildcard : QmlFlowViewNode(qmlItemNode().rootModelNode()).wildcards()) {
|
||||
if (wildcard.bindingProperty("target").resolveToModelNode() == qmlItemNode().modelNode()) {
|
||||
from = wildcard;
|
||||
isWildcardLine = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!from.modelNode().isValid())
|
||||
if (!resolved.from.modelNode().isValid())
|
||||
return;
|
||||
|
||||
QRectF fromRect = QmlItemNode(from).instanceBoundingRect();
|
||||
if (QmlItemNode(from).isFlowDecision())
|
||||
QRectF fromRect = QmlItemNode(resolved.from).instanceBoundingRect();
|
||||
if (QmlItemNode(resolved.from).isFlowDecision())
|
||||
fromRect = QRectF(0,0,200,200);
|
||||
|
||||
if (QmlItemNode(from).isFlowWildcard())
|
||||
if (QmlItemNode(resolved.from).isFlowWildcard())
|
||||
fromRect = QRectF(0,0,200,200);
|
||||
fromRect.translate(QmlItemNode(from).flowPosition());
|
||||
fromRect.translate(QmlItemNode(resolved.from).flowPosition());
|
||||
|
||||
if (isStartLine) {
|
||||
if (resolved.isStartLine) {
|
||||
fromRect = QRectF(0,0,100,100);
|
||||
fromRect.translate(QmlItemNode(to).flowPosition()- QPoint(200, 0));
|
||||
fromRect.translate(QmlItemNode(resolved.to).flowPosition()- QPoint(200, 0));
|
||||
}
|
||||
|
||||
if (!joinConnection && areaNode.isValid()) {
|
||||
fromRect = QmlItemNode(areaNode).instanceBoundingRect();
|
||||
fromRect.translate(QmlItemNode(from).flowPosition());
|
||||
fromRect.translate(areaNode.instancePosition());
|
||||
if (!resolved.joinConnection && resolved.areaNode.isValid()) {
|
||||
fromRect = QmlItemNode(resolved.areaNode).instanceBoundingRect();
|
||||
fromRect.translate(QmlItemNode(resolved.from).flowPosition());
|
||||
fromRect.translate(resolved.areaNode.instancePosition());
|
||||
}
|
||||
|
||||
QRectF toRect = QmlItemNode(to).instanceBoundingRect();
|
||||
if (QmlItemNode(to).isFlowDecision())
|
||||
QRectF toRect = QmlItemNode(resolved.to).instanceBoundingRect();
|
||||
if (QmlItemNode(resolved.to).isFlowDecision())
|
||||
toRect = QRectF(0,0,200,200);
|
||||
|
||||
toRect.translate(QmlItemNode(to).flowPosition());
|
||||
toRect.translate(QmlItemNode(resolved.to).flowPosition());
|
||||
|
||||
if (isStartLine) {
|
||||
if (resolved.isStartLine) {
|
||||
fromRect = QRectF(0,0,50,50);
|
||||
fromRect.translate(QmlItemNode(to).flowPosition() + QPoint(-120, toRect.height() / 2 - 25));
|
||||
fromRect.translate(QmlItemNode(resolved.to).flowPosition() + QPoint(-120, toRect.height() / 2 - 25));
|
||||
}
|
||||
|
||||
toRect.translate(-pos());
|
||||
@@ -1021,9 +1036,12 @@ void FormEditorTransitionItem::paint(QPainter *painter, const QStyleOptionGraphi
|
||||
|
||||
QColor color = "#e71919";
|
||||
|
||||
if (isStartLine)
|
||||
if (resolved.isStartLine)
|
||||
color = "blue";
|
||||
|
||||
if (resolved.isWildcardLine)
|
||||
color = "green";
|
||||
|
||||
bool dash = false;
|
||||
|
||||
if (qmlItemNode().modelNode().hasAuxiliaryData("color"))
|
||||
@@ -1048,7 +1066,7 @@ void FormEditorTransitionItem::paint(QPainter *painter, const QStyleOptionGraphi
|
||||
|
||||
paintConnection(painter, fromRect, toRect, width, adjustedWidth ,color, dash, outOffset, inOffset, breakOffset);
|
||||
|
||||
if (isStartLine) {
|
||||
if (resolved.isStartLine) {
|
||||
QPen pen;
|
||||
pen.setCosmetic(true);
|
||||
|
||||
|
Reference in New Issue
Block a user